@qntx/ur 1.1.0 → 1.8.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 CHANGED
@@ -1,6 +1,6 @@
1
1
  <!-- markdownlint-disable MD033 MD041 -->
2
2
 
3
- # ur.js
3
+ # `@qntx/ur`
4
4
 
5
5
  Uniform Resources (UR) for TypeScript.
6
6
 
@@ -8,22 +8,8 @@ Bytewords, fountain codes, and single- or multi-part UR strings. Transport-only
8
8
 
9
9
  `Encoder` K==1 outbound is single-part (an ur-rs `Decoder` will not consume it). This package still decodes ur-rs `1-1`.
10
10
 
11
- See [docs/](docs/).
11
+ See [docs/](../../docs/).
12
12
 
13
13
  ## License
14
14
 
15
15
  Licensed under the MIT License ([LICENSE](LICENSE) or <https://opensource.org/licenses/MIT>).
16
-
17
- Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in this project shall be licensed as above, without any additional terms or conditions.
18
-
19
- ---
20
-
21
- <div align="center">
22
-
23
- A **[QuantX](https://qntx.org)** open-source project.
24
-
25
- <a href="https://qntx.org"><img alt="QuantX" width="369" src="https://raw.githubusercontent.com/qntx/.github/main/profile/qntx.svg" /></a>
26
-
27
- Code is law. We write both.
28
-
29
- </div>
@@ -0,0 +1,59 @@
1
+ import { i as DecoderPoison, r as DecoderLimits, t as UrType } from "./type-CZ0CIHJk.mjs";
2
+ import { Cbor, CborInput, Tag } from "@blockchaincommons/dcbor";
3
+ //#region src/typed/ur.d.ts
4
+ /** Uniform Resource whose payload is deterministic CBOR. */
5
+ declare class Ur {
6
+ readonly type: UrType;
7
+ readonly cbor: Cbor;
8
+ private constructor();
9
+ static create(type: UrType | string, input: CborInput): Ur;
10
+ /** Wrap already-encoded dCBOR bytes. Used by fromUrString. */
11
+ static fromCborData(type: UrType | string, data: Uint8Array): Ur;
12
+ static fromUrString(uri: string): Ur;
13
+ string(): string;
14
+ qrString(): string;
15
+ checkType(expected: UrType | string): void;
16
+ }
17
+ //#endregion
18
+ //#region src/typed/codec.d.ts
19
+ /** First `tags[0].name` is the UR type; body is untagged. */
20
+ type UrCodec<T> = {
21
+ /** Most-preferred first. First tag.name is the UR type token. */
22
+ readonly tags: ReadonlyArray<Tag>;
23
+ untaggedCbor(value: T): Cbor;
24
+ readonly fromUntaggedCbor: (cbor: Cbor) => T;
25
+ };
26
+ declare function firstTagUrType(tags: ReadonlyArray<Tag>): UrType;
27
+ declare function toUr<T>(value: T, codec: UrCodec<T>): Ur;
28
+ declare function fromUr<T>(ur: Ur, codec: UrCodec<T>): T;
29
+ declare function toUrString<T>(value: T, codec: UrCodec<T>): string;
30
+ declare function fromUrString<T>(uri: string, codec: UrCodec<T>): T;
31
+ //#endregion
32
+ //#region src/typed/multipart.d.ts
33
+ declare class MultipartEncoder {
34
+ #private;
35
+ private constructor();
36
+ static create(ur: Ur, maxFragmentLength: number): MultipartEncoder;
37
+ nextPart(): string;
38
+ get isSinglePart(): boolean;
39
+ get fragmentCount(): number;
40
+ get currentIndex(): number;
41
+ get complete(): boolean;
42
+ }
43
+ declare class MultipartDecoder {
44
+ #private;
45
+ constructor(options?: {
46
+ limits?: Partial<DecoderLimits>;
47
+ expectedType?: UrType;
48
+ });
49
+ receive(uri: string): void;
50
+ get complete(): boolean;
51
+ get fragmentCount(): number;
52
+ resolvedFragmentCount(): number | undefined;
53
+ get type(): UrType | undefined;
54
+ get isPoisoned(): boolean;
55
+ get poisonState(): DecoderPoison | undefined;
56
+ message(): Ur | undefined;
57
+ }
58
+ //#endregion
59
+ export { fromUr as a, toUrString as c, firstTagUrType as i, Ur as l, MultipartEncoder as n, fromUrString as o, UrCodec as r, toUr as s, MultipartDecoder as t };
package/dist/index.d.mts CHANGED
@@ -1,17 +1,14 @@
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";
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-CZ0CIHJk.mjs";
2
2
  //#region src/crc32.d.ts
3
- /**
4
- * CRC-32 ISO-HDLC (polynomial 0xedb88320), matching bcur / ur-rs.
5
- */
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
+ declare const WORDS: ReadonlyArray<string>;
13
10
  /** First+last letter of each byteword (UR minimal style). */
14
- declare const MINIMALS: readonly string[];
11
+ declare const MINIMALS: ReadonlyArray<string>;
15
12
  declare namespace index_d_exports {
16
13
  export { MINIMALS, Style, WORDS, canonicalizeByteword, decode$1 as decode, encode$1 as encode, encodeRaw };
17
14
  }
@@ -19,19 +16,16 @@ declare namespace index_d_exports {
19
16
  type Style = "standard" | "uri" | "minimal";
20
17
  /** Encode `data` with trailing CRC-32 as bytewords. Empty data is allowed. */
21
18
  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
+ /** Encode without CRC trailer. Not for UR bodies — identifiers only. */
20
+ export declare function encodeRaw(data: Uint8Array, style: Style): string;
27
21
  /** Decode bytewords and verify CRC-32. Case-insensitive. */
28
22
  declare function decode$1(encoded: string, style: Style): Uint8Array;
29
23
  /** Canonicalize a 2–4 letter token to the full 4-letter lowercase byteword. */
30
- declare function canonicalizeByteword(token: string): string | undefined;
24
+ export declare function canonicalizeByteword(token: string): string | undefined;
31
25
  //#endregion
32
26
  //#region src/fountain/part.d.ts
33
27
  /** A fountain part (wire metadata + fragment data). */
34
- declare class Part {
28
+ export declare class Part {
35
29
  readonly sequence: number;
36
30
  readonly sequenceCount: number;
37
31
  readonly messageLength: number;
@@ -48,16 +42,18 @@ declare class Part {
48
42
  //#endregion
49
43
  //#region src/fountain/decoder.d.ts
50
44
  /** Fountain decoder with resource limits and fail-closed poison. */
51
- declare class FountainDecoder {
45
+ export declare class FountainDecoder {
52
46
  private readonly decoded;
53
47
  private readonly received;
54
48
  private readonly buffer;
49
+ private readonly bufferIndex;
55
50
  private readonly queue;
56
51
  private sequenceCount;
57
52
  private messageLength;
58
53
  private messageChecksum;
59
54
  private fragmentLength;
60
55
  private readonly limits;
56
+ private chooser;
61
57
  private poisoned;
62
58
  constructor(limits?: Partial<DecoderLimits>);
63
59
  get maxFragmentDataLength(): number;
@@ -68,7 +64,8 @@ declare class FountainDecoder {
68
64
  private escalate;
69
65
  /**
70
66
  * Receive a fountain part.
71
- * @returns whether the part was newly ingested.
67
+ *
68
+ * @returns Whether the part was newly ingested.
72
69
  */
73
70
  receive(part: Part): boolean;
74
71
  private enqueueSimple;
@@ -86,11 +83,12 @@ declare class FountainDecoder {
86
83
  //#endregion
87
84
  //#region src/fountain/encoder.d.ts
88
85
  /** Fountain encoder. */
89
- declare class FountainEncoder {
86
+ export declare class FountainEncoder {
90
87
  private readonly parts;
91
88
  private readonly sequenceCount;
92
89
  private readonly messageLength;
93
90
  private readonly messageChecksum;
91
+ private readonly chooser;
94
92
  private currentSequence;
95
93
  private constructor();
96
94
  static create(message: Uint8Array, maxFragmentLength: number): FountainEncoder;
@@ -102,7 +100,7 @@ declare class FountainEncoder {
102
100
  //#endregion
103
101
  //#region src/ur/parse.d.ts
104
102
  type Kind = "single" | "multi";
105
- interface ParsedUr {
103
+ type ParsedUr = {
106
104
  type: UrType;
107
105
  kind: Kind;
108
106
  indices?: {
@@ -110,37 +108,37 @@ interface ParsedUr {
110
108
  count: number;
111
109
  };
112
110
  body: string;
113
- }
111
+ };
114
112
  /** Lowercase a UR string for case-insensitive QR transport. */
115
- declare function normalizeUr(uri: string): string;
113
+ export declare function normalizeUr(uri: string): string;
116
114
  /** Parse a UR (full-URI case fold). Does not decode bytewords. */
117
- declare function parse(uri: string): ParsedUr;
115
+ export declare function parse(uri: string): ParsedUr;
118
116
  /** Parse an already-lowercased (or body-normalized) UR. */
119
- declare function parseNormalized(uri: string): ParsedUr;
117
+ export declare function parseNormalized(uri: string): ParsedUr;
120
118
  //#endregion
121
119
  //#region src/ur/index.d.ts
122
120
  /** Encode a single-part UR. Empty data is allowed. */
123
- declare function encode(data: Uint8Array, type: UrType): string;
121
+ export declare function encode(data: Uint8Array, type: UrType): string;
124
122
  /**
125
- * Decode payload from a single- or multi-part UR.
126
- * Multi-part returns the CBOR-encoded fountain part bytes, not the message.
123
+ * Decode payload from a single- or multi-part UR. Multi-part returns the CBOR-encoded fountain part
124
+ * bytes, not the message.
127
125
  */
128
- declare function decode(uri: string): {
126
+ export declare function decode(uri: string): {
129
127
  kind: Kind;
130
128
  payload: Uint8Array;
131
129
  };
132
130
  /** Like {@link decode} but retains the normalized type. */
133
- declare function decodeWithType(uri: string): {
131
+ export declare function decodeWithType(uri: string): {
134
132
  type: UrType;
135
133
  kind: Kind;
136
134
  payload: Uint8Array;
137
135
  };
138
136
  /** Decode a single-part UR payload. Multi-part URIs throw `NotSinglePart`. */
139
- declare function decodeMessage(uri: string): Uint8Array;
137
+ export declare function decodeMessage(uri: string): Uint8Array;
140
138
  /** Uppercase UR string for denser QR alphanumeric mode. */
141
- declare function toQrString(uri: string): string;
139
+ export declare function toQrString(uri: string): string;
142
140
  /** UR encoder. `K == 1` emits single-part; otherwise fountain. */
143
- declare class Encoder {
141
+ export declare class Encoder {
144
142
  private readonly fountain;
145
143
  private readonly urType;
146
144
  private readonly message;
@@ -155,7 +153,7 @@ declare class Encoder {
155
153
  nextPart(): string;
156
154
  }
157
155
  /** UR decoder with type stickiness and URI limits. */
158
- declare class Decoder {
156
+ export declare class Decoder {
159
157
  private readonly fountain;
160
158
  private readonly maxUriLen;
161
159
  private readonly maxMessageLength;
@@ -181,4 +179,4 @@ declare class Decoder {
181
179
  get isPoisoned(): boolean;
182
180
  }
183
181
  //#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 };
182
+ export { DEFAULT_LIMITS, type DecoderLimits, type DecoderPoison, type Kind, type ParsedUr, type Style, UrError, type UrErrorCode, UrType, index_d_exports as bytewords, checksum as crc32, decode$1 as decodeBytewords, encode$1 as encodeBytewords, failPoison };
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";
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-BUUcXyia.mjs";
2
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 };
@@ -0,0 +1,142 @@
1
+ import { a as UrError, o as UrErrorCode, t as UrType } from "./type-CZ0CIHJk.mjs";
2
+ import { a as fromUr, c as toUrString, i as firstTagUrType, l as Ur, n as MultipartEncoder, o as fromUrString, r as UrCodec, s as toUr, t as MultipartDecoder } from "./index-BeG2XIr5.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: 60;
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/hdkey.d.ts
66
+ type MasterHdKey = {
67
+ readonly kind: "master";
68
+ readonly keyData: Uint8Array;
69
+ readonly chainCode: Uint8Array;
70
+ };
71
+ type DerivedHdKey = {
72
+ readonly kind: "derived";
73
+ readonly isPrivate?: boolean;
74
+ readonly keyData: Uint8Array;
75
+ readonly chainCode?: Uint8Array;
76
+ readonly useInfo?: CoinInfo;
77
+ readonly origin?: Keypath;
78
+ readonly children?: Keypath;
79
+ readonly parentFingerprint?: number;
80
+ readonly name?: string;
81
+ readonly note?: string;
82
+ };
83
+ type HdKey = MasterHdKey | DerivedHdKey;
84
+ export declare const hdKeyCodec: UrCodec<HdKey>;
85
+ //#endregion
86
+ //#region src/registry/sskr.d.ts
87
+ type SskrShare = {
88
+ readonly identifier: number;
89
+ readonly groupThreshold: number;
90
+ readonly groupCount: number;
91
+ readonly groupIndex: number;
92
+ readonly memberThreshold: number;
93
+ readonly memberIndex: number;
94
+ readonly shareValue: Uint8Array;
95
+ };
96
+ export declare const sskrCodec: UrCodec<SskrShare>;
97
+ //#endregion
98
+ //#region src/registry/envelope.d.ts
99
+ /** Inclusive cap: depth 0..=64 accepted (65 frames). Predicate is `>`, not `>=`. */
100
+ export declare const ENVELOPE_MAX_DEPTH = 64;
101
+ export declare function assertEnvelopeContent(cbor: Cbor, depth?: number): void;
102
+ export declare const envelopeCodec: UrCodec<Cbor>;
103
+ //#endregion
104
+ //#region src/registry/codecs.d.ts
105
+ export declare function codecMap(codecs: ReadonlyArray<UrCodec<unknown>>): ReadonlyMap<string, UrCodec<unknown>>;
106
+ export declare function fromUrStringWith(uri: string, codecs: ReadonlyMap<string, UrCodec<unknown>>): {
107
+ readonly type: string;
108
+ readonly value: unknown;
109
+ };
110
+ //#endregion
111
+ //#region src/registry/digest.d.ts
112
+ /** BCR-2021-002: SHA-256 of the raw seed payload, not the CBOR map. */
113
+ export declare function seedDigest(seed: Seed): Uint8Array;
114
+ /** BCR-2021-002: dCBOR of [keyData, chainCode | null, coinType, network]. */
115
+ export declare function hdKeyDigestSource(key: HdKey): Uint8Array;
116
+ export declare function hdKeyDigest(key: HdKey): Uint8Array;
117
+ //#endregion
118
+ //#region src/registry/tags.d.ts
119
+ export declare const TAG_ENVELOPE = 200;
120
+ export declare const TAG_ENVELOPE_LEAF = 201;
121
+ export declare const TAG_SEED = 40300;
122
+ export declare const TAG_HDKEY = 40303;
123
+ export declare const TAG_KEYPATH = 40304;
124
+ export declare const TAG_COIN_INFO = 40305;
125
+ export declare const TAG_SSKR = 40309;
126
+ export declare const TAG_PSBT = 40310;
127
+ export declare const TAG_KNOWN_VALUE = 40000;
128
+ export declare const TAG_DIGEST = 40001;
129
+ export declare const TAG_ENCRYPTED = 40002;
130
+ export declare const TAG_COMPRESSED = 40003;
131
+ /** Codecs that exist in this version. Number constants for later tags live above. */
132
+ export declare const TAGS: {
133
+ readonly envelope: Tag;
134
+ readonly seed: Tag;
135
+ readonly hdkey: Tag;
136
+ readonly keypath: Tag;
137
+ readonly "coin-info": Tag;
138
+ readonly sskr: Tag;
139
+ readonly psbt: Tag;
140
+ };
141
+ //#endregion
142
+ export { type CoinInfo, type DerivedHdKey, type HdKey, type Keypath, type MasterHdKey, MultipartDecoder, MultipartEncoder, type PathComponent, type Psbt, type Seed, type SskrShare, Ur, type UrCodec, UrError, type UrErrorCode, UrType, firstTagUrType, fromUr, fromUrString, toUr, toUrString };