aegis/lib/dgb/core/hd.js

24 lines
952 B
JavaScript
Raw Normal View History

import { BIP32Factory } from 'bip32';
import * as ecc from '@bitcoinerlab/secp256k1';
import { digibyte, DGB_COIN_TYPE } from './network.js';
const bip32 = BIP32Factory(ecc);
export const PURPOSE_LABEL = {
44: 'BIP44 legacy P2PKH',
49: 'BIP49 P2SH-wrapped SegWit',
84: 'BIP84 native SegWit v0',
86: 'BIP86 Taproot (SegWit v1)',
};
export function rootFromSeed(seed, network = digibyte) {
return bip32.fromSeed(seed, network);
}
// Standard account-level derivation: m/purpose'/coin'/account'.
// account defaults to 0 (the first account).
export function accountNode(root, purpose, account = 0) {
return root.derivePath(`m/${purpose}'/${DGB_COIN_TYPE}'/${account}'`);
}
// Address-level derivation from an account node.
// change = 0 for external (receive) addresses, 1 for internal (change).
export function addressNode(account, change, index) {
return account.derive(change).derive(index);
}
//# sourceMappingURL=hd.js.map