streamseed 0.0.0-stage → 0.2.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 +661 -0
- package/README.md +117 -2
- package/dist/control/control.d.ts +89 -0
- package/dist/control/control.js +396 -0
- package/dist/index.d.ts +19 -0
- package/dist/index.js +15 -0
- package/dist/internal/abort.d.ts +8 -0
- package/dist/internal/abort.js +52 -0
- package/dist/internal/cbor-codec.d.ts +25 -0
- package/dist/internal/cbor-codec.js +134 -0
- package/dist/internal/ed25519.d.ts +15 -0
- package/dist/internal/ed25519.js +55 -0
- package/dist/internal/secp256k1.d.ts +3 -0
- package/dist/internal/secp256k1.js +15 -0
- package/dist/manifest/cbor.d.ts +54 -0
- package/dist/manifest/cbor.js +306 -0
- package/dist/manifest/codec.d.ts +6 -0
- package/dist/manifest/codec.js +360 -0
- package/dist/manifest/constants.d.ts +2 -0
- package/dist/manifest/constants.js +2 -0
- package/dist/manifest/errors.d.ts +20 -0
- package/dist/manifest/errors.js +23 -0
- package/dist/manifest/index.d.ts +6 -0
- package/dist/manifest/index.js +6 -0
- package/dist/manifest/language.d.ts +4 -0
- package/dist/manifest/language.js +26 -0
- package/dist/manifest/types.d.ts +73 -0
- package/dist/manifest/types.js +2 -0
- package/dist/node/codec.d.ts +23 -0
- package/dist/node/codec.js +231 -0
- package/dist/node/document.d.ts +10 -0
- package/dist/node/document.js +123 -0
- package/dist/node/media.d.ts +6 -0
- package/dist/node/media.js +69 -0
- package/dist/node/sequence.d.ts +44 -0
- package/dist/node/sequence.js +137 -0
- package/dist/node/types.d.ts +93 -0
- package/dist/node/types.js +105 -0
- package/dist/program/codec.d.ts +10 -0
- package/dist/program/codec.js +165 -0
- package/dist/program/resolver.d.ts +25 -0
- package/dist/program/resolver.js +189 -0
- package/dist/program/types.d.ts +61 -0
- package/dist/program/types.js +90 -0
- package/dist/protocol/constants.d.ts +33 -0
- package/dist/protocol/constants.js +32 -0
- package/dist/protocol/errors.d.ts +46 -0
- package/dist/protocol/errors.js +57 -0
- package/dist/protocol/hash.d.ts +14 -0
- package/dist/protocol/hash.js +42 -0
- package/dist/protocol/ids.d.ts +60 -0
- package/dist/protocol/ids.js +139 -0
- package/dist/wire/artifact.d.ts +28 -0
- package/dist/wire/artifact.js +74 -0
- package/dist/wire/codec.d.ts +12 -0
- package/dist/wire/codec.js +42 -0
- package/package.json +92 -3
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { KIND_DATA_NODE, KIND_END_NODE, KIND_PROGRAM_INFO, MAX_NODE_OBJECT_SIZE, WIRE_VERSION } from "../protocol/constants.js";
|
|
2
|
+
import { ERROR_CODES, streamSeedError } from "../protocol/errors.js";
|
|
3
|
+
import { copyBytes } from "../protocol/ids.js";
|
|
4
|
+
import { CBORDecoder } from "../internal/cbor-codec.js";
|
|
5
|
+
import { decodeNode } from "../node/codec.js";
|
|
6
|
+
import { decodeProgramObject } from "../program/codec.js";
|
|
7
|
+
import { createArtifact } from "./artifact.js";
|
|
8
|
+
/** 读取 version/kind 并路由到唯一 typed decoder。 */
|
|
9
|
+
export async function parseArtifact(data) {
|
|
10
|
+
if (data.length > MAX_NODE_OBJECT_SIZE)
|
|
11
|
+
throw streamSeedError(ERROR_CODES.FIELD_TOO_LARGE, "wire object exceeds V1 limit");
|
|
12
|
+
const snapshot = copyBytes(data);
|
|
13
|
+
const { version, kind } = readVersionKind(snapshot);
|
|
14
|
+
if (version !== WIRE_VERSION)
|
|
15
|
+
throw streamSeedError(ERROR_CODES.UNSUPPORTED_VERSION, "unsupported wire version");
|
|
16
|
+
let value;
|
|
17
|
+
if (kind === KIND_PROGRAM_INFO)
|
|
18
|
+
value = decodeProgramObject(snapshot);
|
|
19
|
+
else if (kind === KIND_DATA_NODE || kind === KIND_END_NODE)
|
|
20
|
+
value = await decodeNode(snapshot);
|
|
21
|
+
else
|
|
22
|
+
throw streamSeedError(ERROR_CODES.UNSUPPORTED_KIND, "unsupported wire kind");
|
|
23
|
+
return createArtifact(version, kind, snapshot, value);
|
|
24
|
+
}
|
|
25
|
+
/** 顶层解析并额外要求 expectedKind。 */
|
|
26
|
+
export async function parseArtifactAs(data, expectedKind) {
|
|
27
|
+
const artifact = await parseArtifact(data);
|
|
28
|
+
if (artifact.kind !== expectedKind)
|
|
29
|
+
throw streamSeedError(ERROR_CODES.UNSUPPORTED_KIND, "artifact kind does not match expected kind");
|
|
30
|
+
return artifact;
|
|
31
|
+
}
|
|
32
|
+
/** 只读取顶层前缀,不宣称对象已经完整解析或认证。 */
|
|
33
|
+
export function readVersionKind(data) {
|
|
34
|
+
const input = new CBORDecoder(data, BigInt(MAX_NODE_OBJECT_SIZE));
|
|
35
|
+
const length = input.array();
|
|
36
|
+
if (length < 2)
|
|
37
|
+
throw streamSeedError(ERROR_CODES.INVALID_LENGTH, "top-level array must contain version and kind");
|
|
38
|
+
const version = Number(input.uint());
|
|
39
|
+
const kind = Number(input.uint());
|
|
40
|
+
return { version, kind: kind };
|
|
41
|
+
}
|
|
42
|
+
//# sourceMappingURL=codec.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,95 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "streamseed",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"description": "StreamSeed V1 publisher-authenticated headerless sequential media-block stream SDK",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.js",
|
|
7
|
+
"module": "./dist/index.js",
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"import": "./dist/index.js",
|
|
13
|
+
"default": "./dist/index.js"
|
|
14
|
+
},
|
|
15
|
+
"./manifest": {
|
|
16
|
+
"types": "./dist/manifest/index.d.ts",
|
|
17
|
+
"import": "./dist/manifest/index.js",
|
|
18
|
+
"default": "./dist/manifest/index.js"
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
"files": [
|
|
22
|
+
"dist/index.js",
|
|
23
|
+
"dist/index.d.ts",
|
|
24
|
+
"dist/manifest/index.js",
|
|
25
|
+
"dist/manifest/index.d.ts",
|
|
26
|
+
"dist/manifest/constants.js",
|
|
27
|
+
"dist/manifest/constants.d.ts",
|
|
28
|
+
"dist/manifest/errors.js",
|
|
29
|
+
"dist/manifest/errors.d.ts",
|
|
30
|
+
"dist/manifest/types.js",
|
|
31
|
+
"dist/manifest/types.d.ts",
|
|
32
|
+
"dist/manifest/language.js",
|
|
33
|
+
"dist/manifest/language.d.ts",
|
|
34
|
+
"dist/manifest/cbor.js",
|
|
35
|
+
"dist/manifest/cbor.d.ts",
|
|
36
|
+
"dist/manifest/codec.js",
|
|
37
|
+
"dist/manifest/codec.d.ts",
|
|
38
|
+
"dist/internal/cbor-codec.js",
|
|
39
|
+
"dist/internal/cbor-codec.d.ts",
|
|
40
|
+
"dist/internal/ed25519.js",
|
|
41
|
+
"dist/internal/ed25519.d.ts",
|
|
42
|
+
"dist/internal/abort.js",
|
|
43
|
+
"dist/internal/abort.d.ts",
|
|
44
|
+
"dist/internal/secp256k1.js",
|
|
45
|
+
"dist/internal/secp256k1.d.ts",
|
|
46
|
+
"dist/node/codec.js",
|
|
47
|
+
"dist/node/codec.d.ts",
|
|
48
|
+
"dist/node/document.js",
|
|
49
|
+
"dist/node/document.d.ts",
|
|
50
|
+
"dist/node/media.js",
|
|
51
|
+
"dist/node/media.d.ts",
|
|
52
|
+
"dist/node/sequence.js",
|
|
53
|
+
"dist/node/sequence.d.ts",
|
|
54
|
+
"dist/node/types.js",
|
|
55
|
+
"dist/node/types.d.ts",
|
|
56
|
+
"dist/control/control.js",
|
|
57
|
+
"dist/control/control.d.ts",
|
|
58
|
+
"dist/program/codec.js",
|
|
59
|
+
"dist/program/codec.d.ts",
|
|
60
|
+
"dist/program/resolver.js",
|
|
61
|
+
"dist/program/resolver.d.ts",
|
|
62
|
+
"dist/program/types.js",
|
|
63
|
+
"dist/program/types.d.ts",
|
|
64
|
+
"dist/protocol/constants.js",
|
|
65
|
+
"dist/protocol/constants.d.ts",
|
|
66
|
+
"dist/protocol/errors.js",
|
|
67
|
+
"dist/protocol/errors.d.ts",
|
|
68
|
+
"dist/protocol/hash.js",
|
|
69
|
+
"dist/protocol/hash.d.ts",
|
|
70
|
+
"dist/protocol/ids.js",
|
|
71
|
+
"dist/protocol/ids.d.ts",
|
|
72
|
+
"dist/wire/artifact.js",
|
|
73
|
+
"dist/wire/artifact.d.ts",
|
|
74
|
+
"dist/wire/codec.js",
|
|
75
|
+
"dist/wire/codec.d.ts",
|
|
76
|
+
"README.md",
|
|
77
|
+
"LICENSE"
|
|
78
|
+
],
|
|
79
|
+
"engines": {
|
|
80
|
+
"node": ">=20"
|
|
81
|
+
},
|
|
82
|
+
"license": "AGPL-3.0-only",
|
|
83
|
+
"dependencies": {
|
|
84
|
+
"@noble/curves": "2.4.0",
|
|
85
|
+
"@noble/hashes": "2.4.0",
|
|
86
|
+
"masterseed": "1.1.0"
|
|
87
|
+
},
|
|
88
|
+
"devDependencies": {
|
|
89
|
+
"typescript": "^5.7.3"
|
|
90
|
+
},
|
|
91
|
+
"scripts": {
|
|
92
|
+
"build": "tsc -p tsconfig.json",
|
|
93
|
+
"pack:check": "pnpm pack --dry-run"
|
|
94
|
+
}
|
|
6
95
|
}
|