@qntx/ur 1.1.0 → 2.0.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/dist/index.d.mts CHANGED
@@ -1,184 +1,63 @@
1
- import { a as UrError, i as DecoderPoison, n as DEFAULT_LIMITS, o as UrErrorCode, r as DecoderLimits, s as failPoison, t as UrType } from "./type-CSfO9fHL.mjs";
2
- //#region src/crc32.d.ts
3
- /**
4
- * CRC-32 ISO-HDLC (polynomial 0xedb88320), matching bcur / ur-rs.
5
- */
1
+ import { C as parseUrType, S as isUrType, _ as UrError, a as UrEncoderOptions, b as UrLimit, c as FountainEncoder, d as FountainDecoder, f as Progress, g as DecoderLimits, h as DEFAULT_LIMITS, i as UrEncoder, l as FountainEncoderOptions, m as Part, n as UrDecoder, o as encodeUr, p as ReceiveResult, r as UrDecoderOptions, s as toQrString, t as DecodedUr, u as DecoderState, v as UrErrorCode, x as UrType, y as UrErrorInfo } from "./index-DTjNCWBI.mjs";
2
+ //#region src/consensus/crc32.d.ts
6
3
  /** CRC-32 ISO-HDLC checksum of `data`. */
7
4
  declare function checksum(data: Uint8Array): number;
8
5
  //#endregion
9
6
  //#region src/constants.d.ts
10
7
  /** BCR-2020-012 bytewords tables. */
11
8
  /** Four-letter bytewords (index = byte value). */
12
- declare const WORDS: readonly string[];
9
+ export declare const WORDS: ReadonlyArray<string>;
13
10
  /** First+last letter of each byteword (UR minimal style). */
14
- declare const MINIMALS: readonly string[];
15
- declare namespace index_d_exports {
16
- export { MINIMALS, Style, WORDS, canonicalizeByteword, decode$1 as decode, encode$1 as encode, encodeRaw };
17
- }
11
+ export declare const MINIMALS: ReadonlyArray<string>;
12
+ /** BCR-2024-008 bytemoji table (index = byte value). */
13
+ export declare const BYTEMOJIS: ReadonlyArray<string>;
14
+ //#endregion
15
+ //#region src/bytewords/index.d.ts
18
16
  /** Bytewords encoding styles (BCR-2020-012). */
19
- type Style = "standard" | "uri" | "minimal";
17
+ type BytewordsStyle = "standard" | "uri" | "minimal";
20
18
  /** Encode `data` with trailing CRC-32 as bytewords. Empty data is allowed. */
21
- declare function encode$1(data: Uint8Array, style: Style): string;
22
- /**
23
- * Encode without CRC trailer.
24
- * Not for UR bodies — identifiers only.
25
- */
26
- declare function encodeRaw(data: Uint8Array, style: Style): string;
19
+ export declare function encodeBytewords(data: Uint8Array, style: BytewordsStyle): string;
20
+ /** The four checksum words of `data` alone (URKit `checksumWords` semantics). */
21
+ export declare function bytewordsChecksum(data: Uint8Array, style: BytewordsStyle): string;
22
+ /** Encoded length of `length` bytes (without a checksum) for `style`. */
23
+ export declare function bytewordsEncodedLength(length: number, style: BytewordsStyle): number;
24
+ /** Four-word standard-style identifier of a 4-byte digest (BCR-2020-012). */
25
+ export declare function bytewordsIdentifier(data: Uint8Array): string;
26
+ /** Four-emoji identifier of a 4-byte digest (BCR-2024-008). */
27
+ export declare function bytemojiIdentifier(data: Uint8Array): string;
27
28
  /** Decode bytewords and verify CRC-32. Case-insensitive. */
28
- declare function decode$1(encoded: string, style: Style): Uint8Array;
29
+ export declare function decodeBytewords(text: string, style: BytewordsStyle): Uint8Array;
29
30
  /** Canonicalize a 2–4 letter token to the full 4-letter lowercase byteword. */
