@qntx/ur 1.0.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 +3 -17
- package/dist/index-BeG2XIr5.d.mts +59 -0
- package/dist/index.d.mts +29 -79
- package/dist/index.mjs +1 -1497
- package/dist/registry.d.mts +142 -0
- package/dist/registry.mjs +549 -0
- package/dist/type-CZ0CIHJk.d.mts +54 -0
- package/dist/typed-BmHx2GWT.mjs +150 -0
- package/dist/typed.d.mts +3 -0
- package/dist/typed.mjs +3 -0
- package/dist/ur-BUUcXyia.mjs +1577 -0
- package/package.json +32 -13
package/README.md
CHANGED
|
@@ -1,29 +1,15 @@
|
|
|
1
1
|
<!-- markdownlint-disable MD033 MD041 -->
|
|
2
2
|
|
|
3
|
-
# ur
|
|
3
|
+
# `@qntx/ur`
|
|
4
4
|
|
|
5
5
|
Uniform Resources (UR) for TypeScript.
|
|
6
6
|
|
|
7
|
-
Bytewords, fountain codes, and single- or multi-part UR strings. Transport-only
|
|
7
|
+
Bytewords, fountain codes, and single- or multi-part UR strings. Transport-only at the root; typed dCBOR is `@qntx/ur/typed`. Wire-compatible with [bcur](https://github.com/qntx/bcur).
|
|
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,42 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
/** Discriminated error codes for the UR transport stack. */
|
|
3
|
-
type UrErrorCode = "InvalidWord" | "InvalidBytewordsChecksum" | "InvalidBytewordsLength" | "NonAscii" | "EmptyMessage" | "EmptyPart" | "InvalidFragmentLen" | "InvalidSequence" | "InconsistentPart" | "InvalidPadding" | "InvalidMessageChecksum" | "InvalidPartCbor" | "DecoderState" | "SinglePartExhausted" | "ResourceLimit" | "InvalidScheme" | "TypeUnspecified" | "InvalidType" | "InvalidIndices" | "NotSinglePart" | "UnexpectedType";
|
|
4
|
-
/** Structured error thrown by the UR stack. */
|
|
5
|
-
declare class UrError extends Error {
|
|
6
|
-
readonly code: UrErrorCode;
|
|
7
|
-
readonly expected?: string;
|
|
8
|
-
readonly found?: string;
|
|
9
|
-
readonly limit?: string;
|
|
10
|
-
constructor(code: UrErrorCode, options?: {
|
|
11
|
-
expected?: string;
|
|
12
|
-
found?: string;
|
|
13
|
-
limit?: string;
|
|
14
|
-
cause?: unknown;
|
|
15
|
-
});
|
|
16
|
-
}
|
|
17
|
-
/** Fail-closed decoder poison reason. */
|
|
18
|
-
type DecoderPoison = {
|
|
19
|
-
code: "ResourceLimit";
|
|
20
|
-
limit: string;
|
|
21
|
-
} | {
|
|
22
|
-
code: "DecoderState";
|
|
23
|
-
};
|
|
24
|
-
/** Rethrows the stored poison as a {@link UrError}. */
|
|
25
|
-
declare function failPoison(p: DecoderPoison): never;
|
|
26
|
-
//#endregion
|
|
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";
|
|
27
2
|
//#region src/crc32.d.ts
|
|
28
|
-
/**
|
|
29
|
-
* CRC-32 ISO-HDLC (polynomial 0xedb88320), matching bcur / ur-rs.
|
|
30
|
-
*/
|
|
31
3
|
/** CRC-32 ISO-HDLC checksum of `data`. */
|
|
32
4
|
declare function checksum(data: Uint8Array): number;
|
|
33
5
|
//#endregion
|
|
34
6
|
//#region src/constants.d.ts
|
|
35
7
|
/** BCR-2020-012 bytewords tables. */
|
|
36
8
|
/** Four-letter bytewords (index = byte value). */
|
|
37
|
-
declare const WORDS:
|
|
9
|
+
declare const WORDS: ReadonlyArray<string>;
|
|
38
10
|
/** First+last letter of each byteword (UR minimal style). */
|
|
39
|
-
declare const MINIMALS:
|
|
11
|
+
declare const MINIMALS: ReadonlyArray<string>;
|
|
40
12
|
declare namespace index_d_exports {
|
|
41
13
|
export { MINIMALS, Style, WORDS, canonicalizeByteword, decode$1 as decode, encode$1 as encode, encodeRaw };
|
|
42
14
|
}
|
|
@@ -44,32 +16,16 @@ declare namespace index_d_exports {
|
|
|
44
16
|
type Style = "standard" | "uri" | "minimal";
|
|
45
17
|
/** Encode `data` with trailing CRC-32 as bytewords. Empty data is allowed. */
|
|
46
18
|
declare function encode$1(data: Uint8Array, style: Style): string;
|
|
47
|
-
/**
|
|
48
|
-
|
|
49
|
-
* Not for UR bodies — identifiers only.
|
|
50
|
-
*/
|
|
51
|
-
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;
|
|
52
21
|
/** Decode bytewords and verify CRC-32. Case-insensitive. */
|
|
53
22
|
declare function decode$1(encoded: string, style: Style): Uint8Array;
|
|
54
23
|
/** Canonicalize a 2–4 letter token to the full 4-letter lowercase byteword. */
|
|
55
|
-
declare function canonicalizeByteword(token: string): string | undefined;
|
|
56
|
-
//#endregion
|
|
57
|
-
//#region src/fountain/limits.d.ts
|
|
58
|
-
/** Hard limits for adversarial multi-part streams. */
|
|
59
|
-
interface DecoderLimits {
|
|
60
|
-
maxMessageLength: number;
|
|
61
|
-
maxFragmentCount: number;
|
|
62
|
-
maxFragmentDataLength: number;
|
|
63
|
-
maxBufferParts: number;
|
|
64
|
-
maxReceivedParts: number;
|
|
65
|
-
maxUriLen: number;
|
|
66
|
-
}
|
|
67
|
-
/** Production Default; same integers as bcur 1.0. Hosts that need another budget pass `new Decoder({ limits })`. */
|
|
68
|
-
declare const DEFAULT_LIMITS: DecoderLimits;
|
|
24
|
+
export declare function canonicalizeByteword(token: string): string | undefined;
|
|
69
25
|
//#endregion
|
|
70
26
|
//#region src/fountain/part.d.ts
|
|
71
27
|
/** A fountain part (wire metadata + fragment data). */
|
|
72
|
-
declare class Part {
|
|
28
|
+
export declare class Part {
|
|
73
29
|
readonly sequence: number;
|
|
74
30
|
readonly sequenceCount: number;
|
|
75
31
|
readonly messageLength: number;
|
|
@@ -86,16 +42,18 @@ declare class Part {
|
|
|
86
42
|
//#endregion
|
|
87
43
|
//#region src/fountain/decoder.d.ts
|
|
88
44
|
/** Fountain decoder with resource limits and fail-closed poison. */
|
|
89
|
-
declare class FountainDecoder {
|
|
45
|
+
export declare class FountainDecoder {
|
|
90
46
|
private readonly decoded;
|
|
91
47
|
private readonly received;
|
|
92
48
|
private readonly buffer;
|
|
49
|
+
private readonly bufferIndex;
|
|
93
50
|
private readonly queue;
|
|
94
51
|
private sequenceCount;
|
|
95
52
|
private messageLength;
|
|
96
53
|
private messageChecksum;
|
|
97
54
|
private fragmentLength;
|
|
98
55
|
private readonly limits;
|
|
56
|
+
private chooser;
|
|
99
57
|
private poisoned;
|
|
100
58
|
constructor(limits?: Partial<DecoderLimits>);
|
|
101
59
|
get maxFragmentDataLength(): number;
|
|
@@ -106,7 +64,8 @@ declare class FountainDecoder {
|
|
|
106
64
|
private escalate;
|
|
107
65
|
/**
|
|
108
66
|
* Receive a fountain part.
|
|
109
|
-
*
|
|
67
|
+
*
|
|
68
|
+
* @returns Whether the part was newly ingested.
|
|
110
69
|
*/
|
|
111
70
|
receive(part: Part): boolean;
|
|
112
71
|
private enqueueSimple;
|
|
@@ -124,11 +83,12 @@ declare class FountainDecoder {
|
|
|
124
83
|
//#endregion
|
|
125
84
|
//#region src/fountain/encoder.d.ts
|
|
126
85
|
/** Fountain encoder. */
|
|
127
|
-
declare class FountainEncoder {
|
|
86
|
+
export declare class FountainEncoder {
|
|
128
87
|
private readonly parts;
|
|
129
88
|
private readonly sequenceCount;
|
|
130
89
|
private readonly messageLength;
|
|
131
90
|
private readonly messageChecksum;
|
|
91
|
+
private readonly chooser;
|
|
132
92
|
private currentSequence;
|
|
133
93
|
private constructor();
|
|
134
94
|
static create(message: Uint8Array, maxFragmentLength: number): FountainEncoder;
|
|
@@ -138,19 +98,9 @@ declare class FountainEncoder {
|
|
|
138
98
|
nextPart(): Part;
|
|
139
99
|
}
|
|
140
100
|
//#endregion
|
|
141
|
-
//#region src/ur/type.d.ts
|
|
142
|
-
/** Validated UR type token (stored lowercase, `[a-z0-9-]+`). */
|
|
143
|
-
declare class UrType {
|
|
144
|
-
readonly value: string;
|
|
145
|
-
private constructor();
|
|
146
|
-
static parse(s: string): UrType;
|
|
147
|
-
static bytes(): UrType;
|
|
148
|
-
equals(other: UrType): boolean;
|
|
149
|
-
}
|
|
150
|
-
//#endregion
|
|
151
101
|
//#region src/ur/parse.d.ts
|
|
152
102
|
type Kind = "single" | "multi";
|
|
153
|
-
|
|
103
|
+
type ParsedUr = {
|
|
154
104
|
type: UrType;
|
|
155
105
|
kind: Kind;
|
|
156
106
|
indices?: {
|
|
@@ -158,37 +108,37 @@ interface ParsedUr {
|
|
|
158
108
|
count: number;
|
|
159
109
|
};
|
|
160
110
|
body: string;
|
|
161
|
-
}
|
|
111
|
+
};
|
|
162
112
|
/** Lowercase a UR string for case-insensitive QR transport. */
|
|
163
|
-
declare function normalizeUr(uri: string): string;
|
|
113
|
+
export declare function normalizeUr(uri: string): string;
|
|
164
114
|
/** Parse a UR (full-URI case fold). Does not decode bytewords. */
|
|
165
|
-
declare function parse(uri: string): ParsedUr;
|
|
115
|
+
export declare function parse(uri: string): ParsedUr;
|
|
166
116
|
/** Parse an already-lowercased (or body-normalized) UR. */
|
|
167
|
-
declare function parseNormalized(uri: string): ParsedUr;
|
|
117
|
+
export declare function parseNormalized(uri: string): ParsedUr;
|
|
168
118
|
//#endregion
|
|
169
119
|
//#region src/ur/index.d.ts
|
|
170
120
|
/** Encode a single-part UR. Empty data is allowed. */
|
|
171
|
-
declare function encode(data: Uint8Array, type: UrType): string;
|
|
121
|
+
export declare function encode(data: Uint8Array, type: UrType): string;
|
|
172
122
|
/**
|
|
173
|
-
* Decode payload from a single- or multi-part UR.
|
|
174
|
-
*
|
|
123
|
+
* Decode payload from a single- or multi-part UR. Multi-part returns the CBOR-encoded fountain part
|
|
124
|
+
* bytes, not the message.
|
|
175
125
|
*/
|
|
176
|
-
declare function decode(uri: string): {
|
|
126
|
+
export declare function decode(uri: string): {
|
|
177
127
|
kind: Kind;
|
|
178
128
|
payload: Uint8Array;
|
|
179
129
|
};
|
|
180
130
|
/** Like {@link decode} but retains the normalized type. */
|
|
181
|
-
declare function decodeWithType(uri: string): {
|
|
131
|
+
export declare function decodeWithType(uri: string): {
|
|
182
132
|
type: UrType;
|
|
183
133
|
kind: Kind;
|
|
184
134
|
payload: Uint8Array;
|
|
185
135
|
};
|
|
186
136
|
/** Decode a single-part UR payload. Multi-part URIs throw `NotSinglePart`. */
|
|
187
|
-
declare function decodeMessage(uri: string): Uint8Array;
|
|
137
|
+
export declare function decodeMessage(uri: string): Uint8Array;
|
|
188
138
|
/** Uppercase UR string for denser QR alphanumeric mode. */
|
|
189
|
-
declare function toQrString(uri: string): string;
|
|
139
|
+
export declare function toQrString(uri: string): string;
|
|
190
140
|
/** UR encoder. `K == 1` emits single-part; otherwise fountain. */
|
|
191
|
-
declare class Encoder {
|
|
141
|
+
export declare class Encoder {
|
|
192
142
|
private readonly fountain;
|
|
193
143
|
private readonly urType;
|
|
194
144
|
private readonly message;
|
|
@@ -203,7 +153,7 @@ declare class Encoder {
|
|
|
203
153
|
nextPart(): string;
|
|
204
154
|
}
|
|
205
155
|
/** UR decoder with type stickiness and URI limits. */
|
|
206
|
-
declare class Decoder {
|
|
156
|
+
export declare class Decoder {
|
|
207
157
|
private readonly fountain;
|
|
208
158
|
private readonly maxUriLen;
|
|
209
159
|
private readonly maxMessageLength;
|
|
@@ -229,4 +179,4 @@ declare class Decoder {
|
|
|
229
179
|
get isPoisoned(): boolean;
|
|
230
180
|
}
|
|
231
181
|
//#endregion
|
|
232
|
-
export { DEFAULT_LIMITS,
|
|
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 };
|