Reported as "the Aegis DigiByte import error". The vendored @dgb-wallet/core modules under lib/dgb/ imported "bitcoinjs-lib", "bip32", "ecpair", "bip39" and "@bitcoinerlab/secp256k1" as bare specifiers. Node's ESM resolver walks up from the importing file, so that resolves in a dev checkout — where Theseus's node_modules sits above the add-on — and resolves nowhere once Aegis is running from <userData>/extensions/aegis/, which is every OTA install. The import threw, index.js caught it and set dgbCore = null, and any DigiByte import then died in digibyteNetwork() with "DGB adapter not available". So DigiByte worked on a fresh install and disappeared after the first update. Confirmed on this machine: the only node_modules reachable from the installed extension carries bip39 and none of the other four. lib/dgb/deps.js now holds the dependencies, injected by index.js from api.require (which resolves against the app tree) before anything under lib/dgb/ is imported — the same pattern every other lib/*.js in Aegis already uses, and the reason that pattern exists. Consumers read them through accessors rather than capturing them at module scope, so import order is no longer load-bearing: hd.js builds its bip32 on first use and the two initEccLib callers go through a once-only ensureEcc(). Using a DGB module without injection now throws a named error instead of a resolver failure swallowed into a null. Verified by loading the modules from a directory with no reachable node_modules and deriving real addresses: BIP44 D…, BIP49 S… with its legacy 3… pair, BIP84 dgb1q…, BIP86 dgb1p… taproot, plus a WIF round-trip and the non-DGB WIF rejection.
56 lines
No EOL
1.9 KiB
JavaScript
56 lines
No EOL
1.9 KiB
JavaScript
import { Psbt } from '../deps.js';
|
|
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
|