30
- declare function canonicalizeByteword(token: string): string | undefined;
31
- //#endregion
32
- //#region src/fountain/part.d.ts
33
- /** A fountain part (wire metadata + fragment data). */
34
- declare class Part {
35
- readonly sequence: number;
36
- readonly sequenceCount: number;
37
- readonly messageLength: number;
38
- readonly checksum: number;
39
- readonly data: Uint8Array;
40
- private constructor();
41
- static fromFields(sequence: number, sequenceCount: number, messageLength: number, checksum: number, data: Uint8Array): Part;
42
- indexes(): number[];
43
- isSimple(): boolean;
44
- toCbor(): Uint8Array;
45
- static fromCbor(bytes: Uint8Array, maxDataLen?: number, maxFragmentCount?: number): Part;
46
- sequenceId(): string;
47
- }
48
- //#endregion
49
- //#region src/fountain/decoder.d.ts
50
- /** Fountain decoder with resource limits and fail-closed poison. */
51
- declare class FountainDecoder {
52
- private readonly decoded;
53
- private readonly received;
54
- private readonly buffer;
55
- private readonly queue;
56
- private sequenceCount;
57
- private messageLength;
58
- private messageChecksum;
59
- private fragmentLength;
60
- private readonly limits;
61
- private poisoned;
62
- constructor(limits?: Partial<DecoderLimits>);
63
- get maxFragmentDataLength(): number;
64
- get maxFragmentCount(): number;
65
- get isPoisoned(): boolean;
66
- get poisonState(): DecoderPoison | undefined;
67
- private poison;
68
- private escalate;
69
- /**
70
- * Receive a fountain part.
71
- * @returns whether the part was newly ingested.
72
- */
73
- receive(part: Part): boolean;
74
- private enqueueSimple;
75
- private processQueue;
76
- private reduceBufferedPart;
77
- private processComplex;
78
- private insertReduced;
79
- get complete(): boolean;
80
- resolvedFragmentCount(): number | undefined;
81
- get fragmentCount(): number;
82
- validate(part: Part): boolean;
83
- /** Decoded message if complete; otherwise `undefined`. */
84
- message(): Uint8Array | undefined;
85
- }
31
+ export declare function canonicalizeByteword(token: string): string | undefined;
86
32
  //#endregion
87
- //#region src/fountain/encoder.d.ts
88
- /** Fountain encoder. */
89
- declare class FountainEncoder {
90
- private readonly parts;
91
- private readonly sequenceCount;
92
- private readonly messageLength;
93
- private readonly messageChecksum;
94
- private currentSequence;
95
- private constructor();
96
- static create(message: Uint8Array, maxFragmentLength: number): FountainEncoder;
97
- get currentSequenceNum(): number;
98
- get fragmentCount(): number;
99
- get complete(): boolean;
100
- nextPart(): Part;
101
- }
33
+ //#region src/fountain/part-cbor.d.ts
34
+ /**
35
+ * Encode a part as fixed-schema deterministic CBOR: `array(5) [sequence, sequenceCount,
36
+ * messageLength, checksum, data]` with shortest-form integers.
37
+ */
38
+ export declare function encodePart(part: Part): Uint8Array;
39
+ /**
40
+ * Decode a part from CBOR. Lenient on integer width (UR-ADR-017): any well-formed definite-length
41
+ * encoding is accepted; re-encode with {@link encodePart} for the shortest form. `limits` apply
42
+ * `maxFragmentLength` to the bstr and `maxFragmentCount` to `sequenceCount`.
43
+ */
44
+ export declare function decodePart(bytes: Uint8Array, limits?: Partial<DecoderLimits>): Part;
102
45
  //#endregion
103
46
  //#region src/ur/parse.d.ts
