@oma3/omatrust 0.1.0-alpha.11 → 0.1.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.
Files changed (40) hide show
  1. package/README.md +3 -0
  2. package/dist/app-registry/index.cjs +53 -0
  3. package/dist/app-registry/index.cjs.map +1 -1
  4. package/dist/app-registry/index.js +53 -0
  5. package/dist/app-registry/index.js.map +1 -1
  6. package/dist/identity/index.cjs +643 -164
  7. package/dist/identity/index.cjs.map +1 -1
  8. package/dist/identity/index.d.cts +2 -2
  9. package/dist/identity/index.d.ts +2 -2
  10. package/dist/identity/index.js +616 -165
  11. package/dist/identity/index.js.map +1 -1
  12. package/dist/{index-QueRiudB.d.cts → index-B5OC9_8B.d.cts} +155 -4
  13. package/dist/index-Bu-xxcv9.d.ts +407 -0
  14. package/dist/{index-C2w5EvFH.d.ts → index-C6WNgPRx.d.ts} +155 -4
  15. package/dist/index-C7odEbp6.d.cts +407 -0
  16. package/dist/index.cjs +1000 -185
  17. package/dist/index.cjs.map +1 -1
  18. package/dist/index.d.cts +3 -3
  19. package/dist/index.d.ts +3 -3
  20. package/dist/index.js +981 -185
  21. package/dist/index.js.map +1 -1
  22. package/dist/reputation/index.browser.cjs +153 -148
  23. package/dist/reputation/index.browser.cjs.map +1 -1
  24. package/dist/reputation/index.browser.js +153 -148
  25. package/dist/reputation/index.browser.js.map +1 -1
  26. package/dist/reputation/index.cjs +477 -140
  27. package/dist/reputation/index.cjs.map +1 -1
  28. package/dist/reputation/index.d.cts +2 -2
  29. package/dist/reputation/index.d.ts +2 -2
  30. package/dist/reputation/index.js +475 -141
  31. package/dist/reputation/index.js.map +1 -1
  32. package/dist/{types-dpYxRq8N.d.cts → types-Dn0OwaNj.d.cts} +37 -11
  33. package/dist/{types-dpYxRq8N.d.ts → types-Dn0OwaNj.d.ts} +37 -11
  34. package/dist/widgets/index.cjs.map +1 -1
  35. package/dist/widgets/index.d.cts +3 -0
  36. package/dist/widgets/index.d.ts +3 -0
  37. package/dist/widgets/index.js.map +1 -1
  38. package/package.json +4 -2
  39. package/dist/index-BOvk-7Ku.d.cts +0 -235
  40. package/dist/index-R78TpAhN.d.ts +0 -235
@@ -228,6 +228,145 @@ function parseCaip10(input) {
228
228
  }
229
229
  return { namespace, reference, address };
230
230
  }
