// Dependency injection for the vendored DGB modules. // // These files were vendored from @dgb-wallet/core and imported // "bitcoinjs-lib", "bip32", "ecpair" and "@bitcoinerlab/secp256k1" as bare // specifiers. That resolves fine in a dev checkout, where Theseus's // node_modules sits above the add-on — and fails for every OTA install, where // Aegis lives in /extensions/aegis/ and Node's ESM resolver has // nowhere to find them. index.js caught the failure and set dgbCore = null, // so DigiByte quietly stopped existing and an import died with "DGB adapter // not available". It worked on a fresh install and broke after the first // update, which is the worst possible shape for a bug. // // index.js already holds all of these via api.require (which resolves against // the app tree), so it injects them here before importing anything under // lib/dgb/. Every consumer reads them through the accessors below rather than // capturing them at module scope, so nothing depends on import order and a // missing injection fails loudly at the call instead of silently at load. let deps = null; export function setDgbDeps(d) { const need = ["bitcoinjs", "ecc", "bip32Factory", "ecpairFactory", "bip39", "hmac", "sha512"]; for (const k of need) { if (!d || !d[k]) throw new Error(`setDgbDeps: missing ${k}`); } deps = d; } function need() { if (!deps) throw new Error("DGB modules used before setDgbDeps() — see lib/dgb/deps.js"); return deps; } export const bitcoinjs = () => need().bitcoinjs; export const payments = () => need().bitcoinjs.payments; export const Psbt = () => need().bitcoinjs.Psbt; export const ecc = () => need().ecc; export const bip39 = () => need().bip39; export const hmac = () => need().hmac; export const sha512 = () => need().sha512; // initEccLib must run before any Taproot derivation, and exactly once. let eccInstalled = false; export function ensureEcc() { if (eccInstalled) return; need().bitcoinjs.initEccLib(need().ecc); eccInstalled = true; } // Built on first use rather than at module scope, so hd.js no longer forces // the deps to exist merely by being imported. let bip32Cached = null; export function bip32() { if (!bip32Cached) bip32Cached = need().bip32Factory(need().ecc); return bip32Cached; } let ecpairCached = null; export function ECPair() { if (!ecpairCached) ecpairCached = need().ecpairFactory(need().ecc); return ecpairCached; }