import { bip32, hmac, sha512 } from '../deps.js'; import { digibyte, DGB_COIN_TYPE } from './network.js'; // BIP32 derives the master key as HMAC-SHA512(key, seed) with the key // "Bitcoin seed". DigiByte's 2018-19 official mobile wallets (BreadWallet // forks) used "DigiByte seed" instead, so the SAME 12 words give a // completely different key tree — every address differs. A recovery that // only tries the standard key never finds those coins. // Ported from Digibyte.X/dgb-wallet @ 989a2696. export const HMAC_BITCOIN_SEED = 'Bitcoin seed'; export const HMAC_DIGIBYTE_SEED = 'DigiByte seed'; 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, hmacKey = HMAC_BITCOIN_SEED) { if (hmacKey === HMAC_BITCOIN_SEED) return bip32().fromSeed(seed, network); const I = hmac()(sha512(), new TextEncoder().encode(hmacKey), seed); return bip32().fromPrivateKey(Buffer.from(I.slice(0, 32)), Buffer.from(I.slice(32)), 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