@qntx/ur 1.8.0 → 2.1.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/LICENSE-APACHE +201 -0
- package/README.md +7 -6
- package/dist/index-CcMfgay6.d.mts +54 -0
- package/dist/index-DTjNCWBI.d.mts +228 -0
- package/dist/index.d.mts +44 -163
- package/dist/index.mjs +2 -2
- package/dist/registry.d.mts +92 -33
- package/dist/registry.mjs +443 -93
- package/dist/typed-D-SyraAj.mjs +124 -0
- package/dist/typed.d.mts +3 -3
- package/dist/typed.mjs +3 -3
- package/dist/ur-7Ge3roVh.mjs +1993 -0
- package/package.json +22 -15
- package/dist/index-BeG2XIr5.d.mts +0 -59
- package/dist/rolldown-runtime-D7D4PA-g.mjs +0 -13
- package/dist/type-CZ0CIHJk.d.mts +0 -54
- package/dist/typed-BmHx2GWT.mjs +0 -150
- package/dist/ur-BUUcXyia.mjs +0 -1577
- /package/{LICENSE → LICENSE-MIT} +0 -0
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@qntx/ur",
|
|
3
|
-
"version": "1.
|
|
4
|
-
"description": "Uniform Resources (UR)
|
|
3
|
+
"version": "2.1.0",
|
|
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",
|
|
7
7
|
"bytewords",
|
|
@@ -10,19 +10,21 @@
|
|
|
10
10
|
"uniform-resources",
|
|
11
11
|
"ur"
|
|
12
12
|
],
|
|
13
|
-
"homepage": "https://github.com/qntx/ur
|
|
13
|
+
"homepage": "https://github.com/qntx/ur#readme",
|
|
14
14
|
"bugs": {
|
|
15
|
-
"url": "https://github.com/qntx/ur
|
|
15
|
+
"url": "https://github.com/qntx/ur/issues"
|
|
16
16
|
},
|
|
17
|
-
"license": "MIT",
|
|
17
|
+
"license": "MIT OR Apache-2.0",
|
|
18
18
|
"author": "QuantX <x@qntx.org>",
|
|
19
19
|
"repository": {
|
|
20
20
|
"type": "git",
|
|
21
|
-
"url": "git+https://github.com/qntx/ur.
|
|
21
|
+
"url": "git+https://github.com/qntx/ur.git",
|
|
22
22
|
"directory": "packages/ur"
|
|
23
23
|
},
|
|
24
24
|
"files": [
|
|
25
|
-
"dist"
|
|
25
|
+
"dist",
|
|
26
|
+
"LICENSE-MIT",
|
|
27
|
+
"LICENSE-APACHE"
|
|
26
28
|
],
|
|
27
29
|
"type": "module",
|
|
28
30
|
"sideEffects": false,
|
|
@@ -51,18 +53,23 @@
|
|
|
51
53
|
"build": "vp pack",
|
|
52
54
|
"dev": "vp pack --watch",
|
|
53
55
|
"test": "vp test",
|
|
54
|
-
"
|
|
56
|
+
"typecheck": "tsc --noEmit && tsc --noEmit -p tsconfig.src.json",
|
|
57
|
+
"check:pkg": "vp pack && publint && attw --pack . --profile esm-only",
|
|
58
|
+
"smoke:hermes": "bun scripts/hermes-smoke.ts",
|
|
59
|
+
"prepublishOnly": "vp run build",
|
|
60
|
+
"bench": "BENCH=1 vp test bench/decoder.bench.ts"
|
|
55
61
|
},
|
|
56
62
|
"dependencies": {
|
|
57
63
|
"@noble/hashes": "^2.4.0"
|
|
58
64
|
},
|
|
59
65
|
"devDependencies": {
|
|
66
|
+
"@arethetypeswrong/cli": "0.18.5",
|
|
60
67
|
"@blockchaincommons/dcbor": "1.0.0-beta.3",
|
|
61
|
-
"@qntx/tsconfig": "
|
|
62
|
-
"@types/node": "
|
|
63
|
-
"
|
|
64
|
-
"typescript": "
|
|
65
|
-
"vite-plus": "
|
|
68
|
+
"@qntx/tsconfig": "1.0.1",
|
|
69
|
+
"@types/node": "26.6.3",
|
|
70
|
+
"publint": "0.3.24",
|
|
71
|
+
"typescript": "7.0.2",
|
|
72
|
+
"vite-plus": "1.0.0"
|
|
66
73
|
},
|
|
67
74
|
"peerDependencies": {
|
|
68
75
|
"@blockchaincommons/dcbor": "1.0.0-beta.3"
|
|
@@ -75,11 +82,11 @@
|
|
|
75
82
|
"devEngines": {
|
|
76
83
|
"packageManager": {
|
|
77
84
|
"name": "bun",
|
|
78
|
-
"version": "1.
|
|
85
|
+
"version": "1.4.0",
|
|
79
86
|
"onFail": "ignore"
|
|
80
87
|
}
|
|
81
88
|
},
|
|
82
89
|
"engines": {
|
|
83
|
-
"node": ">=
|
|
90
|
+
"node": ">=20.19.0"
|
|
84
91
|
}
|
|
85
92
|
}
|
|
@@ -1,59 +0,0 @@
|
|
|
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 };
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
//#region \0rolldown/runtime.js
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __exportAll = (all, no_symbols) => {
|
|
4
|
-
let target = {};
|
|
5
|
-
for (var name in all) __defProp(target, name, {
|
|
6
|
-
get: all[name],
|
|
7
|
-
enumerable: true
|
|
8
|
-
});
|
|
9
|
-
if (!no_symbols) __defProp(target, Symbol.toStringTag, { value: "Module" });
|
|
10
|
-
return target;
|
|
11
|
-
};
|
|
12
|
-
//#endregion
|
|
13
|
-
export { __exportAll as t };
|
package/dist/type-CZ0CIHJk.d.mts
DELETED
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
//#region src/error.d.ts
|
|
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" | "CborDecode" | "CborType";
|
|
4
|
-
/** Structured error thrown by the UR stack. */
|
|
5
|
-
declare class UrError extends Error {
|
|
6
|
-
readonly code: UrErrorCode;
|
|
7
|
-
readonly expected?: string | undefined;
|
|
8
|
-
readonly found?: string | undefined;
|
|
9
|
-
readonly limit?: string | undefined;
|
|
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
|
|
27
|
-
//#region src/fountain/limits.d.ts
|
|
28
|
-
/** Hard limits for adversarial multi-part streams. */
|
|
29
|
-
type DecoderLimits = {
|
|
30
|
-
maxMessageLength: number;
|
|
31
|
-
maxFragmentCount: number;
|
|
32
|
-
maxFragmentDataLength: number;
|
|
33
|
-
maxBufferParts: number;
|
|
34
|
-
maxReceivedParts: number;
|
|
35
|
-
maxUriLen: number;
|
|
36
|
-
};
|
|
37
|
-
/**
|
|
38
|
-
* Production default; same integers as bcur 1.0.
|
|
39
|
-
*
|
|
40
|
-
* Hosts that need another budget pass `new Decoder({ limits })`.
|
|
41
|
-
*/
|
|
42
|
-
declare const DEFAULT_LIMITS: DecoderLimits;
|
|
43
|
-
//#endregion
|
|
44
|
-
//#region src/ur/type.d.ts
|
|
45
|
-
/** Validated UR type token (stored lowercase, `[a-z0-9-]+`). */
|
|
46
|
-
declare class UrType {
|
|
47
|
-
readonly value: string;
|
|
48
|
-
private constructor();
|
|
49
|
-
static parse(s: string): UrType;
|
|
50
|
-
static bytes(): UrType;
|
|
51
|
-
equals(other: UrType): boolean;
|
|
52
|
-
}
|
|
53
|
-
//#endregion
|
|
54
|
-
export { UrError as a, DecoderPoison as i, DEFAULT_LIMITS as n, UrErrorCode as o, DecoderLimits as r, failPoison as s, UrType as t };
|
package/dist/typed-BmHx2GWT.mjs
DELETED
|
@@ -1,150 +0,0 @@
|
|
|
1
|
-
import { C as fail, a as decodeWithType, d as UrType, n as Encoder, o as encode, s as toQrString, t as Decoder, w as failPoison } from "./ur-BUUcXyia.mjs";
|
|
2
|
-
import { CborError, cbor, decodeCbor, encodeCbor } from "@blockchaincommons/dcbor";
|
|
3
|
-
//#region src/typed/ur.ts
|
|
4
|
-
function mapCborDecode(run) {
|
|
5
|
-
try {
|
|
6
|
-
return run();
|
|
7
|
-
} catch (error) {
|
|
8
|
-
if (CborError.isCborError(error)) fail("CborDecode", { cause: error });
|
|
9
|
-
throw error;
|
|
10
|
-
}
|
|
11
|
-
}
|
|
12
|
-
function mapCborType(run) {
|
|
13
|
-
try {
|
|
14
|
-
return run();
|
|
15
|
-
} catch (error) {
|
|
16
|
-
if (CborError.isCborError(error)) fail("CborType", { cause: error });
|
|
17
|
-
throw error;
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
function parseType(type) {
|
|
21
|
-
return typeof type === "string" ? UrType.parse(type) : type;
|
|
22
|
-
}
|
|
23
|
-
/** Uniform Resource whose payload is deterministic CBOR. */
|
|
24
|
-
var Ur = class Ur {
|
|
25
|
-
type;
|
|
26
|
-
cbor;
|
|
27
|
-
constructor(type, cborValue) {
|
|
28
|
-
this.type = type;
|
|
29
|
-
this.cbor = cborValue;
|
|
30
|
-
}
|
|
31
|
-
static create(type, input) {
|
|
32
|
-
const prepared = input instanceof Uint8Array ? new Uint8Array(input) : input;
|
|
33
|
-
return new Ur(parseType(type), mapCborType(() => cbor(prepared)));
|
|
34
|
-
}
|
|
35
|
-
/** Wrap already-encoded dCBOR bytes. Used by fromUrString. */
|
|
36
|
-
static fromCborData(type, data) {
|
|
37
|
-
const bytes = new Uint8Array(data);
|
|
38
|
-
const value = mapCborDecode(() => decodeCbor(bytes));
|
|
39
|
-
return new Ur(parseType(type), value);
|
|
40
|
-
}
|
|
41
|
-
static fromUrString(uri) {
|
|
42
|
-
const { type, kind, payload } = decodeWithType(uri);
|
|
43
|
-
if (kind !== "single") fail("NotSinglePart");
|
|
44
|
-
return Ur.fromCborData(type, payload);
|
|
45
|
-
}
|
|
46
|
-
string() {
|
|
47
|
-
const bytes = mapCborType(() => encodeCbor(this.cbor));
|
|
48
|
-
return encode(bytes, this.type);
|
|
49
|
-
}
|
|
50
|
-
qrString() {
|
|
51
|
-
return toQrString(this.string());
|
|
52
|
-
}
|
|
53
|
-
checkType(expected) {
|
|
54
|
-
const want = parseType(expected);
|
|
55
|
-
if (!this.type.equals(want)) fail("UnexpectedType", {
|
|
56
|
-
expected: want.value,
|
|
57
|
-
found: this.type.value
|
|
58
|
-
});
|
|
59
|
-
}
|
|
60
|
-
};
|
|
61
|
-
//#endregion
|
|
62
|
-
//#region src/typed/codec.ts
|
|
63
|
-
function firstTagUrType(tags) {
|
|
64
|
-
const name = tags[0]?.name;
|
|
65
|
-
if (name === void 0 || name === "") fail("InvalidType");
|
|
66
|
-
return UrType.parse(name);
|
|
67
|
-
}
|
|
68
|
-
function toUr(value, codec) {
|
|
69
|
-
const type = firstTagUrType(codec.tags);
|
|
70
|
-
const body = mapCborType(() => codec.untaggedCbor(value));
|
|
71
|
-
return Ur.create(type, body);
|
|
72
|
-
}
|
|
73
|
-
function fromUr(ur, codec) {
|
|
74
|
-
ur.checkType(firstTagUrType(codec.tags));
|
|
75
|
-
return mapCborType(() => codec.fromUntaggedCbor(ur.cbor));
|
|
76
|
-
}
|
|
77
|
-
function toUrString(value, codec) {
|
|
78
|
-
return toUr(value, codec).string();
|
|
79
|
-
}
|
|
80
|
-
function fromUrString(uri, codec) {
|
|
81
|
-
return fromUr(Ur.fromUrString(uri), codec);
|
|
82
|
-
}
|
|
83
|
-
//#endregion
|
|
84
|
-
//#region src/typed/multipart.ts
|
|
85
|
-
var MultipartEncoder = class MultipartEncoder {
|
|
86
|
-
#inner;
|
|
87
|
-
constructor(inner) {
|
|
88
|
-
this.#inner = inner;
|
|
89
|
-
}
|
|
90
|
-
static create(ur, maxFragmentLength) {
|
|
91
|
-
const bytes = mapCborType(() => encodeCbor(ur.cbor));
|
|
92
|
-
return new MultipartEncoder(Encoder.create(bytes, maxFragmentLength, ur.type));
|
|
93
|
-
}
|
|
94
|
-
nextPart() {
|
|
95
|
-
return this.#inner.nextPart();
|
|
96
|
-
}
|
|
97
|
-
get isSinglePart() {
|
|
98
|
-
return this.#inner.isSinglePart;
|
|
99
|
-
}
|
|
100
|
-
get fragmentCount() {
|
|
101
|
-
return this.#inner.fragmentCount;
|
|
102
|
-
}
|
|
103
|
-
get currentIndex() {
|
|
104
|
-
return this.#inner.currentIndex;
|
|
105
|
-
}
|
|
106
|
-
get complete() {
|
|
107
|
-
return this.#inner.complete;
|
|
108
|
-
}
|
|
109
|
-
};
|
|
110
|
-
var MultipartDecoder = class {
|
|
111
|
-
#inner;
|
|
112
|
-
constructor(options) {
|
|
113
|
-
this.#inner = new Decoder(options);
|
|
114
|
-
}
|
|
115
|
-
receive(uri) {
|
|
116
|
-
this.#inner.receive(uri);
|
|
117
|
-
}
|
|
118
|
-
get complete() {
|
|
119
|
-
return this.#inner.complete;
|
|
120
|
-
}
|
|
121
|
-
get fragmentCount() {
|
|
122
|
-
return this.#inner.fragmentCount;
|
|
123
|
-
}
|
|
124
|
-
resolvedFragmentCount() {
|
|
125
|
-
return this.#inner.resolvedFragmentCount();
|
|
126
|
-
}
|
|
127
|
-
get type() {
|
|
128
|
-
return this.#inner.type;
|
|
129
|
-
}
|
|
130
|
-
get isPoisoned() {
|
|
131
|
-
return this.#inner.isPoisoned;
|
|
132
|
-
}
|
|
133
|
-
get poisonState() {
|
|
134
|
-
return this.#inner.poisonState;
|
|
135
|
-
}
|
|
136
|
-
message() {
|
|
137
|
-
if (this.#inner.isPoisoned) {
|
|
138
|
-
const poison = this.#inner.poisonState;
|
|
139
|
-
if (poison === void 0) fail("DecoderState");
|
|
140
|
-
failPoison(poison);
|
|
141
|
-
}
|
|
142
|
-
const data = this.#inner.message();
|
|
143
|
-
if (data === void 0) return;
|
|
144
|
-
const { type } = this.#inner;
|
|
145
|
-
if (type === void 0) fail("DecoderState");
|
|
146
|
-
return Ur.fromCborData(type, data);
|
|
147
|
-
}
|
|
148
|
-
};
|
|
149
|
-
//#endregion
|
|
150
|
-
export { fromUrString as a, Ur as c, fromUr as i, MultipartEncoder as n, toUr as o, firstTagUrType as r, toUrString as s, MultipartDecoder as t };
|