Skip to content

tetherto/lib-wallet

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Wallet Dev Kit by Tether

Multi asset cryptocurrency wallet library in JavaScript. Supported on 3 platforms: Node.js, Browser, Bare Runtime

Checkout the website here

⭐ Features

πŸ”‘ Non custodial: not your keys, not your coins.

🧩 Composable: Single facade to interact with multiple assets and wallets

πŸ“¦ Modular: All components are modular and can be used independently.

πŸ› οΈ Extensible: Easily add new asset, seed source, block source...etc

πŸ”— Blockchains

  • Electrum block data source. Support for TCP and Websocket on browser.
  • P2WPKH / BIP84 address support.
  • Web3 and Indexer block data source.
  • ERC20 support.
  • BIP44 address generation.
Blockchain Supported Token Protocol
Bitcoin βœ… -
Ethereum βœ… ERC20
Tron βŒ› TRC20
TON βŒ› Jettons
Avalanche βŒ› C-Chain
Solana βŒ› Solana Token
Celo βŒ› ERC20
Liquid βŒ› Liquid Asset
Tezos βŒ› Tezos Token
Aptos βŒ› Fungible Asset
Cosmos βŒ› ERC20
Near βŒ› Near Token
Polkadot βŒ› AssetHub

πŸ—οΈ Architecture

🧩 Components and Links

The library comes with all the components needed to build a wallet. You can also use these as an example to build your own components.

</> Example Usage

Checkout Quick start guide for more detailed guide.

  const seed = await BIP39Seed.generate(/** seed phrase or leave empty to generate one */)

  // Setup wallet store. Modular data store for  writing data
  const store = new WalletStoreHyperbee({
    store_path: './wallet-store' // Leave empty to use in-memory store
  })

  // Setup Bitcoin asset
  const btcPay = new BitcoinPay({
    // Asset name is used to identify the asset in the wallet.
    // You can have multiple assets of same currency
    asset_name: 'btc',
    // Bitcoin network you'll be using
    network: 'regtest'
  })

  // Setup main wallet class
  const wallet = new Wallet({
    store,
    seed,
    // List of assets that the wallet will support 
    assets: [ btcPay ]
  })

  // Start wallet and initialize
  // Connect to block source 
  // Add asset to wallet registry 
  await wallet.initialize()

  // Traverse wallet history of all assets and sync them. This might take a while depending on wallet size 
  await wallet.syncHistory(opts)


  // All payment features are namespaced under wallet.pay[asset_name][action](opts, ...args)
  // Get a new bitcoin address using api below
  const btcAddress = await wallet.pay.btc.getNewAddress()

  // Get Tx history

  await wallet.pay.btc.getTransactions({}, (tx) =>{
    // do something here 
  }))


  // Add Asset:
  wallet.addAsset()
  //done 

Wallet API Documentation

Constructor

new Wallet(config)

Creates a new Wallet instance.

Parameters

  • config (Object):
    • store (Object): Required. Storage interface for the wallet
    • seed (Object): Required. Seed object for wallet initialization
    • assets (Array): Required. Array of asset objects to be managed by the wallet

Throws

  • WalletError with code 'BAD_ARGS' if required config parameters are missing or invalid

Methods

initialize()

await wallet.initialize()

Initializes the wallet and all its assets. Emits 'ready' event when complete.

destroy()

await wallet.destroy()

Cleanly destroys the wallet instance, closing stores and network connections..

addAsset(assetObj)

await wallet.addAsset(assetObj)

Adds a new asset to the wallet.

  • assetObj (Object): Asset instance to add

syncHistory([options])

await wallet.syncHistory({
    asset : 'asset-name' // sync only this asset
})

await wallet.syncHistory() /// sync everything

Synchronizes transaction history for assets.

Options

  • asset (String): Optional. Sync specific asset name
  • all (Boolean): Optional. If true, syncs all tokens for assets
  • Additional options are passed to asset.syncTransactions()

exportSeed()

const seed = wallet.exportSeed()

Exports the wallet's seed data.

Events

The wallet extends EventEmitter and emits the following events:

  • ready: Emitted when wallet is fully initialized
  • new-tx: Emitted when a new transaction is detected
    • Arguments: (assetName, ...transactionDetails)
  • new-block: Emitted when a new block is detected
    • Arguments: (assetName, ...blockDetails)
  • asset-synced: Emitted when an asset completes synchronization
    • Arguments: (assetName, [token])

Properties

pay

An AssetList instance containing all initialized assets. Available after initialization.

Development

πŸš€ Getting started

The best way to get started developing:

  1. Setup local development enviroment.
  2. Configure example apps to connect to your local blockchains.
  3. Start hacking on example apps. After you have example apps running:
  • Fork/modify existing assets
  • Build new assets.

🐚 Seashell Example Wallet

There is a working example wallet that supports. This wallet can be used as an example for making your own integrations.

πŸ› οΈ Dev Enviroment

The wallet is designed to work with local test enviroments.

🍱 Building your own asset

See guide for how to add new assets

πŸ§ͺ Testing

  • Brittle is used for testing
  • Tests included in this repo cover
    • Shared modules
    • Integration of various blockchains
  • Each asset has it's own tests included in it's repo.

Security

For critical vulnerabilities and bug reports, please reach out to us at [email protected]. Your insights help us keep WDK by Tether secure and reliable!