theseus/bundled-addons/bchwallet/lib/dgb/core/address.js

53 lines
2 KiB
JavaScript
Raw Normal View History

feat(theseus/aegis): DGB adapter on @dgb-wallet/{core,psbt} vendored packages Aegis now shares its DGB code with the standalone DigiByte web-wallet at D:\Dev\SilentCode\Digibyte. Address derivation and PSBT construction come from that project's @dgb-wallet/core and @dgb-wallet/psbt packages instead of Aegis-local reimplementations. Any bugfix upstream flows in via a re-vendor of dist/*. - lib/dgb/{core,psbt}/ — vendored dist/ output of the two packages plus a tiny package.json shim marking them as ESM. @dgb-wallet/core's own import specifier "@dgb-wallet/core" inside psbt/*.js is rewritten to "../core/index.js" so the sibling module resolves without a workspace. - New Theseus deps: bitcoinjs-lib, bip32, bip39, @bitcoinerlab/secp256k1, ecpair — the peer deps the vendored packages need. Loaded via api.require in index.js's loadDeps(). - chain-dgb.js is a thin adapter now: BIP32 tree via bip32 + DGB Network object, addresses via core.p2wpkhAddress, tx via psbt.buildPsbt + PSBT.signInput (per-input, since each UTXO's key differs) + psbt.finalizeAndExtract. Runtime backend stays the same — Theseus's lib/electrum.js against the DGB ElectrumX pool. - Verified end-to-end in scratchpad: abandon×11 mnemonic derives dgb1q9gmf0pv8jdymcly6lz6fl7lf6mhslsd72e2jq8 (matches iancoleman.io/bip39 and the previous inline implementation, so no on-chain address change for anyone who was already using Aegis's DGB slot). PSBT build+sign+ finalize on a mock UTXO produces a valid 223-byte witness tx. BIP44 (D…) and BIP49 (S…) address families are implemented in the vendored core but not yet exposed in Aegis's picker — the panel needs an "address family" selector inside the DGB settings block first. Left for a follow-up; today's DGB pick uses BIP84 native SegWit only.
2026-09-07 02:19:44 +02:00
import { payments, initEccLib } from 'bitcoinjs-lib';
import * as ecc from '@bitcoinerlab/secp256k1';
import { digibyte, digibyteLegacyP2SH } from './network.js';
// Required for Taproot address derivation (P2TR).
initEccLib(ecc);
export function p2pkhAddress(node, network = digibyte) {
const { address } = payments.p2pkh({
pubkey: Buffer.from(node.publicKey),
network,
});
if (!address)
throw new Error('p2pkh derivation returned no address');
return address;
}
export function p2shP2wpkhAddress(node, network = digibyte) {
const redeem = payments.p2wpkh({
pubkey: Buffer.from(node.publicKey),
network,
});
const { address } = payments.p2sh({ redeem, network });
if (!address)
throw new Error('p2sh-p2wpkh derivation returned no address');
return address;
}
// Derive the "S..." (current DGB, scriptHash 0x3f) AND "3..." (legacy
// Bitcoin-compatible, scriptHash 0x05) BIP49 addresses for the same
// key. Ian Coleman's BIP39 tool and several older wallets generate the
// legacy "3..." variant, so any seed-recovery scan must check both.
export function p2shP2wpkhAddressesBoth(node) {
return {
modern: p2shP2wpkhAddress(node, digibyte),
legacy: p2shP2wpkhAddress(node, digibyteLegacyP2SH),
};
}
export function p2wpkhAddress(node, network = digibyte) {
const { address } = payments.p2wpkh({
pubkey: Buffer.from(node.publicKey),
network,
});
if (!address)
throw new Error('p2wpkh derivation returned no address');
return address;
}
// BIP86 Taproot address using the x-only pubkey with no script tree,
// which applies the standard BIP86 tweak internally in bitcoinjs-lib.
export function p2trAddress(node, network = digibyte) {
const internalPubkey = Buffer.from(node.publicKey.subarray(1, 33));
const { address } = payments.p2tr({ internalPubkey, network });
if (!address)
throw new Error('p2tr derivation returned no address');
return address;
}
//# sourceMappingURL=address.js.map