104
- type Kind = "single" | "multi";
105
- interface ParsedUr {
47
+ /** A decoded UR: a single-part message or one validated fountain part. */
48
+ type ParsedUr = Readonly<{
49
+ kind: "single";
106
50
  type: UrType;
107
- kind: Kind;
108
- indices?: {
109
- seq: number;
110
- count: number;
111
- };
112
- body: string;
113
- }
114
- /** Lowercase a UR string for case-insensitive QR transport. */
115
- declare function normalizeUr(uri: string): string;
116
- /** Parse a UR (full-URI case fold). Does not decode bytewords. */
117
- declare function parse(uri: string): ParsedUr;
118
- /** Parse an already-lowercased (or body-normalized) UR. */
119
- declare function parseNormalized(uri: string): ParsedUr;
120
- //#endregion
121
- //#region src/ur/index.d.ts
122
- /** Encode a single-part UR. Empty data is allowed. */
123
- declare function encode(data: Uint8Array, type: UrType): string;
51
+ message: Uint8Array;
52
+ }> | Readonly<{
53
+ kind: "multi";
54
+ type: UrType;
55
+ part: Part;
56
+ }>;
124
57
  /**
125
- * Decode payload from a single- or multi-part UR.
126
- * Multi-part returns the CBOR-encoded fountain part bytes, not the message.
58
+ * Parse and decode a UR string. Case-insensitive for the URI and bytewords content. `limits` bounds
59
+ * the URI length and the multi-part CBOR fields. Throws `UrError`.
127
60
  */
128
- declare function decode(uri: string): {
129
- kind: Kind;
130
- payload: Uint8Array;
131
- };
132
- /** Like {@link decode} but retains the normalized type. */
133
- declare function decodeWithType(uri: string): {
134
- type: UrType;
135
- kind: Kind;
136
- payload: Uint8Array;
137
- };
138
- /** Decode a single-part UR payload. Multi-part URIs throw `NotSinglePart`. */
139
- declare function decodeMessage(uri: string): Uint8Array;
140
- /** Uppercase UR string for denser QR alphanumeric mode. */
141
- declare function toQrString(uri: string): string;
142
- /** UR encoder. `K == 1` emits single-part; otherwise fountain. */
143
- declare class Encoder {
144
- private readonly fountain;
145
- private readonly urType;
146
- private readonly message;
147
- private singleEmitted;
148
- private constructor();
149
- static create(message: Uint8Array, maxFragmentLength: number, type: UrType): Encoder;
150
- static bytes(message: Uint8Array, maxFragmentLength: number): Encoder;
151
- get isSinglePart(): boolean;
152
- get fragmentCount(): number;
153
- get currentIndex(): number;
154
- get complete(): boolean;
155
- nextPart(): string;
156
- }
157
- /** UR decoder with type stickiness and URI limits. */
158
- declare class Decoder {
159
- private readonly fountain;
160
- private readonly maxUriLen;
161
- private readonly maxMessageLength;
162
- private readonly expectedType;
163
- private seenType;
164
- private single;
165
- private poisoned;
166
- constructor(options?: {
167
- limits?: Partial<DecoderLimits>;
168
- expectedType?: UrType;
169
- });
170
- private poison;
171
- private escalate;
172
- get poisonState(): DecoderPoison | undefined;
173
- receive(uri: string): void;
174
- private receiveSingle;
175
- private receiveFountain;
176
- get complete(): boolean;
177
- message(): Uint8Array | undefined;
178
- resolvedFragmentCount(): number | undefined;
179
- get fragmentCount(): number;
180
- get type(): UrType | undefined;
181
- get isPoisoned(): boolean;
182
- }
61
+ export declare function parseUr(text: string, limits?: Partial<DecoderLimits>): ParsedUr;
183
62
  //#endregion
