@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
@@ -1,3 +1,3 @@
1
1
  export { A as AttestationQueryResult, a as AttestationValidationError, B as BuildDelegatedTypedDataFromEncodedParams, C as CallControllerWitnessParams, b as CallControllerWitnessResult, c as ChainConstants, aW as ContractOwnershipProvider, d as ControllerAuthorizationResult, e as ControllerWitnessEvidence, f as CreatePopEip712ProofParams, g as CreatePopJwsProofParams, D as Did, h as DnsTxtRecordResult, aX as EIP1967_ADMIN_SLOT, E as EvidencePointerProof, i as EvmOwnershipProvider, G as GetAttestationParams, j as GetAttestationsByAttesterParams, k as GetControllerAuthorizationParams, l as GetLatestAttestationsParams, H as Hex, L as ListAttestationsParams, aY as OWNERSHIP_PATTERNS, P as PopEip712Proof, m as PopJwsProof, n as PrepareDelegatedAttestationParams, o as PrepareDelegatedAttestationResult, p as ProofPurpose, q as ProofType, r as ProofWrapper, R as RelayErrorDetails, s as RelayMetadata, t as RequestControllerWitnessParams, u as RequestControllerWitnessResult, v as RevokeAttestationParams, w as RevokeAttestationResult, S as SchemaField, x as SubjectOwnershipVerificationMethod, y as SubjectOwnershipVerificationResult, z as SubmitAttestationParams, F as SubmitAttestationResult, I as SubmitDelegatedAttestationParams, J as SubmitDelegatedAttestationResult, T as TxEncodedValueProof, K as TxInteractionProof, V as VerifyAttestationParams, M as VerifyAttestationResult, N as VerifyDidJsonControllerDidOptions, O as VerifyDidPkhOwnershipParams, Q as VerifyDidWebOwnershipParams, aV as VerifyDnsTxtControllerDidOptions, U as VerifyProofParams, W as VerifyProofResult, X as VerifySubjectOwnershipParams, Y as W3CKeyPurpose, Z as X402OfferProof, _ as X402ReceiptProof, $ as buildDelegatedAttestationTypedData, a0 as buildDelegatedTypedDataFromEncoded, a1 as buildDnsTxtRecord, a2 as buildEip712Domain, a3 as calculateAverageUserReviewRating, a4 as calculateTransferAmount, a5 as calculateTransferAmountFromAddresses, a6 as callControllerWitness, a7 as constructSeed, a8 as createEvidencePointerProof, a9 as createPopEip712Proof, aa as createPopJwsProof, ab as createTxEncodedValueProof, ac as createTxInteractionProof, ad as createX402OfferProof, ae as createX402ReceiptProof, af as decodeAttestationData, ag as deduplicateReviews, aZ as discoverContractOwner, a_ as discoverControllingWalletDid, ah as encodeAttestationData, ai as extractEvmAddressesFromDidDocument, aj as extractExpirationTime, ak as extractJwksFromDidDocument, al as fetchDidDocument, am as formatSchemaUid, an as formatTransferAmount, ao as getAttestation, ap as getAttestationsByAttester, aq as getAttestationsForDid, ar as getChainConstants, as as getExplorerAddressUrl, at as getExplorerTxUrl, au as getLatestAttestations, av as getMajorVersion, aw as getOmaTrustProofEip712Types, ax as getSchemaDetails, ay as getSupportedChainIds, az as hashSeed, aA as isChainSupported, aB as listAttestations, aC as normalizeSchema, aD as parseDnsTxtRecord, aE as prepareDelegatedAttestation, a$ as readOwnerFromContract, aF as requestControllerWitness, aG as revokeAttestation, aH as schemaToString, aI as splitSignature, aJ as submitAttestation, aK as submitDelegatedAttestation, aL as validateAttestationData, aM as verifyAttestation, aN as verifyDidDocumentControllerDid, aO as verifyDidJsonControllerDid, aP as verifyDidPkhOwnership, aQ as verifyDidWebOwnership, aR as verifyEip712Signature, aS as verifyProof, aT as verifySchemaExists, aU as verifySubjectOwnership, b0 as verifyTransferProof } from '../subject-ownership-B7cFlm8c.cjs';
