@coderifts/sdk 3.13.2 → 3.14.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/README.md +49 -0
- package/dist/cjs/authorize.d.ts +176 -0
- package/dist/cjs/authorize.d.ts.map +1 -0
- package/dist/cjs/authorize.js +139 -0
- package/dist/cjs/authorize.js.map +1 -0
- package/dist/cjs/client.d.ts +31 -3
- package/dist/cjs/client.d.ts.map +1 -1
- package/dist/cjs/client.js +35 -5
- package/dist/cjs/client.js.map +1 -1
- package/dist/cjs/index.d.ts +4 -0
- package/dist/cjs/index.d.ts.map +1 -1
- package/dist/cjs/index.js +22 -1
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/vendor/package.json +1 -0
- package/dist/cjs/vendor/receipt-verifier/VENDOR.sha256 +41 -0
- package/dist/cjs/vendor/receipt-verifier/arity.js +53 -0
- package/dist/cjs/vendor/receipt-verifier/evidence-root.js +188 -0
- package/dist/cjs/vendor/receipt-verifier/verified-execution-binding.js +507 -0
- package/dist/cjs/vendor/receipt-verifier/verify-evidence.js +410 -0
- package/dist/cjs/vendor/receipt-verifier/verify-grant.js +597 -0
- package/dist/cjs/vendor/receipt-verifier/verify-prove-transcript.js +72 -0
- package/dist/cjs/vendor/receipt-verifier/verify.d.ts +31 -0
- package/dist/cjs/vendor/receipt-verifier/verify.js +454 -0
- package/dist/cjs/verify-receipt-local.d.ts +69 -0
- package/dist/cjs/verify-receipt-local.d.ts.map +1 -0
- package/dist/cjs/verify-receipt-local.js +103 -0
- package/dist/cjs/verify-receipt-local.js.map +1 -0
- package/dist/esm/authorize.d.ts +176 -0
- package/dist/esm/authorize.d.ts.map +1 -0
- package/dist/esm/authorize.js +135 -0
- package/dist/esm/authorize.js.map +1 -0
- package/dist/esm/client.d.ts +31 -3
- package/dist/esm/client.d.ts.map +1 -1
- package/dist/esm/client.js +35 -5
- package/dist/esm/client.js.map +1 -1
- package/dist/esm/index.d.ts +4 -0
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.js +18 -0
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/vendor/package.json +1 -0
- package/dist/esm/vendor/receipt-verifier/VENDOR.sha256 +41 -0
- package/dist/esm/vendor/receipt-verifier/arity.js +53 -0
- package/dist/esm/vendor/receipt-verifier/evidence-root.js +188 -0
- package/dist/esm/vendor/receipt-verifier/verified-execution-binding.js +507 -0
- package/dist/esm/vendor/receipt-verifier/verify-evidence.js +410 -0
- package/dist/esm/vendor/receipt-verifier/verify-grant.js +597 -0
- package/dist/esm/vendor/receipt-verifier/verify-prove-transcript.js +72 -0
- package/dist/esm/vendor/receipt-verifier/verify.d.ts +31 -0
- package/dist/esm/vendor/receipt-verifier/verify.js +454 -0
- package/dist/esm/verify-receipt-local.d.ts +69 -0
- package/dist/esm/verify-receipt-local.d.ts.map +1 -0
- package/dist/esm/verify-receipt-local.js +97 -0
- package/dist/esm/verify-receipt-local.js.map +1 -0
- package/package.json +4 -3
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
# VENDORED FROM receipt-verifier — DO NOT EDIT IN PLACE.
|
|
2
|
+
#
|
|
3
|
+
# The SDK's authorize() QUOTES the shared predicate rather than reimplementing it. A local edit
|
|
4
|
+
# here would be a second implementation wearing the first one's name, which is the failure the
|
|
5
|
+
# whole 1459 consolidation removed: one question, several formulas, disagreeing answers.
|
|
6
|
+
#
|
|
7
|
+
# PER-FILE PROVENANCE. The closure is vendored at each file's own revision — a single
|
|
8
|
+
# source-commit line would be tidier and untrue.
|
|
9
|
+
#
|
|
10
|
+
# arity.js 5ef4dfb19d0ef60d93fe4282f28e38182fc237f5
|
|
11
|
+
# verify.js e0806f31a9db11ba5ad7a6075ff2b5d0e517eb83
|
|
12
|
+
# verify-grant.js a472bf9073781cba25d83c7d1406b1a7c4af0b94
|
|
13
|
+
# verify-prove-transcript.js 724aa9ae8171f1acf629c3c6b4879dc056575f20
|
|
14
|
+
# verify-evidence.js 16cf6654ff3fa6d6293eb4a425bbe7fb6999ee26
|
|
15
|
+
# evidence-root.js 16cf6654ff3fa6d6293eb4a425bbe7fb6999ee26
|
|
16
|
+
# verified-execution-binding.js WORKING-TREE (the core verifies the decision receipt)
|
|
17
|
+
|
|
18
|
+
# ── THE RECEIPT-VERIFIER CORE IS PINNED TO A RELEASED TAG ───────────────────────────────────
|
|
19
|
+
#
|
|
20
|
+
# The shared verification core here comes from receipt-verifier **v1.0.0**, peeled commit
|
|
21
|
+
# 51a8224439959a5b46c0b09e9a2cd67117f05d56.
|
|
22
|
+
#
|
|
23
|
+
# It was pinned to a WORKING TREE and to per-file commits. Both are honest about where the bytes
|
|
24
|
+
# came from and neither is a provenance a stranger can resolve: a working tree is not fetchable,
|
|
25
|
+
# so "the vendored bytes match upstream" reduced to "they match whatever is on this machine right
|
|
26
|
+
# now". A released tag is a name anyone can check out — that is the difference between a pin and
|
|
27
|
+
# a note.
|
|
28
|
+
#
|
|
29
|
+
# The hash lines below are UNCHANGED by the re-pin. Where a file already matched the tag this is
|
|
30
|
+
# prose only; where it did not, it was re-copied from the tag and that is recorded below.
|
|
31
|
+
#
|
|
32
|
+
# source_commit: 51a8224439959a5b46c0b09e9a2cd67117f05d56 (receipt-verifier v1.0.0)
|
|
33
|
+
#
|
|
34
|
+
|
|
35
|
+
721fcac58b960b5e2aa1af91edb6cfc87ebe828a6da73879967ef79a1ca474e8 arity.js
|
|
36
|
+
348d3f851cd79bf63298b51da422d11be980820576ab0bf0a2990b9f007d6249 verify.js
|
|
37
|
+
4a0ad5bd7bb8282e086bea99dcaf8ca278370d80019c5681d2942bf11bc87504 verify-grant.js
|
|
38
|
+
3bb17bd4f16d5ee3cf3fbb754b4df9aa570a615ca94ff2a97b751c4fabd3bd0d verify-prove-transcript.js
|
|
39
|
+
98cd9b989a25095e0442f91f68a1adecd6e6a2a5b05902bf2580b8cba973c5e2 verify-evidence.js
|
|
40
|
+
4d5476fc44bbfc2a847feeb313a1c6c08ef7fd832a2348ef3c244bd8d3f03fcd evidence-root.js
|
|
41
|
+
9d0259e916f2bcd32029744c3e9ec81448bcefa46e6ad3f054c8a650dc0482b7 verified-execution-binding.js
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* 1129 — unified (token, opts) with opts.ctx / opts.intended.
|
|
5
|
+
* 3-ary (token, ctx, opts) wrappers warn once and forward.
|
|
6
|
+
* 2-ary verifiers keep the 1128 throw on a third argument.
|
|
7
|
+
*/
|
|
8
|
+
const warned = new Set();
|
|
9
|
+
|
|
10
|
+
function warnOnce(name) {
|
|
11
|
+
if (warned.has(name)) return;
|
|
12
|
+
warned.add(name);
|
|
13
|
+
const msg = `DEPRECATION: ${name}(token, ctx, opts) is deprecated; use ${name}(token, { ctx, intended }). This warning is emitted once.`;
|
|
14
|
+
if (typeof process !== 'undefined' && typeof process.emitWarning === 'function') {
|
|
15
|
+
process.emitWarning(msg, 'DeprecationWarning');
|
|
16
|
+
} else {
|
|
17
|
+
console.warn(msg);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function throw1128(name, n, consequence) {
|
|
22
|
+
throw new Error(
|
|
23
|
+
`${name}(token, opts) — pass intended via opts.intended. `
|
|
24
|
+
+ `Received ${n} arguments; the third would be ignored and the cross-check `
|
|
25
|
+
+ `would silently not run, grading a mismatched artifact ${consequence}.`,
|
|
26
|
+
);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function looksUnified(obj) {
|
|
30
|
+
if (!obj || typeof obj !== 'object' || Array.isArray(obj)) return false;
|
|
31
|
+
// perSlot is the bundle-dispatch unified shape: verifyBundle(bundle, { ctx, perSlot }).
|
|
32
|
+
// Without it, `{ perSlot }` was treated as a bare ctx and opts.perSlot vanished.
|
|
33
|
+
return obj.ctx != null || obj.intended != null || obj.envelope != null || obj.perSlot != null;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function split3ary(name, nArgs, second, third) {
|
|
37
|
+
if (nArgs > 3) throw1128(name, nArgs, 'VALID');
|
|
38
|
+
if (nArgs === 3) {
|
|
39
|
+
warnOnce(name);
|
|
40
|
+
return { ctx: second || {}, opts: third && typeof third === 'object' ? third : {} };
|
|
41
|
+
}
|
|
42
|
+
const o = second && typeof second === 'object' ? second : {};
|
|
43
|
+
if (looksUnified(o)) {
|
|
44
|
+
return { ctx: o.ctx || {}, opts: o };
|
|
45
|
+
}
|
|
46
|
+
return { ctx: o, opts: {} };
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function _resetWarnedForTest() {
|
|
50
|
+
warned.clear();
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
module.exports = { warnOnce, throw1128, split3ary, looksUnified, _resetWarnedForTest };
|
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* cr.evidence.root.v1 — ONE signed manifest that binds a set of tokens to ONE run.
|
|
5
|
+
*
|
|
6
|
+
* ── THE ATTACK THIS EXISTS FOR (1432) ───────────────────────────────────────────────────────
|
|
7
|
+
*
|
|
8
|
+
* 1423 made every token in a prove artifact authenticate against its issuer's key. That closed
|
|
9
|
+
* forgery and left something open, which the second auditor found and which was reproduced three
|
|
10
|
+
* ways before this file existed: take a REAL second run of the same producer, at the same commit,
|
|
11
|
+
* and move one of ITS tokens into the first run's artifact. Recompute the pin. Everything still
|
|
12
|
+
* verifies — because nothing was forged. Each token really was issued, really is signed, and
|
|
13
|
+
* really says what it says.
|
|
14
|
+
*
|
|
15
|
+
* transcript_token from run B → graded COVERED
|
|
16
|
+
* execution_grant from run B → graded COVERED
|
|
17
|
+
* chain_receipt from run B → graded COVERED
|
|
18
|
+
*
|
|
19
|
+
* Authenticity is a property of a TOKEN. "These tokens are one run" is a property of a SET, and no
|
|
20
|
+
* per-token signature can carry it. So a set needs its own signature.
|
|
21
|
+
*
|
|
22
|
+
* ── WHAT THE ROOT IS, AND WHAT IT IS NOT ────────────────────────────────────────────────────
|
|
23
|
+
*
|
|
24
|
+
* It is the producer saying, under its own key: "this run emitted exactly these bytes". The
|
|
25
|
+
* binding is the sha256 of each token's EXACT bytes, not a claim copied out of it — a substituted
|
|
26
|
+
* token has different bytes, so its digest cannot match, whatever it says inside.
|
|
27
|
+
*
|
|
28
|
+
* It is NOT a second opinion on any token's validity. A root cannot make an expired grant current
|
|
29
|
+
* or a bad signature good; every per-token check still runs and still decides. The root adds one
|
|
30
|
+
* sentence the others could not say.
|
|
31
|
+
*
|
|
32
|
+
* ── WHY IT IS SIGNED BY THE EXECUTOR ────────────────────────────────────────────────────────
|
|
33
|
+
*
|
|
34
|
+
* The executor is the only party present for the whole run: it mints the challenge, consumes the
|
|
35
|
+
* grant, seals the attestation and signs the transcript. The issuer sees one authorize; the
|
|
36
|
+
* provider sees one merge. A manifest of the run has to be signed by whoever witnessed the run,
|
|
37
|
+
* and that is the executor — the same key the correlation already uses, deliberately, so a reader
|
|
38
|
+
* verifying one is verifying the other's signer too.
|
|
39
|
+
*
|
|
40
|
+
* The residual is stated rather than hidden: this is the EXECUTOR's account of its own run. It
|
|
41
|
+
* makes splicing detectable, not impossible for the executor itself. An executor that lies about
|
|
42
|
+
* its own run was never constrained by its own signature — what the root removes is the ability of
|
|
43
|
+
* a THIRD party (anyone who can edit a vendored artifact) to assemble two honest runs into one.
|
|
44
|
+
*/
|
|
45
|
+
|
|
46
|
+
const crypto = require('node:crypto');
|
|
47
|
+
|
|
48
|
+
const ROOT_V = 'cr.evidence.root.v1';
|
|
49
|
+
const ROOT_SIGNING_PREFIX = 'crevidenceroot.v1';
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* The slots a root accounts for. MANDATORY ones must be present and non-null: a root that simply
|
|
53
|
+
* omits a token would let deletion — the strongest tamper there is — read as "not applicable".
|
|
54
|
+
*/
|
|
55
|
+
const SLOTS = Object.freeze({
|
|
56
|
+
chain_receipt: { mandatory: true },
|
|
57
|
+
execution_grant: { mandatory: true },
|
|
58
|
+
transcript_token: { mandatory: true },
|
|
59
|
+
correlation: { mandatory: true },
|
|
60
|
+
atomic_attestation: { mandatory: false },
|
|
61
|
+
provider_readback: { mandatory: false },
|
|
62
|
+
});
|
|
63
|
+
const SLOT_NAMES = Object.freeze(Object.keys(SLOTS));
|
|
64
|
+
|
|
65
|
+
const sha256pref = (bytes) =>
|
|
66
|
+
`sha256:${crypto.createHash('sha256').update(bytes).digest('hex')}`;
|
|
67
|
+
|
|
68
|
+
/** RFC 8785-shaped canonical JSON: sorted keys, no whitespace, no invented values. */
|
|
69
|
+
function canonicalJson(value) {
|
|
70
|
+
if (value === null) return 'null';
|
|
71
|
+
const t = typeof value;
|
|
72
|
+
if (t === 'boolean' || t === 'string') return JSON.stringify(value);
|
|
73
|
+
if (t === 'number') {
|
|
74
|
+
if (!Number.isFinite(value)) throw new TypeError('canonicalJson: non-finite number');
|
|
75
|
+
return JSON.stringify(value);
|
|
76
|
+
}
|
|
77
|
+
if (t === 'undefined') throw new TypeError('canonicalJson: undefined');
|
|
78
|
+
if (Array.isArray(value)) return `[${value.map(canonicalJson).join(',')}]`;
|
|
79
|
+
const keys = Object.keys(value).sort();
|
|
80
|
+
return `{${keys.map((k) => `${JSON.stringify(k)}:${canonicalJson(value[k])}`).join(',')}}`;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* The exact bytes signed. The WHOLE body under canonical JSON, so every field is covered and a
|
|
85
|
+
* future field cannot be added without breaking the signature.
|
|
86
|
+
*/
|
|
87
|
+
function rootSigningInput(body) {
|
|
88
|
+
return `${ROOT_SIGNING_PREFIX}|${canonicalJson(body)}`;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Digest a token exactly as it travels.
|
|
93
|
+
*
|
|
94
|
+
* A STRING is hashed as utf8 bytes. An OBJECT — the correlation is one — is hashed as canonical
|
|
95
|
+
* JSON, so key order in a re-serialised artifact cannot change the digest of a value nobody
|
|
96
|
+
* edited. Absent is null, never the empty-string hash: `sha256('')` is a real value and would
|
|
97
|
+
* make "no token" indistinguishable from "a token that happens to be empty".
|
|
98
|
+
*/
|
|
99
|
+
function digestToken(token) {
|
|
100
|
+
if (token == null) return null;
|
|
101
|
+
if (typeof token === 'string') return token.length === 0 ? null : sha256pref(Buffer.from(token, 'utf8'));
|
|
102
|
+
return sha256pref(Buffer.from(canonicalJson(token), 'utf8'));
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* Build and sign a root.
|
|
107
|
+
*
|
|
108
|
+
* @param {object} o
|
|
109
|
+
* @param {string} o.run_id
|
|
110
|
+
* @param {{name: string, version: string, commit: string|null}} o.producer
|
|
111
|
+
* @param {string} o.operation
|
|
112
|
+
* @param {string} o.target_uri
|
|
113
|
+
* @param {string|null} o.contract_commit
|
|
114
|
+
* @param {object} o.tokens slot name → the token as it travels (string or object)
|
|
115
|
+
* @param {object} o.claims { grant_id, receipt_hash, scope_hash, policy_hash, state_token_hash }
|
|
116
|
+
* @param {import('crypto').KeyObject} o.privateKey
|
|
117
|
+
* @param {string} o.executor_kid
|
|
118
|
+
*/
|
|
119
|
+
function buildEvidenceRoot(o) {
|
|
120
|
+
const artifact_digests = {};
|
|
121
|
+
for (const name of SLOT_NAMES) {
|
|
122
|
+
artifact_digests[name] = digestToken(o.tokens ? o.tokens[name] : null);
|
|
123
|
+
}
|
|
124
|
+
const c = o.claims || {};
|
|
125
|
+
const body = {
|
|
126
|
+
v: ROOT_V,
|
|
127
|
+
run_id: String(o.run_id),
|
|
128
|
+
executor_kid: String(o.executor_kid),
|
|
129
|
+
producer: {
|
|
130
|
+
name: String(o.producer.name),
|
|
131
|
+
version: String(o.producer.version),
|
|
132
|
+
commit: o.producer.commit == null ? null : String(o.producer.commit),
|
|
133
|
+
},
|
|
134
|
+
operation: o.operation == null ? null : String(o.operation),
|
|
135
|
+
target_uri: o.target_uri == null ? null : String(o.target_uri),
|
|
136
|
+
contract_commit: o.contract_commit == null ? null : String(o.contract_commit),
|
|
137
|
+
artifact_digests,
|
|
138
|
+
// The CLAIMS the run asserts. They are ALSO inside the tokens; carrying them here is what
|
|
139
|
+
// lets a verifier compare the two and refuse a manifest that agrees with itself but not with
|
|
140
|
+
// its own evidence.
|
|
141
|
+
grant_id: c.grant_id == null ? null : String(c.grant_id),
|
|
142
|
+
receipt_hash: c.receipt_hash == null ? null : String(c.receipt_hash),
|
|
143
|
+
scope_hash: c.scope_hash == null ? null : String(c.scope_hash),
|
|
144
|
+
policy_hash: c.policy_hash == null ? null : String(c.policy_hash),
|
|
145
|
+
state_token_hash: c.state_token_hash == null ? null : String(c.state_token_hash),
|
|
146
|
+
};
|
|
147
|
+
const signature = crypto.sign(null, Buffer.from(rootSigningInput(body), 'utf8'), o.privateKey);
|
|
148
|
+
return { ...body, signature: signature.toString('base64url') };
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
/** Verify a root's own signature. Says nothing about the tokens — that is verifyEvidenceEnvelope. */
|
|
152
|
+
function verifyEvidenceRoot(root, publicKey) {
|
|
153
|
+
if (!root || root.v !== ROOT_V) {
|
|
154
|
+
return { valid: false, status: 'ROOT_MALFORMED', reason: 'not_an_evidence_root' };
|
|
155
|
+
}
|
|
156
|
+
if (typeof root.signature !== 'string' || root.signature.length === 0) {
|
|
157
|
+
return { valid: false, status: 'ROOT_MALFORMED', reason: 'no_signature' };
|
|
158
|
+
}
|
|
159
|
+
if (!publicKey) {
|
|
160
|
+
return { valid: false, status: 'ROOT_UNKNOWN_KEY', reason: 'unknown_kid' };
|
|
161
|
+
}
|
|
162
|
+
const { signature, ...body } = root;
|
|
163
|
+
let ok = false;
|
|
164
|
+
try {
|
|
165
|
+
ok = crypto.verify(
|
|
166
|
+
null, Buffer.from(rootSigningInput(body), 'utf8'), publicKey,
|
|
167
|
+
Buffer.from(signature, 'base64url'),
|
|
168
|
+
);
|
|
169
|
+
} catch (_) {
|
|
170
|
+
return { valid: false, status: 'ROOT_INVALID_SIGNATURE', reason: 'signature_error' };
|
|
171
|
+
}
|
|
172
|
+
return ok
|
|
173
|
+
? { valid: true, status: 'ROOT_VALID' }
|
|
174
|
+
: { valid: false, status: 'ROOT_INVALID_SIGNATURE', reason: 'signature_mismatch' };
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
module.exports = {
|
|
178
|
+
ROOT_V,
|
|
179
|
+
ROOT_SIGNING_PREFIX,
|
|
180
|
+
SLOTS,
|
|
181
|
+
SLOT_NAMES,
|
|
182
|
+
canonicalJson,
|
|
183
|
+
rootSigningInput,
|
|
184
|
+
digestToken,
|
|
185
|
+
buildEvidenceRoot,
|
|
186
|
+
verifyEvidenceRoot,
|
|
187
|
+
sha256pref,
|
|
188
|
+
};
|