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.
56 lines
No EOL
1.9 KiB
JavaScript
56 lines
No EOL
1.9 KiB
JavaScript
import { Psbt } from 'bitcoinjs-lib';
|
|
import { digibyte } from '../core/index.js';
|
|
// Construct an unsigned PSBT from a set of UTXOs and destination outputs.
|
|
// Does not add a change output — the caller decides change amount and
|
|
// address. Does not compute fees — the caller must have already subtracted
|
|
// fee from outputs.
|
|
export function buildPsbt(params, network = digibyte) {
|
|
const psbt = new Psbt({ network });
|
|
const inputs = params.sortBip69 === false ? params.inputs : sortInputs(params.inputs);
|
|
const outputs = params.sortBip69 === false ? params.outputs : sortOutputs(params.outputs);
|
|
for (const u of inputs) {
|
|
psbt.addInput(inputToPsbtInput(u));
|
|
}
|
|
for (const o of outputs) {
|
|
psbt.addOutput({ address: o.address, value: o.value });
|
|
}
|
|
return psbt;
|
|
}
|
|
function inputToPsbtInput(u) {
|
|
const input = {
|
|
hash: u.txid,
|
|
index: u.vout,
|
|
};
|
|
if (u.witness) {
|
|
input.witnessUtxo = {
|
|
script: Buffer.from(u.witness.scriptHex, 'hex'),
|
|
value: u.witness.value,
|
|
};
|
|
}
|
|
if (u.nonWitnessTxHex) {
|
|
input.nonWitnessUtxo = Buffer.from(u.nonWitnessTxHex, 'hex');
|
|
}
|
|
if (u.redeemScriptHex) {
|
|
input.redeemScript = Buffer.from(u.redeemScriptHex, 'hex');
|
|
}
|
|
if (u.tapInternalKeyHex) {
|
|
input.tapInternalKey = Buffer.from(u.tapInternalKeyHex, 'hex');
|
|
}
|
|
return input;
|
|
}
|
|
// BIP69 lexicographic ordering. Improves privacy by not revealing input
|
|
// selection order (which can hint at wallet coin-selection strategy).
|
|
function sortInputs(inputs) {
|
|
return [...inputs].sort((a, b) => {
|
|
const cmp = a.txid.localeCompare(b.txid);
|
|
return cmp !== 0 ? cmp : a.vout - b.vout;
|
|
});
|
|
}
|
|
function sortOutputs(outputs) {
|
|
return [...outputs].sort((a, b) => {
|
|
if (a.value !== b.value)
|
|
return a.value - b.value;
|
|
return a.address.localeCompare(b.address);
|
|
});
|
|
}
|
|
//# sourceMappingURL=build.js.map
|