@certen.io/sdk 0.14.1 → 0.15.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/CHANGELOG.md +9 -0
- package/dist/agent/core.d.ts +7 -0
- package/dist/agent/core.d.ts.map +1 -0
- package/dist/agent/core.js +7 -0
- package/dist/agent/core.js.map +1 -0
- package/dist/agent/mandate.d.ts +141 -0
- package/dist/agent/mandate.d.ts.map +1 -0
- package/dist/agent/mandate.js +158 -0
- package/dist/agent/mandate.js.map +1 -0
- package/dist/agent-enrollment.d.ts +83 -0
- package/dist/agent-enrollment.d.ts.map +1 -0
- package/dist/agent-enrollment.js +102 -0
- package/dist/agent-enrollment.js.map +1 -0
- package/dist/core/bytes.d.ts +38 -0
- package/dist/core/bytes.d.ts.map +1 -0
- package/dist/core/bytes.js +161 -0
- package/dist/core/bytes.js.map +1 -0
- package/dist/core/grant-profile.d.ts +133 -0
- package/dist/core/grant-profile.d.ts.map +1 -0
- package/dist/core/grant-profile.js +323 -0
- package/dist/core/grant-profile.js.map +1 -0
- package/dist/core/hashes.d.ts +59 -0
- package/dist/core/hashes.d.ts.map +1 -0
- package/dist/core/hashes.js +128 -0
- package/dist/core/hashes.js.map +1 -0
- package/dist/core/jcs.d.ts +29 -0
- package/dist/core/jcs.d.ts.map +1 -0
- package/dist/core/jcs.js +371 -0
- package/dist/core/jcs.js.map +1 -0
- package/dist/core/registry-profile.d.ts +47 -0
- package/dist/core/registry-profile.d.ts.map +1 -0
- package/dist/core/registry-profile.js +119 -0
- package/dist/core/registry-profile.js.map +1 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -1
- package/dist/principal-entries.d.ts +109 -0
- package/dist/principal-entries.d.ts.map +1 -0
- package/dist/principal-entries.js +237 -0
- package/dist/principal-entries.js.map +1 -0
- package/dist/principal-intervention.d.ts +97 -0
- package/dist/principal-intervention.d.ts.map +1 -0
- package/dist/principal-intervention.js +139 -0
- package/dist/principal-intervention.js.map +1 -0
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +2 -2
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"grant-profile.js","sourceRoot":"","sources":["../../src/core/grant-profile.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,aAAa,EAAE,UAAU,EAAa,MAAM,YAAY,CAAC;AACzH,OAAO,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAEnD,MAAM,CAAC,MAAM,YAAY,GAAG,iBAAiB,CAAC;AAC9C,4KAA4K;AAC5K,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,gBAAgB,EAAE,eAAe,EAAE,iBAAiB,EAAE,KAAK,CAAU,CAAC;AAEnG,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,OAAO,EAAE,UAAU,EAAE,QAAQ,CAAU,CAAC;AA8BtE,gMAAgM;AAChM,MAAM,CAAC,MAAM,MAAM,GAAG,EAAE,SAAS,EAAE,KAAK,EAAE,YAAY,EAAE,EAAE,EAAE,KAAK,EAAE,EAAE,EAAE,QAAQ,EAAE,EAAE,EAAE,cAAc,EAAE,CAAC,EAAE,cAAc,EAAE,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC;AAEzI,MAAM,WAAW,GAAG,6BAA6B,CAAC;AAClD,MAAM,cAAc,GAAG,wBAAwB,CAAC;AAEhD,MAAM,OAAQ,SAAQ,KAAK;IACJ;IAAyB;IAA9C,YAAqB,MAAc,EAAW,MAAe;QAC3D,KAAK,CAAC,MAAM,CAAC,CAAC;QADK,WAAM,GAAN,MAAM,CAAQ;QAAW,WAAM,GAAN,MAAM,CAAS;IAE7D,CAAC;CACF;AACD,MAAM,IAAI,GAAG,CAAC,MAAc,EAAE,IAAY,EAAS,EAAE;IAC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AAC,GAAG,aAAa,CAAC,KAAK,CAAC,CAAC;IAC/B,IAAI,CAAC,CAAC,CAAC,EAAE;QAAE,OAAO,CAAC,CAAC;IACpB,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,CAAC,KAAK,EAAE,SAAS,EAAE,YAAY,CAAC,CAAC,CAAC,KAAK,CAAC,EAAE,CAAC;AACxE,CAAC"}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
export declare const TAGS: {
|
|
2
|
+
readonly grant: "certen:grant:v1";
|
|
3
|
+
readonly policy: "certen:policy:v1";
|
|
4
|
+
readonly request: "certen:request:v1";
|
|
5
|
+
readonly decision: "certen:decision:v1";
|
|
6
|
+
readonly exception: "certen:exception:v1";
|
|
7
|
+
readonly subject: "certen:subject:v1";
|
|
8
|
+
readonly subject2: "certen:subject:v2";
|
|
9
|
+
readonly envelopeSig: "certen:envelope-sig:v1";
|
|
10
|
+
readonly declog: "certen:declog:v1";
|
|
11
|
+
readonly declogGenesis: "certen:declog:d0/v1";
|
|
12
|
+
};
|
|
13
|
+
export declare const digestHex: (preimage: Uint8Array) => string;
|
|
14
|
+
/** lp(tag) followed by lp(field) for every field. */
|
|
15
|
+
export declare function taggedPreimage(tag: string, fields: Uint8Array[]): Uint8Array;
|
|
16
|
+
/** The framing check of the goldens (test-only tags): every field is UTF-8 text. */
|
|
17
|
+
export declare function framedPreimage(tag: string, fieldsUtf8: string[]): Uint8Array;
|
|
18
|
+
export declare function grantPreimage(grant: unknown): Uint8Array;
|
|
19
|
+
export declare const hashGrant: (grant: unknown) => string;
|
|
20
|
+
/** The tag a registration is hashed and signed under: certen:subject:v1 for a v1 record, certen:subject:v2 for a lineage version. */
|
|
21
|
+
export declare function registrationTag(registration: unknown): string;
|
|
22
|
+
/** gh-12: the certen.subject/v1 record. */
|
|
23
|
+
export declare const subjectPreimage: (registration: unknown) => Uint8Array;
|
|
24
|
+
/** gh-17: the certen.subject/v2 lineage version. */
|
|
25
|
+
export declare const subject2Preimage: (registration: unknown) => Uint8Array;
|
|
26
|
+
/** The registration hash of either schema (the tag follows the schema). */
|
|
27
|
+
export declare const hashRegistration: (registration: unknown) => string;
|
|
28
|
+
/** policyHash = SHA-256( lp("certen:policy:v1") || lp(canonical rule set) || lp(canonical signer ceilings) ). */
|
|
29
|
+
export declare function policyPreimage(ruleSet: unknown, ceilings: unknown): Uint8Array;
|
|
30
|
+
export declare const hashPolicy: (ruleSet: unknown, ceilings: unknown) => string;
|
|
31
|
+
/**
|
|
32
|
+
* requestHash preimage: chainId as be64, kind and asset and amount as UTF-8, source, target and beneficiary as their
|
|
33
|
+
* 20 raw bytes, executionCommitment, operationId and the Accumulate transaction hash as their 32 raw bytes.
|
|
34
|
+
*/
|
|
35
|
+
export declare function requestPreimage(request: unknown): Uint8Array;
|
|
36
|
+
export declare const hashRequest: (request: unknown) => string;
|
|
37
|
+
export declare const decisionPreimage: (record: unknown) => Uint8Array;
|
|
38
|
+
export declare const hashDecision: (record: unknown) => string;
|
|
39
|
+
export declare const exceptionPreimage: (exception: unknown) => Uint8Array;
|
|
40
|
+
export declare const hashException: (exception: unknown) => string;
|
|
41
|
+
/**
|
|
42
|
+
* What a key signs: SHA-256( lp("certen:envelope-sig:v1") || lp(payloadTag) || lp(payloadHash bytes) || lp(page URL) ).
|
|
43
|
+
* This returns the preimage; envelopeDigest returns the 32-byte digest.
|
|
44
|
+
*/
|
|
45
|
+
export declare function envelopeSigPreimage(payloadTag: string, payloadHash: string, page: string): Uint8Array;
|
|
46
|
+
export declare const envelopeDigest: (payloadTag: string, payloadHash: string, page: string) => Uint8Array;
|
|
47
|
+
export declare const genesisPreimage: (logId: string) => Uint8Array;
|
|
48
|
+
export declare const genesisHash: (logId: string) => string;
|
|
49
|
+
export interface LogEntryFields {
|
|
50
|
+
prev: string;
|
|
51
|
+
seq: number;
|
|
52
|
+
kind: string;
|
|
53
|
+
payload: unknown;
|
|
54
|
+
at: number;
|
|
55
|
+
}
|
|
56
|
+
/** entry hash = SHA-256( lp(tag) || lp(prev) || lp(be64 seq) || lp(kind) || lp(SHA-256(canonical payload)) || lp(be64 at) ) */
|
|
57
|
+
export declare function logEntryPreimage(e: LogEntryFields): Uint8Array;
|
|
58
|
+
export declare const logEntryHash: (e: LogEntryFields) => string;
|
|
59
|
+
//# sourceMappingURL=hashes.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hashes.d.ts","sourceRoot":"","sources":["../../src/core/hashes.ts"],"names":[],"mappings":"AAWA,eAAO,MAAM,IAAI;;;;;;;;;;;CAWP,CAAC;AAEX,eAAO,MAAM,SAAS,GAAI,UAAU,UAAU,KAAG,MAAwC,CAAC;AAE1F,qDAAqD;AACrD,wBAAgB,cAAc,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,GAAG,UAAU,CAE5E;AAED,oFAAoF;AACpF,wBAAgB,cAAc,CAAC,GAAG,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,GAAG,UAAU,CAE5E;AAID,wBAAgB,aAAa,CAAC,KAAK,EAAE,OAAO,GAAG,UAAU,CAExD;AACD,eAAO,MAAM,SAAS,GAAI,OAAO,OAAO,KAAG,MAAyC,CAAC;AAErF,qIAAqI;AACrI,wBAAgB,eAAe,CAAC,YAAY,EAAE,OAAO,GAAG,MAAM,CAE7D;AAKD,2CAA2C;AAC3C,eAAO,MAAM,eAAe,GAAI,cAAc,OAAO,KAAG,UAA8D,CAAC;AACvH,oDAAoD;AACpD,eAAO,MAAM,gBAAgB,GAAI,cAAc,OAAO,KAAG,UAA+D,CAAC;AACzH,2EAA2E;AAC3E,eAAO,MAAM,gBAAgB,GAAI,cAAc,OAAO,KAAG,MAA+G,CAAC;AAIzK,iHAAiH;AACjH,wBAAgB,cAAc,CAAC,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,OAAO,GAAG,UAAU,CAE9E;AACD,eAAO,MAAM,UAAU,GAAI,SAAS,OAAO,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p(tag) || lp(field) || ... ) with lp(x) = four-byte big-endian length followed by x, shown as 0x plus
|
|
4
|
+
* lowercase hex (the proof v2 convention). `*Preimage` returns the bytes that are hashed so that an implementer can find
|
|
5
|
+
* which step differs; `hash*` returns the digest. These helpers throw CoreError on input that has no hash.
|
|
6
|
+
*/
|
|
7
|
+
import { ACTION_KINDS, canonicalGrant } from './grant-profile.js';
|
|
8
|
+
import { canonicalRegistration } from './registry-profile.js';
|
|
9
|
+
import { CoreError, address20, be64, concat, hash32, isAmount, isPlainObject, lp, sha256, toHex, utf8 } from './bytes.js';
|
|
10
|
+
import { canonicalize } from './jcs.js';
|
|
11
|
+
export const TAGS = {
|
|
12
|
+
grant: 'certen:grant:v1',
|
|
13
|
+
policy: 'certen:policy:v1',
|
|
14
|
+
request: 'certen:request:v1',
|
|
15
|
+
decision: 'certen:decision:v1',
|
|
16
|
+
exception: 'certen:exception:v1',
|
|
17
|
+
subject: 'certen:subject:v1',
|
|
18
|
+
subject2: 'certen:subject:v2',
|
|
19
|
+
envelopeSig: 'certen:envelope-sig:v1',
|
|
20
|
+
declog: 'certen:declog:v1',
|
|
21
|
+
declogGenesis: 'certen:declog:d0/v1',
|
|
22
|
+
};
|
|
23
|
+
export const digestHex = (preimage) => '0x' + toHex(sha256(preimage));
|
|
24
|
+
/** lp(tag) followed by lp(field) for every field. */
|
|
25
|
+
export function taggedPreimage(tag, fields) {
|
|
26
|
+
return concat(lp(utf8(tag)), ...fields.map((f) => lp(f)));
|
|
27
|
+
}
|
|
28
|
+
/** The framing check of the goldens (test-only tags): every field is UTF-8 text. */
|
|
29
|
+
export function framedPreimage(tag, fieldsUtf8) {
|
|
30
|
+
return taggedPreimage(tag, fieldsUtf8.map((f) => utf8(f)));
|
|
31
|
+
}
|
|
32
|
+
// ---- grant, subject registration -----------------------------------------------------------------------------
|
|
33
|
+
export function grantPreimage(grant) {
|
|
34
|
+
return taggedPreimage(TAGS.grant, [utf8(canonicalGrant(grant))]);
|
|
35
|
+
}
|
|
36
|
+
export const hashGrant = (grant) => digestHex(grantPreimage(grant));
|
|
37
|
+
/** The tag a registration is hashed and signed under: certen:subject:v1 for a v1 record, certen:subject:v2 for a lineage version. */
|
|
38
|
+
export function registrationTag(registration) {
|
|
39
|
+
return isPlainObject(registration) && registration['schema'] === 'certen.subject/v2' ? TAGS.subject2 : TAGS.subject;
|
|
40
|
+
}
|
|
41
|
+
function registrationPreimage(registration, tag) {
|
|
42
|
+
if (registrationTag(registration) !== tag)
|
|
43
|
+
throw new CoreError('registration_schema_invalid', tag);
|
|
44
|
+
return taggedPreimage(tag, [utf8(canonicalRegistration(registration))]);
|
|
45
|
+
}
|
|
46
|
+
/** gh-12: the certen.subject/v1 record. */
|
|
47
|
+
export const subjectPreimage = (registration) => registrationPreimage(registration, TAGS.subject);
|
|
48
|
+
/** gh-17: the certen.subject/v2 lineage version. */
|
|
49
|
+
export const subject2Preimage = (registration) => registrationPreimage(registration, TAGS.subject2);
|
|
50
|
+
/** The registration hash of either schema (the tag follows the schema). */
|
|
51
|
+
export const hashRegistration = (registration) => digestHex(taggedPreimage(registrationTag(registration), [utf8(canonicalRegistration(registration))]));
|
|
52
|
+
// ---- policy --------------------------------------------------------------------------------------------------
|
|
53
|
+
/** policyHash = SHA-256( lp("certen:policy:v1") || lp(canonical rule set) || lp(canonical signer ceilings) ). */
|
|
54
|
+
export function policyPreimage(ruleSet, ceilings) {
|
|
55
|
+
return taggedPreimage(TAGS.policy, [utf8(canonicalize(ruleSet)), utf8(canonicalize(ceilings))]);
|
|
56
|
+
}
|
|
57
|
+
export const hashPolicy = (ruleSet, ceilings) => digestHex(policyPreimage(ruleSet, ceilings));
|
|
58
|
+
// ---- request -------------------------------------------------------------------------------------------------
|
|
59
|
+
const REQUEST_KEYS = ['chainId', 'kind', 'source', 'target', 'beneficiary', 'asset', 'amount', 'executionCommitment', 'operationId', 'txHash'];
|
|
60
|
+
/**
|
|
61
|
+
* requestHash preimage: chainId as be64, kind and asset and amount as UTF-8, source, target and beneficiary as their
|
|
62
|
+
* 20 raw bytes, executionCommitment, operationId and the Accumulate transaction hash as their 32 raw bytes.
|
|
63
|
+
*/
|
|
64
|
+
export function requestPreimage(request) {
|
|
65
|
+
if (!isPlainObject(request))
|
|
66
|
+
throw new CoreError('request_malformed');
|
|
67
|
+
for (const k of Object.keys(request))
|
|
68
|
+
if (!REQUEST_KEYS.includes(k))
|
|
69
|
+
throw new CoreError('request_unknown_field', k);
|
|
70
|
+
for (const k of REQUEST_KEYS)
|
|
71
|
+
if (!(k in request))
|
|
72
|
+
throw new CoreError('request_missing_field', k);
|
|
73
|
+
const chainId = request['chainId'];
|
|
74
|
+
if (typeof chainId !== 'number' || !Number.isSafeInteger(chainId) || chainId < 1)
|
|
75
|
+
throw new CoreError('request_field_invalid', 'chainId');
|
|
76
|
+
const kind = request['kind'];
|
|
77
|
+
if (typeof kind !== 'string' || !ACTION_KINDS.includes(kind))
|
|
78
|
+
throw new CoreError('request_field_invalid', 'kind');
|
|
79
|
+
const asset = request['asset'];
|
|
80
|
+
if (asset !== 'native')
|
|
81
|
+
address20(asset, 'asset');
|
|
82
|
+
const amount = request['amount'];
|
|
83
|
+
if (!isAmount(amount))
|
|
84
|
+
throw new CoreError('request_field_invalid', 'amount');
|
|
85
|
+
return taggedPreimage(TAGS.request, [
|
|
86
|
+
be64(chainId),
|
|
87
|
+
utf8(kind),
|
|
88
|
+
address20(request['source'], 'source'),
|
|
89
|
+
address20(request['target'], 'target'),
|
|
90
|
+
address20(request['beneficiary'], 'beneficiary'),
|
|
91
|
+
utf8(asset),
|
|
92
|
+
utf8(amount),
|
|
93
|
+
hash32(request['executionCommitment'], 'executionCommitment'),
|
|
94
|
+
hash32(request['operationId'], 'operationId'),
|
|
95
|
+
hash32(request['txHash'], 'txHash'),
|
|
96
|
+
]);
|
|
97
|
+
}
|
|
98
|
+
export const hashRequest = (request) => digestHex(requestPreimage(request));
|
|
99
|
+
// ---- decision record, exception (hash only; their objects are built in DAX-4 and AGT-4) --------------------------
|
|
100
|
+
function schemaObjectPreimage(tag, schema, value, what) {
|
|
101
|
+
if (!isPlainObject(value))
|
|
102
|
+
throw new CoreError(what + '_malformed');
|
|
103
|
+
if (value['schema'] !== schema)
|
|
104
|
+
throw new CoreError(what + '_schema_invalid');
|
|
105
|
+
return taggedPreimage(tag, [utf8(canonicalize(value))]);
|
|
106
|
+
}
|
|
107
|
+
export const decisionPreimage = (record) => schemaObjectPreimage(TAGS.decision, 'certen.decision/v1', record, 'decision');
|
|
108
|
+
export const hashDecision = (record) => digestHex(decisionPreimage(record));
|
|
109
|
+
export const exceptionPreimage = (exception) => schemaObjectPreimage(TAGS.exception, 'certen.exception/v1', exception, 'exception');
|
|
110
|
+
export const hashException = (exception) => digestHex(exceptionPreimage(exception));
|
|
111
|
+
// ---- envelope signature digest -------------------------------------------------------------------------------
|
|
112
|
+
/**
|
|
113
|
+
* What a key signs: SHA-256( lp("certen:envelope-sig:v1") || lp(payloadTag) || lp(payloadHash bytes) || lp(page URL) ).
|
|
114
|
+
* This returns the preimage; envelopeDigest returns the 32-byte digest.
|
|
115
|
+
*/
|
|
116
|
+
export function envelopeSigPreimage(payloadTag, payloadHash, page) {
|
|
117
|
+
return taggedPreimage(TAGS.envelopeSig, [utf8(payloadTag), hash32(payloadHash, 'payloadHash'), utf8(page)]);
|
|
118
|
+
}
|
|
119
|
+
export const envelopeDigest = (payloadTag, payloadHash, page) => sha256(envelopeSigPreimage(payloadTag, payloadHash, page));
|
|
120
|
+
// ---- decision log --------------------------------------------------------------------------------------------
|
|
121
|
+
export const genesisPreimage = (logId) => taggedPreimage(TAGS.declogGenesis, [utf8(logId)]);
|
|
122
|
+
export const genesisHash = (logId) => digestHex(genesisPreimage(logId));
|
|
123
|
+
/** entry hash = SHA-256( lp(tag) || lp(prev) || lp(be64 seq) || lp(kind) || lp(SHA-256(canonical payload)) || lp(be64 at) ) */
|
|
124
|
+
export function logEntryPreimage(e) {
|
|
125
|
+
return taggedPreimage(TAGS.declog, [hash32(e.prev, 'prev'), be64(e.seq), utf8(e.kind), sha256(utf8(canonicalize(e.payload))), be64(e.at)]);
|
|
126
|
+
}
|
|
127
|
+
export const logEntryHash = (e) => digestHex(logEntryPreimage(e));
|
|
128
|
+
//# sourceMappingURL=hashes.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hashes.js","sourceRoot":"","sources":["../../src/core/hashes.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAClE,OAAO,EAAE,qBAAqB,EAAE,MAAM,uBAAuB,CAAC;AAC9D,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,aAAa,EAAE,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AAC1H,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAExC,MAAM,CAAC,MAAM,IAAI,GAAG;IAClB,KAAK,EAAE,iBAAiB;IACxB,MAAM,EAAE,kBAAkB;IAC1B,OAAO,EAAE,mBAAmB;IAC5B,QAAQ,EAAE,oBAAoB;IAC9B,SAAS,EAAE,qBAAqB;IAChC,OAAO,EAAE,mBAAmB;IAC5B,QAAQ,EAAE,mBAAmB;IAC7B,WAAW,EAAE,wBAAwB;IACrC,MAAM,EAAE,kBAAkB;IAC1B,aAAa,EAAE,qBAAqB;CAC5B,CAAC;AAEX,MAAM,CAAC,MAAM,SAAS,GAAG,CAAC,QAAoB,EAAU,EAAE,CAAC,IAAI,GAAG,KAAK,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC;AAE1F,qDAAqD;AACrD,MAAM,UAAU,cAAc,CAAC,GAAW,EAAE,MAAoB;IAC9D,OAAO,MAAM,CAAC,EAAE,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,GAAG,MAAM,CAAC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M,YAAY,GAAG,CAAC,CAAiB,EAAU,EAAE,CAAC,SAAS,CAAC,gBAAgB,CAAC,CAAC,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Strict JSON parsing and RFC 8785 (JCS) canonicalization. Written for this package from RFC 8259 and RFC 8785 and
|
|
3
|
+
* judged by the DAX-2 vectors; it shares no code with docs/core/vectors/lib (GR-06: a third implementation).
|
|
4
|
+
*
|
|
5
|
+
* Parsing refuses what has no single meaning: a duplicate member name, a lone surrogate, trailing data, anything that
|
|
6
|
+
* is not JSON (NaN, a leading zero, a trailing comma). Canonicalization emits members sorted by UTF-16 code units, the
|
|
7
|
+
* ECMAScript form of numbers and the minimal string escapes, and refuses values JSON cannot carry.
|
|
8
|
+
*/
|
|
9
|
+
import { type Json } from './bytes.js';
|
|
10
|
+
export declare const MAX_DEPTH = 128;
|
|
11
|
+
export interface ParseOptions {
|
|
12
|
+
/** Grant profile: every number must be written as a plain integer literal within +/-(2^53-1). */
|
|
13
|
+
integersOnly?: boolean;
|
|
14
|
+
maxDepth?: number;
|
|
15
|
+
}
|
|
16
|
+
/** Parses JSON text strictly; throws CoreError with a stable code. */
|
|
17
|
+
export declare function parseJson(text: string, opts?: ParseOptions): Json;
|
|
18
|
+
/** RFC 8785 text of an in-memory JSON value; throws CoreError for a value JSON cannot carry. */
|
|
19
|
+
export declare function canonicalize(value: unknown): string;
|
|
20
|
+
export type CanonicalizeTextResult = {
|
|
21
|
+
ok: true;
|
|
22
|
+
canonical: string;
|
|
23
|
+
} | {
|
|
24
|
+
ok: false;
|
|
25
|
+
reason: string;
|
|
26
|
+
};
|
|
27
|
+
/** Parse then canonicalize, with a named refusal instead of a throw. */
|
|
28
|
+
export declare function canonicalizeText(text: string): CanonicalizeTextResult;
|
|
29
|
+
//# sourceMappingURL=jcs.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"jcs.d.ts","sourceRoot":"","sources":["../../src/core/jcs.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,OAAO,EAA8C,KAAK,IAAI,EAAE,MAAM,YAAY,CAAC;AAEnF,eAAO,MAAM,SAAS,MAAM,CAAC;AAK7B,MAAM,WAAW,YAAY;IAC3B,iGAAiG;IACjG,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AA0ND,sEAAsE;AACtE,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,GAAE,YAAiB,GAAG,IAAI,CAGrE;AA0DD,gGAAgG;AAChG,wBAAgB,YAAY,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAEnD;AAED,MAAM,MAAM,sBAAsB,GAAG;IAAE,EAAE,EAAE,IAAI,CAAC;IAAC,SAAS,EAAE,MAAM,CAAA;CAAE,GAAG;IAAE,EAAE,EAAE,KAAK,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAAC;AAErG,wEAAwE;AACxE,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,MAAM,GAAG,sBAAsB,CAOrE"}
|
package/dist/core/jcs.js
ADDED
|
@@ -0,0 +1,371 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Strict JSON parsing and RFC 8785 (JCS) canonicalization. Written for this package from RFC 8259 and RFC 8785 and
|
|
3
|
+
* judged by the DAX-2 vectors; it shares no code with docs/core/vectors/lib (GR-06: a third implementation).
|
|
4
|
+
*
|
|
5
|
+
* Parsing refuses what has no single meaning: a duplicate member name, a lone surrogate, trailing data, anything that
|
|
6
|
+
* is not JSON (NaN, a leading zero, a trailing comma). Canonicalization emits members sorted by UTF-16 code units, the
|
|
7
|
+
* ECMAScript form of numbers and the minimal string escapes, and refuses values JSON cannot carry.
|
|
8
|
+
*/
|
|
9
|
+
import { CoreError, hasLoneSurrogate, isPlainObject } from './bytes.js';
|
|
10
|
+
export const MAX_DEPTH = 128;
|
|
11
|
+
const BS = String.fromCharCode(92);
|
|
12
|
+
const DQ = String.fromCharCode(34);
|
|
13
|
+
const isDigit = (c) => c !== undefined && c >= '0' && c <= '9';
|
|
14
|
+
const isHexDigit = (c) => (c >= '0' && c <= '9') || (c >= 'a' && c <= 'f') || (c >= 'A' && c <= 'F');
|
|
15
|
+
class Parser {
|
|
16
|
+
s;
|
|
17
|
+
integersOnly;
|
|
18
|
+
maxDepth;
|
|
19
|
+
i = 0;
|
|
20
|
+
constructor(s, integersOnly, maxDepth) {
|
|
21
|
+
this.s = s;
|
|
22
|
+
this.integersOnly = integersOnly;
|
|
23
|
+
this.maxDepth = maxDepth;
|
|
24
|
+
}
|
|
25
|
+
parseTop() {
|
|
26
|
+
const v = this.value(0);
|
|
27
|
+
this.ws();
|
|
28
|
+
if (this.i < this.s.length)
|
|
29
|
+
throw new CoreError('json_trailing_data');
|
|
30
|
+
return v;
|
|
31
|
+
}
|
|
32
|
+
ws() {
|
|
33
|
+
while (this.i < this.s.length) {
|
|
34
|
+
const c = this.s.charCodeAt(this.i);
|
|
35
|
+
if (c === 32 || c === 9 || c === 10 || c === 13)
|
|
36
|
+
this.i++;
|
|
37
|
+
else
|
|
38
|
+
break;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
value(depth) {
|
|
42
|
+
if (depth > this.maxDepth)
|
|
43
|
+
throw new CoreError('json_too_deep');
|
|
44
|
+
this.ws();
|
|
45
|
+
if (this.i >= this.s.length)
|
|
46
|
+
throw new CoreError('json_unexpected_end');
|
|
47
|
+
const c = this.s[this.i];
|
|
48
|
+
if (c === '{')
|
|
49
|
+
return this.object(depth);
|
|
50
|
+
if (c === '[')
|
|
51
|
+
return this.array(depth);
|
|
52
|
+
if (c === DQ)
|
|
53
|
+
return this.string();
|
|
54
|
+
if (c === '-' || isDigit(c))
|
|
55
|
+
return this.number();
|
|
56
|
+
if (this.s.startsWith('true', this.i)) {
|
|
57
|
+
this.i += 4;
|
|
58
|
+
return true;
|
|
59
|
+
}
|
|
60
|
+
if (this.s.startsWith('false', this.i)) {
|
|
61
|
+
this.i += 5;
|
|
62
|
+
return false;
|
|
63
|
+
}
|
|
64
|
+
if (this.s.startsWith('null', this.i)) {
|
|
65
|
+
this.i += 4;
|
|
66
|
+
return null;
|
|
67
|
+
}
|
|
68
|
+
throw new CoreError('json_unexpected_token');
|
|
69
|
+
}
|
|
70
|
+
object(depth) {
|
|
71
|
+
this.i++;
|
|
72
|
+
const out = {};
|
|
73
|
+
const seen = new Set();
|
|
74
|
+
this.ws();
|
|
75
|
+
if (this.s[this.i] === '}') {
|
|
76
|
+
this.i++;
|
|
77
|
+
return out;
|
|
78
|
+
}
|
|
79
|
+
for (;;) {
|
|
80
|
+
this.ws();
|
|
81
|
+
if (this.i >= this.s.length)
|
|
82
|
+
throw new CoreError('json_unexpected_end');
|
|
83
|
+
if (this.s[this.i] !== DQ)
|
|
84
|
+
throw new CoreError('json_expected_member_name');
|
|
85
|
+
const key = this.string();
|
|
86
|
+
if (seen.has(key))
|
|
87
|
+
throw new CoreError('duplicate_key');
|
|
88
|
+
seen.add(key);
|
|
89
|
+
this.ws();
|
|
90
|
+
if (this.i >= this.s.length)
|
|
91
|
+
throw new CoreError('json_unexpected_end');
|
|
92
|
+
if (this.s[this.i] !== ':')
|
|
93
|
+
throw new CoreError('json_expected_colon');
|
|
94
|
+
this.i++;
|
|
95
|
+
const v = this.value(depth + 1);
|
|
96
|
+
// defineProperty keeps a member named __proto__ as plain data
|
|
97
|
+
Object.defineProperty(out, key, { value: v, enumerable: true, writable: true, configurable: true });
|
|
98
|
+
this.ws();
|
|
99
|
+
if (this.i >= this.s.length)
|
|
100
|
+
throw new CoreError('json_unexpected_end');
|
|
101
|
+
const c = this.s[this.i];
|
|
102
|
+
if (c === ',') {
|
|
103
|
+
this.i++;
|
|
104
|
+
continue;
|
|
105
|
+
}
|
|
106
|
+
if (c === '}') {
|
|
107
|
+
this.i++;
|
|
108
|
+
return out;
|
|
109
|
+
}
|
|
110
|
+
throw new CoreError('json_expected_comma_or_end');
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
array(depth) {
|
|
114
|
+
this.i++;
|
|
115
|
+
const out = [];
|
|
116
|
+
this.ws();
|
|
117
|
+
if (this.s[this.i] === ']') {
|
|
118
|
+
this.i++;
|
|
119
|
+
return out;
|
|
120
|
+
}
|
|
121
|
+
for (;;) {
|
|
122
|
+
out.push(this.value(depth + 1));
|
|
123
|
+
this.ws();
|
|
124
|
+
if (this.i >= this.s.length)
|
|
125
|
+
throw new CoreError('json_unexpected_end');
|
|
126
|
+
const c = this.s[this.i];
|
|
127
|
+
if (c === ',') {
|
|
128
|
+
this.i++;
|
|
129
|
+
continue;
|
|
130
|
+
}
|
|
131
|
+
if (c === ']') {
|
|
132
|
+
this.i++;
|
|
133
|
+
return out;
|
|
134
|
+
}
|
|
135
|
+
throw new CoreError('json_expected_comma_or_end');
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
hex4() {
|
|
139
|
+
const h = this.s.slice(this.i, this.i + 4);
|
|
140
|
+
if (h.length < 4 || ![...h].every(isHexDigit))
|
|
141
|
+
throw new CoreError('json_bad_escape');
|
|
142
|
+
this.i += 4;
|
|
143
|
+
return parseInt(h, 16);
|
|
144
|
+
}
|
|
145
|
+
string() {
|
|
146
|
+
this.i++;
|
|
147
|
+
let out = '';
|
|
148
|
+
for (;;) {
|
|
149
|
+
if (this.i >= this.s.length)
|
|
150
|
+
throw new CoreError('json_unterminated_string');
|
|
151
|
+
const code = this.s.charCodeAt(this.i);
|
|
152
|
+
if (code === 34) {
|
|
153
|
+
this.i++;
|
|
154
|
+
return out;
|
|
155
|
+
}
|
|
156
|
+
if (code < 0x20)
|
|
157
|
+
throw new CoreError('json_control_character');
|
|
158
|
+
if (code === 92) {
|
|
159
|
+
this.i++;
|
|
160
|
+
if (this.i >= this.s.length)
|
|
161
|
+
throw new CoreError('json_unterminated_string');
|
|
162
|
+
const e = this.s[this.i];
|
|
163
|
+
this.i++;
|
|
164
|
+
switch (e) {
|
|
165
|
+
case DQ:
|
|
166
|
+
out += DQ;
|
|
167
|
+
break;
|
|
168
|
+
case BS:
|
|
169
|
+
out += BS;
|
|
170
|
+
break;
|
|
171
|
+
case '/':
|
|
172
|
+
out += '/';
|
|
173
|
+
break;
|
|
174
|
+
case 'b':
|
|
175
|
+
out += String.fromCharCode(8);
|
|
176
|
+
break;
|
|
177
|
+
case 'f':
|
|
178
|
+
out += String.fromCharCode(12);
|
|
179
|
+
break;
|
|
180
|
+
case 'n':
|
|
181
|
+
out += String.fromCharCode(10);
|
|
182
|
+
break;
|
|
183
|
+
case 'r':
|
|
184
|
+
out += String.fromCharCode(13);
|
|
185
|
+
break;
|
|
186
|
+
case 't':
|
|
187
|
+
out += String.fromCharCode(9);
|
|
188
|
+
break;
|
|
189
|
+
case 'u': {
|
|
190
|
+
const u = this.hex4();
|
|
191
|
+
if (u >= 0xd800 && u <= 0xdbff) {
|
|
192
|
+
if (this.s[this.i] === BS && this.s[this.i + 1] === 'u') {
|
|
193
|
+
this.i += 2;
|
|
194
|
+
const low = this.hex4();
|
|
195
|
+
if (low < 0xdc00 || low > 0xdfff)
|
|
196
|
+
throw new CoreError('lone_surrogate');
|
|
197
|
+
out += String.fromCharCode(u, low);
|
|
198
|
+
}
|
|
199
|
+
else
|
|
200
|
+
throw new CoreError('lone_surrogate');
|
|
201
|
+
}
|
|
202
|
+
else if (u >= 0xdc00 && u <= 0xdfff)
|
|
203
|
+
throw new CoreError('lone_surrogate');
|
|
204
|
+
else
|
|
205
|
+
out += String.fromCharCode(u);
|
|
206
|
+
break;
|
|
207
|
+
}
|
|
208
|
+
default:
|
|
209
|
+
throw new CoreError('json_bad_escape');
|
|
210
|
+
}
|
|
211
|
+
continue;
|
|
212
|
+
}
|
|
213
|
+
if (code >= 0xd800 && code <= 0xdbff) {
|
|
214
|
+
const n = this.i + 1 < this.s.length ? this.s.charCodeAt(this.i + 1) : 0;
|
|
215
|
+
if (n >= 0xdc00 && n <= 0xdfff) {
|
|
216
|
+
out += this.s[this.i] + this.s[this.i + 1];
|
|
217
|
+
this.i += 2;
|
|
218
|
+
continue;
|
|
219
|
+
}
|
|
220
|
+
throw new CoreError('lone_surrogate');
|
|
221
|
+
}
|
|
222
|
+
if (code >= 0xdc00 && code <= 0xdfff)
|
|
223
|
+
throw new CoreError('lone_surrogate');
|
|
224
|
+
out += this.s[this.i];
|
|
225
|
+
this.i++;
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
number() {
|
|
229
|
+
const start = this.i;
|
|
230
|
+
if (this.s[this.i] === '-')
|
|
231
|
+
this.i++;
|
|
232
|
+
if (!isDigit(this.s[this.i]))
|
|
233
|
+
throw new CoreError('json_bad_number');
|
|
234
|
+
if (this.s[this.i] === '0')
|
|
235
|
+
this.i++;
|
|
236
|
+
else
|
|
237
|
+
while (isDigit(this.s[this.i]))
|
|
238
|
+
this.i++;
|
|
239
|
+
let integerLiteral = true;
|
|
240
|
+
if (this.s[this.i] === '.') {
|
|
241
|
+
integerLiteral = false;
|
|
242
|
+
this.i++;
|
|
243
|
+
if (!isDigit(this.s[this.i]))
|
|
244
|
+
throw new CoreError('json_bad_number');
|
|
245
|
+
while (isDigit(this.s[this.i]))
|
|
246
|
+
this.i++;
|
|
247
|
+
}
|
|
248
|
+
if (this.s[this.i] === 'e' || this.s[this.i] === 'E') {
|
|
249
|
+
integerLiteral = false;
|
|
250
|
+
this.i++;
|
|
251
|
+
if (this.s[this.i] === '+' || this.s[this.i] === '-')
|
|
252
|
+
this.i++;
|
|
253
|
+
if (!isDigit(this.s[this.i]))
|
|
254
|
+
throw new CoreError('json_bad_number');
|
|
255
|
+
while (isDigit(this.s[this.i]))
|
|
256
|
+
this.i++;
|
|
257
|
+
}
|
|
258
|
+
const token = this.s.slice(start, this.i);
|
|
259
|
+
if (this.integersOnly) {
|
|
260
|
+
if (integerLiteral) {
|
|
261
|
+
if (token === '-0')
|
|
262
|
+
throw new CoreError('number_spelling');
|
|
263
|
+
const mag = BigInt(token.startsWith('-') ? token.slice(1) : token);
|
|
264
|
+
if (mag > 9007199254740991n)
|
|
265
|
+
throw new CoreError('number_not_safe_integer');
|
|
266
|
+
}
|
|
267
|
+
else {
|
|
268
|
+
// an integer-valued number written with a fraction or an exponent (1.0, 4e0) is a spelling problem (GR-45);
|
|
269
|
+
// a real fraction or a value beyond 2^53-1 is not a safe integer (GR-03)
|
|
270
|
+
const v = Number(token);
|
|
271
|
+
if (Number.isFinite(v) && Number.isInteger(v) && Math.abs(v) <= Number.MAX_SAFE_INTEGER)
|
|
272
|
+
throw new CoreError('number_spelling');
|
|
273
|
+
throw new CoreError('number_not_safe_integer');
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
return Number(token);
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
/** Parses JSON text strictly; throws CoreError with a stable code. */
|
|
280
|
+
export function parseJson(text, opts = {}) {
|
|
281
|
+
if (typeof text !== 'string')
|
|
282
|
+
throw new CoreError('json_not_text');
|
|
283
|
+
return new Parser(text, opts.integersOnly === true, opts.maxDepth ?? MAX_DEPTH).parseTop();
|
|
284
|
+
}
|
|
285
|
+
function escapeString(s) {
|
|
286
|
+
if (hasLoneSurrogate(s))
|
|
287
|
+
throw new CoreError('lone_surrogate');
|
|
288
|
+
let out = DQ;
|
|
289
|
+
for (let i = 0; i < s.length; i++) {
|
|
290
|
+
const c = s.charCodeAt(i);
|
|
291
|
+
if (c === 34)
|
|
292
|
+
out += BS + DQ;
|
|
293
|
+
else if (c === 92)
|
|
294
|
+
out += BS + BS;
|
|
295
|
+
else if (c === 8)
|
|
296
|
+
out += BS + 'b';
|
|
297
|
+
else if (c === 9)
|
|
298
|
+
out += BS + 't';
|
|
299
|
+
else if (c === 10)
|
|
300
|
+
out += BS + 'n';
|
|
301
|
+
else if (c === 12)
|
|
302
|
+
out += BS + 'f';
|
|
303
|
+
else if (c === 13)
|
|
304
|
+
out += BS + 'r';
|
|
305
|
+
else if (c < 0x20)
|
|
306
|
+
out += BS + 'u' + c.toString(16).padStart(4, '0');
|
|
307
|
+
else
|
|
308
|
+
out += s[i];
|
|
309
|
+
}
|
|
310
|
+
return out + DQ;
|
|
311
|
+
}
|
|
312
|
+
function canon(v, depth) {
|
|
313
|
+
if (depth > MAX_DEPTH)
|
|
314
|
+
throw new CoreError('json_too_deep');
|
|
315
|
+
if (v === null)
|
|
316
|
+
return 'null';
|
|
317
|
+
switch (typeof v) {
|
|
318
|
+
case 'boolean':
|
|
319
|
+
return v ? 'true' : 'false';
|
|
320
|
+
case 'number':
|
|
321
|
+
if (!Number.isFinite(v))
|
|
322
|
+
throw new CoreError('number_not_finite');
|
|
323
|
+
return String(v);
|
|
324
|
+
case 'string':
|
|
325
|
+
return escapeString(v);
|
|
326
|
+
case 'undefined':
|
|
327
|
+
throw new CoreError('undefined_value');
|
|
328
|
+
case 'object':
|
|
329
|
+
break;
|
|
330
|
+
default:
|
|
331
|
+
throw new CoreError('unsupported_type', typeof v);
|
|
332
|
+
}
|
|
333
|
+
if (Array.isArray(v)) {
|
|
334
|
+
const parts = [];
|
|
335
|
+
for (let i = 0; i < v.length; i++) {
|
|
336
|
+
if (!(i in v))
|
|
337
|
+
throw new CoreError('unsupported_type', 'sparse array');
|
|
338
|
+
parts.push(canon(v[i], depth + 1));
|
|
339
|
+
}
|
|
340
|
+
return '[' + parts.join(',') + ']';
|
|
341
|
+
}
|
|
342
|
+
if (!isPlainObject(v))
|
|
343
|
+
throw new CoreError('unsupported_type', 'object');
|
|
344
|
+
if (Object.getOwnPropertySymbols(v).length > 0)
|
|
345
|
+
throw new CoreError('unsupported_type', 'symbol key');
|
|
346
|
+
const keys = Object.keys(v).sort();
|
|
347
|
+
const parts = [];
|
|
348
|
+
for (const k of keys) {
|
|
349
|
+
const d = Object.getOwnPropertyDescriptor(v, k);
|
|
350
|
+
if (d === undefined || !('value' in d))
|
|
351
|
+
throw new CoreError('unsupported_type', 'accessor');
|
|
352
|
+
parts.push(escapeString(k) + ':' + canon(d.value, depth + 1));
|
|
353
|
+
}
|
|
354
|
+
return '{' + parts.join(',') + '}';
|
|
355
|
+
}
|
|
356
|
+
/** RFC 8785 text of an in-memory JSON value; throws CoreError for a value JSON cannot carry. */
|
|
357
|
+
export function canonicalize(value) {
|
|
358
|
+
return canon(value, 0);
|
|
359
|
+
}
|
|
360
|
+
/** Parse then canonicalize, with a named refusal instead of a throw. */
|
|
361
|
+
export function canonicalizeText(text) {
|
|
362
|
+
try {
|
|
363
|
+
return { ok: true, canonical: canonicalize(parseJson(text)) };
|
|
364
|
+
}
|
|
365
|
+
catch (e) {
|
|
366
|
+
if (e instanceof CoreError)
|
|
367
|
+
return { ok: false, reason: e.code };
|
|
368
|
+
throw e;
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
//# sourceMappingURL=jcs.js.map
|