@hwlt/era-connect 0.2.0 → 0.4.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.
- package/README.md +6 -6
- package/cardano/package.json +6 -0
- package/cosmos/package.json +6 -0
- package/dist/{btc-DfQ0q79G.d.ts → btc-B8LfSEkv.d.ts} +11 -2
- package/dist/{btc-VyJKXq7d.js → btc-B_Nq2H4T.js} +16 -7
- package/dist/btc-B_Nq2H4T.js.map +1 -0
- package/dist/{btc-Fr6Jz4Fi.cjs → btc-ByzjzUKs.cjs} +19 -10
- package/dist/btc-ByzjzUKs.cjs.map +1 -0
- package/dist/{btc-Dn6_Y12c.d.cts → btc-C4dVkxHb.d.cts} +11 -2
- package/dist/btc.cjs +2 -2
- package/dist/btc.d.cts +1 -1
- package/dist/btc.d.ts +1 -1
- package/dist/btc.js +2 -2
- package/dist/cardano-BCT55gwf.js +95 -0
- package/dist/cardano-BCT55gwf.js.map +1 -0
- package/dist/cardano-CzYswGzK.cjs +106 -0
- package/dist/cardano-CzYswGzK.cjs.map +1 -0
- package/dist/cardano-Do1ahUlK.d.cts +62 -0
- package/dist/cardano-OzjWZHh6.d.ts +62 -0
- package/dist/cardano.cjs +10 -0
- package/dist/cardano.d.cts +3 -0
- package/dist/cardano.d.ts +3 -0
- package/dist/cardano.js +3 -0
- package/dist/cosmos-BYrhIqRk.d.cts +77 -0
- package/dist/cosmos-DDsgtUki.cjs +113 -0
- package/dist/cosmos-DDsgtUki.cjs.map +1 -0
- package/dist/cosmos-DqyjA6lg.d.ts +77 -0
- package/dist/cosmos-jUHNxgWC.js +102 -0
- package/dist/cosmos-jUHNxgWC.js.map +1 -0
- package/dist/cosmos.cjs +10 -0
- package/dist/cosmos.d.cts +3 -0
- package/dist/cosmos.d.ts +3 -0
- package/dist/cosmos.js +3 -0
- package/dist/derive-BayrpfJk.cjs +188 -0
- package/dist/derive-BayrpfJk.cjs.map +1 -0
- package/dist/derive-CK9Nc9Jc.js +123 -0
- package/dist/derive-CK9Nc9Jc.js.map +1 -0
- package/dist/{evm-kJb3-oiR.js → evm-CI1cuZsp.js} +3 -2
- package/dist/{evm-kJb3-oiR.js.map → evm-CI1cuZsp.js.map} +1 -1
- package/dist/{evm-BHj_2OTG.cjs → evm-yfKOc2dy.cjs} +6 -5
- package/dist/{evm-BHj_2OTG.cjs.map → evm-yfKOc2dy.cjs.map} +1 -1
- package/dist/evm.cjs +2 -2
- package/dist/evm.js +2 -2
- package/dist/index.cjs +156 -116
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +68 -9
- package/dist/index.d.ts +68 -9
- package/dist/index.js +125 -94
- package/dist/index.js.map +1 -1
- package/dist/keypath-Bvv_cfHt.js +75 -0
- package/dist/keypath-Bvv_cfHt.js.map +1 -0
- package/dist/keypath-pzm_YIfN.cjs +116 -0
- package/dist/keypath-pzm_YIfN.cjs.map +1 -0
- package/dist/{messages-BzcdWlg1.cjs → messages-BZXDY29v.cjs} +2 -2
- package/dist/{messages-BzcdWlg1.cjs.map → messages-BZXDY29v.cjs.map} +1 -1
- package/dist/{messages-17Oup0-Z.js → messages-DbnXy3dC.js} +2 -2
- package/dist/{messages-17Oup0-Z.js.map → messages-DbnXy3dC.js.map} +1 -1
- package/dist/{shared-B8Wc7ViU.js → shared-Bbgejrus.js} +2 -73
- package/dist/shared-Bbgejrus.js.map +1 -0
- package/dist/{shared-nISrEktU.cjs → shared-Cu2yynP9.cjs} +13 -114
- package/dist/shared-Cu2yynP9.cjs.map +1 -0
- package/dist/{solana-DdEn24X4.cjs → solana-BoQBy0hu.cjs} +6 -5
- package/dist/{solana-DdEn24X4.cjs.map → solana-BoQBy0hu.cjs.map} +1 -1
- package/dist/{solana-C7JQEAec.js → solana-BukH3AI3.js} +3 -2
- package/dist/{solana-C7JQEAec.js.map → solana-BukH3AI3.js.map} +1 -1
- package/dist/solana.cjs +2 -2
- package/dist/solana.js +2 -2
- package/dist/sui-6WX6VPlW.d.cts +49 -0
- package/dist/sui-BtbPG6Xt.js +71 -0
- package/dist/sui-BtbPG6Xt.js.map +1 -0
- package/dist/sui-CYRn331O.cjs +82 -0
- package/dist/sui-CYRn331O.cjs.map +1 -0
- package/dist/sui-DI0ruW7E.d.ts +49 -0
- package/dist/sui.cjs +10 -0
- package/dist/sui.d.cts +3 -0
- package/dist/sui.d.ts +3 -0
- package/dist/sui.js +3 -0
- package/dist/{ton-5Uvi5ifg.js → ton-BSPKU5B9.js} +3 -2
- package/dist/{ton-5Uvi5ifg.js.map → ton-BSPKU5B9.js.map} +1 -1
- package/dist/{ton-DUJGXdGa.cjs → ton-CI2s9puH.cjs} +6 -5
- package/dist/{ton-DUJGXdGa.cjs.map → ton-CI2s9puH.cjs.map} +1 -1
- package/dist/ton.cjs +2 -2
- package/dist/ton.js +2 -2
- package/dist/{tron-CQIEqjCA.cjs → tron-B9wXdzlA.cjs} +7 -6
- package/dist/{tron-CQIEqjCA.cjs.map → tron-B9wXdzlA.cjs.map} +1 -1
- package/dist/{tron-Bo9HnvVE.js → tron-fufBDNuQ.js} +4 -3
- package/dist/{tron-Bo9HnvVE.js.map → tron-fufBDNuQ.js.map} +1 -1
- package/dist/tron.cjs +3 -3
- package/dist/tron.js +3 -3
- package/dist/verify.cjs +335 -4
- package/dist/verify.cjs.map +1 -1
- package/dist/verify.d.cts +86 -1
- package/dist/verify.d.ts +86 -1
- package/dist/verify.js +333 -6
- package/dist/verify.js.map +1 -1
- package/dist/xrp-BXAeK4iH.d.cts +32 -0
- package/dist/xrp-BrHXUnX5.cjs +52 -0
- package/dist/xrp-BrHXUnX5.cjs.map +1 -0
- package/dist/xrp-C8LJO5b-.js +47 -0
- package/dist/xrp-C8LJO5b-.js.map +1 -0
- package/dist/xrp-DqCXGYEk.d.ts +32 -0
- package/dist/xrp.cjs +9 -0
- package/dist/xrp.d.cts +3 -0
- package/dist/xrp.d.ts +3 -0
- package/dist/xrp.js +3 -0
- package/package.json +49 -1
- package/sui/package.json +6 -0
- package/xrp/package.json +6 -0
- package/dist/btc-Fr6Jz4Fi.cjs.map +0 -1
- package/dist/btc-VyJKXq7d.js.map +0 -1
- package/dist/shared-B8Wc7ViU.js.map +0 -1
- package/dist/shared-nISrEktU.cjs.map +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shared-Bbgejrus.js","names":["MAX_DEPTH","UrValue"],"sources":["../src/core/errors.ts","../src/cbor/model.ts","../src/core/bytes.ts","../src/cbor/encode.ts","../src/cbor/decode.ts","../src/ur/crc32.ts","../src/ur/bytewords.ts","../src/ur/ur.ts","../src/core/rand.ts","../src/ur/limits.ts","../src/ur/xoshiro.ts","../src/ur/sampler.ts","../src/ur/fragment.ts","../src/ur/encoder.ts","../src/qr/animated-ur.ts","../src/ur/decoder.ts","../src/scan/ur-scanner.ts","../src/chains/shared.ts"],"sourcesContent":["/**\n * Closed set of error codes the SDK can produce. Integrators branch on\n * `code`, never on message text — messages are for humans and may change.\n */\nexport type EraErrorCode =\n /** No CSPRNG available: neither `globalThis.crypto.getRandomValues` nor an injected `randomBytes`. */\n | 'no-secure-random'\n /** The scanned text is not a `ur:` string at all. */\n | 'not-a-ur'\n /** A UR of a type this operation does not accept. */\n | 'wrong-ur-type'\n /** Bytewords body malformed (unknown letter pair, too short). */\n | 'malformed-bytewords'\n /** Bytewords or reassembly CRC32 does not match. */\n | 'checksum-mismatch'\n /** CBOR payload malformed or outside the hardened decoder's policy. */\n | 'malformed-cbor'\n /** The `<seq>` path segment of a multi-part UR is unreadable. */\n | 'malformed-sequence'\n /** A fragment that does not belong to the stream being assembled. */\n | 'fragment-mismatch'\n /** A size/count cap was exceeded (fragment count, message size, inflate ceiling). */\n | 'limit-exceeded'\n /** `result()`/`parse()` called before the scan completed. */\n | 'incomplete-scan'\n /** The reply echoes a different request id — it answers another sign request. */\n | 'request-id-mismatch'\n /** The linked wallet carries no account for the requested path. */\n | 'account-not-found'\n /** Invalid request properties (bad path string, chainId over the device's 32-bit ceiling, ...). */\n | 'invalid-props'\n /** The device refused to sign (e.g. a Bitcoin message for a non-legacy address). */\n | 'empty-signature'\n /** Reply CBOR/protobuf decoded but its shape is not the expected reply. */\n | 'malformed-reply'\n /** gzip payload malformed, truncated, or a decompression bomb. */\n | 'gzip-error'\n /** Protobuf payload malformed. */\n | 'protobuf-error'\n /** A verification helper found a mismatch between request and reply. */\n | 'verification-failed';\n\n/** Every error thrown by this SDK. `code` is stable API; `message` is not. */\nexport class EraSdkError extends Error {\n readonly code: EraErrorCode;\n readonly details?: Record<string, unknown>;\n\n constructor(code: EraErrorCode, message: string, details?: Record<string, unknown>) {\n super(message);\n this.name = 'EraSdkError';\n this.code = code;\n if (details !== undefined) this.details = details;\n }\n}\n","import { EraSdkError } from '../core/errors';\n\n/**\n * Minimal CBOR value model for the ERA wire protocol.\n *\n * Maps are ENTRY LISTS, not JS Maps: insertion order is preserved for\n * byte-exact re-encoding, and the decoder can reject duplicate keys.\n */\nexport type CborValue =\n | { readonly kind: 'uint'; readonly value: bigint }\n | { readonly kind: 'nint'; readonly value: bigint } // encoded as -1 - value\n | { readonly kind: 'bytes'; readonly value: Uint8Array }\n | { readonly kind: 'text'; readonly value: string }\n | { readonly kind: 'array'; readonly items: readonly CborValue[] }\n | { readonly kind: 'map'; readonly entries: readonly (readonly [CborValue, CborValue])[] }\n | { readonly kind: 'bool'; readonly value: boolean }\n | { readonly kind: 'null' }\n | { readonly kind: 'tag'; readonly tag: number; readonly value: CborValue };\n\nexport const cbUint = (value: number | bigint): CborValue => {\n const v = typeof value === 'number' ? BigInt(value) : value;\n if (v < 0n) throw new EraSdkError('invalid-props', 'cbUint: negative value');\n return { kind: 'uint', value: v };\n};\nexport const cbBytes = (value: Uint8Array): CborValue => ({ kind: 'bytes', value });\nexport const cbText = (value: string): CborValue => ({ kind: 'text', value });\nexport const cbArray = (items: CborValue[]): CborValue => ({ kind: 'array', items });\nexport const cbBool = (value: boolean): CborValue => ({ kind: 'bool', value });\nexport const cbTag = (tag: number, value: CborValue): CborValue => ({ kind: 'tag', tag, value });\n\n/** Integer-keyed map in the given entry order (the shape every ERA payload uses). */\nexport const cbMap = (entries: [number, CborValue][]): CborValue => ({\n kind: 'map',\n entries: entries.map(([k, v]) => [cbUint(k), v] as const),\n});\n\n/** Strip any tag wrappers (tag-37 UUID echoes, tag-304 keypaths, ...). */\nexport function stripTags(value: CborValue): CborValue {\n let v = value;\n while (v.kind === 'tag') v = v.value;\n return v;\n}\n\n/** Look up an integer key in a map value. Tag-agnostic on the VALUE is the caller's choice. */\nexport function mapGet(map: CborValue, key: number): CborValue | undefined {\n if (map.kind !== 'map') return undefined;\n const k = BigInt(key);\n for (const [ek, ev] of map.entries) {\n if (ek.kind === 'uint' && ek.value === k) return ev;\n }\n return undefined;\n}\n\nexport function asUint(value: CborValue | undefined): bigint | undefined {\n if (!value) return undefined;\n const v = stripTags(value);\n return v.kind === 'uint' ? v.value : undefined;\n}\n\nexport function asBytes(value: CborValue | undefined): Uint8Array | undefined {\n if (!value) return undefined;\n const v = stripTags(value);\n return v.kind === 'bytes' ? v.value : undefined;\n}\n\nexport function asText(value: CborValue | undefined): string | undefined {\n if (!value) return undefined;\n const v = stripTags(value);\n return v.kind === 'text' ? v.value : undefined;\n}\n\nexport function asArray(value: CborValue | undefined): readonly CborValue[] | undefined {\n if (!value) return undefined;\n const v = stripTags(value);\n return v.kind === 'array' ? v.items : undefined;\n}\n\nexport function asMap(value: CborValue | undefined): CborValue | undefined {\n if (!value) return undefined;\n const v = stripTags(value);\n return v.kind === 'map' ? v : undefined;\n}\n\nexport function asBool(value: CborValue | undefined): boolean | undefined {\n if (!value) return undefined;\n const v = stripTags(value);\n return v.kind === 'bool' ? v.value : undefined;\n}\n","/** Byte helpers. `Uint8Array` end-to-end; no Buffer, no Node built-ins. */\n\nexport function concatBytes(...arrays: Uint8Array[]): Uint8Array {\n let total = 0;\n for (const a of arrays) total += a.length;\n const out = new Uint8Array(total);\n let offset = 0;\n for (const a of arrays) {\n out.set(a, offset);\n offset += a.length;\n }\n return out;\n}\n\n/** Constant-shape byte equality (length check + full loop). */\nexport function equalBytes(a: Uint8Array, b: Uint8Array): boolean {\n if (a.length !== b.length) return false;\n let diff = 0;\n for (let i = 0; i < a.length; i++) diff |= (a[i] ?? 0) ^ (b[i] ?? 0);\n return diff === 0;\n}\n\n/** Big-endian unsigned 32-bit. */\nexport function u32be(value: number): Uint8Array {\n const out = new Uint8Array(4);\n out[0] = (value >>> 24) & 0xff;\n out[1] = (value >>> 16) & 0xff;\n out[2] = (value >>> 8) & 0xff;\n out[3] = value & 0xff;\n return out;\n}\n\nconst HEX_CHARS = '0123456789abcdef';\n\nexport function bytesToHex(bytes: Uint8Array): string {\n let out = '';\n for (const b of bytes) out += HEX_CHARS[b >>> 4]! + HEX_CHARS[b & 0x0f]!;\n return out;\n}\n\nexport function hexToBytes(hex: string): Uint8Array {\n let h = hex;\n if (h.startsWith('0x') || h.startsWith('0X')) h = h.slice(2);\n if (h.length % 2 !== 0) throw new Error('hex string has odd length');\n const out = new Uint8Array(h.length / 2);\n for (let i = 0; i < out.length; i++) {\n const byte = Number.parseInt(h.slice(i * 2, i * 2 + 2), 16);\n if (Number.isNaN(byte)) throw new Error('hex string has non-hex characters');\n out[i] = byte;\n }\n return out;\n}\n\n/** Minimal-width big-endian bytes of a non-negative bigint (empty for 0n is NOT produced; 0n -> [0]). */\nexport function bigintToBytes(value: bigint): Uint8Array {\n if (value < 0n) throw new Error('negative bigint');\n if (value === 0n) return new Uint8Array([0]);\n let hex = value.toString(16);\n if (hex.length % 2 === 1) hex = `0${hex}`;\n return hexToBytes(hex);\n}\n\nexport function bytesToBigint(bytes: Uint8Array): bigint {\n let out = 0n;\n for (const b of bytes) out = (out << 8n) | BigInt(b);\n return out;\n}\n\n/** UTF-8 encode without TextEncoder (absent on older Hermes). */\nexport function utf8Encode(text: string): Uint8Array {\n const out: number[] = [];\n for (let i = 0; i < text.length; i++) {\n let code = text.charCodeAt(i);\n if (code < 0x80) {\n out.push(code);\n } else if (code < 0x800) {\n out.push(0xc0 | (code >> 6), 0x80 | (code & 0x3f));\n } else if (code < 0xd800 || code >= 0xe000) {\n out.push(0xe0 | (code >> 12), 0x80 | ((code >> 6) & 0x3f), 0x80 | (code & 0x3f));\n } else {\n i++;\n if (i >= text.length) throw new Error('unpaired surrogate in string');\n const next = text.charCodeAt(i);\n code = 0x10000 + (((code & 0x3ff) << 10) | (next & 0x3ff));\n out.push(\n 0xf0 | (code >> 18),\n 0x80 | ((code >> 12) & 0x3f),\n 0x80 | ((code >> 6) & 0x3f),\n 0x80 | (code & 0x3f),\n );\n }\n }\n return new Uint8Array(out);\n}\n\n/**\n * STRICT UTF-8 decode without TextDecoder (absent on older Hermes). Throws on\n * malformed input, including overlong encodings, surrogate code points and\n * values past U+10FFFF — a lenient decoder would let a hostile reply smuggle\n * bytes that render as different text than they compare as.\n */\nexport function utf8Decode(bytes: Uint8Array): string {\n let out = '';\n let i = 0;\n while (i < bytes.length) {\n const b0 = bytes[i]!;\n if (b0 < 0x80) {\n out += String.fromCharCode(b0);\n i += 1;\n continue;\n }\n let extra: number;\n let code: number;\n let minCode: number;\n if ((b0 & 0xe0) === 0xc0) {\n extra = 1;\n code = b0 & 0x1f;\n minCode = 0x80;\n } else if ((b0 & 0xf0) === 0xe0) {\n extra = 2;\n code = b0 & 0x0f;\n minCode = 0x800;\n } else if ((b0 & 0xf8) === 0xf0) {\n extra = 3;\n code = b0 & 0x07;\n minCode = 0x10000;\n } else {\n throw new Error('malformed UTF-8'); // continuation or F8-FF lead byte\n }\n if (i + extra >= bytes.length) throw new Error('truncated UTF-8');\n for (let k = 1; k <= extra; k++) {\n const bk = bytes[i + k]!;\n if ((bk & 0xc0) !== 0x80) throw new Error('malformed UTF-8 continuation');\n code = (code << 6) | (bk & 0x3f);\n }\n if (code < minCode) throw new Error('overlong UTF-8 encoding');\n if (code >= 0xd800 && code <= 0xdfff) throw new Error('UTF-8 encodes a surrogate');\n if (code > 0x10ffff) throw new Error('UTF-8 code point out of range');\n if (code > 0xffff) {\n code -= 0x10000;\n out += String.fromCharCode(0xd800 + (code >> 10), 0xdc00 + (code & 0x3ff));\n } else {\n out += String.fromCharCode(code);\n }\n i += 1 + extra;\n }\n return out;\n}\n\n/** ASCII decode (used for replies that carry text as raw bytes). Throws on non-ASCII. */\nexport function asciiDecode(bytes: Uint8Array): string {\n let out = '';\n for (const b of bytes) {\n if (b > 0x7f) throw new Error('non-ASCII byte');\n out += String.fromCharCode(b);\n }\n return out;\n}\n","import { concatBytes, utf8Encode } from '../core/bytes';\nimport { EraSdkError } from '../core/errors';\nimport type { CborValue } from './model';\n\n/**\n * Deterministic CBOR encoder: definite lengths only, minimal-width integer\n * heads, map entries in insertion order. This matches, byte for byte, what the\n * reference implementation produces and what the device firmware parses — the\n * exact bytes are pinned by golden-vector tests, which is why this encoder is\n * hand-rolled rather than delegated to a dependency's release cadence.\n *\n * It deliberately cannot emit floats, indefinite lengths or exotic simple\n * values: the protocol never uses them.\n */\nexport function cborEncode(value: CborValue): Uint8Array {\n const parts: Uint8Array[] = [];\n writeValue(value, parts, 0);\n return concatBytes(...parts);\n}\n\n// Deep enough for the deepest registry structure the SDK speaks (the\n// qr-hardware-call tree nests 9 levels once tags and map entries are\n// counted), with headroom; still a hard bound against recursion abuse.\nconst MAX_DEPTH = 16;\n\nfunction writeValue(value: CborValue, parts: Uint8Array[], depth: number): void {\n if (depth > MAX_DEPTH) {\n throw new EraSdkError('malformed-cbor', 'cbor encode: nesting too deep');\n }\n switch (value.kind) {\n case 'uint':\n parts.push(head(0, value.value));\n return;\n case 'nint': {\n if (value.value < 0n) throw new EraSdkError('malformed-cbor', 'nint holds the magnitude');\n parts.push(head(1, value.value));\n return;\n }\n case 'bytes':\n parts.push(head(2, BigInt(value.value.length)), value.value);\n return;\n case 'text': {\n const utf8 = utf8Encode(value.value);\n parts.push(head(3, BigInt(utf8.length)), utf8);\n return;\n }\n case 'array': {\n parts.push(head(4, BigInt(value.items.length)));\n for (const item of value.items) writeValue(item, parts, depth + 1);\n return;\n }\n case 'map': {\n parts.push(head(5, BigInt(value.entries.length)));\n for (const [k, v] of value.entries) {\n writeValue(k, parts, depth + 1);\n writeValue(v, parts, depth + 1);\n }\n return;\n }\n case 'tag':\n parts.push(head(6, BigInt(value.tag)));\n writeValue(value.value, parts, depth + 1);\n return;\n case 'bool':\n parts.push(new Uint8Array([value.value ? 0xf5 : 0xf4]));\n return;\n case 'null':\n parts.push(new Uint8Array([0xf6]));\n return;\n }\n}\n\n/** Major-type head with a minimal-width argument. */\nfunction head(major: number, arg: bigint): Uint8Array {\n if (arg < 0n) throw new EraSdkError('malformed-cbor', 'cbor head: negative argument');\n const m = major << 5;\n if (arg < 24n) return new Uint8Array([m | Number(arg)]);\n if (arg <= 0xffn) return new Uint8Array([m | 24, Number(arg)]);\n if (arg <= 0xffffn) {\n const n = Number(arg);\n return new Uint8Array([m | 25, n >>> 8, n & 0xff]);\n }\n if (arg <= 0xffffffffn) {\n const n = Number(arg);\n return new Uint8Array([\n m | 26,\n (n >>> 24) & 0xff,\n (n >>> 16) & 0xff,\n (n >>> 8) & 0xff,\n n & 0xff,\n ]);\n }\n if (arg <= 0xffffffffffffffffn) {\n const out = new Uint8Array(9);\n out[0] = m | 27;\n let v = arg;\n for (let i = 8; i >= 1; i--) {\n out[i] = Number(v & 0xffn);\n v >>= 8n;\n }\n return out;\n }\n throw new EraSdkError('malformed-cbor', 'cbor head: argument exceeds 64 bits');\n}\n","import { bytesToHex, utf8Decode } from '../core/bytes';\nimport { EraSdkError } from '../core/errors';\nimport { cborEncode } from './encode';\nimport type { CborValue } from './model';\n\n/**\n * Hardened CBOR decoder for scanned (attacker-controlled) payloads.\n *\n * Policy, enforced as defaults rather than options:\n * - definite lengths only (indefinite refused);\n * - no floats, no simple values beyond bool/null;\n * - duplicate map keys refused;\n * - nesting depth capped;\n * - lengths bounds-checked before any allocation;\n * - trailing bytes after the top-level item refused.\n *\n * Unknown tags are surfaced as `tag` wrappers, never dropped — the tag-37\n * request-id echo is compared tag-agnostically by the callers.\n */\nexport function cborDecode(bytes: Uint8Array): CborValue {\n const reader = new Reader(bytes);\n const value = reader.readValue(0);\n if (reader.offset !== bytes.length) {\n throw err('trailing bytes after the top-level item');\n }\n return value;\n}\n\nconst MAX_DEPTH = 16; // matches the encoder; see encode.ts\n\nfunction err(message: string): EraSdkError {\n return new EraSdkError('malformed-cbor', `cbor: ${message}`);\n}\n\nclass Reader {\n offset = 0;\n constructor(private readonly bytes: Uint8Array) {}\n\n readValue(depth: number): CborValue {\n if (depth > MAX_DEPTH) throw err('nesting too deep');\n const initial = this.readByte();\n const major = initial >>> 5;\n const info = initial & 0x1f;\n\n switch (major) {\n case 0:\n return { kind: 'uint', value: this.readArg(info) };\n case 1:\n return { kind: 'nint', value: this.readArg(info) };\n case 2: {\n const len = this.readLength(info);\n return { kind: 'bytes', value: this.readBytes(len) };\n }\n case 3: {\n const len = this.readLength(info);\n const raw = this.readBytes(len);\n let text: string;\n try {\n text = utf8Decode(raw);\n } catch {\n throw err('text string is not valid UTF-8');\n }\n return { kind: 'text', value: text };\n }\n case 4: {\n const len = this.readLength(info);\n if (len > this.bytes.length - this.offset) throw err('array length exceeds input');\n const items: CborValue[] = [];\n for (let i = 0; i < len; i++) items.push(this.readValue(depth + 1));\n return { kind: 'array', items };\n }\n case 5: {\n const len = this.readLength(info);\n if (len * 2 > this.bytes.length - this.offset) throw err('map length exceeds input');\n const entries: [CborValue, CborValue][] = [];\n const seenKeys = new Set<string>();\n for (let i = 0; i < len; i++) {\n const key = this.readValue(depth + 1);\n const keyId = bytesToHex(cborEncode(key));\n if (seenKeys.has(keyId)) throw err('duplicate map key');\n seenKeys.add(keyId);\n entries.push([key, this.readValue(depth + 1)]);\n }\n return { kind: 'map', entries };\n }\n case 6: {\n const tag = this.readArg(info);\n if (tag > 0xffffffffn) throw err('tag exceeds 32 bits');\n return { kind: 'tag', tag: Number(tag), value: this.readValue(depth + 1) };\n }\n case 7: {\n if (info === 20) return { kind: 'bool', value: false };\n if (info === 21) return { kind: 'bool', value: true };\n if (info === 22) return { kind: 'null' };\n throw err(`unsupported simple/float value (info ${info})`);\n }\n default:\n throw err('unreachable major type');\n }\n }\n\n private readByte(): number {\n const b = this.bytes[this.offset];\n if (b === undefined) throw err('truncated input');\n this.offset += 1;\n return b;\n }\n\n /** Argument of a head. Refuses indefinite (31) and reserved (28-30). */\n private readArg(info: number): bigint {\n if (info < 24) return BigInt(info);\n if (info === 24) return BigInt(this.readByte());\n if (info === 25) {\n const hi = this.readByte();\n return BigInt((hi << 8) | this.readByte());\n }\n if (info === 26) {\n let v = 0n;\n for (let i = 0; i < 4; i++) v = (v << 8n) | BigInt(this.readByte());\n return v;\n }\n if (info === 27) {\n let v = 0n;\n for (let i = 0; i < 8; i++) v = (v << 8n) | BigInt(this.readByte());\n return v;\n }\n if (info === 31) throw err('indefinite lengths are refused');\n throw err(`reserved additional info ${info}`);\n }\n\n private readLength(info: number): number {\n const len = this.readArg(info);\n if (len > BigInt(this.bytes.length - this.offset)) throw err('length exceeds input');\n return Number(len);\n }\n\n private readBytes(length: number): Uint8Array {\n const end = this.offset + length;\n const out = this.bytes.slice(this.offset, end);\n this.offset = end;\n return out;\n }\n}\n","/** IEEE CRC-32 (polynomial 0xEDB88320), table-driven, result as unsigned. */\n\nconst TABLE: Uint32Array = (() => {\n const table = new Uint32Array(256);\n for (let i = 0; i < 256; i++) {\n let c = i;\n for (let k = 0; k < 8; k++) {\n c = c & 1 ? 0xedb88320 ^ (c >>> 1) : c >>> 1;\n }\n table[i] = c >>> 0;\n }\n return table;\n})();\n\nexport function crc32(bytes: Uint8Array): number {\n let crc = 0xffffffff;\n for (const byte of bytes) {\n crc = (crc >>> 8) ^ TABLE[(crc ^ byte) & 0xff]!;\n }\n return (crc ^ 0xffffffff) >>> 0;\n}\n","import { concatBytes, u32be } from '../core/bytes';\nimport { EraSdkError } from '../core/errors';\nimport { crc32 } from './crc32';\n\n/**\n * Bytewords codec (minimal style only), per BCR-2020-012.\n *\n * Decode hardening (each of these used to turn malformed input into plausible\n * bytes in naive implementations):\n * - a letter pair that is not a byteword is a refusal, never a fallback byte;\n * - a body shorter than the four CRC words plus one byte is a refusal;\n * - the trailing CRC32 (big-endian) is verified and stripped.\n *\n * The checksum is unkeyed and is not an authentication control — whoever\n * prints the QR prints the CRC too. What it buys is that garbage stops being\n * accepted as data, which frame dedup and reassembly downstream both assume.\n */\n\nconst BYTE_WORDS =\n 'ableacidalsoapexaquaarchatomauntawayaxisbackbaldbarnbeltbetabiasbluebodybragbrewbulbbuzzcalmcashcatschefcityclawcodecolacookcostcruxcurlcuspcyandarkdatadaysdelidicedietdoordowndrawdropdrumdulldutyeacheasyechoedgeepicevenexamexiteyesfactfairfernfigsfilmfishfizzflapflewfluxfoxyfreefrogfuelfundgalagamegeargemsgiftgirlglowgoodgraygrimgurugushgyrohalfhanghardhawkheathelphighhillholyhopehornhutsicedideaidleinchinkyintoirisironitemjadejazzjoinjoltjowljudojugsjumpjunkjurykeepkenokeptkeyskickkilnkingkitekiwiknoblamblavalazyleaflegsliarlimplionlistlogoloudloveluaulucklungmainmanymathmazememomenumeowmildmintmissmonknailnavyneednewsnextnoonnotenumbobeyoboeomitonyxopenovalowlspaidpartpeckplaypluspoempoolposepuffpumapurrquadquizraceramprealredorichroadrockroofrubyruinrunsrustsafesagascarsetssilkskewslotsoapsolosongstubsurfswantacotasktaxitenttiedtimetinytoiltombtoystriptunatwinuglyundouniturgeuservastveryvetovialvibeviewvisavoidvowswallwandwarmwaspwavewaxywebswhatwhenwhizwolfworkyankyawnyellyogayurtzapszerozestzinczonezoom';\n\nconst DIM = 26;\nconst A = 'a'.charCodeAt(0);\n\n/** Lookup keyed on (first letter, last letter); -1 = not a byteword. */\nconst LOOKUP: Int16Array = (() => {\n const table = new Int16Array(DIM * DIM).fill(-1);\n for (let i = 0; i < 256; i++) {\n const word = BYTE_WORDS.slice(i * 4, i * 4 + 4);\n const x = word.charCodeAt(0) - A;\n const y = word.charCodeAt(3) - A;\n table[y * DIM + x] = i;\n }\n return table;\n})();\n\nexport function bytewordsEncode(data: Uint8Array): string {\n const buf = concatBytes(data, u32be(crc32(data)));\n let out = '';\n for (const byte of buf) {\n const word = BYTE_WORDS.slice(byte * 4, byte * 4 + 4);\n out += word[0]! + word[3]!;\n }\n return out;\n}\n\nexport function bytewordsDecode(body: string): Uint8Array {\n if (body.length % 2 !== 0) {\n throw new EraSdkError('malformed-bytewords', 'bytewords: odd number of letters');\n }\n const words = new Uint8Array(body.length / 2);\n for (let i = 0; i < words.length; i++) {\n const x = body.charCodeAt(i * 2) - A;\n const y = body.charCodeAt(i * 2 + 1) - A;\n if (x < 0 || x >= DIM || y < 0 || y >= DIM) {\n throw new EraSdkError('malformed-bytewords', 'bytewords: letter out of range');\n }\n const value = LOOKUP[y * DIM + x]!;\n if (value < 0) {\n throw new EraSdkError('malformed-bytewords', 'bytewords: not a byteword');\n }\n words[i] = value;\n }\n if (words.length < 5) {\n throw new EraSdkError(\n 'malformed-bytewords',\n 'bytewords: shorter than a checksum plus one byte',\n );\n }\n const bodyBytes = words.slice(0, words.length - 4);\n const declared =\n ((words[words.length - 4]! << 24) |\n (words[words.length - 3]! << 16) |\n (words[words.length - 2]! << 8) |\n words[words.length - 1]!) >>>\n 0;\n if (crc32(bodyBytes) !== declared) {\n throw new EraSdkError('checksum-mismatch', 'bytewords: checksum mismatch');\n }\n return bodyBytes;\n}\n","import { EraSdkError } from '../core/errors';\nimport { bytewordsDecode, bytewordsEncode } from './bytewords';\n\n/** An immutable Uniform Resource: a registry type string plus its CBOR payload. */\nexport class Ur {\n readonly type: string;\n readonly cbor: Uint8Array;\n\n constructor(type: string, cbor: Uint8Array) {\n if (!/^[a-z][a-z0-9-]*$/.test(type)) {\n throw new EraSdkError('invalid-props', `\"${type}\" is not a valid UR type`);\n }\n this.type = type;\n this.cbor = cbor;\n }\n\n /** The whole UR as one single-part `ur:` string, lowercase (the loggable form). */\n toString(): string {\n return `ur:${this.type}/${bytewordsEncode(this.cbor)}`;\n }\n\n /** The single-part wire form, uppercase (QR alphanumeric mode). */\n toWireString(): string {\n return this.toString().toUpperCase();\n }\n}\n\nconst UR_GRAMMAR = /^ur:([a-z-]+)(\\/(\\d+-\\d+))?\\/([a-z]+)$/;\n\nexport interface ParsedUrParts {\n readonly type: string;\n /** null for a single-part UR. */\n readonly seq: { readonly num: number; readonly length: number } | null;\n readonly payload: Uint8Array;\n}\n\n/**\n * Parse one `ur:` string into (type, sequence, decoded payload).\n *\n * An ABSENT sequence segment means a single-part UR. A segment that is present\n * but unreadable (a number too wide, `0-0`) is a malformed frame and throws —\n * promoting it to \"single-part\" would send a broken fragment down the branch\n * that completes a scan.\n */\nexport function parseUrString(text: string): ParsedUrParts {\n const lower = text.toLowerCase();\n const match = UR_GRAMMAR.exec(lower);\n if (!match) {\n throw new EraSdkError('not-a-ur', 'not a ur: string');\n }\n const type = match[1]!;\n const seqSegment = match[3];\n const payload = bytewordsDecode(match[4]!);\n\n if (seqSegment === undefined) {\n return { type, seq: null, payload };\n }\n const [numText, lengthText] = seqSegment.split('-') as [string, string];\n const num = Number(numText);\n const length = Number(lengthText);\n if (!Number.isSafeInteger(num) || !Number.isSafeInteger(length) || num <= 0 || length <= 0) {\n throw new EraSdkError('malformed-sequence', 'unreadable ur sequence segment');\n }\n return { type, seq: { num, length }, payload };\n}\n\n/** The `ur:<type>/` prefix of a frame, without decoding the bytewords body. */\nconst TYPE_PREFIX = /^ur:([a-z][a-z0-9-]*)\\//;\n\nexport function urTypeOf(text: string): string | null {\n const match = TYPE_PREFIX.exec(text.toLowerCase());\n return match ? match[1]! : null;\n}\n","import { bytesToHex, hexToBytes } from './bytes';\nimport { EraSdkError } from './errors';\n\nexport type RandomBytesFn = (length: number) => Uint8Array;\n\n/**\n * 16 unpredictable bytes for a sign request id.\n *\n * A CSPRNG output, deliberately NOT a v4/v8 UUID: a UUID spends bits on the\n * wall clock and version fields, leaking the time of signing into the QR and\n * shrinking the unguessable part. The id is what a reply must echo to prove it\n * answers THIS request; it is formatted as a UUID string only where the wire\n * demands one (Tron's `signId`).\n */\nexport function randomRequestId(randomBytes?: RandomBytesFn): Uint8Array {\n if (randomBytes) {\n const out = randomBytes(16);\n if (!(out instanceof Uint8Array) || out.length !== 16) {\n throw new EraSdkError('no-secure-random', 'randomBytes(16) did not return 16 bytes');\n }\n return out;\n }\n const crypto = (globalThis as { crypto?: { getRandomValues?: (b: Uint8Array) => Uint8Array } })\n .crypto;\n if (crypto?.getRandomValues) {\n const out = new Uint8Array(16);\n crypto.getRandomValues(out);\n return out;\n }\n throw new EraSdkError(\n 'no-secure-random',\n 'no secure random source: install react-native-get-random-values (React Native) ' +\n 'or pass randomBytes in the EraConnect config',\n );\n}\n\n/** Render 16 bytes as a lowercase hyphenated UUID string (8-4-4-4-12). */\nexport function uuidStringify(bytes: Uint8Array): string {\n if (bytes.length !== 16) throw new EraSdkError('invalid-props', 'request id must be 16 bytes');\n const hex = bytesToHex(bytes);\n return `${hex.slice(0, 8)}-${hex.slice(8, 12)}-${hex.slice(12, 16)}-${hex.slice(16, 20)}-${hex.slice(20)}`;\n}\n\n/** Accept a request id as 16 raw bytes or a hyphenated/plain 32-hex string. */\nexport function normalizeRequestId(id: Uint8Array | string): Uint8Array {\n if (id instanceof Uint8Array) {\n if (id.length !== 16) throw new EraSdkError('invalid-props', 'request id must be 16 bytes');\n return new Uint8Array(id);\n }\n const hex = id.replace(/-/g, '');\n if (!/^[0-9a-fA-F]{32}$/.test(hex)) {\n throw new EraSdkError('invalid-props', 'request id string must be a 32-hex UUID');\n }\n return hexToBytes(hex.toLowerCase());\n}\n","/**\n * Bounds every field a scanned UR fragment can dictate, BEFORE that field is\n * allowed to size an allocation or a loop.\n *\n * A QR in the camera frame is attacker-controlled input: a sticker on the\n * device, a second screen, a poster. Without these bounds the fragment\n * header's `seqLength` goes straight into array allocation and into a\n * quadratic index shuffle, so ~60 characters of QR can ask the host for\n * gigabytes or minutes of work — no gzip, no multi-frame assembly, one frame.\n *\n * The numbers are generous headroom over real device traffic, NOT tight\n * protocol bounds: a cap that refuses a genuine reply is worse than the\n * denial of service it prevents.\n */\nexport const UrLimits = {\n /** Largest reassembled UR payload, in bytes. */\n maxMessageBytes: 64 * 1024,\n /** Largest number of source fragments a multi-part UR may declare. */\n maxFragmentCount: 2048,\n /** Largest single fragment payload, in bytes (QR v40 tops out at 2953). */\n maxFragmentBytes: 4096,\n /** Largest value for any u32 header field (`seqNum`, `checksum`). */\n maxUint32: 0xffffffff,\n} as const;\n\n/**\n * Whether a fragment header describes a UR that could exist.\n *\n * The two inequalities are the BC-UR relation\n * `seqLength == ceil(messageLength / fragmentLength)` written without\n * division — exactly what both fountain encoders produce. They stop a header\n * from claiming thousands of fragments for a twenty-byte message.\n *\n * `seqLength >= 2`, not 1: a \"multi-part\" UR with a single source fragment is\n * something neither encoder can produce (both short-circuit to a single-part\n * UR), and it would defeat the two-fragment stream-binding rule with two\n * static images (`1-1` and `2-1` differ only in seqNum and both resolve to\n * fragment 0).\n */\nexport function headerIsConsistent(header: {\n seqNum: number;\n seqLength: number;\n messageLength: number;\n checksum: number;\n fragmentLength: number;\n}): boolean {\n const { seqNum, seqLength, messageLength, checksum, fragmentLength } = header;\n if (seqNum < 1 || seqNum > UrLimits.maxUint32) return false;\n if (checksum < 0 || checksum > UrLimits.maxUint32) return false;\n if (seqLength < 2 || seqLength > UrLimits.maxFragmentCount) return false;\n if (fragmentLength < 1 || fragmentLength > UrLimits.maxFragmentBytes) return false;\n if (messageLength < 1 || messageLength > UrLimits.maxMessageBytes) return false;\n if (messageLength > seqLength * fragmentLength) return false;\n if (messageLength <= (seqLength - 1) * fragmentLength) return false;\n return true;\n}\n","/**\n * Xoshiro256** seeded from a 32-byte digest, with the exact\n * `(x >>> 11) * 2^-53` double conversion the BC-UR fountain code uses.\n *\n * The draw sequence IS the wire protocol: the device runs the same PRNG over\n * the same seed to derive which source fragments a fountain frame covers.\n */\n\nconst MASK64 = (1n << 64n) - 1n;\n\nfunction rotl(x: bigint, k: bigint): bigint {\n return ((x << k) | (x >> (64n - k))) & MASK64;\n}\n\nexport class Xoshiro256ss {\n private s0: bigint;\n private s1: bigint;\n private s2: bigint;\n private s3: bigint;\n\n /** Seed from a 32-byte digest split into four big-endian u64 words. */\n constructor(digest: Uint8Array) {\n if (digest.length !== 32) throw new Error('xoshiro seed must be 32 bytes');\n const word = (offset: number): bigint => {\n let v = 0n;\n for (let i = 0; i < 8; i++) v = (v << 8n) | BigInt(digest[offset + i]!);\n return v;\n };\n this.s0 = word(0);\n this.s1 = word(8);\n this.s2 = word(16);\n this.s3 = word(24);\n if ((this.s0 | this.s1 | this.s2 | this.s3) === 0n) {\n throw new Error('xoshiro seed must not be all zeros');\n }\n }\n\n nextRaw64(): bigint {\n const result = (rotl((this.s1 * 5n) & MASK64, 7n) * 9n) & MASK64;\n const t = (this.s1 << 17n) & MASK64;\n this.s2 ^= this.s0;\n this.s3 ^= this.s1;\n this.s1 ^= this.s2;\n this.s0 ^= this.s3;\n this.s2 ^= t;\n this.s3 = rotl(this.s3, 45n);\n return result;\n }\n\n /** Uniform double in [0, 1): top 53 bits of the raw draw. Exact — no precision loss. */\n nextDouble(): number {\n return Number(this.nextRaw64() >> 11n) * 2 ** -53;\n }\n}\n","import { sha256 } from '@noble/hashes/sha2';\nimport { concatBytes, u32be } from '../core/bytes';\nimport { UrLimits } from './limits';\nimport { Xoshiro256ss } from './xoshiro';\n\n/**\n * Which source fragments the fountain frame `seqNum` of `seqLength` covers.\n *\n * For `seqNum <= seqLength` the frame is the source fragment itself. Above\n * that, the BC-UR fountain sampler runs: seed = sha256(seqNum || checksum)\n * (both big-endian u32), Xoshiro256** drives an alias-method degree chooser\n * over `1/(i+1)` weights, then a full draw-without-replacement permutation of\n * which the first `degree` indexes are taken.\n *\n * Every draw below happens in the exact order of the reference\n * implementation. The draw order IS the wire protocol — a different (even\n * \"equivalent\") shuffle makes the device's fountain frames undecodable.\n */\nexport function chooseFragmentIndexes(\n seqNum: number,\n seqLength: number,\n checksum: number,\n): number[] {\n if (seqLength < 1 || seqLength > UrLimits.maxFragmentCount) {\n throw new RangeError(\n `seqLength ${seqLength} outside 1..${UrLimits.maxFragmentCount}; ` +\n 'cannot build fountain indexes for a UR this large',\n );\n }\n if (seqNum <= seqLength) return [seqNum - 1];\n\n const digest = sha256(concatBytes(u32be(seqNum), u32be(checksum)));\n const rng = new Xoshiro256ss(digest);\n\n // Alias-method table over degree weights 1/(i+1).\n const scaled = new Array<number>(seqLength);\n let sum = 0;\n for (let i = 0; i < seqLength; i++) sum += 1 / (i + 1);\n for (let i = 0; i < seqLength; i++) scaled[i] = ((1 / (i + 1)) * seqLength) / sum;\n\n const prob = new Array<number>(seqLength).fill(0);\n const alias = new Array<number>(seqLength).fill(0);\n const small: number[] = [];\n const large: number[] = [];\n for (let i = seqLength - 1; i >= 0; i--) {\n (scaled[i]! < 1 ? small : large).push(i);\n }\n while (small.length > 0 && large.length > 0) {\n const less = small.pop()!;\n const more = large.pop()!;\n prob[less] = scaled[less]!;\n alias[less] = more;\n scaled[more] = scaled[more]! + scaled[less]! - 1;\n (scaled[more]! < 1 ? small : large).push(more);\n }\n while (large.length > 0) prob[large.pop()!] = 1;\n while (small.length > 0) prob[small.pop()!] = 1;\n\n const c = Math.floor(rng.nextDouble() * prob.length);\n const sample = rng.nextDouble() < prob[c]! ? c : alias[c]!;\n const degree = sample + 1;\n\n // Full permutation by draw-without-replacement; take the first `degree`.\n const remaining: number[] = [];\n for (let i = 0; i < seqLength; i++) remaining.push(i);\n const permutation: number[] = [];\n while (remaining.length > 0) {\n const index = Math.floor(rng.nextDouble() * remaining.length);\n permutation.push(remaining.splice(index, 1)[0]!);\n }\n return permutation.slice(0, degree);\n}\n","import { cborDecode } from '../cbor/decode';\nimport { cborEncode } from '../cbor/encode';\nimport { cbArray, cbBytes, cbUint } from '../cbor/model';\nimport { headerIsConsistent, UrLimits } from './limits';\nimport { chooseFragmentIndexes } from './sampler';\n\n/** A validated multi-part UR fragment. */\nexport interface Fragment {\n readonly type: string;\n readonly seqNum: number;\n readonly seqLength: number;\n readonly messageLength: number;\n readonly checksum: number;\n readonly part: Uint8Array;\n readonly indexes: readonly number[];\n}\n\nexport const isSimple = (fragment: Fragment): boolean => fragment.indexes.length === 1;\n\n/** Fragment CBOR: the definite 5-array `[seqNum, seqLen, msgLen, checksum, bytes]`. */\nexport function fragmentCbor(\n seqNum: number,\n seqLength: number,\n messageLength: number,\n checksum: number,\n part: Uint8Array,\n): Uint8Array {\n return cborEncode(\n cbArray([\n cbUint(seqNum),\n cbUint(seqLength),\n cbUint(messageLength),\n cbUint(checksum),\n cbBytes(part),\n ]),\n );\n}\n\n/**\n * Parse and validate a fragment payload, or return null.\n *\n * Every field here is chosen by whoever printed the QR, and three of them size\n * allocations or loops downstream — so the bounds are checked as a set BEFORE\n * the (quadratic) fountain index derivation pays for anything.\n */\nexport function tryParseFragment(type: string, payload: Uint8Array): Fragment | null {\n let decoded: ReturnType<typeof cborDecode>;\n try {\n decoded = cborDecode(payload);\n } catch {\n return null;\n }\n if (decoded.kind !== 'array' || decoded.items.length !== 5) return null;\n\n const seqNum = uintInRange(decoded.items[0]);\n const seqLength = uintInRange(decoded.items[1]);\n const messageLength = uintInRange(decoded.items[2]);\n const checksum = uintInRange(decoded.items[3]);\n const partValue = decoded.items[4];\n if (\n seqNum === null ||\n seqLength === null ||\n messageLength === null ||\n checksum === null ||\n partValue?.kind !== 'bytes'\n ) {\n return null;\n }\n const part = partValue.value;\n if (\n !headerIsConsistent({ seqNum, seqLength, messageLength, checksum, fragmentLength: part.length })\n ) {\n return null;\n }\n return {\n type,\n seqNum,\n seqLength,\n messageLength,\n checksum,\n part,\n indexes: chooseFragmentIndexes(seqNum, seqLength, checksum),\n };\n}\n\n/** A CBOR uint in [0, 2^32), or null for anything else. */\nfunction uintInRange(value: { kind: string } | undefined): number | null {\n if (value?.kind !== 'uint') return null;\n const big = (value as { kind: 'uint'; value: bigint }).value;\n if (big < 0n || big > BigInt(UrLimits.maxUint32)) return null;\n return Number(big);\n}\n","import { EraSdkError } from '../core/errors';\nimport { bytewordsEncode } from './bytewords';\nimport { crc32 } from './crc32';\nimport { fragmentCbor } from './fragment';\nimport { chooseFragmentIndexes } from './sampler';\nimport type { Ur } from './ur';\n\n/**\n * BC-UR fountain encoder.\n *\n * Partitioning picks the LARGEST fragment length `<= maxFragmentLength` that\n * evenly covers the payload (`ceil(len/count)` for the smallest sufficient\n * `count`), and the last fragment is zero-padded to the common length — both\n * exactly as the reference encoders do, because the receiving side's header\n * consistency check assumes this relation.\n *\n * A payload that fits one fragment is emitted as the plain single-part\n * `ur:<type>/<body>` form on every call — never as a `1-1` sequence.\n */\nexport class UrFountainEncoder {\n readonly ur: Ur;\n private readonly fragments: Uint8Array[];\n private readonly checksum: number;\n private seqNum = 0;\n\n constructor(ur: Ur, maxFragmentLength = 180, minFragmentLength = 10) {\n if (ur.cbor.length === 0) {\n throw new EraSdkError('invalid-props', 'cannot encode an empty UR payload');\n }\n if (maxFragmentLength < minFragmentLength || maxFragmentLength <= 0 || minFragmentLength <= 0) {\n throw new EraSdkError('invalid-props', 'invalid fragment length bounds');\n }\n this.ur = ur;\n this.checksum = crc32(ur.cbor);\n this.fragments = partition(ur.cbor, maxFragmentLength, minFragmentLength);\n }\n\n get isSinglePart(): boolean {\n return this.fragments.length <= 1;\n }\n\n /** How many source fragments the payload was split into (1 for single-part). */\n get fragmentCount(): number {\n return this.fragments.length;\n }\n\n /** Next wire frame, uppercase. Single-part payloads return the same string every call. */\n nextPart(): string {\n if (this.isSinglePart) return this.ur.toWireString();\n\n this.seqNum += 1;\n const indexes = chooseFragmentIndexes(this.seqNum, this.fragments.length, this.checksum);\n const first = this.fragments[0]!;\n const mixed = new Uint8Array(first.length);\n for (const index of indexes) {\n const fragment = this.fragments[index]!;\n for (let i = 0; i < mixed.length; i++) mixed[i] = mixed[i]! ^ (fragment[i] ?? 0);\n }\n const body = fragmentCbor(\n this.seqNum,\n this.fragments.length,\n this.ur.cbor.length,\n this.checksum,\n mixed,\n );\n return `ur:${this.ur.type}/${this.seqNum}-${this.fragments.length}/${bytewordsEncode(body)}`.toUpperCase();\n }\n}\n\n/** Largest `ceil(len/count) <= maxLength` split, last fragment zero-padded. */\nfunction partition(payload: Uint8Array, maxLength: number, minLength: number): Uint8Array[] {\n const maxCount = Math.ceil(payload.length / minLength);\n let fragmentLength = payload.length;\n for (let count = 1; count <= maxCount; count++) {\n fragmentLength = Math.ceil(payload.length / count);\n if (fragmentLength <= maxLength) break;\n }\n const fragments: Uint8Array[] = [];\n for (let offset = 0; offset < payload.length; offset += fragmentLength) {\n const slice = payload.slice(offset, offset + fragmentLength);\n if (slice.length < fragmentLength) {\n const padded = new Uint8Array(fragmentLength);\n padded.set(slice);\n fragments.push(padded);\n } else {\n fragments.push(slice);\n }\n }\n return fragments;\n}\n","import { UrFountainEncoder } from '../ur/encoder';\nimport type { Ur } from '../ur/ur';\n\nexport interface AnimatedUrOptions {\n /**\n * Payload bytes per fountain fragment. The on-wire frame adds a ~16-byte\n * CBOR header, so the default 180 keeps frames within the ~200-byte\n * per-fragment ceiling hardware-wallet cameras scan reliably. Larger\n * fragments mean fewer frames but denser QR codes.\n */\n readonly maxFragmentLength?: number;\n}\n\nexport const DEFAULT_FRAGMENT_LENGTH = 180;\n\n/**\n * Frame source for rendering a UR as an animated QR.\n *\n * Drive `nextFrame()` from your own ticker (~8 fps is the battle-tested\n * default) and hand each string to your QR component. Frames are UPPERCASE so\n * the QR encoder can use alphanumeric mode (~45% denser than byte mode).\n */\nexport class AnimatedUr {\n private readonly encoder: UrFountainEncoder;\n\n constructor(ur: Ur, options?: AnimatedUrOptions) {\n this.encoder = new UrFountainEncoder(ur, options?.maxFragmentLength ?? DEFAULT_FRAGMENT_LENGTH);\n }\n\n /** Whether the payload fits one QR (no animation needed). */\n get isSingleFrame(): boolean {\n return this.encoder.isSinglePart;\n }\n\n /** The UR registry type being sent, e.g. `eth-sign-request`. */\n get urType(): string {\n return this.encoder.ur.type;\n }\n\n /** How many source fragments the payload was split into. */\n get fragmentCount(): number {\n return this.encoder.fragmentCount;\n }\n\n /** Next wire frame (uppercase). Single-frame payloads return the same string every call. */\n nextFrame(): string {\n return this.encoder.nextPart();\n }\n\n /** The whole request as ONE lowercase `ur:` string — the loggable form, not what is on screen. */\n toString(): string {\n return this.encoder.ur.toString();\n }\n}\n","import type { EraErrorCode } from '../core/errors';\nimport { EraSdkError } from '../core/errors';\nimport { crc32 } from './crc32';\nimport type { Fragment } from './fragment';\nimport { isSimple, tryParseFragment } from './fragment';\nimport { UrLimits } from './limits';\nimport { parseUrString, Ur } from './ur';\n\n/** Why the last frame was turned away by validation (null = used or buffered). */\nexport interface UrRefusal {\n readonly code: EraErrorCode;\n readonly message: string;\n}\n\n/**\n * BC-UR fountain decoder with hostile-input stream binding.\n *\n * The naive decoder pins its expectations to the FIRST fragment it ever sees\n * and drops everything that disagrees. That is right while the only thing in\n * front of the camera is the device — and it is exactly how one hostile QR (a\n * sticker, a poster, a second screen) used to end the whole session: it bound\n * first, and the device's real answer could never assemble.\n *\n * The cure is to make binding harder, not reversible:\n *\n * - a stream binds only PROVISIONALLY on its first fragment, and is\n * CONFIRMED only when a second, distinct fragment of the same stream\n * arrives (same fingerprint, different seqNum). A static QR is one\n * fragment forever and can never confirm itself;\n * - a provisional binding is dropped after 32 non-matching frames — a\n * genuine stream confirms on its very next frame, so this cannot be aimed\n * at one;\n * - a CONFIRMED binding is never evicted. Any recovery path is an eviction\n * path, so there is none. A rogue fragment that poisons the XOR costs the\n * accumulated progress (rescan one animation pass), never the binding;\n * - a single-part UR cannot complete the scan while a confirmed multi-part\n * assembly holds received fragments.\n *\n * What this does not defend against is an attacker who owns the camera\n * outright — if the only well-formed UR in view is theirs, it assembles. The\n * layers above (type pinning per request, request-id echo, verification\n * helpers) are what refuse that.\n */\nexport class UrDecoder {\n private boundType = '';\n private seqLength = 0;\n private expectedMessageLength = 0;\n private expectedChecksum = 0;\n private expectedFragmentLength = 0;\n private confirmed = false;\n private framesSinceBinding = 0;\n private bindingSeqNum = 0;\n\n private readonly expectedIndexes: number[] = [];\n private readonly receivedIndexes: number[] = [];\n private mixedParts: Fragment[] = [];\n private readonly queuedParts: Fragment[] = [];\n private readonly simpleParts: Fragment[] = [];\n\n private payload: Uint8Array | null = null;\n private completedType = '';\n\n /** How long a provisional binding may stand without a second fragment of its own. */\n private static readonly framesBeforeDroppingProvisional = 32;\n\n lastRefusal: UrRefusal | null = null;\n\n get isComplete(): boolean {\n return this.payload !== null;\n }\n\n /** The type of the bound (or completed) stream; empty until one binds. */\n get type(): string {\n return this.payload !== null ? this.completedType : this.boundType;\n }\n\n get partsExpected(): number {\n return this.expectedIndexes.length;\n }\n\n get partsReceived(): number {\n return this.receivedIndexes.length;\n }\n\n /** Assembly progress in [0, 1]. */\n get progress(): number {\n if (this.isComplete) return 1;\n if (this.expectedIndexes.length === 0) return 0;\n return this.receivedIndexes.length / this.expectedIndexes.length;\n }\n\n /** The assembled UR. Throws until `isComplete`. */\n result(): Ur {\n if (this.payload === null) {\n throw new EraSdkError('incomplete-scan', 'UR not fully assembled yet');\n }\n return new Ur(this.completedType, this.payload);\n }\n\n /**\n * Feed one scanned frame. Returns true once the UR is fully assembled.\n *\n * Throws EraSdkError for frames that are not parseable URs at all\n * (`not-a-ur`, `malformed-bytewords`, `checksum-mismatch`,\n * `malformed-sequence`); refusals of parseable frames set [lastRefusal]\n * and return false.\n */\n receivePart(text: string): boolean {\n if (this.isComplete) return false;\n this.lastRefusal = null;\n\n const parsed = parseUrString(text);\n\n if (parsed.seq === null) {\n // Single-part branch. It never reaches the fragment-header bounds, so\n // the ceiling is enforced here too — otherwise this is the one shape\n // that can hand an unbounded payload to the layers above.\n if (parsed.payload.length === 0 || parsed.payload.length > UrLimits.maxMessageBytes) {\n this.lastRefusal = {\n code: 'limit-exceeded',\n message: `single-part payload of ${parsed.payload.length} bytes is outside 1..${UrLimits.maxMessageBytes}`,\n };\n return false;\n }\n // A single-part frame must not walk over an assembly under way: every\n // genuine device reply is single-part, so the veto is deliberately\n // narrow — only a CONFIRMED multi-part stream with collected fragments.\n if (this.confirmed && this.receivedIndexes.length > 0) {\n this.lastRefusal = {\n code: 'fragment-mismatch',\n message: `a single-part UR arrived while a \"${this.boundType}\" assembly was under way`,\n };\n return false;\n }\n this.completedType = parsed.type;\n this.payload = parsed.payload;\n return true;\n }\n\n // Validated BEFORE construction: index derivation is quadratic in the\n // header's seqLength, so an unchecked header has already cost whatever\n // the attacker asked for by the time anyone could reject it.\n const fragment = tryParseFragment(parsed.type, parsed.payload);\n if (fragment === null) {\n this.lastRefusal = {\n code: 'limit-exceeded',\n message: 'fragment header is malformed or outside the UrLimits bounds',\n };\n return false;\n }\n if (fragment.seqNum !== parsed.seq.num || fragment.seqLength !== parsed.seq.length) {\n this.lastRefusal = {\n code: 'fragment-mismatch',\n message: 'fragment header disagrees with the ur: path sequence',\n };\n return false;\n }\n if (!this.checkBinding(fragment)) return false;\n\n this.queuedParts.push(fragment);\n while (!this.isComplete && this.queuedParts.length > 0) {\n this.processQueuedItem();\n }\n return this.isComplete;\n }\n\n private fingerprintOf(\n type: string,\n seqLength: number,\n messageLength: number,\n checksum: number,\n fragmentLength: number,\n ): string {\n return `${type}|${seqLength}|${messageLength}|${checksum}|${fragmentLength}`;\n }\n\n /** Decide whether the fragment belongs to the bound stream; bind/confirm/drop per the rules above. */\n private checkBinding(fragment: Fragment): boolean {\n const fingerprint = this.fingerprintOf(\n fragment.type,\n fragment.seqLength,\n fragment.messageLength,\n fragment.checksum,\n fragment.part.length,\n );\n\n if (this.boundType !== '') {\n const bound = this.fingerprintOf(\n this.boundType,\n this.seqLength,\n this.expectedMessageLength,\n this.expectedChecksum,\n this.expectedFragmentLength,\n );\n if (fingerprint === bound) {\n // A second DISTINCT fragment is the proof; the same frame held in\n // front of the camera cannot confirm itself.\n if (!this.confirmed && fragment.seqNum !== this.bindingSeqNum) this.confirmed = true;\n return true;\n }\n if (this.confirmed) {\n this.lastRefusal = {\n code: 'fragment-mismatch',\n message: 'fragment belongs to a different stream than the confirmed assembly',\n };\n return false;\n }\n this.framesSinceBinding += 1;\n if (this.framesSinceBinding < UrDecoder.framesBeforeDroppingProvisional) {\n this.lastRefusal = {\n code: 'fragment-mismatch',\n message: 'fragment belongs to a different stream than the provisional binding',\n };\n return false;\n }\n this.discardBinding();\n }\n\n this.boundType = fragment.type;\n this.seqLength = fragment.seqLength;\n this.expectedMessageLength = fragment.messageLength;\n this.expectedChecksum = fragment.checksum;\n this.expectedFragmentLength = fragment.part.length;\n this.bindingSeqNum = fragment.seqNum;\n this.confirmed = false;\n this.framesSinceBinding = 0;\n\n this.expectedIndexes.length = 0;\n for (let i = 0; i < fragment.seqLength; i++) this.expectedIndexes.push(i);\n return true;\n }\n\n /** Drop a binding that never proved itself (provisional only). */\n private discardBinding(): void {\n this.boundType = '';\n this.seqLength = 0;\n this.expectedMessageLength = 0;\n this.expectedChecksum = 0;\n this.expectedFragmentLength = 0;\n this.confirmed = false;\n this.framesSinceBinding = 0;\n this.bindingSeqNum = 0;\n this.expectedIndexes.length = 0;\n this.receivedIndexes.length = 0;\n this.mixedParts = [];\n this.queuedParts.length = 0;\n this.simpleParts.length = 0;\n }\n\n /**\n * Throw away the accumulation, KEEPING the binding.\n *\n * Reached when the reassembled payload does not hash to the stream's own\n * declared checksum — a rogue fragment that copied the visible header and\n * poisoned the XOR. Unbinding here would hand back the eviction primitive\n * the binding rule denies, so only the collected fragments are discarded:\n * one pass of the animation for the genuine sender, one fragment per pass\n * for the attacker, forever.\n */\n private discardAccumulation(): void {\n this.expectedIndexes.length = 0;\n if (this.seqLength > 0) {\n for (let i = 0; i < this.seqLength; i++) this.expectedIndexes.push(i);\n }\n this.receivedIndexes.length = 0;\n this.mixedParts = [];\n this.queuedParts.length = 0;\n this.simpleParts.length = 0;\n }\n\n private processQueuedItem(): void {\n const part = this.queuedParts.shift();\n if (!part) return;\n if (isSimple(part)) {\n this.processSimplePart(part);\n } else {\n this.processMixedPart(part);\n }\n }\n\n private processSimplePart(fragment: Fragment): void {\n const fragmentIndex = fragment.indexes[0]!;\n if (this.receivedIndexes.includes(fragmentIndex)) return;\n\n this.simpleParts.push(fragment);\n this.receivedIndexes.push(fragmentIndex);\n\n if (sameMembers(this.receivedIndexes, this.expectedIndexes)) {\n const sorted = [...this.simpleParts].sort((a, b) => a.indexes[0]! - b.indexes[0]!);\n let joinedLength = 0;\n for (const p of sorted) joinedLength += p.part.length;\n const joined = new Uint8Array(joinedLength);\n let offset = 0;\n for (const p of sorted) {\n joined.set(p.part, offset);\n offset += p.part.length;\n }\n if (joined.length < this.expectedMessageLength) {\n this.discardAccumulation();\n return;\n }\n const candidate = joined.slice(0, this.expectedMessageLength);\n // Between fragments the checksum only proves they agree with each\n // other; against the assembled message it proves the message is the one\n // the stream was describing. This is the single check that catches a\n // rogue fragment XOR'd into a genuine stream.\n if (crc32(candidate) !== this.expectedChecksum) {\n this.discardAccumulation();\n return;\n }\n this.completedType = this.boundType;\n this.payload = candidate;\n } else {\n this.reduceMixedBy(fragment);\n }\n }\n\n private processMixedPart(fragment: Fragment): void {\n if (this.mixedParts.some((e) => sameMembers([...e.indexes], [...fragment.indexes]))) return;\n // Distinct mixed parts are attacker-suppliable one per frame and each is\n // compared against every other on the next reduction. A real stream never\n // holds more mixed parts than it has source fragments. Backstop only —\n // the reduction's collapse rate keeps real lists tiny.\n if (this.mixedParts.length >= UrLimits.maxFragmentCount) return;\n\n let simple = fragment;\n for (const s of this.simpleParts) simple = this.reducePartByPart(simple, s);\n\n let part = simple;\n for (const m of this.mixedParts) part = this.reducePartByPart(part, m);\n\n if (isSimple(part)) {\n this.queuedParts.push(part);\n } else {\n this.reduceMixedBy(part);\n this.mixedParts.push(part);\n }\n }\n\n private reduceMixedBy(fragment: Fragment): void {\n const newMixed: Fragment[] = [];\n for (const item of this.mixedParts) {\n const reduced = this.reducePartByPart(item, fragment);\n if (isSimple(reduced)) {\n this.queuedParts.push(item);\n } else {\n newMixed.push(reduced);\n }\n }\n this.mixedParts = newMixed;\n }\n\n private reducePartByPart(a: Fragment, b: Fragment): Fragment {\n if (!b.indexes.every((e) => a.indexes.includes(e))) return a;\n\n const newIndexes = a.indexes.filter((e) => !b.indexes.includes(e));\n const newLength = Math.max(a.part.length, b.part.length);\n const newPart = new Uint8Array(newLength);\n for (let i = 0; i < newLength; i++) {\n newPart[i] = (a.part[i] ?? 0) ^ (b.part[i] ?? 0);\n }\n return {\n type: a.type,\n seqNum: a.seqNum,\n seqLength: a.seqLength,\n messageLength: this.expectedMessageLength,\n checksum: crc32(a.part),\n part: newPart,\n indexes: newIndexes,\n };\n }\n}\n\n/** Order-insensitive membership equality (mirrors the reference `arraysEqual`). */\nfunction sameMembers(a: readonly number[], b: readonly number[]): boolean {\n if (a.length !== b.length) return false;\n return a.every((e) => b.includes(e));\n}\n","import type { EraErrorCode } from '../core/errors';\nimport { EraSdkError } from '../core/errors';\nimport { UrDecoder } from '../ur/decoder';\nimport type { Ur } from '../ur/ur';\nimport { urTypeOf } from '../ur/ur';\n\nexport interface UrScannerOptions {\n /**\n * Pin: frames of any other UR type are rejected BEFORE the fountain decoder\n * sees them. The decoder commits to a stream once one binds, so a frame that\n * gets that far has a say in what the rest of the session may look like —\n * pinning is the cheap half of the hostile-QR cure (the decoder's\n * two-fragment binding rule is the other half).\n */\n readonly expectedTypes?: readonly string[];\n}\n\nexport interface ScanRejection {\n readonly code: EraErrorCode;\n readonly message: string;\n /**\n * Consecutive occurrences of this same rejection. A static hostile or\n * malformed QR produces the identical rejection at camera framerate; this\n * counter lets a UI or a log show it once instead of ~10 times per second.\n */\n readonly repeated: number;\n}\n\nexport type ScanFeedResult =\n | {\n readonly kind: 'progress';\n readonly progress: number;\n readonly framesReceived: number;\n readonly framesExpected: number;\n }\n | { readonly kind: 'duplicate' }\n | { readonly kind: 'rejected'; readonly rejection: ScanRejection }\n | { readonly kind: 'complete'; readonly ur: Ur };\n\n/**\n * Accumulates camera frames into a UR. Synchronous and non-throwing on the\n * feed path (safe to call from camera callbacks); malformed frames come back\n * as typed rejections, never exceptions.\n */\nexport class UrScanner {\n private readonly decoder = new UrDecoder();\n private readonly expectedTypes: ReadonlySet<string> | null;\n private readonly seen = new Set<string>();\n private rejection: ScanRejection | null = null;\n\n /** Distinct frames remembered for dedup. Attacker-suppliable strings, so capped. */\n private static readonly maxRememberedFrames = 4096;\n\n constructor(options?: UrScannerOptions) {\n this.expectedTypes = options?.expectedTypes ? new Set(options.expectedTypes) : null;\n }\n\n get isComplete(): boolean {\n return this.decoder.isComplete;\n }\n\n get progress(): number {\n return this.decoder.progress;\n }\n\n /** The UR type of the bound stream, or null until one binds. */\n get urType(): string | null {\n return this.decoder.type === '' ? null : this.decoder.type;\n }\n\n get framesReceived(): number {\n return this.decoder.partsReceived;\n }\n\n get framesExpected(): number {\n return this.decoder.partsExpected;\n }\n\n get lastRejection(): ScanRejection | null {\n return this.rejection;\n }\n\n /** Feed one scanned frame. */\n receivePart(frame: string): ScanFeedResult {\n if (this.decoder.isComplete) {\n return { kind: 'complete', ur: this.decoder.result() };\n }\n if (this.seen.has(frame)) return { kind: 'duplicate' };\n\n // Type pin BEFORE any decoding work.\n const type = urTypeOf(frame);\n if (type === null) {\n return this.reject('not-a-ur', 'not a UR frame');\n }\n if (this.expectedTypes && !this.expectedTypes.has(type)) {\n // The type is attacker-sized (the grammar allows an unbounded letter\n // run) — truncate before it reaches a message or a log.\n const shown = type.length > 32 ? `${type.slice(0, 32)}…` : type;\n return this.reject(\n 'wrong-ur-type',\n `ignored a \"${shown}\" frame; expected ${[...this.expectedTypes].join(' or ')}`,\n );\n }\n\n // Remembered only now: junk that never reached the decoder must not be\n // able to fill the dedup budget.\n if (this.seen.size < UrScanner.maxRememberedFrames) this.seen.add(frame);\n\n let complete: boolean;\n try {\n complete = this.decoder.receivePart(frame);\n } catch (e) {\n // Only the code, never the frame contents — attacker-sized, and on the\n // linking path a wallet's own bytes.\n const code = e instanceof EraSdkError ? e.code : 'not-a-ur';\n return this.reject(code, 'unreadable UR frame');\n }\n if (this.decoder.lastRefusal) {\n return this.reject(this.decoder.lastRefusal.code, this.decoder.lastRefusal.message);\n }\n if (complete) {\n this.rejection = null;\n return { kind: 'complete', ur: this.decoder.result() };\n }\n return {\n kind: 'progress',\n progress: this.decoder.progress,\n framesReceived: this.decoder.partsReceived,\n framesExpected: this.decoder.partsExpected,\n };\n }\n\n /** The assembled UR. Throws `incomplete-scan` until done. */\n result(): Ur {\n return this.decoder.result();\n }\n\n private reject(code: EraErrorCode, message: string): ScanFeedResult {\n const previous = this.rejection;\n this.rejection =\n previous && previous.code === code && previous.message === message\n ? { code, message, repeated: previous.repeated + 1 }\n : { code, message, repeated: 1 };\n return { kind: 'rejected', rejection: this.rejection };\n }\n}\n\n/** A scanner whose completed UR parses into a typed result (a chain signature). */\nexport class TypedUrScanner<TResult> extends UrScanner {\n constructor(\n options: UrScannerOptions,\n private readonly parseResult: (ur: Ur) => TResult,\n ) {\n super(options);\n }\n\n /** Assemble + parse + validate (UR type, request-id echo) in one call. */\n parse(): TResult {\n return this.parseResult(this.result());\n }\n}\n","import { cborDecode } from '../cbor/decode';\nimport type { CborValue } from '../cbor/model';\nimport { asMap, mapGet, stripTags } from '../cbor/model';\nimport { equalBytes } from '../core/bytes';\nimport { EraSdkError } from '../core/errors';\nimport type { RandomBytesFn } from '../core/rand';\nimport { normalizeRequestId, randomRequestId } from '../core/rand';\nimport type { AnimatedUrOptions } from '../qr/animated-ur';\nimport { AnimatedUr, DEFAULT_FRAGMENT_LENGTH } from '../qr/animated-ur';\nimport { TypedUrScanner } from '../scan/ur-scanner';\nimport type { Ur } from '../ur/ur';\nimport { parseUrString, Ur as UrValue } from '../ur/ur';\n\n/** Resolved SDK configuration handed to every chain module. */\nexport interface ChainContext {\n readonly origin: string;\n readonly randomBytes: RandomBytesFn | undefined;\n readonly maxFragmentLength: number;\n}\n\n/** SDK configuration. Everything is optional; the SDK performs NO network I/O ever. */\nexport interface EraConnectConfig {\n /**\n * Wallet name the device shows the user on every request (\"Sign for\n * <origin>?\"). Set it once here; individual requests can override.\n */\n readonly origin?: string | undefined;\n /**\n * CSPRNG override. By default `globalThis.crypto.getRandomValues` is used;\n * on React Native install `react-native-get-random-values`, or inject a\n * secure source here. Request-id minting throws `no-secure-random` when\n * neither is available.\n */\n readonly randomBytes?: RandomBytesFn | undefined;\n /** Default payload bytes per animated-QR fragment (180 unless overridden). */\n readonly maxFragmentLength?: number | undefined;\n}\n\nexport const DEFAULT_ORIGIN = 'ERA Connect';\n\nexport function resolveContext(config?: EraConnectConfig | ChainContext): ChainContext {\n return {\n origin: config?.origin ?? DEFAULT_ORIGIN,\n randomBytes: config?.randomBytes ?? undefined,\n maxFragmentLength: config?.maxFragmentLength ?? DEFAULT_FRAGMENT_LENGTH,\n };\n}\n\n/** Optional expectations when parsing a reply standalone (outside `SignRequest.scanner()`). */\nexport interface ExpectedReply {\n readonly requestId?: Uint8Array | string;\n}\n\n/**\n * A built sign request: the UR to display plus everything needed to consume\n * the reply. The request id is minted at CONSTRUCTION so the same object that\n * renders the QR also validates the echo — a reply carrying a different id\n * (from an earlier, cancelled flow re-presented to the camera) is refused\n * instead of accepted.\n */\nexport interface SignRequest<TResult> {\n readonly ur: Ur;\n /** Absent only where the protocol has no request id (Bitcoin PSBT). */\n readonly requestId: Uint8Array | undefined;\n /** UR types that can answer THIS request. */\n readonly replyTypes: readonly string[];\n /** Non-fatal advisories (e.g. `blind-sign-threshold`). */\n readonly warnings: readonly string[];\n /** Fragment + animate for display. */\n toAnimated(options?: AnimatedUrOptions): AnimatedUr;\n /** A scanner pre-pinned to `replyTypes`; its `parse()` validates the request-id echo. */\n scanner(): TypedUrScanner<TResult>;\n}\n\nexport function makeSignRequest<TResult>(args: {\n ur: Ur;\n requestId?: Uint8Array;\n replyTypes: readonly string[];\n warnings?: readonly string[];\n context: ChainContext;\n parse: (ur: Ur) => TResult;\n}): SignRequest<TResult> {\n const { ur, requestId, replyTypes, context, parse } = args;\n return {\n ur,\n requestId,\n replyTypes,\n warnings: args.warnings ?? [],\n toAnimated: (options?: AnimatedUrOptions) =>\n new AnimatedUr(ur, {\n maxFragmentLength:\n options?.maxFragmentLength ?? context.maxFragmentLength ?? DEFAULT_FRAGMENT_LENGTH,\n }),\n scanner: () => new TypedUrScanner<TResult>({ expectedTypes: replyTypes }, parse),\n };\n}\n\n/** Mint or normalize a request id. */\nexport function resolveRequestId(\n context: ChainContext,\n requestId: Uint8Array | string | undefined,\n): Uint8Array {\n return requestId === undefined\n ? randomRequestId(context.randomBytes)\n : normalizeRequestId(requestId);\n}\n\n/** Accept a reply as a `Ur` object or a single-part `ur:` string. */\nexport function toUr(input: Ur | string): Ur {\n if (typeof input !== 'string') return input;\n const parsed = parseUrString(input);\n if (parsed.seq !== null) {\n throw new EraSdkError(\n 'invalid-props',\n 'multi-part UR string: assemble it with the request scanner first',\n );\n }\n return new UrValue(parsed.type, parsed.payload);\n}\n\n// ---------------------------------------------------------------------------\n// Reply checks: what every `*-signature` must pass before it is a signature.\n// ---------------------------------------------------------------------------\n\nexport function requireUrType(ur: Ur, expected: readonly string[], what: string): void {\n if (!expected.includes(ur.type)) {\n // Attacker-sized string — truncate before it reaches a message or error data.\n const shown = ur.type.length > 32 ? `${ur.type.slice(0, 32)}…` : ur.type;\n throw new EraSdkError(\n 'wrong-ur-type',\n `unexpected ${what} UR type \"${shown}\", expected ${expected.join(' or ')}`,\n { received: shown, expected },\n );\n }\n}\n\nexport function requireReplyMap(ur: Ur, what: string): CborValue {\n let decoded: CborValue;\n try {\n decoded = cborDecode(ur.cbor);\n } catch (e) {\n throw new EraSdkError(\n 'malformed-cbor',\n `${what} is not readable CBOR: ${(e as Error).message}`,\n );\n }\n const map = asMap(decoded);\n if (!map) throw new EraSdkError('malformed-reply', `${what} is not a CBOR map`);\n return map;\n}\n\n/**\n * The reply must echo the request id byte for byte.\n *\n * BYTES, not CBOR values: the device wraps the echo in the UUID tag (37) while\n * requests may send it untagged, so a value-level comparison would reject\n * every genuine reply. An absent echo is a reply that did not come from the\n * request in hand (the device echoes unconditionally when the request carried\n * an id) and is refused rather than tolerated.\n */\nexport function requireRequestIdEcho(\n map: CborValue,\n key: number,\n expected: Uint8Array | undefined,\n what: string,\n): Uint8Array {\n const echoed = mapGet(map, key);\n const value = echoed === undefined ? undefined : stripTags(echoed);\n if (value?.kind !== 'bytes') {\n throw new EraSdkError('malformed-reply', `${what} does not echo the request id (key ${key})`);\n }\n if (expected !== undefined && !equalBytes(value.value, expected)) {\n throw new EraSdkError(\n 'request-id-mismatch',\n `${what} echoes a different request id — it answers another sign request, not this one`,\n );\n }\n return value.value;\n}\n\n/** A signature whose length is inside `[min, max]`, or a typed refusal. */\nexport function requireSignatureBytes(\n value: CborValue | undefined,\n what: string,\n min: number,\n max: number,\n): Uint8Array {\n const v = value === undefined ? undefined : stripTags(value);\n if (v?.kind !== 'bytes') {\n throw new EraSdkError('malformed-reply', `${what} is missing the signature (key 2)`);\n }\n const length = v.value.length;\n if (length < min || length > max) {\n throw new EraSdkError(\n 'malformed-reply',\n `${what} signature is ${length} bytes, expected ${min === max ? `${min}` : `${min}-${max}`}`,\n );\n }\n return v.value;\n}\n"],"mappings":";;;AA2CA,IAAa,cAAb,cAAiC,MAAM;CAIrC,YAAY,MAAoB,SAAiB,SAAmC;EAClF,MAAM,OAAO;EACb,KAAK,OAAO;EACZ,KAAK,OAAO;EACZ,IAAI,YAAY,KAAA,GAAW,KAAK,UAAU;CAC5C;AACF;;;AClCA,MAAa,UAAU,UAAsC;CAC3D,MAAM,IAAI,OAAO,UAAU,WAAW,OAAO,KAAK,IAAI;CACtD,IAAI,IAAI,IAAI,MAAM,IAAI,YAAY,iBAAiB,wBAAwB;CAC3E,OAAO;EAAE,MAAM;EAAQ,OAAO;CAAE;AAClC;AACA,MAAa,WAAW,WAAkC;CAAE,MAAM;CAAS;AAAM;AACjF,MAAa,UAAU,WAA8B;CAAE,MAA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G,KAAK,kCAAkC;CAErF,MAAM,SAAS,EAAE,MAAM;CACvB,IAAI,SAAS,OAAO,SAAS,KAC3B,MAAM,IAAI,YACR,mBACA,GAAG,KAAK,gBAAgB,OAAO,mBAAmB,QAAQ,MAAM,GAAG,QAAQ,GAAG,IAAI,GAAG,OACvF;CAEF,OAAO,EAAE;AACX"}
|
|
@@ -88,77 +88,6 @@ function asBool(value) {
|
|
|
88
88
|
return v.kind === "bool" ? v.value : void 0;
|
|
89
89
|
}
|
|
90
90
|
//#endregion
|
|
91
|
-
//#region src/registry/keypath.ts
|
|
92
|
-
const PATH_LEVEL = /^(\d+)('?)$/;
|
|
93
|
-
const HARDENED_OFFSET = 2147483648;
|
|
94
|
-
/** Parse `m/44'/60'/0'/0/5` into levels. Throws `invalid-props` on anything else. */
|
|
95
|
-
function parsePath(path) {
|
|
96
|
-
if (!path.startsWith("m/")) throw new EraSdkError("invalid-props", `derivation path must start with "m/": ${path}`);
|
|
97
|
-
const segments = path.slice(2).split("/");
|
|
98
|
-
const levels = [];
|
|
99
|
-
for (const segment of segments) {
|
|
100
|
-
const match = PATH_LEVEL.exec(segment);
|
|
101
|
-
if (!match) throw new EraSdkError("invalid-props", `bad derivation path segment "${segment}"`);
|
|
102
|
-
const index = Number(match[1]);
|
|
103
|
-
if (!Number.isSafeInteger(index) || index >= HARDENED_OFFSET) throw new EraSdkError("invalid-props", `derivation index out of range in "${segment}"`);
|
|
104
|
-
levels.push({
|
|
105
|
-
index,
|
|
106
|
-
hardened: match[2] === "'"
|
|
107
|
-
});
|
|
108
|
-
}
|
|
109
|
-
if (levels.length === 0) throw new EraSdkError("invalid-props", "derivation path has no levels");
|
|
110
|
-
return levels;
|
|
111
|
-
}
|
|
112
|
-
function formatPath(levels) {
|
|
113
|
-
return `m/${levels.map((l) => `${l.index}${l.hardened ? "'" : ""}`).join("/")}`;
|
|
114
|
-
}
|
|
115
|
-
function pathEquals(a, b) {
|
|
116
|
-
if (a.length !== b.length) return false;
|
|
117
|
-
return a.every((l, i) => l.index === b[i].index && l.hardened === b[i].hardened);
|
|
118
|
-
}
|
|
119
|
-
/** Flat `[index, hardened, index, hardened, ...]` component list. */
|
|
120
|
-
function pathComponentsCbor(levels) {
|
|
121
|
-
const items = [];
|
|
122
|
-
for (const level of levels) items.push(cbUint(level.index), cbBool(level.hardened));
|
|
123
|
-
return cbArray(items);
|
|
124
|
-
}
|
|
125
|
-
/** A `crypto-keypath` (tag 304): `{1: components, 2: xfp}` (key 2 omitted when no xfp). */
|
|
126
|
-
function keypath304(levels, xfp) {
|
|
127
|
-
const entries = [[1, pathComponentsCbor(levels)]];
|
|
128
|
-
if (xfp !== void 0) entries.push([2, cbUint(xfp)]);
|
|
129
|
-
return cbTag(304, cbMap(entries));
|
|
130
|
-
}
|
|
131
|
-
/** Parse the flat component list of a `crypto-keypath` back into levels (null on malformed). */
|
|
132
|
-
function parsePathComponents(value) {
|
|
133
|
-
const items = asArray(value);
|
|
134
|
-
if (!items || items.length % 2 !== 0) return null;
|
|
135
|
-
const levels = [];
|
|
136
|
-
for (let i = 0; i < items.length; i += 2) {
|
|
137
|
-
const index = asUint(items[i]);
|
|
138
|
-
const hardened = asBool(items[i + 1]);
|
|
139
|
-
if (index === void 0 || hardened === void 0 || index >= BigInt(HARDENED_OFFSET)) return null;
|
|
140
|
-
levels.push({
|
|
141
|
-
index: Number(index),
|
|
142
|
-
hardened
|
|
143
|
-
});
|
|
144
|
-
}
|
|
145
|
-
return levels;
|
|
146
|
-
}
|
|
147
|
-
/** Normalize an xfp given as a u32 int or an 8-hex string into a u32 number. */
|
|
148
|
-
function normalizeXfp(xfp) {
|
|
149
|
-
if (typeof xfp === "number") {
|
|
150
|
-
if (!Number.isSafeInteger(xfp) || xfp < 0 || xfp > 4294967295) throw new EraSdkError("invalid-props", "xfp must be an unsigned 32-bit integer");
|
|
151
|
-
return xfp;
|
|
152
|
-
}
|
|
153
|
-
const hex = xfp.startsWith("0x") ? xfp.slice(2) : xfp;
|
|
154
|
-
if (!/^[0-9a-fA-F]{1,8}$/.test(hex)) throw new EraSdkError("invalid-props", "xfp string must be up to 8 hex characters");
|
|
155
|
-
return Number.parseInt(hex, 16);
|
|
156
|
-
}
|
|
157
|
-
/** Lowercase 8-hex form of an xfp (the display / Tron wire form). */
|
|
158
|
-
function xfpToHex(xfp) {
|
|
159
|
-
return xfp.toString(16).padStart(8, "0");
|
|
160
|
-
}
|
|
161
|
-
//#endregion
|
|
162
91
|
//#region src/core/bytes.ts
|
|
163
92
|
/** Byte helpers. `Uint8Array` end-to-end; no Buffer, no Node built-ins. */
|
|
164
93
|
function concatBytes(...arrays) {
|
|
@@ -1521,6 +1450,12 @@ Object.defineProperty(exports, "asArray", {
|
|
|
1521
1450
|
return asArray;
|
|
1522
1451
|
}
|
|
1523
1452
|
});
|
|
1453
|
+
Object.defineProperty(exports, "asBool", {
|
|
1454
|
+
enumerable: true,
|
|
1455
|
+
get: function() {
|
|
1456
|
+
return asBool;
|
|
1457
|
+
}
|
|
1458
|
+
});
|
|
1524
1459
|
Object.defineProperty(exports, "asBytes", {
|
|
1525
1460
|
enumerable: true,
|
|
1526
1461
|
get: function() {
|
|
@@ -1569,6 +1504,12 @@ Object.defineProperty(exports, "cbArray", {
|
|
|
1569
1504
|
return cbArray;
|
|
1570
1505
|
}
|
|
1571
1506
|
});
|
|
1507
|
+
Object.defineProperty(exports, "cbBool", {
|
|
1508
|
+
enumerable: true,
|
|
1509
|
+
get: function() {
|
|
1510
|
+
return cbBool;
|
|
1511
|
+
}
|
|
1512
|
+
});
|
|
1572
1513
|
Object.defineProperty(exports, "cbBytes", {
|
|
1573
1514
|
enumerable: true,
|
|
1574
1515
|
get: function() {
|
|
@@ -1629,24 +1570,12 @@ Object.defineProperty(exports, "equalBytes", {
|
|
|
1629
1570
|
return equalBytes;
|
|
1630
1571
|
}
|
|
1631
1572
|
});
|
|
1632
|
-
Object.defineProperty(exports, "formatPath", {
|
|
1633
|
-
enumerable: true,
|
|
1634
|
-
get: function() {
|
|
1635
|
-
return formatPath;
|
|
1636
|
-
}
|
|
1637
|
-
});
|
|
1638
1573
|
Object.defineProperty(exports, "hexToBytes", {
|
|
1639
1574
|
enumerable: true,
|
|
1640
1575
|
get: function() {
|
|
1641
1576
|
return hexToBytes;
|
|
1642
1577
|
}
|
|
1643
1578
|
});
|
|
1644
|
-
Object.defineProperty(exports, "keypath304", {
|
|
1645
|
-
enumerable: true,
|
|
1646
|
-
get: function() {
|
|
1647
|
-
return keypath304;
|
|
1648
|
-
}
|
|
1649
|
-
});
|
|
1650
1579
|
Object.defineProperty(exports, "makeSignRequest", {
|
|
1651
1580
|
enumerable: true,
|
|
1652
1581
|
get: function() {
|
|
@@ -1665,36 +1594,12 @@ Object.defineProperty(exports, "normalizeRequestId", {
|
|
|
1665
1594
|
return normalizeRequestId;
|
|
1666
1595
|
}
|
|
1667
1596
|
});
|
|
1668
|
-
Object.defineProperty(exports, "normalizeXfp", {
|
|
1669
|
-
enumerable: true,
|
|
1670
|
-
get: function() {
|
|
1671
|
-
return normalizeXfp;
|
|
1672
|
-
}
|
|
1673
|
-
});
|
|
1674
|
-
Object.defineProperty(exports, "parsePath", {
|
|
1675
|
-
enumerable: true,
|
|
1676
|
-
get: function() {
|
|
1677
|
-
return parsePath;
|
|
1678
|
-
}
|
|
1679
|
-
});
|
|
1680
|
-
Object.defineProperty(exports, "parsePathComponents", {
|
|
1681
|
-
enumerable: true,
|
|
1682
|
-
get: function() {
|
|
1683
|
-
return parsePathComponents;
|
|
1684
|
-
}
|
|
1685
|
-
});
|
|
1686
1597
|
Object.defineProperty(exports, "parseUrString", {
|
|
1687
1598
|
enumerable: true,
|
|
1688
1599
|
get: function() {
|
|
1689
1600
|
return parseUrString;
|
|
1690
1601
|
}
|
|
1691
1602
|
});
|
|
1692
|
-
Object.defineProperty(exports, "pathEquals", {
|
|
1693
|
-
enumerable: true,
|
|
1694
|
-
get: function() {
|
|
1695
|
-
return pathEquals;
|
|
1696
|
-
}
|
|
1697
|
-
});
|
|
1698
1603
|
Object.defineProperty(exports, "requireReplyMap", {
|
|
1699
1604
|
enumerable: true,
|
|
1700
1605
|
get: function() {
|
|
@@ -1767,11 +1672,5 @@ Object.defineProperty(exports, "uuidStringify", {
|
|
|
1767
1672
|
return uuidStringify;
|
|
1768
1673
|
}
|
|
1769
1674
|
});
|
|
1770
|
-
Object.defineProperty(exports, "xfpToHex", {
|
|
1771
|
-
enumerable: true,
|
|
1772
|
-
get: function() {
|
|
1773
|
-
return xfpToHex;
|
|
1774
|
-
}
|
|
1775
|
-
});
|
|
1776
1675
|
|
|
1777
|
-
//# sourceMappingURL=shared-
|
|
1676
|
+
//# sourceMappingURL=shared-Cu2yynP9.cjs.map
|