@oma3/omatrust 0.1.0-alpha.11 → 0.1.0-alpha.13

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 (42) 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-Bu-xxcv9.d.ts +407 -0
  13. package/dist/index-C7odEbp6.d.cts +407 -0
  14. package/dist/index-CnWY9arI.d.cts +612 -0
  15. package/dist/index-DREQRFIE.d.ts +612 -0
  16. package/dist/index.cjs +1316 -202
  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 +1297 -202
  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 +884 -163
  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 +860 -164
  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-C2w5EvFH.d.ts +0 -329
  41. package/dist/index-QueRiudB.d.cts +0 -329
  42. package/dist/index-R78TpAhN.d.ts +0 -235
package/dist/index.cjs CHANGED
@@ -3,12 +3,36 @@
3
3
  var ethers = require('ethers');
4
4
  var jose = require('jose');
5
5
  var canonicalize = require('canonicalize');
6
+ var cid = require('multiformats/cid');
7
+ var sha2 = require('multiformats/hashes/sha2');
8
+ var raw = require('multiformats/codecs/raw');
9
+ var base32 = require('multiformats/bases/base32');
10
+ var base58 = require('multiformats/bases/base58');
6
11
  var easSdk = require('@ethereum-attestation-service/eas-sdk');
7
12
  var promises = require('dns/promises');
8
13
 
9
14
  function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
10
15
 
16
+ function _interopNamespace(e) {
17
+ if (e && e.__esModule) return e;
18
+ var n = Object.create(null);
19
+ if (e) {
20
+ Object.keys(e).forEach(function (k) {
21
+ if (k !== 'default') {
22
+ var d = Object.getOwnPropertyDescriptor(e, k);
23
+ Object.defineProperty(n, k, d.get ? d : {
24
+ enumerable: true,
25
+ get: function () { return e[k]; }
26
+ });
27
+ }
28
+ });
29
+ }
30
+ n.default = e;
31
+ return Object.freeze(n);
32
+ }
33
+
11
34
  var canonicalize__default = /*#__PURE__*/_interopDefault(canonicalize);
35
+ var raw__namespace = /*#__PURE__*/_interopNamespace(raw);
12
36
 
13
37
  var __defProp = Object.defineProperty;
