Skip to content
This repository was archived by the owner on Dec 1, 2024. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
"bchaddrjs": "0.5.2",
"bignumber.js": "9.0.2",
"bip32": "3.0.1",
"bip86": "0.0.1",
Comment thread
vsenkiv-ledger marked this conversation as resolved.
"bitcoinjs-lib": "6.0.1",
"bitcore-lib-cash": "8.25.28",
"bs58check": "2.1.2",
Expand Down
26 changes: 25 additions & 1 deletion src/actions/deriveAddresses.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import bs58 from "bs58check";
import { publicKeyTweakAdd } from "secp256k1";

const bip32 = BIP32Factory(ecc);
const BIP86 = require('bip86');

class BIP32 {
publicKey: any;
Expand Down Expand Up @@ -134,6 +135,25 @@ function getNativeSegWitAddress(
return String(address);
}

/**
* derive a Taproot address at a given account and index positions
* @param xpub the xpub from which to derive the native SegWit address
* @param account account number from which to derive the native SegWit address
* @param index index number from which to derive the native SegWit address
* @returns the derived Taproot address
*/
function getTaprootAddress(
xpub: string,
account: number,
index: number,
): string {

var account1 = new BIP86.fromXPub(xpub);
var address = account1.getAddress(index,!!account);
Comment thread
vsenkiv-ledger marked this conversation as resolved.

return String(address);
}

/**
* derive a Bitcoin Cash address at a given account and index positions
* @param xpub the xpub from which to derive the Bitcoin Cash address
Expand Down Expand Up @@ -201,6 +221,8 @@ function deriveAddress(
return getSegWitAddress(xpub, account, index);
case DerivationMode.NATIVE:
return getNativeSegWitAddress(xpub, account, index);
case DerivationMode.TAPROOT:
return getTaprootAddress(xpub,account,index);
case DerivationMode.BCH:
return getLegacyBitcoinCashAddress(xpub, account, index);
case DerivationMode.DOGECOIN:
Expand All @@ -221,8 +243,10 @@ function deriveAddress(
*/

function getDerivationMode(address: string) {
if (address.match("^(bc1|tb1|ltc1).*")) {
if (address.match("^(bc1q|tb1|ltc1).*")) {
Comment thread
vsenkiv-ledger marked this conversation as resolved.
return DerivationMode.NATIVE;
} else if (address.match("^[bc1p].*")) {
return DerivationMode.TAPROOT;
} else if (address.match("^[32M].*")) {
return DerivationMode.SEGWIT;
} else if (address.match("^[1nmL].*")) {
Expand Down
2 changes: 2 additions & 0 deletions src/configuration/currencies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ export enum DerivationMode {
LEGACY = "Legacy",
NATIVE = "Native SegWit",
SEGWIT = "SegWit",
TAPROOT = "Taproot",
BCH = "Bitcoin Cash",
ETHEREUM = "Ethereum",
DOGECOIN = "Dogecoin",
Expand All @@ -20,6 +21,7 @@ export const currencies = {
DerivationMode.LEGACY,
DerivationMode.SEGWIT,
DerivationMode.NATIVE,
DerivationMode.TAPROOT,
],
precision: 10 ** 8,
utxo_based: true,
Expand Down