184
- export { DEFAULT_LIMITS, Decoder, type DecoderLimits, type DecoderPoison, Encoder, FountainDecoder, FountainEncoder, type Kind, type ParsedUr, Part, type Style, UrError, type UrErrorCode, UrType, index_d_exports as bytewords, canonicalizeByteword, checksum as crc32, decode, decode$1 as decodeBytewords, decodeMessage, decodeWithType, encode, encode$1 as encodeBytewords, encodeRaw, failPoison, normalizeUr, parse, parseNormalized, toQrString };
63
+ export { type BytewordsStyle, DEFAULT_LIMITS, type DecodedUr, type DecoderLimits, type DecoderState, FountainDecoder, FountainEncoder, type FountainEncoderOptions, type ParsedUr, type Part, type Progress, type ReceiveResult, UrDecoder, type UrDecoderOptions, UrEncoder, type UrEncoderOptions, UrError, type UrErrorCode, type UrErrorInfo, type UrLimit, type UrType, checksum as crc32, encodeUr, isUrType, parseUrType, toQrString };
package/dist/index.mjs CHANGED
@@ -1,2 +1,2 @@
1
- import { S as UrError, _ as canonicalizeByteword, a as decodeWithType, b as encodeRaw, c as normalizeUr, d as UrType, f as FountainEncoder, g as bytewords_exports, h as DEFAULT_LIMITS, i as decodeMessage, l as parse, m as Part, n as Encoder, o as encode, p as FountainDecoder, r as decode, s as toQrString, t as Decoder, u as parseNormalized, v as decode$1, w as failPoison, x as checksum, y as encode$1 } from "./ur-C5n_FgVn.mjs";
2
- export { DEFAULT_LIMITS, Decoder, Encoder, FountainDecoder, FountainEncoder, Part, UrError, UrType, bytewords_exports as bytewords, canonicalizeByteword, checksum as crc32, decode, decode$1 as decodeBytewords, decodeMessage, decodeWithType, encode, encode$1 as encodeBytewords, encodeRaw, failPoison, normalizeUr, parse, parseNormalized, toQrString };
1
+ import { C as checksum, S as WORDS, _ as canonicalizeByteword, a as parseUr, b as BYTEMOJIS, c as decodePart, d as FountainDecoder, f as DEFAULT_LIMITS, g as bytewordsIdentifier, h as bytewordsEncodedLength, i as toQrString, l as encodePart, m as bytewordsChecksum, n as UrEncoder, o as isUrType, p as bytemojiIdentifier, r as encodeUr, s as parseUrType, t as UrDecoder, u as FountainEncoder, v as decodeBytewords, w as UrError, x as MINIMALS, y as encodeBytewords } from "./ur-7Ge3roVh.mjs";
2
+ export { BYTEMOJIS, DEFAULT_LIMITS, FountainDecoder, FountainEncoder, MINIMALS, UrDecoder, UrEncoder, UrError, WORDS, bytemojiIdentifier, bytewordsChecksum, bytewordsEncodedLength, bytewordsIdentifier, canonicalizeByteword, checksum as crc32, decodeBytewords, decodePart, encodeBytewords, encodePart, encodeUr, isUrType, parseUr, parseUrType, toQrString };
@@ -0,0 +1,201 @@
1
+ import { C as parseUrType, S as isUrType, _ as UrError, b as UrLimit, v as UrErrorCode, x as UrType, y as UrErrorInfo } from "./index-DTjNCWBI.mjs";
2
+ import { a as fromUr, c as toUr, i as fromTagged, l as Ur, n as codecMap, o as fromUrWith, r as codecUrTypes, s as toTagged, t as UrCodec } from "./index-CcMfgay6.mjs";
3
+ import { Cbor, CborDate, Tag } from "@blockchaincommons/dcbor";
4
+ //#region src/registry/seed.d.ts
5
+ type Seed = {
6
+ readonly payload: Uint8Array;
7
+ readonly creationDate?: CborDate;
8
+ readonly name?: string;
9
+ readonly note?: string;
10
+ };
11
+ export declare const seedCodec: UrCodec<Seed>;
12
+ //#endregion
13
+ //#region src/registry/psbt.d.ts
14
+ type Psbt = {
15
+ readonly bytes: Uint8Array;
16
+ };
17
+ export declare const psbtCodec: UrCodec<Psbt>;
18
+ //#endregion
19
+ //#region src/registry/keypath.d.ts
20
+ type PathComponent = {
21
+ readonly kind: "index";
22
+ readonly index: number;
23
+ readonly hardened: boolean;
24
+ } | {
25
+ readonly kind: "range";
26
+ readonly low: number;
27
+ readonly high: number;
28
+ readonly hardened: boolean;
29
+ } | {
30
+ readonly kind: "wildcard";
31
+ readonly hardened: boolean;
32
+ } | {
33
+ readonly kind: "pair";
34
+ readonly external: {
35
+ readonly index: number;
36
+ readonly hardened: boolean;
37
+ };
38
+ readonly internal: {
39
+ readonly index: number;
40
+ readonly hardened: boolean;
41
+ };
42
+ };
43
+ type Keypath = {
44
+ readonly components: ReadonlyArray<PathComponent>;
45
+ readonly sourceFingerprint?: number;
46
+ readonly depth?: number;
47
+ };
48
+ export declare const keypathCodec: UrCodec<Keypath>;
49
+ //#endregion
50
+ //#region src/registry/coin-info.d.ts
51
+ export declare const CoinType: {
52
+ readonly btc: 0;
53
+ readonly eth: 0x3c;
54
+ };
55
+ export declare const Network: {
56
+ readonly mainnet: 0;
57
+ readonly btcTestnet: 1;
58
+ };
59
+ type CoinInfo = {
60
+ readonly type?: number;
61
+ readonly network?: number;
62
+ };
63
+ export declare const coinInfoCodec: UrCodec<CoinInfo>;
64
+ //#endregion
65
+ //#region src/registry/eckey.d.ts
66
+ type EcKey = {
67
+ readonly curve?: number;
68
+ readonly isPrivate?: boolean;
69
+ readonly data: Uint8Array;
70
+ };
71
+ export declare const ecKeyCodec: UrCodec<EcKey>;
72
+ //#endregion
73
+ //#region src/registry/address.d.ts
74
+ declare const ADDRESS_TYPES: readonly ["p2pkh", "p2sh", "p2wpkh"];
75
+ type AddressType = (typeof ADDRESS_TYPES)[number];
76
+ type Address = {
77
+ readonly info?: CoinInfo;
78
+ readonly type?: AddressType;
79
+ readonly data: Uint8Array;
80
+ };
81
+ export declare const addressCodec: UrCodec<Address>;
82
+ //#endregion
83
+ //#region src/registry/hdkey.d.ts
84
+ type MasterHdKey = {
85
+ readonly kind: "master";
86
+ readonly keyData: Uint8Array;
87
+ readonly chainCode: Uint8Array;
88
+ };
89
+ type DerivedHdKey = {
90
+ readonly kind: "derived";
91
+ readonly isPrivate?: boolean;
92
+ readonly keyData: Uint8Array;
93
+ readonly chainCode?: Uint8Array;
94
+ readonly useInfo?: CoinInfo;
95
+ readonly origin?: Keypath;
96
+ readonly children?: Keypath;
97
+ readonly parentFingerprint?: number;
98
+ readonly name?: string;
99
+ readonly note?: string;
100
+ };
101
+ type HdKey = MasterHdKey | DerivedHdKey;
102
+ export declare const hdKeyCodec: UrCodec<HdKey>;
103
+ //#endregion
104
+ //#region src/registry/script-expression.d.ts
105
+ type DescriptorKey = {
106
+ readonly kind: "hdkey";
107
+ readonly key: HdKey;
108
+ } | {
109
+ readonly kind: "eckey";
110
+ readonly key: EcKey;
111
+ } | {
112
+ readonly kind: "address";
113
+ readonly address: Address;
114
+ };
115
+ //#endregion
116
+ //#region src/registry/output-descriptor.d.ts
117
+ type OutputDescriptor = {
118
+ readonly source: string;
119
+ readonly keys: ReadonlyArray<DescriptorKey>;
120
+ readonly name?: string;
121
+ readonly note?: string;
122
+ };
123
+ export declare const outputDescriptorCodec: UrCodec<OutputDescriptor>;
124
+ //#endregion
125
+ //#region src/registry/account-descriptor.d.ts
126
+ type AccountDescriptor = {
127
+ readonly masterFingerprint: number;
128
+ readonly outputDescriptors: ReadonlyArray<OutputDescriptor>;
129
+ };
130
+ export declare const accountDescriptorCodec: UrCodec<AccountDescriptor>;
131
+ //#endregion
132
+ //#region src/registry/sskr.d.ts
133
+ type SskrShare = {
134
+ readonly identifier: number;
135
+ readonly groupThreshold: number;
136
+ readonly groupCount: number;
137
+ readonly groupIndex: number;
138
+ readonly memberThreshold: number;
139
+ readonly memberIndex: number;
140
+ readonly shareValue: Uint8Array;
141
+ };
142
+ export declare const sskrCodec: UrCodec<SskrShare>;
143
+ //#endregion
144
+ //#region src/registry/envelope.d.ts
145
+ /** Inclusive cap: depth 0..=64 accepted (65 frames). Predicate is `>`, not `>=`. */
146
+ export declare const ENVELOPE_MAX_DEPTH = 64;
147
+ export declare function assertEnvelopeContent(cbor: Cbor, depth?: number): void;
148
+ export declare const envelopeCodec: UrCodec<Cbor>;
149
+ //#endregion
150
+ //#region src/registry/digest.d.ts
151
+ /** BCR-2021-002: SHA-256 of the raw seed payload, not the CBOR map. */
152
+ export declare function seedDigest(seed: Seed): Uint8Array;
153
+ /** BCR-2021-002: dCBOR of [keyData, chainCode | null, coinType, network]. */
154
+ export declare function hdKeyDigestSource(key: HdKey): Uint8Array;
155
+ export declare function hdKeyDigest(key: HdKey): Uint8Array;
156
+ //#endregion
157
+ //#region src/registry/tags.d.ts
158
+ /**
159
+ * Codecs that exist in this version. The `crypto-*` entries are the deprecated v1 tags
160
+ * (BCR-2020-006): read-only, never written. `SCRIPT_TAGS` are the BCR-2020-010 script-expression
161
+ * tags embedded inside v1 crypto-output bodies.
162
+ */
163
+ export declare const TAGS: Readonly<{
164
+ envelope: Tag;
165
+ seed: Tag;
166
+ hdkey: Tag;
167
+ keypath: Tag;
168
+ "coin-info": Tag;
169
+ eckey: Tag;
170
+ address: Tag;
171
+ "output-descriptor": Tag;
172
+ sskr: Tag;
173
+ psbt: Tag;
174
+ "account-descriptor": Tag;
175
+ "crypto-seed": Tag;
176
+ "crypto-hdkey": Tag;
177
+ "crypto-keypath": Tag;
178
+ "crypto-coin-info": Tag;
179
+ "crypto-eckey": Tag;
180
+ "crypto-address": Tag;
181
+ "crypto-output": Tag;
182
+ "crypto-sskr": Tag;
183
+ "crypto-psbt": Tag;
184
+ "crypto-account": Tag;
185
+ }>;
186
+ /** BCR-2020-010 script-expression tags by descriptor function name. */
187
+ export declare const SCRIPT_TAGS: Readonly<{
188
+ sh: Tag;
189
+ wsh: Tag;
190
+ pk: Tag;
191
+ pkh: Tag;
192
+ wpkh: Tag;
193
+ combo: Tag;
194
+ multi: Tag;
195
+ sortedmulti: Tag;
196
+ raw: Tag;
197
+ tr: Tag;
198
+ cosigner: Tag;
199
+ }>;
200
+ //#endregion
201
+ export { type AccountDescriptor, type Address, type AddressType, type CoinInfo, type DerivedHdKey, type DescriptorKey, type EcKey, type HdKey, type Keypath, type MasterHdKey, type OutputDescriptor, type PathComponent, type Psbt, type Seed, type SskrShare, Ur, type UrCodec, UrError, type UrErrorCode, type UrErrorInfo, type UrLimit, type UrType, codecMap, codecUrTypes, fromTagged, fromUr, fromUrWith, isUrType, parseUrType, toTagged, toUr };