231
+ var VALID_KTY = /* @__PURE__ */ new Set(["EC", "OKP", "RSA"]);
232
+ var PRIVATE_KEY_FIELDS = /* @__PURE__ */ new Set(["d", "p", "q", "dp", "dq", "qi", "oth"]);
233
+ var REQUIRED_PUBLIC_FIELDS = {
234
+ EC: ["crv", "x", "y"],
235
+ OKP: ["crv", "x"],
236
+ RSA: ["n", "e"]
237
+ };
238
+ function validatePublicJwk(jwk) {
239
+ if (!jwk || typeof jwk !== "object" || Array.isArray(jwk)) {
240
+ return { valid: false, error: "JWK must be a non-null object" };
241
+ }
242
+ const obj = jwk;
243
+ const kty = obj.kty;
244
+ if (typeof kty !== "string" || !VALID_KTY.has(kty)) {
245
+ return {
246
+ valid: false,
247
+ error: `Invalid or missing kty (must be one of: ${[...VALID_KTY].join(", ")})`
248
+ };
249
+ }
250
+ for (const field of PRIVATE_KEY_FIELDS) {
251
+ if (field in obj) {
252
+ return {
253
+ valid: false,
254
+ error: `JWK contains private key field "${field}" \u2014 only public keys are allowed`
255
+ };
256
+ }
257
+ }
258
+ const required = REQUIRED_PUBLIC_FIELDS[kty];
259
+ if (required) {
260
+ for (const field of required) {
261
+ if (!(field in obj) || obj[field] === void 0 || obj[field] === null || obj[field] === "") {
262
+ return {
263
+ valid: false,
264
+ error: `Missing required public key field "${field}" for kty="${kty}"`
265
+ };
266
+ }
267
+ }
268
+ }
269
+ return { valid: true };
270
+ }
271
+ function canonicalizeJwkJson(jwk) {
272
+ const sorted = Object.keys(jwk).sort();
273
+ const obj = {};
274
+ for (const key of sorted) {
275
+ obj[key] = jwk[key];
276
+ }
277
+ return JSON.stringify(obj);
278
+ }
279
+ function jwkToDidJwk(jwk) {
280
+ assertObject(jwk, "jwk", "INVALID_JWK");
281
+ const validation = validatePublicJwk(jwk);
282
+ if (!validation.valid) {
283
+ throw new OmaTrustError("INVALID_JWK", validation.error ?? "Invalid public JWK", { jwk });
284
+ }
285
+ const canonical = canonicalizeJwkJson(jwk);
286
+ const encoded = jose.base64url.encode(new TextEncoder().encode(canonical));
287
+ return `did:jwk:${encoded}`;
288
+ }
289
+ function didJwkToJwk(didJwk) {
290
+ if (typeof didJwk !== "string" || !didJwk.startsWith("did:jwk:")) {
291
+ throw new OmaTrustError("INVALID_DID", "Expected a did:jwk DID", { input: didJwk });
292
+ }
293
+ const parts = didJwk.split(":");
294
+ if (parts.length !== 3) {
295
+ throw new OmaTrustError("INVALID_DID", "did:jwk must have exactly 3 colon-separated parts", {
296
+ input: didJwk
297
+ });
298
+ }
299
+ const encoded = parts[2];
300
+ if (!encoded || encoded.length === 0) {
301
+ throw new OmaTrustError("INVALID_DID", "Missing base64url-encoded JWK identifier", {
302
+ input: didJwk
303
+ });
304
+ }
305
+ let decoded;
306
+ try {
307
+ const bytes = jose.base64url.decode(encoded);
308
+ decoded = new TextDecoder().decode(bytes);
309
+ } catch {
310
+ throw new OmaTrustError("INVALID_DID", "Failed to base64url-decode did:jwk identifier", {
311
+ input: didJwk
312
+ });
313
+ }
314
+ let jwk;
315
+ try {
316
+ jwk = JSON.parse(decoded);
317
+ } catch {
318
+ throw new OmaTrustError("INVALID_DID", "Decoded did:jwk identifier is not valid JSON", {
319
+ input: didJwk
320
+ });
321
+ }
322
+ if (!jwk || typeof jwk !== "object" || Array.isArray(jwk)) {
323
+ throw new OmaTrustError("INVALID_DID", "Decoded did:jwk must be a JSON object", {
324
+ input: didJwk
325
+ });
326
+ }
327
+ const validation = validatePublicJwk(jwk);
328
+ if (!validation.valid) {
329
+ throw new OmaTrustError("INVALID_DID", validation.error ?? "Invalid public JWK in did:jwk", {
330
+ input: didJwk
331
+ });
332
+ }
333
+ return jwk;
334
+ }
335
+ function extractPublicKeyFields(jwk) {
336
+ const result = {};
337
+ const metadataFields = /* @__PURE__ */ new Set(["kid", "use", "key_ops", "alg", "ext"]);
338
+ for (const [key, value] of Object.entries(jwk)) {
339
+ if (PRIVATE_KEY_FIELDS.has(key)) continue;
340
+ if (metadataFields.has(key)) continue;
341
+ result[key] = value;
342
+ }
343
+ return result;
344
+ }
345
+ function publicJwkEquals(a, b) {
346
+ assertObject(a, "a", "INVALID_JWK");
347
+ assertObject(b, "b", "INVALID_JWK");
348
+ const aObj = a;
349
+ const bObj = b;
350
+ for (const field of PRIVATE_KEY_FIELDS) {
351
+ if (field in aObj) {
352
+ throw new OmaTrustError(
353
+ "INVALID_JWK",
354
+ `First JWK contains private key field "${field}"`,
355
+ { field }
356
+ );
357
+ }
358
+ if (field in bObj) {
359
+ throw new OmaTrustError(
360
+ "INVALID_JWK",
361
+ `Second JWK contains private key field "${field}"`,
362
+ { field }
363
+ );
364
+ }
365
+ }
366
+ const aPublic = extractPublicKeyFields(aObj);
367
+ const bPublic = extractPublicKeyFields(bObj);
368
+ return canonicalizeJwkJson(aPublic) === canonicalizeJwkJson(bPublic);
369
+ }
231
370
 
