@agenticprimitives/situations 0.0.0-alpha.4 → 0.0.0-alpha.6
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/canonical.d.ts +2 -9
- package/dist/canonical.d.ts.map +1 -1
- package/dist/canonical.js +5 -107
- package/dist/canonical.js.map +1 -1
- package/package.json +2 -2
package/dist/canonical.d.ts
CHANGED
|
@@ -17,15 +17,8 @@
|
|
|
17
17
|
* subset of JSON (string / number / boolean / null / object / array). We do not
|
|
18
18
|
* handle BigInt or Date — callers must serialise those upstream.
|
|
19
19
|
*/
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
constructor(message: string, path: string);
|
|
23
|
-
}
|
|
24
|
-
/**
|
|
25
|
-
* Canonicalize a JSON-compatible value per RFC 8785.
|
|
26
|
-
* Returns the canonical string (UTF-8 text; callers wrap with `utf8ToBytes` to hash).
|
|
27
|
-
*/
|
|
28
|
-
export declare function jcsCanonicalize(value: unknown, path?: string): string;
|
|
20
|
+
import { JcsError, jcsCanonicalize } from '@agenticprimitives/types';
|
|
21
|
+
export { JcsError, jcsCanonicalize };
|
|
29
22
|
/**
|
|
30
23
|
* Compute the canonical hash of a value: `keccak256(jcsCanonicalize(value))`.
|
|
31
24
|
* Returns the 32-byte hex hash.
|
package/dist/canonical.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"canonical.d.ts","sourceRoot":"","sources":["../src/canonical.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;
|
|
1
|
+
{"version":3,"file":"canonical.d.ts","sourceRoot":"","sources":["../src/canonical.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAQH,OAAO,EAAE,QAAQ,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;AACrE,OAAO,EAAE,QAAQ,EAAE,eAAe,EAAE,CAAC;AAKrC;;;GAGG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,MAAM,EAAE,CAK3D"}
|
package/dist/canonical.js
CHANGED
|
@@ -19,113 +19,11 @@
|
|
|
19
19
|
*/
|
|
20
20
|
import { keccak_256 } from '@noble/hashes/sha3.js';
|
|
21
21
|
import { utf8ToBytes } from '@noble/hashes/utils.js';
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
/**
|
|
30
|
-
* Canonicalize a JSON-compatible value per RFC 8785.
|
|
31
|
-
* Returns the canonical string (UTF-8 text; callers wrap with `utf8ToBytes` to hash).
|
|
32
|
-
*/
|
|
33
|
-
export function jcsCanonicalize(value, path = '$') {
|
|
34
|
-
if (value === null)
|
|
35
|
-
return 'null';
|
|
36
|
-
if (value === undefined) {
|
|
37
|
-
throw new JcsError('undefined is not JSON', path);
|
|
38
|
-
}
|
|
39
|
-
switch (typeof value) {
|
|
40
|
-
case 'boolean':
|
|
41
|
-
return value ? 'true' : 'false';
|
|
42
|
-
case 'string':
|
|
43
|
-
return serializeString(value);
|
|
44
|
-
case 'number':
|
|
45
|
-
return serializeNumber(value, path);
|
|
46
|
-
case 'object': {
|
|
47
|
-
if (Array.isArray(value)) {
|
|
48
|
-
const items = value.map((v, i) => jcsCanonicalize(v, `${path}[${i}]`));
|
|
49
|
-
return `[${items.join(',')}]`;
|
|
50
|
-
}
|
|
51
|
-
// Plain object
|
|
52
|
-
const entries = Object.entries(value)
|
|
53
|
-
.filter(([, v]) => v !== undefined)
|
|
54
|
-
.sort(([a], [b]) => sortByCodeUnit(a, b));
|
|
55
|
-
const items = entries.map(([k, v]) => `${serializeString(k)}:${jcsCanonicalize(v, `${path}.${k}`)}`);
|
|
56
|
-
return `{${items.join(',')}}`;
|
|
57
|
-
}
|
|
58
|
-
default:
|
|
59
|
-
throw new JcsError(`unsupported JSON type: ${typeof value}`, path);
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
/** UTF-16 code unit comparison — exactly what RFC 8785 §3.2.3 requires. */
|
|
63
|
-
function sortByCodeUnit(a, b) {
|
|
64
|
-
const len = Math.min(a.length, b.length);
|
|
65
|
-
for (let i = 0; i < len; i++) {
|
|
66
|
-
const av = a.charCodeAt(i);
|
|
67
|
-
const bv = b.charCodeAt(i);
|
|
68
|
-
if (av !== bv)
|
|
69
|
-
return av - bv;
|
|
70
|
-
}
|
|
71
|
-
return a.length - b.length;
|
|
72
|
-
}
|
|
73
|
-
/** RFC 8259 string serialisation with JCS-compatible escaping (RFC 8785 §3.2.2.2). */
|
|
74
|
-
function serializeString(s) {
|
|
75
|
-
let out = '"';
|
|
76
|
-
for (let i = 0; i < s.length; i++) {
|
|
77
|
-
const code = s.charCodeAt(i);
|
|
78
|
-
if (code === 0x22) {
|
|
79
|
-
out += '\\"';
|
|
80
|
-
}
|
|
81
|
-
else if (code === 0x5c) {
|
|
82
|
-
out += '\\\\';
|
|
83
|
-
}
|
|
84
|
-
else if (code < 0x20) {
|
|
85
|
-
// Control characters
|
|
86
|
-
switch (code) {
|
|
87
|
-
case 0x08:
|
|
88
|
-
out += '\\b';
|
|
89
|
-
break;
|
|
90
|
-
case 0x09:
|
|
91
|
-
out += '\\t';
|
|
92
|
-
break;
|
|
93
|
-
case 0x0a:
|
|
94
|
-
out += '\\n';
|
|
95
|
-
break;
|
|
96
|
-
case 0x0c:
|
|
97
|
-
out += '\\f';
|
|
98
|
-
break;
|
|
99
|
-
case 0x0d:
|
|
100
|
-
out += '\\r';
|
|
101
|
-
break;
|
|
102
|
-
default:
|
|
103
|
-
out += `\\u${code.toString(16).padStart(4, '0')}`;
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
else {
|
|
107
|
-
out += s[i];
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
out += '"';
|
|
111
|
-
return out;
|
|
112
|
-
}
|
|
113
|
-
/** RFC 8785 §3.2.2.3 — shortest round-tripping IEEE 754 representation. */
|
|
114
|
-
function serializeNumber(n, path) {
|
|
115
|
-
if (!Number.isFinite(n)) {
|
|
116
|
-
throw new JcsError(`non-finite number (${n})`, path);
|
|
117
|
-
}
|
|
118
|
-
if (Object.is(n, -0))
|
|
119
|
-
return '0';
|
|
120
|
-
if (n === 0)
|
|
121
|
-
return '0';
|
|
122
|
-
if (Number.isInteger(n) && Math.abs(n) < 1e21) {
|
|
123
|
-
return n.toString();
|
|
124
|
-
}
|
|
125
|
-
// Browsers + Node give us the shortest round-trip via `toString()`
|
|
126
|
-
// (per ECMA-262 §6.1.6.1.13). RFC 8785 expects the ES round-trip form.
|
|
127
|
-
return n.toString();
|
|
128
|
-
}
|
|
22
|
+
// RFC 8785 JCS lives in `@agenticprimitives/types` — ONE implementation. It was byte-identical here
|
|
23
|
+
// and in the sibling package, and neither could import the other (the edge is a cycle). Imported for
|
|
24
|
+
// local use AND re-exported, so consumers of this package are unaffected.
|
|
25
|
+
import { JcsError, jcsCanonicalize } from '@agenticprimitives/types';
|
|
26
|
+
export { JcsError, jcsCanonicalize };
|
|
129
27
|
/**
|
|
130
28
|
* Compute the canonical hash of a value: `keccak256(jcsCanonicalize(value))`.
|
|
131
29
|
* Returns the 32-byte hex hash.
|
package/dist/canonical.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"canonical.js","sourceRoot":"","sources":["../src/canonical.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AACnD,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAErD,
|
|
1
|
+
{"version":3,"file":"canonical.js","sourceRoot":"","sources":["../src/canonical.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AACnD,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAErD,oGAAoG;AACpG,qGAAqG;AACrG,0EAA0E;AAC1E,OAAO,EAAE,QAAQ,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;AACrE,OAAO,EAAE,QAAQ,EAAE,eAAe,EAAE,CAAC;AAKrC;;;GAGG;AACH,MAAM,UAAU,aAAa,CAAC,KAAc;IAC1C,MAAM,SAAS,GAAG,eAAe,CAAC,KAAK,CAAC,CAAC;IACzC,MAAM,KAAK,GAAG,WAAW,CAAC,SAAS,CAAC,CAAC;IACrC,MAAM,MAAM,GAAG,UAAU,CAAC,KAAK,CAAC,CAAC;IACjC,OAAO,KAAK,UAAU,CAAC,MAAM,CAAC,EAAmB,CAAC;AACpD,CAAC;AAED,SAAS,UAAU,CAAC,CAAa;IAC/B,IAAI,CAAC,GAAG,EAAE,CAAC;IACX,KAAK,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC;QAClB,CAAC,IAAI,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC;IACvC,CAAC;IACD,OAAO,CAAC,CAAC;AACX,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@agenticprimitives/situations",
|
|
3
|
-
"version": "0.0.0-alpha.
|
|
3
|
+
"version": "0.0.0-alpha.6",
|
|
4
4
|
"description": "Substrate Situation primitive (SituationV2, RoleBinding, EntityRef) — spec 324 W2.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
30
30
|
"@noble/hashes": "^2.2.0",
|
|
31
|
-
"@agenticprimitives/types": "1.0.0-alpha.
|
|
31
|
+
"@agenticprimitives/types": "1.0.0-alpha.22"
|
|
32
32
|
},
|
|
33
33
|
"devDependencies": {
|
|
34
34
|
"vitest": "^4.1.8"
|