2
- export { E as Eip712VerificationFailure, a as Eip712VerificationResult, X as X402Eip712Artifact, b as X402JwsArtifact, c as X402JwsVerifyOptions, g as getControllerAuthorization, v as verifyDnsTxtControllerDid, d as verifyX402Eip712Artifact, e as verifyX402Eip712Offer, f as verifyX402Eip712Receipt, h as verifyX402JwsArtifact, j as verifyX402JwsOffer, k as verifyX402JwsReceipt } from '../index-QueRiudB.cjs';
3
- import '../types-dpYxRq8N.cjs';
2
+ export { E as Eip712VerificationFailure, a as Eip712VerificationResult, K as KeyBindingData, L as LinkedIdentifierData, S as SchemaProofCheck, b as SchemaProofVerificationResult, V as VerifyX402Options, X as X402Artifact, c as X402Eip712Artifact, d as X402JwsArtifact, e as X402JwsVerifyOptions, f as X402VerificationFailure, g as X402VerificationResult, h as X402VerificationSuccess, j as getControllerAuthorization, v as verifyDnsTxtControllerDid, k as verifyKeyBindingProofs, l as verifyLinkedIdentifierProofs, m as verifyX402Artifact, n as verifyX402Eip712Artifact, o as verifyX402Eip712Offer, p as verifyX402Eip712Receipt, q as verifyX402JwsArtifact, r as verifyX402JwsOffer, s as verifyX402JwsReceipt } from '../index-B5OC9_8B.cjs';
3
+ import '../types-Dn0OwaNj.cjs';
@@ -1,3 +1,3 @@
1
1
  export { A as AttestationQueryResult, a as AttestationValidationError, B as BuildDelegatedTypedDataFromEncodedParams, C as CallControllerWitnessParams, b as CallControllerWitnessResult, c as ChainConstants, aW as ContractOwnershipProvider, d as ControllerAuthorizationResult, e as ControllerWitnessEvidence, f as CreatePopEip712ProofParams, g as CreatePopJwsProofParams, D as Did, h as DnsTxtRecordResult, aX as EIP1967_ADMIN_SLOT, E as EvidencePointerProof, i as EvmOwnershipProvider, G as GetAttestationParams, j as GetAttestationsByAttesterParams, k as GetControllerAuthorizationParams, l as GetLatestAttestationsParams, H as Hex, L as ListAttestationsParams, aY as OWNERSHIP_PATTERNS, P as PopEip712Proof, m as PopJwsProof, n as PrepareDelegatedAttestationParams, o as PrepareDelegatedAttestationResult, p as ProofPurpose, q as ProofType, r as ProofWrapper, R as RelayErrorDetails, s as RelayMetadata, t as RequestControllerWitnessParams, u as RequestControllerWitnessResult, v as RevokeAttestationParams, w as RevokeAttestationResult, S as SchemaField, x as SubjectOwnershipVerificationMethod, y as SubjectOwnershipVerificationResult, z as SubmitAttestationParams, F as SubmitAttestationResult, I as SubmitDelegatedAttestationParams, J as SubmitDelegatedAttestationResult, T as TxEncodedValueProof, K as TxInteractionProof, V as VerifyAttestationParams, M as VerifyAttestationResult, N as VerifyDidJsonControllerDidOptions, O as VerifyDidPkhOwnershipParams, Q as VerifyDidWebOwnershipParams, aV as VerifyDnsTxtControllerDidOptions, U as VerifyProofParams, W as VerifyProofResult, X as VerifySubjectOwnershipParams, Y as W3CKeyPurpose, Z as X402OfferProof, _ as X402ReceiptProof, $ as buildDelegatedAttestationTypedData, a0 as buildDelegatedTypedDataFromEncoded, a1 as buildDnsTxtRecord, a2 as buildEip712Domain, a3 as calculateAverageUserReviewRating, a4 as calculateTransferAmount, a5 as calculateTransferAmountFromAddresses, a6 as callControllerWitness, a7 as constructSeed, a8 as createEvidencePointerProof, a9 as createPopEip712Proof, aa as createPopJwsProof, ab as createTxEncodedValueProof, ac as createTxInteractionProof, ad as createX402OfferProof, ae as createX402ReceiptProof, af as decodeAttestationData, ag as deduplicateReviews, aZ as discoverContractOwner, a_ as discoverControllingWalletDid, ah as encodeAttestationData, ai as extractEvmAddressesFromDidDocument, aj as extractExpirationTime, ak as extractJwksFromDidDocument, al as fetchDidDocument, am as formatSchemaUid, an as formatTransferAmount, ao as getAttestation, ap as getAttestationsByAttester, aq as getAttestationsForDid, ar as getChainConstants, as as getExplorerAddressUrl, at as getExplorerTxUrl, au as getLatestAttestations, av as getMajorVersion, aw as getOmaTrustProofEip712Types, ax as getSchemaDetails, ay as getSupportedChainIds, az as hashSeed, aA as isChainSupported, aB as listAttestations, aC as normalizeSchema, aD as parseDnsTxtRecord, aE as prepareDelegatedAttestation, a$ as readOwnerFromContract, aF as requestControllerWitness, aG as revokeAttestation, aH as schemaToString, aI as splitSignature, aJ as submitAttestation, aK as submitDelegatedAttestation, aL as validateAttestationData, aM as verifyAttestation, aN as verifyDidDocumentControllerDid, aO as verifyDidJsonControllerDid, aP as verifyDidPkhOwnership, aQ as verifyDidWebOwnership, aR as verifyEip712Signature, aS as verifyProof, aT as verifySchemaExists, aU as verifySubjectOwnership, b0 as verifyTransferProof } from '../subject-ownership-B7cFlm8c.js';
2
- export { E as Eip712VerificationFailure, a as Eip712VerificationResult, X as X402Eip712Artifact, b as X402JwsArtifact, c as X402JwsVerifyOptions, g as getControllerAuthorization, v as verifyDnsTxtControllerDid, d as verifyX402Eip712Artifact, e as verifyX402Eip712Offer, f as verifyX402Eip712Receipt, h as verifyX402JwsArtifact, j as verifyX402JwsOffer, k as verifyX402JwsReceipt } from '../index-C2w5EvFH.js';
3
- import '../types-dpYxRq8N.js';
2
+ export { E as Eip712VerificationFailure, a as Eip712VerificationResult, K as KeyBindingData, L as LinkedIdentifierData, S as SchemaProofCheck, b as SchemaProofVerificationResult, V as VerifyX402Options, X as X402Artifact, c as X402Eip712Artifact, d as X402JwsArtifact, e as X402JwsVerifyOptions, f as X402VerificationFailure, g as X402VerificationResult, h as X402VerificationSuccess, j as getControllerAuthorization, v as verifyDnsTxtControllerDid, k as verifyKeyBindingProofs, l as verifyLinkedIdentifierProofs, m as verifyX402Artifact, n as verifyX402Eip712Artifact, o as verifyX402Eip712Offer, p as verifyX402Eip712Receipt, q as verifyX402JwsArtifact, r as verifyX402JwsOffer, s as verifyX402JwsReceipt } from '../index-C6WNgPRx.js';
3
+ import '../types-Dn0OwaNj.js';
@@ -222,6 +222,145 @@ function parseCaip10(input) {
222
222
  }
