@qntx/ur 2.1.0 → 3.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.
@@ -10,9 +10,9 @@ declare function parseUrType(text: string): UrType;
10
10
  declare function isUrType(text: string): text is UrType;
11
11
  //#endregion
12
12
  //#region src/error.d.ts
13
- /** Discriminated error codes for the UR transport stack. Mirrors `bcur::ErrorKind`. */
14
- type UrErrorCode = "NonAscii" | "InvalidWord" | "InvalidBytewordsLength" | "InvalidBytewordsChecksum" | "InvalidScheme" | "TypeUnspecified" | "InvalidType" | "InvalidIndices" | "UnexpectedType" | "InvalidPartCbor" | "InvalidPart" | "InconsistentPart" | "ResourceLimit" | "InvalidPadding" | "InvalidMessageChecksum" | "EmptyMessage" | "InvalidFragmentLength" | "MessageTooLong" | "NotSinglePart" | "CborDecode" | "CborType" | "Internal";
15
- /** Decoder budget names carried by `ResourceLimit` errors. Mirrors `bcur::Limit`. */
13
+ /** Discriminated error codes for the UR transport stack. */
14
+ type UrErrorCode = "NonAscii" | "InvalidWord" | "InvalidBytewordsLength" | "InvalidBytewordsChecksum" | "InvalidScheme" | "TypeUnspecified" | "InvalidType" | "InvalidIndices" | "UnexpectedType" | "InvalidPartCbor" | "InvalidPart" | "InconsistentPart" | "ResourceLimit" | "InvalidPadding" | "InvalidMessageChecksum" | "EmptyMessage" | "MessageTooLong" | "NotSinglePart" | "CborDecode" | "CborType" | "Internal";
15
+ /** Decoder budget names carried by `ResourceLimit` errors. */
16
16
  type UrLimit = "messageLength" | "fragmentCount" | "fragmentLength" | "uriLength";
17
17
  /** Per-code error detail; `switch (info.code)` narrows the payload. */
