openxiangda-contracts 2.0.0-alpha.12

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 ADDED
@@ -0,0 +1,8 @@
1
+ # openxiangda-contracts
2
+
3
+ Canonical TypeScript types, JSON Schemas, error codes and deterministic digest
4
+ helpers for OpenXiangda 2.0.
5
+
6
+ The package deliberately has no runtime dependencies. Platform and toolchain
7
+ implementations must negotiate `OPENXIANGDA_CONTRACT_VERSION` through
8
+ `/openxiangda-api/v2/capabilities` before using a contract.
@@ -0,0 +1,5 @@
1
+ /** Browser-safe contract surface. Node-only canonical hashing stays on the root export. */
2
+ export * from './schemas.js';
3
+ export * from './types.js';
4
+ export * from './validation.js';
5
+ //# sourceMappingURL=browser.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"browser.d.ts","sourceRoot":"","sources":["../src/browser.ts"],"names":[],"mappings":"AAAA,2FAA2F;AAC3F,cAAc,cAAc,CAAC;AAC7B,cAAc,YAAY,CAAC;AAC3B,cAAc,iBAAiB,CAAC"}
@@ -0,0 +1,5 @@
1
+ /** Browser-safe contract surface. Node-only canonical hashing stays on the root export. */
2
+ export * from './schemas.js';
3
+ export * from './types.js';
4
+ export * from './validation.js';
5
+ //# sourceMappingURL=browser.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"browser.js","sourceRoot":"","sources":["../src/browser.ts"],"names":[],"mappings":"AAAA,2FAA2F;AAC3F,cAAc,cAAc,CAAC;AAC7B,cAAc,YAAY,CAAC;AAC3B,cAAc,iBAAiB,CAAC"}
@@ -0,0 +1,3 @@
1
+ export declare function canonicalJson(value: unknown): string;
2
+ export declare function sha256Digest(value: unknown): string;
3
+ //# sourceMappingURL=canonical.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"canonical.d.ts","sourceRoot":"","sources":["../src/canonical.ts"],"names":[],"mappings":"AA6CA,wBAAgB,aAAa,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAEpD;AAED,wBAAgB,YAAY,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAEnD"}
@@ -0,0 +1,44 @@
1
+ import { createHash } from 'node:crypto';
2
+ function isPlainObject(value) {
3
+ if (!value || typeof value !== 'object')
4
+ return false;
5
+ const prototype = Object.getPrototypeOf(value);
6
+ return prototype === Object.prototype || prototype === null;
7
+ }
8
+ function canonicalJsonAt(value, path) {
9
+ if (value === null)
10
+ return 'null';
11
+ if (typeof value === 'string' || typeof value === 'boolean') {
12
+ return JSON.stringify(value);
13
+ }
14
+ if (typeof value === 'number') {
15
+ if (!Number.isFinite(value)) {
16
+ throw new TypeError(`JSON number must be finite: ${path}`);
17
+ }
18
+ return JSON.stringify(value);
19
+ }
20
+ if (Array.isArray(value)) {
21
+ return `[${value
22
+ .map((item, index) => canonicalJsonAt(item, `${path}[${index}]`))
23
+ .join(',')}]`;
24
+ }
25
+ if (isPlainObject(value)) {
26
+ const entries = Object.keys(value)
27
+ .filter(key => value[key] !== undefined)
28
+ .sort((left, right) => (left === right ? 0 : left < right ? -1 : 1))
29
+ .map(key => `${JSON.stringify(key)}:${canonicalJsonAt(value[key], `${path}.${key}`)}`);
30
+ return `{${entries.join(',')}}`;
31
+ }
32
+ const type = value instanceof Date
33
+ ? 'Date'
34
+ : value?.constructor?.name ||
35
+ typeof value;
36
+ throw new TypeError(`Value is not JSON serializable: ${path} (${type})`);
37
+ }
38
+ export function canonicalJson(value) {
39
+ return canonicalJsonAt(value, '$');
40
+ }
41
+ export function sha256Digest(value) {
42
+ return createHash('sha256').update(canonicalJson(value)).digest('hex');
43
+ }
44
+ //# sourceMappingURL=canonical.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"canonical.js","sourceRoot":"","sources":["../src/canonical.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAEzC,SAAS,aAAa,CAAC,KAAc;IACnC,IAAI,CAAC,KAAK,IAAI,OAAO,KA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AK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;aACnE,GAAG,CACF,GAAG,CAAC,EAAE,CACJ,GAAG,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,IAAI,eAAe,CACvC,KAAK,CAAC,GAAG,CAAC,EACV,GAAG,IAAI,IAAI,GAAG,EAAE,CACjB,EAAE,CACN,CAAC;QACJ,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC;IAClC,CAAC;IACD,MAAM,IAAI,GACR,KAAK,YAAY,IAAI;QACnB,CAAC,CAAC,MAAM;QACR,CAAC,CAAE,KAA6C,EAAE,WAAW,EAAE,IAAI;YACjE,OAAO,KAAK,CAAC;IACnB,MAAM,IAAI,SAAS,CAAC,mCAAmC,IAAI,KAAK,IAAI,GAAG,CAAC,CAAC;AAC3E,CAAC;AAED,MAAM,UAAU,aAAa,CAAC,KAAc;IAC1C,OAAO,eAAe,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;AACrC,CAAC;AAED,MAAM,UAAU,YAAY,CAAC,KAAc;IACzC,OAAO,UAAU,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;AACzE,CAAC"}
@@ -0,0 +1,5 @@
1
+ export * from './canonical.js';
2
+ export * from './schemas.js';
3
+ export * from './types.js';
4
+ export * from './validation.js';
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,cAAc,CAAC;AAC7B,cAAc,YAAY,CAAC;AAC3B,cAAc,iBAAiB,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,5 @@
1
+ export * from './canonical.js';
2
+ export * from './schemas.js';
3
+ export * from './types.js';
4
+ export * from './validation.js';
5
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC;AAC/B,cAAc,cAAc,CAAC;AAC7B,cAAc,YAAY,CAAC;AAC3B,cAAc,iBAAiB,CAAC"}