@kya-os/mcp 1.13.0 → 1.14.2
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 +71 -0
- package/README.md +12 -0
- package/dist/card/delegation.d.ts +4 -4
- package/dist/card/delegation.d.ts.map +1 -1
- package/dist/card/delegation.js +2 -2
- package/dist/card/delegation.js.map +1 -1
- package/dist/card/revocation.d.ts +9 -3
- package/dist/card/revocation.d.ts.map +1 -1
- package/dist/card/revocation.js +6 -53
- package/dist/card/revocation.js.map +1 -1
- package/dist/card/verify.d.ts +2 -2
- package/dist/card/verify.d.ts.map +1 -1
- package/dist/card/verify.js.map +1 -1
- package/dist/delegation/bitstring.d.ts +6 -0
- package/dist/delegation/bitstring.d.ts.map +1 -1
- package/dist/delegation/bitstring.js +8 -48
- package/dist/delegation/bitstring.js.map +1 -1
- package/dist/delegation/did-key-resolver.d.ts +4 -0
- package/dist/delegation/did-key-resolver.d.ts.map +1 -1
- package/dist/delegation/did-key-resolver.js +2 -2
- package/dist/delegation/did-key-resolver.js.map +1 -1
- package/dist/delegation/index.d.ts +1 -0
- package/dist/delegation/index.d.ts.map +1 -1
- package/dist/delegation/index.js +1 -0
- package/dist/delegation/index.js.map +1 -1
- package/dist/delegation/statuslist-manager.d.ts.map +1 -1
- package/dist/delegation/statuslist-manager.js +4 -11
- package/dist/delegation/statuslist-manager.js.map +1 -1
- package/dist/delegation/vc-jwt-verify.d.ts.map +1 -1
- package/dist/delegation/vc-jwt-verify.js +5 -3
- package/dist/delegation/vc-jwt-verify.js.map +1 -1
- package/dist/delegation/vc-verification-checks.d.ts.map +1 -1
- package/dist/delegation/vc-verification-checks.js +3 -2
- package/dist/delegation/vc-verification-checks.js.map +1 -1
- package/dist/delegation/verification-method-key.d.ts +15 -0
- package/dist/delegation/verification-method-key.d.ts.map +1 -0
- package/dist/delegation/verification-method-key.js +56 -0
- package/dist/delegation/verification-method-key.js.map +1 -0
- package/dist/integrations/cheqd/dlr.d.ts +9 -1
- package/dist/integrations/cheqd/dlr.d.ts.map +1 -1
- package/dist/integrations/cheqd/dlr.js +25 -0
- package/dist/integrations/cheqd/dlr.js.map +1 -1
- package/dist/integrations/cheqd/index.d.ts +1 -0
- package/dist/integrations/cheqd/index.d.ts.map +1 -1
- package/dist/integrations/cheqd/index.js +1 -0
- package/dist/integrations/cheqd/index.js.map +1 -1
- package/dist/integrations/cheqd/statuslist-resolver.d.ts +74 -0
- package/dist/integrations/cheqd/statuslist-resolver.d.ts.map +1 -0
- package/dist/integrations/cheqd/statuslist-resolver.js +138 -0
- package/dist/integrations/cheqd/statuslist-resolver.js.map +1 -0
- package/dist/middleware/with-kya-os.delegation-gate.d.ts.map +1 -1
- package/dist/middleware/with-kya-os.delegation-gate.js +13 -53
- package/dist/middleware/with-kya-os.delegation-gate.js.map +1 -1
- package/dist/middleware/with-kya-os.delegation-verify.d.ts +23 -10
- package/dist/middleware/with-kya-os.delegation-verify.d.ts.map +1 -1
- package/dist/middleware/with-kya-os.delegation-verify.js +68 -2
- package/dist/middleware/with-kya-os.delegation-verify.js.map +1 -1
- package/dist/utils/statuslist-bits.d.ts +51 -0
- package/dist/utils/statuslist-bits.d.ts.map +1 -0
- package/dist/utils/statuslist-bits.js +106 -0
- package/dist/utils/statuslist-bits.js.map +1 -0
- package/package.json +13 -13
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
import { verificationMethodJwk } from '../../delegation/verification-method-key.js';
|
|
2
|
+
import { canonicalizeJSON } from '../../delegation/utils.js';
|
|
3
|
+
import { decodeStatusListPayload, parseStatusListIndex, readStatusBit, } from '../../utils/statuslist-bits.js';
|
|
4
|
+
import { assertStatusPurpose } from '../../utils/statuslist-purpose.js';
|
|
5
|
+
import { base64urlDecodeToBytes, bytesToBase64 } from '../../utils/base64.js';
|
|
6
|
+
import { TtlCache } from '../../utils/ttl-cache.js';
|
|
7
|
+
export class CheqdStatusListResolver {
|
|
8
|
+
opts;
|
|
9
|
+
cacheTtlMs;
|
|
10
|
+
cache;
|
|
11
|
+
bustNextFetch = false;
|
|
12
|
+
constructor(options) {
|
|
13
|
+
this.opts = options;
|
|
14
|
+
this.cacheTtlMs = options.cacheTtlMs ?? 10_000;
|
|
15
|
+
// A single issuer realistically publishes a handful of lists; 16 entries
|
|
16
|
+
// is generous without being unbounded.
|
|
17
|
+
this.cache = new TtlCache({
|
|
18
|
+
ttlMs: this.cacheTtlMs,
|
|
19
|
+
maxEntries: 16,
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
/** Drop the cached list and defeat upstream HTTP caches on the next fetch. */
|
|
23
|
+
invalidateCache() {
|
|
24
|
+
this.cache.clear();
|
|
25
|
+
this.bustNextFetch = true;
|
|
26
|
+
}
|
|
27
|
+
/** TRUE = revoked. Throws on anything unprovable — the verifier fails closed. */
|
|
28
|
+
async checkStatus(status) {
|
|
29
|
+
const url = status.statusListCredential;
|
|
30
|
+
if (typeof url !== 'string' || !/^https:\/\//.test(url)) {
|
|
31
|
+
throw new Error('credentialStatus.statusListCredential must be an https URL');
|
|
32
|
+
}
|
|
33
|
+
const index = parseStatusListIndex(status.statusListIndex);
|
|
34
|
+
const credential = await this.fetchAndVerifyList(url);
|
|
35
|
+
// Purpose parity, fail-closed (shared validator): a clear bit on the WRONG
|
|
36
|
+
// KIND of list would report "not revoked" from a list that never tracked
|
|
37
|
+
// revocation.
|
|
38
|
+
assertStatusPurpose(credential.credentialSubject.statusPurpose, status.statusPurpose);
|
|
39
|
+
const bits = await decodeStatusListPayload(credential.credentialSubject.encodedList, (bytes) => this.opts.decompressor.decompress(bytes));
|
|
40
|
+
return readStatusBit(bits, index);
|
|
41
|
+
}
|
|
42
|
+
async fetchAndVerifyList(url) {
|
|
43
|
+
const cached = this.cache.get(url);
|
|
44
|
+
if (cached) {
|
|
45
|
+
return cached;
|
|
46
|
+
}
|
|
47
|
+
// NEVER append query params here: the cheqd resolver parses the query as
|
|
48
|
+
// DID URL dereferencing input and 400s (invalidDidUrl) on unknown params
|
|
49
|
+
// (verified live). The endpoint is served cf-cache-status DYNAMIC, so
|
|
50
|
+
// post-revocation freshness only needs a no-cache header.
|
|
51
|
+
const response = await this.opts.fetchProvider.fetch(url, {
|
|
52
|
+
method: 'GET',
|
|
53
|
+
headers: {
|
|
54
|
+
Accept: 'application/json',
|
|
55
|
+
...(this.bustNextFetch
|
|
56
|
+
? { 'Cache-Control': 'no-cache', Pragma: 'no-cache' }
|
|
57
|
+
: {}),
|
|
58
|
+
},
|
|
59
|
+
});
|
|
60
|
+
if (!response.ok) {
|
|
61
|
+
throw new Error(`Status list fetch failed: HTTP ${response.status} for ${url}`);
|
|
62
|
+
}
|
|
63
|
+
const body = (await response.json());
|
|
64
|
+
this.assertShape(body);
|
|
65
|
+
this.assertIssuer(body);
|
|
66
|
+
await this.assertSignature(body);
|
|
67
|
+
this.bustNextFetch = false;
|
|
68
|
+
this.cache.set(url, body);
|
|
69
|
+
return body;
|
|
70
|
+
}
|
|
71
|
+
assertShape(vc) {
|
|
72
|
+
const types = Array.isArray(vc?.type) ? vc.type : [];
|
|
73
|
+
if (!types.includes('StatusList2021Credential')) {
|
|
74
|
+
throw new Error('Fetched resource is not a StatusList2021Credential');
|
|
75
|
+
}
|
|
76
|
+
const subject = vc.credentialSubject;
|
|
77
|
+
if (subject?.type !== 'StatusList2021' ||
|
|
78
|
+
typeof subject.encodedList !== 'string' ||
|
|
79
|
+
subject.encodedList.length === 0) {
|
|
80
|
+
throw new Error('Status list credentialSubject is malformed (missing StatusList2021 encodedList)');
|
|
81
|
+
}
|
|
82
|
+
if (!vc.proof || typeof vc.proof !== 'object') {
|
|
83
|
+
throw new Error('Status list credential is unsigned');
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
assertIssuer(vc) {
|
|
87
|
+
const issuer = typeof vc.issuer === 'string' ? vc.issuer : vc.issuer?.id;
|
|
88
|
+
if (issuer !== this.opts.expectedIssuerDid) {
|
|
89
|
+
throw new Error(`Status list issuer "${issuer}" is not the expected issuer "${this.opts.expectedIssuerDid}"`);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Verify the Ed25519Signature2020 proof over the JCS-canonicalized VC
|
|
94
|
+
* (minus `proof`) against the issuer's on-chain DID document. Key material
|
|
95
|
+
* arrives however the DID method publishes it — `verificationMethodJwk`
|
|
96
|
+
* accepts `publicKeyJwk`, `publicKeyMultibase` (cheqd's format), or legacy
|
|
97
|
+
* `publicKeyBase58`.
|
|
98
|
+
*/
|
|
99
|
+
async assertSignature(vc) {
|
|
100
|
+
const proof = vc.proof;
|
|
101
|
+
const proofValue = proof['proofValue'];
|
|
102
|
+
if (typeof proofValue !== 'string' || proofValue.length === 0) {
|
|
103
|
+
throw new Error('Status list proof is missing proofValue');
|
|
104
|
+
}
|
|
105
|
+
const unsigned = { ...vc };
|
|
106
|
+
delete unsigned['proof'];
|
|
107
|
+
const data = new TextEncoder().encode(canonicalizeJSON(unsigned));
|
|
108
|
+
const signature = base64urlDecodeToBytes(proofValue);
|
|
109
|
+
const didDoc = await this.opts.didResolver.resolve(this.opts.expectedIssuerDid);
|
|
110
|
+
if (!didDoc) {
|
|
111
|
+
throw new Error(`Could not resolve issuer DID ${this.opts.expectedIssuerDid}`);
|
|
112
|
+
}
|
|
113
|
+
const verificationMethodId = typeof proof['verificationMethod'] === 'string'
|
|
114
|
+
? proof['verificationMethod']
|
|
115
|
+
: undefined;
|
|
116
|
+
const methods = didDoc.verificationMethod ?? [];
|
|
117
|
+
const candidates = verificationMethodId
|
|
118
|
+
? methods.filter((m) => m.id === verificationMethodId)
|
|
119
|
+
: methods;
|
|
120
|
+
if (candidates.length === 0) {
|
|
121
|
+
throw new Error(`Issuer DID document has no verification method matching "${verificationMethodId ?? '(any)'}"`);
|
|
122
|
+
}
|
|
123
|
+
for (const method of candidates) {
|
|
124
|
+
const jwk = verificationMethodJwk(method);
|
|
125
|
+
if (!jwk)
|
|
126
|
+
continue;
|
|
127
|
+
const publicKeyBase64 = bytesToBase64(base64urlDecodeToBytes(jwk.x));
|
|
128
|
+
if (await this.opts.cryptoProvider.verify(data, signature, publicKeyBase64)) {
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
throw new Error('Status list signature verification FAILED against the issuer DID document');
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
export function createCheqdStatusListResolver(options) {
|
|
136
|
+
return new CheqdStatusListResolver(options);
|
|
137
|
+
}
|
|
138
|
+
//# sourceMappingURL=statuslist-resolver.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"statuslist-resolver.js","sourceRoot":"","sources":["../../../src/integrations/cheqd/statuslist-resolver.ts"],"names":[],"mappings":"AAqCA,OAAO,EAAE,qBAAqB,EAAE,MAAM,6CAA6C,CAAC;AACpF,OAAO,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAC;AAC7D,OAAO,EACL,uBAAuB,EACvB,oBAAoB,EACpB,aAAa,GACd,MAAM,gCAAgC,CAAC;AACxC,OAAO,EAAE,mBAAmB,EAAE,MAAM,mCAAmC,CAAC;AACxE,OAAO,EAAE,sBAAsB,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AAC9E,OAAO,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AAsBpD,MAAM,OAAO,uBAAuB;IACjB,IAAI,CAAiC;IACrC,UAAU,CAAS;IAC5B,KAAK,CAAqC;IAC1C,aAAa,GAAG,KAAK,CAAC;IAE9B,YAAY,OAAuC;QACjD,IAAI,CAAC,IAAI,GAAG,OAAO,CAAC;QACpB,IAAI,CAAC,UAAU,GAAG,OAAO,CAAC,UAAU,IAAI,MAAM,CAAC;QAC/C,yEAAyE;QACzE,uCAAuC;QACvC,IAAI,CAAC,KAAK,GAAG,IAAI,QAAQ,CAA2B;YAClD,KAAK,EAAE,IAAI,CAAC,UAAU;YACtB,UAAU,EAAE,EAAE;SACf,CAAC,CAAC;IACL,CAAC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AAuC;IAEvC,OAAO,IAAI,uBAAuB,CAAC,OAAO,CAAC,CAAC;AAC9C,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"with-kya-os.delegation-gate.d.ts","sourceRoot":"","sources":["../../src/middleware/with-kya-os.delegation-gate.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;
|
|
1
|
+
{"version":3,"file":"with-kya-os.delegation-gate.d.ts","sourceRoot":"","sources":["../../src/middleware/with-kya-os.delegation-gate.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAYH,OAAO,KAAK,EAEV,mBAAmB,EACpB,MAAM,wBAAwB,CAAC;AAChC,OAAO,KAAK,EAAE,cAAc,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAChF,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAkC/D,gFAAgF;AAChF,MAAM,WAAW,oBAAoB;IACnC,kBAAkB,EAAE,kBAAkB,CAAC;IACvC,oBAAoB,EAAE,eAAe,CAAC,sBAAsB,CAAC,CAAC;IAC9D,kBAAkB,EAAE,eAAe,CAAC,oBAAoB,CAAC,CAAC;CAC3D;AAED,wBAAgB,oBAAoB,CAClC,IAAI,EAAE,cAAc,EACpB,MAAM,EAAE,oBAAoB,GAC3B,IAAI,CAAC,mBAAmB,EAAE,oBAAoB,CAAC,CAsQjD"}
|
|
@@ -8,7 +8,6 @@
|
|
|
8
8
|
*/
|
|
9
9
|
import { isHolderBindingApplicable, isKyaOsControlArg, assertHolderBinding, toHolderBindingRequest, } from "../delegation/holder-binding.js";
|
|
10
10
|
import { scopeSatisfies } from "../delegation/scope-matcher.js";
|
|
11
|
-
import { parseVCJWT } from "../delegation/utils.js";
|
|
12
11
|
import { logger } from "../logging/index.js";
|
|
13
12
|
import { KYA_OS_ERROR_CODES } from "../errors.js";
|
|
14
13
|
import { sanitizeForMessage } from "./with-kya-os.helpers.js";
|
|
@@ -44,7 +43,7 @@ function rejectedDelegationRef(value) {
|
|
|
44
43
|
export function createDelegationGate(deps, wiring) {
|
|
45
44
|
const { identity, holderBindingMode, holderBindingVerifier, audit, cryptoProvider } = deps;
|
|
46
45
|
const { attachOutcomeProof, resolveExistingGrant, bindGrantOnSuccess } = wiring;
|
|
47
|
-
const {
|
|
46
|
+
const { verifyDelegation, buildDelegationErrorResponse, buildNeedsAuthorizationChallenge, } = createDelegationVerification(deps);
|
|
48
47
|
function wrapWithDelegation(toolName, config, handler) {
|
|
49
48
|
return async (args, sessionId) => {
|
|
50
49
|
const delegationArg = args["_kyaos_delegation"];
|
|
@@ -91,55 +90,15 @@ export function createDelegationGate(deps, wiring) {
|
|
|
91
90
|
const { challengeContent, message } = await buildNeedsAuthorizationChallenge(toolName, config);
|
|
92
91
|
return attachOutcomeProof({ content: challengeContent }, toolName, args, sessionId, message, "needs_authorization", undefined, challengeContent);
|
|
93
92
|
}
|
|
94
|
-
//
|
|
95
|
-
//
|
|
96
|
-
//
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
if (
|
|
100
|
-
const parsed = parseVCJWT(delegationArg);
|
|
101
|
-
if (!parsed || !parsed.payload.vc) {
|
|
102
|
-
return attachOutcomeProof(buildDelegationErrorResponse(KYA_OS_ERROR_CODES.delegation_invalid, "Invalid VC-JWT format"), toolName, args, sessionId, "Invalid VC-JWT format");
|
|
103
|
-
}
|
|
104
|
-
vc = parsed.payload.vc;
|
|
105
|
-
// VC-JWTs don't have an embedded proof — the JWT signature is the
|
|
106
|
-
// proof. Add a marker so basic validation (which checks for proof
|
|
107
|
-
// presence) passes. The actual signature is in the JWT envelope.
|
|
108
|
-
if (!vc.proof) {
|
|
109
|
-
vc = { ...vc, proof: { type: 'JwtProof2020', jwt: delegationArg } };
|
|
110
|
-
}
|
|
111
|
-
isVCJWT = true;
|
|
112
|
-
}
|
|
113
|
-
else {
|
|
114
|
-
vc = delegationArg;
|
|
115
|
-
}
|
|
116
|
-
// For VC-JWTs the embedded-signature check is skipped (the JWT envelope
|
|
117
|
-
// signature is the proof); schema/expiry/status/scope checks still apply.
|
|
118
|
-
// validateDelegationChain performs the shape check and returns
|
|
119
|
-
// { valid, reason } for malformed input, never throwing on normal or
|
|
120
|
-
// structurally-malformed credentials. This try/catch is therefore a PURE
|
|
121
|
-
// BACKSTOP — it fires only on a truly unexpected throw (e.g. a hostile
|
|
122
|
-
// getter/Proxy accessor or a provider fault): it logs the detail
|
|
123
|
-
// server-side and returns a GENERIC reason, so no internal/implementation
|
|
124
|
-
// detail (stack, raw error text) leaks to the client or the signed proof.
|
|
125
|
-
const verificationResult = await (async () => {
|
|
126
|
-
try {
|
|
127
|
-
return await validateDelegationChain(vc, { skipSignature: isVCJWT });
|
|
128
|
-
}
|
|
129
|
-
catch (error) {
|
|
130
|
-
logger.error("[kya-os] Unexpected error verifying delegation", {
|
|
131
|
-
tool: toolName,
|
|
132
|
-
error: error instanceof Error ? error.message : String(error),
|
|
133
|
-
stack: error instanceof Error ? error.stack : undefined,
|
|
134
|
-
});
|
|
135
|
-
return { valid: false, reason: "Delegation credential could not be verified" };
|
|
136
|
-
}
|
|
137
|
-
})();
|
|
138
|
-
if (!verificationResult.valid) {
|
|
139
|
-
const reason = verificationResult.reason ?? "Unknown delegation validation error";
|
|
93
|
+
// Authenticate the presented delegation (object embedded-proof OR VC-JWT
|
|
94
|
+
// string) and normalize it to a verified credential. verifyDelegation owns
|
|
95
|
+
// the wire-form-specific signature checks — the gate never sets
|
|
96
|
+
// skipSignature itself, so a JWT envelope can't be silently skipped.
|
|
97
|
+
const check = await verifyDelegation(delegationArg);
|
|
98
|
+
if (!check.valid) {
|
|
140
99
|
try {
|
|
141
100
|
await audit?.delegation('rejected', {
|
|
142
|
-
delegationRef: rejectedDelegationRef(vc),
|
|
101
|
+
delegationRef: rejectedDelegationRef(check.vc),
|
|
143
102
|
outcome: 'failed',
|
|
144
103
|
reasonCode: 'DELEGATION_VERIFICATION_FAILED',
|
|
145
104
|
});
|
|
@@ -150,9 +109,10 @@ export function createDelegationGate(deps, wiring) {
|
|
|
150
109
|
error: error instanceof Error ? error.message : String(error),
|
|
151
110
|
});
|
|
152
111
|
}
|
|
153
|
-
logger.warn(`[kya-os] Delegation verification failed for "${toolName}": ${sanitizeForMessage(reason)}`);
|
|
154
|
-
return attachOutcomeProof(buildDelegationErrorResponse(KYA_OS_ERROR_CODES.delegation_invalid, reason), toolName, args, sessionId, reason);
|
|
112
|
+
logger.warn(`[kya-os] Delegation verification failed for "${toolName}": ${sanitizeForMessage(check.reason)}`);
|
|
113
|
+
return attachOutcomeProof(buildDelegationErrorResponse(KYA_OS_ERROR_CODES.delegation_invalid, check.reason), toolName, args, sessionId, check.reason);
|
|
155
114
|
}
|
|
115
|
+
const { vc, isJwt } = check;
|
|
156
116
|
// Holder binding (spec §11.8): the delegation is valid, but a valid
|
|
157
117
|
// *credential* is a bearer token until we also prove the caller holds the
|
|
158
118
|
// delegation SUBJECT's key. Opt-in via `delegation.holderBinding`. did:key
|
|
@@ -215,7 +175,7 @@ export function createDelegationGate(deps, wiring) {
|
|
|
215
175
|
logger.warn(`[kya-os] Delegation missing required scope "${config.scopeId}" for "${toolName}"`);
|
|
216
176
|
return attachOutcomeProof(buildDelegationErrorResponse(KYA_OS_ERROR_CODES.insufficient_scope, reason), toolName, args, sessionId, reason);
|
|
217
177
|
}
|
|
218
|
-
const serializedCredential =
|
|
178
|
+
const serializedCredential = isJwt
|
|
219
179
|
? new TextEncoder().encode(delegationArg)
|
|
220
180
|
: canonicalizeJsonBytes(vc);
|
|
221
181
|
const credentialDigest = await cryptoProvider.hash(serializedCredential);
|
|
@@ -258,7 +218,7 @@ export function createDelegationGate(deps, wiring) {
|
|
|
258
218
|
}
|
|
259
219
|
// Mint a durable grant from this verified delegation so the next call —
|
|
260
220
|
// on any instance — resolves via resolveExistingGrant with no re-paste.
|
|
261
|
-
await bindGrantOnSuccess(vc, delegationArg,
|
|
221
|
+
await bindGrantOnSuccess(vc, delegationArg, isJwt, sessionId, config.scopeId);
|
|
262
222
|
logger.debug(`[kya-os] Delegation verified for "${toolName}", scope "${config.scopeId}"`);
|
|
263
223
|
return handler(cleanArgs, sessionId, callContext);
|
|
264
224
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"with-kya-os.delegation-gate.js","sourceRoot":"","sources":["../../src/middleware/with-kya-os.delegation-gate.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EACL,yBAAyB,EACzB,iBAAiB,EACjB,mBAAmB,EACnB,sBAAsB,GACvB,MAAM,iCAAiC,CAAC;AACzC,OAAO,EAAE,cAAc,EAAE,MAAM,gCAAgC,CAAC;
|
|
1
|
+
{"version":3,"file":"with-kya-os.delegation-gate.js","sourceRoot":"","sources":["../../src/middleware/with-kya-os.delegation-gate.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EACL,yBAAyB,EACzB,iBAAiB,EACjB,mBAAmB,EACnB,sBAAsB,GACvB,MAAM,iCAAiC,CAAC;AACzC,OAAO,EAAE,cAAc,EAAE,MAAM,gCAAgC,CAAC;AAEhE,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAC7C,OAAO,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAOlD,OAAO,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AAC9D,OAAO,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAC;AAEnE,OAAO,EACL,4BAA4B,GAE7B,MAAM,oCAAoC,CAAC;AAE5C,MAAM,0BAA0B,GAAG,GAAG,CAAC;AAEvC,+EAA+E;AAC/E,SAAS,qBAAqB,CAAC,KAAc;IAC3C,IAAI,CAAC;QACH,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI;YAAE,OAAO,SAAS,CAAC;QAClE,MAAM,UAAU,GAAG,KAAgC,CAAC;QACpD,MAAM,MAAM,GAAG,UAAU,CAAC,EAAE,CAAC;QAC7B,IAAI,OAAO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UAAU,EAAE,EAAE;oBAC1E,CAAC,CAAC,EAAE,CAAC;gBACP,aAAa;aACd,CAAC;YAEF,MAAM,KAAK,EAAE,UAAU,CAAC,UAAU,EAAE;gBAClC,aAAa;gBACb,OAAO,EAAE,WAAW;gBACpB,SAAS,EAAE,EAAE,CAAC,iBAAiB,CAAC,UAAU,CAAC,QAAQ;gBACnD,OAAO,EAAE,WAAW;aACrB,CAAC,CAAC;YACH,MAAM,KAAK,EAAE,aAAa,CAAC,UAAU,EAAE;gBACrC,OAAO,EAAE,WAAW;gBACpB,OAAO,EAAE,WAAW;aACrB,CAAC,CAAC;YAEH,qEAAqE;YACrE,uEAAuE;YACvE,0EAA0E;YAC1E,MAAM,SAAS,GAA4B,EAAE,CAAC;YAC9C,KAAK,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC;gBAC1C,IAAI,CAAC,iBAAiB,CAAC,CAAC,CAAC;oBAAE,SAAS,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;YAC9C,CAAC;YAED,wEAAwE;YACxE,wEAAwE;YACxE,MAAM,kBAAkB,CAAC,EAAE,EAAE,aAAa,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,CAAC,OAAO,CAAC,CAAC;YAE9E,MAAM,CAAC,KAAK,CACV,qCAAqC,QAAQ,aAAa,MAAM,CAAC,OAAO,GAAG,CAC5E,CAAC;YACF,OAAO,OAAO,CAAC,SAAS,EAAE,SAAS,EAAE,WAAW,CAAC,CAAC;QACpD,CAAC,CAAC;IACJ,CAAC;IAED,OAAO,EAAE,kBAAkB,EAAE,CAAC;AAChC,CAAC"}
|
|
@@ -18,19 +18,32 @@ export interface DelegationGateConfig {
|
|
|
18
18
|
text: string;
|
|
19
19
|
}>;
|
|
20
20
|
}
|
|
21
|
+
/**
|
|
22
|
+
* Outcome of authenticating a presented delegation. On success the caller gets
|
|
23
|
+
* the normalized credential and its wire form; on failure a sanitizable reason
|
|
24
|
+
* plus the best-effort parsed credential (for audit references), if any.
|
|
25
|
+
*/
|
|
26
|
+
export type DelegationCheck = {
|
|
27
|
+
valid: true;
|
|
28
|
+
vc: DelegationCredential;
|
|
29
|
+
isJwt: boolean;
|
|
30
|
+
} | {
|
|
31
|
+
valid: false;
|
|
32
|
+
reason: string;
|
|
33
|
+
vc?: DelegationCredential;
|
|
34
|
+
};
|
|
21
35
|
export interface DelegationVerification {
|
|
22
36
|
/**
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
*
|
|
37
|
+
* Authenticate and normalize a presented `_kyaos_delegation`, in either wire
|
|
38
|
+
* form, into a single verified credential. A VC-JWT **string** is verified by
|
|
39
|
+
* its compact-JWS ENVELOPE signature against the issuer's published key; an
|
|
40
|
+
* **object** is verified by its embedded Data-Integrity proof. Both then run
|
|
41
|
+
* the full chain / scope-superset / expiry / status / revocation walk. Owning
|
|
42
|
+
* the `skipSignature` decision here (never at the call site) is what stops a
|
|
43
|
+
* JWT envelope from being silently skipped. Returns a {@link DelegationCheck},
|
|
44
|
+
* never throws on normal or structurally-malformed input.
|
|
27
45
|
*/
|
|
28
|
-
|
|
29
|
-
skipSignature?: boolean;
|
|
30
|
-
}): Promise<{
|
|
31
|
-
valid: boolean;
|
|
32
|
-
reason?: string;
|
|
33
|
-
}>;
|
|
46
|
+
verifyDelegation(delegationArg: unknown): Promise<DelegationCheck>;
|
|
34
47
|
/** A structured `{ error, reason }` tool response with a sanitized reason. */
|
|
35
48
|
buildDelegationErrorResponse(error: string, reason: string): Awaited<ReturnType<KyaOsToolHandler>>;
|
|
36
49
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"with-kya-os.delegation-verify.d.ts","sourceRoot":"","sources":["../../src/middleware/with-kya-os.delegation-verify.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAiBH,OAAO,EAGL,KAAK,oBAAoB,EACzB,KAAK,uBAAuB,EAC7B,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CAAA;CAAE,CAAC;AAEhE,MAAM,WAAW,sBAAsB;IACrC;;;;;;;;;OASG;IACH,gBAAgB,CAAC,aAAa,EAAE,OAAO,GAAG,OAAO,CAAC,eAAe,CAAC,CAAC;IACnE,8EAA8E;IAC9E,4BAA4B,CAC1B,KAAK,EAAE,MAAM,EACb,MAAM,EAAE,MAAM,GACb,OAAO,CAAC,UAAU,CAAC,gBAAgB,CAAC,CAAC,CAAC;IACzC;;;;;OAKG;IACH,gCAAgC,CAC9B,QAAQ,EAAE,MAAM,EAChB,MAAM,EAAE,oBAAoB,GAC3B,OAAO,CAAC;QACT,gBAAgB,EAAE,KAAK,CAAC;YAAE,IAAI,EAAE,MAAM,CAAC;YAAC,IAAI,EAAE,MAAM,CAAA;SAAE,CAAC,CAAC;QACxD,OAAO,EAAE,MAAM,CAAC;KACjB,CAAC,CAAC;CACJ;AAED,wBAAgB,4BAA4B,CAC1C,IAAI,EAAE,cAAc,GACnB,sBAAsB,CA+PxB"}
|
|
@@ -13,7 +13,7 @@ import { getDidMethod } from "../utils/did-helpers.js";
|
|
|
13
13
|
import { DelegationCredentialVerifier, } from "../delegation/vc-verifier.js";
|
|
14
14
|
import { validateDelegationChain as validateDelegationChainCore } from "../delegation/chain-enforcement.js";
|
|
15
15
|
import { RuntimeFetchProvider } from "../providers/runtime-fetch.js";
|
|
16
|
-
import { canonicalizeJSON } from "../delegation/utils.js";
|
|
16
|
+
import { canonicalizeJSON, parseVCJWT } from "../delegation/utils.js";
|
|
17
17
|
import { base64urlDecodeToBytes, bytesToBase64 } from "../utils/base64.js";
|
|
18
18
|
import { createNeedsAuthorizationError, readCredentialProofValue, } from "../types/protocol.js";
|
|
19
19
|
import { logger } from "../logging/index.js";
|
|
@@ -117,6 +117,72 @@ export function createDelegationVerification(deps) {
|
|
|
117
117
|
statusListConfigured: !!delegationConfig?.statusListResolver,
|
|
118
118
|
revocationChecker: delegationConfig?.revocationChecker,
|
|
119
119
|
}, options);
|
|
120
|
+
async function verifyDelegation(delegationArg) {
|
|
121
|
+
// Normalize to a DelegationCredential, authenticating by wire form. A VC-JWT
|
|
122
|
+
// string carries its signature in the compact-JWS ENVELOPE; an object carries
|
|
123
|
+
// an embedded Data-Integrity proof (verified inside validateDelegationChain).
|
|
124
|
+
let vc;
|
|
125
|
+
let isJwt = false;
|
|
126
|
+
if (typeof delegationArg === "string") {
|
|
127
|
+
const parsed = parseVCJWT(delegationArg);
|
|
128
|
+
if (!parsed || !parsed.payload.vc) {
|
|
129
|
+
return { valid: false, reason: "Invalid VC-JWT format" };
|
|
130
|
+
}
|
|
131
|
+
// Envelope-first: verify the JWT signature against the issuer's published
|
|
132
|
+
// key BEFORE the chain runs with skipSignature. Reuses the vetted verifier
|
|
133
|
+
// (EdDSA-pinned compact-JWS + iss/issuer consistency; fail-closed). Status
|
|
134
|
+
// is checked once by the chain walk below, so skip it here.
|
|
135
|
+
const envelope = await verifier.verifyDelegationJwt(delegationArg, {
|
|
136
|
+
skipStatus: true,
|
|
137
|
+
});
|
|
138
|
+
if (!envelope.valid) {
|
|
139
|
+
return {
|
|
140
|
+
valid: false,
|
|
141
|
+
reason: envelope.reason ?? "VC-JWT envelope signature is not valid",
|
|
142
|
+
vc: parsed.payload.vc,
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
vc = parsed.payload.vc;
|
|
146
|
+
// A JWT has no embedded `proof`; add a marker so basic validation (which
|
|
147
|
+
// requires proof presence) passes. The already-verified envelope is the
|
|
148
|
+
// real proof, so the chain walk runs with skipSignature (below).
|
|
149
|
+
if (!vc.proof) {
|
|
150
|
+
vc = { ...vc, proof: { type: "JwtProof2020", jwt: delegationArg } };
|
|
151
|
+
}
|
|
152
|
+
isJwt = true;
|
|
153
|
+
}
|
|
154
|
+
else {
|
|
155
|
+
vc = delegationArg;
|
|
156
|
+
}
|
|
157
|
+
// Chain / scope-superset / expiry / status / revocation. skipSignature is
|
|
158
|
+
// true ONLY for a JWT (its envelope, verified above, is the proof); an object
|
|
159
|
+
// keeps it false so validateDelegationChain verifies the embedded proof.
|
|
160
|
+
// That call never throws on normal/malformed input; this backstop catches
|
|
161
|
+
// only a truly unexpected throw (hostile getter/Proxy, provider fault) and
|
|
162
|
+
// returns a GENERIC reason so no internal detail leaks to the client/proof.
|
|
163
|
+
let chain;
|
|
164
|
+
try {
|
|
165
|
+
chain = await validateDelegationChain(vc, { skipSignature: isJwt });
|
|
166
|
+
}
|
|
167
|
+
catch (error) {
|
|
168
|
+
logger.error("[kya-os] Unexpected error verifying delegation", {
|
|
169
|
+
error: error instanceof Error ? error.message : String(error),
|
|
170
|
+
stack: error instanceof Error ? error.stack : undefined,
|
|
171
|
+
});
|
|
172
|
+
chain = {
|
|
173
|
+
valid: false,
|
|
174
|
+
reason: "Delegation credential could not be verified",
|
|
175
|
+
};
|
|
176
|
+
}
|
|
177
|
+
if (!chain.valid) {
|
|
178
|
+
return {
|
|
179
|
+
valid: false,
|
|
180
|
+
reason: chain.reason ?? "Unknown delegation validation error",
|
|
181
|
+
vc,
|
|
182
|
+
};
|
|
183
|
+
}
|
|
184
|
+
return { valid: true, vc, isJwt };
|
|
185
|
+
}
|
|
120
186
|
async function buildNeedsAuthorizationChallenge(toolName, config) {
|
|
121
187
|
const tokenBytes = await cryptoProvider.randomBytes(16);
|
|
122
188
|
const hex = Array.from(tokenBytes)
|
|
@@ -159,7 +225,7 @@ export function createDelegationVerification(deps) {
|
|
|
159
225
|
return { challengeContent, message: authError.message };
|
|
160
226
|
}
|
|
161
227
|
return {
|
|
162
|
-
|
|
228
|
+
verifyDelegation,
|
|
163
229
|
buildDelegationErrorResponse,
|
|
164
230
|
buildNeedsAuthorizationChallenge,
|
|
165
231
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"with-kya-os.delegation-verify.js","sourceRoot":"","sources":["../../src/middleware/with-kya-os.delegation-verify.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,oBAAoB,EAAE,MAAM,mCAAmC,CAAC;AACzE,OAAO,EAAE,oBAAoB,EAAE,MAAM,mCAAmC,CAAC;AACzE,OAAO,EACL,wBAAwB,GACzB,MAAM,wCAAwC,CAAC;AAChD,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AACvD,OAAO,EACL,4BAA4B,GAG7B,MAAM,8BAA8B,CAAC;AACtC,OAAO,EAAE,uBAAuB,IAAI,2BAA2B,EAAE,MAAM,oCAAoC,CAAC;AAC5G,OAAO,EAAE,oBAAoB,EAAE,MAAM,+BAA+B,CAAC;AACrE,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;
|
|
1
|
+
{"version":3,"file":"with-kya-os.delegation-verify.js","sourceRoot":"","sources":["../../src/middleware/with-kya-os.delegation-verify.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,oBAAoB,EAAE,MAAM,mCAAmC,CAAC;AACzE,OAAO,EAAE,oBAAoB,EAAE,MAAM,mCAAmC,CAAC;AACzE,OAAO,EACL,wBAAwB,GACzB,MAAM,wCAAwC,CAAC;AAChD,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AACvD,OAAO,EACL,4BAA4B,GAG7B,MAAM,8BAA8B,CAAC;AACtC,OAAO,EAAE,uBAAuB,IAAI,2BAA2B,EAAE,MAAM,oCAAoC,CAAC;AAC5G,OAAO,EAAE,oBAAoB,EAAE,MAAM,+BAA+B,CAAC;AACrE,OAAO,EAAE,gBAAgB,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AACtE,OAAO,EAAE,sBAAsB,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAC3E,OAAO,EACL,6BAA6B,EAC7B,wBAAwB,GAGzB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAG7C,OAAO,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AAoD9D,MAAM,UAAU,4BAA4B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C1E,IAAI,EAAE,QAAQ;oBACd,KAAK,EAAE,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC;iBAC9D,CAAC,CAAC;gBACH,gBAAgB,GAAG,uBAAuB,CAAC;YAC7C,CAAC;QACH,CAAC;QACD,OAAO,EAAE,gBAAgB,EAAE,OAAO,EAAE,SAAS,CAAC,OAAO,EAAE,CAAC;IAC1D,CAAC;IAED,OAAO;QACL,gBAAgB;QAChB,4BAA4B;QAC5B,gCAAgC;KACjC,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Hard ceiling on an INFLATED status bitstring (16 MiB ≈ 134M entries — far
|
|
3
|
+
* beyond any herd-privacy list). A fixed cap costs nothing legitimate while
|
|
4
|
+
* stopping a decompression bomb; exceeding it throws (fail-closed).
|
|
5
|
+
*/
|
|
6
|
+
export declare const MAX_STATUS_LIST_BYTES: number;
|
|
7
|
+
/**
|
|
8
|
+
* The W3C Bitstring Status List `encodedList` multibase prefix (base64url,
|
|
9
|
+
* no padding). A gzip stream's fixed magic byte (0x1f) makes its base64url
|
|
10
|
+
* start with `H`, never `u`, so a leading `u` is unambiguously the multibase
|
|
11
|
+
* code rather than payload.
|
|
12
|
+
*/
|
|
13
|
+
export declare const MULTIBASE_BASE64URL = "u";
|
|
14
|
+
/**
|
|
15
|
+
* Parse a decimal `statusListIndex` (a non-negative integer expressed as a
|
|
16
|
+
* string), fail-closed. Canonical decimal ONLY: `Number()` alone would coerce
|
|
17
|
+
* whitespace (`" "` → 0), hex (`"0x2A"` → 42), `"+42"`, and `"1e1"` → 10 —
|
|
18
|
+
* silently reading a DIFFERENT (often clear) bit than the credential names,
|
|
19
|
+
* so a revoked credential could read as live.
|
|
20
|
+
*/
|
|
21
|
+
export declare function parseStatusListIndex(raw: string): number;
|
|
22
|
+
/**
|
|
23
|
+
* Decode a status-list `encodedList` to the raw bitstring: strip the optional
|
|
24
|
+
* multibase `u` prefix, base64url-decode, run the injected decompressor, and
|
|
25
|
+
* re-check the {@link MAX_STATUS_LIST_BYTES} cap POST-inflation as a backstop
|
|
26
|
+
* (a production decompressor SHOULD also bound output during inflation).
|
|
27
|
+
* The decompressor is the bare-function common denominator — an
|
|
28
|
+
* object-shaped `DecompressionFunction` adapts inline:
|
|
29
|
+
* `(b) => decompressor.decompress(b)`.
|
|
30
|
+
*/
|
|
31
|
+
export declare function decodeStatusListPayload(encodedList: string, decompress: (bytes: Uint8Array) => Uint8Array | Promise<Uint8Array>): Promise<Uint8Array>;
|
|
32
|
+
/**
|
|
33
|
+
* Read the status bit at `index` — MSB-first within each byte (W3C Bitstring
|
|
34
|
+
* encoding). Uses FULL-PRECISION arithmetic (`Math.floor(index / 8)`) rather
|
|
35
|
+
* than 32-bit bitwise ops, which coerce to uint32 first: an index ≥ 2^32
|
|
36
|
+
* would silently wrap onto a low byte and read the WRONG — often clear — bit,
|
|
37
|
+
* turning an out-of-range index that MUST fail-closed into a fail-OPEN "not
|
|
38
|
+
* revoked". NaN/negative/fractional/out-of-buffer indexes throw.
|
|
39
|
+
*/
|
|
40
|
+
export declare function readStatusBit(bits: Uint8Array, index: number): boolean;
|
|
41
|
+
/**
|
|
42
|
+
* Assert a status-list credential is fit to ANCHOR (publish) — signed, and
|
|
43
|
+
* actually carrying a bitstring. Method-agnostic on purpose: the cheqd DLR
|
|
44
|
+
* publisher enforces it today; any future anchoring integration (another
|
|
45
|
+
* DLR-bearing DID method, a different chain) imports the same guard rather
|
|
46
|
+
* than re-deriving "what makes a status list publishable". An unsigned or
|
|
47
|
+
* bitstring-less list anchored on-chain would be an unverifiable — and
|
|
48
|
+
* therefore fail-closed-unusable — revocation source for every holder.
|
|
49
|
+
*/
|
|
50
|
+
export declare function assertAnchorableStatusListCredential(content: unknown): void;
|
|
51
|
+
//# sourceMappingURL=statuslist-bits.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"statuslist-bits.d.ts","sourceRoot":"","sources":["../../src/utils/statuslist-bits.ts"],"names":[],"mappings":"AAmBA;;;;GAIG;AACH,eAAO,MAAM,qBAAqB,QAAmB,CAAC;AAEtD;;;;;GAKG;AACH,eAAO,MAAM,mBAAmB,MAAM,CAAC;AAEvC;;;;;;GAMG;AACH,wBAAgB,oBAAoB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAWxD;AAED;;;;;;;;GAQG;AACH,wBAAsB,uBAAuB,CAC3C,WAAW,EAAE,MAAM,EACnB,UAAU,EAAE,CAAC,KAAK,EAAE,UAAU,KAAK,UAAU,GAAG,OAAO,CAAC,UAAU,CAAC,GAClE,OAAO,CAAC,UAAU,CAAC,CAUrB;AAED;;;;;;;GAOG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,UAAU,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAUtE;AAED;;;;;;;;GAQG;AACH,wBAAgB,oCAAoC,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI,CAiB3E"}
|