aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2026-03-03 09:14:17 -0800
committerAdam Soltys <[email protected]>2026-03-03 09:14:17 -0800
commitfdce612b18571de36216c1ed12fabd349d4e39e2 (patch)
treec6519cf11407e1d56c392745e7bd1c363ae5cdaa
parent94569349ea73685ae531ca0da91bfc3ff9d40c58 (diff)
downloadcoinos-server-fdce612b18571de36216c1ed12fabd349d4e39e2.tar.gz
coinos-server-fdce612b18571de36216c1ed12fabd349d4e39e2.zip
p2a lookups
-rw-r--r--lib/p2a.ts25
1 files changed, 6 insertions, 19 deletions
diff --git a/lib/p2a.ts b/lib/p2a.ts
index 6e256f20..ce91006f 100644
--- a/lib/p2a.ts
+++ b/lib/p2a.ts
@@ -8,13 +8,6 @@ export const CHILD_VSIZE = 152;
const P2A_WITNESS_PROGRAM = new Uint8Array([0x4e, 0x73]);
const P2A_WITNESS_VERSION = 1;
-const P2A_ADDRESSES: Record<string, string> = {
- mainnet: "bc1pfeessrawgf",
- testnet: "tb1pfeessrawgf",
- signet: "tb1pfeessrawgf",
- regtest: "bcrt1pfeessrawgf",
-};
-
const BECH32M_PREFIXES: Record<string, string> = {
mainnet: "bc",
testnet: "tb",
@@ -22,22 +15,16 @@ const BECH32M_PREFIXES: Record<string, string> = {
regtest: "bcrt",
};
-function verifyP2AAddresses() {
- for (const [network, expected] of Object.entries(P2A_ADDRESSES)) {
- const prefix = BECH32M_PREFIXES[network];
- const words = [P2A_WITNESS_VERSION, ...bech32m.toWords(P2A_WITNESS_PROGRAM)];
- const encoded = bech32m.encode(prefix, words);
- if (encoded !== expected) {
- throw new Error(`P2A address mismatch for ${network}: got ${encoded}, expected ${expected}`);
- }
- }
+function encodeP2AAddress(network: string): string {
+ const prefix = BECH32M_PREFIXES[network];
+ if (!prefix) throw new Error(`Unknown network: ${network}`);
+ const words = [P2A_WITNESS_VERSION, ...bech32m.toWords(P2A_WITNESS_PROGRAM)];
+ return bech32m.encode(prefix, words);
}
-verifyP2AAddresses();
-
export function getP2AAddress(): string {
const network = config.bitcoin.network || "mainnet";
- return P2A_ADDRESSES[network];
+ return encodeP2AAddress(network);
}
export function isP2AOutput(scriptPubKeyHex: string): boolean {