dcr-ts 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/errors.ts","../src/bytes.ts","../src/blake256.ts","../src/hash.ts","../src/base58.ts","../src/networks.ts","../src/keys.ts","../src/script.ts","../src/address.ts","../src/wif.ts","../src/hd.ts","../src/bip39.ts","../src/tx.ts","../src/sighash.ts","../src/sign.ts","../src/amount.ts"],"names":["ripemd160","secp256k1","ed25519","out","hash160","pubKey","SignatureType","hmac","sha512","english","scureGenerateMnemonic","scureValidateMnemonic","scureMnemonicToEntropy","scureEntropyToMnemonic","mnemonicToSeedSync","TxSerializeType","TxTree","signatureScript","SigHashType"],"mappings":";;;;;;;;;;;AAuGA,IAAM,KAAA,mBAAQ,MAAA,CAAO,GAAA,CAAI,iBAAiB,CAAA;AAGnC,IAAM,QAAA,GAAN,cAAuB,KAAA,CAAM;AAAA,EAGlC,WAAA,CAEW,IAAA,EACT,OAAA,EACA,OAAA,EACA;AACA,IAAA,KAAA,CAAM,SAAS,OAAO,CAAA;AAJb,IAAA,IAAA,CAAA,IAAA,GAAA,IAAA;AAOT,IAAA,MAAA,CAAO,eAAe,IAAA,EAAM,KAAA,EAAO,EAAE,KAAA,EAAO,MAAM,CAAA;AAAA,EACpD;AAAA,EARW,IAAA;AAAA,EAJO,IAAA,GAAO,UAAA;AAa3B;AAMO,SAAS,WAAW,CAAA,EAA2B;AACpD,EAAA,OAAO,aAAa,QAAA,IAAa,OAAO,MAAM,QAAA,IAAY,CAAA,KAAM,QAAQ,KAAA,IAAS,CAAA;AACnF;AAOO,SAAS,YAAA,CAAa,GAAY,IAAA,EAA6B;AACpE,EAAA,OAAO,UAAA,CAAW,CAAC,CAAA,IAAK,CAAA,CAAE,IAAA,KAAS,IAAA;AACrC;AAGO,SAAS,GAAA,CAAI,IAAA,EAAoB,GAAA,EAAa,OAAA,EAA2B;AAC9E,EAAA,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ything this library throws is a {@link DcrError} carrying a stable\n * {@link DcrErrorCode}. Without one, the only way to tell a mistyped address from\n * a right-address-wrong-network paste is to match on prose — which is not part of\n * any API, breaks the moment a message is reworded, and cannot express the cases\n * that share wording. The tests in this repository had exactly that problem.\n *\n * ```ts\n * try {\n * addressToScript(pasted, mainnet);\n * } catch (e) {\n * if (hasErrorCode(e, \"bad-checksum\")) showTypoHelp();\n * else if (hasErrorCode(e, \"wrong-network\")) showWrongNetworkHelp();\n * else throw e;\n * }\n * ```\n *\n * Codes are the stable part; messages are for humans and may be reworded.\n */\n\n/**\n * What went wrong, as a value rather than a sentence.\n *\n * Grouped by concern. New codes may be added in a minor release, so treat an\n * unrecognised one as a generic failure rather than assuming the set is closed.\n */\nexport type DcrErrorCode =\n // --- Encoding and parsing ---\n /** A character outside the base58 alphabet. */\n | \"invalid-base58\"\n /** base58check or WIF checksum did not match. Usually a typo. */\n | \"bad-checksum\"\n /** Input longer than the format allows; rejected before the quadratic decode. */\n | \"input-too-long\"\n /** A field or payload was not the required size. */\n | \"bad-length\"\n /** A varint that could have been encoded in fewer bytes (dcrd's ErrNonCanonicalVarInt). */\n | \"non-canonical-varint\"\n /** Ran off the end of the input while reading. */\n | \"unexpected-end\"\n /** Input parsed, but bytes remained after it. */\n | \"trailing-bytes\"\n\n // --- Keys ---\n /** Not a valid private scalar (zero, or out of range for the suite's group order). */\n | \"invalid-private-key\"\n /** Wrong length or prefix, or not a point on the curve. */\n | \"invalid-public-key\"\n\n // --- Addresses ---\n /** The two-byte version prefix belongs to no known network and kind. */\n | \"unknown-prefix\"\n /** Well-formed, but for a different network than the one required. */\n | \"wrong-network\"\n /** A signature-suite identifier this library does not support. */\n | \"unsupported-signature-type\"\n\n // --- HD keys ---\n /** Cannot derive a hardened child from a public key. */\n | \"hardened-from-public\"\n /** The derived child is invalid; retry the next index (BIP32 says this is ~2^-127). */\n | \"invalid-child\"\n /** Refused to derive past the depth a single byte can serialize. */\n | \"max-depth\"\n /** A derivation path that does not parse. */\n | \"invalid-path\"\n /** A private-key operation was asked of a public (neutered) key. */\n | \"not-a-private-key\"\n /** Extended-key version bytes matching no known network. */\n | \"unknown-version\"\n /** Mnemonic failed its checksum, or used a word outside the wordlist. */\n | \"invalid-mnemonic\"\n\n // --- Scripts and signing ---\n /** A script whose data pushes do not tokenize (dcrd's checkScriptParses). */\n | \"malformed-script\"\n /** A signature hash type dcrd would not accept, or one wider than a byte. */\n | \"invalid-hash-type\"\n /** A push above MaxScriptElementSize, which dcrd can never execute. */\n | \"element-too-large\"\n\n // --- Values ---\n /** A numeric argument outside its permitted range. */\n | \"out-of-range\"\n /** A numeric argument that was not an integer (includes NaN and Infinity). */\n | \"not-an-integer\"\n /** A malformed or unrepresentable amount. */\n | \"invalid-amount\"\n /** A required argument was missing or of the wrong shape. */\n | \"invalid-argument\";\n\n/**\n * Identity that survives duplicate copies of this package.\n *\n * A dual ESM+CJS build can be loaded twice in one process: Node's exports map\n * hands `import` the ESM bundle and `require` the CJS one, and bundlers land in\n * the same place resolving `module` for application code and `main` for a\n * CommonJS dependency. Each copy defines its own class, so `instanceof` is false\n * across them. A registry symbol is the same value in every copy, and in every\n * realm.\n */\nconst BRAND = Symbol.for(\"dcr-ts.DcrError\");\n\n/** Every error this library throws. */\nexport class DcrError extends Error {\n override readonly name = \"DcrError\";\n\n constructor(\n /** Stable, machine-readable. Branch on this, not on {@link message}. */\n readonly code: DcrErrorCode,\n message: string,\n options?: { cause?: unknown },\n ) {\n super(message, options);\n // Not a class field: keeping it off the declared shape keeps the two builds'\n // `.d.ts` types mutually assignable, and keeps it off `Object.keys`.\n Object.defineProperty(this, BRAND, { value: true });\n }\n}\n\n/**\n * True when `e` is a {@link DcrError}, including one thrown by another copy of\n * this package loaded into the same process.\n */\nexport function isDcrError(e: unknown): e is DcrError {\n return e instanceof DcrError || (typeof e === \"object\" && e !== null && BRAND in e);\n}\n\n/**\n * True when `e` is a {@link DcrError} with this code.\n *\n * Safe on an `unknown` from a `catch`, so it needs no type guard at the call site.\n */\nexport function hasErrorCode(e: unknown, code: DcrErrorCode): boolean {\n return isDcrError(e) && e.code === code;\n}\n\n/** Construct a {@link DcrError}, prefixing `message` with the operation name. */\nexport function err(code: DcrErrorCode, who: string, message: string): DcrError {\n return new DcrError(code, `${who}: ${message}`);\n}\n","/**\n * Little-endian byte reader/writer with Bitcoin/Decred \"compact size\" varints.\n *\n * All multi-byte integers in the Decred wire format are little-endian. Amounts\n * and a few counters are 64-bit, so those cross through `bigint`.\n */\nimport { err } from \"./errors.js\";\n\n/**\n * Copy `n` bytes out of `src` starting at `off`, always into a fresh buffer.\n *\n * Deliberately not `src.slice(off, off + n)`. `Uint8Array.prototype.slice`\n * copies, but Node's `Buffer` overrides it to return a *view* over the same\n * memory (deprecated, still the behaviour). Since `Buffer` is what\n * `fs.readFileSync`, `Buffer.from(hex, \"hex\")`, sockets and database drivers all\n * hand back, a `slice()` here would silently alias the caller's memory for the\n * most common input type: reusing or zeroing that buffer afterwards would mutate\n * an already-parsed transaction or key.\n */\nexport function copyOf(src: Uint8Array, off: number, n: number): Uint8Array {\n // Validated because this is exported: `subarray` clamps, so an out-of-range\n // read would silently return a short-then-zero-padded buffer rather than fail,\n // and a negative offset would read from the wrong place.\n if (!Number.isInteger(off) || !Number.isInteger(n) || off < 0 || n < 0) {\n throw err(\n \"not-an-integer\",\n \"copyOf\",\n `offset and length must be non-negative integers, got ${shown(off)}, ${shown(n)}`,\n );\n }\n if (off + n > src.length) {\n throw err(\n \"out-of-range\",\n \"copyOf\",\n `reading ${n} bytes at ${off} overruns a ${src.length}-byte source`,\n );\n }\n const out = new Uint8Array(n);\n out.set(src.subarray(off, off + n));\n return out;\n}\n\n/**\n * True when `v` is really a byte array.\n *\n * `length` is not enough on its own: a 32-*character* string satisfies\n * `v.length === 32`, and so does a 32-element `Array<number>` or `Int8Array`.\n * Anything that then reads the value byte by byte gets a number that is not the\n * key, hash or scalar the caller meant — a wrong answer rather than a failure.\n *\n * Tag-based rather than `instanceof`, for the same reason {@link DcrError} is\n * branded with a registry symbol: `instanceof Uint8Array` is false for a typed\n * array from another realm (a `vm` context, an iframe, a worker boundary). The\n * tag is `\"[object Uint8Array]\"` in every realm, and for a Node `Buffer`, which\n * is a `Uint8Array` subclass and must keep working.\n */\nexport function isBytes(v: unknown): v is Uint8Array {\n return Object.prototype.toString.call(v) === \"[object Uint8Array]\";\n}\n\n/**\n * Name a rejected argument in an error message, without interpolating its value.\n *\n * Lives here rather than in `keys.ts` because every foreign boundary in the\n * library needs it, `isBytes` is its usual companion, and `bytes.ts` is the one\n * module low enough in the import graph for all of them to reach.\n */\nexport function typeName(v: unknown): string {\n return Object.prototype.toString.call(v).slice(8, -1).toLowerCase();\n}\n\n/** Longest run of a caller's own text repeated back in an error message. */\nconst MAX_SHOWN_LENGTH = 32;\n\n/**\n * Render a rejected argument for an error message without letting the argument\n * decide what the message says.\n *\n * Plain `${v}` has two problems on a validation path, and both only show up for\n * the values that fail. It calls the argument's own `toString`, so an object can\n * write anything it likes into the message — newlines that split a log line in\n * two, an ESC that starts a terminal escape sequence, a megabyte of text. And\n * a string argument is echoed verbatim, so a pasted address carrying a control\n * character carries it straight through. Neither is a break in this library,\n * which logs nothing, but the message is the one thing here that routinely ends\n * up in someone else's log file or UI.\n *\n * So: numbers and the other primitives render as themselves, strings are quoted\n * with control characters escaped and long ones clipped, and anything else is\n * named by type rather than asked what it would like to say.\n */\nexport function shown(v: unknown): string {\n if (typeof v === \"string\") {\n const head = v.length > MAX_SHOWN_LENGTH ? v.slice(0, MAX_SHOWN_LENGTH) : v;\n let out = \"\";\n for (const ch of head) {\n const c = ch.codePointAt(0)!;\n out += c < 0x20 || c === 0x7f ? `\\\\u${c.toString(16).padStart(4, \"0\")}` : ch;\n }\n const clipped = v.length > MAX_SHOWN_LENGTH ? `… (${v.length} characters)` : \"\";\n return `\"${out}\"${clipped}`;\n }\n // Numbers keep rendering exactly as they did, so no message with a length or\n // an index in it moves.\n if (\n typeof v === \"number\" ||\n typeof v === \"bigint\" ||\n typeof v === \"boolean\" ||\n v === null ||\n v === undefined\n ) {\n return String(v);\n }\n return typeName(v);\n}\n\n/** Reject a value that would be silently truncated by a fixed-width write. */\nfunction checkUint(v: number, bits: number, who: string): void {\n // Without this, `v & 0xff` quietly turns NaN into 0, -1 into 255 and 2**32\n // into 0 — writing a wire field the caller never asked for.\n if (!Number.isInteger(v) || v < 0 || v > (bits === 32 ? 0xffffffff : (1 << bits) - 1)) {\n throw err(\n Number.isInteger(v) ? \"out-of-range\" : \"not-an-integer\",\n `Writer.${who}`,\n `expected an integer in 0..2^${bits}-1, got ${shown(v)}`,\n );\n }\n}\n\n/** Growable little-endian byte writer. */\nexport class Writer {\n private buf = new Uint8Array(256);\n private view = new DataView(this.buf.buffer);\n private len = 0;\n\n private ensure(extra: number): void {\n if (this.len + extra <= this.buf.length) return;\n let cap = this.buf.length * 2;\n while (cap < this.len + extra) cap *= 2;\n const next = new Uint8Array(cap);\n next.set(this.buf.subarray(0, this.len));\n this.buf = next;\n this.view = new DataView(next.buffer);\n }\n\n u8(v: number): this {\n checkUint(v, 8, \"u8\");\n this.ensure(1);\n this.buf[this.len++] = v;\n return this;\n }\n\n u16(v: number): this {\n checkUint(v, 16, \"u16\");\n this.ensure(2);\n this.view.setUint16(this.len, v, true);\n this.len += 2;\n return this;\n }\n\n u32(v: number): this {\n checkUint(v, 32, \"u32\");\n this.ensure(4);\n this.view.setUint32(this.len, v, true);\n this.len += 4;\n return this;\n }\n\n // The 64-bit paths go through DataView rather than eight BigInt shift/mask\n // steps. Every input amount and output value in a transaction crosses one of\n // these, and the loop version measured ~33x slower on the primitive.\n u64(v: bigint): this {\n if (v < 0n || v > 0xffffffffffffffffn) throw err(\"out-of-range\", \"Writer.u64\", \"value must fit in an unsigned 64-bit integer\");\n this.ensure(8);\n this.view.setBigUint64(this.len, v, true);\n this.len += 8;\n return this;\n }\n\n /** Signed 64-bit little-endian (two's complement). Used for atom amounts. */\n i64(v: bigint): this {\n if (v < -(1n << 63n) || v >= 1n << 63n) throw err(\"out-of-range\", \"Writer.i64\", \"value must fit in a signed 64-bit integer\");\n this.ensure(8);\n this.view.setBigInt64(this.len, v, true);\n this.len += 8;\n return this;\n }\n\n bytes(b: Uint8Array): this {\n this.ensure(b.length);\n this.buf.set(b, this.len);\n this.len += b.length;\n return this;\n }\n\n /** Compact-size varint. */\n varInt(v: number | bigint): this {\n // The number path deliberately repeats the ladder below rather than\n // converting into it. `BigInt(v)` is a heap allocation on every call — V8\n // has no immediate representation for BigInt — and the call count is\n // superlinear where it matters: a prefix costs two plus one per output, but\n // the witness half writes one per input on *every* call, so signing N inputs\n // walks it N(N+1) times.\n //\n // Measured against the previous implementation, writing N counters: 34 ns\n // -> 10 ns per call at N=250, 43 ns -> 23 ns at N=1000 (2-3.5x). End to end\n // the gain is far smaller and this does not change the exponent — ECDSA\n // still dominates signing, as the 1.7x figure in README.md records — but it\n // was the last unmeasured allocation left on the serialize path after\n // fae12d0.\n if (typeof v === \"number\") {\n // Checked before any conversion, not after: `BigInt(1.5)`, `BigInt(NaN)`\n // and `BigInt(Infinity)` throw a bare `RangeError` from the engine, which\n // would escape the typed-error contract every other path in this class\n // honours.\n if (!Number.isInteger(v)) {\n throw err(\"not-an-integer\", \"Writer.varInt\", `expected an integer, got ${v}`);\n }\n if (v < 0) throw err(\"out-of-range\", \"Writer.varInt\", \"value must not be negative\");\n if (v < 0xfd) return this.u8(v);\n if (v <= 0xffff) return this.u8(0xfd).u16(v);\n if (v <= 0xffffffff) return this.u8(0xfe).u32(v);\n // Past 2^32 it is a u64 field, and `Writer.u64` is what rejects a number\n // too large to be one — so this converts and lets that check stand rather\n // than duplicating its bound here.\n return this.u8(0xff).u64(BigInt(v));\n }\n // Anything that is not a number and not a bigint is rejected here rather\n // than fed to the ladder below. Letting it through would not merely change\n // which error surfaced: relational comparison coerces by its own rules, so\n // `null < 0n` is false and `null < 0xfdn` is true, and `varInt(null)` would\n // quietly write a `0x00` length prefix instead of failing.\n if (typeof v !== \"bigint\") {\n throw err(\"not-an-integer\", \"Writer.varInt\", `expected an integer, got ${typeName(v)}`);\n }\n const n: bigint = v;\n if (n < 0n) throw err(\"out-of-range\", \"Writer.varInt\", \"value must not be negative\");\n if (n < 0xfdn) return this.u8(Number(n));\n if (n <= 0xffffn) return this.u8(0xfd).u16(Number(n));\n if (n <= 0xffffffffn) return this.u8(0xfe).u32(Number(n));\n return this.u8(0xff).u64(n);\n }\n\n /** A varint length prefix followed by the bytes themselves. */\n varBytes(b: Uint8Array): this {\n return this.varInt(b.length).bytes(b);\n }\n\n finish(): Uint8Array {\n return this.buf.slice(0, this.len);\n }\n}\n\n/** Little-endian byte reader. */\nexport class Reader {\n private off = 0;\n private readonly view: DataView;\n constructor(private readonly data: Uint8Array) {\n // Honour byteOffset/byteLength so a subarray-backed input reads correctly.\n this.view = new DataView(data.buffer, data.byteOffset, data.byteLength);\n }\n\n get offset(): number {\n return this.off;\n }\n\n get remaining(): number {\n return this.data.length - this.off;\n }\n\n private need(n: number): void {\n if (this.off + n > this.data.length) throw err(\"unexpected-end\", \"Reader\", `wanted ${n} more byte(s), ${this.data.length - this.off} remain`);\n }\n\n u8(): number {\n this.need(1);\n return this.data[this.off++]!;\n }\n\n u16(): number {\n this.need(2);\n const v = this.data[this.off]! | (this.data[this.off + 1]! << 8);\n this.off += 2;\n return v >>> 0;\n }\n\n u32(): number {\n this.need(4);\n const v =\n (this.data[this.off]! |\n (this.data[this.off + 1]! << 8) |\n (this.data[this.off + 2]! << 16) |\n (this.data[this.off + 3]! << 24)) >>>\n 0;\n this.off += 4;\n return v;\n }\n\n u64(): bigint {\n this.need(8);\n const v = this.view.getBigUint64(this.off, true);\n this.off += 8;\n return v;\n }\n\n /** Signed 64-bit little-endian (two's complement). */\n i64(): bigint {\n this.need(8);\n const v = this.view.getBigInt64(this.off, true);\n this.off += 8;\n return v;\n }\n\n bytes(n: number): Uint8Array {\n // A negative or fractional length would slip past `need` (which only checks\n // the upper bound), read nothing, and then rewind the offset.\n if (!Number.isInteger(n) || n < 0) throw err(Number.isInteger(n) ? \"out-of-range\" : \"not-an-integer\", \"Reader.bytes\", `bad length ${n}`);\n this.need(n);\n const out = copyOf(this.data, this.off, n);\n this.off += n;\n return out;\n }\n\n /**\n * Compact-size varint. Rejects non-canonical encodings (a value that could\n * have been encoded in fewer bytes), matching dcrd's `ErrNonCanonicalVarInt`.\n * Without this check two distinct byte strings could parse to the same\n * transaction while hashing to different ids.\n */\n varInt(): number {\n const first = this.u8();\n if (first < 0xfd) return first;\n if (first === 0xfd) {\n const v = this.u16();\n if (v < 0xfd) throw err(\"non-canonical-varint\", \"Reader.varInt\", \"value could have been encoded in fewer bytes\");\n return v;\n }\n if (first === 0xfe) {\n const v = this.u32();\n if (v < 0x10000) throw err(\"non-canonical-varint\", \"Reader.varInt\", \"value could have been encoded in fewer bytes\");\n return v;\n }\n const big = this.u64();\n if (big < 0x100000000n) throw err(\"non-canonical-varint\", \"Reader.varInt\", \"value could have been encoded in fewer bytes\");\n if (big > BigInt(Number.MAX_SAFE_INTEGER)) throw err(\"out-of-range\", \"Reader.varInt\", \"value exceeds Number.MAX_SAFE_INTEGER\");\n return Number(big);\n }\n\n varBytes(): Uint8Array {\n return this.bytes(this.varInt());\n }\n}\n","/**\n * BLAKE-256 — the 14-round SHA-3 finalist (Aumasson, Henzen, Meier, Phan).\n *\n * This is the hash Decred uses *everywhere*: transaction and block hashes,\n * signature hashes, address hashes, and base58 checksums. It is **not** BLAKE2\n * or BLAKE3; those are entirely different constructions. No mainstream JS hash\n * package shipped the original BLAKE for years, so it is implemented here from\n * the specification and pinned by known-answer vectors generated from dcrd's own\n * `crypto/blake256` package.\n *\n * Reference: \"SHA-3 proposal BLAKE\" (version 1.3), section 2.\n */\nimport { err } from \"./errors.js\";\nimport { isBytes, typeName } from \"./bytes.js\";\n\n// SHA-256 initialization vector (BLAKE-256 shares it).\nconst IV = Uint32Array.of(\n 0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a, 0x510e527f, 0x9b05688c,\n 0x1f83d9ab, 0x5be0cd19,\n);\n\n// The 16 constants: the first 512 bits of the fractional part of pi.\nconst C = Uint32Array.of(\n 0x243f6a88, 0x85a308d3, 0x13198a2e, 0x03707344, 0xa4093822, 0x299f31d0,\n 0x082efa98, 0xec4e6c89, 0x452821e6, 0x38d01377, 0xbe5466cf, 0x34e90c6c,\n 0xc0ac29b7, 0xc97c50dd, 0x3f84d5b5, 0xb5470917,\n);\n\n// The 10 message-permutation rows (SIGMA). BLAKE-256 runs 14 rounds, reusing\n// the rows modulo 10.\n// prettier-ignore\nconst SIGMA = Uint8Array.of(\n 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,10,11,12,13,14,15,\n 14,10, 4, 8, 9,15,13, 6, 1,12, 0, 2,11, 7, 5, 3,\n 11, 8,12, 0, 5, 2,15,13,10,14, 3, 6, 7, 1, 9, 4,\n 7, 9, 3, 1,13,12,11,14, 2, 6, 5,10, 4, 0,15, 8,\n 9, 0, 5, 7, 2, 4,10,15,14, 1,11,12, 6, 8, 3,13,\n 2,12, 6,10, 0,11, 8, 3, 4,13, 7, 5,15,14, 1, 9,\n 12, 5, 1,15,14,13, 4,10, 0, 7, 6, 3, 9, 2, 8,11,\n 13,11, 7,14,12, 1, 3, 9, 5, 0,15, 4, 8, 6, 2,10,\n 6,15,14, 9,11, 3, 0, 8,12, 2,13, 7, 1, 4,10, 5,\n 10, 2, 8, 4, 7, 6, 1, 5,15,11, 9,14, 3,12,13, 0,\n);\n\nconst ROUNDS = 14;\n\n/** The BLAKE-256 digest length in bytes. */\nexport const BLAKE256_DIGEST_LENGTH = 32;\n/** The BLAKE-256 block length in bytes. */\nexport const BLAKE256_BLOCK_LENGTH = 64;\n\n// Scratch buffers reused across the whole module (single-threaded JS).\nconst V = new Uint32Array(16);\nconst M = new Uint32Array(16);\n\n/**\n * The BLAKE-256 compression function. `nullt` selects the \"no counter\" mode\n * used for a padding-only final block, matching the reference implementation's\n * behaviour where a block that carries no message bits is fed a zero counter.\n */\nfunction compress(\n h: Uint32Array,\n block: Uint8Array,\n offset: number,\n t0: number,\n t1: number,\n nullt: boolean,\n): void {\n for (let i = 0; i < 16; i++) {\n const j = offset + i * 4;\n M[i] =\n (((block[j]! << 24) |\n (block[j + 1]! << 16) |\n (block[j + 2]! << 8) |\n block[j + 3]!) >>>\n 0);\n }\n\n V[0] = h[0]!; V[1] = h[1]!; V[2] = h[2]!; V[3] = h[3]!;\n V[4] = h[4]!; V[5] = h[5]!; V[6] = h[6]!; V[7] = h[7]!;\n // Salt is always zero here, so v[8..11] reduce to the constants.\n V[8] = C[0]!; V[9] = C[1]!; V[10] = C[2]!; V[11] = C[3]!;\n V[12] = C[4]!; V[13] = C[5]!; V[14] = C[6]!; V[15] = C[7]!;\n if (!nullt) {\n V[12] ^= t0; V[13] ^= t0; V[14] ^= t1; V[15] ^= t1;\n }\n\n // The G mixing function, inlined across all eight columns.\n //\n // This was a `g(a, b, c, d, sBase, e)` helper, which reads far better. It is\n // written out because the call overhead dominates: G runs 8 times per round and\n // 14 rounds per 64-byte block, so 112 calls per block with six arguments each.\n // Inlining it measured 2.09x end-to-end throughput on this machine (97 -> 204\n // MiB/s over 8 MiB) with a byte-identical digest, and BLAKE-256 backs every\n // txid, signature hash, address hash and base58 checksum in the library.\n //\n // The bodies are mechanically identical; only the V indices and the SIGMA\n // column offset differ. Verified against dcrd's known-answer vectors at every\n // padding boundary and differentially against @noble/hashes over lengths 0..300.\n let p: number, s0: number, s1: number;\n let va: number, vb: number, vc: number, vd: number, t: number;\n for (let r = 0; r < ROUNDS; r++) {\n const s = (r % 10) * 16;\n\n // column 0: V[0] V[4] V[8] V[12]\n p = s + 0;\n s0 = SIGMA[p]!;\n s1 = SIGMA[p + 1]!;\n va = V[0]!; vb = V[4]!; vc = V[8]!; vd = V[12]!;\n va = (va + vb + ((M[s0]! ^ C[s1]!) >>> 0)) >>> 0;\n t = vd ^ va; vd = (t >>> 16) | (t << 16);\n vc = (vc + vd) >>> 0;\n t = vb ^ vc; vb = (t >>> 12) | (t << 20);\n va = (va + vb + ((M[s1]! ^ C[s0]!) >>> 0)) >>> 0;\n t = vd ^ va; vd = (t >>> 8) | (t << 24);\n vc = (vc + vd) >>> 0;\n t = vb ^ vc; vb = (t >>> 7) | (t << 25);\n V[0] = va; V[4] = vb; V[8] = vc; V[12] = vd;\n\n // column 1: V[1] V[5] V[9] V[13]\n p = s + 2;\n s0 = SIGMA[p]!;\n s1 = SIGMA[p + 1]!;\n va = V[1]!; vb = V[5]!; vc = V[9]!; vd = V[13]!;\n va = (va + vb + ((M[s0]! ^ C[s1]!) >>> 0)) >>> 0;\n t = vd ^ va; vd = (t >>> 16) | (t << 16);\n vc = (vc + vd) >>> 0;\n t = vb ^ vc; vb = (t >>> 12) | (t << 20);\n va = (va + vb + ((M[s1]! ^ C[s0]!) >>> 0)) >>> 0;\n t = vd ^ va; vd = (t >>> 8) | (t << 24);\n vc = (vc + vd) >>> 0;\n t = vb ^ vc; vb = (t >>> 7) | (t << 25);\n V[1] = va; V[5] = vb; V[9] = vc; V[13] = vd;\n\n // column 2: V[2] V[6] V[10] V[14]\n p = s + 4;\n s0 = SIGMA[p]!;\n s1 = SIGMA[p + 1]!;\n va = V[2]!; vb = V[6]!; vc = V[10]!; vd = V[14]!;\n va = (va + vb + ((M[s0]! ^ C[s1]!) >>> 0)) >>> 0;\n t = vd ^ va; vd = (t >>> 16) | (t << 16);\n vc = (vc + vd) >>> 0;\n t = vb ^ vc; vb = (t >>> 12) | (t << 20);\n va = (va + vb + ((M[s1]! ^ C[s0]!) >>> 0)) >>> 0;\n t = vd ^ va; vd = (t >>> 8) | (t << 24);\n vc = (vc + vd) >>> 0;\n t = vb ^ vc; vb = (t >>> 7) | (t << 25);\n V[2] = va; V[6] = vb; V[10] = vc; V[14] = vd;\n\n // column 3: V[3] V[7] V[11] V[15]\n p = s + 6;\n s0 = SIGMA[p]!;\n s1 = SIGMA[p + 1]!;\n va = V[3]!; vb = V[7]!; vc = V[11]!; vd = V[15]!;\n va = (va + vb + ((M[s0]! ^ C[s1]!) >>> 0)) >>> 0;\n t = vd ^ va; vd = (t >>> 16) | (t << 16);\n vc = (vc + vd) >>> 0;\n t = vb ^ vc; vb = (t >>> 12) | (t << 20);\n va = (va + vb + ((M[s1]! ^ C[s0]!) >>> 0)) >>> 0;\n t = vd ^ va; vd = (t >>> 8) | (t << 24);\n vc = (vc + vd) >>> 0;\n t = vb ^ vc; vb = (t >>> 7) | (t << 25);\n V[3] = va; V[7] = vb; V[11] = vc; V[15] = vd;\n\n // column 4: V[0] V[5] V[10] V[15]\n p = s + 8;\n s0 = SIGMA[p]!;\n s1 = SIGMA[p + 1]!;\n va = V[0]!; vb = V[5]!; vc = V[10]!; vd = V[15]!;\n va = (va + vb + ((M[s0]! ^ C[s1]!) >>> 0)) >>> 0;\n t = vd ^ va; vd = (t >>> 16) | (t << 16);\n vc = (vc + vd) >>> 0;\n t = vb ^ vc; vb = (t >>> 12) | (t << 20);\n va = (va + vb + ((M[s1]! ^ C[s0]!) >>> 0)) >>> 0;\n t = vd ^ va; vd = (t >>> 8) | (t << 24);\n vc = (vc + vd) >>> 0;\n t = vb ^ vc; vb = (t >>> 7) | (t << 25);\n V[0] = va; V[5] = vb; V[10] = vc; V[15] = vd;\n\n // column 5: V[1] V[6] V[11] V[12]\n p = s + 10;\n s0 = SIGMA[p]!;\n s1 = SIGMA[p + 1]!;\n va = V[1]!; vb = V[6]!; vc = V[11]!; vd = V[12]!;\n va = (va + vb + ((M[s0]! ^ C[s1]!) >>> 0)) >>> 0;\n t = vd ^ va; vd = (t >>> 16) | (t << 16);\n vc = (vc + vd) >>> 0;\n t = vb ^ vc; vb = (t >>> 12) | (t << 20);\n va = (va + vb + ((M[s1]! ^ C[s0]!) >>> 0)) >>> 0;\n t = vd ^ va; vd = (t >>> 8) | (t << 24);\n vc = (vc + vd) >>> 0;\n t = vb ^ vc; vb = (t >>> 7) | (t << 25);\n V[1] = va; V[6] = vb; V[11] = vc; V[12] = vd;\n\n // column 6: V[2] V[7] V[8] V[13]\n p = s + 12;\n s0 = SIGMA[p]!;\n s1 = SIGMA[p + 1]!;\n va = V[2]!; vb = V[7]!; vc = V[8]!; vd = V[13]!;\n va = (va + vb + ((M[s0]! ^ C[s1]!) >>> 0)) >>> 0;\n t = vd ^ va; vd = (t >>> 16) | (t << 16);\n vc = (vc + vd) >>> 0;\n t = vb ^ vc; vb = (t >>> 12) | (t << 20);\n va = (va + vb + ((M[s1]! ^ C[s0]!) >>> 0)) >>> 0;\n t = vd ^ va; vd = (t >>> 8) | (t << 24);\n vc = (vc + vd) >>> 0;\n t = vb ^ vc; vb = (t >>> 7) | (t << 25);\n V[2] = va; V[7] = vb; V[8] = vc; V[13] = vd;\n\n // column 7: V[3] V[4] V[9] V[14]\n p = s + 14;\n s0 = SIGMA[p]!;\n s1 = SIGMA[p + 1]!;\n va = V[3]!; vb = V[4]!; vc = V[9]!; vd = V[14]!;\n va = (va + vb + ((M[s0]! ^ C[s1]!) >>> 0)) >>> 0;\n t = vd ^ va; vd = (t >>> 16) | (t << 16);\n vc = (vc + vd) >>> 0;\n t = vb ^ vc; vb = (t >>> 12) | (t << 20);\n va = (va + vb + ((M[s1]! ^ C[s0]!) >>> 0)) >>> 0;\n t = vd ^ va; vd = (t >>> 8) | (t << 24);\n vc = (vc + vd) >>> 0;\n t = vb ^ vc; vb = (t >>> 7) | (t << 25);\n V[3] = va; V[4] = vb; V[9] = vc; V[14] = vd;\n }\n\n for (let i = 0; i < 8; i++) {\n h[i] = (h[i]! ^ V[i]! ^ V[i + 8]!) >>> 0;\n }\n}\n\n/** Incremental BLAKE-256 hasher. */\nexport class Blake256 {\n private readonly h = IV.slice();\n private readonly buf = new Uint8Array(BLAKE256_BLOCK_LENGTH);\n private buflen = 0;\n /** Total message bytes fed in (used for the final length encoding). */\n private total = 0;\n /** Message bytes already absorbed by the compression function. */\n private compressed = 0;\n private finished = false;\n\n update(data: Uint8Array): this {\n if (this.finished) throw err(\"invalid-argument\", \"Blake256\", \"update after digest\");\n // The single choke point for `blake256`, `hash256` and `hash160`: guarding\n // here types the failure for all three. Without it, `subarray` on a\n // non-array throws a bare TypeError out of the hashing primitive every\n // address and txid goes through.\n if (!isBytes(data)) {\n throw err(\"invalid-argument\", \"Blake256\", `data must be a Uint8Array, got ${typeName(data)}`);\n }\n let i = 0;\n const n = data.length;\n this.total += n;\n\n // Top up a partially-filled buffer first.\n if (this.buflen > 0) {\n const need = BLAKE256_BLOCK_LENGTH - this.buflen;\n const take = Math.min(need, n);\n this.buf.set(data.subarray(0, take), this.buflen);\n this.buflen += take;\n i = take;\n if (this.buflen === BLAKE256_BLOCK_LENGTH) {\n this.compressed += BLAKE256_BLOCK_LENGTH;\n compress(this.h, this.buf, 0, lo32(this.compressed), hi32(this.compressed), false);\n this.buflen = 0;\n }\n }\n\n // Absorb whole blocks straight from the input.\n while (n - i >= BLAKE256_BLOCK_LENGTH) {\n this.compressed += BLAKE256_BLOCK_LENGTH;\n compress(this.h, data, i, lo32(this.compressed), hi32(this.compressed), false);\n i += BLAKE256_BLOCK_LENGTH;\n }\n\n // Stash the remainder.\n if (i < n) {\n this.buf.set(data.subarray(i), this.buflen);\n this.buflen += n - i;\n }\n return this;\n }\n\n digest(): Uint8Array {\n if (this.finished) throw err(\"invalid-argument\", \"Blake256\", \"digest called twice\");\n this.finished = true;\n\n const rem = this.buflen;\n const block = new Uint8Array(BLAKE256_BLOCK_LENGTH);\n block.set(this.buf.subarray(0, rem));\n\n if (rem <= 55) {\n // Everything fits in one final block.\n block[rem] = 0x80; // padding start ('1' bit)\n block[55]! |= 0x01; // BLAKE-256 domain bit (merges to 0x81 when rem === 55)\n writeLen(block, this.total);\n // A block with no message bytes carries a zero counter (nullt).\n if (rem === 0) compress(this.h, block, 0, 0, 0, true);\n else compress(this.h, block, 0, lo32(this.total), hi32(this.total), false);\n } else {\n // Not enough room for the length: emit a data block then a padding block.\n block[rem] = 0x80;\n compress(this.h, block, 0, lo32(this.total), hi32(this.total), false);\n const tail = new Uint8Array(BLAKE256_BLOCK_LENGTH);\n tail[55] = 0x01;\n writeLen(tail, this.total);\n compress(this.h, tail, 0, 0, 0, true);\n }\n\n const out = new Uint8Array(BLAKE256_DIGEST_LENGTH);\n for (let i = 0; i < 8; i++) {\n const v = this.h[i]!;\n out[i * 4] = (v >>> 24) & 0xff;\n out[i * 4 + 1] = (v >>> 16) & 0xff;\n out[i * 4 + 2] = (v >>> 8) & 0xff;\n out[i * 4 + 3] = v & 0xff;\n }\n return out;\n }\n}\n\n/**\n * The BLAKE counter is a 64-bit *bit* count, split into two 32-bit halves.\n *\n * These take a **byte** count and derive the halves with plain number\n * arithmetic. The previous version built a BigInt per 64-byte block, which cost\n * roughly 11% of throughput on long inputs for no benefit: a byte count stays\n * exact in a double up to 2^53, so `bytes * 8` is exact up to 2^50 bytes — a\n * pebibyte, far past any message this will see. `>>> 0` is ToUint32, i.e. modulo\n * 2^32 of an exact integer, so the low half is exact too.\n */\nfunction lo32(bytes: number): number {\n return (bytes * 8) >>> 0;\n}\nfunction hi32(bytes: number): number {\n return Math.floor((bytes * 8) / 0x100000000) >>> 0;\n}\nfunction writeLen(block: Uint8Array, totalBytes: number): void {\n const h = hi32(totalBytes);\n const l = lo32(totalBytes);\n block[56] = (h >>> 24) & 0xff;\n block[57] = (h >>> 16) & 0xff;\n block[58] = (h >>> 8) & 0xff;\n block[59] = h & 0xff;\n block[60] = (l >>> 24) & 0xff;\n block[61] = (l >>> 16) & 0xff;\n block[62] = (l >>> 8) & 0xff;\n block[63] = l & 0xff;\n}\n\n/** One-shot BLAKE-256. Returns the 32-byte digest. */\nexport function blake256(data: Uint8Array): Uint8Array {\n return new Blake256().update(data).digest();\n}\n","/**\n * Decred hashing helpers built on {@link blake256}.\n *\n * Decred replaced Bitcoin's double-SHA-256 with BLAKE-256 across the protocol:\n *\n * - `hash256` (double BLAKE-256) — the checksum used by base58check and the\n * extended-key serialization.\n * - `hash160` — RIPEMD-160 of a single BLAKE-256, used for pubkey/script hashes\n * in addresses.\n *\n * Single-BLAKE-256 (used directly for txids, block hashes and signature hashes)\n * is just {@link blake256}.\n */\nimport { ripemd160 } from \"@noble/hashes/ripemd160\";\nimport { blake256 } from \"./blake256.js\";\n\nexport { blake256, Blake256 } from \"./blake256.js\";\n\n/** Double BLAKE-256: `blake256(blake256(data))`. */\nexport function hash256(data: Uint8Array): Uint8Array {\n return blake256(blake256(data));\n}\n\n/** RIPEMD-160 of BLAKE-256: `ripemd160(blake256(data))`. The address hash. */\nexport function hash160(data: Uint8Array): Uint8Array {\n return ripemd160(blake256(data));\n}\n","/**\n * Base58 and Decred's base58check.\n *\n * The alphabet is the standard Bitcoin one, but the check variant differs in a\n * consensus-critical way: the 4-byte checksum is the first four bytes of the\n * **double BLAKE-256** of the payload, not double SHA-256. Everything encoded\n * for humans on Decred — addresses, WIF private keys and `dprv`/`dpub` extended\n * keys — rides on {@link checkEncode}.\n */\nimport { err } from \"./errors.js\";\nimport { hash256 } from \"./hash.js\";\nimport { shown } from \"./bytes.js\";\n\nconst ALPHABET = \"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz\";\nconst BASE = 58n;\n\n// Reverse lookup: char code -> value, or 255 for invalid.\nconst INDEX = new Uint8Array(128).fill(255);\nfor (let i = 0; i < ALPHABET.length; i++) {\n INDEX[ALPHABET.charCodeAt(i)] = i;\n}\n\n/** Encode raw bytes as base58 (no checksum). */\nexport function base58Encode(bytes: Uint8Array): string {\n // Preserve leading zero bytes as leading '1's.\n let zeros = 0;\n while (zeros < bytes.length && bytes[zeros] === 0) zeros++;\n\n let num = 0n;\n for (const b of bytes) num = num * 256n + BigInt(b);\n\n let out = \"\";\n while (num > 0n) {\n const rem = num % BASE;\n num = num / BASE;\n out = ALPHABET[Number(rem)] + out;\n }\n return \"1\".repeat(zeros) + out;\n}\n\n/**\n * Longest base58 string that can decode to `decodedLen` bytes.\n *\n * base58 expands by at most log_58(256) ≈ 1.37 bytes of output per input byte,\n * which is how dcrd derives its own bounds (`stdaddr.DecodeAddressV0`'s\n * `maxV0AddrLen`, `hdkeychain.NewKeyFromString`'s `maxKeyLen`). Callers must cap\n * untrusted input *before* decoding: {@link base58Decode} accumulates one BigInt\n * digit at a time and is therefore quadratic, so an unbounded string is a cheap\n * way to stall the event loop.\n */\nexport function maxBase58Length(decodedLen: number): number {\n return Math.floor((decodedLen * 137) / 100) + 1;\n}\n\n/**\n * Decode a base58 string to raw bytes. Throws on invalid characters.\n *\n * Cost is **quadratic** in the length of `str`. There is deliberately no length\n * cap here, because the function is general-purpose; every decoder in this\n * library bounds its input first via {@link maxBase58Length}, and anything\n * calling this directly on untrusted input must do the same.\n */\nexport function base58Decode(str: string): Uint8Array {\n let zeros = 0;\n while (zeros < str.length && str[zeros] === \"1\") zeros++;\n\n let num = 0n;\n for (let i = 0; i < str.length; i++) {\n const code = str.charCodeAt(i);\n const val = code < 128 ? INDEX[code]! : 255;\n // `shown` rather than the raw character: this is the everyday\n // paste-an-address path, so the offending code unit is attacker-chosen by\n // definition, and a newline or an ESC embedded verbatim in the message\n // splits a log line or starts a terminal escape sequence in whatever renders\n // it. Escaped, it still says exactly which character it was.\n if (val === 255) throw err(\"invalid-base58\", \"base58Decode\", `invalid character ${shown(str[i])} at index ${i}`);\n num = num * BASE + BigInt(val);\n }\n\n // Convert the big integer back to bytes (big-endian).\n const tail: number[] = [];\n while (num > 0n) {\n tail.push(Number(num % 256n));\n num = num / 256n;\n }\n tail.reverse();\n\n const out = new Uint8Array(zeros + tail.length);\n out.set(tail, zeros);\n return out;\n}\n\n/** base58check-encode: append the 4-byte double-BLAKE-256 checksum. */\nexport function checkEncode(data: Uint8Array): string {\n const checksum = hash256(data).subarray(0, 4);\n const full = new Uint8Array(data.length + 4);\n full.set(data);\n full.set(checksum, data.length);\n return base58Encode(full);\n}\n\n/**\n * base58check-decode and verify the checksum, returning the payload without the\n * trailing 4 checksum bytes. Throws if the checksum does not match.\n *\n * Inherits {@link base58Decode}'s **quadratic** cost and its lack of a length\n * cap, and the checksum does not change that: the whole string is decoded before\n * there is anything to check. Cap untrusted input with {@link maxBase58Length}\n * first, exactly as `decodeAddress`, `decodeWif` and `ExtendedKey.fromString`\n * do before they call this — the bound is in each of those callers, not in here.\n */\nexport function checkDecode(str: string): Uint8Array {\n const full = base58Decode(str);\n if (full.length < 4) throw err(\"bad-length\", \"base58check\", \"input is shorter than the 4-byte checksum\");\n const data = full.subarray(0, full.length - 4);\n const checksum = full.subarray(full.length - 4);\n const expected = hash256(data).subarray(0, 4);\n for (let i = 0; i < 4; i++) {\n if (checksum[i] !== expected[i]) throw err(\"bad-checksum\", \"base58check\", \"checksum does not match\");\n }\n return data.slice();\n}\n","/**\n * Decred network parameters.\n *\n * The magic prefix bytes, private-key IDs, extended-key version bytes and coin\n * types are taken verbatim from dcrd's `chaincfg` package for the four\n * networks. They are what make an address human-readable as `Ds…`/`Ts…`/`Ss…`\n * and what bind a key to a specific network.\n */\n\n/** Two-byte address version prefixes and related per-network identifiers. */\nexport interface Network {\n /** Human name, e.g. \"mainnet\". */\n readonly name: string;\n /** Network magic (wire protocol identifier). */\n readonly net: number;\n /** Leading character(s) of every address on this network (informational). */\n readonly addressPrefix: string;\n /** Version prefix for pay-to-pubkey (secp256k1 ECDSA) addresses. */\n readonly pubKeyAddrId: readonly [number, number];\n /** Version prefix for pay-to-pubkey-hash (secp256k1 ECDSA) addresses. */\n readonly pubKeyHashAddrId: readonly [number, number];\n /** Version prefix for pay-to-pubkey-hash (Ed25519) addresses. */\n readonly pubKeyHashEdwardsAddrId: readonly [number, number];\n /** Version prefix for pay-to-pubkey-hash (secp256k1 Schnorr) addresses. */\n readonly pubKeyHashSchnorrAddrId: readonly [number, number];\n /** Version prefix for pay-to-script-hash addresses. */\n readonly scriptHashAddrId: readonly [number, number];\n /** Version prefix for WIF private keys. */\n readonly privateKeyId: readonly [number, number];\n /** BIP32 extended private key version bytes (`dprv`/`tprv`/…). */\n readonly hdPrivateKeyId: readonly [number, number, number, number];\n /** BIP32 extended public key version bytes (`dpub`/`tpub`/…). */\n readonly hdPublicKeyId: readonly [number, number, number, number];\n /** SLIP-0044 registered coin type used in BIP44 derivation paths. */\n readonly slip44: number;\n}\n\nexport const mainnet: Network = {\n name: \"mainnet\",\n net: 0xd9b400f9,\n addressPrefix: \"D\",\n pubKeyAddrId: [0x13, 0x86],\n pubKeyHashAddrId: [0x07, 0x3f],\n pubKeyHashEdwardsAddrId: [0x07, 0x1f],\n pubKeyHashSchnorrAddrId: [0x07, 0x01],\n scriptHashAddrId: [0x07, 0x1a],\n privateKeyId: [0x22, 0xde],\n hdPrivateKeyId: [0x02, 0xfd, 0xa4, 0xe8],\n hdPublicKeyId: [0x02, 0xfd, 0xa9, 0x26],\n slip44: 42,\n};\n\nexport const testnet3: Network = {\n name: \"testnet3\",\n net: 0xb194aa75,\n addressPrefix: \"T\",\n pubKeyAddrId: [0x28, 0xf7],\n pubKeyHashAddrId: [0x0f, 0x21],\n pubKeyHashEdwardsAddrId: [0x0f, 0x01],\n pubKeyHashSchnorrAddrId: [0x0e, 0xe3],\n scriptHashAddrId: [0x0e, 0xfc],\n privateKeyId: [0x23, 0x0e],\n hdPrivateKeyId: [0x04, 0x35, 0x83, 0x97],\n hdPublicKeyId: [0x04, 0x35, 0x87, 0xd1],\n slip44: 1,\n};\n\nexport const simnet: Network = {\n name: \"simnet\",\n net: 0x12141c16,\n addressPrefix: \"S\",\n pubKeyAddrId: [0x27, 0x6f],\n pubKeyHashAddrId: [0x0e, 0x91],\n pubKeyHashEdwardsAddrId: [0x0e, 0x71],\n pubKeyHashSchnorrAddrId: [0x0e, 0x53],\n scriptHashAddrId: [0x0e, 0x6c],\n privateKeyId: [0x23, 0x07],\n hdPrivateKeyId: [0x04, 0x20, 0xb9, 0x03],\n hdPublicKeyId: [0x04, 0x20, 0xbd, 0x3d],\n slip44: 1,\n};\n\nexport const regnet: Network = {\n name: \"regnet\",\n net: 0xdab500fa,\n addressPrefix: \"R\",\n pubKeyAddrId: [0x25, 0xe5],\n pubKeyHashAddrId: [0x0e, 0x00],\n pubKeyHashEdwardsAddrId: [0x0d, 0xe0],\n pubKeyHashSchnorrAddrId: [0x0d, 0xc2],\n scriptHashAddrId: [0x0d, 0xdb],\n privateKeyId: [0x22, 0xfe],\n hdPrivateKeyId: [0xea, 0xb4, 0x04, 0x48],\n hdPublicKeyId: [0xea, 0xb4, 0xf9, 0x87],\n slip44: 1,\n};\n\n/** All networks keyed by name. */\nexport const networks = { mainnet, testnet3, simnet, regnet } as const;\n\nexport type NetworkName = keyof typeof networks;\n","/**\n * secp256k1 helpers.\n *\n * Elliptic-curve math is delegated to the audited `@noble/curves` package; this\n * module only adapts it to the shapes the rest of the library needs (compressed\n * keys, scalar/point arithmetic for BIP32 derivation).\n */\nimport { err } from \"./errors.js\";\nimport { isBytes, typeName } from \"./bytes.js\";\nimport { secp256k1 } from \"@noble/curves/secp256k1\";\nimport { ed25519 } from \"@noble/curves/ed25519\";\n\n/** The secp256k1 group order. */\nexport const CURVE_ORDER: bigint = secp256k1.CURVE.n;\n\n/**\n * The Ed25519 group order, 2^252 + 27742317777372353535851937790883648493.\n *\n * Written out rather than read from `ed25519.CURVE.n` so that a consumer who\n * never touches the Ed25519 suite does not carry the curve. Reading the curve\n * object evaluates at module scope, which anchors `@noble/curves`' `ed25519`\n * and `edwards` modules — about 27 KB — into every bundle that reaches `wif.ts`,\n * even though the only consumer is `assertWifScalar`, which returns early for\n * both secp256k1 suites. No bundler can prove that branch dead, so the eager\n * read is the only thing available to remove; deferring it behind a lazy getter\n * does not help, because `assertWifScalar` itself is always reachable.\n *\n * `encoding.test.ts` asserts this equals `ed25519.CURVE.n`, so the value stays\n * tied to the audited source without the module graph depending on it.\n */\nexport const ED25519_CURVE_ORDER: bigint = 2n ** 252n + 27742317777372353535851937790883648493n;\n\n/** True when `key` is a valid secp256k1 private scalar (0 < key < n). */\nexport function isValidPrivateKey(key: Uint8Array): boolean {\n // The type check is load-bearing, not defensive: without it a 32-character\n // string, a 32-element `Array<number>` or an `Int8Array` all satisfy the length\n // test, and `bytesToBigInt` reads them into some unrelated number — so this\n // predicate answered `true` for values that are not keys at all.\n if (!isBytes(key) || key.length !== 32) return false;\n const n = bytesToBigInt(key);\n return n > 0n && n < CURVE_ORDER;\n}\n\n/**\n * Throw unless `key` is a usable secp256k1 private scalar.\n *\n * Everything that signs, or turns a private key into a public one, goes through\n * this. `@noble` checks the same two conditions itself but throws its own plain\n * `Error`, which escapes the typed-error contract — a caller branching on\n * `hasErrorCode` cannot classify a zeroed or wrong-length key buffer, which is\n * exactly the mistake worth classifying.\n *\n * Deliberately stricter than dcrd, which cannot express this failure at all:\n * `secp256k1.PrivKeyFromBytes` reduces mod n and left-pads a short slice, so a\n * zero key there signs under an all-zero-X public key and a 31-byte key is\n * silently padded. Rejecting is the safer contract for a signing API.\n */\nexport function assertPrivateKey(key: Uint8Array, who: string): void {\n if (!isBytes(key)) {\n throw err(\"invalid-argument\", who, `private key must be a Uint8Array, got ${typeName(key)}`);\n }\n if (key.length !== 32) {\n throw err(\"bad-length\", who, `private key must be 32 bytes, got ${key.length}`);\n }\n if (!isValidPrivateKey(key)) {\n throw err(\"invalid-private-key\", who, \"private key is zero, or at or above the group order\");\n }\n}\n\n/** Compressed (33-byte) public key for a private key. */\nexport function publicKeyFromPrivate(privateKey: Uint8Array, compressed = true): Uint8Array {\n assertPrivateKey(privateKey, \"publicKeyFromPrivate\");\n return secp256k1.getPublicKey(privateKey, compressed);\n}\n\n/** True when `key` is a valid serialized secp256k1 point (compressed or not). */\nexport function isValidPublicKey(key: Uint8Array): boolean {\n try {\n secp256k1.ProjectivePoint.fromHex(key);\n return true;\n } catch {\n return false;\n }\n}\n\n/**\n * True when `key` is a valid 32-byte Ed25519 public key.\n *\n * Decred's alternative signature suites are recognised on decode even though this\n * library cannot sign for them, and an address whose key is not on the curve is\n * unspendable — so it should not decode as valid. Ed25519 comes from the same\n * `@noble/curves` package already in use, so this adds no dependency.\n */\nexport function isValidEd25519PublicKey(key: Uint8Array): boolean {\n // A predicate that throws is worse than one that answers: `isBytes` first, so\n // `isValidEd25519PublicKey(undefined)` is `false` rather than a bare TypeError\n // out of a function whose whole job is to answer true or false.\n if (!isBytes(key) || key.length !== 32) return false;\n try {\n // ZIP-215 decoding, because that is what dcrd does. Its `ParsePubKey` goes\n // through AGL's `edwards25519`, whose `FeFromBytes` masks off only the sign\n // bit and never rejects a Y at or above the field prime; the reduction to\n // 0..p-1 happens on the way back out, so the `Y < P` check in `ParsePubKey`\n // can never fire. `@noble` defaults to the stricter RFC 8032 range, which\n // rejects 23 encodings dcrd accepts.\n const point = ed25519.ExtendedPoint.fromHex(key, true);\n // The one thing dcrd does reject: X = 0 with the sign bit set. Its sign\n // fix-up is `x.Sub(curve.P, x)`, which for X = 0 yields exactly P and then\n // trips the `X < P` check. `@noble` applies the same rule, but only when\n // ZIP-215 decoding is off, so it has to be restated here.\n return !(point.toAffine().x === 0n && (key[31]! & 0x80) !== 0);\n } catch {\n return false;\n }\n}\n\n/**\n * Throw unless `key` is a 33-byte compressed secp256k1 point.\n *\n * Anything that turns a public key into an address or an output script must go\n * through this. Length alone is not enough, and length is not even checked in the\n * common mistake: passing a 32-byte private key where the public key was meant\n * type-checks fine, since both are `Uint8Array`. The resulting address or script\n * is well-formed and permanently unspendable, because no key hashes to it.\n */\nexport function assertCompressedPubKey(key: Uint8Array, who: string): void {\n if (!isBytes(key)) {\n throw err(\"invalid-argument\", who, `public key must be a Uint8Array, got ${typeName(key)}`);\n }\n if (key.length !== 33) {\n throw err(\"invalid-public-key\", who, `public key must be 33 compressed bytes, got ${key.length}`);\n }\n if (key[0] !== 0x02 && key[0] !== 0x03) {\n throw err(\n \"invalid-public-key\",\n who,\n `public key must start with 0x02 or 0x03, got 0x${key[0]!.toString(16).padStart(2, \"0\")}`,\n );\n }\n if (!isValidPublicKey(key)) {\n throw err(\"invalid-public-key\", who, \"public key is not a point on the secp256k1 curve\");\n }\n}\n\n/**\n * Throw unless `key` is a serialized secp256k1 point — 33-byte compressed or\n * 65-byte uncompressed.\n *\n * For hashing a key into a P2PKH address, where both serializations are\n * legitimate and produce *different* addresses (dcrd hashes whichever form the\n * caller holds; see `dcrutil/util.go`). Use {@link assertCompressedPubKey}\n * wherever the format itself requires 33 bytes, such as the pay-to-pubkey address\n * payload or a bare-P2PK script.\n */\nexport function assertPubKey(key: Uint8Array, who: string): void {\n if (!isBytes(key)) {\n throw err(\"invalid-argument\", who, `public key must be a Uint8Array, got ${typeName(key)}`);\n }\n if (key.length !== 33 && key.length !== 65) {\n throw err(\n \"invalid-public-key\",\n who,\n `public key must be 33 (compressed) or 65 (uncompressed) bytes, got ${key.length}`,\n );\n }\n const prefix = key[0]!;\n const ok = key.length === 33 ? prefix === 0x02 || prefix === 0x03 : prefix === 0x04;\n // Deliberately redundant, and kept: `isValidPublicKey` below rejects every\n // wrong prefix on its own, because `@noble`'s point decoder checks the marker\n // before the coordinates. Removing this changes no answer today — a mutation\n // that deletes it leaves the suite green. It stays because it names the\n // failure precisely (\"prefix 0x04 is not valid for a 33-byte key\") where the\n // curve check can only say \"not a point\", and because the specific reason\n // matters to a caller who mixed up the two serializations.\n if (!ok) {\n throw err(\n \"invalid-public-key\",\n who,\n `public key has prefix 0x${prefix.toString(16).padStart(2, \"0\")}, which is not valid ` +\n `for a ${key.length}-byte key`,\n );\n }\n if (!isValidPublicKey(key)) {\n throw err(\"invalid-public-key\", who, \"public key is not a point on the secp256k1 curve\");\n }\n}\n\n/** Big-endian 32-byte encoding of a scalar already reduced mod n. */\nexport function scalarToBytes(x: bigint): Uint8Array {\n const out = new Uint8Array(32);\n let v = x;\n for (let i = 31; i >= 0; i--) {\n out[i] = Number(v & 0xffn);\n v >>= 8n;\n }\n return out;\n}\n\nexport function bytesToBigInt(b: Uint8Array): bigint {\n let v = 0n;\n for (const x of b) v = (v << 8n) | BigInt(x);\n return v;\n}\n\n/**\n * BIP32 private child tweak: `(IL + kPar) mod n`, returned as 32 bytes.\n * Returns `null` when the result is invalid (IL zero or >= n, or the sum is\n * zero), which signals the caller to skip to the next index.\n *\n * BIP32 invalidates only `IL >= n` and `ki == 0`. Rejecting `IL == 0` as well is\n * dcrd's rule — `overflow || ilModN.IsZero()` in `hdkeychain`'s `child`, checked\n * before the private/public split, so it applies to both paths — and it is what\n * {@link publicKeyTweakAddPoint} already does. Without it a zero IL would make\n * the child byte-identical to its parent.\n */\nexport function privateKeyTweakAdd(kPar: Uint8Array, il: Uint8Array): Uint8Array | null {\n const ilInt = bytesToBigInt(il);\n if (ilInt === 0n || ilInt >= CURVE_ORDER) return null;\n const child = (ilInt + bytesToBigInt(kPar)) % CURVE_ORDER;\n if (child === 0n) return null;\n return scalarToBytes(child);\n}\n\n/**\n * A parsed secp256k1 point, for reuse across derivations.\n *\n * Deliberately *not* re-exported from the package root: it is `@noble`'s type, and\n * pinning the public API to a dependency's internals is not worth the 1.4x.\n */\nexport type PublicKeyPoint = InstanceType<typeof secp256k1.ProjectivePoint>;\n\n/**\n * Decompress a serialized public key once, so a caller deriving a chain of\n * children can reuse it.\n *\n * Decompressing costs a modular square root — measured ~65 us, about 29% of a\n * public (watch-only) derivation step, and it is the same parent key every time\n * when scanning addresses under one account.\n */\nexport function parsePublicKeyPoint(key: Uint8Array): PublicKeyPoint | null {\n try {\n return secp256k1.ProjectivePoint.fromHex(key);\n } catch {\n return null;\n }\n}\n\n/** {@link publicKeyTweakAdd} with the parent already decompressed. */\nexport function publicKeyTweakAddPoint(\n parent: PublicKeyPoint,\n il: Uint8Array,\n): Uint8Array | null {\n const ilInt = bytesToBigInt(il);\n if (ilInt >= CURVE_ORDER || ilInt === 0n) return null;\n const P = secp256k1.ProjectivePoint;\n try {\n const child = P.BASE.multiply(ilInt).add(parent);\n if (child.equals(P.ZERO)) return null;\n return child.toRawBytes(true);\n } catch {\n return null;\n }\n}\n\n","/**\n * Minimal Decred script support: opcode constants, canonical data pushes, the\n * standard payment-script builders and matching classifiers.\n *\n * This is deliberately not a full script engine — it covers the templates a\n * wallet needs to build and recognise: P2PKH, P2SH and bare P2PK.\n */\nimport { err } from \"./errors.js\";\nimport { copyOf, isBytes, shown, typeName } from \"./bytes.js\";\nimport { assertCompressedPubKey, isValidEd25519PublicKey } from \"./keys.js\";\n\n// The opcodes referenced by this library. Decred's opcode table matches\n// Bitcoin's for these; `OP_CHECKSIGALT` is a Decred addition for the Ed25519 /\n// Schnorr signature suites.\nexport const OP = {\n OP_0: 0x00,\n DATA_20: 0x14,\n DATA_32: 0x20,\n DATA_33: 0x21,\n PUSHDATA1: 0x4c,\n PUSHDATA2: 0x4d,\n PUSHDATA4: 0x4e,\n OP_1NEGATE: 0x4f,\n OP_1: 0x51,\n OP_2: 0x52,\n OP_16: 0x60,\n DUP: 0x76,\n EQUAL: 0x87,\n EQUALVERIFY: 0x88,\n HASH160: 0xa9,\n CHECKSIG: 0xac,\n CHECKSIGALT: 0xbe,\n} as const;\n\n/**\n * Largest a single stack element may be (dcrd `txscript.MaxScriptElementSize`).\n * dcrd rejects a bigger push both when building and at execution, so anything\n * over this can never run.\n */\nexport const MAX_SCRIPT_ELEMENT_SIZE = 2048;\n\n/**\n * Encode a canonical data push — the smallest valid encoding for `data`.\n *\n * \"Smallest\" includes the small-integer opcodes, which is a consensus rule and\n * not a policy one: dcrd's script engine applies `checkMinimalDataPush` to every\n * executed push with no verification flag gating it, so `OP_DATA_1 0x05` fails\n * where `OP_5` succeeds. A script built with a non-minimal push is unspendable.\n */\nexport function pushData(data: Uint8Array): Uint8Array {\n if (!isBytes(data)) {\n throw err(\"invalid-argument\", \"pushData\", `data must be a Uint8Array, got ${typeName(data)}`);\n }\n const n = data.length;\n if (n > MAX_SCRIPT_ELEMENT_SIZE) {\n throw err(\n \"element-too-large\",\n \"pushData\",\n `${n} bytes exceeds MaxScriptElementSize (${MAX_SCRIPT_ELEMENT_SIZE})`,\n );\n }\n // The single-byte cases dcrd requires a dedicated opcode for. Mirrors\n // txscript/scriptbuilder.go addData.\n if (n === 1) {\n const b = data[0]!;\n if (b === 0) return Uint8Array.of(OP.OP_0);\n if (b >= 1 && b <= 16) return Uint8Array.of(OP.OP_1 + b - 1);\n if (b === 0x81) return Uint8Array.of(OP.OP_1NEGATE);\n }\n if (n < OP.PUSHDATA1) {\n const out = new Uint8Array(1 + n);\n out[0] = n;\n out.set(data, 1);\n return out;\n }\n if (n <= 0xff) {\n const out = new Uint8Array(2 + n);\n out[0] = OP.PUSHDATA1;\n out[1] = n;\n out.set(data, 2);\n return out;\n }\n // No OP_PUSHDATA4 branch: the MaxScriptElementSize check above caps `n` at\n // 2048, so a 4-byte length is never the minimal encoding. If that cap is ever\n // relaxed, this is where the branch goes back.\n const out = new Uint8Array(3 + n);\n out[0] = OP.PUSHDATA2;\n out[1] = n & 0xff;\n out[2] = (n >>> 8) & 0xff;\n out.set(data, 3);\n return out;\n}\n\n/**\n * True when `script` tokenizes cleanly as a version-0 script — i.e. every data\n * push declares a length that actually fits.\n *\n * The equivalent of dcrd's `checkScriptParses`, which its exported\n * `CalcSignatureHash` runs before hashing. Signing against a script that does\n * not parse produces a signature over a message dcrd would refuse to compute,\n * so the resulting transaction can never be spent.\n *\n * This is a structural check only, not an execution one: it says nothing about\n * whether the opcodes are valid or the script would succeed.\n */\nexport function scriptParses(script: Uint8Array): boolean {\n if (!isBytes(script)) return false;\n let i = 0;\n while (i < script.length) {\n const op = script[i]!;\n if (op >= 0x01 && op <= 0x4b) {\n // OP_DATA_1..OP_DATA_75: the opcode byte plus exactly that many more.\n if (script.length - i < op + 1) return false;\n i += op + 1;\n } else if (op === OP.PUSHDATA1 || op === OP.PUSHDATA2 || op === OP.PUSHDATA4) {\n const lenSize = op === OP.PUSHDATA1 ? 1 : op === OP.PUSHDATA2 ? 2 : 4;\n if (script.length - (i + 1) < lenSize) return false;\n let dataLen = 0;\n for (let b = 0; b < lenSize; b++) dataLen |= script[i + 1 + b]! << (8 * b);\n // dcrd reads the length as a signed int32, so a 4-byte length with the\n // high bit set comes out negative and is rejected rather than treated as\n // enormous. JS `<<` yields int32, so this matches for free.\n if (dataLen < 0 || dataLen > script.length - (i + 1 + lenSize)) return false;\n i += 1 + lenSize + dataLen;\n } else {\n i += 1;\n }\n }\n return true;\n}\n\n/**\n * Reject a hash argument that is not a byte array at all.\n *\n * `length` alone cannot carry this: a 20-character string, a 20-element\n * `Array<number>` and a `Float64Array` all satisfy `.length === 20`, and\n * `Uint8Array.prototype.set` then coerces each element — a string yields twenty\n * zero bytes, i.e. a burn script that looks perfectly well-formed. The same\n * reasoning `isValidPrivateKey` records for keys.\n */\nfunction assertHash160(hash160: Uint8Array, who: string): void {\n if (!isBytes(hash160)) {\n throw err(\"invalid-argument\", who, `hash must be a Uint8Array, got ${typeName(hash160)}`);\n }\n}\n\n/** Build a P2PKH script: `OP_DUP OP_HASH160 <20-byte hash> OP_EQUALVERIFY OP_CHECKSIG`. */\nexport function payToPubKeyHashScript(hash160: Uint8Array): Uint8Array {\n assertHash160(hash160, \"payToPubKeyHash\");\n if (hash160.length !== 20) throw err(\"bad-length\", \"payToPubKeyHash\", `hash must be 20 bytes, got ${hash160.length}`);\n // Preallocate and `set` rather than spreading through a JS number array, which\n // measured several times slower. Scripts are built once per output, so this is\n // on the hot path for any wallet assembling many transactions.\n const out = new Uint8Array(25);\n out[0] = OP.DUP;\n out[1] = OP.HASH160;\n out[2] = OP.DATA_20;\n out.set(hash160, 3);\n out[23] = OP.EQUALVERIFY;\n out[24] = OP.CHECKSIG;\n return out;\n}\n\n/**\n * Build a P2PKH script for an alternative signature suite (Ed25519 = 1,\n * secp256k1 Schnorr = 2): `OP_DUP OP_HASH160 <20-byte hash> OP_EQUALVERIFY\n * <OP_1|OP_2> OP_CHECKSIGALT`. The signature type is pushed as a small integer.\n */\nexport function payToPubKeyHashAltScript(hash160: Uint8Array, sigType: 1 | 2): Uint8Array {\n assertHash160(hash160, \"payToPubKeyHashAlt\");\n if (hash160.length !== 20) throw err(\"bad-length\", \"payToPubKeyHashAlt\", `hash must be 20 bytes, got ${hash160.length}`);\n if (sigType !== 1 && sigType !== 2) throw err(\"unsupported-signature-type\", \"payToPubKeyHashAlt\", `sigType must be 1 or 2, got ${shown(sigType)}`);\n const out = new Uint8Array(26);\n out[0] = OP.DUP;\n out[1] = OP.HASH160;\n out[2] = OP.DATA_20;\n out.set(hash160, 3);\n out[23] = OP.EQUALVERIFY;\n out[24] = sigType === 1 ? OP.OP_1 : OP.OP_2;\n out[25] = OP.CHECKSIGALT;\n return out;\n}\n\n/** Build a P2SH script: `OP_HASH160 <20-byte hash> OP_EQUAL`. */\nexport function payToScriptHashScript(hash160: Uint8Array): Uint8Array {\n assertHash160(hash160, \"payToScriptHash\");\n if (hash160.length !== 20) throw err(\"bad-length\", \"payToScriptHash\", `hash must be 20 bytes, got ${hash160.length}`);\n const out = new Uint8Array(23);\n out[0] = OP.HASH160;\n out[1] = OP.DATA_20;\n out.set(hash160, 2);\n out[22] = OP.EQUAL;\n return out;\n}\n\n/**\n * Build a bare P2PK script: `<33-byte compressed pubkey> OP_CHECKSIG`.\n *\n * The key is validated as an actual curve point, not just measured. This is an\n * *output* script: paying to one built around arbitrary 33 bytes burns the coins,\n * because no signature can ever satisfy an `OP_CHECKSIG` whose key does not\n * parse. dcrd cannot express this — its constructor takes a parsed public key.\n */\nexport function payToPubKeyScript(compressedPubKey: Uint8Array): Uint8Array {\n assertCompressedPubKey(compressedPubKey, \"payToPubKey\");\n const out = new Uint8Array(35);\n out[0] = OP.DATA_33;\n out.set(compressedPubKey, 1);\n out[34] = OP.CHECKSIG;\n return out;\n}\n\n/**\n * Build a pay-to-pubkey script for an alternative signature suite.\n *\n * Ed25519 takes a 32-byte key: `<32-byte pubkey> OP_1 OP_CHECKSIGALT`.\n * secp256k1 Schnorr takes a 33-byte compressed key:\n * `<33-byte pubkey> OP_2 OP_CHECKSIGALT`.\n *\n * The suite is pushed as a small integer, exactly as in\n * {@link payToPubKeyHashAltScript}.\n */\nexport function payToPubKeyAltScript(pubKey: Uint8Array, sigType: 1 | 2): Uint8Array {\n if (sigType === 1) {\n if (pubKey.length !== 32) {\n throw err(\n \"invalid-public-key\",\n \"payToPubKeyAlt\",\n `an Ed25519 public key must be 32 bytes, got ${pubKey.length}`,\n );\n }\n // Same check `pubKeyEd25519Address` applies, for the same reason: 32 bytes\n // off the curve build a well-formed script that no key can ever satisfy.\n // The secp256k1 arm below gets this from `assertCompressedPubKey`; without\n // it here the Ed25519 arm is the one payment builder that will hand back an\n // unspendable output.\n if (!isValidEd25519PublicKey(pubKey)) {\n throw err(\"invalid-public-key\", \"payToPubKeyAlt\", \"public key is not a valid Ed25519 curve point\");\n }\n const out = new Uint8Array(35);\n out[0] = OP.DATA_32;\n out.set(pubKey, 1);\n out[33] = OP.OP_1;\n out[34] = OP.CHECKSIGALT;\n return out;\n }\n if (sigType !== 2) throw err(\"unsupported-signature-type\", \"payToPubKeyAlt\", `sigType must be 1 or 2, got ${shown(sigType)}`);\n assertCompressedPubKey(pubKey, \"payToPubKeyAlt\");\n const out = new Uint8Array(36);\n out[0] = OP.DATA_33;\n out.set(pubKey, 1);\n out[34] = OP.OP_2;\n out[35] = OP.CHECKSIGALT;\n return out;\n}\n\n/** True when `script` is a canonical version-0 P2PKH template. */\nexport function isPayToPubKeyHash(script: Uint8Array): boolean {\n return (\n isBytes(script) &&\n script.length === 25 &&\n script[0] === OP.DUP &&\n script[1] === OP.HASH160 &&\n script[2] === OP.DATA_20 &&\n script[23] === OP.EQUALVERIFY &&\n script[24] === OP.CHECKSIG\n );\n}\n\n/** True when `script` is a canonical version-0 P2SH template. */\nexport function isPayToScriptHash(script: Uint8Array): boolean {\n return (\n isBytes(script) &&\n script.length === 23 &&\n script[0] === OP.HASH160 &&\n script[1] === OP.DATA_20 &&\n script[22] === OP.EQUAL\n );\n}\n\n/**\n * Extract the 20-byte hash from a P2PKH or P2SH script, or `null`.\n *\n * Note this deliberately loses *which* template matched, and the two need\n * different addresses — use {@link classifyScript} when that matters, or the\n * hash will be encoded as the wrong address kind.\n */\nexport function extractHash160(script: Uint8Array): Uint8Array | null {\n if (isPayToPubKeyHash(script)) return copyOf(script, 3, 20);\n if (isPayToScriptHash(script)) return copyOf(script, 2, 20);\n return null;\n}\n\n/** What {@link classifyScript} recognises. */\nexport type ScriptKind =\n | \"pubkeyhash-ecdsa\"\n | \"pubkeyhash-ed25519\"\n | \"pubkeyhash-schnorr\"\n | \"scripthash\";\n\n/**\n * Classify a version-0 payment script and return its 20-byte hash.\n *\n * {@link extractHash160} returns a bare hash for either the P2PKH or the P2SH\n * template, so a caller labelling outputs by address has no way to tell which\n * encoder to use — and picking wrong produces a completely different, valid\n * address for the same script. This keeps the kind attached. Also recognises the\n * two `OP_CHECKSIGALT` templates the library can build, which nothing could\n * classify before.\n */\nexport function classifyScript(script: Uint8Array): { kind: ScriptKind; hash: Uint8Array } | null {\n if (!isBytes(script)) return null;\n if (isPayToPubKeyHash(script)) return { kind: \"pubkeyhash-ecdsa\", hash: copyOf(script, 3, 20) };\n if (isPayToScriptHash(script)) return { kind: \"scripthash\", hash: copyOf(script, 2, 20) };\n if (\n script.length === 26 &&\n script[0] === OP.DUP &&\n script[1] === OP.HASH160 &&\n script[2] === OP.DATA_20 &&\n script[23] === OP.EQUALVERIFY &&\n script[25] === OP.CHECKSIGALT\n ) {\n if (script[24] === OP.OP_1) {\n return { kind: \"pubkeyhash-ed25519\", hash: copyOf(script, 3, 20) };\n }\n if (script[24] === OP.OP_2) {\n return { kind: \"pubkeyhash-schnorr\", hash: copyOf(script, 3, 20) };\n }\n }\n return null;\n}\n","/**\n * Decred addresses.\n *\n * A Decred address is `base58check(versionPrefix || payload)` where the version\n * prefix is **two** bytes (unlike Bitcoin's one) and the checksum is the\n * double-BLAKE-256 one from {@link checkEncode}. The two-byte prefix encodes\n * both the network and the address kind, which is how an address advertises the\n * signature suite it commits to.\n *\n * Supported kinds:\n * - pay-to-pubkey-hash (secp256k1 ECDSA) — the everyday `Ds…` address\n * - pay-to-script-hash\n * - pay-to-pubkey-hash (Ed25519 and secp256k1 Schnorr) — recognised on decode\n * - pay-to-pubkey (secp256k1 ECDSA) — the `Dk…` full-pubkey address\n */\nimport { err } from \"./errors.js\";\nimport { checkDecode, checkEncode, maxBase58Length } from \"./base58.js\";\nimport { hash160 } from \"./hash.js\";\nimport type { Network } from \"./networks.js\";\nimport { networks } from \"./networks.js\";\nimport {\n payToPubKeyAltScript,\n payToPubKeyHashAltScript,\n payToPubKeyHashScript,\n payToPubKeyScript,\n payToScriptHashScript,\n} from \"./script.js\";\nimport { copyOf, typeName } from \"./bytes.js\";\nimport {\n assertCompressedPubKey,\n assertPubKey,\n isValidEd25519PublicKey,\n isValidPublicKey,\n} from \"./keys.js\";\n\nexport type AddressKind =\n | \"pubkeyhash-ecdsa\"\n | \"pubkeyhash-ed25519\"\n | \"pubkeyhash-schnorr\"\n | \"scripthash\"\n | \"pubkey-ecdsa\"\n | \"pubkey-ed25519\"\n | \"pubkey-schnorr\";\n\n/** The hash-based address kinds, which carry a 20-byte `hash`. */\nexport type HashAddressKind =\n | \"pubkeyhash-ecdsa\"\n | \"pubkeyhash-ed25519\"\n | \"pubkeyhash-schnorr\"\n | \"scripthash\";\n\n/** The pay-to-pubkey kinds, which carry a serialized `pubKey`. */\nexport type PubKeyAddressKind = \"pubkey-ecdsa\" | \"pubkey-ed25519\" | \"pubkey-schnorr\";\n\n/**\n * A decoded address.\n *\n * A discriminated union on `kind`, so `hash` and `pubKey` are present exactly\n * where they exist — narrowing on `kind` (or on `\"hash\" in decoded`) replaces\n * what would otherwise be a non-null assertion at every use.\n */\nexport type DecodedAddress =\n | {\n readonly network: Network;\n readonly kind: HashAddressKind;\n /** 20-byte hash. */\n readonly hash: Uint8Array;\n /** The original address string. */\n readonly address: string;\n }\n | {\n readonly network: Network;\n readonly kind: PubKeyAddressKind;\n /**\n * The serialized public key: 33-byte compressed secp256k1 for\n * `pubkey-ecdsa` and `pubkey-schnorr`, 32-byte Ed25519 for\n * `pubkey-ed25519`.\n */\n readonly pubKey: Uint8Array;\n readonly address: string;\n };\n\ninterface PrefixEntry {\n network: Network;\n kind: AddressKind;\n prefix: readonly [number, number];\n}\n\n/**\n * Longest a version-0 address can be: a 33-byte payload (the pay-to-pubkey kind)\n * plus a 2-byte version prefix and a 4-byte checksum. Matches dcrd's\n * `maxV0AddrLen`.\n */\nexport const MAX_ADDRESS_LENGTH = maxBase58Length(33 + 2 + 4);\n\n// Every (network, kind) → 2-byte prefix, used to classify on decode.\nconst PREFIXES: PrefixEntry[] = [];\nfor (const network of Object.values(networks)) {\n PREFIXES.push(\n { network, kind: \"pubkeyhash-ecdsa\", prefix: network.pubKeyHashAddrId },\n { network, kind: \"pubkeyhash-ed25519\", prefix: network.pubKeyHashEdwardsAddrId },\n { network, kind: \"pubkeyhash-schnorr\", prefix: network.pubKeyHashSchnorrAddrId },\n { network, kind: \"scripthash\", prefix: network.scriptHashAddrId },\n { network, kind: \"pubkey-ecdsa\", prefix: network.pubKeyAddrId },\n );\n}\n\nfunction encode(prefix: readonly [number, number], payload: Uint8Array): string {\n const data = new Uint8Array(2 + payload.length);\n data[0] = prefix[0];\n data[1] = prefix[1];\n data.set(payload, 2);\n return checkEncode(data);\n}\n\n/** Encode a 20-byte pubkey hash as a P2PKH (secp256k1 ECDSA) address. */\nexport function pubKeyHashAddress(hash: Uint8Array, network: Network): string {\n if (hash.length !== 20) throw err(\"bad-length\", \"pubKeyHashAddress\", `hash must be 20 bytes, got ${hash.length}`);\n return encode(network.pubKeyHashAddrId, hash);\n}\n\n/** Encode a 20-byte script hash as a P2SH address. */\nexport function scriptHashAddress(hash: Uint8Array, network: Network): string {\n if (hash.length !== 20) throw err(\"bad-length\", \"scriptHashAddress\", `hash must be 20 bytes, got ${hash.length}`);\n return encode(network.scriptHashAddrId, hash);\n}\n\n/** Encode a 20-byte pubkey hash as a P2PKH (Ed25519) address. */\nexport function pubKeyHashEd25519Address(hash: Uint8Array, network: Network): string {\n if (hash.length !== 20) throw err(\"bad-length\", \"pubKeyHashEd25519Address\", `hash must be 20 bytes, got ${hash.length}`);\n return encode(network.pubKeyHashEdwardsAddrId, hash);\n}\n\n/** Encode a 20-byte pubkey hash as a P2PKH (secp256k1 Schnorr) address. */\nexport function pubKeyHashSchnorrAddress(hash: Uint8Array, network: Network): string {\n if (hash.length !== 20) throw err(\"bad-length\", \"pubKeyHashSchnorrAddress\", `hash must be 20 bytes, got ${hash.length}`);\n return encode(network.pubKeyHashSchnorrAddrId, hash);\n}\n\n// A secp256k1 pay-to-pubkey address does not store the raw compressed key.\n// Instead the 33-byte data is `identifier || X`, where the identifier is the\n// signature type (0 for ECDSA) with the high bit set when the key's Y is odd.\nconst SIG_TYPE_ODD_FLAG = 0x80;\n\nfunction encodePubKeyData(compressedPubKey: Uint8Array): Uint8Array {\n assertCompressedPubKey(compressedPubKey, \"pubKeyAddress\");\n const prefix = compressedPubKey[0]!;\n const data = new Uint8Array(33);\n data[0] = SignatureTypeEcdsa | (prefix === 0x03 ? SIG_TYPE_ODD_FLAG : 0);\n data.set(compressedPubKey.subarray(1), 1);\n return data;\n}\n\n/**\n * Decode a pay-to-pubkey payload for any of the three signature suites.\n *\n * All three share the layout `identifier || 32 bytes`, where the identifier is\n * the suite with the high bit set when a secp256k1 key's Y is odd. dcrd's\n * `DecodeAddressV0` accepts all three under one address ID, so handling only\n * ECDSA reported a legitimate mainnet address as invalid.\n */\nfunction decodePubKeyData(data: Uint8Array): { kind: PubKeyAddressKind; pubKey: Uint8Array } {\n const sigType = data[0]! & ~SIG_TYPE_ODD_FLAG;\n const odd = (data[0]! & SIG_TYPE_ODD_FLAG) !== 0;\n\n if (sigType === SignatureTypeEd25519) {\n // The payload *is* the Ed25519 key; there is no oddness bit to apply.\n const pubKey = copyOf(data, 1, 32);\n if (!isValidEd25519PublicKey(pubKey)) {\n throw err(\"invalid-public-key\", \"decodeAddress\", \"pubkey is not a valid Ed25519 curve point\");\n }\n return { kind: \"pubkey-ed25519\", pubKey };\n }\n\n if (sigType !== SignatureTypeEcdsa && sigType !== SignatureTypeSchnorr) {\n throw err(\"unsupported-signature-type\", \"decodeAddress\", `unsupported pubkey signature type ${sigType}`);\n }\n // secp256k1: rebuild the compressed serialization from X plus the oddness bit.\n const pubKey = new Uint8Array(33);\n pubKey[0] = odd ? 0x03 : 0x02;\n pubKey.set(data.subarray(1), 1);\n if (!isValidPublicKey(pubKey)) {\n throw err(\"invalid-public-key\", \"decodeAddress\", \"pubkey is not a valid curve point\");\n }\n return { kind: sigType === SignatureTypeEcdsa ? \"pubkey-ecdsa\" : \"pubkey-schnorr\", pubKey };\n}\n\n// dcrec.SignatureType values.\nconst SignatureTypeEcdsa = 0;\nconst SignatureTypeEd25519 = 1;\nconst SignatureTypeSchnorr = 2;\n\n/** Encode a compressed public key as a pay-to-pubkey (secp256k1 ECDSA) address. */\nexport function pubKeyAddress(compressedPubKey: Uint8Array, network: Network): string {\n return encode(network.pubKeyAddrId, encodePubKeyData(compressedPubKey));\n}\n\n/** Encode a 32-byte Ed25519 public key as a pay-to-pubkey address. */\nexport function pubKeyEd25519Address(pubKey: Uint8Array, network: Network): string {\n if (pubKey.length !== 32) {\n throw err(\"invalid-public-key\", \"pubKeyEd25519Address\", `an Ed25519 public key must be 32 bytes, got ${pubKey.length}`);\n }\n if (!isValidEd25519PublicKey(pubKey)) {\n throw err(\"invalid-public-key\", \"pubKeyEd25519Address\", \"public key is not a valid Ed25519 curve point\");\n }\n const data = new Uint8Array(33);\n data[0] = SignatureTypeEd25519;\n data.set(pubKey, 1);\n return encode(network.pubKeyAddrId, data);\n}\n\n/** Encode a compressed public key as a pay-to-pubkey (secp256k1 Schnorr) address. */\nexport function pubKeySchnorrAddress(compressedPubKey: Uint8Array, network: Network): string {\n assertCompressedPubKey(compressedPubKey, \"pubKeySchnorrAddress\");\n const data = new Uint8Array(33);\n data[0] = SignatureTypeSchnorr | (compressedPubKey[0] === 0x03 ? SIG_TYPE_ODD_FLAG : 0);\n data.set(compressedPubKey.subarray(1), 1);\n return encode(network.pubKeyAddrId, data);\n}\n\n/**\n * Derive the standard P2PKH address for a public key (`hash160` of the key).\n *\n * Accepts **either** serialization: 33-byte compressed or 65-byte uncompressed.\n * They hash to different addresses, and both are legitimate — dcrd hashes\n * whichever form the caller holds — so refusing the uncompressed form would break\n * the only address a signature script built with\n * `signatureScript(..., compressed = false)` can ever satisfy.\n *\n * The key is validated as a real curve point. Without that, any byte string\n * hashes to something and produces a well-formed, valid-checksum address that no\n * key can ever spend from — and the way to hit it is mundane: passing\n * `privateKeyBytes()` where `publicKey()` was meant type-checks silently, because\n * both are `Uint8Array`, and 32 vs 33 bytes is invisible at the call site.\n */\nexport function addressFromPubKey(pubKey: Uint8Array, network: Network): string {\n assertPubKey(pubKey, \"addressFromPubKey\");\n return pubKeyHashAddress(hash160(pubKey), network);\n}\n\n/** Derive the P2SH address that pays to `redeemScript`. */\nexport function addressFromScript(redeemScript: Uint8Array, network: Network): string {\n return scriptHashAddress(hash160(redeemScript), network);\n}\n\n/**\n * Decode and validate an address. When `network` is given the address must\n * belong to it; otherwise the network is inferred from the version prefix.\n */\nexport function decodeAddress(address: string, network?: Network): DecodedAddress {\n // Bound the input before decoding. base58 decoding is quadratic, so without\n // this a long string is a cheap way to stall the event loop — and every length\n // check below happens after the decode. dcrd caps identically\n // (stdaddr.DecodeAddressV0's maxV0AddrLen): the largest version-0 address holds\n // a 33-byte payload plus a 2-byte prefix and a 4-byte checksum.\n if (typeof address !== \"string\") {\n throw err(\"invalid-argument\", \"decodeAddress\", `address must be a string, got ${typeName(address)}`);\n }\n if (address.length > MAX_ADDRESS_LENGTH) {\n throw err(\n \"input-too-long\",\n \"decodeAddress\",\n `${address.length} characters exceeds the ${MAX_ADDRESS_LENGTH}-character maximum`,\n );\n }\n const data = checkDecode(address); // throws on bad checksum\n if (data.length < 3) throw err(\"bad-length\", \"decodeAddress\", `payload is ${data.length} bytes, too short to hold a prefix and data`);\n const prefix: [number, number] = [data[0]!, data[1]!];\n const payload = data.subarray(2);\n\n const match = PREFIXES.find(\n (e) =>\n e.prefix[0] === prefix[0] &&\n e.prefix[1] === prefix[1] &&\n (!network || e.network === network),\n );\n if (!match) {\n // Distinguish \"this is not an address at all\" from \"this is a valid address\n // for a different network\", which a UI needs to say different things about,\n // and which folding both into one lookup previously made impossible.\n const hex = `0x${prefix[0]!.toString(16).padStart(2, \"0\")}${prefix[1]!\n .toString(16)\n .padStart(2, \"0\")}`;\n const onAnotherNetwork =\n network && PREFIXES.find((e) => e.prefix[0] === prefix[0] && e.prefix[1] === prefix[1]);\n if (onAnotherNetwork) {\n throw err(\n \"wrong-network\",\n \"decodeAddress\",\n `address is a ${onAnotherNetwork.kind} address for ${onAnotherNetwork.network.name}, ` +\n `not ${network.name}`,\n );\n }\n throw err(\"unknown-prefix\", \"decodeAddress\", `unknown address prefix ${hex}`);\n }\n\n if (match.kind === \"pubkey-ecdsa\") {\n // One address ID covers all three signature suites; the payload's first byte\n // says which, so the concrete kind comes from decoding rather than the prefix.\n if (payload.length !== 33) throw err(\"bad-length\", \"decodeAddress\", `pay-to-pubkey payload must be 33 bytes, got ${payload.length}`);\n const { kind, pubKey } = decodePubKeyData(payload);\n return { network: match.network, kind, pubKey, address };\n }\n if (payload.length !== 20) throw err(\"bad-length\", \"decodeAddress\", `hash payload must be 20 bytes, got ${payload.length}`);\n return {\n network: match.network,\n kind: match.kind as HashAddressKind,\n hash: copyOf(payload, 0, 20),\n address,\n };\n}\n\n/** True when `address` is a well-formed address (optionally for `network`). */\nexport function isValidAddress(address: string, network?: Network): boolean {\n try {\n decodeAddress(address, network);\n return true;\n } catch {\n return false;\n }\n}\n\n/**\n * Build the pkScript that pays to `address`.\n *\n * `network` is **required**, and deliberately so. A payment script commits only\n * to the 20-byte hash, not to the network, so `addressToScript` on a testnet\n * address produces bytes byte-identical to the mainnet address for the same hash\n * — a pasted testnet address would quietly pay whoever controls that hash on\n * mainnet. Naming the expected network here is the only thing that catches it.\n *\n * Use {@link decodeAddress} without a network when you genuinely want to inspect\n * an address of unknown origin; it returns the network it found.\n */\nexport function addressToScript(address: string, network: Network): Uint8Array {\n // Checked at runtime, not just by the type system: a JavaScript caller (or a\n // stale `.d.ts`) can still pass nothing, and silently falling back to\n // network-agnostic decoding is the exact failure this parameter exists to stop.\n if (!network || typeof network.name !== \"string\") {\n throw err(\n \"invalid-argument\",\n \"addressToScript\",\n \"a network is required (pass mainnet, testnet3, simnet or regnet)\",\n );\n }\n const d = decodeAddress(address, network);\n switch (d.kind) {\n case \"pubkeyhash-ecdsa\":\n return payToPubKeyHashScript(d.hash);\n // The alternative signature suites use OP_CHECKSIGALT with the signature\n // type pushed as a small integer (Ed25519 = 1, Schnorr = 2).\n case \"pubkeyhash-ed25519\":\n return payToPubKeyHashAltScript(d.hash, 1);\n case \"pubkeyhash-schnorr\":\n return payToPubKeyHashAltScript(d.hash, 2);\n case \"scripthash\":\n return payToScriptHashScript(d.hash);\n case \"pubkey-ecdsa\":\n return payToPubKeyScript(d.pubKey);\n case \"pubkey-ed25519\":\n return payToPubKeyAltScript(d.pubKey, 1);\n case \"pubkey-schnorr\":\n return payToPubKeyAltScript(d.pubKey, 2);\n }\n}\n\n","/**\n * WIF (Wallet Import Format) private keys, Decred style.\n *\n * Decred's WIF differs from Bitcoin's in two ways: the network prefix is two\n * bytes, and instead of Bitcoin's trailing \"compressed\" flag it carries a\n * leading signature-type byte selecting the key's signature suite. The layout\n * is `base58check(privateKeyId[2] || sigType[1] || privKey[32])`.\n */\nimport { err } from \"./errors.js\";\nimport { base58Decode, base58Encode, maxBase58Length } from \"./base58.js\";\nimport { isBytes, typeName } from \"./bytes.js\";\nimport { bytesToBigInt, ED25519_CURVE_ORDER } from \"./keys.js\";\nimport { blake256 } from \"./hash.js\";\nimport type { Network } from \"./networks.js\";\nimport { networks } from \"./networks.js\";\n\n/** Decred signature suites, matching dcrd's `dcrec.SignatureType`. */\nexport enum SignatureType {\n Ecdsa = 0,\n Ed25519 = 1,\n SchnorrSecp256k1 = 2,\n}\n\nexport interface DecodedWif {\n readonly privateKey: Uint8Array;\n readonly network: Network;\n readonly signatureType: SignatureType;\n}\n\n// Unlike addresses, WIF uses a *single* BLAKE-256 checksum (dcrd's\n// `chainhash.HashB`), not the double-BLAKE-256 of base58check.\nfunction wifChecksum(data: Uint8Array): Uint8Array {\n return blake256(data).subarray(0, 4);\n}\n\n/**\n * Throw unless an Ed25519-suite key is a scalar dcrd would accept.\n *\n * dcrd runs suite-1 keys through `edwards.PrivKeyFromScalar` on both sides of the\n * codec — `NewWIF` and `DecodeWIF` — which rejects a zero scalar and anything\n * *above* the group order. The bound really is strict: `D.Cmp(N) > 0`, so a\n * scalar equal to the order is accepted, even though it derives the identity\n * point. Matched as written, so the accept/reject boundary is identical.\n *\n * The secp256k1 suites are deliberately left unchecked, as dcrd leaves them:\n * `secp256k1.PrivKeyFromBytes` cannot fail — it reduces mod n and discards the\n * overflow — so dcrd accepts a zero or all-`ff` key for suites 0 and 2.\n */\nfunction assertWifScalar(privateKey: Uint8Array, signatureType: SignatureType, who: string): void {\n if (signatureType !== SignatureType.Ed25519) return;\n const scalar = bytesToBigInt(privateKey);\n if (scalar === 0n || scalar > ED25519_CURVE_ORDER) {\n throw err(\"invalid-private-key\", who, \"Ed25519 scalar is zero or above the group order\");\n }\n}\n\n/** Encode a 32-byte private key as WIF. */\nexport function encodeWif(\n privateKey: Uint8Array,\n network: Network,\n signatureType: SignatureType = SignatureType.Ecdsa,\n): string {\n if (!isBytes(privateKey)) throw err(\"invalid-argument\", \"encodeWif\", \"private key must be a Uint8Array\");\n if (privateKey.length !== 32) throw err(\"bad-length\", \"encodeWif\", `private key must be 32 bytes, got ${privateKey.length}`);\n // Checked here as well as on decode, because `payload[2] = signatureType` is a\n // store into a Uint8Array, which coerces rather than rejects: 256 would land as\n // suite 0, -1 as suite 255, 1.5 as suite 1, and the enum *name* \"Ed25519\" as\n // suite 0 — a well-formed WIF for a suite the caller never asked for. dcrd's\n // `NewWIF` rejects an unsupported scheme too. The integer guard is what catches\n // the last of those, since `SignatureType[\"Ed25519\"]` is 1.\n if (!Number.isInteger(signatureType) || SignatureType[signatureType] === undefined) {\n throw err(\"unsupported-signature-type\", \"encodeWif\", `unknown signature type ${signatureType}`);\n }\n assertWifScalar(privateKey, signatureType, \"encodeWif\");\n const payload = new Uint8Array(3 + 32);\n payload[0] = network.privateKeyId[0];\n payload[1] = network.privateKeyId[1];\n payload[2] = signatureType;\n payload.set(privateKey, 3);\n const full = new Uint8Array(payload.length + 4);\n full.set(payload);\n full.set(wifChecksum(payload), payload.length);\n return base58Encode(full);\n}\n\n/**\n * Longest a WIF string can be: 2 prefix + 1 suite + 32 key + 4 checksum bytes.\n */\nexport const MAX_WIF_LENGTH = maxBase58Length(39);\n\n/** Decode and validate a WIF string. */\nexport function decodeWif(wif: string): DecodedWif {\n // Bound before decoding; base58 decoding is quadratic. See maxBase58Length.\n if (typeof wif !== \"string\") {\n throw err(\"invalid-argument\", \"decodeWif\", `WIF must be a string, got ${typeName(wif)}`);\n }\n if (wif.length > MAX_WIF_LENGTH) {\n throw err(\n \"input-too-long\",\n \"decodeWif\",\n `${wif.length} characters exceeds the ${MAX_WIF_LENGTH}-character maximum`,\n );\n }\n const full = base58Decode(wif);\n if (full.length !== 39) throw err(\"bad-length\", \"decodeWif\", `decoded to ${full.length} bytes, expected 39`);\n const data = full.subarray(0, 35);\n const checksum = full.subarray(35);\n const expected = wifChecksum(data);\n for (let i = 0; i < 4; i++) {\n if (checksum[i] !== expected[i]) throw err(\"bad-checksum\", \"decodeWif\", \"checksum does not match\");\n }\n const prefix: [number, number] = [data[0]!, data[1]!];\n const signatureType = data[2]! as SignatureType;\n const privateKey = data.slice(3);\n\n const network = Object.values(networks).find(\n (n) => n.privateKeyId[0] === prefix[0] && n.privateKeyId[1] === prefix[1],\n );\n if (!network) throw err(\"unknown-prefix\", \"decodeWif\", `no network has the private-key prefix 0x${prefix[0]!.toString(16).padStart(2, \"0\")}${prefix[1]!.toString(16).padStart(2, \"0\")}`);\n // A deliberate divergence: dcrd's `DecodeWIF` switches on this byte with no\n // default arm, so an unknown suite yields a WIF holding a nil private key —\n // one whose own `String()` is no longer a WIF. Rejecting is the only sane read.\n if (SignatureType[signatureType] === undefined) {\n throw err(\"unsupported-signature-type\", \"decodeWif\", `unknown signature type ${signatureType}`);\n }\n assertWifScalar(privateKey, signatureType, \"decodeWif\");\n return { privateKey, network, signatureType };\n}\n","/**\n * BIP32 hierarchical-deterministic keys, Decred serialization.\n *\n * The serialized form uses Decred's four-byte version identifiers\n * (`dprv`/`dpub` on mainnet, `tprv`/`tpub` on testnet, …) and the\n * double-BLAKE-256 base58check checksum. Both private (signer) and public\n * (watch-only) derivation are supported.\n *\n * The seed → master-key HMAC still keys on the literal string \"Bitcoin seed\",\n * which Decred kept for compatibility.\n *\n * # Hardened derivation is not plain BIP32\n *\n * Decred also differs in the hardened child function, and the difference is\n * load-bearing. dcrd's `hdkeychain` strips leading zero bytes from a derived\n * private key and carries the shortened string into the next hardened HMAC\n * (`hdkeychain/extendedkey.go`):\n *\n * > Note that per [BIP32] this should be the fully zero-padded 32-bytes,\n * > however, the Decred variation strips leading zeros for legacy reasons and\n * > changing it now would break derivation for a lot of Decred wallets that\n * > rely on this behavior.\n *\n * So for a parent scalar with a leading zero byte the hardened HMAC input is\n * `0x00 ‖ key31 ‖ 0x00 ‖ ser32(i)` rather than BIP32's\n * `0x00 ‖ 0x00 ‖ key31 ‖ ser32(i)` — the same length, different bytes, and\n * every descendant diverges. Roughly 1 seed in 128 is affected on a BIP44 path (two hardened\n * levels below the master, each with a 1/256 chance); measured 0.8-0.9% over\n * 20,000 seeds.\n *\n * dcrd exposes both (`Child` legacy, `ChildBIP32Std` strict) and dcrwallet uses\n * the legacy one for the entire wallet path, so {@link ExtendedKey.derive} and\n * {@link ExtendedKey.derivePath} are the Decred variant. Strict BIP32 is\n * available as {@link ExtendedKey.deriveBip32Std} /\n * {@link ExtendedKey.derivePathBip32Std}.\n *\n * Getting this wrong is silent: a signer that derived strictly would show a user\n * restoring their Decrediton seed a different, empty wallet, with coins sent to\n * its addresses invisible to every other Decred wallet holding the same phrase.\n *\n * Two consequences worth knowing:\n *\n * - **Public (non-hardened) derivation is unaffected** — there is no private key\n * to strip, and a stripped scalar has the same value and therefore the same\n * public key. An account `dpub` and every address below it agree between the\n * two variants.\n * - **The stripped state does not survive serialization.** dcrd pads the scalar\n * back to 32 bytes in the extended-key string, so a key round-tripped through\n * `dprv` derives strictly from then on — in dcrd too, which this mirrors.\n * Only hardened steps are affected, and in BIP44 the deepest hardened level is\n * the account key, so this rarely shows up in practice.\n */\nimport { err } from \"./errors.js\";\nimport { hmac } from \"@noble/hashes/hmac\";\nimport { sha512 } from \"@noble/hashes/sha512\";\nimport { checkDecode, checkEncode, maxBase58Length } from \"./base58.js\";\nimport { copyOf, shown, typeName } from \"./bytes.js\";\nimport { hash160 } from \"./hash.js\";\nimport {\n isValidPrivateKey,\n isValidPublicKey,\n parsePublicKeyPoint,\n privateKeyTweakAdd,\n publicKeyFromPrivate,\n publicKeyTweakAddPoint,\n type PublicKeyPoint,\n} from \"./keys.js\";\nimport type { Network } from \"./networks.js\";\nimport { networks } from \"./networks.js\";\nimport { pubKeyHashAddress } from \"./address.js\";\n\n/** Index of the first hardened child (2^31). */\nexport const HARDENED_OFFSET = 0x80000000;\n\nconst MASTER_HMAC_KEY = new TextEncoder().encode(\"Bitcoin seed\");\nconst SERIALIZED_LENGTH = 78;\n\n/**\n * Longest a `dprv`/`dpub` string can be: the 78-byte serialization plus a 4-byte\n * checksum. Matches dcrd's `maxKeyLen` in `NewKeyFromString`.\n */\nexport const MAX_EXTENDED_KEY_LENGTH = maxBase58Length(SERIALIZED_LENGTH + 4);\n\n/**\n * Mark a BIP44 child index as hardened.\n *\n * Rejects anything outside `0..2^31-1`: adding the offset to an already-hardened\n * or out-of-range index wraps, and the result would be a *non*-hardened index\n * silently derived from the wrong branch.\n */\nexport function hardened(index: number): number {\n if (!Number.isInteger(index) || index < 0 || index >= HARDENED_OFFSET) {\n throw err(Number.isInteger(index) ? \"out-of-range\" : \"not-an-integer\", \"hardened\", `index must be an integer in 0..2^31-1, got ${shown(index)}`);\n }\n return (index + HARDENED_OFFSET) >>> 0;\n}\n\nfunction ser32(value: number): Uint8Array {\n return Uint8Array.of(\n (value >>> 24) & 0xff,\n (value >>> 16) & 0xff,\n (value >>> 8) & 0xff,\n value & 0xff,\n );\n}\n\n/** Number of leading 0x00 bytes, i.e. how many dcrd's `child` would strip. */\nfunction leadingZeros(key: Uint8Array): number {\n let n = 0;\n while (n < key.length && key[n] === 0) n++;\n return n;\n}\n\n/** A BIP32 extended key with Decred version bytes. */\nexport class ExtendedKey {\n private constructor(\n readonly network: Network,\n readonly isPrivate: boolean,\n /** 32-byte private scalar, or `null` for a public (neutered) key. */\n private readonly privateKey: Uint8Array | null,\n /** 33-byte compressed public key. */\n private readonly compressedPublicKey: Uint8Array,\n private readonly chainCodeBytes: Uint8Array,\n readonly depth: number,\n private readonly parentFingerprintBytes: Uint8Array,\n readonly childNumber: number,\n /**\n * Whether dcrd would be holding this scalar with its leading zero bytes\n * stripped, which changes the hardened HMAC input of its children (see the\n * module docs). True only for keys produced by {@link derive} — dcrd strips\n * in `child` alone, so a master key from `fromSeed` and a key parsed by\n * `fromSerialized` are both held at full width, exactly as `NewMaster` and\n * `NewKeyFromString` do. The scalar itself is always stored padded to 32\n * bytes here; only the HMAC input is narrowed.\n */\n private readonly scalarStripped: boolean = false,\n ) {}\n\n /** Memoized hash160 of the public key; see {@link identifier}. */\n private cachedIdentifier: Uint8Array | undefined = undefined;\n\n /**\n * Memoized decompression of {@link compressedPublicKey}, so deriving a chain of\n * public children does the modular square root once instead of per step. Only\n * populated on the public-derivation path.\n */\n private cachedPoint: PublicKeyPoint | undefined = undefined;\n\n /** Derive a master key from a BIP32 seed (16–64 bytes). */\n static fromSeed(seed: Uint8Array, network: Network): ExtendedKey {\n if (seed.length < 16 || seed.length > 64) {\n throw err(\"out-of-range\", \"ExtendedKey.fromSeed\", `seed must be 16..64 bytes, got ${seed.length}`);\n }\n const I = hmac(sha512, MASTER_HMAC_KEY, seed);\n const il = I.subarray(0, 32);\n const ir = I.subarray(32, 64);\n if (!isValidPrivateKey(il)) throw err(\"invalid-private-key\", \"ExtendedKey.fromSeed\", \"seed produced an unusable master key; retry with a new seed\");\n return new ExtendedKey(\n network,\n true,\n il.slice(),\n publicKeyFromPrivate(il),\n ir.slice(),\n 0,\n new Uint8Array(4),\n 0,\n );\n }\n\n /** The compressed public key (33 bytes). */\n publicKey(): Uint8Array {\n return this.compressedPublicKey.slice();\n }\n\n /** The 32-byte private scalar. Throws for a public key. */\n privateKeyBytes(): Uint8Array {\n if (!this.privateKey) throw err(\"not-a-private-key\", \"ExtendedKey.privateKeyBytes\", \"this is a public (neutered) key\");\n return this.privateKey.slice();\n }\n\n /**\n * The 32-byte chain code. A copy: the key's own derivation reads the internal\n * bytes, so handing out a live view would let a caller change what this key\n * derives.\n */\n get chainCode(): Uint8Array {\n return copyOf(this.chainCodeBytes, 0, 32);\n }\n\n /** The parent's 4-byte fingerprint, or four zero bytes for a master key. A copy. */\n get parentFingerprint(): Uint8Array {\n return copyOf(this.parentFingerprintBytes, 0, 4);\n }\n\n /**\n * Identifier = hash160(compressed pubkey); the fingerprint is its first 4 bytes.\n *\n * Memoized, because `derive` needs the parent fingerprint for every child and\n * would otherwise recompute a BLAKE-256 plus a RIPEMD-160 of the same key at\n * every step. Both accessors return copies: the memo turned what used to be a\n * per-call throwaway digest into long-lived shared state, so handing out a view\n * would let one caller's write corrupt the cache, this key's own fingerprint,\n * every sibling's `parentFingerprint` and every child derived afterwards.\n */\n identifier(): Uint8Array {\n return copyOf(this.identifierBytes(), 0, 20);\n }\n\n fingerprint(): Uint8Array {\n return copyOf(this.identifierBytes(), 0, 4);\n }\n\n /** The memoized digest itself. Never escapes this class. */\n private identifierBytes(): Uint8Array {\n if (this.cachedIdentifier === undefined) {\n this.cachedIdentifier = hash160(this.compressedPublicKey);\n }\n return this.cachedIdentifier;\n }\n\n /**\n * Derive a child key by index, the **Decred way** — the equivalent of dcrd\n * `hdkeychain.Child`, and what dcrwallet and Decrediton derive with for the\n * whole wallet path. Use {@link hardened} for hardened indices.\n *\n * This is the default because it is what the Decred ecosystem derives; see\n * {@link deriveBip32Std} for the strict form and the module docs for why they\n * differ.\n */\n derive(index: number): ExtendedKey {\n return this.deriveInner(index, false);\n }\n\n /**\n * Derive a child key by **strict BIP32** — the equivalent of dcrd\n * `hdkeychain.ChildBIP32Std`, retaining the leading zero bytes of the parent\n * private key that {@link derive} strips.\n *\n * Produces different hardened children from {@link derive} for any parent\n * scalar with a leading zero byte, which is about 1 key in 256 at each\n * hardened step. Use it only when strict BIP32 is what you want; anything that\n * has to agree with a dcrwallet or Decrediton seed must not.\n */\n deriveBip32Std(index: number): ExtendedKey {\n return this.deriveInner(index, true);\n }\n\n private deriveInner(index: number, strictBip32: boolean): ExtendedKey {\n // The serialized depth is a single byte, so refuse to go past what can be\n // round-tripped. (dcrd keeps depth as a uint16 and serializes depth%256, so\n // it will happily derive further and wrap; this is the stricter choice.)\n if (this.depth >= 255) throw err(\"max-depth\", \"ExtendedKey.derive\", \"cannot derive beyond depth 255, which is all a single byte can serialize\");\n if (!Number.isInteger(index)) throw err(\"not-an-integer\", \"ExtendedKey.derive\", `index must be an integer, got ${shown(index)}`);\n if (index < 0 || index > 0xffffffff) throw err(\"out-of-range\", \"ExtendedKey.derive\", `index ${index} is outside 0..2^32-1`);\n const idx = index >>> 0;\n const isHardened = idx >= HARDENED_OFFSET;\n\n const data = new Uint8Array(37);\n if (isHardened) {\n if (!this.privateKey) {\n throw err(\"hardened-from-public\", \"ExtendedKey.derive\", \"cannot derive a hardened child from a public key\");\n }\n // dcrd zeroes a 37-byte buffer, copies the parent scalar in at offset 1\n // and writes ser32(index) at offset 33. In the Decred variant the stored\n // scalar has had its leading zero bytes stripped, so it lands\n // LEFT-aligned at offset 1 and the gap before ser32(index) stays zero:\n //\n // strict: 0x00 ‖ 0x00 ‖ key31 ‖ ser32(i)\n // Decred: 0x00 ‖ key31 ‖ 0x00 ‖ ser32(i)\n //\n // Same length, different bytes — hence a different child.\n //\n // How the PARENT is read depends only on how the parent is stored, never on\n // which variant is being requested: dcrd's `copy(data[1:], k.key)` makes no\n // reference to its strictBIP32 flag, which gates only whether the *child*\n // it derives gets stripped. Letting `strictBip32` suppress this would make\n // derive(a).deriveBip32Std(b) disagree with dcrd's Child(a).ChildBIP32Std(b).\n const skip = this.scalarStripped ? leadingZeros(this.privateKey) : 0;\n data.set(this.privateKey.subarray(skip), 1);\n } else {\n // Non-hardened derivation commits to the public key, which is unchanged by\n // stripping (a stripped scalar has the same value), so both variants agree.\n data.set(this.compressedPublicKey, 0);\n }\n data.set(ser32(idx), 33);\n\n const I = hmac(sha512, this.chainCodeBytes, data);\n const il = I.subarray(0, 32);\n const childChainCode = I.subarray(32, 64).slice();\n const parentFp = this.fingerprint();\n const childDepth = this.depth + 1;\n\n if (this.privateKey) {\n const childPriv = privateKeyTweakAdd(this.privateKey, il);\n if (!childPriv) throw err(\"invalid-child\", \"ExtendedKey.derive\", \"derived an invalid child key; retry with the next index\");\n return new ExtendedKey(\n this.network,\n true,\n childPriv,\n publicKeyFromPrivate(childPriv),\n childChainCode,\n childDepth,\n parentFp,\n idx,\n // dcrd's `child` strips the derived scalar unless strict BIP32 was asked\n // for, and that state is what the next hardened step reads.\n !strictBip32,\n );\n }\n\n if (this.cachedPoint === undefined) {\n const parsed = parsePublicKeyPoint(this.compressedPublicKey);\n if (parsed === null) throw err(\"invalid-public-key\", \"ExtendedKey.derive\", \"public key is not a valid curve point\");\n this.cachedPoint = parsed;\n }\n const childPub = publicKeyTweakAddPoint(this.cachedPoint, il);\n if (!childPub) throw err(\"invalid-child\", \"ExtendedKey.derive\", \"derived an invalid child key; retry with the next index\");\n return new ExtendedKey(\n this.network,\n false,\n null,\n childPub,\n childChainCode,\n childDepth,\n parentFp,\n idx,\n );\n }\n\n /**\n * Derive along a path like `m/44'/42'/0'/0/0`, the **Decred way** (see\n * {@link derive}). An apostrophe or `h` marks a hardened index.\n */\n derivePath(path: string): ExtendedKey {\n return this.derivePathInner(path, false);\n }\n\n /**\n * Derive along a path using **strict BIP32** (see {@link deriveBip32Std}).\n * Diverges from {@link derivePath} below any hardened step whose parent scalar\n * has a leading zero byte, so do not use it to reproduce a wallet seed.\n */\n derivePathBip32Std(path: string): ExtendedKey {\n return this.derivePathInner(path, true);\n }\n\n private derivePathInner(path: string, strictBip32: boolean): ExtendedKey {\n const parts = path.trim().split(\"/\");\n // BIP32 writes the public chain as `M/…` and the private one as `m/…`. Both\n // name the same path; only the key you start from differs, and deriving a\n // hardened element from a public key is already rejected below. Refusing `M`\n // would break the notation a watch-only caller naturally writes.\n if (parts[0] === \"m\" || parts[0] === \"M\") parts.shift();\n let key: ExtendedKey = this;\n for (const raw of parts) {\n const isH = raw.endsWith(\"'\") || raw.endsWith(\"h\") || raw.endsWith(\"H\");\n const numStr = isH ? raw.slice(0, -1) : raw;\n // Strict decimal only — `Number()` would accept \"0x10\", \"1e2\", \"\", etc.\n if (!/^\\d+$/.test(numStr)) {\n // `shown` caps and escapes: a path segment is any run of characters\n // between slashes, so this is the one message here whose length the\n // caller picks outright.\n throw err(\"invalid-path\", \"ExtendedKey.derivePath\", `invalid path element ${shown(raw)}`);\n }\n const n = Number(numStr);\n if (n >= HARDENED_OFFSET) {\n throw err(\"invalid-path\", \"ExtendedKey.derivePath\", `path index ${n} is at or above the hardened offset; write it as ${n - HARDENED_OFFSET}' instead`);\n }\n const idx = isH ? hardened(n) : n;\n key = strictBip32 ? key.deriveBip32Std(idx) : key.derive(idx);\n }\n return key;\n }\n\n /** Return the public (watch-only) version of this key. */\n neuter(): ExtendedKey {\n if (!this.isPrivate) return this;\n return new ExtendedKey(\n this.network,\n false,\n null,\n this.compressedPublicKey,\n this.chainCodeBytes,\n this.depth,\n this.parentFingerprintBytes,\n this.childNumber,\n );\n }\n\n /** The standard P2PKH address for this key on its network. */\n address(network: Network = this.network): string {\n return pubKeyHashAddress(hash160(this.compressedPublicKey), network);\n }\n\n /** Serialize to the 78-byte BIP32 form (without the base58check checksum). */\n serialize(): Uint8Array {\n const version = this.isPrivate ? this.network.hdPrivateKeyId : this.network.hdPublicKeyId;\n const out = new Uint8Array(SERIALIZED_LENGTH);\n out[0] = version[0];\n out[1] = version[1];\n out[2] = version[2];\n out[3] = version[3];\n out[4] = this.depth & 0xff;\n out.set(this.parentFingerprintBytes, 5);\n out.set(ser32(this.childNumber), 9);\n out.set(this.chainCodeBytes, 13);\n if (this.isPrivate) {\n out[45] = 0x00;\n out.set(this.privateKey!, 46);\n } else {\n out.set(this.compressedPublicKey, 45);\n }\n return out;\n }\n\n /** Encode as a `dprv`/`dpub` (or per-network) base58check string. */\n toString(): string {\n return checkEncode(this.serialize());\n }\n\n /** Parse an extended key string, validating the checksum and version. */\n static fromString(str: string): ExtendedKey {\n // Bound before decoding; base58 decoding is quadratic, so an unbounded string\n // burns CPU proportional to its length squared. dcrd caps identically\n // (hdkeychain.NewKeyFromString's maxKeyLen).\n if (typeof str !== \"string\") {\n throw err(\n \"invalid-argument\",\n \"ExtendedKey.fromString\",\n `extended key must be a string, got ${typeName(str)}`,\n );\n }\n if (str.length > MAX_EXTENDED_KEY_LENGTH) {\n throw err(\n \"input-too-long\",\n \"ExtendedKey.fromString\",\n `${str.length} characters exceeds the ${MAX_EXTENDED_KEY_LENGTH}-character maximum`,\n );\n }\n const data = checkDecode(str);\n return ExtendedKey.fromSerialized(data);\n }\n\n /**\n * Parse a raw 78-byte serialization (checksum already verified/absent).\n *\n * Every field is copied out of `data`, so the returned key does not alias the\n * caller's buffer — which matters most here, because a caller doing the right\n * thing and wiping the serialization after parsing would otherwise destroy the\n * key it just parsed. See {@link copyOf}.\n */\n static fromSerialized(data: Uint8Array): ExtendedKey {\n if (data.length !== SERIALIZED_LENGTH) throw err(\"bad-length\", \"ExtendedKey.fromSerialized\", `expected ${SERIALIZED_LENGTH} bytes, got ${data.length}`);\n const version: [number, number, number, number] = [data[0]!, data[1]!, data[2]!, data[3]!];\n const depth = data[4]!;\n const parentFingerprint = copyOf(data, 5, 4);\n const childNumber =\n ((data[9]! << 24) | (data[10]! << 16) | (data[11]! << 8) | data[12]!) >>> 0;\n const chainCode = copyOf(data, 13, 32);\n const keyData = copyOf(data, 45, 33);\n\n const found = matchVersion(version);\n if (!found) throw err(\"unknown-version\", \"ExtendedKey.fromSerialized\", `no network has the extended-key version 0x${version.map((b) => b.toString(16).padStart(2, \"0\")).join(\"\")}`);\n const { network, isPrivate } = found;\n\n if (isPrivate) {\n if (keyData[0] !== 0x00) throw err(\"invalid-private-key\", \"ExtendedKey.fromSerialized\", `a private key must be padded with a leading 0x00, got 0x${keyData[0]!.toString(16).padStart(2, \"0\")}`);\n const priv = copyOf(keyData, 1, 32);\n if (!isValidPrivateKey(priv)) throw err(\"invalid-private-key\", \"ExtendedKey.fromSerialized\", \"not a valid secp256k1 scalar\");\n return new ExtendedKey(\n network,\n true,\n priv,\n publicKeyFromPrivate(priv),\n chainCode,\n depth,\n parentFingerprint,\n childNumber,\n );\n }\n if (keyData[0] !== 0x02 && keyData[0] !== 0x03) {\n throw err(\"invalid-public-key\", \"ExtendedKey.fromSerialized\", `a compressed public key must start with 0x02 or 0x03, got 0x${keyData[0]!.toString(16).padStart(2, \"0\")}`);\n }\n if (!isValidPublicKey(keyData)) {\n throw err(\"invalid-public-key\", \"ExtendedKey.fromSerialized\", \"public key is not a valid curve point\");\n }\n return new ExtendedKey(\n network,\n false,\n null,\n keyData,\n chainCode,\n depth,\n parentFingerprint,\n childNumber,\n );\n }\n}\n\ninterface VersionMatch {\n network: Network;\n isPrivate: boolean;\n}\n\nfunction matchVersion(v: readonly number[]): VersionMatch | null {\n for (const network of Object.values(networks)) {\n if (eq4(v, network.hdPrivateKeyId)) return { network, isPrivate: true };\n if (eq4(v, network.hdPublicKeyId)) return { network, isPrivate: false };\n }\n return null;\n}\n\nfunction eq4(a: readonly number[], b: readonly number[]): boolean {\n return a[0] === b[0] && a[1] === b[1] && a[2] === b[2] && a[3] === b[3];\n}\n\n","/**\n * BIP39 mnemonics.\n *\n * A thin, Decred-flavoured wrapper over the audited `@scure/bip39`. The mnemonic\n * standard is not Decred-specific; the Decred part is expanding the resulting\n * seed into a {@link ExtendedKey} with the right network version bytes.\n *\n * Every function takes an optional `wordlist` and defaults to English. BIP39\n * defines eight more, and a phrase in one of them is just as valid — the seed\n * derivation itself does not depend on the wordlist at all, only the checksum\n * check does. Import the list you need from `@scure/bip39/wordlists/…`.\n */\nimport { err } from \"./errors.js\";\nimport { shown } from \"./bytes.js\";\nimport {\n entropyToMnemonic as scureEntropyToMnemonic,\n generateMnemonic as scureGenerateMnemonic,\n mnemonicToEntropy as scureMnemonicToEntropy,\n mnemonicToSeedSync,\n validateMnemonic as scureValidateMnemonic,\n} from \"@scure/bip39\";\nimport { wordlist as english } from \"@scure/bip39/wordlists/english\";\nimport { ExtendedKey } from \"./hd.js\";\nimport type { Network } from \"./networks.js\";\n\n/** A BIP39 wordlist: 2048 words. Defaults to English throughout this module. */\nexport type Wordlist = readonly string[];\n\n/** The English BIP39 wordlist, used wherever `wordlist` is omitted. */\nexport const englishWordlist: Wordlist = english;\n\n/** The five word counts BIP39 defines. Anything else is not a mnemonic. */\nconst MNEMONIC_WORD_COUNTS: readonly number[] = [12, 15, 18, 21, 24];\n\n/**\n * Throw unless `mnemonic` is a string.\n *\n * Separated from the phrase checks because it is a different fault with a\n * different remedy: `@scure` reports it as the same untyped throw as a bad\n * checksum, and folding the two together told a caller who passed a number that\n * their checksum was wrong.\n */\nfunction assertMnemonicString(mnemonic: string, who: string): void {\n if (typeof mnemonic !== \"string\") {\n throw err(\"invalid-argument\", who, `mnemonic must be a string, got ${typeof mnemonic}`);\n }\n}\n\n/**\n * Throw unless `wordlist` holds the 2048 words BIP39 requires.\n *\n * `Wordlist` is `readonly string[]`, so a list of the wrong size type-checks\n * fine — and this module invites callers to bring their own. `@scure` rejects it\n * with a plain `Error`, which would escape the typed-error contract.\n */\nfunction assertWordlist(wordlist: Wordlist, who: string): void {\n if (wordlist.length !== 2048) {\n throw err(\"invalid-argument\", who, `wordlist must hold 2048 words, got ${wordlist.length}`);\n }\n}\n\n/** Generate a new mnemonic. `strength` is entropy bits (128–256, default 128). */\nexport function generateMnemonic(strength = 128, wordlist: Wordlist = english): string {\n // `@scure` also rejects everything outside this set, but two layers down, as a\n // plain `Error` about a byte length the caller never named.\n if (!Number.isInteger(strength) || strength < 128 || strength > 256 || strength % 32 !== 0) {\n throw err(\n Number.isInteger(strength) ? \"out-of-range\" : \"not-an-integer\",\n \"generateMnemonic\",\n `strength must be 128, 160, 192, 224 or 256 bits, got ${shown(strength)}`,\n );\n }\n assertWordlist(wordlist, \"generateMnemonic\");\n return scureGenerateMnemonic(wordlist as string[], strength);\n}\n\n/** Validate a mnemonic's checksum and wordlist membership. */\nexport function validateMnemonic(mnemonic: string, wordlist: Wordlist = english): boolean {\n return scureValidateMnemonic(mnemonic, wordlist as string[]);\n}\n\n/** Recover the raw entropy behind a mnemonic. */\nexport function mnemonicToEntropy(mnemonic: string, wordlist: Wordlist = english): Uint8Array {\n assertMnemonicString(mnemonic, \"mnemonicToEntropy\");\n assertWordlist(wordlist, \"mnemonicToEntropy\");\n // Every remaining failure — word count, unknown word, checksum — is one code to\n // the caller, so catching is enough and costs nothing; pre-validating would\n // decode twice. `@scure`'s own message is worth discarding: for an unknown word\n // it inlines the whole 2048-word list.\n try {\n return scureMnemonicToEntropy(mnemonic, wordlist as string[]);\n } catch {\n throw err(\n \"invalid-mnemonic\",\n \"mnemonicToEntropy\",\n \"bad checksum, wrong word count, or a word not in the wordlist — pass the \" +\n \"matching wordlist for a non-English phrase\",\n );\n }\n}\n\n/** Encode entropy (16–32 bytes, multiple of 4) as a mnemonic. */\nexport function entropyToMnemonic(entropy: Uint8Array, wordlist: Wordlist = english): string {\n if (entropy.length < 16 || entropy.length > 32 || entropy.length % 4 !== 0) {\n throw err(\n \"bad-length\",\n \"entropyToMnemonic\",\n `entropy must be 16–32 bytes and a multiple of 4, got ${entropy.length}`,\n );\n }\n assertWordlist(wordlist, \"entropyToMnemonic\");\n return scureEntropyToMnemonic(entropy, wordlist as string[]);\n}\n\n/**\n * Expand a mnemonic (with optional passphrase) into the 64-byte BIP39 seed.\n *\n * Checksum-unchecked, by design: derivation does not consult a wordlist, so any\n * phrase of a legal length expands whether or not its words are in a list and\n * whether or not its checksum holds. Use {@link mnemonicToMasterKey} to get the\n * checksum verified first. The word count *is* enforced: BIP39 is defined only\n * for 12, 15, 18, 21 or 24 words.\n *\n * Both failures are checked here rather than caught from `@scure`, and the two\n * checks are exhaustive: `mnemonicToSeedSync` reaches the caller's input only\n * through `nfkd`, which rejects a non-string, and `normalize`, which rejects a\n * word count outside the five. Its salt is `\"mnemonic\" + passphrase`, a\n * concatenation that always yields a string, and its PBKDF2 parameters are\n * constants — so nothing else in it can throw. Catching instead would report\n * `invalid-mnemonic` for a future `@scure` failure that has nothing to do with\n * the mnemonic, which is the one direction that wastes the most debugging time.\n */\nexport function mnemonicToSeed(mnemonic: string, passphrase = \"\"): Uint8Array {\n assertMnemonicString(mnemonic, \"mnemonicToSeed\");\n // NFKD before counting, and split on a single space, because that is what\n // `@scure` does: normalization can *create* a word boundary, since it maps a\n // no-break space to a plain one.\n const words = mnemonic.normalize(\"NFKD\").split(\" \").length;\n if (!MNEMONIC_WORD_COUNTS.includes(words)) {\n throw err(\n \"invalid-mnemonic\",\n \"mnemonicToSeed\",\n `a mnemonic is 12, 15, 18, 21 or 24 words, got ${words}`,\n );\n }\n return mnemonicToSeedSync(mnemonic, passphrase);\n}\n\n/**\n * Expand a mnemonic straight into a Decred master {@link ExtendedKey}.\n *\n * The mnemonic's checksum is verified first, against `wordlist` (English by\n * default). Because seed derivation consults no wordlist, a typo'd or\n * mis-transcribed phrase of the right length would otherwise expand happily into\n * a different, valid-looking wallet — one of the classic ways to lose funds while\n * every operation appears to succeed.\n *\n * Pass the matching `wordlist` for a non-English phrase; validating a Spanish\n * mnemonic against the English list would reject a perfectly good one. Use\n * {@link mnemonicToSeed} directly if you specifically want the unchecked\n * primitive.\n */\nexport function mnemonicToMasterKey(\n mnemonic: string,\n network: Network,\n passphrase = \"\",\n wordlist: Wordlist = english,\n): ExtendedKey {\n // `validateMnemonic` answers `false` for a non-string rather than throwing, so\n // without this the message below would blame the checksum for a type error.\n assertMnemonicString(mnemonic, \"mnemonicToMasterKey\");\n assertWordlist(wordlist, \"mnemonicToMasterKey\");\n if (!validateMnemonic(mnemonic, wordlist)) {\n throw err(\n \"invalid-mnemonic\",\n \"mnemonicToMasterKey\",\n \"bad checksum, or a word not in the wordlist — pass the matching wordlist \" +\n \"for a non-English phrase\",\n );\n }\n return ExtendedKey.fromSeed(mnemonicToSeed(mnemonic, passphrase), network);\n}\n","/**\n * The Decred transaction wire format (`MsgTx`).\n *\n * A Decred transaction is split into a **prefix** and a **witness**. The prefix\n * holds the non-malleable data (outpoints, outputs, locktime, expiry); the\n * witness holds the input amounts, the block height/index of the funding output\n * and the signature scripts. The transaction id is the BLAKE-256 of the prefix\n * only, which is what makes it stable under signing.\n *\n * The 32-bit version word packs the real version in its low 16 bits and a\n * serialization-type selector in its high 16 bits.\n */\nimport { err } from \"./errors.js\";\nimport { blake256 } from \"./hash.js\";\nimport { copyOf, isBytes, Reader, shown, typeName, Writer } from \"./bytes.js\";\n\n/** Transaction serialization selectors (encoded in the version word). */\nexport enum TxSerializeType {\n Full = 0,\n NoWitness = 1,\n OnlyWitness = 2,\n}\n\n/**\n * Largest serialization type that fits the high half of the version word.\n *\n * `TxSerializeType` stops at 2, but `sighash.ts` packs dcrd's\n * `SigHashSerializeWitness` (3) into the same field, so the wire-level bound is\n * 3 even though only three values are transaction serialization types.\n */\nconst MAX_SERIALIZE_TYPE = 3;\n\n/** Output tree: regular spends vs. the stake tree. */\nexport enum TxTree {\n Regular = 0,\n Stake = 1,\n}\n\nexport const DEFAULT_TX_VERSION = 1;\nexport const MAX_SEQUENCE = 0xffffffff;\n/**\n * Sentinel \"unknown\" input amount / block position used for unsigned inputs,\n * matching dcrd's `wire.NullValueIn` / `NullBlockHeight` / `NullBlockIndex`.\n *\n * Note the asymmetry, which is dcrd's and not a typo here: the null block\n * *height* is `0` (\"it references the genesis block\") while the null block\n * *index* is `0xffffffff`.\n */\nexport const NULL_VALUE_IN = -1n;\nexport const NULL_BLOCK_HEIGHT = 0;\nexport const NULL_BLOCK_INDEX = 0xffffffff;\n\nexport interface OutPoint {\n /** 32-byte transaction hash in internal (serialized) byte order. */\n hash: Uint8Array;\n index: number;\n tree: number;\n}\n\nexport interface TxInput {\n previousOutPoint: OutPoint;\n sequence: number;\n // Witness fields:\n valueIn: bigint;\n blockHeight: number;\n blockIndex: number;\n signatureScript: Uint8Array;\n}\n\nexport interface TxOutput {\n value: bigint;\n version: number;\n pkScript: Uint8Array;\n}\n\nfunction reverse(bytes: Uint8Array): Uint8Array {\n const out = new Uint8Array(bytes.length);\n for (let i = 0; i < bytes.length; i++) out[i] = bytes[bytes.length - 1 - i]!;\n return out;\n}\n\nfunction toHex(bytes: Uint8Array): string {\n let s = \"\";\n for (const b of bytes) s += b.toString(16).padStart(2, \"0\");\n return s;\n}\n\n/**\n * Pack the 32-bit version word: serialization type in the high 16 bits, the\n * transaction version in the low 16. Shared with the signature hash, whose\n * serialization types are its own (see sighash.ts).\n *\n * The version is range-checked rather than only masked, for the reason\n * `checkUint` gives in bytes.ts: `& 0xffff` quietly turns 65537 into 1, -1 into\n * 65535 and `NaN` into 0, so the caller would get bytes — and a txid, and a\n * signature — for a version they never asked for. The other 16-bit field in this\n * serializer, `TxOutput.version`, already throws on exactly these inputs, since\n * `writePrefixBody` writes it with `Writer.u16`. dcrd cannot express the case at\n * all: `wire.MsgTx.Version` is a uint16, and the high half of this word is the\n * serialization type — which is also why the mask cannot simply be dropped, as an\n * out-of-range version would then corrupt the serialization type.\n */\nexport function packVersion(version: number, serType: number): number {\n if (!Number.isInteger(version) || version < 0 || version > 0xffff) {\n throw err(\n Number.isInteger(version) ? \"out-of-range\" : \"not-an-integer\",\n \"tx.version\",\n `expected an integer in 0..2^16-1, got ${shown(version)}`,\n );\n }\n // The same argument, for the other half of the word. `<<` coerces its left\n // operand to int32, so an unchecked type wraps exactly the way an unchecked\n // version would: a type of 65536 shifts clean off the top and silently\n // becomes 0, i.e. Full, and a negative one sets the version bits as well.\n // Both hand back a valid-looking word for a transaction the caller never\n // described.\n //\n // The ceiling is 3 rather than `TxSerializeType.OnlyWitness` because the\n // signature hash reuses this field with dcrd's own pseudo-types, where the\n // witness half is 3 (`SigHashSerializeWitness`) — a value with no\n // `TxSerializeType` member. Four bit patterns are meaningful; the rest are\n // not.\n if (!Number.isInteger(serType) || serType < 0 || serType > MAX_SERIALIZE_TYPE) {\n throw err(\n Number.isInteger(serType) ? \"out-of-range\" : \"not-an-integer\",\n \"tx.serializeType\",\n `expected an integer in 0..${MAX_SERIALIZE_TYPE}, got ${shown(serType)}`,\n );\n }\n return ((serType << 16) | version) >>> 0;\n}\n\n/** A mutable Decred transaction. */\nexport class Transaction {\n version = DEFAULT_TX_VERSION;\n inputs: TxInput[] = [];\n outputs: TxOutput[] = [];\n lockTime = 0;\n expiry = 0;\n\n /**\n * Add an input. Witness fields default to the \"unsigned/unknown\" sentinels.\n *\n * The outpoint and signature script are copied, so a caller that reuses or\n * scrubs its own buffers afterwards cannot silently rewrite this transaction's\n * bytes — which would change its txid and invalidate every signature already\n * computed over it, with nothing to detect the change.\n */\n addInput(\n previousOutPoint: OutPoint,\n opts: Partial<Omit<TxInput, \"previousOutPoint\">> = {},\n ): this {\n if (previousOutPoint === null || typeof previousOutPoint !== \"object\") {\n throw err(\n \"invalid-argument\",\n \"tx.addInput\",\n `outpoint must be an object, got ${typeName(previousOutPoint)}`,\n );\n }\n if (!isBytes(previousOutPoint.hash)) {\n throw err(\n \"invalid-argument\",\n \"tx.addInput\",\n `outpoint hash must be a Uint8Array, got ${typeName(previousOutPoint.hash)}`,\n );\n }\n if (previousOutPoint.hash.length !== 32) {\n throw err(\n \"bad-length\",\n \"tx.addInput\",\n `outpoint hash must be 32 bytes, got ${previousOutPoint.hash.length}`,\n );\n }\n // dcrd types Tree as int8 and defines TxTreeUnknown = -1, but only Regular (0)\n // and Stake (1) are consensus-valid, and the unsigned writer would otherwise\n // reject anything else with a message about bytes rather than about the tree.\n // Parsing stays permissive (fromBytes accepts any byte, as dcrd's decoder\n // does); this is the construction path.\n if (previousOutPoint.tree !== TxTree.Regular && previousOutPoint.tree !== TxTree.Stake) {\n throw err(\n \"out-of-range\",\n \"tx.addInput\",\n `outpoint tree must be ${TxTree.Regular} (regular) or ${TxTree.Stake} (stake), ` +\n `got ${shown(previousOutPoint.tree)}`,\n );\n }\n this.inputs.push({\n previousOutPoint: {\n hash: copyOf(previousOutPoint.hash, 0, 32),\n index: previousOutPoint.index,\n tree: previousOutPoint.tree,\n },\n sequence: opts.sequence ?? MAX_SEQUENCE,\n valueIn: opts.valueIn ?? NULL_VALUE_IN,\n blockHeight: opts.blockHeight ?? NULL_BLOCK_HEIGHT,\n blockIndex: opts.blockIndex ?? NULL_BLOCK_INDEX,\n signatureScript: opts.signatureScript\n ? copyOf(opts.signatureScript, 0, opts.signatureScript.length)\n : new Uint8Array(0),\n });\n return this;\n }\n\n /** Add an output. The script is copied; see {@link addInput}. */\n addOutput(value: bigint, pkScript: Uint8Array, version = 0): this {\n if (!isBytes(pkScript)) {\n throw err(\n \"invalid-argument\",\n \"tx.addOutput\",\n `pkScript must be a Uint8Array, got ${typeName(pkScript)}`,\n );\n }\n this.outputs.push({ value, version, pkScript: copyOf(pkScript, 0, pkScript.length) });\n return this;\n }\n\n private writeVersion(w: Writer, serType: TxSerializeType): void {\n w.u32(packVersion(this.version, serType));\n }\n\n private writePrefixBody(w: Writer): void {\n w.varInt(this.inputs.length);\n for (const input of this.inputs) {\n const op = input.previousOutPoint;\n if (op.hash.length !== 32) throw err(\"bad-length\", \"tx\", `outpoint hash must be 32 bytes, got ${op.hash.length}`);\n w.bytes(op.hash).u32(op.index).u8(op.tree).u32(input.sequence);\n }\n w.varInt(this.outputs.length);\n for (const out of this.outputs) {\n w.i64(out.value).u16(out.version).varBytes(out.pkScript);\n }\n w.u32(this.lockTime).u32(this.expiry);\n }\n\n private writeWitnessBody(w: Writer): void {\n w.varInt(this.inputs.length);\n for (const input of this.inputs) {\n w.i64(input.valueIn)\n .u32(input.blockHeight)\n .u32(input.blockIndex)\n .varBytes(input.signatureScript);\n }\n }\n\n /** Serialize as prefix ‖ witness (the full form). */\n serialize(): Uint8Array {\n const w = new Writer();\n this.writeVersion(w, TxSerializeType.Full);\n this.writePrefixBody(w);\n this.writeWitnessBody(w);\n return w.finish();\n }\n\n /** Serialize the prefix only (no witness). This is what the txid hashes. */\n serializePrefix(): Uint8Array {\n const w = new Writer();\n this.writeVersion(w, TxSerializeType.NoWitness);\n this.writePrefixBody(w);\n return w.finish();\n }\n\n /** Serialize the witness only. */\n serializeWitness(): Uint8Array {\n const w = new Writer();\n this.writeVersion(w, TxSerializeType.OnlyWitness);\n this.writeWitnessBody(w);\n return w.finish();\n }\n\n /** Raw 32-byte prefix hash (internal byte order). */\n hash(): Uint8Array {\n return blake256(this.serializePrefix());\n }\n\n /** The transaction id (reversed-hex display form of the prefix hash). */\n txid(): string {\n return toHex(reverse(this.hash()));\n }\n\n /** The witness hash id (display form). */\n witnessTxid(): string {\n return toHex(reverse(blake256(this.serializeWitness())));\n }\n\n /** The full hash id: `blake256(prefixHash ‖ witnessHash)`, display form. */\n fullTxid(): string {\n const concat = new Uint8Array(64);\n concat.set(blake256(this.serializePrefix()), 0);\n concat.set(blake256(this.serializeWitness()), 32);\n return toHex(reverse(blake256(concat)));\n }\n\n /**\n * Parse a full (prefix ‖ witness) serialization.\n *\n * The declared input and output counts are deliberately **not** capped, where\n * dcrd's `decodePrefix` and `decodeWitness` reject anything above\n * `maxTxInPerMessage` (780336) or `maxTxOutPerMessage` (3728271) — the counts\n * that could fit a 32 MiB `MaxMessagePayload`. Those bounds exist because dcrd\n * decodes from an `io.Reader` of unknown length and sizes `make([]TxIn, count)`\n * from the count *before* reading an input; here the argument is a `Uint8Array`\n * whose length is already the bound, and nothing is sized from a count —\n * `Reader` checks every read against the bytes that remain, so an inflated\n * count fails at the first short read having allocated nothing. The only\n * observable difference is that a blob of ~43 MiB or larger declaring more than\n * 780336 inputs parses here and does not in dcrd; such a transaction is neither\n * relayable (over `MaxMessagePayload`) nor valid (mainnet `MaxTxSize` is 393216\n * bytes, 115x smaller). On a *truncated* blob both reject, only with different\n * errors: dcrd's `ErrTooManyTxs` against this library's `unexpected-end`.\n *\n * Cost is still linear in `bytes.length`, so cap the size of untrusted input at\n * the call site. dcrd's count limits would not help with that: 32 MiB holds\n * 818400 minimal prefix inputs and the cap is 780336, so a buffer at the wire\n * maximum stays under it.\n */\n static fromBytes(bytes: Uint8Array): Transaction {\n const r = new Reader(bytes);\n const versionWord = r.u32();\n const serType = (versionWord >>> 16) as TxSerializeType;\n if (serType !== TxSerializeType.Full) {\n throw err(\"invalid-argument\", \"tx.fromBytes\", `expects the full serialization, got serialization type ${serType}`);\n }\n const tx = new Transaction();\n tx.version = versionWord & 0xffff;\n\n // Prefix.\n const numIn = r.varInt();\n const prefixes: OutPoint[] = [];\n const sequences: number[] = [];\n for (let i = 0; i < numIn; i++) {\n const hash = r.bytes(32);\n const index = r.u32();\n const tree = r.u8();\n const sequence = r.u32();\n prefixes.push({ hash, index, tree });\n sequences.push(sequence);\n }\n const numOut = r.varInt();\n for (let i = 0; i < numOut; i++) {\n const value = r.i64();\n const version = r.u16();\n const pkScript = r.varBytes();\n tx.outputs.push({ value, version, pkScript });\n }\n tx.lockTime = r.u32();\n tx.expiry = r.u32();\n\n // Witness.\n const numWit = r.varInt();\n if (numWit !== numIn) throw err(\"bad-length\", \"tx.fromBytes\", `witness declares ${numWit} inputs, prefix declares ${numIn}`);\n for (let i = 0; i < numIn; i++) {\n const valueIn = r.i64();\n const blockHeight = r.u32();\n const blockIndex = r.u32();\n const signatureScript = r.varBytes();\n tx.inputs.push({\n previousOutPoint: prefixes[i]!,\n sequence: sequences[i]!,\n valueIn,\n blockHeight,\n blockIndex,\n signatureScript,\n });\n }\n if (r.remaining !== 0) throw err(\"trailing-bytes\", \"tx.fromBytes\", `${r.remaining} byte(s) remain after the transaction`);\n return tx;\n }\n}\n\n/** Build an OutPoint from a txid *string* (reverses to internal byte order). */\nexport function outPointFromTxid(txid: string, index: number, tree = TxTree.Regular): OutPoint {\n if (!/^[0-9a-fA-F]{64}$/.test(txid)) {\n throw err(\"invalid-argument\", \"outPointFromTxid\", \"txid must be 64 hex characters\");\n }\n const display = new Uint8Array(32);\n for (let i = 0; i < 32; i++) display[i] = parseInt(txid.slice(i * 2, i * 2 + 2), 16);\n return { hash: reverse(display), index, tree };\n}\n","/**\n * The Decred signature hash.\n *\n * Decred does not use Bitcoin's BIP143. Instead the message to sign is\n * `BLAKE256( le32(hashType) || prefixHash || witnessHash )`, where the prefix\n * and witness are re-serialized subsets of the transaction selected by the\n * hash type. This mirrors dcrd's `txscript.CalcSignatureHash` byte-for-byte.\n *\n * The version words embedded in the prefix/witness serializations use dedicated\n * signature-hash serialization types (prefix = 1, witness = **3**), which are\n * fixed by consensus and differ from the wire serialization types.\n */\nimport { err } from \"./errors.js\";\nimport { blake256 } from \"./hash.js\";\nimport { shown, Writer } from \"./bytes.js\";\nimport { scriptParses } from \"./script.js\";\nimport { packVersion, type Transaction } from \"./tx.js\";\n\nexport enum SigHashType {\n All = 0x01,\n None = 0x02,\n Single = 0x03,\n AnyOneCanPay = 0x80,\n}\n\nconst SIG_HASH_MASK = 0x1f;\nconst SIG_HASH_SERIALIZE_PREFIX = 1;\nconst SIG_HASH_SERIALIZE_WITNESS = 3;\n\n/**\n * True when `hashType` is one dcrd's script engine will accept, i.e. the six\n * values `CheckHashTypeEncoding` permits: All/None/Single, each optionally\n * OR'ed with AnyOneCanPay.\n *\n * Note {@link calcSignatureHash} deliberately still computes a hash for other\n * byte values, because dcrd's `calcSignatureHash` does — undefined types hash as\n * if they were All. Validation belongs at the point a signature is *produced*,\n * which is where {@link assertSignableSigHashType} is applied.\n */\nexport function isSignableSigHashType(hashType: number): boolean {\n if (!Number.isInteger(hashType) || hashType < 0 || hashType > 0xff) return false;\n const masked = hashType & 0x7f; // dcrd: hashType & ^SigHashAnyOneCanPay\n return masked >= SigHashType.All && masked <= SigHashType.Single;\n}\n\n/** Throw unless `hashType` is one dcrd's engine accepts. */\nexport function assertSignableSigHashType(hashType: number): void {\n if (!isSignableSigHashType(hashType)) {\n const label = Number.isInteger(hashType)\n ? `0x${Number(hashType).toString(16)}`\n : shown(hashType);\n throw err(\n \"invalid-hash-type\",\n \"sighash\",\n `hash type ${label} is not one dcrd accepts (All/None/Single, optionally |AnyOneCanPay)`,\n );\n }\n}\n\n/**\n * The reusable prefix hash for `SigHashAll` without `AnyOneCanPay`.\n *\n * Under that hash type the prefix half of the signature hash does not depend on\n * which input is being signed, and its serialization is byte-identical to the\n * transaction's own prefix serialization — `SigHashSerializePrefix` and\n * `TxSerializeNoWitness` are both `1`, and the bodies are the same. So this is\n * exactly `tx.hash()`, and passing it to {@link calcSignatureHash} as\n * `cachedPrefix` removes the dominant per-input cost when signing.\n *\n * It does **not** make signing linear. The witness half still walks every input\n * on each call (one varint apiece), so signing N inputs stays O(N²) — but the\n * prefix half is the expensive one, since it re-serializes every outpoint and\n * every output script, so the constant drops by more than an order of magnitude.\n * Measured on the hashing alone: 12x at 50 inputs, 26x at 500.\n *\n * This is what dcrd's `cachedPrefix` parameter exists for.\n */\nexport function sigHashPrefixAll(tx: Transaction): Uint8Array {\n return tx.hash();\n}\n\n/**\n * Compute the signature hash for input `idx` of `tx` under `hashType`, with\n * `subScript` as the script being satisfied (the prevout pkScript for P2PKH, or\n * the redeem script for P2SH). Returns the 32-byte hash to be signed.\n *\n * `cachedPrefix` is an optional pre-computed prefix hash from\n * {@link sigHashPrefixAll}, honoured only for `SigHashAll` without\n * `AnyOneCanPay` — the one case where the prefix half is input-independent. It is\n * ignored for every other hash type rather than trusted, so it is safe to pass\n * for *any hash type*.\n *\n * It is **not** checked against `tx`, because a 32-byte hash carries nothing to\n * check it with: it must be this transaction's current prefix hash. Passing a\n * stale one — taken before the prefix was changed, or from a different\n * transaction — silently produces a signature over the wrong message. Take it\n * from the transaction you are about to sign, after the prefix is final, or use\n * {@link signP2PKHInputs}, which does that for you.\n */\nexport function calcSignatureHash(\n subScript: Uint8Array,\n hashType: SigHashType | number,\n tx: Transaction,\n idx: number,\n cachedPrefix?: Uint8Array,\n): Uint8Array {\n // dcrd's SigHashType is a byte, and the final preimage commits to it as a\n // little-endian uint32 while a signature script carries only the low byte. A\n // value above 0xff would therefore be committed to in full but transmitted\n // truncated, so a verifier would recompute a different hash and the signature\n // could never verify. Reject rather than silently produce that.\n if (!Number.isInteger(hashType) || hashType < 0 || hashType > 0xff) {\n throw err(\"invalid-hash-type\", \"sighash\", `hash type must be a byte (0..255), got ${shown(hashType)}`);\n }\n // NaN and fractional indices slip past both comparisons below (every relational\n // test against NaN is false), leaving a hash that commits the subScript to no\n // input at all.\n if (!Number.isInteger(idx)) {\n throw err(\"not-an-integer\", \"sighash\", `input index must be an integer, got ${shown(idx)}`);\n }\n\n const masked = hashType & SIG_HASH_MASK;\n const anyoneCanPay = (hashType & SigHashType.AnyOneCanPay) !== 0;\n\n // dcrd's exported CalcSignatureHash gates on checkScriptParses before hashing;\n // signing against a script that does not tokenize yields a signature over a\n // message dcrd would refuse to compute, i.e. an unspendable input.\n if (!scriptParses(subScript)) {\n throw err(\"malformed-script\", \"sighash\", \"subScript does not tokenize (malformed data push)\");\n }\n\n if (masked === SigHashType.Single && idx >= tx.outputs.length) {\n throw err(\n \"out-of-range\",\n \"sighash\",\n `SigHashSingle input ${idx} has no corresponding output`,\n );\n }\n if (idx < 0 || idx >= tx.inputs.length) {\n throw err(\"out-of-range\", \"sighash\", `input index ${idx} out of range`);\n }\n\n // Inputs committed to: only the signed input under AnyOneCanPay, else all.\n const inputs = anyoneCanPay ? [tx.inputs[idx]!] : tx.inputs;\n const signInIdx = anyoneCanPay ? 0 : idx;\n\n // ---- Prefix hash ----\n // For SigHashAll without AnyOneCanPay the prefix half does not depend on which\n // input is being signed, so a caller signing N inputs can compute it once. Every\n // other hash type changes what the prefix commits to — cleared outputs, zeroed\n // sequences, or a single input — so the cache is ignored rather than trusted.\n const prefixIsInputIndependent = masked === SigHashType.All && !anyoneCanPay;\n let prefixHash: Uint8Array;\n if (cachedPrefix !== undefined && prefixIsInputIndependent) {\n if (cachedPrefix.length !== 32) {\n throw err(\"bad-length\", \"sighash\", `cachedPrefix must be 32 bytes, got ${cachedPrefix.length}`);\n }\n prefixHash = cachedPrefix;\n } else {\n const pw = new Writer();\n pw.u32(packVersion(tx.version, SIG_HASH_SERIALIZE_PREFIX));\n\n pw.varInt(inputs.length);\n for (let i = 0; i < inputs.length; i++) {\n const input = inputs[i]!;\n const op = input.previousOutPoint;\n pw.bytes(op.hash).u32(op.index).u8(op.tree);\n let sequence = input.sequence;\n if ((masked === SigHashType.None || masked === SigHashType.Single) && i !== signInIdx) {\n sequence = 0;\n }\n pw.u32(sequence);\n }\n\n // Outputs committed to depend on the hash type.\n let outputs = tx.outputs;\n if (masked === SigHashType.None) outputs = [];\n else if (masked === SigHashType.Single) outputs = tx.outputs.slice(0, idx + 1);\n\n pw.varInt(outputs.length);\n for (let i = 0; i < outputs.length; i++) {\n const out = outputs[i]!;\n if (masked === SigHashType.Single && i !== idx) {\n // Cleared output: amount -1, empty script.\n pw.i64(-1n).u16(out.version).varInt(0);\n } else {\n pw.i64(out.value).u16(out.version).varBytes(out.pkScript);\n }\n }\n pw.u32(tx.lockTime).u32(tx.expiry);\n prefixHash = blake256(pw.finish());\n }\n\n // ---- Witness hash ----\n const ww = new Writer();\n ww.u32(packVersion(tx.version, SIG_HASH_SERIALIZE_WITNESS));\n ww.varInt(inputs.length);\n for (let i = 0; i < inputs.length; i++) {\n // Only the signed input commits to the sub script; the rest commit to nil.\n if (i === signInIdx) ww.varBytes(subScript);\n else ww.varInt(0);\n }\n const witnessHash = blake256(ww.finish());\n\n // ---- Final hash ----\n const fw = new Writer();\n fw.u32(hashType >>> 0).bytes(prefixHash).bytes(witnessHash);\n return blake256(fw.finish());\n}\n","/**\n * Transaction input signing for P2PKH (secp256k1 ECDSA, SigHashAll and friends).\n *\n * Signatures are deterministic (RFC 6979) and low-S normalised, matching dcrd\n * exactly — the same key and signature hash produce byte-identical DER. The\n * signature script for a P2PKH input is `<DER-sig ‖ hashType> <pubkey>`.\n */\nimport { secp256k1 } from \"@noble/curves/secp256k1\";\nimport { err } from \"./errors.js\";\nimport { isBytes } from \"./bytes.js\";\nimport { assertPrivateKey, publicKeyFromPrivate } from \"./keys.js\";\nimport { pushData } from \"./script.js\";\nimport {\n assertSignableSigHashType,\n calcSignatureHash,\n sigHashPrefixAll,\n SigHashType,\n} from \"./sighash.js\";\nimport type { Transaction } from \"./tx.js\";\n\n/**\n * Throw unless `hash` is exactly 32 bytes.\n *\n * Both `@noble` and dcrd reduce the hash to a scalar with no length check, and\n * they agree byte-for-byte on what that produces — so this is not a divergence\n * in the signatures either side emits, it is a hazard both share. It bites\n * because the reduction is not injective:\n *\n * - a short hash signs identically to itself left-padded with zeros to 32 bytes\n * (`sign(h31)` and `sign(0x00 ‖ h31)` are the same DER bytes), and\n * - a long hash is silently truncated to its first 32 bytes.\n *\n * So a caller who passes a mis-sliced buffer gets a valid signature committing\n * to a *different* message than the one they hold, with nothing raising. dcrd\n * needs no guard because its type system is the guard: `chainhash.Hash` is\n * `[32]byte` and the only thing that ever reaches `ecdsa.Sign` is a BLAKE-256\n * output. A `Uint8Array` carries no length in its type, so the check is explicit\n * here — the same reason {@link assertPrivateKey} exists.\n */\nfunction assertHash32(hash: Uint8Array, who: string): void {\n if (!isBytes(hash)) {\n throw err(\"invalid-argument\", who, \"signature hash must be a Uint8Array\");\n }\n if (hash.length !== 32) {\n throw err(\"bad-length\", who, `signature hash must be 32 bytes, got ${hash.length}`);\n }\n}\n\n/** DER-encode a deterministic low-S ECDSA signature over a 32-byte hash. */\nexport function signHash(hash: Uint8Array, privateKey: Uint8Array): Uint8Array {\n assertHash32(hash, \"signHash\");\n assertPrivateKey(privateKey, \"signHash\");\n const sig = secp256k1.sign(hash, privateKey, { lowS: true });\n return sig.toDERRawBytes();\n}\n\n/**\n * Verify a **DER** signature over a 32-byte hash against a public key.\n *\n * Strictly DER, and low-S. `@noble`'s `verify` falls back to the 64-byte compact\n * `r ‖ s` encoding when DER parsing fails, so without parsing the DER ourselves\n * first this would accept a signature encoding dcrd's script engine rejects — a\n * co-signer or hardware device emitting compact signatures would pass local\n * validation and then fail consensus.\n */\nexport function verifyHash(\n hash: Uint8Array,\n derSignature: Uint8Array,\n publicKey: Uint8Array,\n): boolean {\n // Before the try, and thrown rather than returned as `false`: a wrong-length\n // hash is a caller bug, not a failed verification, and `false` would hide the\n // one case that matters — a 31-byte hash verifies against a signature over its\n // zero-padded 32-byte form, so `true` here would attest to the wrong message.\n assertHash32(hash, \"verifyHash\");\n try {\n const sig = secp256k1.Signature.fromDER(derSignature);\n // Require the *canonical* DER encoding, matching dcrd's\n // IsStrictSignatureEncoding: re-encoding a parsed signature is canonical, so\n // any padding or non-minimal length in the input shows up as a mismatch.\n // Also deliberately redundant at `@noble` 1.9.7: its `fromDER` already\n // rejects unnecessary leading zeros, long-form and indefinite lengths, and\n // trailing bytes, so no input reaching here re-encodes differently — this\n // comparison has no test that can kill it in isolation. It is kept as the\n // backstop for exactly that dependency behaviour changing, since dcrd's\n // `IsStrictSignatureEncoding` is a consensus rule and a loosened parser\n // upstream would silently make this library accept signatures dcrd rejects.\n const canonical = sig.toDERRawBytes();\n if (canonical.length !== derSignature.length) return false;\n for (let i = 0; i < canonical.length; i++) {\n if (canonical[i] !== derSignature[i]) return false;\n }\n // Same again: `{ lowS: true }` on the verify below enforces this too, so\n // this line alone cannot be mutation-killed. Stated here so the rule is\n // visible at the point the signature is inspected rather than buried in an\n // options object, and so removing the option does not silently drop it.\n if (sig.hasHighS()) return false;\n // Verify from the unambiguous 64-byte form; passing bytes back in would let\n // noble re-guess the encoding.\n return secp256k1.verify(sig.toCompactRawBytes(), hash, publicKey, { lowS: true });\n } catch {\n return false;\n }\n}\n\n/**\n * Produce the raw signature for input `idx`: the DER signature over the Decred\n * signature hash with the one-byte hash type appended (as it appears in a\n * signature script and in a signature stack element).\n */\nexport function rawTxInSignature(\n tx: Transaction,\n idx: number,\n subScript: Uint8Array,\n hashType: SigHashType | number,\n privateKey: Uint8Array,\n cachedPrefix?: Uint8Array,\n): Uint8Array {\n // Only the six hash types dcrd's engine accepts can produce a spendable input.\n // calcSignatureHash still computes a hash for other byte values, matching\n // dcrd's split between hashing and validation, but there is no reason to hand\n // back a signature that cannot be redeemed.\n assertSignableSigHashType(hashType);\n const hash = calcSignatureHash(subScript, hashType, tx, idx, cachedPrefix);\n const der = signHash(hash, privateKey);\n const out = new Uint8Array(der.length + 1);\n out.set(der);\n out[der.length] = hashType & 0xff;\n return out;\n}\n\n/**\n * Build the full P2PKH signature script for input `idx`:\n * `push(<DER-sig ‖ hashType>) push(<pubkey>)`.\n */\nexport function signatureScript(\n tx: Transaction,\n idx: number,\n subScript: Uint8Array,\n hashType: SigHashType | number,\n privateKey: Uint8Array,\n compressed = true,\n cachedPrefix?: Uint8Array,\n): Uint8Array {\n const rawSig = rawTxInSignature(tx, idx, subScript, hashType, privateKey, cachedPrefix);\n const pubKey = publicKeyFromPrivate(privateKey, compressed);\n const a = pushData(rawSig);\n const b = pushData(pubKey);\n const out = new Uint8Array(a.length + b.length);\n out.set(a);\n out.set(b, a.length);\n return out;\n}\n\n/**\n * Sign input `idx` in place: compute and assign its P2PKH signature script.\n * Returns the signed transaction for chaining.\n *\n * For a transaction with several inputs prefer {@link signP2PKHInputs}, which\n * reuses one prefix hash instead of recomputing it per input.\n */\nexport function signP2PKHInput(\n tx: Transaction,\n idx: number,\n subScript: Uint8Array,\n privateKey: Uint8Array,\n hashType: SigHashType | number = SigHashType.All,\n compressed = true,\n): Transaction {\n tx.inputs[idx]!.signatureScript = signatureScript(\n tx,\n idx,\n subScript,\n hashType,\n privateKey,\n compressed,\n );\n return tx;\n}\n\n/** One input to sign, for {@link signP2PKHInputs}. */\nexport interface P2PKHInputToSign {\n /** Index into `tx.inputs`. */\n idx: number;\n /** The script being satisfied — the prevout pkScript for P2PKH. */\n subScript: Uint8Array;\n privateKey: Uint8Array;\n /** Serialize the public key compressed (the default). */\n compressed?: boolean;\n}\n\n/**\n * Sign several P2PKH inputs in place, reusing one prefix hash.\n *\n * `calcSignatureHash` re-serializes and re-hashes the whole transaction prefix on\n * every call — every outpoint and every output script — which is the dominant\n * cost for a transaction with many inputs. Under `SigHashAll` without\n * `AnyOneCanPay` that half is input-independent, so it is computed once here and\n * reused, which is what dcrd's `cachedPrefix` parameter is for.\n *\n * This lowers the constant, not the exponent: the witness half still walks every\n * input per call, so signing stays O(N²). On the hashing alone it measured 12x at\n * 50 inputs and 26x at 500; end to end the gain is smaller (1.7x at 250) because\n * ECDSA dominates.\n *\n * The prefix hash is taken **before** any signature script is assigned, which is\n * also why this is correct: the prefix commits to no witness data, so writing\n * signature scripts cannot invalidate it. For other hash types the cache is\n * ignored and each input is hashed independently, so passing one is always safe.\n */\nexport function signP2PKHInputs(\n tx: Transaction,\n toSign: readonly P2PKHInputToSign[],\n hashType: SigHashType | number = SigHashType.All,\n): Transaction {\n assertSignableSigHashType(hashType);\n const cachedPrefix = sigHashPrefixAll(tx);\n for (const { idx, subScript, privateKey, compressed = true } of toSign) {\n // Deliberately the same builder the single-input path uses, with the cache\n // handed to it. This loop used to inline its own copy of `rawTxInSignature`\n // and `signatureScript`, which left two hand-synced copies of consensus\n // byte assembly in one file and made \"batched is byte-identical to\n // one-at-a-time\" a property a test had to keep checking rather than one the\n // code could not break.\n tx.inputs[idx]!.signatureScript = signatureScript(\n tx,\n idx,\n subScript,\n hashType,\n privateKey,\n compressed,\n cachedPrefix,\n );\n }\n return tx;\n}\n","/**\n * DCR amounts.\n *\n * Amounts are integer numbers of **atoms** (the smallest unit); 1 DCR =\n * 100,000,000 atoms. Values are `bigint` to avoid the precision loss that\n * floating point would introduce around 21 million coins.\n */\nimport { err } from \"./errors.js\";\nimport { shown } from \"./bytes.js\";\n\n/** Atoms in one DCR. */\nexport const ATOMS_PER_COIN = 100_000_000n;\n\n/** Decimal places in a DCR amount. */\nexport const COIN_DECIMALS = 8;\n\n/**\n * Parse a decimal DCR string (e.g. \"1.5\", \"-0.00000001\") into atoms.\n * Accepts up to 8 fractional digits; more is an error.\n */\nexport function dcrToAtoms(dcr: string): bigint {\n const s = dcr.trim();\n if (!/^-?\\d+(\\.\\d+)?$/.test(s)) throw err(\"invalid-amount\", \"dcrToAtoms\", `cannot parse ${shown(dcr)}`);\n const negative = s.startsWith(\"-\");\n const body = negative ? s.slice(1) : s;\n const [intPart = \"0\", fracPart = \"\"] = body.split(\".\");\n if (fracPart.length > COIN_DECIMALS) {\n throw err(\"invalid-amount\", \"dcrToAtoms\", `more than ${COIN_DECIMALS} decimal places`);\n }\n const frac = (fracPart + \"00000000\").slice(0, COIN_DECIMALS);\n const atoms = BigInt(intPart) * ATOMS_PER_COIN + BigInt(frac);\n return negative ? -atoms : atoms;\n}\n\n/**\n * Format atoms as a fixed 8-decimal DCR string (e.g. 150000000n → \"1.50000000\").\n */\nexport function atomsToDcr(atoms: bigint): string {\n const negative = atoms < 0n;\n const a = negative ? -atoms : atoms;\n const intPart = a / ATOMS_PER_COIN;\n const frac = (a % ATOMS_PER_COIN).toString().padStart(COIN_DECIMALS, \"0\");\n return `${negative ? \"-\" : \"\"}${intPart.toString()}.${frac}`;\n}\n"]}