Skip to content

DavisDmitry/BitPurseBot

Repository files navigation

BitPurseBot

BitPurseBot - a self-custody opensource Bitcoin wallet within Telegram.


BitPurseBot SvelteKit Static Badge TailwindCSS Material You Zig lang Web Assembly BlockStream Grammy PocketBase


Run locally

Requirements

Instruction

  • Clone this repository:

    git clone https://github.com/DavisDmitry/BitPurseBot
  • Install dependencies

    yarn
  • Copy .env.example as .env

    cp .env.example .env
  • Make the app public available

    yarn expose
  • Edit your .env (see Configuration).

  • Build

    yarn build
  • Set webhook url (replace <VALUE> with values from Configuration)

    curl -d "url=<PUBLIC_APP_URL>/api/bot&secret_token=<WEBHOOK_SECRET>" -X POST https://api.telegram.org/bot<BOT_TOKEN>/setWebhook
  • Run

    yarn preview

Configuration

Everything is configured using environment variables. All settings can be divided into two types:

  • Static (build time)
  • Dynamic (runtime)

About SvelteKit environment variables

Variables

  • PUBLIC_NET: Bitcoin network (main or test) - static
  • PUBLIC_BOT_USERNAME: Username of your bot (without @) - static
  • PUBLIC_APP_URL: Base path of your mini app - static

    must start with https://

  • BOT_TOKEN: Token of your bot - dynamic

    You can get it from @BotFather

  • WEBHOOK_SECRET: Secret token for webhooks from Telegram Bot API - dynamic

    Bot API #sendWebhook

  • PB_URL: PocketBase backend URL - dynamic, optional (set empty string if you don't need it)

    Optional PocketBase backend

  • PB_EMAIL: PocketBase admin email - dynamic, required if PB_URL provided (set empty string if you don't need it)
  • PB_PASSWORD: PocketBase admin password - dynamic, required if PB_URL provided (set empty string if you don't need it)

Optional backend

If you want to save bot users to a database, you can run the PocketBase backend. But this is not necessary, the bot will work without it.

Instruction

  • Download PocketBase binary

  • Apply migrations (stored in pb_migrations)

    ./pocketbase migrate
  • Start the web server

    ./pocketbase server
  • Go to PocketBase admin UI and setup admin account

  • Configure PB_* variables in your .env

Production deploy

BitPurseBot can be deployed like any other SvelteKit application. See SvelteKit documentation

For developers

WASM code for signing transactions has already been compiled (stored in static). You can also compile it yourself if you have Zig installed

yarn build-zig

Supported Telegram Mini App features

Current state and limitations

Since I had a little time to develop, the functionality of BitPurseBot is quite limited at the moment.

  • BIP-44 and BIP-84 have been partially implemented. BitPurseBot creates a hierarchy of keys, but uses only one account and one key for incoming transactions and change (m/84'/0'/0'/0/0 for mainnet, m/84'/1'/0'/0/0 for testnet)

  • Only one address type can be created: Native SegWit (bech32)

  • Only one type of outgoing transactions is supported: P2WPKH (native SegWit)

  • The seed phrase cannot be imported and is generated randomly when the Mini App is first launched

  • The seed phrase is stored in localStorage (wallet's TON Space does the same, but has the ability to make a cloud backup)

Because of all this, the mainnet version has not yet been launched.