theseus/bundled-addons/aegis/lib/dgb/core/wif.js
Local Dev 2e54bf5e5a Ship Theseus 0.3.28 5d15508b (Aegis update card + DevTools in tab sidebar + real favicons)
Setup    5d15508bba929f1f074c052ac933863eadf6eb8e56984ebd5a1af75e80626643
Portable a5d346b97f5a13d85fa3bd301a72075ddb82fe636d7b1a51840ffd5a16d879f4

Bundled since 0.3.27:

32d4b75 - Aegis (bchwallet) gains its own update card in Settings >
General beside Ariadne. Check for updates hits the same signed OTA
endpoint the boot timer uses; Restart to apply appears when a signed
newer version is staged. Uses the existing addons-check-updates + a
new app-restart IPC. New Aegis versions ship without a Theseus release.

32d4b75 (same commit) - DevTools (F12 / Ctrl+Shift+I) opens docked to
the right of the tab (mode: 'right') instead of a detached window.
Matches stock Chrome. Users who prefer detached can drag out via the
DevTools own toolbar.

b71c925 - Search-engine favicons in Settings > Search now use Google's
/s2/favicons service — DuckDuckGo's ip3 source returned 404 for enough
hosts (Brave, Bing, Yandex, etc.) that half the list was falling
through to the emoji placeholder.

Deployed. Verified LIVE 0.3.28.
2026-09-08 18:17:25 +02:00

72 lines
No EOL
3.3 KiB
JavaScript

import { ECPairFactory } from 'ecpair';
import * as ecc from '@bitcoinerlab/secp256k1';
import { payments, initEccLib } from 'bitcoinjs-lib';
import { digibyte, digibyteLegacyP2SH, digibyteLegacyWIF } from './network.js';
const ECPair = ECPairFactory(ecc);
initEccLib(ecc);
// Import a DigiByte private key in WIF (Wallet Import Format).
// Tries the modern 0x80 prefix first, falls back to the legacy 0x9e
// prefix that older DGB tools produced. Rejects anything else with a
// clear message that identifies the network mismatch.
export function importWif(wif) {
const trimmed = wif.trim();
try {
return { keyPair: ECPair.fromWIF(trimmed, digibyte), variant: 'modern' };
}
catch {
// fall through to legacy attempt
}
try {
return { keyPair: ECPair.fromWIF(trimmed, digibyteLegacyWIF), variant: 'legacy' };
}
catch (e) {
throw new Error(`Not a valid DigiByte WIF (tried both current 0x80 and legacy 0x9e prefixes). ` +
`Underlying error: ${e.message}. Check the key is for DGB mainnet, not testnet or another chain.`);
}
}
// Import against a specific network only (advanced / testing).
export function importWifStrict(wif, network = digibyte) {
return ECPair.fromWIF(wif.trim(), network);
}
export function exportWif(keyPair) {
return keyPair.toWIF();
}
export function addressesForPubkey(pubkey, network = digibyte) {
const p2pkh = payments.p2pkh({ pubkey, network });
const wpkhRedeem = payments.p2wpkh({ pubkey, network });
// bitcoinjs-lib enforces `redeem.network === outerNetwork` (identity
// comparison, not shape). To render the legacy 3-prefix P2SH address
// we need a fresh redeem whose .network property is the legacy variant
// — same bytes on the wire, different object identity.
const wpkhRedeemLegacy = payments.p2wpkh({ pubkey, network: digibyteLegacyP2SH });
const p2shModern = payments.p2sh({ redeem: wpkhRedeem, network });
const p2shLegacy = payments.p2sh({ redeem: wpkhRedeemLegacy, network: digibyteLegacyP2SH });
const p2wpkh = payments.p2wpkh({ pubkey, network });
const p2tr = payments.p2tr({ internalPubkey: pubkey.subarray(1, 33), network });
if (!p2pkh.address || !p2shModern.address || !p2shLegacy.address || !p2wpkh.address || !p2tr.address) {
throw new Error('bitcoinjs-lib returned an empty address for one of the payment types');
}
if (!p2pkh.output || !p2shModern.output || !p2wpkh.output || !p2tr.output) {
throw new Error('bitcoinjs-lib returned an empty scriptPubKey for one of the payment types');
}
return {
p2pkh: p2pkh.address,
p2shP2wpkhModern: p2shModern.address,
p2shP2wpkhLegacy: p2shLegacy.address,
p2wpkh: p2wpkh.address,
p2tr: p2tr.address,
scripts: {
p2pkh: Buffer.from(p2pkh.output).toString('hex'),
p2shP2wpkh: Buffer.from(p2shModern.output).toString('hex'),
p2wpkh: Buffer.from(p2wpkh.output).toString('hex'),
p2tr: Buffer.from(p2tr.output).toString('hex'),
},
};
}
export function importWifWithAddresses(wif) {
const imported = importWif(wif);
const pubkey = Buffer.from(imported.keyPair.publicKey);
const addrs = addressesForPubkey(pubkey);
return { ...imported, ...addrs };
}
//# sourceMappingURL=wif.js.map