223
223
  return { namespace, reference, address };
224
224
  }
225
+ var VALID_KTY = /* @__PURE__ */ new Set(["EC", "OKP", "RSA"]);
226
+ var PRIVATE_KEY_FIELDS = /* @__PURE__ */ new Set(["d", "p", "q", "dp", "dq", "qi", "oth"]);
227
+ var REQUIRED_PUBLIC_FIELDS = {
228
+ EC: ["crv", "x", "y"],
229
+ OKP: ["crv", "x"],
230
+ RSA: ["n", "e"]
231
+ };
232
+ function validatePublicJwk(jwk) {
233
+ if (!jwk || typeof jwk !== "object" || Array.isArray(jwk)) {
234
+ return { valid: false, error: "JWK must be a non-null object" };
235
+ }
236
+ const obj = jwk;
237
+ const kty = obj.kty;
238
+ if (typeof kty !== "string" || !VALID_KTY.has(kty)) {
239
+ return {
240
+ valid: false,
241
+ error: `Invalid or missing kty (must be one of: ${[...VALID_KTY].join(", ")})`
242
+ };
243
+ }
244
+ for (const field of PRIVATE_KEY_FIELDS) {
245
+ if (field in obj) {
246
+ return {
247
+ valid: false,
248
+ error: `JWK contains private key field "${field}" \u2014 only public keys are allowed`
249
+ };
250
+ }
251
+ }
252
+ const required = REQUIRED_PUBLIC_FIELDS[kty];
253
+ if (required) {
254
+ for (const field of required) {
255
+ if (!(field in obj) || obj[field] === void 0 || obj[field] === null || obj[field] === "") {
256
+ return {
257
+ valid: false,
258
+ error: `Missing required public key field "${field}" for kty="${kty}"`
259
+ };
260
+ }
261
+ }
262
+ }
263
+ return { valid: true };
264
+ }
265
+ function canonicalizeJwkJson(jwk) {
266
+ const sorted = Object.keys(jwk).sort();
267
+ const obj = {};
268
+ for (const key of sorted) {
269
+ obj[key] = jwk[key];
270
+ }
271
+ return JSON.stringify(obj);
272
+ }
273
+ function jwkToDidJwk(jwk) {
274
+ assertObject(jwk, "jwk", "INVALID_JWK");
275
+ const validation = validatePublicJwk(jwk);
276
+ if (!validation.valid) {
277
+ throw new OmaTrustError("INVALID_JWK", validation.error ?? "Invalid public JWK", { jwk });
278
+ }
279
+ const canonical = canonicalizeJwkJson(jwk);
280
+ const encoded = base64url.encode(new TextEncoder().encode(canonical));
281
+ return `did:jwk:${encoded}`;
282
+ }
283
+ function didJwkToJwk(didJwk) {
284
+ if (typeof didJwk !== "string" || !didJwk.startsWith("did:jwk:")) {
285
+ throw new OmaTrustError("INVALID_DID", "Expected a did:jwk DID", { input: didJwk });
286
+ }
287
+ const parts = didJwk.split(":");
288
+ if (parts.length !== 3) {
289
+ throw new OmaTrustError("INVALID_DID", "did:jwk must have exactly 3 colon-separated parts", {
290
+ input: didJwk
291
+ });
292
+ }
293
+ const encoded = parts[2];
294
+ if (!encoded || encoded.length === 0) {
295
+ throw new OmaTrustError("INVALID_DID", "Missing base64url-encoded JWK identifier", {
296
+ input: didJwk
297
+ });
298
+ }
299
+ let decoded;
300
+ try {
301
+ const bytes = base64url.decode(encoded);
302
+ decoded = new TextDecoder().decode(bytes);
303
+ } catch {
304
+ throw new OmaTrustError("INVALID_DID", "Failed to base64url-decode did:jwk identifier", {
305
+ input: didJwk
306
+ });
307
+ }
308
+ let jwk;
309
+ try {
310
+ jwk = JSON.parse(decoded);
311
+ } catch {
312
+ throw new OmaTrustError("INVALID_DID", "Decoded did:jwk identifier is not valid JSON", {
313
+ input: didJwk
314
+ });
315
+ }
316
+ if (!jwk || typeof jwk !== "object" || Array.isArray(jwk)) {
317
+ throw new OmaTrustError("INVALID_DID", "Decoded did:jwk must be a JSON object", {
318
+ input: didJwk
319
+ });
320
+ }
321
+ const validation = validatePublicJwk(jwk);
322
+ if (!validation.valid) {
323
+ throw new OmaTrustError("INVALID_DID", validation.error ?? "Invalid public JWK in did:jwk", {
324
+ input: didJwk
325
+ });
326
+ }
327
+ return jwk;
328
+ }
329
+ function extractPublicKeyFields(jwk) {
330
+ const result = {};
331
+ const metadataFields = /* @__PURE__ */ new Set(["kid", "use", "key_ops", "alg", "ext"]);
332
+ for (const [key, value] of Object.entries(jwk)) {
333
+ if (PRIVATE_KEY_FIELDS.has(key)) continue;
334
+ if (metadataFields.has(key)) continue;
335
+ result[key] = value;
336
+ }
337
+ return result;
338
+ }
339
+ function publicJwkEquals(a, b) {
340
+ assertObject(a, "a", "INVALID_JWK");
341
+ assertObject(b, "b", "INVALID_JWK");
342
+ const aObj = a;
343
+ const bObj = b;
344
+ for (const field of PRIVATE_KEY_FIELDS) {
345
+ if (field in aObj) {
346
+ throw new OmaTrustError(
347
+ "INVALID_JWK",
348
+ `First JWK contains private key field "${field}"`,
349
+ { field }
350
+ );
351
+ }
352
+ if (field in bObj) {
353
+ throw new OmaTrustError(
354
+ "INVALID_JWK",
355
+ `Second JWK contains private key field "${field}"`,
356
+ { field }
357
+ );
358
+ }
359
+ }
360
+ const aPublic = extractPublicKeyFields(aObj);
361
+ const bPublic = extractPublicKeyFields(bObj);
362
+ return canonicalizeJwkJson(aPublic) === canonicalizeJwkJson(bPublic);
363
+ }
225
364
 
