@cardanowall/sdk-ts 0.1.0 → 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.
- package/README.md +14 -14
- package/dist/client/index.cjs +34 -34
- package/dist/client/index.cjs.map +1 -1
- package/dist/client/index.d.cts +52 -52
- package/dist/client/index.d.ts +52 -52
- package/dist/client/index.js +33 -33
- package/dist/client/index.js.map +1 -1
- package/dist/conformance/cli.cjs +17 -17
- package/dist/conformance/cli.cjs.map +1 -1
- package/dist/conformance/cli.js +17 -17
- package/dist/conformance/cli.js.map +1 -1
- package/dist/identity/index.cjs.map +1 -1
- package/dist/identity/index.d.cts +1 -1
- package/dist/identity/index.d.ts +1 -1
- package/dist/identity/index.js.map +1 -1
- package/dist/ids/index.cjs.map +1 -1
- package/dist/ids/index.js.map +1 -1
- package/dist/index.cjs +50 -50
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +3 -3
- package/dist/index.d.ts +3 -3
- package/dist/index.js +48 -48
- package/dist/index.js.map +1 -1
- package/dist/merkle/index.cjs +1 -1
- package/dist/merkle/index.cjs.map +1 -1
- package/dist/merkle/index.js +1 -1
- package/dist/merkle/index.js.map +1 -1
- package/dist/{types-BQMtbRCb.d.cts → types-DGsZTMuZ.d.cts} +6 -6
- package/dist/{types-BQMtbRCb.d.ts → types-DGsZTMuZ.d.ts} +6 -6
- package/dist/verifier/index.cjs +17 -17
- package/dist/verifier/index.cjs.map +1 -1
- package/dist/verifier/index.d.cts +3 -3
- package/dist/verifier/index.d.ts +3 -3
- package/dist/verifier/index.js +17 -17
- package/dist/verifier/index.js.map +1 -1
- package/package.json +8 -8
package/dist/ids/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/ids/crockford-base32.ts","../../src/ids/prefixed-id.ts","../../src/ids/zod-schemas.ts"],"names":["z"],"mappings":";;;;;AAiBA,IAAM,QAAA,GAAW,kCAAA;AAIjB,IAAM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AA,CAA2B,KAAK,IAAI,CAAA;AAC7C;ACxFA,IAAM,eAAA,GAAkB,wBAAA;AAEjB,IAAM,aAAA,GAAgB;AAEtB,IAAM,WAAA,GAAcA,KAAA,CACxB,MAAA,EAAO,CACP,KAAA,CAAM,IAAI,MAAA,CAAO,CAAA,CAAA,EAAI,aAAa,CAAA,CAAA,EAAI,eAAe,CAAA,CAAA,CAAG,GAAG,gBAAgB;AAEvE,IAAM,cAAA,GAAiB,CAAA,CAAA,EAAI,aAAa,CAAA,CAAA,EAAI,eAAe,CAAA,CAAA","file":"index.cjs","sourcesContent":["// Crockford Base32 codec for 16-byte UUID payloads (yielding 26-char strings).\n//\n// Alphabet per https://www.crockford.com/base32.html — `0123456789ABCDEFGHJKMNPQRSTVWXYZ`\n// (32 symbols; the letters I, L, O, U are intentionally excluded for visual\n// disambiguation against digits and to avoid accidental profanity in\n// generated identifiers).\n//\n// Encoding: 16 raw bytes (128 bits) packs into exactly 26 base32 symbols\n// (130 bits with 2 trailing zero-padding bits we drop on encode and\n// reconstruct on decode). No `=` padding character is emitted — UUID payloads\n// are fixed-width.\n//\n// Decoding: case-insensitive (per Crockford spec); we also tolerate the\n// disambiguation map I/L → 1, O → 0. The encoded length MUST be 26 chars;\n// rejection is explicit (callers downstream feed the bytes back into a UUIDv7\n// validator anyway, so we surface the length problem at the codec boundary).\n\nconst ALPHABET = '0123456789abcdefghjkmnpqrstvwxyz';\n\n// 256-entry decode table indexed by lowercased ASCII char code. -1 = invalid.\n// We populate it once at module load.\nconst DECODE_TABLE: Int8Array = (() => {\n const table = new Int8Array(128).fill(-1);\n for (let i = 0; i < ALPHABET.length; i++) {\n const ch = ALPHABET.charCodeAt(i);\n table[ch] = i;\n // Uppercase variant (Crockford accepts case-insensitive input).\n const upper = String.fromCharCode(ch).toUpperCase().charCodeAt(0);\n table[upper] = i;\n }\n // Crockford disambiguation: I, L → 1; O → 0; U is reserved (always invalid).\n table['I'.charCodeAt(0)] = 1;\n table['i'.charCodeAt(0)] = 1;\n table['L'.charCodeAt(0)] = 1;\n table['l'.charCodeAt(0)] = 1;\n table['O'.charCodeAt(0)] = 0;\n table['o'.charCodeAt(0)] = 0;\n return table;\n})();\n\nexport const CROCKFORD_ENCODED_LENGTH_FOR_UUID = 26;\n\n/**\n * Encode `bytes.length` raw bytes as a lowercase Crockford base32 string.\n * Output length is `ceil(bytes.length * 8 / 5)` — no `=` padding character.\n * For 16-byte UUIDs this produces 26 chars; for 32-byte API-key secrets it\n * produces 52 chars (256 bits of entropy, matching the Stripe / OpenAI /\n * Anthropic secret-key entropy class).\n */\nexport function encodeBytesVariableLength(bytes: Uint8Array): string {\n let bits = 0;\n let bitCount = 0;\n let out = '';\n for (let i = 0; i < bytes.length; i++) {\n bits = (bits << 8) | bytes[i]!;\n bitCount += 8;\n while (bitCount >= 5) {\n bitCount -= 5;\n const idx = (bits >>> bitCount) & 0x1f;\n out += ALPHABET[idx];\n }\n }\n if (bitCount > 0) {\n const idx = (bits << (5 - bitCount)) & 0x1f;\n out += ALPHABET[idx];\n }\n return out;\n}\n\n/**\n * Encode 16 raw bytes (a UUID payload) as a 26-char lowercase Crockford\n * base32 string. Throws if the input is not exactly 16 bytes.\n */\nexport function encodeBytes(bytes: Uint8Array): string {\n if (bytes.length !== 16) {\n throw new Error(`crockford-base32: expected 16 bytes, got ${bytes.length}`);\n }\n // 16 bytes × 8 = 128 bits → 26 × 5 = 130 bits; we pad the input with 2 zero\n // bits on the right, which simply means we treat byte[15] as occupying the\n // top 8 bits of a 10-bit window for the final two symbols.\n return encodeBytesVariableLength(bytes);\n}\n\n/**\n * Decode a 26-char Crockford base32 string back to 16 raw bytes.\n * Case-insensitive; accepts the I/L → 1, O → 0 disambiguation mappings.\n * Throws on wrong length, invalid characters, or non-zero pad bits.\n */\nexport function decodeBytes(encoded: string): Uint8Array {\n if (encoded.length !== CROCKFORD_ENCODED_LENGTH_FOR_UUID) {\n throw new Error(\n `crockford-base32: expected ${CROCKFORD_ENCODED_LENGTH_FOR_UUID}-char input, got ${encoded.length}`,\n );\n }\n const out = new Uint8Array(16);\n let bits = 0;\n let bitCount = 0;\n let outIdx = 0;\n for (let i = 0; i < encoded.length; i++) {\n const code = encoded.charCodeAt(i);\n const value = code < 128 ? DECODE_TABLE[code]! : -1;\n if (value < 0) {\n throw new Error(\n `crockford-base32: invalid character ${JSON.stringify(encoded[i])} at index ${i}`,\n );\n }\n bits = (bits << 5) | value;\n bitCount += 5;\n if (bitCount >= 8) {\n bitCount -= 8;\n out[outIdx++] = (bits >>> bitCount) & 0xff;\n }\n }\n // After 26 symbols × 5 = 130 bits consumed and 16 bytes × 8 = 128 bits\n // emitted, there should be exactly 2 trailing zero pad bits. Anything else\n // means the input wasn't produced by our encoder (or was tampered with).\n if (bitCount !== 2 || (bits & 0x3) !== 0) {\n throw new Error('crockford-base32: non-zero pad bits at end of input');\n }\n return out;\n}\n","// Stripe-style prefixed resource IDs. The Postgres column stays UUIDv7; the\n// wire form is `<prefix>_<26-char-crockford-base32>`. This module is the\n// only place that knows the byte-level encoding — everything else (Zod\n// schemas, route handlers, SDK types) consumes the helpers below.\n//\n// We intentionally do NOT bind the helpers to a closed prefix enum here: the\n// SDK is published as a versioned dependency and adding a new resource type\n// (e.g. `topup_*`) must not require an SDK bump just to validate the wire.\n// The helpers therefore take the prefix as a generic string parameter; the\n// per-resource Zod schemas in `./zod-schemas.ts` are the place to enumerate\n// the known prefixes for validation purposes.\n\nimport { decodeBytes, encodeBytes } from './crockford-base32';\n\n/**\n * Branded string type — `${prefix}_<26-base32-chars>`. The phantom `__brand`\n * field gives TypeScript a way to refuse a bare string at API boundaries\n * (`function fn(id: PrefixedId<'poe'>)`) while staying ABI-compatible with\n * `string` on the wire and in JSON serialisation.\n */\nexport type PrefixedId<P extends string> = `${P}_${string}` & { readonly __brand: P };\n\n// 32-char hex UUID without separators is what the encoder converts to bytes.\nconst UUID_RE_BYTES = /^[0-9a-f]{32}$/;\n\nfunction uuidStringToBytes(uuid: string): Uint8Array {\n // Accept canonical 8-4-4-4-12 hyphenated form (case-insensitive) only —\n // this is what every UUIDv4/v7 library produces and what Postgres returns\n // for the UUIDv7 columns. Anything else (no hyphens, wrong width, non-hex)\n // is rejected.\n const hex = uuid.replace(/-/g, '').toLowerCase();\n if (!UUID_RE_BYTES.test(hex) || uuid.replace(/[^-]/g, '').length !== 4) {\n throw new Error(`prefixed-id: not a canonical hyphenated UUID: ${JSON.stringify(uuid)}`);\n }\n const out = new Uint8Array(16);\n for (let i = 0; i < 16; i++) {\n out[i] = parseInt(hex.slice(i * 2, i * 2 + 2), 16);\n }\n return out;\n}\n\nfunction bytesToUuidString(bytes: Uint8Array): string {\n if (bytes.length !== 16) {\n throw new Error(`prefixed-id: expected 16 decoded bytes, got ${bytes.length}`);\n }\n const hex = Array.from(bytes, (b) => b.toString(16).padStart(2, '0')).join('');\n return `${hex.slice(0, 8)}-${hex.slice(8, 12)}-${hex.slice(12, 16)}-${hex.slice(16, 20)}-${hex.slice(20)}`;\n}\n\n/**\n * Encode a bare canonical UUID string (8-4-4-4-12 hyphenated) into the\n * Stripe-style wire form `${prefix}_<crockford>`.\n */\nexport function encodePrefixedId<P extends string>(prefix: P, uuid: string): PrefixedId<P> {\n const bytes = uuidStringToBytes(uuid);\n const encoded = encodeBytes(bytes);\n return `${prefix}_${encoded}` as PrefixedId<P>;\n}\n\n/**\n * Decode a wire-format prefixed id back to the bare canonical UUID string.\n * Throws when the prefix does not match, the body is not 26 base32 chars,\n * or the encoded payload is malformed.\n */\nexport function decodePrefixedId<P extends string>(prefix: P, encoded: string): string {\n if (typeof encoded !== 'string') {\n throw new Error(`prefixed-id: expected string, got ${typeof encoded}`);\n }\n const sep = encoded.indexOf('_');\n if (sep < 0) {\n throw new Error(`prefixed-id: missing prefix separator in ${JSON.stringify(encoded)}`);\n }\n const actualPrefix = encoded.slice(0, sep);\n if (actualPrefix !== prefix) {\n throw new Error(\n `prefixed-id: expected prefix ${JSON.stringify(prefix)}, got ${JSON.stringify(actualPrefix)}`,\n );\n }\n const body = encoded.slice(sep + 1);\n const bytes = decodeBytes(body);\n return bytesToUuidString(bytes);\n}\n\n/**\n * Type guard. Cheap-check: matches the prefix and the lowercase Crockford\n * length, but does NOT validate the payload bytes round-trip. Use\n * `decodePrefixedId` when a full validation is required.\n */\nexport function isPrefixedId<P extends string>(\n prefix: P,\n candidate: unknown,\n): candidate is PrefixedId<P> {\n if (typeof candidate !== 'string') return false;\n if (!candidate.startsWith(`${prefix}_`)) return false;\n const body = candidate.slice(prefix.length + 1);\n if (body.length !== 26) return false;\n // Strict Crockford alphabet — no I, L, O, U; lowercase only on the wire.\n return /^[0-9a-hjkmnp-tv-z]{26}$/.test(body);\n}\n","// Zod schema gating the CIP-309 record id at every parse boundary (HTTP route\n// handlers, SDK input validation, OpenAPI registration).\n//\n// The regex is the strict Crockford-32 alphabet (lowercase only on the wire,\n// no I/L/O/U). This is stricter than `[0-9a-z]{26}` because it catches the\n// most common typo classes (`poe_…ol1u…`) at the parser rather than letting\n// them through to the decoder for a confusing `non-zero pad bits` error.\n\nimport { z } from 'zod';\n\nconst CROCKFORD_LOWER = '[0-9a-hjkmnp-tv-z]{26}';\n\nexport const POE_ID_PREFIX = 'poe' as const;\n\nexport const PoeIdSchema = z\n .string()\n .regex(new RegExp(`^${POE_ID_PREFIX}_${CROCKFORD_LOWER}$`), 'invalid poe id');\n\nexport const POE_ID_PATTERN = `^${POE_ID_PREFIX}_${CROCKFORD_LOWER}$`;\n"]}
|
|
1
|
+
{"version":3,"sources":["../../src/ids/crockford-base32.ts","../../src/ids/prefixed-id.ts","../../src/ids/zod-schemas.ts"],"names":["z"],"mappings":";;;;;AAiBA,IAAM,QAAA,GAAW,kCAAA;AAIjB,IAAM,gBAA2B,MAAM;AACrC,EAAA,MAAM,QAAQ,IAAI,SAAA,CAAU,GAAG,CAAA,CAAE,KAAK,EAAE,CAAA;AACxC,EAAA,KAAA,IAAS,CAAA,GAAI,CAAA,EAAG,CAAA,GAAI,QAAA,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M,IAAI,MAAA,CAAO,CAAA,CAAA,EAAI,aAAa,CAAA,CAAA,EAAI,eAAe,CAAA,CAAA,CAAG,GAAG,gBAAgB;AAEvE,IAAM,cAAA,GAAiB,CAAA,CAAA,EAAI,aAAa,CAAA,CAAA,EAAI,eAAe,CAAA,CAAA","file":"index.cjs","sourcesContent":["// Crockford Base32 codec for 16-byte UUID payloads (yielding 26-char strings).\n//\n// Alphabet per https://www.crockford.com/base32.html — `0123456789ABCDEFGHJKMNPQRSTVWXYZ`\n// (32 symbols; the letters I, L, O, U are intentionally excluded for visual\n// disambiguation against digits and to avoid accidental profanity in\n// generated identifiers).\n//\n// Encoding: 16 raw bytes (128 bits) packs into exactly 26 base32 symbols\n// (130 bits with 2 trailing zero-padding bits we drop on encode and\n// reconstruct on decode). No `=` padding character is emitted — UUID payloads\n// are fixed-width.\n//\n// Decoding: case-insensitive (per Crockford spec); we also tolerate the\n// disambiguation map I/L → 1, O → 0. The encoded length MUST be 26 chars;\n// rejection is explicit (callers downstream feed the bytes back into a UUIDv7\n// validator anyway, so we surface the length problem at the codec boundary).\n\nconst ALPHABET = '0123456789abcdefghjkmnpqrstvwxyz';\n\n// 256-entry decode table indexed by lowercased ASCII char code. -1 = invalid.\n// We populate it once at module load.\nconst DECODE_TABLE: Int8Array = (() => {\n const table = new Int8Array(128).fill(-1);\n for (let i = 0; i < ALPHABET.length; i++) {\n const ch = ALPHABET.charCodeAt(i);\n table[ch] = i;\n // Uppercase variant (Crockford accepts case-insensitive input).\n const upper = String.fromCharCode(ch).toUpperCase().charCodeAt(0);\n table[upper] = i;\n }\n // Crockford disambiguation: I, L → 1; O → 0; U is reserved (always invalid).\n table['I'.charCodeAt(0)] = 1;\n table['i'.charCodeAt(0)] = 1;\n table['L'.charCodeAt(0)] = 1;\n table['l'.charCodeAt(0)] = 1;\n table['O'.charCodeAt(0)] = 0;\n table['o'.charCodeAt(0)] = 0;\n return table;\n})();\n\nexport const CROCKFORD_ENCODED_LENGTH_FOR_UUID = 26;\n\n/**\n * Encode `bytes.length` raw bytes as a lowercase Crockford base32 string.\n * Output length is `ceil(bytes.length * 8 / 5)` — no `=` padding character.\n * For 16-byte UUIDs this produces 26 chars; for 32-byte API-key secrets it\n * produces 52 chars (256 bits of entropy, matching the Stripe / OpenAI /\n * Anthropic secret-key entropy class).\n */\nexport function encodeBytesVariableLength(bytes: Uint8Array): string {\n let bits = 0;\n let bitCount = 0;\n let out = '';\n for (let i = 0; i < bytes.length; i++) {\n bits = (bits << 8) | bytes[i]!;\n bitCount += 8;\n while (bitCount >= 5) {\n bitCount -= 5;\n const idx = (bits >>> bitCount) & 0x1f;\n out += ALPHABET[idx];\n }\n }\n if (bitCount > 0) {\n const idx = (bits << (5 - bitCount)) & 0x1f;\n out += ALPHABET[idx];\n }\n return out;\n}\n\n/**\n * Encode 16 raw bytes (a UUID payload) as a 26-char lowercase Crockford\n * base32 string. Throws if the input is not exactly 16 bytes.\n */\nexport function encodeBytes(bytes: Uint8Array): string {\n if (bytes.length !== 16) {\n throw new Error(`crockford-base32: expected 16 bytes, got ${bytes.length}`);\n }\n // 16 bytes × 8 = 128 bits → 26 × 5 = 130 bits; we pad the input with 2 zero\n // bits on the right, which simply means we treat byte[15] as occupying the\n // top 8 bits of a 10-bit window for the final two symbols.\n return encodeBytesVariableLength(bytes);\n}\n\n/**\n * Decode a 26-char Crockford base32 string back to 16 raw bytes.\n * Case-insensitive; accepts the I/L → 1, O → 0 disambiguation mappings.\n * Throws on wrong length, invalid characters, or non-zero pad bits.\n */\nexport function decodeBytes(encoded: string): Uint8Array {\n if (encoded.length !== CROCKFORD_ENCODED_LENGTH_FOR_UUID) {\n throw new Error(\n `crockford-base32: expected ${CROCKFORD_ENCODED_LENGTH_FOR_UUID}-char input, got ${encoded.length}`,\n );\n }\n const out = new Uint8Array(16);\n let bits = 0;\n let bitCount = 0;\n let outIdx = 0;\n for (let i = 0; i < encoded.length; i++) {\n const code = encoded.charCodeAt(i);\n const value = code < 128 ? DECODE_TABLE[code]! : -1;\n if (value < 0) {\n throw new Error(\n `crockford-base32: invalid character ${JSON.stringify(encoded[i])} at index ${i}`,\n );\n }\n bits = (bits << 5) | value;\n bitCount += 5;\n if (bitCount >= 8) {\n bitCount -= 8;\n out[outIdx++] = (bits >>> bitCount) & 0xff;\n }\n }\n // After 26 symbols × 5 = 130 bits consumed and 16 bytes × 8 = 128 bits\n // emitted, there should be exactly 2 trailing zero pad bits. Anything else\n // means the input wasn't produced by our encoder (or was tampered with).\n if (bitCount !== 2 || (bits & 0x3) !== 0) {\n throw new Error('crockford-base32: non-zero pad bits at end of input');\n }\n return out;\n}\n","// Stripe-style prefixed resource IDs. The Postgres column stays UUIDv7; the\n// wire form is `<prefix>_<26-char-crockford-base32>`. This module is the\n// only place that knows the byte-level encoding — everything else (Zod\n// schemas, route handlers, SDK types) consumes the helpers below.\n//\n// We intentionally do NOT bind the helpers to a closed prefix enum here: the\n// SDK is published as a versioned dependency and adding a new resource type\n// (e.g. `topup_*`) must not require an SDK bump just to validate the wire.\n// The helpers therefore take the prefix as a generic string parameter; the\n// per-resource Zod schemas in `./zod-schemas.ts` are the place to enumerate\n// the known prefixes for validation purposes.\n\nimport { decodeBytes, encodeBytes } from './crockford-base32';\n\n/**\n * Branded string type — `${prefix}_<26-base32-chars>`. The phantom `__brand`\n * field gives TypeScript a way to refuse a bare string at API boundaries\n * (`function fn(id: PrefixedId<'poe'>)`) while staying ABI-compatible with\n * `string` on the wire and in JSON serialisation.\n */\nexport type PrefixedId<P extends string> = `${P}_${string}` & { readonly __brand: P };\n\n// 32-char hex UUID without separators is what the encoder converts to bytes.\nconst UUID_RE_BYTES = /^[0-9a-f]{32}$/;\n\nfunction uuidStringToBytes(uuid: string): Uint8Array {\n // Accept canonical 8-4-4-4-12 hyphenated form (case-insensitive) only —\n // this is what every UUIDv4/v7 library produces and what Postgres returns\n // for the UUIDv7 columns. Anything else (no hyphens, wrong width, non-hex)\n // is rejected.\n const hex = uuid.replace(/-/g, '').toLowerCase();\n if (!UUID_RE_BYTES.test(hex) || uuid.replace(/[^-]/g, '').length !== 4) {\n throw new Error(`prefixed-id: not a canonical hyphenated UUID: ${JSON.stringify(uuid)}`);\n }\n const out = new Uint8Array(16);\n for (let i = 0; i < 16; i++) {\n out[i] = parseInt(hex.slice(i * 2, i * 2 + 2), 16);\n }\n return out;\n}\n\nfunction bytesToUuidString(bytes: Uint8Array): string {\n if (bytes.length !== 16) {\n throw new Error(`prefixed-id: expected 16 decoded bytes, got ${bytes.length}`);\n }\n const hex = Array.from(bytes, (b) => b.toString(16).padStart(2, '0')).join('');\n return `${hex.slice(0, 8)}-${hex.slice(8, 12)}-${hex.slice(12, 16)}-${hex.slice(16, 20)}-${hex.slice(20)}`;\n}\n\n/**\n * Encode a bare canonical UUID string (8-4-4-4-12 hyphenated) into the\n * Stripe-style wire form `${prefix}_<crockford>`.\n */\nexport function encodePrefixedId<P extends string>(prefix: P, uuid: string): PrefixedId<P> {\n const bytes = uuidStringToBytes(uuid);\n const encoded = encodeBytes(bytes);\n return `${prefix}_${encoded}` as PrefixedId<P>;\n}\n\n/**\n * Decode a wire-format prefixed id back to the bare canonical UUID string.\n * Throws when the prefix does not match, the body is not 26 base32 chars,\n * or the encoded payload is malformed.\n */\nexport function decodePrefixedId<P extends string>(prefix: P, encoded: string): string {\n if (typeof encoded !== 'string') {\n throw new Error(`prefixed-id: expected string, got ${typeof encoded}`);\n }\n const sep = encoded.indexOf('_');\n if (sep < 0) {\n throw new Error(`prefixed-id: missing prefix separator in ${JSON.stringify(encoded)}`);\n }\n const actualPrefix = encoded.slice(0, sep);\n if (actualPrefix !== prefix) {\n throw new Error(\n `prefixed-id: expected prefix ${JSON.stringify(prefix)}, got ${JSON.stringify(actualPrefix)}`,\n );\n }\n const body = encoded.slice(sep + 1);\n const bytes = decodeBytes(body);\n return bytesToUuidString(bytes);\n}\n\n/**\n * Type guard. Cheap-check: matches the prefix and the lowercase Crockford\n * length, but does NOT validate the payload bytes round-trip. Use\n * `decodePrefixedId` when a full validation is required.\n */\nexport function isPrefixedId<P extends string>(\n prefix: P,\n candidate: unknown,\n): candidate is PrefixedId<P> {\n if (typeof candidate !== 'string') return false;\n if (!candidate.startsWith(`${prefix}_`)) return false;\n const body = candidate.slice(prefix.length + 1);\n if (body.length !== 26) return false;\n // Strict Crockford alphabet — no I, L, O, U; lowercase only on the wire.\n return /^[0-9a-hjkmnp-tv-z]{26}$/.test(body);\n}\n","// Zod schema gating the Label 309 record id at every parse boundary (HTTP route\n// handlers, SDK input validation, OpenAPI registration).\n//\n// The regex is the strict Crockford-32 alphabet (lowercase only on the wire,\n// no I/L/O/U). This is stricter than `[0-9a-z]{26}` because it catches the\n// most common typo classes (`poe_…ol1u…`) at the parser rather than letting\n// them through to the decoder for a confusing `non-zero pad bits` error.\n\nimport { z } from 'zod';\n\nconst CROCKFORD_LOWER = '[0-9a-hjkmnp-tv-z]{26}';\n\nexport const POE_ID_PREFIX = 'poe' as const;\n\nexport const PoeIdSchema = z\n .string()\n .regex(new RegExp(`^${POE_ID_PREFIX}_${CROCKFORD_LOWER}$`), 'invalid poe id');\n\nexport const POE_ID_PATTERN = `^${POE_ID_PREFIX}_${CROCKFORD_LOWER}$`;\n"]}
|
package/dist/ids/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/ids/crockford-base32.ts","../../src/ids/prefixed-id.ts","../../src/ids/zod-schemas.ts"],"names":[],"mappings":";;;AAiBA,IAAM,QAAA,GAAW,kCAAA;AAIjB,IAAM,gBAA2B,MAAM;AACrC,EAAA,MAAM,QAAQ,IAAI,SAAA,CAAU,GAAG,CAAA,CAAE,KAAK,EAAE,CAAA;AACxC,EAAA,KAAA,IAAS,CAAA,GAAI,CAAA,EAAG,CAAA,GAAI,QAAA,CAAS,QAAQ,CAAA,EAAA,EAAK;AACxC,IAAA,MAAM,EAAA,GAAK,QAAA,CAAS,UAAA,CAAW,CAAC,CAAA;AAChC,IAAA,KAAA,CAAM,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AiB,CAAA,CAAA,EAAI,aAAa,CAAA,CAAA,EAAI,eAAe,CAAA,CAAA","file":"index.js","sourcesContent":["// Crockford Base32 codec for 16-byte UUID payloads (yielding 26-char strings).\n//\n// Alphabet per https://www.crockford.com/base32.html — `0123456789ABCDEFGHJKMNPQRSTVWXYZ`\n// (32 symbols; the letters I, L, O, U are intentionally excluded for visual\n// disambiguation against digits and to avoid accidental profanity in\n// generated identifiers).\n//\n// Encoding: 16 raw bytes (128 bits) packs into exactly 26 base32 symbols\n// (130 bits with 2 trailing zero-padding bits we drop on encode and\n// reconstruct on decode). No `=` padding character is emitted — UUID payloads\n// are fixed-width.\n//\n// Decoding: case-insensitive (per Crockford spec); we also tolerate the\n// disambiguation map I/L → 1, O → 0. The encoded length MUST be 26 chars;\n// rejection is explicit (callers downstream feed the bytes back into a UUIDv7\n// validator anyway, so we surface the length problem at the codec boundary).\n\nconst ALPHABET = '0123456789abcdefghjkmnpqrstvwxyz';\n\n// 256-entry decode table indexed by lowercased ASCII char code. -1 = invalid.\n// We populate it once at module load.\nconst DECODE_TABLE: Int8Array = (() => {\n const table = new Int8Array(128).fill(-1);\n for (let i = 0; i < ALPHABET.length; i++) {\n const ch = ALPHABET.charCodeAt(i);\n table[ch] = i;\n // Uppercase variant (Crockford accepts case-insensitive input).\n const upper = String.fromCharCode(ch).toUpperCase().charCodeAt(0);\n table[upper] = i;\n }\n // Crockford disambiguation: I, L → 1; O → 0; U is reserved (always invalid).\n table['I'.charCodeAt(0)] = 1;\n table['i'.charCodeAt(0)] = 1;\n table['L'.charCodeAt(0)] = 1;\n table['l'.charCodeAt(0)] = 1;\n table['O'.charCodeAt(0)] = 0;\n table['o'.charCodeAt(0)] = 0;\n return table;\n})();\n\nexport const CROCKFORD_ENCODED_LENGTH_FOR_UUID = 26;\n\n/**\n * Encode `bytes.length` raw bytes as a lowercase Crockford base32 string.\n * Output length is `ceil(bytes.length * 8 / 5)` — no `=` padding character.\n * For 16-byte UUIDs this produces 26 chars; for 32-byte API-key secrets it\n * produces 52 chars (256 bits of entropy, matching the Stripe / OpenAI /\n * Anthropic secret-key entropy class).\n */\nexport function encodeBytesVariableLength(bytes: Uint8Array): string {\n let bits = 0;\n let bitCount = 0;\n let out = '';\n for (let i = 0; i < bytes.length; i++) {\n bits = (bits << 8) | bytes[i]!;\n bitCount += 8;\n while (bitCount >= 5) {\n bitCount -= 5;\n const idx = (bits >>> bitCount) & 0x1f;\n out += ALPHABET[idx];\n }\n }\n if (bitCount > 0) {\n const idx = (bits << (5 - bitCount)) & 0x1f;\n out += ALPHABET[idx];\n }\n return out;\n}\n\n/**\n * Encode 16 raw bytes (a UUID payload) as a 26-char lowercase Crockford\n * base32 string. Throws if the input is not exactly 16 bytes.\n */\nexport function encodeBytes(bytes: Uint8Array): string {\n if (bytes.length !== 16) {\n throw new Error(`crockford-base32: expected 16 bytes, got ${bytes.length}`);\n }\n // 16 bytes × 8 = 128 bits → 26 × 5 = 130 bits; we pad the input with 2 zero\n // bits on the right, which simply means we treat byte[15] as occupying the\n // top 8 bits of a 10-bit window for the final two symbols.\n return encodeBytesVariableLength(bytes);\n}\n\n/**\n * Decode a 26-char Crockford base32 string back to 16 raw bytes.\n * Case-insensitive; accepts the I/L → 1, O → 0 disambiguation mappings.\n * Throws on wrong length, invalid characters, or non-zero pad bits.\n */\nexport function decodeBytes(encoded: string): Uint8Array {\n if (encoded.length !== CROCKFORD_ENCODED_LENGTH_FOR_UUID) {\n throw new Error(\n `crockford-base32: expected ${CROCKFORD_ENCODED_LENGTH_FOR_UUID}-char input, got ${encoded.length}`,\n );\n }\n const out = new Uint8Array(16);\n let bits = 0;\n let bitCount = 0;\n let outIdx = 0;\n for (let i = 0; i < encoded.length; i++) {\n const code = encoded.charCodeAt(i);\n const value = code < 128 ? DECODE_TABLE[code]! : -1;\n if (value < 0) {\n throw new Error(\n `crockford-base32: invalid character ${JSON.stringify(encoded[i])} at index ${i}`,\n );\n }\n bits = (bits << 5) | value;\n bitCount += 5;\n if (bitCount >= 8) {\n bitCount -= 8;\n out[outIdx++] = (bits >>> bitCount) & 0xff;\n }\n }\n // After 26 symbols × 5 = 130 bits consumed and 16 bytes × 8 = 128 bits\n // emitted, there should be exactly 2 trailing zero pad bits. Anything else\n // means the input wasn't produced by our encoder (or was tampered with).\n if (bitCount !== 2 || (bits & 0x3) !== 0) {\n throw new Error('crockford-base32: non-zero pad bits at end of input');\n }\n return out;\n}\n","// Stripe-style prefixed resource IDs. The Postgres column stays UUIDv7; the\n// wire form is `<prefix>_<26-char-crockford-base32>`. This module is the\n// only place that knows the byte-level encoding — everything else (Zod\n// schemas, route handlers, SDK types) consumes the helpers below.\n//\n// We intentionally do NOT bind the helpers to a closed prefix enum here: the\n// SDK is published as a versioned dependency and adding a new resource type\n// (e.g. `topup_*`) must not require an SDK bump just to validate the wire.\n// The helpers therefore take the prefix as a generic string parameter; the\n// per-resource Zod schemas in `./zod-schemas.ts` are the place to enumerate\n// the known prefixes for validation purposes.\n\nimport { decodeBytes, encodeBytes } from './crockford-base32';\n\n/**\n * Branded string type — `${prefix}_<26-base32-chars>`. The phantom `__brand`\n * field gives TypeScript a way to refuse a bare string at API boundaries\n * (`function fn(id: PrefixedId<'poe'>)`) while staying ABI-compatible with\n * `string` on the wire and in JSON serialisation.\n */\nexport type PrefixedId<P extends string> = `${P}_${string}` & { readonly __brand: P };\n\n// 32-char hex UUID without separators is what the encoder converts to bytes.\nconst UUID_RE_BYTES = /^[0-9a-f]{32}$/;\n\nfunction uuidStringToBytes(uuid: string): Uint8Array {\n // Accept canonical 8-4-4-4-12 hyphenated form (case-insensitive) only —\n // this is what every UUIDv4/v7 library produces and what Postgres returns\n // for the UUIDv7 columns. Anything else (no hyphens, wrong width, non-hex)\n // is rejected.\n const hex = uuid.replace(/-/g, '').toLowerCase();\n if (!UUID_RE_BYTES.test(hex) || uuid.replace(/[^-]/g, '').length !== 4) {\n throw new Error(`prefixed-id: not a canonical hyphenated UUID: ${JSON.stringify(uuid)}`);\n }\n const out = new Uint8Array(16);\n for (let i = 0; i < 16; i++) {\n out[i] = parseInt(hex.slice(i * 2, i * 2 + 2), 16);\n }\n return out;\n}\n\nfunction bytesToUuidString(bytes: Uint8Array): string {\n if (bytes.length !== 16) {\n throw new Error(`prefixed-id: expected 16 decoded bytes, got ${bytes.length}`);\n }\n const hex = Array.from(bytes, (b) => b.toString(16).padStart(2, '0')).join('');\n return `${hex.slice(0, 8)}-${hex.slice(8, 12)}-${hex.slice(12, 16)}-${hex.slice(16, 20)}-${hex.slice(20)}`;\n}\n\n/**\n * Encode a bare canonical UUID string (8-4-4-4-12 hyphenated) into the\n * Stripe-style wire form `${prefix}_<crockford>`.\n */\nexport function encodePrefixedId<P extends string>(prefix: P, uuid: string): PrefixedId<P> {\n const bytes = uuidStringToBytes(uuid);\n const encoded = encodeBytes(bytes);\n return `${prefix}_${encoded}` as PrefixedId<P>;\n}\n\n/**\n * Decode a wire-format prefixed id back to the bare canonical UUID string.\n * Throws when the prefix does not match, the body is not 26 base32 chars,\n * or the encoded payload is malformed.\n */\nexport function decodePrefixedId<P extends string>(prefix: P, encoded: string): string {\n if (typeof encoded !== 'string') {\n throw new Error(`prefixed-id: expected string, got ${typeof encoded}`);\n }\n const sep = encoded.indexOf('_');\n if (sep < 0) {\n throw new Error(`prefixed-id: missing prefix separator in ${JSON.stringify(encoded)}`);\n }\n const actualPrefix = encoded.slice(0, sep);\n if (actualPrefix !== prefix) {\n throw new Error(\n `prefixed-id: expected prefix ${JSON.stringify(prefix)}, got ${JSON.stringify(actualPrefix)}`,\n );\n }\n const body = encoded.slice(sep + 1);\n const bytes = decodeBytes(body);\n return bytesToUuidString(bytes);\n}\n\n/**\n * Type guard. Cheap-check: matches the prefix and the lowercase Crockford\n * length, but does NOT validate the payload bytes round-trip. Use\n * `decodePrefixedId` when a full validation is required.\n */\nexport function isPrefixedId<P extends string>(\n prefix: P,\n candidate: unknown,\n): candidate is PrefixedId<P> {\n if (typeof candidate !== 'string') return false;\n if (!candidate.startsWith(`${prefix}_`)) return false;\n const body = candidate.slice(prefix.length + 1);\n if (body.length !== 26) return false;\n // Strict Crockford alphabet — no I, L, O, U; lowercase only on the wire.\n return /^[0-9a-hjkmnp-tv-z]{26}$/.test(body);\n}\n","// Zod schema gating the CIP-309 record id at every parse boundary (HTTP route\n// handlers, SDK input validation, OpenAPI registration).\n//\n// The regex is the strict Crockford-32 alphabet (lowercase only on the wire,\n// no I/L/O/U). This is stricter than `[0-9a-z]{26}` because it catches the\n// most common typo classes (`poe_…ol1u…`) at the parser rather than letting\n// them through to the decoder for a confusing `non-zero pad bits` error.\n\nimport { z } from 'zod';\n\nconst CROCKFORD_LOWER = '[0-9a-hjkmnp-tv-z]{26}';\n\nexport const POE_ID_PREFIX = 'poe' as const;\n\nexport const PoeIdSchema = z\n .string()\n .regex(new RegExp(`^${POE_ID_PREFIX}_${CROCKFORD_LOWER}$`), 'invalid poe id');\n\nexport const POE_ID_PATTERN = `^${POE_ID_PREFIX}_${CROCKFORD_LOWER}$`;\n"]}
|
|
1
|
+
{"version":3,"sources":["../../src/ids/crockford-base32.ts","../../src/ids/prefixed-id.ts","../../src/ids/zod-schemas.ts"],"names":[],"mappings":";;;AAiBA,IAAM,QAAA,GAAW,kCAAA;AAIjB,IAAM,gBAA2B,MAAM;AACrC,EAAA,MAAM,QAAQ,IAAI,SAAA,CAAU,GAAG,CAAA,CAAE,KAAK,EAAE,CAAA;AACxC,EAAA,KAAA,IAAS,CAAA,GAAI,CAAA,EAAG,CAAA,GAAI,QAAA,CAAS,QAAQ,CAAA,EAAA,EAAK;AACxC,IAAA,MAAM,EAAA,GAAK,QAAA,CAAS,UAAA,CAAW,CAAC,CAAA;AAChC,IAAA,KAAA,CAAM,EAAE,CAAA,GAAI,CAAA;AAEZ,IAAA,MAAM,KAAA,GAAQ,OAAO,YAAA,CAAa,EAAE,EAAE,WAAA,EAAY,CAAE,WAAW,CAAC,CAAA;AAChE,IAAA,KAAA,CAAM,KAAK,CAAA,GAAI,CAAA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AG,GAAG,CAAA;AACzC,EAAA,IAAI,iBAAiB,MAAA,EAAQ;AAC3B,IAAA,MAAM,IAAI,KAAA;AAAA,MACR,CAAA,6BAAA,EAAgC,KAAK,SAAA,CAAU,MAAM,CAAC,CAAA,MAAA,EAAS,IAAA,CAAK,SAAA,CAAU,YAAY,CAAC,CAAA;AAAA,KAC7F;AAAA,EACF;AACA,EAAA,MAAM,IAAA,GAAO,OAAA,CAAQ,KAAA,CAAM,GAAA,GAAM,CAAC,CAAA;AAClC,EAAA,MAAM,KAAA,GAAQ,YAAY,IAAI,CAAA;AAC9B,EAAA,OAAO,kBAAkB,KAAK,CAAA;AAChC;AAOO,SAAS,YAAA,CACd,QACA,SAAA,EAC4B;AAC5B,EAAA,IAAI,OAAO,SAAA,KAAc,QAAA,EAAU,OAAO,KAAA;AAC1C,EAAA,IAAI,CAAC,SAAA,CAAU,UAAA,CAAW,GAAG,MAAM,CAAA,CAAA,CAAG,GAAG,OAAO,KAAA;AAChD,EAAA,MAAM,IAAA,GAAO,SAAA,CAAU,KAAA,CAAM,MAAA,CAAO,SAAS,CAAC,CAAA;AAC9C,EAAA,IAAI,IAAA,CAAK,MAAA,KAAW,EAAA,EAAI,OAAO,KAAA;AAE/B,EAAA,OAAO,0BAAA,CAA2B,KAAK,IAAI,CAAA;AAC7C;ACxFA,IAAM,eAAA,GAAkB,wBAAA;AAEjB,IAAM,aAAA,GAAgB;AAEtB,IAAM,WAAA,GAAc,CAAA,CACxB,MAAA,EAAO,CACP,KAAA,CAAM,IAAI,MAAA,CAAO,CAAA,CAAA,EAAI,aAAa,CAAA,CAAA,EAAI,eAAe,CAAA,CAAA,CAAG,GAAG,gBAAgB;AAEvE,IAAM,cAAA,GAAiB,CAAA,CAAA,EAAI,aAAa,CAAA,CAAA,EAAI,eAAe,CAAA,CAAA","file":"index.js","sourcesContent":["// Crockford Base32 codec for 16-byte UUID payloads (yielding 26-char strings).\n//\n// Alphabet per https://www.crockford.com/base32.html — `0123456789ABCDEFGHJKMNPQRSTVWXYZ`\n// (32 symbols; the letters I, L, O, U are intentionally excluded for visual\n// disambiguation against digits and to avoid accidental profanity in\n// generated identifiers).\n//\n// Encoding: 16 raw bytes (128 bits) packs into exactly 26 base32 symbols\n// (130 bits with 2 trailing zero-padding bits we drop on encode and\n// reconstruct on decode). No `=` padding character is emitted — UUID payloads\n// are fixed-width.\n//\n// Decoding: case-insensitive (per Crockford spec); we also tolerate the\n// disambiguation map I/L → 1, O → 0. The encoded length MUST be 26 chars;\n// rejection is explicit (callers downstream feed the bytes back into a UUIDv7\n// validator anyway, so we surface the length problem at the codec boundary).\n\nconst ALPHABET = '0123456789abcdefghjkmnpqrstvwxyz';\n\n// 256-entry decode table indexed by lowercased ASCII char code. -1 = invalid.\n// We populate it once at module load.\nconst DECODE_TABLE: Int8Array = (() => {\n const table = new Int8Array(128).fill(-1);\n for (let i = 0; i < ALPHABET.length; i++) {\n const ch = ALPHABET.charCodeAt(i);\n table[ch] = i;\n // Uppercase variant (Crockford accepts case-insensitive input).\n const upper = String.fromCharCode(ch).toUpperCase().charCodeAt(0);\n table[upper] = i;\n }\n // Crockford disambiguation: I, L → 1; O → 0; U is reserved (always invalid).\n table['I'.charCodeAt(0)] = 1;\n table['i'.charCodeAt(0)] = 1;\n table['L'.charCodeAt(0)] = 1;\n table['l'.charCodeAt(0)] = 1;\n table['O'.charCodeAt(0)] = 0;\n table['o'.charCodeAt(0)] = 0;\n return table;\n})();\n\nexport const CROCKFORD_ENCODED_LENGTH_FOR_UUID = 26;\n\n/**\n * Encode `bytes.length` raw bytes as a lowercase Crockford base32 string.\n * Output length is `ceil(bytes.length * 8 / 5)` — no `=` padding character.\n * For 16-byte UUIDs this produces 26 chars; for 32-byte API-key secrets it\n * produces 52 chars (256 bits of entropy, matching the Stripe / OpenAI /\n * Anthropic secret-key entropy class).\n */\nexport function encodeBytesVariableLength(bytes: Uint8Array): string {\n let bits = 0;\n let bitCount = 0;\n let out = '';\n for (let i = 0; i < bytes.length; i++) {\n bits = (bits << 8) | bytes[i]!;\n bitCount += 8;\n while (bitCount >= 5) {\n bitCount -= 5;\n const idx = (bits >>> bitCount) & 0x1f;\n out += ALPHABET[idx];\n }\n }\n if (bitCount > 0) {\n const idx = (bits << (5 - bitCount)) & 0x1f;\n out += ALPHABET[idx];\n }\n return out;\n}\n\n/**\n * Encode 16 raw bytes (a UUID payload) as a 26-char lowercase Crockford\n * base32 string. Throws if the input is not exactly 16 bytes.\n */\nexport function encodeBytes(bytes: Uint8Array): string {\n if (bytes.length !== 16) {\n throw new Error(`crockford-base32: expected 16 bytes, got ${bytes.length}`);\n }\n // 16 bytes × 8 = 128 bits → 26 × 5 = 130 bits; we pad the input with 2 zero\n // bits on the right, which simply means we treat byte[15] as occupying the\n // top 8 bits of a 10-bit window for the final two symbols.\n return encodeBytesVariableLength(bytes);\n}\n\n/**\n * Decode a 26-char Crockford base32 string back to 16 raw bytes.\n * Case-insensitive; accepts the I/L → 1, O → 0 disambiguation mappings.\n * Throws on wrong length, invalid characters, or non-zero pad bits.\n */\nexport function decodeBytes(encoded: string): Uint8Array {\n if (encoded.length !== CROCKFORD_ENCODED_LENGTH_FOR_UUID) {\n throw new Error(\n `crockford-base32: expected ${CROCKFORD_ENCODED_LENGTH_FOR_UUID}-char input, got ${encoded.length}`,\n );\n }\n const out = new Uint8Array(16);\n let bits = 0;\n let bitCount = 0;\n let outIdx = 0;\n for (let i = 0; i < encoded.length; i++) {\n const code = encoded.charCodeAt(i);\n const value = code < 128 ? DECODE_TABLE[code]! : -1;\n if (value < 0) {\n throw new Error(\n `crockford-base32: invalid character ${JSON.stringify(encoded[i])} at index ${i}`,\n );\n }\n bits = (bits << 5) | value;\n bitCount += 5;\n if (bitCount >= 8) {\n bitCount -= 8;\n out[outIdx++] = (bits >>> bitCount) & 0xff;\n }\n }\n // After 26 symbols × 5 = 130 bits consumed and 16 bytes × 8 = 128 bits\n // emitted, there should be exactly 2 trailing zero pad bits. Anything else\n // means the input wasn't produced by our encoder (or was tampered with).\n if (bitCount !== 2 || (bits & 0x3) !== 0) {\n throw new Error('crockford-base32: non-zero pad bits at end of input');\n }\n return out;\n}\n","// Stripe-style prefixed resource IDs. The Postgres column stays UUIDv7; the\n// wire form is `<prefix>_<26-char-crockford-base32>`. This module is the\n// only place that knows the byte-level encoding — everything else (Zod\n// schemas, route handlers, SDK types) consumes the helpers below.\n//\n// We intentionally do NOT bind the helpers to a closed prefix enum here: the\n// SDK is published as a versioned dependency and adding a new resource type\n// (e.g. `topup_*`) must not require an SDK bump just to validate the wire.\n// The helpers therefore take the prefix as a generic string parameter; the\n// per-resource Zod schemas in `./zod-schemas.ts` are the place to enumerate\n// the known prefixes for validation purposes.\n\nimport { decodeBytes, encodeBytes } from './crockford-base32';\n\n/**\n * Branded string type — `${prefix}_<26-base32-chars>`. The phantom `__brand`\n * field gives TypeScript a way to refuse a bare string at API boundaries\n * (`function fn(id: PrefixedId<'poe'>)`) while staying ABI-compatible with\n * `string` on the wire and in JSON serialisation.\n */\nexport type PrefixedId<P extends string> = `${P}_${string}` & { readonly __brand: P };\n\n// 32-char hex UUID without separators is what the encoder converts to bytes.\nconst UUID_RE_BYTES = /^[0-9a-f]{32}$/;\n\nfunction uuidStringToBytes(uuid: string): Uint8Array {\n // Accept canonical 8-4-4-4-12 hyphenated form (case-insensitive) only —\n // this is what every UUIDv4/v7 library produces and what Postgres returns\n // for the UUIDv7 columns. Anything else (no hyphens, wrong width, non-hex)\n // is rejected.\n const hex = uuid.replace(/-/g, '').toLowerCase();\n if (!UUID_RE_BYTES.test(hex) || uuid.replace(/[^-]/g, '').length !== 4) {\n throw new Error(`prefixed-id: not a canonical hyphenated UUID: ${JSON.stringify(uuid)}`);\n }\n const out = new Uint8Array(16);\n for (let i = 0; i < 16; i++) {\n out[i] = parseInt(hex.slice(i * 2, i * 2 + 2), 16);\n }\n return out;\n}\n\nfunction bytesToUuidString(bytes: Uint8Array): string {\n if (bytes.length !== 16) {\n throw new Error(`prefixed-id: expected 16 decoded bytes, got ${bytes.length}`);\n }\n const hex = Array.from(bytes, (b) => b.toString(16).padStart(2, '0')).join('');\n return `${hex.slice(0, 8)}-${hex.slice(8, 12)}-${hex.slice(12, 16)}-${hex.slice(16, 20)}-${hex.slice(20)}`;\n}\n\n/**\n * Encode a bare canonical UUID string (8-4-4-4-12 hyphenated) into the\n * Stripe-style wire form `${prefix}_<crockford>`.\n */\nexport function encodePrefixedId<P extends string>(prefix: P, uuid: string): PrefixedId<P> {\n const bytes = uuidStringToBytes(uuid);\n const encoded = encodeBytes(bytes);\n return `${prefix}_${encoded}` as PrefixedId<P>;\n}\n\n/**\n * Decode a wire-format prefixed id back to the bare canonical UUID string.\n * Throws when the prefix does not match, the body is not 26 base32 chars,\n * or the encoded payload is malformed.\n */\nexport function decodePrefixedId<P extends string>(prefix: P, encoded: string): string {\n if (typeof encoded !== 'string') {\n throw new Error(`prefixed-id: expected string, got ${typeof encoded}`);\n }\n const sep = encoded.indexOf('_');\n if (sep < 0) {\n throw new Error(`prefixed-id: missing prefix separator in ${JSON.stringify(encoded)}`);\n }\n const actualPrefix = encoded.slice(0, sep);\n if (actualPrefix !== prefix) {\n throw new Error(\n `prefixed-id: expected prefix ${JSON.stringify(prefix)}, got ${JSON.stringify(actualPrefix)}`,\n );\n }\n const body = encoded.slice(sep + 1);\n const bytes = decodeBytes(body);\n return bytesToUuidString(bytes);\n}\n\n/**\n * Type guard. Cheap-check: matches the prefix and the lowercase Crockford\n * length, but does NOT validate the payload bytes round-trip. Use\n * `decodePrefixedId` when a full validation is required.\n */\nexport function isPrefixedId<P extends string>(\n prefix: P,\n candidate: unknown,\n): candidate is PrefixedId<P> {\n if (typeof candidate !== 'string') return false;\n if (!candidate.startsWith(`${prefix}_`)) return false;\n const body = candidate.slice(prefix.length + 1);\n if (body.length !== 26) return false;\n // Strict Crockford alphabet — no I, L, O, U; lowercase only on the wire.\n return /^[0-9a-hjkmnp-tv-z]{26}$/.test(body);\n}\n","// Zod schema gating the Label 309 record id at every parse boundary (HTTP route\n// handlers, SDK input validation, OpenAPI registration).\n//\n// The regex is the strict Crockford-32 alphabet (lowercase only on the wire,\n// no I/L/O/U). This is stricter than `[0-9a-z]{26}` because it catches the\n// most common typo classes (`poe_…ol1u…`) at the parser rather than letting\n// them through to the decoder for a confusing `non-zero pad bits` error.\n\nimport { z } from 'zod';\n\nconst CROCKFORD_LOWER = '[0-9a-hjkmnp-tv-z]{26}';\n\nexport const POE_ID_PREFIX = 'poe' as const;\n\nexport const PoeIdSchema = z\n .string()\n .regex(new RegExp(`^${POE_ID_PREFIX}_${CROCKFORD_LOWER}$`), 'invalid poe id');\n\nexport const POE_ID_PATTERN = `^${POE_ID_PREFIX}_${CROCKFORD_LOWER}$`;\n"]}
|
package/dist/index.cjs
CHANGED
|
@@ -499,7 +499,7 @@ function decodeCanonicalCbor(bytes) {
|
|
|
499
499
|
...cbor2.cdeDecodeOptions,
|
|
500
500
|
rejectStreaming: true,
|
|
501
501
|
rejectDuplicateKeys: true,
|
|
502
|
-
// A
|
|
502
|
+
// A Label 309 record carries integers, byte/text strings, arrays, maps and
|
|
503
503
|
// `null` — and nothing else. Without these rejections the major-type-7
|
|
504
504
|
// surface leaks into the decoder: a float16/32/64 that happens to hold an
|
|
505
505
|
// integral value (e.g. 1.0) silently decodes to the integer 1 and passes
|
|
@@ -646,7 +646,7 @@ function decodeCanonicalCbor2(bytes) {
|
|
|
646
646
|
...cbor2.cdeDecodeOptions,
|
|
647
647
|
rejectStreaming: true,
|
|
648
648
|
rejectDuplicateKeys: true,
|
|
649
|
-
// A
|
|
649
|
+
// A Label 309 record carries integers, byte/text strings, arrays, maps and
|
|
650
650
|
// `null` — and nothing else. Without these rejections the major-type-7
|
|
651
651
|
// surface leaks into the decoder: a float16/32/64 that happens to hold an
|
|
652
652
|
// integral value (e.g. 1.0) silently decodes to the integer 1 and passes
|
|
@@ -747,7 +747,7 @@ function buildSigStructure(args) {
|
|
|
747
747
|
args.payload
|
|
748
748
|
]);
|
|
749
749
|
}
|
|
750
|
-
function
|
|
750
|
+
function buildLabel309SigStructure(args) {
|
|
751
751
|
const toSign = new Uint8Array(
|
|
752
752
|
CARDANO_POE_SIG_DOMAIN_PREFIX_BYTES.length + args.recordBodyCbor.length
|
|
753
753
|
);
|
|
@@ -830,7 +830,7 @@ function decodeCoseSign1(bytes) {
|
|
|
830
830
|
signature: signatureRaw
|
|
831
831
|
};
|
|
832
832
|
}
|
|
833
|
-
function
|
|
833
|
+
function coseSign1Label309Verify(args) {
|
|
834
834
|
let decoded;
|
|
835
835
|
try {
|
|
836
836
|
decoded = decodeCoseSign1(args.message);
|
|
@@ -897,7 +897,7 @@ function coseSign1Cip309Verify(args) {
|
|
|
897
897
|
payload: hashedPayload
|
|
898
898
|
});
|
|
899
899
|
} else {
|
|
900
|
-
sigStructureBytes =
|
|
900
|
+
sigStructureBytes = buildLabel309SigStructure({
|
|
901
901
|
bodyProtectedBytes: decoded.protectedBytes,
|
|
902
902
|
recordBodyCbor: args.detachedRecordBodyCbor
|
|
903
903
|
});
|
|
@@ -1402,7 +1402,7 @@ function validateOneUri(chunks, path, errors) {
|
|
|
1402
1402
|
const cid = slashIdx === -1 ? rest : rest.slice(0, slashIdx);
|
|
1403
1403
|
if (!validateCidProfile(cid)) {
|
|
1404
1404
|
errors.push(
|
|
1405
|
-
issue("INVALID_URI", path, "ipfs:// URI is not a valid CID under the
|
|
1405
|
+
issue("INVALID_URI", path, "ipfs:// URI is not a valid CID under the Label 309 profile")
|
|
1406
1406
|
);
|
|
1407
1407
|
}
|
|
1408
1408
|
return;
|
|
@@ -1450,7 +1450,7 @@ function checkItemEnc(item, idx, errors) {
|
|
|
1450
1450
|
issue(
|
|
1451
1451
|
"UNAUTHENTICATED_CIPHER_FORBIDDEN",
|
|
1452
1452
|
[...basePath, "aead"],
|
|
1453
|
-
`'${enc.aead}' is an unauthenticated cipher;
|
|
1453
|
+
`'${enc.aead}' is an unauthenticated cipher; Label 309 mandates an authenticated (AEAD) cipher`
|
|
1454
1454
|
)
|
|
1455
1455
|
);
|
|
1456
1456
|
return;
|
|
@@ -3931,7 +3931,7 @@ function decodeCanonicalCbor3(bytes) {
|
|
|
3931
3931
|
...cbor2.cdeDecodeOptions,
|
|
3932
3932
|
rejectStreaming: true,
|
|
3933
3933
|
rejectDuplicateKeys: true,
|
|
3934
|
-
// A
|
|
3934
|
+
// A Label 309 record carries integers, byte/text strings, arrays, maps and
|
|
3935
3935
|
// `null` — and nothing else. Without these rejections the major-type-7
|
|
3936
3936
|
// surface leaks into the decoder: a float16/32/64 that happens to hold an
|
|
3937
3937
|
// integral value (e.g. 1.0) silently decodes to the integer 1 and passes
|
|
@@ -4546,11 +4546,11 @@ function decodeIntKey(h) {
|
|
|
4546
4546
|
// src/verifier/resolve.ts
|
|
4547
4547
|
var KOIOS_MAINNET_URL = "https://api.koios.rest/api/v1";
|
|
4548
4548
|
var BLOCKFROST_MAINNET_HOST = "https://cardano-mainnet.blockfrost.io/api/v0";
|
|
4549
|
-
var
|
|
4549
|
+
var NotALabel309RecordError = class extends Error {
|
|
4550
4550
|
code = "METADATA_NOT_FOUND";
|
|
4551
4551
|
constructor(message) {
|
|
4552
4552
|
super(message);
|
|
4553
|
-
this.name = "
|
|
4553
|
+
this.name = "NotALabel309RecordError";
|
|
4554
4554
|
}
|
|
4555
4555
|
};
|
|
4556
4556
|
async function resolveCardanoTx(args) {
|
|
@@ -4561,7 +4561,7 @@ async function resolveCardanoTx(args) {
|
|
|
4561
4561
|
try {
|
|
4562
4562
|
return await resolveViaKoios(input.txHash, koiosUrl, fetchFn);
|
|
4563
4563
|
} catch (e) {
|
|
4564
|
-
if (e instanceof
|
|
4564
|
+
if (e instanceof NotALabel309RecordError) throw e;
|
|
4565
4565
|
lastErr = e;
|
|
4566
4566
|
}
|
|
4567
4567
|
}
|
|
@@ -4569,7 +4569,7 @@ async function resolveCardanoTx(args) {
|
|
|
4569
4569
|
try {
|
|
4570
4570
|
return await resolveViaBlockfrost(input.txHash, input.blockfrostProjectId, fetchFn);
|
|
4571
4571
|
} catch (e) {
|
|
4572
|
-
if (e instanceof
|
|
4572
|
+
if (e instanceof NotALabel309RecordError) throw e;
|
|
4573
4573
|
lastErr = e;
|
|
4574
4574
|
}
|
|
4575
4575
|
}
|
|
@@ -4587,7 +4587,7 @@ async function resolveViaKoios(txHash, koiosUrl, fetchFn) {
|
|
|
4587
4587
|
}
|
|
4588
4588
|
const cborJson = parseJson(cborRes.bytes);
|
|
4589
4589
|
if (!Array.isArray(cborJson) || cborJson.length === 0) {
|
|
4590
|
-
throw new
|
|
4590
|
+
throw new NotALabel309RecordError("koios returned empty array for tx_cbor; tx may not exist");
|
|
4591
4591
|
}
|
|
4592
4592
|
const cborEntry = cborJson[0];
|
|
4593
4593
|
if (typeof cborEntry.cbor !== "string") {
|
|
@@ -4608,7 +4608,7 @@ async function resolveViaKoios(txHash, koiosUrl, fetchFn) {
|
|
|
4608
4608
|
}
|
|
4609
4609
|
const infoJson = parseJson(infoRes.bytes);
|
|
4610
4610
|
if (!Array.isArray(infoJson) || infoJson.length === 0) {
|
|
4611
|
-
throw new
|
|
4611
|
+
throw new NotALabel309RecordError("koios returned empty array for tx_info");
|
|
4612
4612
|
}
|
|
4613
4613
|
const infoEntry = infoJson[0];
|
|
4614
4614
|
if (typeof infoEntry.tx_hash === "string" && infoEntry.tx_hash.toLowerCase() !== txHash.toLowerCase()) {
|
|
@@ -4753,7 +4753,7 @@ async function verifyOneSig(index, entry, recordBodyCbor, input) {
|
|
|
4753
4753
|
return { index, verdict: "unresolved", reason: "SIGNER_KEY_UNRESOLVED" };
|
|
4754
4754
|
}
|
|
4755
4755
|
const { pub, signerType } = resolved;
|
|
4756
|
-
const verifyResult =
|
|
4756
|
+
const verifyResult = coseSign1Label309Verify({
|
|
4757
4757
|
message: coseBytes,
|
|
4758
4758
|
detachedRecordBodyCbor: recordBodyCbor,
|
|
4759
4759
|
expectedSignerKey: pub
|
|
@@ -5105,7 +5105,7 @@ async function verifyTx(input) {
|
|
|
5105
5105
|
try {
|
|
5106
5106
|
resolved = await resolveCardanoTx({ input, fetchFn });
|
|
5107
5107
|
} catch (e) {
|
|
5108
|
-
if (e instanceof
|
|
5108
|
+
if (e instanceof NotALabel309RecordError) {
|
|
5109
5109
|
return base({
|
|
5110
5110
|
verdict: "failed",
|
|
5111
5111
|
exit_code: 1,
|
|
@@ -5446,7 +5446,7 @@ function prepareSigStructure(args) {
|
|
|
5446
5446
|
}
|
|
5447
5447
|
const { protectedHeaderBytes } = encodePath1ProtectedHeader(args.signerPubkey);
|
|
5448
5448
|
const recordBodyCbor = encodeRecordBodyForSigning(args.record);
|
|
5449
|
-
const sigStructureBytes =
|
|
5449
|
+
const sigStructureBytes = buildLabel309SigStructure({
|
|
5450
5450
|
bodyProtectedBytes: protectedHeaderBytes,
|
|
5451
5451
|
recordBodyCbor
|
|
5452
5452
|
});
|
|
@@ -5540,7 +5540,7 @@ function extractProblemExtensions(problem) {
|
|
|
5540
5540
|
}
|
|
5541
5541
|
return out;
|
|
5542
5542
|
}
|
|
5543
|
-
var
|
|
5543
|
+
var Label309HttpError = class extends Error {
|
|
5544
5544
|
problem;
|
|
5545
5545
|
code;
|
|
5546
5546
|
httpStatus;
|
|
@@ -5555,7 +5555,7 @@ var Cip309HttpError = class extends Error {
|
|
|
5555
5555
|
retryAfterSeconds;
|
|
5556
5556
|
constructor(init) {
|
|
5557
5557
|
super(init.problem.detail || `${init.problem.title} (HTTP ${init.problem.status})`);
|
|
5558
|
-
this.name = "
|
|
5558
|
+
this.name = "Label309HttpError";
|
|
5559
5559
|
this.problem = init.problem;
|
|
5560
5560
|
this.code = init.problem.code;
|
|
5561
5561
|
this.httpStatus = init.problem.status;
|
|
@@ -5572,7 +5572,7 @@ var Cip309HttpError = class extends Error {
|
|
|
5572
5572
|
};
|
|
5573
5573
|
|
|
5574
5574
|
// src/client/batch-empty-error.ts
|
|
5575
|
-
var BatchEmptyError = class extends
|
|
5575
|
+
var BatchEmptyError = class extends Label309HttpError {
|
|
5576
5576
|
constructor(init) {
|
|
5577
5577
|
super(init);
|
|
5578
5578
|
this.name = "BatchEmptyError";
|
|
@@ -5583,7 +5583,7 @@ var BatchEmptyError = class extends Cip309HttpError {
|
|
|
5583
5583
|
function readInt(value) {
|
|
5584
5584
|
return typeof value === "number" && Number.isFinite(value) ? value : void 0;
|
|
5585
5585
|
}
|
|
5586
|
-
var BatchTooLargeError = class extends
|
|
5586
|
+
var BatchTooLargeError = class extends Label309HttpError {
|
|
5587
5587
|
max;
|
|
5588
5588
|
got;
|
|
5589
5589
|
constructor(init) {
|
|
@@ -5595,7 +5595,7 @@ var BatchTooLargeError = class extends Cip309HttpError {
|
|
|
5595
5595
|
};
|
|
5596
5596
|
|
|
5597
5597
|
// src/client/forbidden-error.ts
|
|
5598
|
-
var ForbiddenError = class extends
|
|
5598
|
+
var ForbiddenError = class extends Label309HttpError {
|
|
5599
5599
|
constructor(init) {
|
|
5600
5600
|
super(init);
|
|
5601
5601
|
this.name = "ForbiddenError";
|
|
@@ -5603,7 +5603,7 @@ var ForbiddenError = class extends Cip309HttpError {
|
|
|
5603
5603
|
};
|
|
5604
5604
|
|
|
5605
5605
|
// src/client/idempotency-conflict-error.ts
|
|
5606
|
-
var IdempotencyConflictError = class extends
|
|
5606
|
+
var IdempotencyConflictError = class extends Label309HttpError {
|
|
5607
5607
|
constructor(init) {
|
|
5608
5608
|
super(init);
|
|
5609
5609
|
this.name = "IdempotencyConflictError";
|
|
@@ -5623,7 +5623,7 @@ function readBigIntString(value) {
|
|
|
5623
5623
|
function readString(value) {
|
|
5624
5624
|
return typeof value === "string" ? value : void 0;
|
|
5625
5625
|
}
|
|
5626
|
-
var InsufficientFundsError = class extends
|
|
5626
|
+
var InsufficientFundsError = class extends Label309HttpError {
|
|
5627
5627
|
balanceUsdMicros;
|
|
5628
5628
|
requiredUsdMicros;
|
|
5629
5629
|
topUpUrl;
|
|
@@ -5641,7 +5641,7 @@ function readScopeArray(value) {
|
|
|
5641
5641
|
if (!Array.isArray(value)) return [];
|
|
5642
5642
|
return value.filter((entry) => typeof entry === "string");
|
|
5643
5643
|
}
|
|
5644
|
-
var InsufficientScopeError = class extends
|
|
5644
|
+
var InsufficientScopeError = class extends Label309HttpError {
|
|
5645
5645
|
requiredScopes;
|
|
5646
5646
|
grantedScopes;
|
|
5647
5647
|
constructor(init) {
|
|
@@ -5657,7 +5657,7 @@ var InsufficientScopeError = class extends Cip309HttpError {
|
|
|
5657
5657
|
};
|
|
5658
5658
|
|
|
5659
5659
|
// src/client/internal-server-error.ts
|
|
5660
|
-
var InternalServerError = class extends
|
|
5660
|
+
var InternalServerError = class extends Label309HttpError {
|
|
5661
5661
|
constructor(init) {
|
|
5662
5662
|
super(init);
|
|
5663
5663
|
this.name = "InternalServerError";
|
|
@@ -5665,7 +5665,7 @@ var InternalServerError = class extends Cip309HttpError {
|
|
|
5665
5665
|
};
|
|
5666
5666
|
|
|
5667
5667
|
// src/client/invalid-body-error.ts
|
|
5668
|
-
var InvalidBodyError = class extends
|
|
5668
|
+
var InvalidBodyError = class extends Label309HttpError {
|
|
5669
5669
|
constructor(init) {
|
|
5670
5670
|
super(init);
|
|
5671
5671
|
this.name = "InvalidBodyError";
|
|
@@ -5673,7 +5673,7 @@ var InvalidBodyError = class extends Cip309HttpError {
|
|
|
5673
5673
|
};
|
|
5674
5674
|
|
|
5675
5675
|
// src/client/malformed-cbor-error.ts
|
|
5676
|
-
var MalformedCborError = class extends
|
|
5676
|
+
var MalformedCborError = class extends Label309HttpError {
|
|
5677
5677
|
constructor(init) {
|
|
5678
5678
|
super(init);
|
|
5679
5679
|
this.name = "MalformedCborError";
|
|
@@ -5681,7 +5681,7 @@ var MalformedCborError = class extends Cip309HttpError {
|
|
|
5681
5681
|
};
|
|
5682
5682
|
|
|
5683
5683
|
// src/client/not-found-error.ts
|
|
5684
|
-
var NotFoundError = class extends
|
|
5684
|
+
var NotFoundError = class extends Label309HttpError {
|
|
5685
5685
|
constructor(init) {
|
|
5686
5686
|
super(init);
|
|
5687
5687
|
this.name = "NotFoundError";
|
|
@@ -5692,7 +5692,7 @@ var NotFoundError = class extends Cip309HttpError {
|
|
|
5692
5692
|
function readString2(value) {
|
|
5693
5693
|
return typeof value === "string" ? value : void 0;
|
|
5694
5694
|
}
|
|
5695
|
-
var QuoteAlreadyConsumedError = class extends
|
|
5695
|
+
var QuoteAlreadyConsumedError = class extends Label309HttpError {
|
|
5696
5696
|
quoteId;
|
|
5697
5697
|
constructor(init) {
|
|
5698
5698
|
super(init);
|
|
@@ -5705,7 +5705,7 @@ var QuoteAlreadyConsumedError = class extends Cip309HttpError {
|
|
|
5705
5705
|
function readString3(value) {
|
|
5706
5706
|
return typeof value === "string" ? value : void 0;
|
|
5707
5707
|
}
|
|
5708
|
-
var QuoteExpiredError = class extends
|
|
5708
|
+
var QuoteExpiredError = class extends Label309HttpError {
|
|
5709
5709
|
quoteId;
|
|
5710
5710
|
constructor(init) {
|
|
5711
5711
|
super(init);
|
|
@@ -5718,7 +5718,7 @@ var QuoteExpiredError = class extends Cip309HttpError {
|
|
|
5718
5718
|
function readString4(value) {
|
|
5719
5719
|
return typeof value === "string" ? value : void 0;
|
|
5720
5720
|
}
|
|
5721
|
-
var QuoteNotFoundError = class extends
|
|
5721
|
+
var QuoteNotFoundError = class extends Label309HttpError {
|
|
5722
5722
|
quoteId;
|
|
5723
5723
|
constructor(init) {
|
|
5724
5724
|
super(init);
|
|
@@ -5728,7 +5728,7 @@ var QuoteNotFoundError = class extends Cip309HttpError {
|
|
|
5728
5728
|
};
|
|
5729
5729
|
|
|
5730
5730
|
// src/client/rate-limited-error.ts
|
|
5731
|
-
var RateLimitedError = class extends
|
|
5731
|
+
var RateLimitedError = class extends Label309HttpError {
|
|
5732
5732
|
constructor(init) {
|
|
5733
5733
|
super(init);
|
|
5734
5734
|
this.name = "RateLimitedError";
|
|
@@ -5736,7 +5736,7 @@ var RateLimitedError = class extends Cip309HttpError {
|
|
|
5736
5736
|
};
|
|
5737
5737
|
|
|
5738
5738
|
// src/client/record-not-found-error.ts
|
|
5739
|
-
var RecordNotFoundError = class extends
|
|
5739
|
+
var RecordNotFoundError = class extends Label309HttpError {
|
|
5740
5740
|
constructor(init) {
|
|
5741
5741
|
super(init);
|
|
5742
5742
|
this.name = "RecordNotFoundError";
|
|
@@ -5744,7 +5744,7 @@ var RecordNotFoundError = class extends Cip309HttpError {
|
|
|
5744
5744
|
};
|
|
5745
5745
|
|
|
5746
5746
|
// src/client/service-unavailable-error.ts
|
|
5747
|
-
var ServiceUnavailableError = class extends
|
|
5747
|
+
var ServiceUnavailableError = class extends Label309HttpError {
|
|
5748
5748
|
constructor(init) {
|
|
5749
5749
|
super(init);
|
|
5750
5750
|
this.name = "ServiceUnavailableError";
|
|
@@ -5752,7 +5752,7 @@ var ServiceUnavailableError = class extends Cip309HttpError {
|
|
|
5752
5752
|
};
|
|
5753
5753
|
|
|
5754
5754
|
// src/client/unauthorized-error.ts
|
|
5755
|
-
var UnauthorizedError = class extends
|
|
5755
|
+
var UnauthorizedError = class extends Label309HttpError {
|
|
5756
5756
|
constructor(init) {
|
|
5757
5757
|
super(init);
|
|
5758
5758
|
this.name = "UnauthorizedError";
|
|
@@ -5760,7 +5760,7 @@ var UnauthorizedError = class extends Cip309HttpError {
|
|
|
5760
5760
|
};
|
|
5761
5761
|
|
|
5762
5762
|
// src/client/validation-failed-error.ts
|
|
5763
|
-
var ValidationFailedError = class extends
|
|
5763
|
+
var ValidationFailedError = class extends Label309HttpError {
|
|
5764
5764
|
constructor(init) {
|
|
5765
5765
|
super(init);
|
|
5766
5766
|
this.name = "ValidationFailedError";
|
|
@@ -5878,7 +5878,7 @@ function parseHttpError(args) {
|
|
|
5878
5878
|
case "fx-stale":
|
|
5879
5879
|
return new ServiceUnavailableError(init);
|
|
5880
5880
|
default:
|
|
5881
|
-
return new
|
|
5881
|
+
return new Label309HttpError(init);
|
|
5882
5882
|
}
|
|
5883
5883
|
}
|
|
5884
5884
|
|
|
@@ -6339,7 +6339,7 @@ var PoeNamespace = class {
|
|
|
6339
6339
|
* publish time against the locked price snapshot.
|
|
6340
6340
|
*
|
|
6341
6341
|
* On HTTP-level failure (auth, rate limit, malformed request) this throws
|
|
6342
|
-
* a typed `
|
|
6342
|
+
* a typed `Label309HttpError` subclass. Per-file failures inside a 200
|
|
6343
6343
|
* response are NOT thrown by `uploads()` itself — the response body is
|
|
6344
6344
|
* returned verbatim so the caller can decide how to react. The
|
|
6345
6345
|
* higher-level helpers (`publishSealed`, `publishMerkle`) treat any failed
|
|
@@ -6424,7 +6424,7 @@ var PoeNamespace = class {
|
|
|
6424
6424
|
}
|
|
6425
6425
|
/**
|
|
6426
6426
|
* High-level hash-only publish: hash the supplied content, build a
|
|
6427
|
-
* single-item
|
|
6427
|
+
* single-item Label 309 record, optionally sign it with the caller-supplied
|
|
6428
6428
|
* signer, and submit. No Arweave, no storage round-trip — anchors the
|
|
6429
6429
|
* digest only.
|
|
6430
6430
|
*/
|
|
@@ -6442,7 +6442,7 @@ var PoeNamespace = class {
|
|
|
6442
6442
|
/**
|
|
6443
6443
|
* Sealed-PoE: encrypt the supplied content to the recipient X25519 public
|
|
6444
6444
|
* keys (age-style sealed envelope), upload the ciphertext to Arweave via
|
|
6445
|
-
* /uploads, build a
|
|
6445
|
+
* /uploads, build a Label 309 record with the resulting `ar://` URI, sign
|
|
6446
6446
|
* it (optional), and submit via /publish.
|
|
6447
6447
|
*
|
|
6448
6448
|
* The sender SHOULD include their own X25519 public key in `recipients`
|
|
@@ -6540,7 +6540,7 @@ var RecordsNamespace = class {
|
|
|
6540
6540
|
return await readJson(response);
|
|
6541
6541
|
}
|
|
6542
6542
|
/**
|
|
6543
|
-
* Run the canonical
|
|
6543
|
+
* Run the canonical Label 309 verifier against the record at `txHash`.
|
|
6544
6544
|
* Returns the same `VerifyReport` shape the standalone verifier emits —
|
|
6545
6545
|
* `VerifyReport` IS the wire body of this endpoint, with no transformer in
|
|
6546
6546
|
* between.
|
|
@@ -6563,31 +6563,31 @@ var RecordsNamespace = class {
|
|
|
6563
6563
|
}
|
|
6564
6564
|
};
|
|
6565
6565
|
|
|
6566
|
-
// src/client/
|
|
6566
|
+
// src/client/label-309-client.ts
|
|
6567
6567
|
function resolveFetch(provided) {
|
|
6568
6568
|
if (provided !== void 0) return provided;
|
|
6569
6569
|
if (typeof globalThis.fetch === "function") {
|
|
6570
6570
|
return globalThis.fetch.bind(globalThis);
|
|
6571
6571
|
}
|
|
6572
6572
|
throw new Error(
|
|
6573
|
-
"
|
|
6573
|
+
"Label309Client: no fetch implementation available. Pass `fetch` in the config or run on a platform with globalThis.fetch."
|
|
6574
6574
|
);
|
|
6575
6575
|
}
|
|
6576
6576
|
function resolveBaseUrl(config) {
|
|
6577
6577
|
const baseUrl = config.baseUrl?.trim();
|
|
6578
6578
|
if (baseUrl === void 0 || baseUrl === "") {
|
|
6579
6579
|
throw new InvalidClientConfigError(
|
|
6580
|
-
"
|
|
6580
|
+
"Label309Client: baseUrl is required. Pass the base URL of the Label 309 gateway you are targeting (e.g. https://gateway.example.com)."
|
|
6581
6581
|
);
|
|
6582
6582
|
}
|
|
6583
6583
|
return baseUrl.replace(/\/$/, "");
|
|
6584
6584
|
}
|
|
6585
|
-
var
|
|
6585
|
+
var Label309Client = class {
|
|
6586
6586
|
poe;
|
|
6587
6587
|
records;
|
|
6588
6588
|
account;
|
|
6589
6589
|
/**
|
|
6590
|
-
* Construct a client against a
|
|
6590
|
+
* Construct a client against a Label 309 gateway.
|
|
6591
6591
|
*
|
|
6592
6592
|
* `config.baseUrl` is required — there is no default deployment. The
|
|
6593
6593
|
* `config.apiKey`, when supplied, is an opaque bearer token sent verbatim as
|
|
@@ -7028,8 +7028,6 @@ exports.BatchTooLargeError = BatchTooLargeError;
|
|
|
7028
7028
|
exports.BodyTooLargeError = BodyTooLargeError;
|
|
7029
7029
|
exports.CONFIRMATION_DEPTH_THRESHOLD_DEFAULT = CONFIRMATION_DEPTH_THRESHOLD_DEFAULT;
|
|
7030
7030
|
exports.CROCKFORD_ENCODED_LENGTH_FOR_UUID = CROCKFORD_ENCODED_LENGTH_FOR_UUID;
|
|
7031
|
-
exports.Cip309Client = Cip309Client;
|
|
7032
|
-
exports.Cip309HttpError = Cip309HttpError;
|
|
7033
7031
|
exports.DEFAULT_OUTBOUND_MAX_BYTES = DEFAULT_OUTBOUND_MAX_BYTES;
|
|
7034
7032
|
exports.DEFAULT_PROFILE = DEFAULT_PROFILE;
|
|
7035
7033
|
exports.DENY_HOSTS_DEFAULT = DENY_HOSTS_DEFAULT;
|
|
@@ -7043,8 +7041,10 @@ exports.InternalServerError = InternalServerError;
|
|
|
7043
7041
|
exports.InvalidBodyError = InvalidBodyError;
|
|
7044
7042
|
exports.InvalidClientConfigError = InvalidClientConfigError;
|
|
7045
7043
|
exports.KOIOS_MAINNET_URL = KOIOS_MAINNET_URL;
|
|
7044
|
+
exports.Label309Client = Label309Client;
|
|
7045
|
+
exports.Label309HttpError = Label309HttpError;
|
|
7046
7046
|
exports.MalformedCborError = MalformedCborError;
|
|
7047
|
-
exports.
|
|
7047
|
+
exports.NotALabel309RecordError = NotALabel309RecordError;
|
|
7048
7048
|
exports.NotFoundError = NotFoundError;
|
|
7049
7049
|
exports.OffHostSignError = OffHostSignError;
|
|
7050
7050
|
exports.OutboundExhaustedError = OutboundExhaustedError;
|