18
18
  type UrErrorInfo = Readonly<{
@@ -37,14 +37,14 @@ declare class UrError extends Error {
37
37
  //#endregion
38
38
  //#region src/fountain/limits.d.ts
39
39
  /** Hard limits for adversarial multi-part streams (UR-ADR-015). */
40
- type DecoderLimits = {
40
+ type DecoderLimits = Readonly<{
41
41
  maxMessageLength: number;
42
42
  maxFragmentCount: number;
43
43
  maxFragmentLength: number;
44
44
  maxUriLength: number;
45
- };
45
+ }>;
46
46
  /**
47
- * Production default; same integers as bcur.
47
+ * Production default (1 MiB message, 2000 fragments, 8192-byte fragments and URIs), frozen.
48
48
  *
49
49
  * Hosts that need another budget pass `new UrDecoder({ limits })`.
50
50
  */
@@ -145,7 +145,7 @@ type FountainEncoderOptions = Readonly<{
145
145
  /**
146
146
  * Fountain encoder. An infinite iterator: produces parts with sequence `firstSequence + 1`, `+2`, …
147
147
  * and ends after `0xFFFFFFFF` (UR-ADR-028). For `K == 1` it keeps producing identical parts with
148
- * rising sequences.
148
+ * rising sequences. Message problems throw `UrError`; invalid options throw `RangeError`.
149
149
  */
150
150
  declare class FountainEncoder implements IterableIterator<Part> {
151
151
  #private;
@@ -1,4 +1,4 @@
1
- import { a as UrEncoderOptions, i as UrEncoder, t as DecodedUr, x as UrType } from "./index-DTjNCWBI.mjs";
1
+ import { a as UrEncoderOptions, i as UrEncoder, t as DecodedUr, x as UrType } from "./index-HtwyWL4y.mjs";
2
2
  import { Cbor, CborInput, Tag } from "@blockchaincommons/dcbor";
3
3
  //#region src/typed/ur.d.ts
4
4
  /** Uniform Resource whose payload is deterministic CBOR. */
@@ -13,7 +13,7 @@ declare class Ur {
13
13
  static parse(text: string): Ur;
14
14
  /** Wrap a completed {@link UrDecoder} result; the message must be dCBOR. */
15
15
  static fromDecoded(decoded: DecodedUr): Ur;
16
- toCborData(): Uint8Array;
16
+ toCborData(): Uint8Array<ArrayBuffer>;
17
17
  toString(): string;
18
18
  toQrString(): string;
19
19
  /** L3 encoder over this UR's dCBOR bytes. */
@@ -43,12 +43,16 @@ declare function fromUr<T>(ur: Ur, codec: UrCodec<T>): T;
43
43
  declare function toTagged<T>(value: T, codec: UrCodec<T>): Cbor;
44
44
  /** Unwraps any of the codec's tags, then decodes the body. */
45
45
  declare function fromTagged<T>(cbor: Cbor, codec: UrCodec<T>): T;
46
+ /** Value type of a codec. */
47
+ type CodecValue<C> = C extends UrCodec<infer T> ? T : never;
48
+ /** `UrType -> codec` map, typed by the union of the codecs' value types. */
49
+ type CodecMap<T> = ReadonlyMap<UrType, UrCodec<T>>;
46
50
  /** `UrType -> codec` map covering every tag name; a duplicate type is `InvalidType`. */
47
- declare function codecMap(codecs: ReadonlyArray<UrCodec<unknown>>): ReadonlyMap<UrType, UrCodec<unknown>>;
51
+ declare function codecMap<const C extends ReadonlyArray<UrCodec<unknown>>>(codecs: C): CodecMap<CodecValue<C[number]>>;
48
52
  /** Decodes `ur` through the codec registered for its type. */
49
- declare function fromUrWith(ur: Ur, codecs: ReadonlyMap<UrType, UrCodec<unknown>>): Readonly<{
53
+ declare function fromUrWith<T>(ur: Ur, codecs: CodecMap<T>): Readonly<{
50
54
  type: UrType;
51
- value: unknown;
55
+ value: T;
52
56
  }>;
53
57
  //#endregion
54
- export { fromUr as a, toUr as c, fromTagged as i, Ur as l, codecMap as n, fromUrWith as o, codecUrTypes as r, toTagged as s, UrCodec as t };
58
+ export { codecUrTypes as a, fromUrWith as c, Ur as d, codecMap as i, toTagged as l, CodecValue as n, fromTagged as o, UrCodec as r, fromUr as s, CodecMap as t, toUr as u };
package/dist/index.d.mts CHANGED
@@ -1,4 +1,4 @@
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";
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-HtwyWL4y.mjs";
2
2
  //#region src/consensus/crc32.d.ts
3
3
  /** CRC-32 ISO-HDLC checksum of `data`. */
4
4
  declare function checksum(data: Uint8Array): number;
@@ -26,7 +26,7 @@ export declare function bytewordsIdentifier(data: Uint8Array): string;
26
26
  /** Four-emoji identifier of a 4-byte digest (BCR-2024-008). */
27
27
  export declare function bytemojiIdentifier(data: Uint8Array): string;
28
28
  /** Decode bytewords and verify CRC-32. Case-insensitive. */
29
- export declare function decodeBytewords(text: string, style: BytewordsStyle): Uint8Array;
29
+ export declare function decodeBytewords(text: string, style: BytewordsStyle): Uint8Array<ArrayBuffer>;
30
30
  /** Canonicalize a 2–4 letter token to the full 4-letter lowercase byteword. */
31
31
  export declare function canonicalizeByteword(token: string): string | undefined;
32
32
  //#endregion
@@ -35,7 +35,7 @@ export declare function canonicalizeByteword(token: string): string | undefined;
35
35
  * Encode a part as fixed-schema deterministic CBOR: `array(5) [sequence, sequenceCount,
36
36
  * messageLength, checksum, data]` with shortest-form integers.
37
37
  */
38
- export declare function encodePart(part: Part): Uint8Array;
38
+ export declare function encodePart(part: Part): Uint8Array<ArrayBuffer>;
39
39
  /**
40
40
  * Decode a part from CBOR. Lenient on integer width (UR-ADR-017): any well-formed definite-length
41
41
  * encoding is accepted; re-encode with {@link encodePart} for the shortest form. `limits` apply
package/dist/index.mjs CHANGED
@@ -1,2 +1,2 @@
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";
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-ChGW72hQ.mjs";
2
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 };
@@ -1,10 +1,10 @@
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";
1
+ import { C as parseUrType, S as isUrType, _ as UrError, b as UrLimit, v as UrErrorCode, x as UrType, y as UrErrorInfo } from "./index-HtwyWL4y.mjs";
2
+ import { a as codecUrTypes, c as fromUrWith, d as Ur, i as codecMap, l as toTagged, n as CodecValue, o as fromTagged, r as UrCodec, s as fromUr, t as CodecMap, u as toUr } from "./index-rxH9gNTp.mjs";
3
+ import { Cbor, Tag } from "@blockchaincommons/dcbor";
4
4
  //#region src/registry/seed.d.ts
5
5
  type Seed = {
6
6
  readonly payload: Uint8Array;
7
- readonly creationDate?: CborDate;
7
+ readonly creationDate?: Date;
8
8
  readonly name?: string;
9
9
  readonly note?: string;
10
10
  };
@@ -149,10 +149,10 @@ export declare const envelopeCodec: UrCodec<Cbor>;
149
149
  //#endregion
150
150
  //#region src/registry/digest.d.ts
151
151
  /** BCR-2021-002: SHA-256 of the raw seed payload, not the CBOR map. */
152
- export declare function seedDigest(seed: Seed): Uint8Array;
152
+ export declare function seedDigest(seed: Seed): Uint8Array<ArrayBuffer>;
153
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;
154
+ export declare function hdKeyDigestSource(key: HdKey): Uint8Array<ArrayBuffer>;
155
+ export declare function hdKeyDigest(key: HdKey): Uint8Array<ArrayBuffer>;
156
156
  //#endregion
157
157
  //#region src/registry/tags.d.ts
158
158
  /**
@@ -198,4 +198,4 @@ export declare const SCRIPT_TAGS: Readonly<{
198
198
  cosigner: Tag;
199
199
  }>;
200
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 };
201
+ export { type AccountDescriptor, type Address, type AddressType, type CodecMap, type CodecValue, 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 };
package/dist/registry.mjs CHANGED
@@ -1,5 +1,5 @@
1
- import { o as isUrType, s as parseUrType, w as UrError } from "./ur-7Ge3roVh.mjs";
2
- import { a as fromUrWith, c as Ur, i as fromUr, n as codecUrTypes, o as toTagged, r as fromTagged, s as toUr, t as codecMap } from "./typed-D-SyraAj.mjs";
1
+ import { o as isUrType, s as parseUrType, w as UrError } from "./ur-ChGW72hQ.mjs";
2
+ import { a as fromUrWith, c as Ur, i as fromUr, n as codecUrTypes, o as toTagged, r as fromTagged, s as toUr, t as codecMap } from "./typed-C8j8iVYT.mjs";
3
3
  import { sha256 } from "@noble/hashes/sha2.js";
4
4
  import { CborDate, CborError, CborMap, MajorType, Tag, bytesToHex, cbor, encodeCbor, expectArray, expectBoolean, expectBytes, expectInteger, expectMap, expectText, expectUnsigned, extractTaggedContent, hasTag, isArray, isBytes, isMap, isTagged, isUnsigned } from "@blockchaincommons/dcbor";
5
5
  //#region src/registry/bytes.ts
@@ -115,7 +115,7 @@ const seedCodec = {
115
115
  assertPayloadLen(seed.payload);
116
116
  const map = new CborMap();
117
117
  map.set(1, cbor(copyBuf(seed.payload)));
118
- if (seed.creationDate !== void 0) map.set(2, seed.creationDate);
118
+ if (seed.creationDate !== void 0) map.set(2, CborDate.fromDate(seed.creationDate));
119
119
  if (seed.name !== void 0 && seed.name !== "") map.set(3, assertText(seed.name));
120
120
  if (seed.note !== void 0 && seed.note !== "") map.set(4, assertText(seed.note));
121
121
  return cbor(map);
@@ -129,7 +129,7 @@ const seedCodec = {
129
129
  const note = map.get(4);
130
130
  return Object.freeze({
131
131
  payload,
132
- ...date === void 0 ? {} : { creationDate: expectSeedDate(date) },
132
+ ...date === void 0 ? {} : { creationDate: expectSeedDate(date).toDate() },
133
133
  ...name === void 0 ? {} : { name: expectText(name) },
134
134
  ...note === void 0 ? {} : { note: expectText(note) }
135
135
  });
@@ -462,7 +462,8 @@ const hdKeyCodec = {
462
462
  const map = new CborMap();
463
463
  if (key.kind === "master") {
464
464
  map.set(1, true);
465
- map.set(3, cbor(copyLen(key.keyData, KEY_DATA_LEN)));
465
+ assertKeyData(true, key.keyData);
466
+ map.set(3, cbor(copyBuf(key.keyData)));
466
467
  map.set(4, cbor(copyLen(key.chainCode, CHAIN_CODE_LEN)));
467
468
  return cbor(map);
468
469
  }
@@ -483,9 +484,11 @@ const hdKeyCodec = {
483
484
  if (masterFlag !== void 0) {
484
485
  if (!expectBool(masterFlag)) throw CborError.wrongType();
485
486
  const map = expectClosedIntMap(value, MASTER_KEYS);
487
+ const keyData = bytesOfLen(map.getOrThrow(3), KEY_DATA_LEN);
488
+ assertKeyData(true, keyData);
486
489
  return Object.freeze({
487
490
  kind: "master",
488
- keyData: bytesOfLen(map.getOrThrow(3), KEY_DATA_LEN),
491
+ keyData,
489
492
  chainCode: bytesOfLen(map.getOrThrow(4), CHAIN_CODE_LEN)
490
493
  });
491
494
  }
@@ -878,22 +881,22 @@ const envelopeCodec = {
878
881
  //#region src/registry/digest.ts
879
882
  /** BCR-2021-002: SHA-256 of the raw seed payload, not the CBOR map. */
880
883
  function seedDigest(seed) {
881
- return sha256(seed.payload);
884
+ return new Uint8Array(sha256(seed.payload));
882
885
  }
883
886
  /** BCR-2021-002: dCBOR of [keyData, chainCode | null, coinType, network]. */
884
887
  function hdKeyDigestSource(key) {
885
888
  const chainCode = key.chainCode === void 0 ? null : copyBuf(key.chainCode);
886
889
  const coinType = key.kind === "master" ? 0 : key.useInfo?.type ?? 0;
887
890
  const network = key.kind === "master" ? 0 : key.useInfo?.network ?? 0;
888
- return encodeCbor(cbor([
891
+ return new Uint8Array(encodeCbor(cbor([
889
892
  copyBuf(key.keyData),
890
893
  chainCode,
891
894
  coinType,
892
895
  network
893
- ]));
896
+ ])));
894
897
  }
895
898
  function hdKeyDigest(key) {
896
- return sha256(hdKeyDigestSource(key));
899
+ return new Uint8Array(sha256(hdKeyDigestSource(key)));
897
900
  }
898
901
  //#endregion
899
902
  export { CoinType, ENVELOPE_MAX_DEPTH, Network, SCRIPT_TAGS, TAGS, Ur, UrError, accountDescriptorCodec, addressCodec, assertEnvelopeContent, codecMap, codecUrTypes, coinInfoCodec, ecKeyCodec, envelopeCodec, fromTagged, fromUr, fromUrWith, hdKeyCodec, hdKeyDigest, hdKeyDigestSource, isUrType, keypathCodec, outputDescriptorCodec, parseUrType, psbtCodec, seedCodec, seedDigest, sskrCodec, toTagged, toUr };
@@ -1,4 +1,4 @@
1
- import { T as fail, a as parseUr, i as toQrString, n as UrEncoder, r as encodeUr, s as parseUrType } from "./ur-7Ge3roVh.mjs";
1
+ import { T as fail, a as parseUr, i as toQrString, n as UrEncoder, r as encodeUr, s as parseUrType } from "./ur-ChGW72hQ.mjs";
2
2
  import { CborError, cbor, decodeCbor, encodeCbor, extractTaggedContent, taggedValue, validateTag } from "@blockchaincommons/dcbor";
3
3
  //#region src/typed/ur.ts
4
4
  function mapCborDecode(run) {
@@ -46,7 +46,7 @@ var Ur = class Ur {
46
46
  return Ur.fromCborData(decoded.type, decoded.message);
47
47
  }
48
48
  toCborData() {
49
- return mapCborType(() => encodeCbor(this.cbor));
49
+ return new Uint8Array(mapCborType(() => encodeCbor(this.cbor)));
50
50
  }
51
51
  toString() {
52
52
  return encodeUr(this.type, this.toCborData());
@@ -98,7 +98,6 @@ function fromTagged(cbor, codec) {
98
98
  return codec.decode(extractTaggedContent(cbor));
99
99
  });
100
100
  }
101
- /** `UrType -> codec` map covering every tag name; a duplicate type is `InvalidType`. */
102
101
  function codecMap(codecs) {
103
102
  const map = /* @__PURE__ */ new Map();
104
103
  for (const codec of codecs) for (const type of codecUrTypes(codec)) {
package/dist/typed.d.mts CHANGED
@@ -1,3 +1,3 @@
1
- import { C as parseUrType, S as isUrType, _ as UrError, b as UrLimit, g as DecoderLimits, h as DEFAULT_LIMITS, 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
- export { DEFAULT_LIMITS, type DecoderLimits, Ur, type UrCodec, UrError, type UrErrorCode, type UrErrorInfo, type UrLimit, type UrType, codecMap, codecUrTypes, fromTagged, fromUr, fromUrWith, isUrType, parseUrType, toTagged, toUr };
1
+ import { C as parseUrType, S as isUrType, _ as UrError, b as UrLimit, g as DecoderLimits, h as DEFAULT_LIMITS, v as UrErrorCode, x as UrType, y as UrErrorInfo } from "./index-HtwyWL4y.mjs";
2
+ import { a as codecUrTypes, c as fromUrWith, d as Ur, i as codecMap, l as toTagged, n as CodecValue, o as fromTagged, r as UrCodec, s as fromUr, t as CodecMap, u as toUr } from "./index-rxH9gNTp.mjs";
3
+ export { type CodecMap, type CodecValue, DEFAULT_LIMITS, type DecoderLimits, Ur, type UrCodec, UrError, type UrErrorCode, type UrErrorInfo, type UrLimit, type UrType, codecMap, codecUrTypes, fromTagged, fromUr, fromUrWith, isUrType, parseUrType, toTagged, toUr };
package/dist/typed.mjs CHANGED
@@ -1,3 +1,3 @@
1
- import { f as DEFAULT_LIMITS, o as isUrType, s as parseUrType, w as UrError } from "./ur-7Ge3roVh.mjs";
2
- import { a as fromUrWith, c as Ur, i as fromUr, n as codecUrTypes, o as toTagged, r as fromTagged, s as toUr, t as codecMap } from "./typed-D-SyraAj.mjs";
1
+ import { f as DEFAULT_LIMITS, o as isUrType, s as parseUrType, w as UrError } from "./ur-ChGW72hQ.mjs";
2
+ import { a as fromUrWith, c as Ur, i as fromUr, n as codecUrTypes, o as toTagged, r as fromTagged, s as toUr, t as codecMap } from "./typed-C8j8iVYT.mjs";
3
3
  export { DEFAULT_LIMITS, Ur, UrError, codecMap, codecUrTypes, fromTagged, fromUr, fromUrWith, isUrType, parseUrType, toTagged, toUr };
@@ -17,7 +17,6 @@ const MESSAGES = {
17
17
  InvalidPadding: "invalid fountain part padding",
18
18
  InvalidMessageChecksum: "invalid fountain message checksum",
19
19
  EmptyMessage: "empty message",
20
- InvalidFragmentLength: "invalid fragment length",
21
20
  MessageTooLong: "message too long",
22
21
  NotSinglePart: "expected single-part UR",
23
22
  CborDecode: "dCBOR decode failed",
@@ -63,7 +62,7 @@ function toUrError(error) {
63
62
  }
64
63
  //#endregion
65
64
  //#region src/consensus/crc32.ts
66
- /** CRC-32 ISO-HDLC (polynomial 0xedb88320), matching bcur / ur-rs. */
65
+ /** CRC-32 ISO-HDLC (polynomial 0xedb88320). */
67
66
  const TABLE = (() => {
68
67
  const table = /* @__PURE__ */ new Uint32Array(256);
69
68
  for (let i = 0; i < 256; i++) {
@@ -83,8 +82,7 @@ function checksum(data) {
83
82
  //#region src/ascii.ts
84
83
  /**
85
84
  * ASCII-only character helpers. `String.prototype.toLowerCase`/`toUpperCase` are Unicode-aware
86
- * (e.g. `"\u212A"` folds to `"k"`); the UR wire format folds ASCII letters only, like Rust
87
- * `to_ascii_lowercase`/`to_ascii_uppercase`.
85
+ * (e.g. `"\u212A"` folds to `"k"`); the UR wire format folds ASCII letters only.
88
86
  */
89
87
  /** True iff every code point of `text` is `<= 0x7F`. */
90
88
  function isAscii(text) {
@@ -998,7 +996,7 @@ function at(list, i) {
998
996
  if (v === void 0) throw new Error("unreachable: index out of range");
999
997
  return v;
1000
998
  }
1001
- /** Walker's alias method with reverse-index ordered partition (ur-rs / bcur). */
999
+ /** Walker's alias method with reverse-index ordered partition. */
1002
1000
  var Sampler = class {
1003
1001
  #aliases;
1004
1002
  #probs;
@@ -1062,7 +1060,7 @@ function scaledInt(d, low, high) {
1062
1060
  const span = high - low + 1;
1063
1061
  return Math.min(Math.floor(d * span), span - 1) + low;
1064
1062
  }
1065
- /** Xoshiro256** with SHA-256 seeding matching URKit / ur-rs / bcur. */
1063
+ /** Xoshiro256** with SHA-256 seeding. */
1066
1064
  var Xoshiro256 = class Xoshiro256 {
1067
1065
  s0;
1068
1066
  s1;
@@ -1184,16 +1182,16 @@ var FragmentChooser = class {
1184
1182
  //#endregion
1185
1183
  //#region src/fountain/limits.ts
1186
1184
  /**
1187
- * Production default; same integers as bcur.
1185
+ * Production default (1 MiB message, 2000 fragments, 8192-byte fragments and URIs), frozen.
1188
1186
  *
1189
1187
  * Hosts that need another budget pass `new UrDecoder({ limits })`.
1190
1188
  */
1191
- const DEFAULT_LIMITS = {
1189
+ const DEFAULT_LIMITS = Object.freeze({
1192
1190
  maxMessageLength: 1048576,
1193
1191
  maxFragmentCount: 2e3,
1194
1192
  maxFragmentLength: 8192,
1195
1193
  maxUriLength: 8192
1196
- };
1194
+ });
1197
1195
  function mergeLimits(partial) {
1198
1196
  return {
1199
1197
  ...DEFAULT_LIMITS,
@@ -1483,7 +1481,7 @@ function partition(data, fragLen) {
1483
1481
  /**
1484
1482
  * Fountain encoder. An infinite iterator: produces parts with sequence `firstSequence + 1`, `+2`, …
1485
1483
  * and ends after `0xFFFFFFFF` (UR-ADR-028). For `K == 1` it keeps producing identical parts with
1486
- * rising sequences.
1484
+ * rising sequences. Message problems throw `UrError`; invalid options throw `RangeError`.
1487
1485
  */
1488
1486
  var FountainEncoder = class {
1489
1487
  #parts;
@@ -1498,7 +1496,8 @@ var FountainEncoder = class {
1498
1496
  const { maxFragmentLength, minFragmentLength = DEFAULT_MIN_FRAGMENT_LENGTH, firstSequence = 0 } = options;
1499
1497
  if (message.length === 0) fail("EmptyMessage");
1500
1498
  if (message.length > MAX_U32$1) fail("MessageTooLong");
1501
- if (!Number.isSafeInteger(maxFragmentLength) || maxFragmentLength < 1 || !Number.isSafeInteger(minFragmentLength) || minFragmentLength < 1 || minFragmentLength > maxFragmentLength) fail("InvalidFragmentLength");
1499
+ if (!Number.isSafeInteger(maxFragmentLength) || maxFragmentLength < 1) throw new RangeError("maxFragmentLength must be a positive integer");
1500
+ if (!Number.isSafeInteger(minFragmentLength) || minFragmentLength < 1 || minFragmentLength > maxFragmentLength) throw new RangeError("minFragmentLength must be a positive integer at most maxFragmentLength");
1502
1501
  if (!Number.isSafeInteger(firstSequence) || firstSequence < 0 || firstSequence > MAX_U32$1) throw new RangeError("firstSequence must be an integer in 0..=0xFFFFFFFF");
1503
1502
  const fragLen = fragmentLength(message.length, maxFragmentLength, minFragmentLength);
1504
1503
  const fragments = partition(message, fragLen);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@qntx/ur",
3
- "version": "2.1.0",
3
+ "version": "3.0.0",
4
4
  "description": "Uniform Resources (UR) for TypeScript: Bytewords, fountain codes, multi-part UR, typed dCBOR, and BCR-2020-006 registry types.",
5
5
  "keywords": [
6
6
  "blockchain-commons",