226
365
  // src/identity/did.ts
227
366
  var DID_REGEX = /^did:[a-z0-9]+:.+$/i;
@@ -293,7 +432,7 @@ function normalizeDidKey(input) {
293
432
  }
294
433
  function normalizeDid(input) {
295
434
  assertString(input, "input", "INVALID_DID");
296
- const trimmed = input.trim();
435
+ const trimmed = input.trim().split("#")[0];
297
436
  if (!trimmed.startsWith("did:")) {
298
437
  return normalizeDidWeb(trimmed);
299
438
  }
@@ -454,6 +593,10 @@ function validateDidJwk(did) {
454
593
  error: "DID must reference a public key \u2014 private key component (d) is not allowed"
455
594
  };
456
595
  }
596
+ const jwkValidation = validatePublicJwk(jwk);
597
+ if (!jwkValidation.valid) {
598
+ return { valid: false, method: "jwk", error: jwkValidation.error };
599
+ }
457
600
  return { valid: true, method: "jwk" };
458
601
  }
459
602
  function normalizeDidJwk(input) {
@@ -1122,145 +1265,6 @@ function getExplorerTxUrl(chainId, txHash) {
1122
1265
  function getExplorerAddressUrl(chainId, address) {
1123
1266
  return `${getConfig(chainId).explorer}/address/${address}`;
1124
1267
  }
1125
- var VALID_KTY = /* @__PURE__ */ new Set(["EC", "OKP", "RSA"]);
1126
- var PRIVATE_KEY_FIELDS = /* @__PURE__ */ new Set(["d", "p", "q", "dp", "dq", "qi", "oth"]);
1127
- var REQUIRED_PUBLIC_FIELDS = {
1128
- EC: ["crv", "x", "y"],
1129
- OKP: ["crv", "x"],
1130
- RSA: ["n", "e"]
1131
- };
1132
- function validatePublicJwk(jwk) {
1133
- if (!jwk || typeof jwk !== "object" || Array.isArray(jwk)) {
1134
- return { valid: false, error: "JWK must be a non-null object" };
1135
- }
1136
- const obj = jwk;
1137
- const kty = obj.kty;
1138
- if (typeof kty !== "string" || !VALID_KTY.has(kty)) {
1139
- return {
1140
- valid: false,
1141
- error: `Invalid or missing kty (must be one of: ${[...VALID_KTY].join(", ")})`
1142
- };
1143
- }
1144
- for (const field of PRIVATE_KEY_FIELDS) {
1145
- if (field in obj) {
1146
- return {
1147
- valid: false,
1148
- error: `JWK contains private key field "${field}" \u2014 only public keys are allowed`
1149
- };
1150
- }
1151
- }
1152
- const required = REQUIRED_PUBLIC_FIELDS[kty];
1153
- if (required) {
1154
- for (const field of required) {
1155
- if (!(field in obj) || obj[field] === void 0 || obj[field] === null || obj[field] === "") {
1156
- return {
1157
- valid: false,
1158
- error: `Missing required public key field "${field}" for kty="${kty}"`
1159
- };
1160
- }
1161
- }
1162
- }
1163
- return { valid: true };
1164
- }
1165
- function canonicalizeJwkJson(jwk) {
1166
- const sorted = Object.keys(jwk).sort();
1167
- const obj = {};
1168
- for (const key of sorted) {
1169
- obj[key] = jwk[key];
1170
- }
1171
- return JSON.stringify(obj);
1172
- }
1173
- function jwkToDidJwk(jwk) {
1174
- assertObject(jwk, "jwk", "INVALID_JWK");
1175
- const validation = validatePublicJwk(jwk);
1176
- if (!validation.valid) {
1177
- throw new OmaTrustError("INVALID_JWK", validation.error ?? "Invalid public JWK", { jwk });
1178
- }
1179
- const canonical = canonicalizeJwkJson(jwk);
1180
- const encoded = base64url.encode(new TextEncoder().encode(canonical));
1181
- return `did:jwk:${encoded}`;
1182
- }
1183
- function didJwkToJwk(didJwk) {
1184
- if (typeof didJwk !== "string" || !didJwk.startsWith("did:jwk:")) {
1185
- throw new OmaTrustError("INVALID_DID", "Expected a did:jwk DID", { input: didJwk });
1186
- }
1187
- const parts = didJwk.split(":");
1188
- if (parts.length !== 3) {
1189
- throw new OmaTrustError("INVALID_DID", "did:jwk must have exactly 3 colon-separated parts", {
1190
- input: didJwk
1191
- });
1192
- }
1193
- const encoded = parts[2];
1194
- if (!encoded || encoded.length === 0) {
1195
- throw new OmaTrustError("INVALID_DID", "Missing base64url-encoded JWK identifier", {
1196
- input: didJwk
1197
- });
1198
- }
1199
- let decoded;
1200
- try {
1201
- const bytes = base64url.decode(encoded);
1202
- decoded = new TextDecoder().decode(bytes);
1203
- } catch {
1204
- throw new OmaTrustError("INVALID_DID", "Failed to base64url-decode did:jwk identifier", {
1205
- input: didJwk
1206
- });
1207
- }
1208
- let jwk;
1209
- try {
1210
- jwk = JSON.parse(decoded);
1211
- } catch {
1212
- throw new OmaTrustError("INVALID_DID", "Decoded did:jwk identifier is not valid JSON", {
1213
- input: didJwk
1214
- });
1215
- }
1216
- if (!jwk || typeof jwk !== "object" || Array.isArray(jwk)) {
1217
- throw new OmaTrustError("INVALID_DID", "Decoded did:jwk must be a JSON object", {
1218
- input: didJwk
1219
- });
1220
- }
1221
- const validation = validatePublicJwk(jwk);
1222
- if (!validation.valid) {
1223
- throw new OmaTrustError("INVALID_DID", validation.error ?? "Invalid public JWK in did:jwk", {
1224
- input: didJwk
1225
- });
1226
- }
1227
- return jwk;
1228
- }
1229
- function extractPublicKeyFields(jwk) {
1230
- const result = {};
1231
- const metadataFields = /* @__PURE__ */ new Set(["kid", "use", "key_ops", "alg", "ext"]);
1232
- for (const [key, value] of Object.entries(jwk)) {
1233
- if (PRIVATE_KEY_FIELDS.has(key)) continue;
1234
- if (metadataFields.has(key)) continue;
1235
- result[key] = value;
1236
- }
1237
- return result;
1238
- }
1239
- function publicJwkEquals(a, b) {
1240
- assertObject(a, "a", "INVALID_JWK");
1241
- assertObject(b, "b", "INVALID_JWK");
1242
- const aObj = a;
1243
- const bObj = b;
1244
- for (const field of PRIVATE_KEY_FIELDS) {
1245
- if (field in aObj) {
1246
- throw new OmaTrustError(
1247
- "INVALID_JWK",
1248
- `First JWK contains private key field "${field}"`,
1249
- { field }
1250
- );
1251
- }
1252
- if (field in bObj) {
1253
- throw new OmaTrustError(
1254
- "INVALID_JWK",
1255
- `Second JWK contains private key field "${field}"`,
1256
- { field }
1257
- );
1258
- }
1259
- }
1260
- const aPublic = extractPublicKeyFields(aObj);
1261
- const bPublic = extractPublicKeyFields(bObj);
1262
- return canonicalizeJwkJson(aPublic) === canonicalizeJwkJson(bPublic);
1263
- }
1264
1268
 
1265
1269
  // src/shared/did-document.ts
1266
1270
  async function fetchDidDocument(domain) {
@@ -2862,6 +2866,42 @@ function createX402OfferProof(offer) {
2862
2866
  };
2863
2867
  }
2864
2868
 
2869
+ // src/reputation/proof/x402-verify.ts
2870
+ async function verifyX402Artifact(artifact, options) {
2871
+ if (!artifact || typeof artifact !== "object") {
2872
+ return {
2873
+ valid: false,
2874
+ error: { code: "INVALID_ARTIFACT", message: "Artifact must be a non-null object" }
2875
+ };
2876
+ }
2877
+ const format = artifact.format;
2878
+ switch (format) {
2879
+ case "jws": {
2880
+ const jwsArtifact = artifact;
2881
+ const jwsOptions = options.resolveOptions ? { resolveOptions: options.resolveOptions } : void 0;
2882
+ if (options.artifactType === "offer") {
2883
+ return verifyX402JwsOffer(jwsArtifact, jwsOptions);
2884
+ }
2885
+ return verifyX402JwsReceipt(jwsArtifact, jwsOptions);
2886
+ }
2887
+ case "eip712": {
2888
+ const eip712Artifact = artifact;
2889
+ if (options.artifactType === "offer") {
2890
+ return verifyX402Eip712Offer(eip712Artifact);
2891
+ }
2892
+ return verifyX402Eip712Receipt(eip712Artifact);
2893
+ }
2894
+ default:
2895
+ return {
2896
+ valid: false,
2897
+ error: {
2898
+ code: "UNSUPPORTED_FORMAT",
2899
+ message: `Unsupported x402 artifact format: "${format}"`
2900
+ }
2901
+ };
2902
+ }
2903
+ }
2904
+
2865
2905
  // src/reputation/proof/evidence-pointer.ts
2866
2906
  function createEvidencePointerProof(url) {
2867
2907
  if (!url || typeof url !== "string") {
@@ -3147,7 +3187,301 @@ async function verifySubjectOwnership(params) {
3147
3187
  subjectDid
3148
3188
  });
3149
3189
  }
3190
+ function extractEip712Signer(proof) {
3191
+ const { domain, message, signature } = proof.proofObject;
3192
+ const typedData = {
3193
+ domain,
3194
+ types: {
3195
+ OmaTrustProof: [
3196
+ { name: "signer", type: "address" },
3197
+ { name: "authorizedEntity", type: "string" },
3198
+ { name: "signingPurpose", type: "string" },
3199
+ { name: "creationTimestamp", type: "uint256" },
3200
+ { name: "expirationTimestamp", type: "uint256" },
3201
+ { name: "randomValue", type: "bytes32" },
3202
+ { name: "statement", type: "string" }
3203
+ ]
3204
+ },
3205
+ message
3206
+ };
3207
+ try {
3208
+ const result = verifyEip712Signature(typedData, signature);
3209
+ return result.valid && result.signer ? result.signer : null;
3210
+ } catch (err) {
3211
+ console.warn("[omatrust] EIP-712 signer extraction failed:", err);
3212
+ return null;
3213
+ }
3214
+ }
3215
+ function extractJwsHeaderJwk(proof) {
3216
+ const jws = proof.proofObject;
3217
+ if (typeof jws !== "string") return null;
3218
+ const parts = jws.split(".");
3219
+ if (parts.length !== 3) return null;
3220
+ try {
3221
+ const headerB64 = parts[0].replace(/-/g, "+").replace(/_/g, "/");
3222
+ const padded = headerB64.padEnd(
3223
+ headerB64.length + (4 - headerB64.length % 4) % 4,
3224
+ "="
3225
+ );
3226
+ let headerJson;
3227
+ if (typeof atob === "function") {
3228
+ headerJson = decodeURIComponent(
3229
+ Array.from(atob(padded)).map((char) => `%${char.charCodeAt(0).toString(16).padStart(2, "0")}`).join("")
3230
+ );
3231
+ } else {
3232
+ headerJson = Buffer.from(padded, "base64").toString("utf8");
3233
+ }
3234
+ const header = JSON.parse(headerJson);
3235
+ return header.jwk ?? null;
3236
+ } catch {
3237
+ return null;
3238
+ }
3239
+ }
3240
+ function extractJwsPayload(proof) {
3241
+ const jws = proof.proofObject;
3242
+ if (typeof jws !== "string") return null;
3243
+ const parts = jws.split(".");
3244
+ if (parts.length !== 3) return null;
3245
+ try {
3246
+ const payloadB64 = parts[1].replace(/-/g, "+").replace(/_/g, "/");
3247
+ const padded = payloadB64.padEnd(
3248
+ payloadB64.length + (4 - payloadB64.length % 4) % 4,
3249
+ "="
3250
+ );
3251
+ let payloadJson;
3252
+ if (typeof atob === "function") {
3253
+ payloadJson = decodeURIComponent(
3254
+ Array.from(atob(padded)).map((char) => `%${char.charCodeAt(0).toString(16).padStart(2, "0")}`).join("")
3255
+ );
3256
+ } else {
3257
+ payloadJson = Buffer.from(padded, "base64").toString("utf8");
3258
+ }
3259
+ return JSON.parse(payloadJson);
3260
+ } catch {
3261
+ return null;
3262
+ }
3263
+ }
3264
+ function signerMatchesDid(signerAddress, did) {
3265
+ try {
3266
+ const didAddress = extractAddressFromDid(did);
3267
+ return getAddress(signerAddress).toLowerCase() === getAddress(didAddress).toLowerCase();
3268
+ } catch {
3269
+ return false;
3270
+ }
3271
+ }
3272
+ function jwkMatchesDid(jwk, did) {
3273
+ const method = extractDidMethod(did);
3274
+ if (method === "jwk") {
3275
+ try {
3276
+ const didJwk = didJwkToJwk(did);
3277
+ return publicJwkEquals(jwk, didJwk);
3278
+ } catch {
3279
+ return false;
3280
+ }
3281
+ }
3282
+ return false;
3283
+ }
3284
+ function proofSignerMatchesDid(proof, did) {
3285
+ switch (proof.proofType) {
3286
+ case "pop-eip712": {
3287
+ const signer = extractEip712Signer(proof);
3288
+ if (!signer) return false;
3289
+ return signerMatchesDid(signer, did);
3290
+ }
3291
+ case "pop-jws": {
3292
+ const jwsProof = proof;
3293
+ const jwk = extractJwsHeaderJwk(jwsProof);
3294
+ if (jwk && jwkMatchesDid(jwk, did)) return true;
3295
+ const payload = extractJwsPayload(jwsProof);
3296
+ if (payload && typeof payload.iss === "string") {
3297
+ if (payload.iss === did) return true;
3298
+ }
3299
+ return false;
3300
+ }
3301
+ case "tx-encoded-value":
3302
+ case "tx-interaction":
3303
+ return false;
3304
+ case "evidence-pointer":
3305
+ return false;
3306
+ default:
3307
+ return false;
3308
+ }
3309
+ }
3310
+ function proofAuthorizedEntityMatchesDid(proof, did) {
3311
+ switch (proof.proofType) {
3312
+ case "pop-eip712": {
3313
+ const eip712 = proof;
3314
+ const authorizedEntity = eip712.proofObject.message.authorizedEntity;
3315
+ return typeof authorizedEntity === "string" && authorizedEntity === did;
3316
+ }
3317
+ case "pop-jws": {
3318
+ const payload = extractJwsPayload(proof);
3319
+ if (!payload) return false;
3320
+ return typeof payload.aud === "string" && payload.aud === did;
3321
+ }
3322
+ default:
3323
+ return false;
3324
+ }
3325
+ }
3326
+ function verifyLinkedIdentifierProofs(data) {
3327
+ if (!data.subject || !data.linkedId) {
3328
+ return {
3329
+ valid: false,
3330
+ checks: [],
3331
+ reasons: ["subject and linkedId are required"]
3332
+ };
3333
+ }
3334
+ if (!Array.isArray(data.proofs) || data.proofs.length === 0) {
3335
+ return {
3336
+ valid: false,
3337
+ checks: [],
3338
+ reasons: ["At least one proof is required"]
3339
+ };
3340
+ }
3341
+ const checks = [];
3342
+ let subjectProved = false;
3343
+ let linkedIdProved = false;
3344
+ for (let i = 0; i < data.proofs.length; i++) {
3345
+ const proof = data.proofs[i];
3346
+ if (proofSignerMatchesDid(proof, data.subject)) {
3347
+ checks.push({
3348
+ proofIndex: i,
3349
+ proofType: proof.proofType,
3350
+ checkType: "signer-is-subject",
3351
+ valid: true
3352
+ });
3353
+ subjectProved = true;
3354
+ if (!proofAuthorizedEntityMatchesDid(proof, data.linkedId)) {
3355
+ checks.push({
3356
+ proofIndex: i,
3357
+ proofType: proof.proofType,
3358
+ checkType: "signer-is-subject",
3359
+ valid: false,
3360
+ reason: "Proof from subject does not authorize linkedId (aud mismatch)"
3361
+ });
3362
+ }
3363
+ }
3364
+ if (proofSignerMatchesDid(proof, data.linkedId)) {
3365
+ checks.push({
3366
+ proofIndex: i,
3367
+ proofType: proof.proofType,
3368
+ checkType: "signer-is-linkedId",
3369
+ valid: true
3370
+ });
3371
+ linkedIdProved = true;
3372
+ if (!proofAuthorizedEntityMatchesDid(proof, data.subject)) {
3373
+ checks.push({
3374
+ proofIndex: i,
3375
+ proofType: proof.proofType,
3376
+ checkType: "signer-is-linkedId",
3377
+ valid: false,
3378
+ reason: "Proof from linkedId does not authorize subject (aud mismatch)"
3379
+ });
3380
+ }
3381
+ }
3382
+ if (proof.proofType === "evidence-pointer") {
3383
+ checks.push({
3384
+ proofIndex: i,
3385
+ proofType: proof.proofType,
3386
+ checkType: "signer-is-subject",
3387
+ valid: true,
3388
+ reason: "Evidence pointer accepted (requires URL fetch for full verification)"
3389
+ });
3390
+ subjectProved = true;
3391
+ }
3392
+ }
3393
+ const reasons = [];
3394
+ if (!subjectProved) {
3395
+ reasons.push("No proof demonstrates control by subject");
3396
+ }
3397
+ if (!linkedIdProved) {
3398
+ reasons.push("No proof demonstrates control by linkedId");
3399
+ }
3400
+ return {
3401
+ valid: reasons.length === 0,
3402
+ checks,
3403
+ reasons
3404
+ };
3405
+ }
3406
+ function verifyKeyBindingProofs(data) {
3407
+ if (!data.subject || !data.keyId) {
3408
+ return {
3409
+ valid: false,
3410
+ checks: [],
3411
+ reasons: ["subject and keyId are required"]
3412
+ };
3413
+ }
3414
+ if (!Array.isArray(data.proofs) || data.proofs.length === 0) {
3415
+ return {
3416
+ valid: false,
3417
+ checks: [],
3418
+ reasons: ["At least one proof is required"]
3419
+ };
3420
+ }
3421
+ const checks = [];
3422
+ let subjectAuthorizedKey = false;
3423
+ for (let i = 0; i < data.proofs.length; i++) {
3424
+ const proof = data.proofs[i];
3425
+ if (proofSignerMatchesDid(proof, data.subject)) {
3426
+ const authorizesKey = proofAuthorizedEntityMatchesDid(proof, data.keyId);
3427
+ checks.push({
3428
+ proofIndex: i,
3429
+ proofType: proof.proofType,
3430
+ checkType: "signer-is-subject-for-key",
3431
+ valid: authorizesKey,
3432
+ reason: authorizesKey ? void 0 : "Proof signed by subject but does not authorize the keyId"
3433
+ });
3434
+ if (authorizesKey) {
3435
+ subjectAuthorizedKey = true;
3436
+ }
3437
+ }
3438
+ if (proofSignerMatchesDid(proof, data.keyId)) {
3439
+ checks.push({
3440
+ proofIndex: i,
3441
+ proofType: proof.proofType,
3442
+ checkType: "signer-is-keyId",
3443
+ valid: true,
3444
+ reason: "Key proved possession (supplementary, not sufficient alone)"
3445
+ });
3446
+ }
3447
+ if (proof.proofType === "evidence-pointer") {
3448
+ checks.push({
3449
+ proofIndex: i,
3450
+ proofType: proof.proofType,
3451
+ checkType: "signer-is-subject-for-key",
3452
+ valid: true,
3453
+ reason: "Evidence pointer accepted (requires URL fetch for full verification)"
3454
+ });
3455
+ subjectAuthorizedKey = true;
3456
+ }
3457
+ }
3458
+ if (data.publicKeyJwk && extractDidMethod(data.keyId) === "jwk") {
3459
+ try {
3460
+ const keyIdJwk = didJwkToJwk(data.keyId);
3461
+ const jwkConsistent = publicJwkEquals(data.publicKeyJwk, keyIdJwk);
3462
+ if (!jwkConsistent) {
3463
+ return {
3464
+ valid: false,
3465
+ checks,
3466
+ reasons: ["publicKeyJwk does not match the key material in keyId (did:jwk)"]
3467
+ };
3468
+ }
3469
+ } catch {
3470
+ }
3471
+ }
3472
+ const reasons = [];
3473
+ if (!subjectAuthorizedKey) {
3474
+ reasons.push(
3475
+ "No proof demonstrates that subject authorized the key binding"
3476
+ );
3477
+ }
3478
+ return {
3479
+ valid: reasons.length === 0,
3480
+ checks,
3481
+ reasons
3482
+ };
3483
+ }
3150
3484
 
3151
- export { EIP1967_ADMIN_SLOT, OWNERSHIP_PATTERNS, buildDelegatedAttestationTypedData, buildDelegatedTypedDataFromEncoded, buildDnsTxtRecord, buildEip712Domain, calculateAverageUserReviewRating, calculateTransferAmount, calculateTransferAmountFromAddresses, callControllerWitness, constructSeed, createEvidencePointerProof, createPopEip712Proof, createPopJwsProof, createTxEncodedValueProof, createTxInteractionProof, createX402OfferProof, createX402ReceiptProof, decodeAttestationData, deduplicateReviews, discoverContractOwner, discoverControllingWalletDid, encodeAttestationData, extractEvmAddressesFromDidDocument, extractExpirationTime, extractJwksFromDidDocument, fetchDidDocument, formatSchemaUid, formatTransferAmount, getAttestation, getAttestationsByAttester, getAttestationsForDid, getChainConstants, getControllerAuthorization, getExplorerAddressUrl, getExplorerTxUrl, getLatestAttestations, getMajorVersion, getOmaTrustProofEip712Types, getSchemaDetails, getSupportedChainIds, hashSeed, isChainSupported, listAttestations, normalizeSchema, parseDnsTxtRecord, prepareDelegatedAttestation, readOwnerFromContract, requestControllerWitness, revokeAttestation, schemaToString, splitSignature, submitAttestation, submitDelegatedAttestation, validateAttestationData, verifyAttestation, verifyDidDocumentControllerDid, verifyDidJsonControllerDid, verifyDidPkhOwnership, verifyDidWebOwnership, verifyDnsTxtControllerDid2 as verifyDnsTxtControllerDid, verifyEip712Signature, verifyProof, verifySchemaExists, verifySubjectOwnership, verifyTransferProof, verifyX402Eip712Artifact, verifyX402Eip712Offer, verifyX402Eip712Receipt, verifyX402JwsArtifact, verifyX402JwsOffer, verifyX402JwsReceipt };
3485
+ export { EIP1967_ADMIN_SLOT, OWNERSHIP_PATTERNS, buildDelegatedAttestationTypedData, buildDelegatedTypedDataFromEncoded, buildDnsTxtRecord, buildEip712Domain, calculateAverageUserReviewRating, calculateTransferAmount, calculateTransferAmountFromAddresses, callControllerWitness, constructSeed, createEvidencePointerProof, createPopEip712Proof, createPopJwsProof, createTxEncodedValueProof, createTxInteractionProof, createX402OfferProof, createX402ReceiptProof, decodeAttestationData, deduplicateReviews, discoverContractOwner, discoverControllingWalletDid, encodeAttestationData, extractEvmAddressesFromDidDocument, extractExpirationTime, extractJwksFromDidDocument, fetchDidDocument, formatSchemaUid, formatTransferAmount, getAttestation, getAttestationsByAttester, getAttestationsForDid, getChainConstants, getControllerAuthorization, getExplorerAddressUrl, getExplorerTxUrl, getLatestAttestations, getMajorVersion, getOmaTrustProofEip712Types, getSchemaDetails, getSupportedChainIds, hashSeed, isChainSupported, listAttestations, normalizeSchema, parseDnsTxtRecord, prepareDelegatedAttestation, readOwnerFromContract, requestControllerWitness, revokeAttestation, schemaToString, splitSignature, submitAttestation, submitDelegatedAttestation, validateAttestationData, verifyAttestation, verifyDidDocumentControllerDid, verifyDidJsonControllerDid, verifyDidPkhOwnership, verifyDidWebOwnership, verifyDnsTxtControllerDid2 as verifyDnsTxtControllerDid, verifyEip712Signature, verifyKeyBindingProofs, verifyLinkedIdentifierProofs, verifyProof, verifySchemaExists, verifySubjectOwnership, verifyTransferProof, verifyX402Artifact, verifyX402Eip712Artifact, verifyX402Eip712Offer, verifyX402Eip712Receipt, verifyX402JwsArtifact, verifyX402JwsOffer, verifyX402JwsReceipt };
3152
3486
  //# sourceMappingURL=index.js.map
3153
3487
  //# sourceMappingURL=index.js.map