232
371
  // src/identity/did.ts
233
372
  var DID_REGEX = /^did:[a-z0-9]+:.+$/i;
@@ -299,7 +438,7 @@ function normalizeDidKey(input) {
299
438
  }
300
439
  function normalizeDid(input) {
301
440
  assertString(input, "input", "INVALID_DID");
302
- const trimmed = input.trim();
441
+ const trimmed = input.trim().split("#")[0];
303
442
  if (!trimmed.startsWith("did:")) {
304
443
  return normalizeDidWeb(trimmed);
305
444
  }
@@ -460,6 +599,10 @@ function validateDidJwk(did) {
460
599
  error: "DID must reference a public key \u2014 private key component (d) is not allowed"
461
600
  };
462
601
  }
602
+ const jwkValidation = validatePublicJwk(jwk);
603
+ if (!jwkValidation.valid) {
604
+ return { valid: false, method: "jwk", error: jwkValidation.error };
605
+ }
463
606
  return { valid: true, method: "jwk" };
464
607
  }
465
608
  function normalizeDidJwk(input) {
@@ -1128,145 +1271,6 @@ function getExplorerTxUrl(chainId, txHash) {
1128
1271
  function getExplorerAddressUrl(chainId, address) {
1129
1272
  return `${getConfig(chainId).explorer}/address/${address}`;
1130
1273
  }
1131
- var VALID_KTY = /* @__PURE__ */ new Set(["EC", "OKP", "RSA"]);
1132
- var PRIVATE_KEY_FIELDS = /* @__PURE__ */ new Set(["d", "p", "q", "dp", "dq", "qi", "oth"]);
1133
- var REQUIRED_PUBLIC_FIELDS = {
1134
- EC: ["crv", "x", "y"],
1135
- OKP: ["crv", "x"],
1136
- RSA: ["n", "e"]
1137
- };
1138
- function validatePublicJwk(jwk) {
1139
- if (!jwk || typeof jwk !== "object" || Array.isArray(jwk)) {
1140
- return { valid: false, error: "JWK must be a non-null object" };
1141
- }
1142
- const obj = jwk;
1143
- const kty = obj.kty;
1144
- if (typeof kty !== "string" || !VALID_KTY.has(kty)) {
1145
- return {
1146
- valid: false,
1147
- error: `Invalid or missing kty (must be one of: ${[...VALID_KTY].join(", ")})`
1148
- };
1149
- }
1150
- for (const field of PRIVATE_KEY_FIELDS) {
1151
- if (field in obj) {
1152
- return {
1153
- valid: false,
1154
- error: `JWK contains private key field "${field}" \u2014 only public keys are allowed`
1155
- };
1156
- }
1157
- }
1158
- const required = REQUIRED_PUBLIC_FIELDS[kty];
1159
- if (required) {
1160
- for (const field of required) {
1161
- if (!(field in obj) || obj[field] === void 0 || obj[field] === null || obj[field] === "") {
1162
- return {
1163
- valid: false,
1164
- error: `Missing required public key field "${field}" for kty="${kty}"`
1165
- };
1166
- }
1167
- }
1168
- }
1169
- return { valid: true };
1170
- }
1171
- function canonicalizeJwkJson(jwk) {
1172
- const sorted = Object.keys(jwk).sort();
1173
- const obj = {};
1174
- for (const key of sorted) {
1175
- obj[key] = jwk[key];
1176
- }
1177
- return JSON.stringify(obj);
1178
- }
1179
- function jwkToDidJwk(jwk) {
1180
- assertObject(jwk, "jwk", "INVALID_JWK");
1181
- const validation = validatePublicJwk(jwk);
1182
- if (!validation.valid) {
1183
- throw new OmaTrustError("INVALID_JWK", validation.error ?? "Invalid public JWK", { jwk });
1184
- }
1185
- const canonical = canonicalizeJwkJson(jwk);
1186
- const encoded = jose.base64url.encode(new TextEncoder().encode(canonical));
1187
- return `did:jwk:${encoded}`;
1188
- }
1189
- function didJwkToJwk(didJwk) {
1190
- if (typeof didJwk !== "string" || !didJwk.startsWith("did:jwk:")) {
1191
- throw new OmaTrustError("INVALID_DID", "Expected a did:jwk DID", { input: didJwk });
1192
- }
1193
- const parts = didJwk.split(":");
1194
- if (parts.length !== 3) {
1195
- throw new OmaTrustError("INVALID_DID", "did:jwk must have exactly 3 colon-separated parts", {
1196
- input: didJwk
1197
- });
1198
- }
1199
- const encoded = parts[2];
1200
- if (!encoded || encoded.length === 0) {
1201
- throw new OmaTrustError("INVALID_DID", "Missing base64url-encoded JWK identifier", {
1202
- input: didJwk
1203
- });
1204
- }
1205
- let decoded;
1206
- try {
1207
- const bytes = jose.base64url.decode(encoded);
1208
- decoded = new TextDecoder().decode(bytes);
1209
- } catch {
1210
- throw new OmaTrustError("INVALID_DID", "Failed to base64url-decode did:jwk identifier", {
1211
- input: didJwk
1212
- });
1213
- }
1214
- let jwk;
1215
- try {
1216
- jwk = JSON.parse(decoded);
1217
- } catch {
1218
- throw new OmaTrustError("INVALID_DID", "Decoded did:jwk identifier is not valid JSON", {
1219
- input: didJwk
1220
- });
1221
- }
1222
- if (!jwk || typeof jwk !== "object" || Array.isArray(jwk)) {
1223
- throw new OmaTrustError("INVALID_DID", "Decoded did:jwk must be a JSON object", {
1224
- input: didJwk
1225
- });
1226
- }
1227
- const validation = validatePublicJwk(jwk);
1228
- if (!validation.valid) {
1229
- throw new OmaTrustError("INVALID_DID", validation.error ?? "Invalid public JWK in did:jwk", {
1230
- input: didJwk
1231
- });
1232
- }
1233
- return jwk;
1234
- }
1235
- function extractPublicKeyFields(jwk) {
1236
- const result = {};
1237
- const metadataFields = /* @__PURE__ */ new Set(["kid", "use", "key_ops", "alg", "ext"]);
1238
- for (const [key, value] of Object.entries(jwk)) {
1239
- if (PRIVATE_KEY_FIELDS.has(key)) continue;
1240
- if (metadataFields.has(key)) continue;
1241
- result[key] = value;
1242
- }
1243
- return result;
1244
- }
1245
- function publicJwkEquals(a, b) {
1246
- assertObject(a, "a", "INVALID_JWK");
1247
- assertObject(b, "b", "INVALID_JWK");
1248
- const aObj = a;
1249
- const bObj = b;
1250
- for (const field of PRIVATE_KEY_FIELDS) {
1251
- if (field in aObj) {
1252
- throw new OmaTrustError(
1253
- "INVALID_JWK",
1254
- `First JWK contains private key field "${field}"`,
1255
- { field }
1256
- );
1257
- }
1258
- if (field in bObj) {
1259
- throw new OmaTrustError(
1260
- "INVALID_JWK",
1261
- `Second JWK contains private key field "${field}"`,
1262
- { field }
1263
- );
1264
- }
1265
- }
1266
- const aPublic = extractPublicKeyFields(aObj);
1267
- const bPublic = extractPublicKeyFields(bObj);
1268
- return canonicalizeJwkJson(aPublic) === canonicalizeJwkJson(bPublic);
1269
- }
1270
1274
 
1271
1275
  // src/shared/did-document.ts
1272
1276
  async function fetchDidDocument(domain) {
@@ -2868,6 +2872,42 @@ function createX402OfferProof(offer) {
2868
2872
  };
2869
2873
  }
2870
2874
 
2875
+ // src/reputation/proof/x402-verify.ts
2876
+ async function verifyX402Artifact(artifact, options) {
2877
+ if (!artifact || typeof artifact !== "object") {
2878
+ return {
2879
+ valid: false,
2880
+ error: { code: "INVALID_ARTIFACT", message: "Artifact must be a non-null object" }
2881
+ };
2882
+ }
2883
+ const format = artifact.format;
2884
+ switch (format) {
2885
+ case "jws": {
2886
+ const jwsArtifact = artifact;
2887
+ const jwsOptions = options.resolveOptions ? { resolveOptions: options.resolveOptions } : void 0;
2888
+ if (options.artifactType === "offer") {
2889
+ return verifyX402JwsOffer(jwsArtifact, jwsOptions);
2890
+ }
2891
+ return verifyX402JwsReceipt(jwsArtifact, jwsOptions);
2892
+ }
2893
+ case "eip712": {
2894
+ const eip712Artifact = artifact;
2895
+ if (options.artifactType === "offer") {
2896
+ return verifyX402Eip712Offer(eip712Artifact);
2897
+ }
2898
+ return verifyX402Eip712Receipt(eip712Artifact);
2899
+ }
2900
+ default:
2901
+ return {
2902
+ valid: false,
2903
+ error: {
2904
+ code: "UNSUPPORTED_FORMAT",
2905
+ message: `Unsupported x402 artifact format: "${format}"`
2906
+ }
2907
+ };
2908
+ }
2909
+ }
2910
+
2871
2911
  // src/reputation/proof/evidence-pointer.ts
2872
2912
  function createEvidencePointerProof(url) {
2873
2913
  if (!url || typeof url !== "string") {
@@ -3153,6 +3193,300 @@ async function verifySubjectOwnership(params) {
3153
3193
  subjectDid
3154
3194
  });
3155
3195
  }
3196
+ function extractEip712Signer(proof) {
3197
+ const { domain, message, signature } = proof.proofObject;
3198
+ const typedData = {
3199
+ domain,
3200
+ types: {
3201
+ OmaTrustProof: [
3202
+ { name: "signer", type: "address" },
3203
+ { name: "authorizedEntity", type: "string" },
3204
+ { name: "signingPurpose", type: "string" },
3205
+ { name: "creationTimestamp", type: "uint256" },
3206
+ { name: "expirationTimestamp", type: "uint256" },
3207
+ { name: "randomValue", type: "bytes32" },
3208
+ { name: "statement", type: "string" }
3209
+ ]
3210
+ },
3211
+ message
3212
+ };
3213
+ try {
3214
+ const result = verifyEip712Signature(typedData, signature);
3215
+ return result.valid && result.signer ? result.signer : null;
3216
+ } catch (err) {
3217
+ console.warn("[omatrust] EIP-712 signer extraction failed:", err);
3218
+ return null;
3219
+ }
3220
+ }
3221
+ function extractJwsHeaderJwk(proof) {
3222
+ const jws = proof.proofObject;
3223
+ if (typeof jws !== "string") return null;
3224
+ const parts = jws.split(".");
3225
+ if (parts.length !== 3) return null;
3226
+ try {
3227
+ const headerB64 = parts[0].replace(/-/g, "+").replace(/_/g, "/");
3228
+ const padded = headerB64.padEnd(
3229
+ headerB64.length + (4 - headerB64.length % 4) % 4,
3230
+ "="
3231
+ );
3232
+ let headerJson;
3233
+ if (typeof atob === "function") {
3234
+ headerJson = decodeURIComponent(
3235
+ Array.from(atob(padded)).map((char) => `%${char.charCodeAt(0).toString(16).padStart(2, "0")}`).join("")
3236
+ );
3237
+ } else {
3238
+ headerJson = Buffer.from(padded, "base64").toString("utf8");
3239
+ }
3240
+ const header = JSON.parse(headerJson);
3241
+ return header.jwk ?? null;
3242
+ } catch {
3243
+ return null;
3244
+ }
3245
+ }
3246
+ function extractJwsPayload(proof) {
3247
+ const jws = proof.proofObject;
3248
+ if (typeof jws !== "string") return null;
3249
+ const parts = jws.split(".");
3250
+ if (parts.length !== 3) return null;
3251
+ try {
3252
+ const payloadB64 = parts[1].replace(/-/g, "+").replace(/_/g, "/");
3253
+ const padded = payloadB64.padEnd(
3254
+ payloadB64.length + (4 - payloadB64.length % 4) % 4,
3255
+ "="
3256
+ );
3257
+ let payloadJson;
3258
+ if (typeof atob === "function") {
3259
+ payloadJson = decodeURIComponent(
3260
+ Array.from(atob(padded)).map((char) => `%${char.charCodeAt(0).toString(16).padStart(2, "0")}`).join("")
3261
+ );
3262
+ } else {
3263
+ payloadJson = Buffer.from(padded, "base64").toString("utf8");
3264
+ }
3265
+ return JSON.parse(payloadJson);
3266
+ } catch {
3267
+ return null;
3268
+ }
3269
+ }
3270
+ function signerMatchesDid(signerAddress, did) {
3271
+ try {
3272
+ const didAddress = extractAddressFromDid(did);
3273
+ return ethers.getAddress(signerAddress).toLowerCase() === ethers.getAddress(didAddress).toLowerCase();
3274
+ } catch {
3275
+ return false;
3276
+ }
3277
+ }
3278
+ function jwkMatchesDid(jwk, did) {
3279
+ const method = extractDidMethod(did);
3280
+ if (method === "jwk") {
3281
+ try {
3282
+ const didJwk = didJwkToJwk(did);
3283
+ return publicJwkEquals(jwk, didJwk);
3284
+ } catch {
3285
+ return false;
3286
+ }
3287
+ }
3288
+ return false;
3289
+ }
3290
+ function proofSignerMatchesDid(proof, did) {
3291
+ switch (proof.proofType) {
3292
+ case "pop-eip712": {
3293
+ const signer = extractEip712Signer(proof);
3294
+ if (!signer) return false;
3295
+ return signerMatchesDid(signer, did);
3296
+ }
3297
+ case "pop-jws": {
3298
+ const jwsProof = proof;
3299
+ const jwk = extractJwsHeaderJwk(jwsProof);
3300
+ if (jwk && jwkMatchesDid(jwk, did)) return true;
3301
+ const payload = extractJwsPayload(jwsProof);
3302
+ if (payload && typeof payload.iss === "string") {
3303
+ if (payload.iss === did) return true;
3304
+ }
3305
+ return false;
3306
+ }
3307
+ case "tx-encoded-value":
3308
+ case "tx-interaction":
3309
+ return false;
3310
+ case "evidence-pointer":
3311
+ return false;
3312
+ default:
3313
+ return false;
3314
+ }
3315
+ }
3316
+ function proofAuthorizedEntityMatchesDid(proof, did) {
3317
+ switch (proof.proofType) {
3318
+ case "pop-eip712": {
3319
+ const eip712 = proof;
3320
+ const authorizedEntity = eip712.proofObject.message.authorizedEntity;
3321
+ return typeof authorizedEntity === "string" && authorizedEntity === did;
3322
+ }
3323
+ case "pop-jws": {
3324
+ const payload = extractJwsPayload(proof);
3325
+ if (!payload) return false;
3326
+ return typeof payload.aud === "string" && payload.aud === did;
3327
+ }
3328
+ default:
3329
+ return false;
3330
+ }
3331
+ }
3332
+ function verifyLinkedIdentifierProofs(data) {
3333
+ if (!data.subject || !data.linkedId) {
3334
+ return {
3335
+ valid: false,
3336
+ checks: [],
3337
+ reasons: ["subject and linkedId are required"]
3338
+ };
3339
+ }
3340
+ if (!Array.isArray(data.proofs) || data.proofs.length === 0) {
3341
+ return {
3342
+ valid: false,
3343
+ checks: [],
3344
+ reasons: ["At least one proof is required"]
3345
+ };
3346
+ }
3347
+ const checks = [];
3348
+ let subjectProved = false;
3349
+ let linkedIdProved = false;
3350
+ for (let i = 0; i < data.proofs.length; i++) {
3351
+ const proof = data.proofs[i];
3352
+ if (proofSignerMatchesDid(proof, data.subject)) {
3353
+ checks.push({
3354
+ proofIndex: i,
3355
+ proofType: proof.proofType,
3356
+ checkType: "signer-is-subject",
3357
+ valid: true
3358
+ });
3359
+ subjectProved = true;
3360
+ if (!proofAuthorizedEntityMatchesDid(proof, data.linkedId)) {
3361
+ checks.push({
3362
+ proofIndex: i,
3363
+ proofType: proof.proofType,
3364
+ checkType: "signer-is-subject",
3365
+ valid: false,
3366
+ reason: "Proof from subject does not authorize linkedId (aud mismatch)"
3367
+ });
3368
+ }
3369
+ }
3370
+ if (proofSignerMatchesDid(proof, data.linkedId)) {
3371
+ checks.push({
3372
+ proofIndex: i,
3373
+ proofType: proof.proofType,
3374
+ checkType: "signer-is-linkedId",
3375
+ valid: true
3376
+ });
3377
+ linkedIdProved = true;
3378
+ if (!proofAuthorizedEntityMatchesDid(proof, data.subject)) {
3379
+ checks.push({
3380
+ proofIndex: i,
3381
+ proofType: proof.proofType,
3382
+ checkType: "signer-is-linkedId",
3383
+ valid: false,
3384
+ reason: "Proof from linkedId does not authorize subject (aud mismatch)"
3385
+ });
3386
+ }
3387
+ }
3388
+ if (proof.proofType === "evidence-pointer") {
3389
+ checks.push({
3390
+ proofIndex: i,
3391
+ proofType: proof.proofType,
3392
+ checkType: "signer-is-subject",
3393
+ valid: true,
3394
+ reason: "Evidence pointer accepted (requires URL fetch for full verification)"
3395
+ });
3396
+ subjectProved = true;
3397
+ }
3398
+ }
3399
+ const reasons = [];
3400
+ if (!subjectProved) {
3401
+ reasons.push("No proof demonstrates control by subject");
3402
+ }
3403
+ if (!linkedIdProved) {
3404
+ reasons.push("No proof demonstrates control by linkedId");
3405
+ }
3406
+ return {
3407
+ valid: reasons.length === 0,
3408
+ checks,
3409
+ reasons
3410
+ };
3411
+ }
3412
+ function verifyKeyBindingProofs(data) {
3413
+ if (!data.subject || !data.keyId) {
3414
+ return {
3415
+ valid: false,
3416
+ checks: [],
3417
+ reasons: ["subject and keyId are required"]
3418
+ };
3419
+ }
3420
+ if (!Array.isArray(data.proofs) || data.proofs.length === 0) {
3421
+ return {
3422
+ valid: false,
3423
+ checks: [],
3424
+ reasons: ["At least one proof is required"]
3425
+ };
3426
+ }
3427
+ const checks = [];
3428
+ let subjectAuthorizedKey = false;
3429
+ for (let i = 0; i < data.proofs.length; i++) {
3430
+ const proof = data.proofs[i];
3431
+ if (proofSignerMatchesDid(proof, data.subject)) {
3432
+ const authorizesKey = proofAuthorizedEntityMatchesDid(proof, data.keyId);
3433
+ checks.push({
3434
+ proofIndex: i,
3435
+ proofType: proof.proofType,
3436
+ checkType: "signer-is-subject-for-key",
3437
+ valid: authorizesKey,
3438
+ reason: authorizesKey ? void 0 : "Proof signed by subject but does not authorize the keyId"
3439
+ });
3440
+ if (authorizesKey) {
3441
+ subjectAuthorizedKey = true;
3442
+ }
3443
+ }
3444
+ if (proofSignerMatchesDid(proof, data.keyId)) {
3445
+ checks.push({
3446
+ proofIndex: i,
3447
+ proofType: proof.proofType,
3448
+ checkType: "signer-is-keyId",
3449
+ valid: true,
3450
+ reason: "Key proved possession (supplementary, not sufficient alone)"
3451
+ });
3452
+ }
3453
+ if (proof.proofType === "evidence-pointer") {
3454
+ checks.push({
3455
+ proofIndex: i,
3456
+ proofType: proof.proofType,
3457
+ checkType: "signer-is-subject-for-key",
3458
+ valid: true,
3459
+ reason: "Evidence pointer accepted (requires URL fetch for full verification)"
3460
+ });
3461
+ subjectAuthorizedKey = true;
3462
+ }
3463
+ }
3464
+ if (data.publicKeyJwk && extractDidMethod(data.keyId) === "jwk") {
3465
+ try {
3466
+ const keyIdJwk = didJwkToJwk(data.keyId);
3467
+ const jwkConsistent = publicJwkEquals(data.publicKeyJwk, keyIdJwk);
3468
+ if (!jwkConsistent) {
3469
+ return {
3470
+ valid: false,
3471
+ checks,
3472
+ reasons: ["publicKeyJwk does not match the key material in keyId (did:jwk)"]
3473
+ };
3474
+ }
3475
+ } catch {
3476
+ }
3477
+ }
3478
+ const reasons = [];
3479
+ if (!subjectAuthorizedKey) {
3480
+ reasons.push(
3481
+ "No proof demonstrates that subject authorized the key binding"
3482
+ );
3483
+ }
3484
+ return {
3485
+ valid: reasons.length === 0,
3486
+ checks,
3487
+ reasons
3488
+ };
3489
+ }
3156
3490
 
3157
3491
  exports.EIP1967_ADMIN_SLOT = EIP1967_ADMIN_SLOT;
3158
3492
  exports.OWNERSHIP_PATTERNS = OWNERSHIP_PATTERNS;
@@ -3216,10 +3550,13 @@ exports.verifyDidPkhOwnership = verifyDidPkhOwnership;
3216
3550
  exports.verifyDidWebOwnership = verifyDidWebOwnership;
3217
3551
  exports.verifyDnsTxtControllerDid = verifyDnsTxtControllerDid2;
3218
3552
  exports.verifyEip712Signature = verifyEip712Signature;
3553
+ exports.verifyKeyBindingProofs = verifyKeyBindingProofs;
3554
+ exports.verifyLinkedIdentifierProofs = verifyLinkedIdentifierProofs;
3219
3555
  exports.verifyProof = verifyProof;
3220
3556
  exports.verifySchemaExists = verifySchemaExists;
3221
3557
  exports.verifySubjectOwnership = verifySubjectOwnership;
3222
3558
  exports.verifyTransferProof = verifyTransferProof;
3559
+ exports.verifyX402Artifact = verifyX402Artifact;
3223
3560
  exports.verifyX402Eip712Artifact = verifyX402Eip712Artifact;
3224
3561
  exports.verifyX402Eip712Offer = verifyX402Eip712Offer;
3225
3562
  exports.verifyX402Eip712Receipt = verifyX402Eip712Receipt;