14
38
  var __export = (target, all) => {
@@ -20,31 +44,31 @@ var __export = (target, all) => {
20
44
  var OmaTrustError = class extends Error {
21
45
  code;
22
46
  details;
23
- constructor(code, message, details) {
47
+ constructor(code2, message, details) {
24
48
  super(message);
25
49
  this.name = "OmaTrustError";
26
- this.code = code;
50
+ this.code = code2;
27
51
  this.details = details;
28
52
  }
29
53
  };
30
- function toOmaTrustError(code, message, details) {
31
- return new OmaTrustError(code, message, details);
54
+ function toOmaTrustError(code2, message, details) {
55
+ return new OmaTrustError(code2, message, details);
32
56
  }
33
57
 
34
58
  // src/shared/assert.ts
35
- function assertString(value, name, code = "INVALID_INPUT") {
59
+ function assertString(value, name, code2 = "INVALID_INPUT") {
36
60
  if (typeof value !== "string" || value.trim().length === 0) {
37
- throw new OmaTrustError(code, `${name} must be a non-empty string`, { value });
61
+ throw new OmaTrustError(code2, `${name} must be a non-empty string`, { value });
38
62
  }
39
63
  }
40
- function assertNumber(value, name, code = "INVALID_INPUT") {
64
+ function assertNumber(value, name, code2 = "INVALID_INPUT") {
41
65
  if (typeof value !== "number" || Number.isNaN(value)) {
42
- throw new OmaTrustError(code, `${name} must be a valid number`, { value });
66
+ throw new OmaTrustError(code2, `${name} must be a valid number`, { value });
43
67
  }
44
68
  }
45
- function assertObject(value, name, code = "INVALID_INPUT") {
69
+ function assertObject(value, name, code2 = "INVALID_INPUT") {
46
70
  if (!value || typeof value !== "object" || Array.isArray(value)) {
47
- throw new OmaTrustError(code, `${name} must be an object`, { value });
71
+ throw new OmaTrustError(code2, `${name} must be an object`, { value });
48
72
  }
49
73
  }
50
74
  function asError(err) {
@@ -57,19 +81,25 @@ function asError(err) {
57
81
  // src/identity/index.ts
58
82
  var identity_exports = {};
59
83
  __export(identity_exports, {
84
+ artifactDidFromBytes: () => artifactDidFromBytes,
85
+ artifactDidFromJson: () => artifactDidFromJson,
60
86
  assertBareDid: () => assertBareDid,
87
+ assertJsonSafe: () => assertJsonSafe,
61
88
  buildCaip10: () => buildCaip10,
62
89
  buildCaip2: () => buildCaip2,
63
90
  buildDidPkh: () => buildDidPkh,
64
91
  buildDidPkhFromCaip10: () => buildDidPkhFromCaip10,
65
92
  buildDidWeb: () => buildDidWeb,
66
93
  buildEvmDidPkh: () => buildEvmDidPkh,
94
+ canonicalizeAndKeccak256: () => canonicalizeAndKeccak256,
67
95
  canonicalizeForHash: () => canonicalizeForHash,
68
96
  canonicalizeJson: () => canonicalizeJson,
69
97
  computeDidAddress: () => computeDidAddress,
70
98
  computeDidHash: () => computeDidHash,
71
99
  computeJwkThumbprint: () => computeJwkThumbprint,
100
+ didEthrToDidPkh: () => didEthrToDidPkh,
72
101
  didJwkToJwk: () => didJwkToJwk,
102
+ didKeyToDidJwk: () => didKeyToDidJwk,
73
103
  didToAddress: () => didToAddress,
74
104
  extractAddressFromDid: () => extractAddressFromDid,
75
105
  extractAuthorizationMetadata: () => extractAuthorizationMetadata,
@@ -96,15 +126,18 @@ __export(identity_exports, {
96
126
  normalizeDidPkh: () => normalizeDidPkh,
97
127
  normalizeDidWeb: () => normalizeDidWeb,
98
128
  normalizeDomain: () => normalizeDomain,
129
+ parseArtifactDid: () => parseArtifactDid,
99
130
  parseCaip10: () => parseCaip10,
100
131
  parseCaip2: () => parseCaip2,
101
132
  parseDidUrl: () => parseDidUrl,
133
+ parseJsonStrict: () => parseJsonStrict,
102
134
  publicJwkEquals: () => publicJwkEquals,
103
135
  resolveDidUrlToControllerDid: () => resolveDidUrlToControllerDid,
104
136
  resolveDidUrlToPublicKey: () => resolveDidUrlToPublicKey,
105
137
  validateDidAddress: () => validateDidAddress,
106
138
  validatePrivateKeyDid: () => validatePrivateKeyDid,
107
- validatePublicJwk: () => validatePublicJwk
139
+ validatePublicJwk: () => validatePublicJwk,
140
+ verifyDidArtifact: () => verifyDidArtifact
108
141
  });
109
142
 
110
143
  // src/identity/caip.ts
@@ -160,6 +193,158 @@ function parseCaip2(caip2) {
160
193
  }
161
194
  return { namespace, reference };
162
195
  }
196
+ var VALID_KTY = /* @__PURE__ */ new Set(["EC", "OKP", "RSA"]);
197
+ var PRIVATE_KEY_FIELDS = /* @__PURE__ */ new Set(["d", "p", "q", "dp", "dq", "qi", "oth"]);
198
+ var REQUIRED_PUBLIC_FIELDS = {
199
+ EC: ["crv", "x", "y"],
200
+ OKP: ["crv", "x"],
201
+ RSA: ["n", "e"]
202
+ };
203
+ function validatePublicJwk(jwk) {
204
+ if (!jwk || typeof jwk !== "object" || Array.isArray(jwk)) {
205
+ return { valid: false, error: "JWK must be a non-null object" };
206
+ }
207
+ const obj = jwk;
208
+ const kty = obj.kty;
209
+ if (typeof kty !== "string" || !VALID_KTY.has(kty)) {
210
+ return {
211
+ valid: false,
212
+ error: `Invalid or missing kty (must be one of: ${[...VALID_KTY].join(", ")})`
213
+ };
214
+ }
215
+ for (const field of PRIVATE_KEY_FIELDS) {
216
+ if (field in obj) {
217
+ return {
218
+ valid: false,
219
+ error: `JWK contains private key field "${field}" \u2014 only public keys are allowed`
220
+ };
221
+ }
222
+ }
223
+ const required = REQUIRED_PUBLIC_FIELDS[kty];
224
+ if (required) {
225
+ for (const field of required) {
226
+ if (!(field in obj) || obj[field] === void 0 || obj[field] === null || obj[field] === "") {
227
+ return {
228
+ valid: false,
229
+ error: `Missing required public key field "${field}" for kty="${kty}"`
230
+ };
231
+ }
232
+ }
233
+ }
234
+ return { valid: true };
235
+ }
236
+ function canonicalizeJwkJson(jwk) {
237
+ const sorted = Object.keys(jwk).sort();
238
+ const obj = {};
239
+ for (const key of sorted) {
240
+ obj[key] = jwk[key];
241
+ }
242
+ return JSON.stringify(obj);
243
+ }
244
+ function jwkToDidJwk(jwk) {
245
+ assertObject(jwk, "jwk", "INVALID_JWK");
246
+ const validation = validatePublicJwk(jwk);
247
+ if (!validation.valid) {
248
+ throw new OmaTrustError("INVALID_JWK", validation.error ?? "Invalid public JWK", { jwk });
249
+ }
250
+ const canonical = canonicalizeJwkJson(jwk);
251
+ const encoded = jose.base64url.encode(new TextEncoder().encode(canonical));
252
+ return `did:jwk:${encoded}`;
253
+ }
254
+ function didJwkToJwk(didJwk) {
255
+ if (typeof didJwk !== "string" || !didJwk.startsWith("did:jwk:")) {
256
+ throw new OmaTrustError("INVALID_DID", "Expected a did:jwk DID", { input: didJwk });
257
+ }
258
+ const parts = didJwk.split(":");
259
+ if (parts.length !== 3) {
260
+ throw new OmaTrustError("INVALID_DID", "did:jwk must have exactly 3 colon-separated parts", {
261
+ input: didJwk
262
+ });
263
+ }
264
+ const encoded = parts[2];
265
+ if (!encoded || encoded.length === 0) {
266
+ throw new OmaTrustError("INVALID_DID", "Missing base64url-encoded JWK identifier", {
267
+ input: didJwk
268
+ });
269
+ }
270
+ let decoded;
271
+ try {
272
+ const bytes = jose.base64url.decode(encoded);
273
+ decoded = new TextDecoder().decode(bytes);
274
+ } catch {
275
+ throw new OmaTrustError("INVALID_DID", "Failed to base64url-decode did:jwk identifier", {
276
+ input: didJwk
277
+ });
278
+ }
279
+ let jwk;
280
+ try {
281
+ jwk = JSON.parse(decoded);
282
+ } catch {
283
+ throw new OmaTrustError("INVALID_DID", "Decoded did:jwk identifier is not valid JSON", {
284
+ input: didJwk
285
+ });
286
+ }
287
+ if (!jwk || typeof jwk !== "object" || Array.isArray(jwk)) {
288
+ throw new OmaTrustError("INVALID_DID", "Decoded did:jwk must be a JSON object", {
289
+ input: didJwk
290
+ });
291
+ }
292
+ const validation = validatePublicJwk(jwk);
293
+ if (!validation.valid) {
294
+ throw new OmaTrustError("INVALID_DID", validation.error ?? "Invalid public JWK in did:jwk", {
295
+ input: didJwk
296
+ });
297
+ }
298
+ return jwk;
299
+ }
300
+ function extractPublicKeyFields(jwk) {
301
+ const result = {};
302
+ const metadataFields = /* @__PURE__ */ new Set(["kid", "use", "key_ops", "alg", "ext"]);
303
+ for (const [key, value] of Object.entries(jwk)) {
304
+ if (PRIVATE_KEY_FIELDS.has(key)) continue;
305
+ if (metadataFields.has(key)) continue;
306
+ result[key] = value;
307
+ }
308
+ return result;
309
+ }
310
+ function publicJwkEquals(a, b) {
311
+ assertObject(a, "a", "INVALID_JWK");
312
+ assertObject(b, "b", "INVALID_JWK");
313
+ const aObj = a;
314
+ const bObj = b;
315
+ for (const field of PRIVATE_KEY_FIELDS) {
316
+ if (field in aObj) {
317
+ throw new OmaTrustError(
318
+ "INVALID_JWK",
319
+ `First JWK contains private key field "${field}"`,
320
+ { field }
321
+ );
322
+ }
323
+ if (field in bObj) {
324
+ throw new OmaTrustError(
325
+ "INVALID_JWK",
326
+ `Second JWK contains private key field "${field}"`,
327
+ { field }
328
+ );
329
+ }
330
+ }
331
+ const aPublic = extractPublicKeyFields(aObj);
332
+ const bPublic = extractPublicKeyFields(bObj);
333
+ return canonicalizeJwkJson(aPublic) === canonicalizeJwkJson(bPublic);
334
+ }
335
+ async function computeJwkThumbprint(jwk, digestAlgorithm = "sha256") {
336
+ assertObject(jwk, "jwk", "INVALID_JWK");
337
+ const validation = validatePublicJwk(jwk);
338
+ if (!validation.valid) {
339
+ throw new OmaTrustError("INVALID_JWK", validation.error ?? "Invalid public JWK", { jwk });
340
+ }
341
+ const alg = digestAlgorithm === "sha256" ? "sha256" : digestAlgorithm === "sha384" ? "sha384" : "sha512";
342
+ return jose.calculateJwkThumbprint(jwk, alg);
343
+ }
344
+ async function formatJktValue(jwk) {
345
+ const thumbprint = await computeJwkThumbprint(jwk, "sha256");
346
+ return `jkt=S256:${thumbprint}`;
347
+ }
163
348
 
164
349
  // src/identity/did.ts
165
350
  var DID_REGEX = /^did:[a-z0-9]+:.+$/i;
@@ -235,7 +420,7 @@ function normalizeDidKey(input) {
235
420
  }
236
421
  function normalizeDid(input) {
237
422
  assertString(input, "input", "INVALID_DID");
238
- const trimmed = input.trim();
423
+ const trimmed = input.trim().split("#")[0];
239
424
  if (!trimmed.startsWith("did:")) {
240
425
  return normalizeDidWeb(trimmed);
241
426
  }
@@ -424,6 +609,15 @@ function validateDidPkh(did) {
424
609
  };
425
610
  }
426
611
  }
612
+ if (namespace === "solana") {
613
+ if (!/^[1-9A-HJ-NP-Za-km-z]{32,44}$/.test(address)) {
614
+ return {
615
+ valid: false,
616
+ method: "pkh",
617
+ error: `Invalid Solana address "${address}" (must be 32-44 base58 characters)`
618
+ };
619
+ }
620
+ }
427
621
  return { valid: true, method: "pkh" };
428
622
  }
429
623
  function validateDidJwk(did) {
@@ -477,6 +671,10 @@ function validateDidJwk(did) {
477
671
  error: "DID must reference a public key \u2014 private key component (d) is not allowed"
478
672
  };
479
673
  }
674
+ const jwkValidation = validatePublicJwk(jwk);
675
+ if (!jwkValidation.valid) {
676
+ return { valid: false, method: "jwk", error: jwkValidation.error };
677
+ }
480
678
  return { valid: true, method: "jwk" };
481
679
  }
482
680
  function normalizeDidJwk(input) {
@@ -543,158 +741,6 @@ function assertBareDid(input, paramName = "did") {
543
741
  );
544
742
  }
545
743
  }
546
- var VALID_KTY = /* @__PURE__ */ new Set(["EC", "OKP", "RSA"]);
547
- var PRIVATE_KEY_FIELDS = /* @__PURE__ */ new Set(["d", "p", "q", "dp", "dq", "qi", "oth"]);
548
- var REQUIRED_PUBLIC_FIELDS = {
549
- EC: ["crv", "x", "y"],
550
- OKP: ["crv", "x"],
551
- RSA: ["n", "e"]
552
- };
553
- function validatePublicJwk(jwk) {
554
- if (!jwk || typeof jwk !== "object" || Array.isArray(jwk)) {
555
- return { valid: false, error: "JWK must be a non-null object" };
556
- }
557
- const obj = jwk;
558
- const kty = obj.kty;
559
- if (typeof kty !== "string" || !VALID_KTY.has(kty)) {
560
- return {
561
- valid: false,
562
- error: `Invalid or missing kty (must be one of: ${[...VALID_KTY].join(", ")})`
563
- };
564
- }
565
- for (const field of PRIVATE_KEY_FIELDS) {
566
- if (field in obj) {
567
- return {
568
- valid: false,
569
- error: `JWK contains private key field "${field}" \u2014 only public keys are allowed`
570
- };
571
- }
572
- }
573
- const required = REQUIRED_PUBLIC_FIELDS[kty];
574
- if (required) {
575
- for (const field of required) {
576
- if (!(field in obj) || obj[field] === void 0 || obj[field] === null || obj[field] === "") {
577
- return {
578
- valid: false,
579
- error: `Missing required public key field "${field}" for kty="${kty}"`
580
- };
581
- }
582
- }
583
- }
584
- return { valid: true };
585
- }
586
- function canonicalizeJwkJson(jwk) {
587
- const sorted = Object.keys(jwk).sort();
588
- const obj = {};
589
- for (const key of sorted) {
590
- obj[key] = jwk[key];
591
- }
592
- return JSON.stringify(obj);
593
- }
594
- function jwkToDidJwk(jwk) {
595
- assertObject(jwk, "jwk", "INVALID_JWK");
596
- const validation = validatePublicJwk(jwk);
597
- if (!validation.valid) {
598
- throw new OmaTrustError("INVALID_JWK", validation.error ?? "Invalid public JWK", { jwk });
599
- }
600
- const canonical = canonicalizeJwkJson(jwk);
601
- const encoded = jose.base64url.encode(new TextEncoder().encode(canonical));
602
- return `did:jwk:${encoded}`;
603
- }
604
- function didJwkToJwk(didJwk) {
605
- if (typeof didJwk !== "string" || !didJwk.startsWith("did:jwk:")) {
606
- throw new OmaTrustError("INVALID_DID", "Expected a did:jwk DID", { input: didJwk });
607
- }
608
- const parts = didJwk.split(":");
609
- if (parts.length !== 3) {
610
- throw new OmaTrustError("INVALID_DID", "did:jwk must have exactly 3 colon-separated parts", {
611
- input: didJwk
612
- });
613
- }
614
- const encoded = parts[2];
615
- if (!encoded || encoded.length === 0) {
616
- throw new OmaTrustError("INVALID_DID", "Missing base64url-encoded JWK identifier", {
617
- input: didJwk
618
- });
619
- }
620
- let decoded;
621
- try {
622
- const bytes = jose.base64url.decode(encoded);
623
- decoded = new TextDecoder().decode(bytes);
624
- } catch {
625
- throw new OmaTrustError("INVALID_DID", "Failed to base64url-decode did:jwk identifier", {
626
- input: didJwk
627
- });
628
- }
629
- let jwk;
630
- try {
631
- jwk = JSON.parse(decoded);
632
- } catch {
633
- throw new OmaTrustError("INVALID_DID", "Decoded did:jwk identifier is not valid JSON", {
634
- input: didJwk
635
- });
636
- }
637
- if (!jwk || typeof jwk !== "object" || Array.isArray(jwk)) {
638
- throw new OmaTrustError("INVALID_DID", "Decoded did:jwk must be a JSON object", {
639
- input: didJwk
640
- });
641
- }
642
- const validation = validatePublicJwk(jwk);
643
- if (!validation.valid) {
644
- throw new OmaTrustError("INVALID_DID", validation.error ?? "Invalid public JWK in did:jwk", {
645
- input: didJwk
646
- });
647
- }
648
- return jwk;
649
- }
650
- function extractPublicKeyFields(jwk) {
651
- const result = {};
652
- const metadataFields = /* @__PURE__ */ new Set(["kid", "use", "key_ops", "alg", "ext"]);
653
- for (const [key, value] of Object.entries(jwk)) {
654
- if (PRIVATE_KEY_FIELDS.has(key)) continue;
655
- if (metadataFields.has(key)) continue;
656
- result[key] = value;
657
- }
658
- return result;
659
- }
660
- function publicJwkEquals(a, b) {
661
- assertObject(a, "a", "INVALID_JWK");
662
- assertObject(b, "b", "INVALID_JWK");
663
- const aObj = a;
664
- const bObj = b;
665
- for (const field of PRIVATE_KEY_FIELDS) {
666
- if (field in aObj) {
667
- throw new OmaTrustError(
668
- "INVALID_JWK",
669
- `First JWK contains private key field "${field}"`,
670
- { field }
671
- );
672
- }
673
- if (field in bObj) {
674
- throw new OmaTrustError(
675
- "INVALID_JWK",
676
- `Second JWK contains private key field "${field}"`,
677
- { field }
678
- );
679
- }
680
- }
681
- const aPublic = extractPublicKeyFields(aObj);
682
- const bPublic = extractPublicKeyFields(bObj);
683
- return canonicalizeJwkJson(aPublic) === canonicalizeJwkJson(bPublic);
684
- }
685
- async function computeJwkThumbprint(jwk, digestAlgorithm = "sha256") {
686
- assertObject(jwk, "jwk", "INVALID_JWK");
687
- const validation = validatePublicJwk(jwk);
688
- if (!validation.valid) {
689
- throw new OmaTrustError("INVALID_JWK", validation.error ?? "Invalid public JWK", { jwk });
690
- }
691
- const alg = digestAlgorithm === "sha256" ? "sha256" : digestAlgorithm === "sha384" ? "sha384" : "sha512";
692
- return jose.calculateJwkThumbprint(jwk, alg);
693
- }
694
- async function formatJktValue(jwk) {
695
- const thumbprint = await computeJwkThumbprint(jwk, "sha256");
696
- return `jkt=S256:${thumbprint}`;
697
- }
698
744
 
699
745
  // src/shared/did-document.ts
700
746
  async function fetchDidDocument(domain) {
@@ -857,7 +903,7 @@ function extractControllerEvmAddress(controllerDid) {
857
903
  function extractAuthorizationMetadata(result) {
858
904
  const payload = result.payload;
859
905
  const resourceUrl = typeof payload.resourceUrl === "string" ? payload.resourceUrl : null;
860
- const issuedAt = typeof payload.issuedAt === "string" ? payload.issuedAt : null;
906
+ const issuedAt = typeof payload.issuedAt === "string" ? payload.issuedAt : typeof payload.issuedAt === "number" ? payload.issuedAt : null;
861
907
  let subjectDid = null;
862
908
  if (resourceUrl) {
863
909
  try {
@@ -866,33 +912,466 @@ function extractAuthorizationMetadata(result) {
866
912
  } catch {
867
913
  }
868
914
  }
869
- return {
870
- controllerDid: result.publicKeyDid,
871
- subjectDid,
872
- resourceUrl,
873
- issuedAt,
874
- kid: result.kid,
875
- publicKeyJwk: result.publicKeyJwk
876
- };
877
- }
878
- function canonicalizeJson(obj) {
879
- const jcs = canonicalize__default.default(obj);
880
- if (!jcs) {
881
- throw new OmaTrustError("INVALID_INPUT", "Object cannot be canonicalized", { obj });
915
+ if ("publicKeyDid" in result) {
916
+ const jwsResult = result;
917
+ return {
918
+ controllerDid: jwsResult.publicKeyDid,
919
+ subjectDid,
920
+ resourceUrl,
921
+ issuedAt,
922
+ kid: jwsResult.kid,
923
+ publicKeyJwk: jwsResult.publicKeyJwk,
924
+ signer: null
925
+ };
926
+ }
927
+ const eip712Result = result;
928
+ const signerAddress = eip712Result.signer.toLowerCase();
929
+ return {
930
+ controllerDid: `did:pkh:eip155:1:${signerAddress}`,
931
+ subjectDid,
932
+ resourceUrl,
933
+ issuedAt,
934
+ kid: null,
935
+ publicKeyJwk: null,
936
+ signer: eip712Result.signer
937
+ };
938
+ }
939
+ var VALID_ALGORITHMS = /* @__PURE__ */ new Set(["keccak256", "sha256"]);
940
+ var MAX_JSON_DEPTH = 32;
941
+ function assertDepthLimit(depth, context) {
942
+ if (depth > MAX_JSON_DEPTH) {
943
+ const msg = context ? `JSON nesting depth exceeds maximum of ${MAX_JSON_DEPTH} at ${context}` : `JSON nesting depth exceeds maximum of ${MAX_JSON_DEPTH}`;
944
+ throw new OmaTrustError("INVALID_INPUT", msg);
945
+ }
946
+ }
947
+ function parseJsonStrict(input) {
948
+ if (typeof input !== "string") {
949
+ throw new OmaTrustError("INVALID_INPUT", "Input must be a string");
950
+ }
951
+ const duplicateKeys = detectDuplicateKeys(input);
952
+ if (duplicateKeys.length > 0) {
953
+ throw new OmaTrustError(
954
+ "INVALID_INPUT",
955
+ `Duplicate JSON key${duplicateKeys.length > 1 ? "s" : ""} detected: ${duplicateKeys.map((k) => `"${k}"`).join(", ")}`,
956
+ { duplicateKeys }
957
+ );
958
+ }
959
+ try {
960
+ return JSON.parse(input);
961
+ } catch {
962
+ throw new OmaTrustError("INVALID_INPUT", "Input is not valid JSON");
963
+ }
964
+ }
965
+ function detectDuplicateKeys(input) {
966
+ const duplicates = [];
967
+ const objectKeyStack = [];
968
+ let inString = false;
969
+ let escaped = false;
970
+ let currentKey = "";
971
+ let collectingKey = false;
972
+ let afterColon = false;
973
+ let i = 0;
974
+ while (i < input.length) {
975
+ const ch = input[i];
976
+ if (escaped) {
977
+ if (collectingKey) currentKey += ch;
978
+ escaped = false;
979
+ i++;
980
+ continue;
981
+ }
982
+ if (ch === "\\") {
983
+ escaped = true;
984
+ if (collectingKey) currentKey += ch;
985
+ i++;
986
+ continue;
987
+ }
988
+ if (ch === '"') {
989
+ if (!inString) {
990
+ inString = true;
991
+ if (objectKeyStack.length > 0 && !afterColon) {
992
+ collectingKey = true;
993
+ currentKey = "";
994
+ }
995
+ } else {
996
+ inString = false;
997
+ if (collectingKey) {
998
+ collectingKey = false;
999
+ const keySet = objectKeyStack[objectKeyStack.length - 1];
1000
+ if (keySet.has(currentKey)) {
1001
+ if (!duplicates.includes(currentKey)) {
1002
+ duplicates.push(currentKey);
1003
+ }
1004
+ } else {
1005
+ keySet.add(currentKey);
1006
+ }
1007
+ }
1008
+ }
1009
+ i++;
1010
+ continue;
1011
+ }
1012
+ if (inString) {
1013
+ if (collectingKey) currentKey += ch;
1014
+ i++;
1015
+ continue;
1016
+ }
1017
+ if (ch === "{") {
1018
+ objectKeyStack.push(/* @__PURE__ */ new Set());
1019
+ assertDepthLimit(objectKeyStack.length);
1020
+ afterColon = false;
1021
+ } else if (ch === "}") {
1022
+ objectKeyStack.pop();
1023
+ afterColon = objectKeyStack.length > 0;
1024
+ } else if (ch === "[") {
1025
+ objectKeyStack.push(/* @__PURE__ */ new Set(["__array__"]));
1026
+ assertDepthLimit(objectKeyStack.length);
1027
+ afterColon = false;
1028
+ } else if (ch === "]") {
1029
+ objectKeyStack.pop();
1030
+ afterColon = objectKeyStack.length > 0;
1031
+ } else if (ch === ":") {
1032
+ afterColon = true;
1033
+ } else if (ch === ",") {
1034
+ afterColon = false;
1035
+ }
1036
+ i++;
1037
+ }
1038
+ return duplicates;
1039
+ }
1040
+ function assertJsonSafe(value, path = "$", depth = 0) {
1041
+ assertDepthLimit(depth, path);
1042
+ if (value === void 0) {
1043
+ throw new OmaTrustError("INVALID_INPUT", `Non-JSON-safe value at ${path}: undefined`);
1044
+ }
1045
+ if (value === null) return;
1046
+ switch (typeof value) {
1047
+ case "string":
1048
+ case "boolean":
1049
+ return;
1050
+ case "number":
1051
+ if (!Number.isFinite(value)) {
1052
+ throw new OmaTrustError("INVALID_INPUT", `Non-JSON-safe value at ${path}: ${value} (must be finite number)`);
1053
+ }
1054
+ return;
1055
+ case "bigint":
1056
+ throw new OmaTrustError("INVALID_INPUT", `Non-JSON-safe value at ${path}: BigInt (use number or string)`);
1057
+ case "function":
1058
+ throw new OmaTrustError("INVALID_INPUT", `Non-JSON-safe value at ${path}: function`);
1059
+ case "symbol":
1060
+ throw new OmaTrustError("INVALID_INPUT", `Non-JSON-safe value at ${path}: Symbol`);
1061
+ case "object":
1062
+ if (value instanceof Date) {
1063
+ throw new OmaTrustError("INVALID_INPUT", `Non-JSON-safe value at ${path}: Date (use ISO string or timestamp)`);
1064
+ }
1065
+ if (value instanceof RegExp) {
1066
+ throw new OmaTrustError("INVALID_INPUT", `Non-JSON-safe value at ${path}: RegExp`);
1067
+ }
1068
+ if (Array.isArray(value)) {
1069
+ for (let i = 0; i < value.length; i++) {
1070
+ assertJsonSafe(value[i], `${path}[${i}]`, depth + 1);
1071
+ }
1072
+ return;
1073
+ }
1074
+ for (const [key, val] of Object.entries(value)) {
1075
+ assertJsonSafe(val, `${path}.${key}`, depth + 1);
1076
+ }
1077
+ return;
1078
+ default:
1079
+ throw new OmaTrustError("INVALID_INPUT", `Non-JSON-safe value at ${path}: unknown type "${typeof value}"`);
1080
+ }
1081
+ }
1082
+ function canonicalizeJson(obj) {
1083
+ assertJsonSafe(obj);
1084
+ const jcs = canonicalize__default.default(obj);
1085
+ if (!jcs) {
1086
+ throw new OmaTrustError("INVALID_INPUT", "Object cannot be canonicalized", { obj });
1087
+ }
1088
+ return jcs;
1089
+ }
1090
+ function canonicalizeAndKeccak256(obj) {
1091
+ const jcsJson = canonicalizeJson(obj);
1092
+ return {
1093
+ jcsJson,
1094
+ hash: ethers.keccak256(ethers.toUtf8Bytes(jcsJson))
1095
+ };
1096
+ }
1097
+ function canonicalizeForHash(obj) {
1098
+ return canonicalizeAndKeccak256(obj);
1099
+ }
1100
+ function hashCanonicalizedJson(obj, algorithm) {
1101
+ if (!VALID_ALGORITHMS.has(algorithm)) {
1102
+ throw new OmaTrustError("INVALID_INPUT", `Unsupported hash algorithm: "${algorithm}". Must be "keccak256" or "sha256".`, { algorithm });
1103
+ }
1104
+ const jcs = canonicalizeJson(obj);
1105
+ const bytes = ethers.toUtf8Bytes(jcs);
1106
+ return algorithm === "keccak256" ? ethers.keccak256(bytes) : ethers.sha256(bytes);
1107
+ }
1108
+ var DID_ARTIFACT_PREFIX = "did:artifact:";
1109
+ var CID_VERSION = 1;
1110
+ var RAW_CODEC = raw__namespace.code;
1111
+ var SHA2_256_CODE = 18;
1112
+ var SHA2_256_DIGEST_LENGTH = 32;
1113
+ async function artifactDidFromBytes(bytes) {
1114
+ if (!(bytes instanceof Uint8Array) || bytes.length === 0) {
1115
+ throw new OmaTrustError(
1116
+ "INVALID_INPUT",
1117
+ "bytes must be a non-empty Uint8Array"
1118
+ );
1119
+ }
1120
+ const digest = await sha2.sha256.digest(bytes);
1121
+ const cid$1 = cid.CID.createV1(RAW_CODEC, digest);
1122
+ return `${DID_ARTIFACT_PREFIX}${cid$1.toString(base32.base32)}`;
1123
+ }
1124
+ async function artifactDidFromJson(input) {
1125
+ const value = typeof input === "string" ? parseJsonStrict(input) : input;
1126
+ const jcs = canonicalizeJson(value);
1127
+ const bytes = new TextEncoder().encode(jcs);
1128
+ const digest = await sha2.sha256.digest(bytes);
1129
+ const cid$1 = cid.CID.createV1(RAW_CODEC, digest);
1130
+ return `${DID_ARTIFACT_PREFIX}${cid$1.toString(base32.base32)}`;
1131
+ }
1132
+ function parseArtifactDid(did) {
1133
+ if (typeof did !== "string" || !did.startsWith(DID_ARTIFACT_PREFIX)) {
1134
+ throw new OmaTrustError("INVALID_DID", "Expected a did:artifact DID", { did });
1135
+ }
1136
+ const identifier = did.slice(DID_ARTIFACT_PREFIX.length);
1137
+ if (!identifier || identifier.length === 0) {
1138
+ throw new OmaTrustError("INVALID_DID", "Missing method-specific identifier", { did });
1139
+ }
1140
+ if (identifier[0] !== "b") {
1141
+ throw new OmaTrustError(
1142
+ "INVALID_DID",
1143
+ `Invalid multibase prefix "${identifier[0]}", expected "b" (base32lower)`,
1144
+ { did }
1145
+ );
1146
+ }
1147
+ let cid$1;
1148
+ try {
1149
+ cid$1 = cid.CID.parse(identifier, base32.base32);
1150
+ } catch (err) {
1151
+ throw new OmaTrustError(
1152
+ "INVALID_DID",
1153
+ "Failed to decode base32 CID from did:artifact identifier",
1154
+ { did, cause: err }
1155
+ );
1156
+ }
1157
+ if (cid$1.version !== CID_VERSION) {
1158
+ throw new OmaTrustError(
1159
+ "INVALID_DID",
1160
+ `CID version must be 1, got ${cid$1.version}`,
1161
+ { did }
1162
+ );
1163
+ }
1164
+ if (cid$1.code !== RAW_CODEC) {
1165
+ throw new OmaTrustError(
1166
+ "INVALID_DID",
1167
+ `Multicodec must be raw (0x55), got 0x${cid$1.code.toString(16)}`,
1168
+ { did }
1169
+ );
1170
+ }
1171
+ if (cid$1.multihash.code !== SHA2_256_CODE) {
1172
+ throw new OmaTrustError(
1173
+ "INVALID_DID",
1174
+ `Multihash function must be sha2-256 (0x12), got 0x${cid$1.multihash.code.toString(16)}`,
1175
+ { did }
1176
+ );
1177
+ }
1178
+ if (cid$1.multihash.digest.length !== SHA2_256_DIGEST_LENGTH) {
1179
+ throw new OmaTrustError(
1180
+ "INVALID_DID",
1181
+ `SHA-256 digest must be 32 bytes, got ${cid$1.multihash.digest.length}`,
1182
+ { did }
1183
+ );
1184
+ }
1185
+ const digest = cid$1.multihash.digest;
1186
+ const digestHex = Array.from(digest).map((b) => b.toString(16).padStart(2, "0")).join("");
1187
+ return { did, identifier, digest, digestHex };
1188
+ }
1189
+ async function verifyDidArtifact(did, content) {
1190
+ let parsed;
1191
+ try {
1192
+ parsed = parseArtifactDid(did);
1193
+ } catch (err) {
1194
+ return {
1195
+ valid: false,
1196
+ reason: err instanceof OmaTrustError ? err.message : "Invalid did:artifact DID"
1197
+ };
1198
+ }
1199
+ const expectedHex = parsed.digestHex;
1200
+ if (typeof content === "string" || typeof content === "object" && content !== null && !(content instanceof Uint8Array)) {
1201
+ try {
1202
+ const value = typeof content === "string" ? parseJsonStrict(content) : content;
1203
+ const jcs = canonicalizeJson(value);
1204
+ const jcsBytes = new TextEncoder().encode(jcs);
1205
+ const digest2 = await sha2.sha256.digest(jcsBytes);
1206
+ const digestHex2 = Array.from(digest2.digest).map((b) => b.toString(16).padStart(2, "0")).join("");
1207
+ if (digestHex2 === expectedHex) {
1208
+ return { valid: true, matchedAs: "json" };
1209
+ }
1210
+ } catch {
1211
+ }
1212
+ }
1213
+ let rawBytes;
1214
+ if (content instanceof Uint8Array) {
1215
+ rawBytes = content;
1216
+ } else if (typeof content === "string") {
1217
+ rawBytes = new TextEncoder().encode(content);
1218
+ } else {
1219
+ return {
1220
+ valid: false,
1221
+ reason: "Content did not match as canonical JSON and is not raw bytes"
1222
+ };
1223
+ }
1224
+ const digest = await sha2.sha256.digest(rawBytes);
1225
+ const digestHex = Array.from(digest.digest).map((b) => b.toString(16).padStart(2, "0")).join("");
1226
+ if (digestHex === expectedHex) {
1227
+ return { valid: true, matchedAs: "binary" };
1228
+ }
1229
+ return {
1230
+ valid: false,
1231
+ reason: "Content does not match the did:artifact identifier (neither as canonical JSON nor as raw bytes)"
1232
+ };
1233
+ }
1234
+ function didEthrToDidPkh(did) {
1235
+ if (typeof did !== "string" || !did.startsWith("did:ethr:")) {
1236
+ throw new OmaTrustError("INVALID_DID", "Expected a did:ethr DID", { did });
1237
+ }
1238
+ const remainder = did.slice("did:ethr:".length);
1239
+ if (!remainder) {
1240
+ throw new OmaTrustError("INVALID_DID", "Missing identifier in did:ethr DID", { did });
1241
+ }
1242
+ let chainId;
1243
+ let address;
1244
+ const parts = remainder.split(":");
1245
+ if (parts.length === 1) {
1246
+ chainId = "1";
1247
+ address = parts[0];
1248
+ } else if (parts.length === 2) {
1249
+ const rawChainId = parts[0];
1250
+ address = parts[1];
1251
+ if (rawChainId.startsWith("0x")) {
1252
+ chainId = String(parseInt(rawChainId, 16));
1253
+ } else if (/^\d+$/.test(rawChainId)) {
1254
+ chainId = rawChainId;
1255
+ } else {
1256
+ const networkMap = {
1257
+ mainnet: "1",
1258
+ goerli: "5",
1259
+ sepolia: "11155111",
1260
+ polygon: "137",
1261
+ arbitrum: "42161",
1262
+ optimism: "10",
1263
+ base: "8453"
1264
+ };
1265
+ const mapped = networkMap[rawChainId.toLowerCase()];
1266
+ if (!mapped) {
1267
+ throw new OmaTrustError(
1268
+ "INVALID_DID",
1269
+ `Unknown did:ethr network "${rawChainId}"`,
1270
+ { did, network: rawChainId }
1271
+ );
1272
+ }
1273
+ chainId = mapped;
1274
+ }
1275
+ } else {
1276
+ throw new OmaTrustError("INVALID_DID", "Invalid did:ethr format", { did });
1277
+ }
1278
+ if (!ethers.isAddress(address)) {
1279
+ throw new OmaTrustError("INVALID_DID", "Invalid Ethereum address in did:ethr DID", {
1280
+ did,
1281
+ address
1282
+ });
1283
+ }
1284
+ const checksummed = ethers.getAddress(address);
1285
+ return `did:pkh:eip155:${chainId}:${checksummed.toLowerCase()}`;
1286
+ }
1287
+ var MULTICODEC_KEY_TYPES = {
1288
+ // Ed25519 public key: 0xed (varint encoded as [0xed, 0x01])
1289
+ 237: { kty: "OKP", crv: "Ed25519" },
1290
+ // X25519 public key: 0xec (varint encoded as [0xec, 0x01])
1291
+ 236: { kty: "OKP", crv: "X25519" },
1292
+ // secp256k1 public key (compressed): 0xe7 (varint encoded as [0xe7, 0x01])
1293
+ 231: { kty: "EC", crv: "secp256k1", coordSize: 33 },
1294
+ // P-256 public key (compressed): 0x80 0x24 (varint 0x1200)
1295
+ 4608: { kty: "EC", crv: "P-256", coordSize: 33 },
1296
+ // P-384 public key (compressed): 0x81 0x24 (varint 0x1201)
1297
+ 4609: { kty: "EC", crv: "P-384", coordSize: 49 }
1298
+ };
1299
+ function readVarint(bytes, offset) {
1300
+ let value = 0;
1301
+ let shift = 0;
1302
+ let bytesRead = 0;
1303
+ while (offset + bytesRead < bytes.length) {
1304
+ const byte = bytes[offset + bytesRead];
1305
+ value |= (byte & 127) << shift;
1306
+ bytesRead++;
1307
+ if ((byte & 128) === 0) {
1308
+ return { value, bytesRead };
1309
+ }
1310
+ shift += 7;
1311
+ if (shift > 28) {
1312
+ throw new OmaTrustError("INVALID_DID", "Varint too long in did:key multicodec prefix");
1313
+ }
1314
+ }
1315
+ throw new OmaTrustError("INVALID_DID", "Truncated varint in did:key multicodec prefix");
1316
+ }
1317
+ function decompressEcKey(compressedKey, crv) {
1318
+ throw new OmaTrustError(
1319
+ "UNSUPPORTED_KEY_TYPE",
1320
+ `Cannot convert compressed EC key (${crv}) from did:key to did:jwk. Decompressing EC points requires elliptic curve arithmetic. For EVM keys, use didEthrToDidPkh() instead.`,
1321
+ { crv, keyLength: compressedKey.length }
1322
+ );
1323
+ }
1324
+ function didKeyToDidJwk(did) {
1325
+ if (typeof did !== "string" || !did.startsWith("did:key:")) {
1326
+ throw new OmaTrustError("INVALID_DID", "Expected a did:key DID", { did });
1327
+ }
1328
+ const identifier = did.slice("did:key:".length);
1329
+ if (!identifier || !identifier.startsWith("z")) {
1330
+ throw new OmaTrustError(
1331
+ "INVALID_DID",
1332
+ "did:key identifier must start with 'z' (base58btc multibase prefix)",
1333
+ { did }
1334
+ );
1335
+ }
1336
+ let decoded;
1337
+ try {
1338
+ decoded = base58.base58btc.decode(identifier);
1339
+ } catch (err) {
1340
+ throw new OmaTrustError(
1341
+ "INVALID_DID",
1342
+ "Failed to decode base58btc from did:key identifier",
1343
+ { did, cause: err }
1344
+ );
1345
+ }
1346
+ if (decoded.length < 3) {
1347
+ throw new OmaTrustError("INVALID_DID", "did:key decoded bytes too short", { did });
1348
+ }
1349
+ const { value: codecValue, bytesRead } = readVarint(decoded, 0);
1350
+ const keyType = MULTICODEC_KEY_TYPES[codecValue];
1351
+ if (!keyType) {
1352
+ throw new OmaTrustError(
1353
+ "UNSUPPORTED_KEY_TYPE",
1354
+ `Unsupported multicodec key type 0x${codecValue.toString(16)} in did:key`,
1355
+ { did, codec: `0x${codecValue.toString(16)}` }
1356
+ );
1357
+ }
1358
+ const keyBytes = decoded.slice(bytesRead);
1359
+ if (keyType.kty === "OKP") {
1360
+ if (keyBytes.length !== 32) {
1361
+ throw new OmaTrustError(
1362
+ "INVALID_DID",
1363
+ `Expected 32-byte ${keyType.crv} key, got ${keyBytes.length} bytes`,
1364
+ { did, crv: keyType.crv }
1365
+ );
1366
+ }
1367
+ const jwk = {
1368
+ kty: keyType.kty,
1369
+ crv: keyType.crv,
1370
+ x: jose.base64url.encode(keyBytes)
1371
+ };
1372
+ return jwkToDidJwk(jwk);
882
1373
  }
883
- return jcs;
884
- }
885
- function canonicalizeForHash(obj) {
886
- const jcsJson = canonicalizeJson(obj);
887
- return {
888
- jcsJson,
889
- hash: ethers.keccak256(ethers.toUtf8Bytes(jcsJson))
890
- };
891
- }
892
- function hashCanonicalizedJson(obj, algorithm) {
893
- const jcs = canonicalizeJson(obj);
894
- const bytes = ethers.toUtf8Bytes(jcs);
895
- return algorithm === "keccak256" ? ethers.keccak256(bytes) : ethers.sha256(bytes);
1374
+ return decompressEcKey(keyBytes, keyType.crv).x.toString();
896
1375
  }
897
1376
 
898
1377
  // src/reputation/index.ts
@@ -939,7 +1418,9 @@ __export(reputation_exports, {
939
1418
  getOmaTrustProofEip712Types: () => getOmaTrustProofEip712Types,
940
1419
  getSchemaDetails: () => getSchemaDetails,
941
1420
  getSupportedChainIds: () => getSupportedChainIds,
1421
+ getVerifiedArtifactAttestations: () => getVerifiedArtifactAttestations,
942
1422
  hashSeed: () => hashSeed,
1423
+ isArtifactClaimedBy: () => isArtifactClaimedBy,
943
1424
  isChainSupported: () => isChainSupported,
944
1425
  listAttestations: () => listAttestations,
945
1426
  normalizeSchema: () => normalizeSchema,
@@ -960,10 +1441,14 @@ __export(reputation_exports, {
960
1441
  verifyDidWebOwnership: () => verifyDidWebOwnership,
961
1442
  verifyDnsTxtControllerDid: () => verifyDnsTxtControllerDid2,
962
1443
  verifyEip712Signature: () => verifyEip712Signature,
1444
+ verifyKeyBindingProofs: () => verifyKeyBindingProofs,
1445
+ verifyLinkedIdentifierProofs: () => verifyLinkedIdentifierProofs,
963
1446
  verifyProof: () => verifyProof,
1447
+ verifyResponsibilityClaim: () => verifyResponsibilityClaim,
964
1448
  verifySchemaExists: () => verifySchemaExists,
965
1449
  verifySubjectOwnership: () => verifySubjectOwnership,
966
1450
  verifyTransferProof: () => verifyTransferProof,
1451
+ verifyX402Artifact: () => verifyX402Artifact,
967
1452
  verifyX402Eip712Artifact: () => verifyX402Eip712Artifact,
968
1453
  verifyX402Eip712Offer: () => verifyX402Eip712Offer,
969
1454
  verifyX402Eip712Receipt: () => verifyX402Eip712Receipt,
@@ -1976,10 +2461,10 @@ function validateReceiptPayload(payload) {
1976
2461
  }
1977
2462
  return { valid: true };
1978
2463
  }
1979
- function failure(code, message, partial) {
2464
+ function failure(code2, message, partial) {
1980
2465
  return {
1981
2466
  valid: false,
1982
- error: { code, message },
2467
+ error: { code: code2, message },
1983
2468
  ...partial
1984
2469
  };
1985
2470
  }
@@ -2177,10 +2662,10 @@ function validateReceiptPayload2(payload) {
2177
2662
  }
2178
2663
  return { valid: true };
2179
2664
  }
2180
- function failure2(code, message, partial) {
2665
+ function failure2(code2, message, partial) {
2181
2666
  return {
2182
2667
  valid: false,
2183
- error: { code, message },
2668
+ error: { code: code2, message },
2184
2669
  ...partial
2185
2670
  };
2186
2671
  }
@@ -2698,8 +3183,8 @@ async function readOwnerFromContract(provider, contractAddress, signature, metho
2698
3183
  }
2699
3184
  async function discoverContractOwner(provider, contractAddress) {
2700
3185
  try {
2701
- const code = await provider.getCode(contractAddress);
2702
- if (code === "0x" || code === "0x0") {
3186
+ const code2 = await provider.getCode(contractAddress);
3187
+ if (code2 === "0x" || code2 === "0x0") {
2703
3188
  return null;
2704
3189
  }
2705
3190
  } catch {
@@ -3207,6 +3692,42 @@ function createX402OfferProof(offer) {
3207
3692
  };
3208
3693
  }
3209
3694
 
3695
+ // src/reputation/proof/x402-verify.ts
3696
+ async function verifyX402Artifact(artifact, options) {
3697
+ if (!artifact || typeof artifact !== "object") {
3698
+ return {
3699
+ valid: false,
3700
+ error: { code: "INVALID_ARTIFACT", message: "Artifact must be a non-null object" }
3701
+ };
3702
+ }
3703
+ const format = artifact.format;
3704
+ switch (format) {
3705
+ case "jws": {
3706
+ const jwsArtifact = artifact;
3707
+ const jwsOptions = options.resolveOptions ? { resolveOptions: options.resolveOptions } : void 0;
3708
+ if (options.artifactType === "offer") {
3709
+ return verifyX402JwsOffer(jwsArtifact, jwsOptions);
3710
+ }
3711
+ return verifyX402JwsReceipt(jwsArtifact, jwsOptions);
3712
+ }
3713
+ case "eip712": {
3714
+ const eip712Artifact = artifact;
3715
+ if (options.artifactType === "offer") {
3716
+ return verifyX402Eip712Offer(eip712Artifact);
3717
+ }
3718
+ return verifyX402Eip712Receipt(eip712Artifact);
3719
+ }
3720
+ default:
3721
+ return {
3722
+ valid: false,
3723
+ error: {
3724
+ code: "UNSUPPORTED_FORMAT",
3725
+ message: `Unsupported x402 artifact format: "${format}"`
3726
+ }
3727
+ };
3728
+ }
3729
+ }
3730
+
3210
3731
  // src/reputation/proof/evidence-pointer.ts
3211
3732
  function createEvidencePointerProof(url) {
3212
3733
  if (!url || typeof url !== "string") {
@@ -3315,8 +3836,8 @@ async function verifyDidPkhOwnership(params) {
3315
3836
  subjectDid: params.subjectDid
3316
3837
  });
3317
3838
  }
3318
- const code = await params.provider.getCode(subjectAddress);
3319
- const isContract = code !== "0x" && code !== "0x0";
3839
+ const code2 = await params.provider.getCode(subjectAddress);
3840
+ const isContract = code2 !== "0x" && code2 !== "0x0";
3320
3841
  if (!isContract) {
3321
3842
  if (ethers.getAddress(subjectAddress) === ethers.getAddress(connectedWalletAddress)) {
3322
3843
  return {
@@ -3492,6 +4013,596 @@ async function verifySubjectOwnership(params) {
3492
4013
  subjectDid
3493
4014
  });
3494
4015
  }
4016
+ function extractEip712Signer(proof) {
4017
+ const { domain, message, signature } = proof.proofObject;
4018
+ const typedData = {
4019
+ domain,
4020
+ types: {
4021
+ OmaTrustProof: [
4022
+ { name: "signer", type: "address" },
4023
+ { name: "authorizedEntity", type: "string" },
4024
+ { name: "signingPurpose", type: "string" },
4025
+ { name: "creationTimestamp", type: "uint256" },
4026
+ { name: "expirationTimestamp", type: "uint256" },
4027
+ { name: "randomValue", type: "bytes32" },
4028
+ { name: "statement", type: "string" }
4029
+ ]
4030
+ },
4031
+ message
4032
+ };
4033
+ try {
4034
+ const result = verifyEip712Signature(typedData, signature);
4035
+ return result.valid && result.signer ? result.signer : null;
4036
+ } catch (err) {
4037
+ console.warn("[omatrust] EIP-712 signer extraction failed:", err);
4038
+ return null;
4039
+ }
4040
+ }
4041
+ function extractJwsHeaderJwk(proof) {
4042
+ const jws = proof.proofObject;
4043
+ if (typeof jws !== "string") return null;
4044
+ const parts = jws.split(".");
4045
+ if (parts.length !== 3) return null;
4046
+ try {
4047
+ const headerB64 = parts[0].replace(/-/g, "+").replace(/_/g, "/");
4048
+ const padded = headerB64.padEnd(
4049
+ headerB64.length + (4 - headerB64.length % 4) % 4,
4050
+ "="
4051
+ );
4052
+ let headerJson;
4053
+ if (typeof atob === "function") {
4054
+ headerJson = decodeURIComponent(
4055
+ Array.from(atob(padded)).map((char) => `%${char.charCodeAt(0).toString(16).padStart(2, "0")}`).join("")
4056
+ );
4057
+ } else {
4058
+ headerJson = Buffer.from(padded, "base64").toString("utf8");
4059
+ }
4060
+ const header = JSON.parse(headerJson);
4061
+ return header.jwk ?? null;
4062
+ } catch {
4063
+ return null;
4064
+ }
4065
+ }
4066
+ function extractJwsPayload(proof) {
4067
+ const jws = proof.proofObject;
4068
+ if (typeof jws !== "string") return null;
4069
+ const parts = jws.split(".");
4070
+ if (parts.length !== 3) return null;
4071
+ try {
4072
+ const payloadB64 = parts[1].replace(/-/g, "+").replace(/_/g, "/");
4073
+ const padded = payloadB64.padEnd(
4074
+ payloadB64.length + (4 - payloadB64.length % 4) % 4,
4075
+ "="
4076
+ );
4077
+ let payloadJson;
4078
+ if (typeof atob === "function") {
4079
+ payloadJson = decodeURIComponent(
4080
+ Array.from(atob(padded)).map((char) => `%${char.charCodeAt(0).toString(16).padStart(2, "0")}`).join("")
4081
+ );
4082
+ } else {
4083
+ payloadJson = Buffer.from(padded, "base64").toString("utf8");
4084
+ }
4085
+ return JSON.parse(payloadJson);
4086
+ } catch {
4087
+ return null;
4088
+ }
4089
+ }
4090
+ function signerMatchesDid(signerAddress, did) {
4091
+ try {
4092
+ const didAddress = extractAddressFromDid(did);
4093
+ return ethers.getAddress(signerAddress).toLowerCase() === ethers.getAddress(didAddress).toLowerCase();
4094
+ } catch {
4095
+ return false;
4096
+ }
4097
+ }
4098
+ function jwkMatchesDid(jwk, did) {
4099
+ const method = extractDidMethod(did);
4100
+ if (method === "jwk") {
4101
+ try {
4102
+ const didJwk = didJwkToJwk(did);
4103
+ return publicJwkEquals(jwk, didJwk);
4104
+ } catch {
4105
+ return false;
4106
+ }
4107
+ }
4108
+ return false;
4109
+ }
4110
+ function proofSignerMatchesDid(proof, did) {
4111
+ switch (proof.proofType) {
4112
+ case "pop-eip712": {
4113
+ const signer = extractEip712Signer(proof);
4114
+ if (!signer) return false;
4115
+ return signerMatchesDid(signer, did);
4116
+ }
4117
+ case "pop-jws": {
4118
+ const jwsProof = proof;
4119
+ const jwk = extractJwsHeaderJwk(jwsProof);
4120
+ if (jwk && jwkMatchesDid(jwk, did)) return true;
4121
+ const payload = extractJwsPayload(jwsProof);
4122
+ if (payload && typeof payload.iss === "string") {
4123
+ if (payload.iss === did) return true;
4124
+ }
4125
+ return false;
4126
+ }
4127
+ case "tx-encoded-value":
4128
+ case "tx-interaction":
4129
+ return false;
4130
+ case "evidence-pointer":
4131
+ return false;
4132
+ default:
4133
+ return false;
4134
+ }
4135
+ }
4136
+ function proofAuthorizedEntityMatchesDid(proof, did) {
4137
+ switch (proof.proofType) {
4138
+ case "pop-eip712": {
4139
+ const eip712 = proof;
4140
+ const authorizedEntity = eip712.proofObject.message.authorizedEntity;
4141
+ return typeof authorizedEntity === "string" && authorizedEntity === did;
4142
+ }
4143
+ case "pop-jws": {
4144
+ const payload = extractJwsPayload(proof);
4145
+ if (!payload) return false;
4146
+ return typeof payload.aud === "string" && payload.aud === did;
4147
+ }
4148
+ default:
4149
+ return false;
4150
+ }
4151
+ }
4152
+ function verifyLinkedIdentifierProofs(data) {
4153
+ if (!data.subject || !data.linkedId) {
4154
+ return {
4155
+ valid: false,
4156
+ checks: [],
4157
+ reasons: ["subject and linkedId are required"]
4158
+ };
4159
+ }
4160
+ if (!Array.isArray(data.proofs) || data.proofs.length === 0) {
4161
+ return {
4162
+ valid: false,
4163
+ checks: [],
4164
+ reasons: ["At least one proof is required"]
4165
+ };
4166
+ }
4167
+ const checks = [];
4168
+ let subjectProved = false;
4169
+ let linkedIdProved = false;
4170
+ for (let i = 0; i < data.proofs.length; i++) {
4171
+ const proof = data.proofs[i];
4172
+ if (proofSignerMatchesDid(proof, data.subject)) {
4173
+ checks.push({
4174
+ proofIndex: i,
4175
+ proofType: proof.proofType,
4176
+ checkType: "signer-is-subject",
4177
+ valid: true
4178
+ });
4179
+ subjectProved = true;
4180
+ if (!proofAuthorizedEntityMatchesDid(proof, data.linkedId)) {
4181
+ checks.push({
4182
+ proofIndex: i,
4183
+ proofType: proof.proofType,
4184
+ checkType: "signer-is-subject",
4185
+ valid: false,
4186
+ reason: "Proof from subject does not authorize linkedId (aud mismatch)"
4187
+ });
4188
+ }
4189
+ }
4190
+ if (proofSignerMatchesDid(proof, data.linkedId)) {
4191
+ checks.push({
4192
+ proofIndex: i,
4193
+ proofType: proof.proofType,
4194
+ checkType: "signer-is-linkedId",
4195
+ valid: true
4196
+ });
4197
+ linkedIdProved = true;
4198
+ if (!proofAuthorizedEntityMatchesDid(proof, data.subject)) {
4199
+ checks.push({
4200
+ proofIndex: i,
4201
+ proofType: proof.proofType,
4202
+ checkType: "signer-is-linkedId",
4203
+ valid: false,
4204
+ reason: "Proof from linkedId does not authorize subject (aud mismatch)"
4205
+ });
4206
+ }
4207
+ }
4208
+ if (proof.proofType === "evidence-pointer") {
4209
+ checks.push({
4210
+ proofIndex: i,
4211
+ proofType: proof.proofType,
4212
+ checkType: "signer-is-subject",
4213
+ valid: true,
4214
+ reason: "Evidence pointer accepted (requires URL fetch for full verification)"
4215
+ });
4216
+ subjectProved = true;
4217
+ }
4218
+ }
4219
+ const reasons = [];
4220
+ if (!subjectProved) {
4221
+ reasons.push("No proof demonstrates control by subject");
4222
+ }
4223
+ if (!linkedIdProved) {
4224
+ reasons.push("No proof demonstrates control by linkedId");
4225
+ }
4226
+ return {
4227
+ valid: reasons.length === 0,
4228
+ checks,
4229
+ reasons
4230
+ };
4231
+ }
4232
+ function verifyKeyBindingProofs(data) {
4233
+ if (!data.subject || !data.keyId) {
4234
+ return {
4235
+ valid: false,
4236
+ checks: [],
4237
+ reasons: ["subject and keyId are required"]
4238
+ };
4239
+ }
4240
+ if (!Array.isArray(data.proofs) || data.proofs.length === 0) {
4241
+ return {
4242
+ valid: false,
4243
+ checks: [],
4244
+ reasons: ["At least one proof is required"]
4245
+ };
4246
+ }
4247
+ const checks = [];
4248
+ let subjectAuthorizedKey = false;
4249
+ for (let i = 0; i < data.proofs.length; i++) {
4250
+ const proof = data.proofs[i];
4251
+ if (proofSignerMatchesDid(proof, data.subject)) {
4252
+ const authorizesKey = proofAuthorizedEntityMatchesDid(proof, data.keyId);
4253
+ checks.push({
4254
+ proofIndex: i,
4255
+ proofType: proof.proofType,
4256
+ checkType: "signer-is-subject-for-key",
4257
+ valid: authorizesKey,
4258
+ reason: authorizesKey ? void 0 : "Proof signed by subject but does not authorize the keyId"
4259
+ });
4260
+ if (authorizesKey) {
4261
+ subjectAuthorizedKey = true;
4262
+ }
4263
+ }
4264
+ if (proofSignerMatchesDid(proof, data.keyId)) {
4265
+ checks.push({
4266
+ proofIndex: i,
4267
+ proofType: proof.proofType,
4268
+ checkType: "signer-is-keyId",
4269
+ valid: true,
4270
+ reason: "Key proved possession (supplementary, not sufficient alone)"
4271
+ });
4272
+ }
4273
+ if (proof.proofType === "evidence-pointer") {
4274
+ checks.push({
4275
+ proofIndex: i,
4276
+ proofType: proof.proofType,
4277
+ checkType: "signer-is-subject-for-key",
4278
+ valid: true,
4279
+ reason: "Evidence pointer accepted (requires URL fetch for full verification)"
4280
+ });
4281
+ subjectAuthorizedKey = true;
4282
+ }
4283
+ }
4284
+ if (data.publicKeyJwk && extractDidMethod(data.keyId) === "jwk") {
4285
+ try {
4286
+ const keyIdJwk = didJwkToJwk(data.keyId);
4287
+ const jwkConsistent = publicJwkEquals(data.publicKeyJwk, keyIdJwk);
4288
+ if (!jwkConsistent) {
4289
+ return {
4290
+ valid: false,
4291
+ checks,
4292
+ reasons: ["publicKeyJwk does not match the key material in keyId (did:jwk)"]
4293
+ };
4294
+ }
4295
+ } catch {
4296
+ }
4297
+ }
4298
+ const reasons = [];
4299
+ if (!subjectAuthorizedKey) {
4300
+ reasons.push(
4301
+ "No proof demonstrates that subject authorized the key binding"
4302
+ );
4303
+ }
4304
+ return {
4305
+ valid: reasons.length === 0,
4306
+ checks,
4307
+ reasons
4308
+ };
4309
+ }
4310
+
4311
+ // src/reputation/artifact-verification.ts
4312
+ async function verifyResponsibilityClaim(params) {
4313
+ const {
4314
+ attestation,
4315
+ artifactDid,
4316
+ provider,
4317
+ easContractAddress,
4318
+ chain,
4319
+ chainId,
4320
+ responsibilityClaimSchemaString
4321
+ } = params;
4322
+ const reasons = [];
4323
+ const checks = {
4324
+ schemaValid: false,
4325
+ subjectMatches: false,
4326
+ notRevoked: false,
4327
+ currentlyEffective: false,
4328
+ controllerAuthorized: false,
4329
+ issuedDuringAuthorizationWindow: false
4330
+ };
4331
+ let decoded;
4332
+ try {
4333
+ if (attestation.raw) {
4334
+ decoded = decodeAttestationData(responsibilityClaimSchemaString, attestation.raw);
4335
+ } else if (attestation.data && typeof attestation.data === "object") {
4336
+ decoded = attestation.data;
4337
+ } else {
4338
+ reasons.push("No attestation data available to decode");
4339
+ return buildFailedResult(checks, reasons);
4340
+ }
4341
+ } catch (err) {
4342
+ reasons.push(
4343
+ `Failed to decode attestation data: ${err instanceof Error ? err.message : "unknown error"}`
4344
+ );
4345
+ return buildFailedResult(checks, reasons);
4346
+ }
4347
+ const responsibleParty = decoded.responsibleParty;
4348
+ const subject = decoded.subject;
4349
+ const responsibilityType = decoded.responsibilityType;
4350
+ const issuedAt = decoded.issuedAt;
4351
+ const effectiveAt = decoded.effectiveAt;
4352
+ const expiresAt = decoded.expiresAt;
4353
+ const subjectLabel = decoded.subjectLabel;
4354
+ if (!responsibleParty || !subject || !responsibilityType || !issuedAt) {
4355
+ if (!responsibleParty) reasons.push("Missing required field: responsibleParty");
4356
+ if (!subject) reasons.push("Missing required field: subject");
4357
+ if (!responsibilityType) reasons.push("Missing required field: responsibilityType");
4358
+ if (!issuedAt) reasons.push("Missing required field: issuedAt");
4359
+ return buildFailedResult(checks, reasons, {
4360
+ responsibleParty,
4361
+ subjectLabel,
4362
+ responsibilityType
4363
+ });
4364
+ }
4365
+ if (!Array.isArray(responsibilityType) || responsibilityType.length === 0) {
4366
+ reasons.push("responsibilityType must be a non-empty array");
4367
+ return buildFailedResult(checks, reasons, {
4368
+ responsibleParty,
4369
+ subjectLabel,
4370
+ responsibilityType
4371
+ });
4372
+ }
4373
+ checks.schemaValid = true;
4374
+ if (artifactDid) {
4375
+ checks.subjectMatches = subject.toLowerCase() === artifactDid.toLowerCase();
4376
+ if (!checks.subjectMatches) {
4377
+ reasons.push(`Subject "${subject}" does not match expected artifact "${artifactDid}"`);
4378
+ }
4379
+ } else {
4380
+ checks.subjectMatches = true;
4381
+ }
4382
+ checks.notRevoked = attestation.revocationTime === BigInt(0);
4383
+ if (!checks.notRevoked) {
4384
+ reasons.push("Attestation has been revoked");
4385
+ }
4386
+ const now = BigInt(Math.floor(Date.now() / 1e3));
4387
+ const effectiveTime = toBigInt(effectiveAt);
4388
+ const expirationTime = toBigInt(expiresAt);
4389
+ const isEffective = effectiveTime === BigInt(0) || effectiveTime <= now;
4390
+ const isNotExpired = expirationTime === BigInt(0) || expirationTime > now;
4391
+ checks.currentlyEffective = isEffective && isNotExpired;
4392
+ if (!isEffective) {
4393
+ reasons.push("Attestation is not yet effective");
4394
+ }
4395
+ if (!isNotExpired) {
4396
+ reasons.push("Attestation has expired");
4397
+ }
4398
+ const controllerDid = `did:pkh:eip155:${chainId}:${attestation.attester.toLowerCase()}`;
4399
+ let authorization = null;
4400
+ try {
4401
+ const resolvedChain = chain ?? `eip155:${chainId}`;
4402
+ authorization = await getControllerAuthorization({
4403
+ subjectDid: responsibleParty,
4404
+ controllerDid,
4405
+ provider,
4406
+ chain: resolvedChain,
4407
+ easContractAddress
4408
+ });
4409
+ checks.controllerAuthorized = authorization.authorized;
4410
+ if (!checks.controllerAuthorized) {
4411
+ reasons.push(`Controller ${controllerDid} is not authorized for ${responsibleParty}`);
4412
+ }
4413
+ if (authorization.authorized && authorization.anchoredFrom !== null) {
4414
+ const issuedAtBigInt = toBigInt(issuedAt);
4415
+ const afterStart = issuedAtBigInt >= authorization.anchoredFrom;
4416
+ const beforeEnd = authorization.until === null || issuedAtBigInt <= authorization.until;
4417
+ checks.issuedDuringAuthorizationWindow = afterStart && beforeEnd;
4418
+ if (!afterStart) {
4419
+ reasons.push("Attestation was issued before the authorization window started");
4420
+ }
4421
+ if (!beforeEnd) {
4422
+ reasons.push("Attestation was issued after the authorization window ended");
4423
+ }
4424
+ } else if (authorization.authorized && authorization.anchoredFrom === null) {
4425
+ checks.issuedDuringAuthorizationWindow = true;
4426
+ } else {
4427
+ checks.issuedDuringAuthorizationWindow = false;
4428
+ }
4429
+ } catch (err) {
4430
+ reasons.push(
4431
+ `Controller authorization check failed: ${err instanceof Error ? err.message : "unknown error"}`
4432
+ );
4433
+ checks.controllerAuthorized = false;
4434
+ checks.issuedDuringAuthorizationWindow = false;
4435
+ }
4436
+ const valid = Object.values(checks).every(Boolean);
4437
+ return {
4438
+ valid,
4439
+ responsibleParty,
4440
+ controllerDid,
4441
+ responsibilityTypes: responsibilityType,
4442
+ subjectLabel: subjectLabel || void 0,
4443
+ authorization,
4444
+ checks,
4445
+ reasons
4446
+ };
4447
+ }
4448
+ async function getVerifiedArtifactAttestations(params) {
4449
+ const {
4450
+ artifactDid,
4451
+ provider,
4452
+ easContractAddress,
4453
+ chain,
4454
+ chainId,
4455
+ schemaUids,
4456
+ responsibilityClaimSchemaUid,
4457
+ responsibilityClaimSchemaString,
4458
+ securityAssessmentSchemaUid,
4459
+ certificationSchemaUid,
4460
+ fromBlock,
4461
+ limit
4462
+ } = params;
4463
+ parseArtifactDid(artifactDid);
4464
+ if (schemaUids.length === 0) {
4465
+ return {
4466
+ artifactDid,
4467
+ responsibilityClaims: [],
4468
+ securityAssessments: [],
4469
+ certifications: [],
4470
+ otherAttestations: []
4471
+ };
4472
+ }
4473
+ const results = await listAttestations({
4474
+ subjectDid: artifactDid,
4475
+ provider,
4476
+ easContractAddress,
4477
+ schemas: schemaUids,
4478
+ limit: limit ?? 100,
4479
+ fromBlock
4480
+ });
4481
+ const responsibilityClaims = [];
4482
+ const securityAssessments = [];
4483
+ const certifications = [];
4484
+ const otherAttestations = [];
4485
+ for (const att of results) {
4486
+ const schemaUidLower = att.schema.toLowerCase();
4487
+ if (schemaUidLower === responsibilityClaimSchemaUid.toLowerCase()) {
4488
+ const verification = await verifyResponsibilityClaim({
4489
+ attestation: att,
4490
+ artifactDid,
4491
+ provider,
4492
+ easContractAddress,
4493
+ chain,
4494
+ chainId,
4495
+ responsibilityClaimSchemaString
4496
+ });
4497
+ responsibilityClaims.push({ attestation: att, verification });
4498
+ } else if (securityAssessmentSchemaUid && schemaUidLower === securityAssessmentSchemaUid.toLowerCase()) {
4499
+ const verification = await runStandardVerification(att, provider);
4500
+ securityAssessments.push({ attestation: att, verification });
4501
+ } else if (certificationSchemaUid && schemaUidLower === certificationSchemaUid.toLowerCase()) {
4502
+ const verification = await runStandardVerification(att, provider);
4503
+ certifications.push({ attestation: att, verification });
4504
+ } else {
4505
+ const verification = await runStandardVerification(att, provider);
4506
+ otherAttestations.push({ attestation: att, verification });
4507
+ }
4508
+ }
4509
+ return {
4510
+ artifactDid,
4511
+ responsibilityClaims,
4512
+ securityAssessments,
4513
+ certifications,
4514
+ otherAttestations
4515
+ };
4516
+ }
4517
+ async function isArtifactClaimedBy(params) {
4518
+ const { artifactDid, responsibleParty, responsibilityTypes } = params;
4519
+ const result = await getVerifiedArtifactAttestations({
4520
+ artifactDid,
4521
+ provider: params.provider,
4522
+ easContractAddress: params.easContractAddress,
4523
+ chain: params.chain,
4524
+ chainId: params.chainId,
4525
+ schemaUids: params.schemaUids,
4526
+ responsibilityClaimSchemaUid: params.responsibilityClaimSchemaUid,
4527
+ responsibilityClaimSchemaString: params.responsibilityClaimSchemaString,
4528
+ securityAssessmentSchemaUid: params.securityAssessmentSchemaUid,
4529
+ certificationSchemaUid: params.certificationSchemaUid
4530
+ });
4531
+ const matchingClaims = result.responsibilityClaims.filter(
4532
+ (claim) => claim.verification.responsibleParty.toLowerCase() === responsibleParty.toLowerCase()
4533
+ );
4534
+ const validClaims = matchingClaims.filter((claim) => claim.verification.valid);
4535
+ let finalClaims = validClaims;
4536
+ let matchedTypes = [];
4537
+ if (responsibilityTypes && responsibilityTypes.length > 0) {
4538
+ finalClaims = validClaims.filter(
4539
+ (claim) => claim.verification.responsibilityTypes.some(
4540
+ (t) => responsibilityTypes.includes(t)
4541
+ )
4542
+ );
4543
+ matchedTypes = [
4544
+ ...new Set(
4545
+ finalClaims.flatMap(
4546
+ (claim) => claim.verification.responsibilityTypes.filter(
4547
+ (t) => responsibilityTypes.includes(t)
4548
+ )
4549
+ )
4550
+ )
4551
+ ];
4552
+ } else {
4553
+ matchedTypes = [
4554
+ ...new Set(
4555
+ validClaims.flatMap((claim) => claim.verification.responsibilityTypes)
4556
+ )
4557
+ ];
4558
+ }
4559
+ const reasons = [];
4560
+ if (finalClaims.length === 0) {
4561
+ if (matchingClaims.length === 0) {
4562
+ reasons.push(
4563
+ `No responsibility claims found from ${responsibleParty} for this artifact`
4564
+ );
4565
+ } else if (validClaims.length === 0) {
4566
+ reasons.push(
4567
+ `Claims from ${responsibleParty} exist but none passed verification`
4568
+ );
4569
+ } else if (responsibilityTypes) {
4570
+ reasons.push(
4571
+ `No claims matched the requested responsibility types: ${responsibilityTypes.join(", ")}`
4572
+ );
4573
+ }
4574
+ }
4575
+ return {
4576
+ claimed: finalClaims.length > 0,
4577
+ claims: finalClaims,
4578
+ matchedResponsibilityTypes: matchedTypes,
4579
+ reasons
4580
+ };
4581
+ }
4582
+ function toBigInt(value) {
4583
+ if (value === void 0 || value === null) return BigInt(0);
4584
+ if (typeof value === "bigint") return value;
4585
+ return BigInt(value);
4586
+ }
4587
+ function buildFailedResult(checks, reasons, decoded) {
4588
+ return {
4589
+ valid: false,
4590
+ responsibleParty: decoded?.responsibleParty ?? "",
4591
+ controllerDid: "",
4592
+ responsibilityTypes: decoded?.responsibilityType ?? [],
4593
+ subjectLabel: decoded?.subjectLabel || void 0,
4594
+ authorization: null,
4595
+ checks,
4596
+ reasons
4597
+ };
4598
+ }
4599
+ async function runStandardVerification(attestation, provider) {
4600
+ try {
4601
+ return await verifyAttestation({ attestation, provider });
4602
+ } catch {
4603
+ return void 0;
4604
+ }
4605
+ }
3495
4606
 
3496
4607
  // src/app-registry/index.ts
3497
4608
  var app_registry_exports = {};
@@ -3579,8 +4690,8 @@ function getInterfaceTypes(bitmap) {
3579
4690
  }
3580
4691
 
3581
4692
  // src/app-registry/status.ts
3582
- function registryCodeToStatus(code) {
3583
- switch (code) {
4693
+ function registryCodeToStatus(code2) {
4694
+ switch (code2) {
3584
4695
  case 0:
3585
4696
  return "Active";
3586
4697
  case 1:
@@ -3588,7 +4699,7 @@ function registryCodeToStatus(code) {
3588
4699
  case 2:
3589
4700
  return "Replaced";
3590
4701
  default:
3591
- throw new OmaTrustError("INVALID_INPUT", "Invalid registry status code", { code });
4702
+ throw new OmaTrustError("INVALID_INPUT", "Invalid registry status code", { code: code2 });
3592
4703
  }
3593
4704
  }
3594
4705
  function registryStatusToCode(status) {
@@ -3690,6 +4801,9 @@ async function computeDataHashFromUrl(url, algorithm) {
3690
4801
  if (!url || typeof url !== "string") {
3691
4802
  throw new OmaTrustError("INVALID_INPUT", "url must be a non-empty string", { url });
3692
4803
  }
4804
+ if (algorithm !== "keccak256" && algorithm !== "sha256") {
4805
+ throw new OmaTrustError("INVALID_INPUT", `Unsupported hash algorithm: "${algorithm}". Must be "keccak256" or "sha256".`, { algorithm });
4806
+ }
3693
4807
  const json = await fetchJson(url);
3694
4808
  const jcsJson = canonicalizeJson(json);
3695
4809
  return hashJcs(jcsJson, algorithm);