Skip to content

An algorithm which calculates BTC address for deposits to ckBTC minter

License

Notifications You must be signed in to change notification settings

research-ag/ckbtc-address-js

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

BTC Deposit Address Generator for ckBTC Minter

This Typescript module provides an implementation of a Bitcoin address derivation algorithm for depositing BTC to the ckBTC minter on the Internet Computer.

Overview

The module derives SegWit (P2WPKH) Bitcoin addresses for depositing BTC into a ckBTC minter using an extended public key (xpub). It follows the BIP32 key derivation standard.

Features

  • BIP32 hierarchical deterministic (HD) key derivation
  • SegWit (P2WPKH) Bitcoin address generation
  • Computing deposit addresses for ICRC-1 accounts

Installation

npm install @research-ag/ckbtc-address-js --save

Usage

Importing the Module

import { Minter, CKBTC_MINTER_MAINNET_XPUBKEY } from "@research-ag/ckbtc-address-js";

Creating a Minter Instance

let minter = new Minter(CKBTC_MINTER_MAINNET_XPUBKEY);

Note: CKBTC_MINTER_MAINNET_XPUBKEY is a key for mainnet ckBTC minter

Deriving a BTC Deposit Address

For a given ICRC-1 account:

let account = {
    owner: Principal.fromText("<owner-principal>"),
    subaccount: null,
};

let depositAddress = minter.depositAddr(account);

Alternatively, using a function-based approach:

let depositAddressFunc = minter.depositAddrFunc(Principal.fromText("<owner-principal>"));
let btcAddress = depositAddressFunc(null);  // Passing optional subaccount

Testing

Run the module tests:

npm run test

Module Structure

The package consists of:

bip32.ts

  • Implements BIP32 key derivation.
  • Provides functions for deriving child keys and computing Bitcoin addresses.

minter.ts

  • Implements the Minter class.
  • Computes deposit addresses based on the derived keys.

License

This project is licensed under the MIT License.

About

An algorithm which calculates BTC address for deposits to ckBTC minter

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published