@emagjby/strata-js 0.3.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/dist/__tests__/decode.test.js +28 -0
- package/dist/__tests__/encode.vectors.test.js +46 -0
- package/dist/__tests__/hash.vectors.test.js +51 -0
- package/dist/__tests__/value.test.js +23 -0
- package/dist/__tests__/varint.test.js +37 -0
- package/dist/__tests__/vectors.enforcement.test.js +75 -0
- package/dist/__tests__/vectors.smoke.test.js +17 -0
- package/dist/cli.d.ts +3 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +127 -0
- package/dist/cli.js.map +1 -0
- package/dist/decode.d.ts +3 -0
- package/dist/decode.d.ts.map +1 -0
- package/dist/decode.js +140 -0
- package/dist/decode.js.map +1 -0
- package/dist/decode_error.d.ts +18 -0
- package/dist/decode_error.d.ts.map +1 -0
- package/dist/decode_error.js +10 -0
- package/dist/decode_error.js.map +1 -0
- package/dist/encode.d.ts +3 -0
- package/dist/encode.d.ts.map +1 -0
- package/dist/encode.js +88 -0
- package/dist/encode.js.map +1 -0
- package/dist/hash.d.ts +6 -0
- package/dist/hash.d.ts.map +1 -0
- package/dist/hash.js +21 -0
- package/dist/hash.js.map +1 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +10 -0
- package/dist/index.js.map +1 -0
- package/dist/lexer.d.ts +63 -0
- package/dist/lexer.d.ts.map +1 -0
- package/dist/lexer.js +298 -0
- package/dist/lexer.js.map +1 -0
- package/dist/parse_error.d.ts +17 -0
- package/dist/parse_error.d.ts.map +1 -0
- package/dist/parse_error.js +14 -0
- package/dist/parse_error.js.map +1 -0
- package/dist/parser.d.ts +16 -0
- package/dist/parser.d.ts.map +1 -0
- package/dist/parser.js +159 -0
- package/dist/parser.js.map +1 -0
- package/dist/value.d.ts +29 -0
- package/dist/value.d.ts.map +1 -0
- package/dist/value.js +2 -0
- package/dist/value.js.map +1 -0
- package/dist/value_factory.d.ts +11 -0
- package/dist/value_factory.d.ts.map +1 -0
- package/dist/value_factory.js +30 -0
- package/dist/value_factory.js.map +1 -0
- package/dist/varint.d.ts +11 -0
- package/dist/varint.d.ts.map +1 -0
- package/dist/varint.js +86 -0
- package/dist/varint.js.map +1 -0
- package/package.json +35 -0
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import test from "node:test";
|
|
2
|
+
import assert from "node:assert/strict";
|
|
3
|
+
import { decodeValue } from "../decode.js";
|
|
4
|
+
import { encodeValue } from "../encode.js";
|
|
5
|
+
import { V } from "../value_factory.js";
|
|
6
|
+
import { DecodeError } from "../decode_error.js";
|
|
7
|
+
test("decode simple int", () => {
|
|
8
|
+
const bytes = new Uint8Array([0x10, 0x01]);
|
|
9
|
+
const v = decodeValue(bytes);
|
|
10
|
+
assert.equal(v.kind, "int");
|
|
11
|
+
assert.equal(v.value, 1n);
|
|
12
|
+
});
|
|
13
|
+
test("encode -> decode roundtrip", () => {
|
|
14
|
+
const value = V.map([
|
|
15
|
+
["a", V.int(1n)],
|
|
16
|
+
["b", V.bool(true)],
|
|
17
|
+
["c", V.list([V.null(), V.string("hi")])],
|
|
18
|
+
]);
|
|
19
|
+
const encoded = encodeValue(value);
|
|
20
|
+
const decoded = decodeValue(encoded);
|
|
21
|
+
assert.deepEqual(decoded, value);
|
|
22
|
+
});
|
|
23
|
+
test("invalid tag throws DecodeError", () => {
|
|
24
|
+
const bytes = new Uint8Array([0xff]);
|
|
25
|
+
assert.throws(() => decodeValue(bytes), (err) => err instanceof DecodeError &&
|
|
26
|
+
err.kind.type === "InvalidTag" &&
|
|
27
|
+
err.offset === 0);
|
|
28
|
+
});
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import test from "node:test";
|
|
2
|
+
import assert from "node:assert/strict";
|
|
3
|
+
import { readFileSync } from "node:fs";
|
|
4
|
+
import { join } from "node:path";
|
|
5
|
+
import { encodeValue } from "../encode.js";
|
|
6
|
+
import { V } from "../value_factory.js";
|
|
7
|
+
const VECTORS_DIR = join(process.cwd(), "..", "vectors");
|
|
8
|
+
function readHex(path) {
|
|
9
|
+
const text = readFileSync(path, "utf-8").trim();
|
|
10
|
+
assert.equal(text.length % 2, 0, "Hex string must have even length");
|
|
11
|
+
const out = new Uint8Array(text.length / 2);
|
|
12
|
+
for (let i = 0; i < text.length; i += 2) {
|
|
13
|
+
out[i / 2] = Number.parseInt(text.slice(i, i + 2), 16);
|
|
14
|
+
}
|
|
15
|
+
return out;
|
|
16
|
+
}
|
|
17
|
+
test("encode matches v1/01-basic.scb.hex", () => {
|
|
18
|
+
const config = V.map([
|
|
19
|
+
["enabled", V.bool(true)],
|
|
20
|
+
["retries", V.int(3n)],
|
|
21
|
+
["name", V.string("strata")],
|
|
22
|
+
["empty", V.null()],
|
|
23
|
+
]);
|
|
24
|
+
const root = V.map([["config", config]]);
|
|
25
|
+
const expected = readHex(join(VECTORS_DIR, "v1", "01-basic.scb.hex"));
|
|
26
|
+
const actual = encodeValue(root);
|
|
27
|
+
assert.deepEqual([...actual], [...expected]);
|
|
28
|
+
});
|
|
29
|
+
test("encode matches v1/03-bigint-bytes.scb.hex", () => {
|
|
30
|
+
const avatar = new Uint8Array([
|
|
31
|
+
0x9f, 0x86, 0xd0, 0x81, 0x88, 0x4c, 0x7d, 0x65, 0x9a, 0x2f, 0xea, 0xa0,
|
|
32
|
+
0xc5, 0x5a, 0xd0, 0x15,
|
|
33
|
+
]);
|
|
34
|
+
const profile = V.map([
|
|
35
|
+
["id", V.int(9007199254740993n)],
|
|
36
|
+
["avatar_hash", V.bytes(avatar)],
|
|
37
|
+
[
|
|
38
|
+
"tags",
|
|
39
|
+
V.list([V.string("logistics"), V.string("state"), V.string("integrity")]),
|
|
40
|
+
],
|
|
41
|
+
]);
|
|
42
|
+
const root = V.map([["profile", profile]]);
|
|
43
|
+
const expected = readHex(join(VECTORS_DIR, "v1", "03-bigint-bytes.scb.hex"));
|
|
44
|
+
const actual = encodeValue(root);
|
|
45
|
+
assert.deepEqual([...actual], [...expected]);
|
|
46
|
+
});
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import test from "node:test";
|
|
2
|
+
import assert from "node:assert/strict";
|
|
3
|
+
import { readFileSync } from "node:fs";
|
|
4
|
+
import { join } from "node:path";
|
|
5
|
+
import { V } from "../value_factory.js";
|
|
6
|
+
import { hashValueHex } from "../hash.js";
|
|
7
|
+
const VECTORS_DIR = join(process.cwd(), "..", "vectors");
|
|
8
|
+
function readText(path) {
|
|
9
|
+
return readFileSync(path, "utf8").trim();
|
|
10
|
+
}
|
|
11
|
+
test("hash matches v1/01-basic.hash.hex", () => {
|
|
12
|
+
const config = V.map([
|
|
13
|
+
["enabled", V.bool(true)],
|
|
14
|
+
["retries", V.int(3n)],
|
|
15
|
+
["name", V.string("strata")],
|
|
16
|
+
["empty", V.null()],
|
|
17
|
+
]);
|
|
18
|
+
const root = V.map([["config", config]]);
|
|
19
|
+
const expected = readText(join(VECTORS_DIR, "v1", "01-basic.hash.hex"));
|
|
20
|
+
const actual = hashValueHex(root);
|
|
21
|
+
assert.equal(actual, expected);
|
|
22
|
+
});
|
|
23
|
+
test("hash matches v1/02-map-order.hash.hex", () => {
|
|
24
|
+
const data = V.map([
|
|
25
|
+
["z", V.int(1n)],
|
|
26
|
+
["a", V.int(2n)],
|
|
27
|
+
["m", V.int(3n)],
|
|
28
|
+
]);
|
|
29
|
+
const root = V.map([["data", data]]);
|
|
30
|
+
const expected = readText(join(VECTORS_DIR, "v1", "02-map-order.hash.hex"));
|
|
31
|
+
const actual = hashValueHex(root);
|
|
32
|
+
assert.equal(actual, expected);
|
|
33
|
+
});
|
|
34
|
+
test("hash matches v1/03-bigint-bytes.hash.hex", () => {
|
|
35
|
+
const avatar = new Uint8Array([
|
|
36
|
+
0x9f, 0x86, 0xd0, 0x81, 0x88, 0x4c, 0x7d, 0x65, 0x9a, 0x2f, 0xea, 0xa0,
|
|
37
|
+
0xc5, 0x5a, 0xd0, 0x15,
|
|
38
|
+
]);
|
|
39
|
+
const profile = V.map([
|
|
40
|
+
["id", V.int(9007199254740993n)],
|
|
41
|
+
["avatar_hash", V.bytes(avatar)],
|
|
42
|
+
[
|
|
43
|
+
"tags",
|
|
44
|
+
V.list([V.string("logistics"), V.string("state"), V.string("integrity")]),
|
|
45
|
+
],
|
|
46
|
+
]);
|
|
47
|
+
const root = V.map([["profile", profile]]);
|
|
48
|
+
const expected = readText(join(VECTORS_DIR, "v1", "03-bigint-bytes.hash.hex"));
|
|
49
|
+
const actual = hashValueHex(root);
|
|
50
|
+
assert.equal(actual, expected);
|
|
51
|
+
});
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import test from "node:test";
|
|
2
|
+
import assert from "node:assert/strict";
|
|
3
|
+
import { V } from "../value_factory.js";
|
|
4
|
+
test("can represent all core value types", () => {
|
|
5
|
+
const v = V.map([
|
|
6
|
+
["null", V.null()],
|
|
7
|
+
["bool", V.bool(true)],
|
|
8
|
+
["int", V.int(42n)],
|
|
9
|
+
["string", V.string("strata")],
|
|
10
|
+
["bytes", V.bytes(new Uint8Array([0xde, 0xad]))],
|
|
11
|
+
["list", V.list([V.int(1n), V.int(2n), V.int(3n)])],
|
|
12
|
+
]);
|
|
13
|
+
assert.equal(v.kind, "map");
|
|
14
|
+
});
|
|
15
|
+
test("rejects number for int", () => {
|
|
16
|
+
// @ts-expect-error
|
|
17
|
+
assert.throws(() => V.int(42));
|
|
18
|
+
});
|
|
19
|
+
test("supports BigInt beyond JS safe integer range", () => {
|
|
20
|
+
const big = 9007199254740993n;
|
|
21
|
+
const v = V.int(big);
|
|
22
|
+
assert.equal(v.value, big);
|
|
23
|
+
});
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import test from "node:test";
|
|
2
|
+
import assert from "node:assert/strict";
|
|
3
|
+
import { encodeULEB128, decodeULEB128, encodeSLEB128, decodeSLEB128, } from "../varint.js";
|
|
4
|
+
test("ULEB128 basic values", () => {
|
|
5
|
+
assert.deepEqual(encodeULEB128(0n), Uint8Array.from([0x00]));
|
|
6
|
+
assert.deepEqual(encodeULEB128(1n), Uint8Array.from([0x01]));
|
|
7
|
+
assert.deepEqual(encodeULEB128(127n), Uint8Array.from([0x7f]));
|
|
8
|
+
assert.deepEqual(encodeULEB128(128n), Uint8Array.from([0x80, 0x01]));
|
|
9
|
+
});
|
|
10
|
+
test("ULEB128 round trip", () => {
|
|
11
|
+
const values = [0n, 1n, 127n, 128n, 1024n, 9007199254740993n];
|
|
12
|
+
for (const value of values) {
|
|
13
|
+
const encoded = encodeULEB128(value);
|
|
14
|
+
const decoded = decodeULEB128(encoded);
|
|
15
|
+
assert.equal(decoded.value, value);
|
|
16
|
+
assert.equal(decoded.nextOffset, encoded.length);
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
test("SLEB128 basic values", () => {
|
|
20
|
+
const values = [
|
|
21
|
+
0n,
|
|
22
|
+
1n,
|
|
23
|
+
-1n,
|
|
24
|
+
63n,
|
|
25
|
+
-64n,
|
|
26
|
+
127n,
|
|
27
|
+
-128n,
|
|
28
|
+
9007199254740993n,
|
|
29
|
+
-9007199254740993n,
|
|
30
|
+
];
|
|
31
|
+
for (const value of values) {
|
|
32
|
+
const encoded = encodeSLEB128(value);
|
|
33
|
+
const decoded = decodeSLEB128(encoded);
|
|
34
|
+
assert.equal(decoded.value, value);
|
|
35
|
+
assert.equal(decoded.nextOffset, encoded.length);
|
|
36
|
+
}
|
|
37
|
+
});
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import test from "node:test";
|
|
2
|
+
import assert from "node:assert/strict";
|
|
3
|
+
import { readFileSync } from "node:fs";
|
|
4
|
+
import { join } from "node:path";
|
|
5
|
+
import { encodeValue } from "../encode.js";
|
|
6
|
+
import { decodeValue } from "../decode.js";
|
|
7
|
+
import { hashValueHex } from "../hash.js";
|
|
8
|
+
import { parse } from "../parser.js";
|
|
9
|
+
import { DecodeError } from "../decode_error.js";
|
|
10
|
+
const VECTORS_DIR = join(process.cwd(), "..", "vectors");
|
|
11
|
+
function readHex(path) {
|
|
12
|
+
const text = readFileSync(path, "utf8").trim();
|
|
13
|
+
assert.ok(text.length % 2 === 0, "Hex string must have even length");
|
|
14
|
+
const out = new Uint8Array(text.length / 2);
|
|
15
|
+
for (let i = 0; i < text.length; i += 2) {
|
|
16
|
+
out[i / 2] = Number.parseInt(text.slice(i, i + 2), 16);
|
|
17
|
+
}
|
|
18
|
+
return out;
|
|
19
|
+
}
|
|
20
|
+
function readText(path) {
|
|
21
|
+
return readFileSync(path, "utf8");
|
|
22
|
+
}
|
|
23
|
+
function readJson(path) {
|
|
24
|
+
return JSON.parse(readFileSync(path, "utf8"));
|
|
25
|
+
}
|
|
26
|
+
function runPositiveVector(relPath) {
|
|
27
|
+
const base = join(VECTORS_DIR, relPath);
|
|
28
|
+
const stPath = base + ".st";
|
|
29
|
+
const scbHexPath = base + ".scb.hex";
|
|
30
|
+
const hashHexPath = base + ".hash.hex";
|
|
31
|
+
const source = readText(stPath);
|
|
32
|
+
const parsedValue = parse(source);
|
|
33
|
+
const encoded = encodeValue(parsedValue);
|
|
34
|
+
const expectedScb = readHex(scbHexPath);
|
|
35
|
+
assert.deepEqual([...encoded], [...expectedScb], `SCB mismatch for vector ${relPath}`);
|
|
36
|
+
//hash
|
|
37
|
+
const actualHash = hashValueHex(parsedValue);
|
|
38
|
+
const expectedHash = readText(hashHexPath).trim();
|
|
39
|
+
assert.equal(actualHash, expectedHash, `Hash mismatch for vector ${relPath}`);
|
|
40
|
+
}
|
|
41
|
+
function runNegativeDecodeVector(relPath) {
|
|
42
|
+
const base = join(VECTORS_DIR, relPath);
|
|
43
|
+
const hexPath = base + ".hex";
|
|
44
|
+
const errorPath = base + ".error.json";
|
|
45
|
+
const bytes = readHex(hexPath);
|
|
46
|
+
const expectedError = readJson(errorPath);
|
|
47
|
+
let thrown;
|
|
48
|
+
try {
|
|
49
|
+
decodeValue(bytes);
|
|
50
|
+
}
|
|
51
|
+
catch (err) {
|
|
52
|
+
thrown = err;
|
|
53
|
+
}
|
|
54
|
+
assert.ok(thrown instanceof DecodeError, `Expected DecodeError for ${relPath}`);
|
|
55
|
+
const err = thrown;
|
|
56
|
+
if (expectedError.kind === "InvalidTag") {
|
|
57
|
+
assert.equal(err.kind.type, "InvalidTag");
|
|
58
|
+
}
|
|
59
|
+
else {
|
|
60
|
+
assert.equal(err.kind.type, expectedError.kind);
|
|
61
|
+
}
|
|
62
|
+
assert.equal(err.offset, expectedError.offset, `offset mismatch for ${relPath}`);
|
|
63
|
+
}
|
|
64
|
+
// v1
|
|
65
|
+
test("vector v1/01-basic", () => runPositiveVector("v1/01-basic"));
|
|
66
|
+
test("vector v1/02-map-order", () => runPositiveVector("v1/02-map-order"));
|
|
67
|
+
test("vector v1/03-bigint-bytes", () => runPositiveVector("v1/03-bigint-bytes"));
|
|
68
|
+
// v2
|
|
69
|
+
test("vector v2/01-decode-roundtrip", () => runPositiveVector("v2/01-decode-roundtrip"));
|
|
70
|
+
test("vector v2/02-noncanonical-map-order", () => runPositiveVector("v2/02-noncanonical-map-order"));
|
|
71
|
+
test("vector v2/03-nested-structure", () => runPositiveVector("v2/03-nested-structure"));
|
|
72
|
+
test("neg v2.1/01-invalid-tag", () => runNegativeDecodeVector("v2.1/neg-01-invalid-tag"));
|
|
73
|
+
test("neg v2.1/02-truncated-string", () => runNegativeDecodeVector("v2.1/neg-02-truncated-string"));
|
|
74
|
+
test("neg v2.1/03-varint-overflow", () => runNegativeDecodeVector("v2.1/neg-03-varint-overflow"));
|
|
75
|
+
test("neg v2.1/04-invalid-utf8", () => runNegativeDecodeVector("v2.1/neg-04-invalid-utf8"));
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import test from "node:test";
|
|
2
|
+
import assert from "node:assert/strict";
|
|
3
|
+
import { readFileSync, readdirSync } from "node:fs";
|
|
4
|
+
import { join } from "node:path";
|
|
5
|
+
const VECTORS_DIR = join(process.cwd(), "..", "vectors");
|
|
6
|
+
test("JS can see vectors directory", () => {
|
|
7
|
+
const entries = readdirSync(VECTORS_DIR);
|
|
8
|
+
assert.ok(entries.includes("v1"));
|
|
9
|
+
assert.ok(entries.includes("v2"));
|
|
10
|
+
assert.ok(entries.includes("v2.1"));
|
|
11
|
+
});
|
|
12
|
+
test("JS can read a known vector file", () => {
|
|
13
|
+
const path = join(VECTORS_DIR, "v1", "01-basic.st");
|
|
14
|
+
const content = readFileSync(path, "utf-8");
|
|
15
|
+
assert.ok(content.includes("config"));
|
|
16
|
+
assert.ok(content.includes("enabled"));
|
|
17
|
+
});
|
package/dist/cli.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":""}
|
package/dist/cli.js
ADDED
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import fs from "node:fs";
|
|
3
|
+
import process from "node:process";
|
|
4
|
+
import { parse } from "./parser.js";
|
|
5
|
+
import { encodeValue } from "./encode.js";
|
|
6
|
+
import { decodeValue } from "./decode.js";
|
|
7
|
+
import { hashBytes } from "./hash.js";
|
|
8
|
+
import { DecodeError } from "./decode_error.js";
|
|
9
|
+
import { ParseError } from "./parse_error.js";
|
|
10
|
+
function exitOk() {
|
|
11
|
+
process.exit(0);
|
|
12
|
+
}
|
|
13
|
+
function exitInvalid(msg) {
|
|
14
|
+
if (msg) {
|
|
15
|
+
console.error(msg);
|
|
16
|
+
}
|
|
17
|
+
process.exit(1);
|
|
18
|
+
}
|
|
19
|
+
function exitIo(err) {
|
|
20
|
+
if (err instanceof Error) {
|
|
21
|
+
console.error(err.message);
|
|
22
|
+
}
|
|
23
|
+
process.exit(2);
|
|
24
|
+
}
|
|
25
|
+
function exitInternal(err) {
|
|
26
|
+
console.error("internal error");
|
|
27
|
+
if (err instanceof Error) {
|
|
28
|
+
console.error(err.stack);
|
|
29
|
+
}
|
|
30
|
+
process.exit(100);
|
|
31
|
+
}
|
|
32
|
+
function hex(bytes) {
|
|
33
|
+
return Array.from(bytes, (b) => b.toString(16).padStart(2, "0")).join("");
|
|
34
|
+
}
|
|
35
|
+
function cmdCompile(input, output) {
|
|
36
|
+
const source = fs.readFileSync(input, "utf8");
|
|
37
|
+
const value = parse(source);
|
|
38
|
+
const encoded = encodeValue(value);
|
|
39
|
+
fs.writeFileSync(output, encoded);
|
|
40
|
+
}
|
|
41
|
+
function cmdDecode(input) {
|
|
42
|
+
const encoded = fs.readFileSync(input);
|
|
43
|
+
const value = decodeValue(encoded);
|
|
44
|
+
console.log(JSON.stringify(value, null, 2));
|
|
45
|
+
}
|
|
46
|
+
function cmdHash(input) {
|
|
47
|
+
let encoded;
|
|
48
|
+
if (input.endsWith(".st")) {
|
|
49
|
+
const source = fs.readFileSync(input, "utf8");
|
|
50
|
+
const value = parse(source);
|
|
51
|
+
encoded = encodeValue(value);
|
|
52
|
+
}
|
|
53
|
+
else {
|
|
54
|
+
encoded = fs.readFileSync(input);
|
|
55
|
+
}
|
|
56
|
+
const hashed = hashBytes(encoded);
|
|
57
|
+
console.log(hex(hashed));
|
|
58
|
+
}
|
|
59
|
+
function cmdFmt(input) {
|
|
60
|
+
const source = fs.readFileSync(input, "utf8");
|
|
61
|
+
const parsedValue = parse(source);
|
|
62
|
+
console.log(JSON.stringify(parsedValue, null, 2));
|
|
63
|
+
}
|
|
64
|
+
function main() {
|
|
65
|
+
const [, , cmd, ...args] = process.argv;
|
|
66
|
+
if (!cmd) {
|
|
67
|
+
exitInvalid("no command provided");
|
|
68
|
+
}
|
|
69
|
+
switch (cmd) {
|
|
70
|
+
case "compile": {
|
|
71
|
+
if (args.length !== 2) {
|
|
72
|
+
exitInvalid("usage: strata-js compile <input.st> <output.scb>");
|
|
73
|
+
}
|
|
74
|
+
cmdCompile(args[0], args[1]);
|
|
75
|
+
return exitOk();
|
|
76
|
+
}
|
|
77
|
+
case "decode": {
|
|
78
|
+
if (args.length !== 1) {
|
|
79
|
+
exitInvalid("usage: strata-js decode <input.scb>");
|
|
80
|
+
}
|
|
81
|
+
cmdDecode(args[0]);
|
|
82
|
+
return exitOk();
|
|
83
|
+
}
|
|
84
|
+
case "hash": {
|
|
85
|
+
if (args.length !== 1) {
|
|
86
|
+
exitInvalid("usage: strata-js hash <input.st|input.scb>");
|
|
87
|
+
}
|
|
88
|
+
cmdHash(args[0]);
|
|
89
|
+
return exitOk();
|
|
90
|
+
}
|
|
91
|
+
case "fmt": {
|
|
92
|
+
if (args.length !== 1) {
|
|
93
|
+
exitInvalid("usage: strata-js fmt <input.st>");
|
|
94
|
+
}
|
|
95
|
+
cmdFmt(args[0]);
|
|
96
|
+
return exitOk();
|
|
97
|
+
}
|
|
98
|
+
case "--help": {
|
|
99
|
+
console.log(`
|
|
100
|
+
Strata CLI (JavaScript)
|
|
101
|
+
|
|
102
|
+
Commands:
|
|
103
|
+
compile <input.st> <output.scb>
|
|
104
|
+
decode <input.scb>
|
|
105
|
+
hash <input.st|input.scb>
|
|
106
|
+
fmt <input.st>
|
|
107
|
+
`);
|
|
108
|
+
process.exit(0);
|
|
109
|
+
}
|
|
110
|
+
default:
|
|
111
|
+
exitInvalid(`unknown command: ${cmd}`);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
try {
|
|
115
|
+
main();
|
|
116
|
+
}
|
|
117
|
+
catch (err) {
|
|
118
|
+
if (err instanceof DecodeError || err instanceof ParseError) {
|
|
119
|
+
console.error("error: ", err.message);
|
|
120
|
+
process.exit(1);
|
|
121
|
+
}
|
|
122
|
+
if (err instanceof Error && "code" in err && err.code === "ENOENT") {
|
|
123
|
+
exitIo(err);
|
|
124
|
+
}
|
|
125
|
+
exitInternal(err);
|
|
126
|
+
}
|
|
127
|
+
//# sourceMappingURL=cli.js.map
|
package/dist/cli.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";AAEA,OAAO,EAAE,MA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AAI,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;gBACpB,WAAW,CAAC,iCAAiC,CAAC,CAAC;YACnD,CAAC;YACD,MAAM,CAAC,IAAI,CAAC,CAAC,CAAE,CAAC,CAAC;YACjB,OAAO,MAAM,EAAE,CAAC;QACpB,CAAC;QAED,KAAK,QAAQ,CAAC,CAAC,CAAC;YACZ,OAAO,CAAC,GAAG,CAAC;;;;;;;;aAQX,CAAC,CAAC;YACH,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QACpB,CAAC;QAED;YACI,WAAW,CAAC,oBAAoB,GAAG,EAAE,CAAC,CAAC;IAC/C,CAAC;AACL,CAAC;AAED,IAAI,CAAC;IACD,IAAI,EAAE,CAAC;AACX,CAAC;AAAC,OAAO,GAAG,EAAE,CAAC;IACX,IAAI,GAAG,YAAY,WAAW,IAAI,GAAG,YAAY,UAAU,EAAE,CAAC;QAC1D,OAAO,CAAC,KAAK,CAAC,SAAS,EAAE,GAAG,CAAC,OAAO,CAAC,CAAC;QACtC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IACpB,CAAC;IAED,IAAI,GAAG,YAAY,KAAK,IAAI,MAAM,IAAI,GAAG,IAAK,GAAW,CAAC,IAAI,KAAK,QAAQ,EAAE,CAAC;QAC1E,MAAM,CAAC,GAAG,CAAC,CAAC;IAChB,CAAC;IAED,YAAY,CAAC,GAAG,CAAC,CAAC;AACtB,CAAC"}
|
package/dist/decode.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"decode.d.ts","sourceRoot":"","sources":["../src/decode.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AA2JnC,wBAAgB,WAAW,CAAC,KAAK,EAAE,UAAU,GAAG,KAAK,CAYpD"}
|
package/dist/decode.js
ADDED
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import { V } from "./value_factory.js";
|
|
2
|
+
import { decodeULEB128, decodeSLEB128 } from "./varint.js";
|
|
3
|
+
import { DecodeError } from "./decode_error.js";
|
|
4
|
+
const td = new TextDecoder("utf-8", { fatal: true });
|
|
5
|
+
const TAG_NULL = 0x00;
|
|
6
|
+
const TAG_FALSE = 0x01;
|
|
7
|
+
const TAG_TRUE = 0x02;
|
|
8
|
+
const TAG_INT = 0x10;
|
|
9
|
+
const TAG_STRING = 0x20;
|
|
10
|
+
const TAG_BYTES = 0x21;
|
|
11
|
+
const TAG_LIST = 0x30;
|
|
12
|
+
const TAG_MAP = 0x40;
|
|
13
|
+
class Decoder {
|
|
14
|
+
input;
|
|
15
|
+
offset = 0;
|
|
16
|
+
constructor(input) {
|
|
17
|
+
this.input = input;
|
|
18
|
+
}
|
|
19
|
+
remaining() {
|
|
20
|
+
return this.input.length - this.offset;
|
|
21
|
+
}
|
|
22
|
+
readByte() {
|
|
23
|
+
if (this.offset >= this.input.length) {
|
|
24
|
+
throw new DecodeError({ type: "UnexpectedEOF" }, this.offset);
|
|
25
|
+
}
|
|
26
|
+
return this.input[this.offset++];
|
|
27
|
+
}
|
|
28
|
+
readSlice(len) {
|
|
29
|
+
if (this.remaining() < len) {
|
|
30
|
+
throw new DecodeError({ type: "UnexpectedEOF" }, this.offset);
|
|
31
|
+
}
|
|
32
|
+
const slice = this.input.subarray(this.offset, this.offset + len);
|
|
33
|
+
this.offset += len;
|
|
34
|
+
return slice;
|
|
35
|
+
}
|
|
36
|
+
decodeValue() {
|
|
37
|
+
const tagOffset = this.offset;
|
|
38
|
+
const tag = this.readByte();
|
|
39
|
+
const payloadOffset = this.offset;
|
|
40
|
+
switch (tag) {
|
|
41
|
+
case TAG_NULL:
|
|
42
|
+
return V.null();
|
|
43
|
+
case TAG_FALSE:
|
|
44
|
+
return V.bool(false);
|
|
45
|
+
case TAG_TRUE:
|
|
46
|
+
return V.bool(true);
|
|
47
|
+
case TAG_INT: {
|
|
48
|
+
try {
|
|
49
|
+
const { value, nextOffset } = decodeSLEB128(this.input, this.offset);
|
|
50
|
+
this.offset = nextOffset;
|
|
51
|
+
return V.int(value);
|
|
52
|
+
}
|
|
53
|
+
catch {
|
|
54
|
+
throw new DecodeError({ type: "InvalidVarint" }, payloadOffset);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
case TAG_STRING: {
|
|
58
|
+
let len;
|
|
59
|
+
try {
|
|
60
|
+
const result = decodeULEB128(this.input, this.offset);
|
|
61
|
+
len = result.value;
|
|
62
|
+
this.offset = result.nextOffset;
|
|
63
|
+
}
|
|
64
|
+
catch {
|
|
65
|
+
throw new DecodeError({ type: "InvalidVarint" }, payloadOffset);
|
|
66
|
+
}
|
|
67
|
+
const start = this.offset;
|
|
68
|
+
const bytes = this.readSlice(Number(len));
|
|
69
|
+
try {
|
|
70
|
+
const str = td.decode(bytes);
|
|
71
|
+
return V.string(str);
|
|
72
|
+
}
|
|
73
|
+
catch {
|
|
74
|
+
throw new DecodeError({ type: "InvalidUtf8" }, start);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
case TAG_BYTES: {
|
|
78
|
+
let len;
|
|
79
|
+
try {
|
|
80
|
+
const result = decodeULEB128(this.input, this.offset);
|
|
81
|
+
len = result.value;
|
|
82
|
+
this.offset = result.nextOffset;
|
|
83
|
+
}
|
|
84
|
+
catch {
|
|
85
|
+
throw new DecodeError({ type: "InvalidVarint" }, payloadOffset);
|
|
86
|
+
}
|
|
87
|
+
const bytes = this.readSlice(Number(len));
|
|
88
|
+
return V.bytes(bytes);
|
|
89
|
+
}
|
|
90
|
+
case TAG_LIST: {
|
|
91
|
+
let count;
|
|
92
|
+
try {
|
|
93
|
+
const result = decodeULEB128(this.input, this.offset);
|
|
94
|
+
count = result.value;
|
|
95
|
+
this.offset = result.nextOffset;
|
|
96
|
+
}
|
|
97
|
+
catch {
|
|
98
|
+
throw new DecodeError({ type: "InvalidVarint" }, payloadOffset);
|
|
99
|
+
}
|
|
100
|
+
const items = [];
|
|
101
|
+
for (let i = 0n; i < count; i++) {
|
|
102
|
+
items.push(this.decodeValue());
|
|
103
|
+
}
|
|
104
|
+
return V.list(items);
|
|
105
|
+
}
|
|
106
|
+
case TAG_MAP: {
|
|
107
|
+
let count;
|
|
108
|
+
try {
|
|
109
|
+
const result = decodeULEB128(this.input, this.offset);
|
|
110
|
+
count = result.value;
|
|
111
|
+
this.offset = result.nextOffset;
|
|
112
|
+
}
|
|
113
|
+
catch {
|
|
114
|
+
throw new DecodeError({ type: "InvalidVarint" }, payloadOffset);
|
|
115
|
+
}
|
|
116
|
+
const map = new Map();
|
|
117
|
+
for (let i = 0n; i < count; i++) {
|
|
118
|
+
const keyValue = this.decodeValue();
|
|
119
|
+
if (keyValue.kind !== "string") {
|
|
120
|
+
throw new DecodeError({ type: "InvalidTag", tag }, this.offset);
|
|
121
|
+
}
|
|
122
|
+
const value = this.decodeValue();
|
|
123
|
+
map.set(keyValue.value, value);
|
|
124
|
+
}
|
|
125
|
+
return V.map(map);
|
|
126
|
+
}
|
|
127
|
+
default:
|
|
128
|
+
throw new DecodeError({ type: "InvalidTag", tag }, tagOffset);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
export function decodeValue(input) {
|
|
133
|
+
const decoder = new Decoder(input);
|
|
134
|
+
const value = decoder.decodeValue();
|
|
135
|
+
if (decoder["remaining"]() !== 0) {
|
|
136
|
+
throw new DecodeError({ type: "TrailingBytes" }, input.length - decoder["remaining"]());
|
|
137
|
+
}
|
|
138
|
+
return value;
|
|
139
|
+
}
|
|
140
|
+
//# sourceMappingURL=decode.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"decode.js","sourceRoot":"","sources":["../src/decode.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,CAAC,EAAE,MAAM,oBAAoB,CAAC;AACvC,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC3D,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAEhD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,KAAK,GAAG,IAAI,CAAC,WAAW,EAAE,CAAC;oBACjC,GAAG,CAAC,GAAG,CAAC,QAAQ,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;gBACnC,CAAC;gBAED,OAAO,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;YACtB,CAAC;YAED;gBACI,MAAM,IAAI,WAAW,CAAC,EAAE,IAAI,EAAE,YAAY,EAAE,GAAG,EAAE,EAAE,SAAS,CAAC,CAAC;QACtE,CAAC;IACL,CAAC;CACJ;AAED,MAAM,UAAU,WAAW,CAAC,KAAiB;IACzC,MAAM,OAAO,GAAG,IAAI,OAAO,CAAC,KAAK,CAAC,CAAC;IACnC,MAAM,KAAK,GAAG,OAAO,CAAC,WAAW,EAAE,CAAC;IAEpC,IAAI,OAAO,CAAC,WAAW,CAAC,EAAE,KAAK,CAAC,EAAE,CAAC;QAC/B,MAAM,IAAI,WAAW,CACjB,EAAE,IAAI,EAAE,eAAe,EAAE,EACzB,KAAK,CAAC,MAAM,GAAG,OAAO,CAAC,WAAW,CAAC,EAAE,CACxC,CAAC;IACN,CAAC;IAED,OAAO,KAAK,CAAC;AACjB,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export type DecodeErrorKind = {
|
|
2
|
+
type: "InvalidTag";
|
|
3
|
+
tag: number;
|
|
4
|
+
} | {
|
|
5
|
+
type: "UnexpectedEOF";
|
|
6
|
+
} | {
|
|
7
|
+
type: "InvalidVarint";
|
|
8
|
+
} | {
|
|
9
|
+
type: "InvalidUtf8";
|
|
10
|
+
} | {
|
|
11
|
+
type: "TrailingBytes";
|
|
12
|
+
};
|
|
13
|
+
export declare class DecodeError extends Error {
|
|
14
|
+
readonly kind: DecodeErrorKind;
|
|
15
|
+
readonly offset: number;
|
|
16
|
+
constructor(kind: DecodeErrorKind, offset: number);
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=decode_error.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"decode_error.d.ts","sourceRoot":"","sources":["../src/decode_error.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,eAAe,GACrB;IAAE,IAAI,EAAE,YAAY,CAAC;IAAC,GAAG,EAAE,MAAM,CAAA;CAAE,GACnC;IAAE,IAAI,EAAE,eAAe,CAAA;CAAE,GACzB;IAAE,IAAI,EAAE,eAAe,CAAA;CAAE,GACzB;IAAE,IAAI,EAAE,aAAa,CAAA;CAAE,GACvB;IAAE,IAAI,EAAE,eAAe,CAAA;CAAE,CAAC;AAEhC,qBAAa,WAAY,SAAQ,KAAK;IAClC,QAAQ,CAAC,IAAI,EAAE,eAAe,CAAC;IAC/B,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;gBAEZ,IAAI,EAAE,eAAe,EAAE,MAAM,EAAE,MAAM;CAKpD"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"decode_error.js","sourceRoot":"","sources":["../src/decode_error.ts"],"names":[],"mappings":"AAOA,MAAM,OAAO,WAAY,SAAQ,KAAK;IACzB,IAAI,CAAkB;IACtB,MAAM,CAAS;IAExB,YAAY,IAAqB,EAAE,MAAc;QAC7C,KAAK,CAAC,kBAAkB,MAAM,EAAE,CAAC,CAAC;QAClC,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACzB,CAAC;CACJ"}
|
package/dist/encode.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"encode.d.ts","sourceRoot":"","sources":["../src/encode.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAgBnC,wBAAgB,WAAW,CAAC,KAAK,EAAE,KAAK,GAAG,UAAU,CAIpD"}
|