@oma3/omatrust 0.1.0-alpha.2 → 0.1.0-alpha.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.cts CHANGED
@@ -1,6 +1,7 @@
1
1
  export { i as identity } from './index-QZDExA4I.cjs';
2
- export { i as reputation } from './index-ChbJxwOA.cjs';
2
+ export { i as reputation } from './index-DP6IIpIh.cjs';
3
3
  export { i as appRegistry } from './index-_Bkhoj8k.cjs';
4
+ import './eip712-C4a-JGko.cjs';
4
5
 
5
6
  declare class OmaTrustError extends Error {
6
7
  code: string;
package/dist/index.d.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  export { i as identity } from './index-QZDExA4I.js';
2
- export { i as reputation } from './index-ChbJxwOA.js';
2
+ export { i as reputation } from './index-BDeQNCi_.js';
3
3
  export { i as appRegistry } from './index-_Bkhoj8k.js';
4
+ import './eip712-C4a-JGko.js';
4
5
 
5
6
  declare class OmaTrustError extends Error {
6
7
  code: string;
package/dist/index.js CHANGED
@@ -355,6 +355,7 @@ function hashCanonicalizedJson(obj, algorithm) {
355
355
  var reputation_exports = {};
356
356
  __export(reputation_exports, {
357
357
  buildDelegatedAttestationTypedData: () => buildDelegatedAttestationTypedData,
358
+ buildDelegatedTypedDataFromEncoded: () => buildDelegatedTypedDataFromEncoded,
358
359
  buildDnsTxtRecord: () => buildDnsTxtRecord,
359
360
  buildEip712Domain: () => buildEip712Domain,
360
361
  calculateAverageUserReviewRating: () => calculateAverageUserReviewRating,
@@ -526,6 +527,53 @@ function resolveRecipientAddress(data) {
526
527
  return ZeroAddress;
527
528
  }
528
529
 
530
+ // src/reputation/eas-adapter.ts
531
+ function isRecord(value) {
532
+ return Boolean(value) && typeof value === "object";
533
+ }
534
+ function isHex32(value) {
535
+ return typeof value === "string" && /^0x[0-9a-fA-F]{64}$/.test(value);
536
+ }
537
+ function getEasTransactionReceipt(tx) {
538
+ if (!isRecord(tx)) {
539
+ return void 0;
540
+ }
541
+ const candidates = [tx.receipt, tx.tx, tx.transaction];
542
+ for (const candidate of candidates) {
543
+ if (isRecord(candidate)) {
544
+ return candidate;
545
+ }
546
+ }
547
+ return void 0;
548
+ }
549
+ function getEasTransactionHash(tx) {
550
+ const receipt = getEasTransactionReceipt(tx);
551
+ if (receipt) {
552
+ const receiptHash = receipt.hash;
553
+ if (isHex32(receiptHash)) {
554
+ return receiptHash;
555
+ }
556
+ const transactionHash = receipt.transactionHash;
557
+ if (isHex32(transactionHash)) {
558
+ return transactionHash;
559
+ }
560
+ }
561
+ if (isRecord(tx) && isHex32(tx.hash)) {
562
+ return tx.hash;
563
+ }
564
+ return void 0;
565
+ }
566
+ function isEasSchemaNotFoundError(err) {
567
+ if (!isRecord(err)) {
568
+ return false;
569
+ }
570
+ const message = err.message;
571
+ if (typeof message !== "string" || message.length === 0) {
572
+ return false;
573
+ }
574
+ return /schema not found/i.test(message);
575
+ }
576
+
529
577
  // src/reputation/submit.ts
530
578
  async function submitAttestation(params) {
531
579
  if (!params || typeof params !== "object") {
@@ -556,25 +604,18 @@ async function submitAttestation(params) {
556
604
  }
557
605
  });
558
606
  const uid = await tx.wait();
559
- const txAny = tx;
560
- const txHash = txAny.tx?.hash ?? txAny.hash ?? txAny.transaction?.hash ?? ZERO_UID;
607
+ const txHash = getEasTransactionHash(tx) ?? ZERO_UID;
608
+ const receipt = getEasTransactionReceipt(tx);
561
609
  return {
562
610
  uid,
563
611
  txHash,
564
- receipt: txAny.tx
612
+ receipt
565
613
  };
566
614
  } catch (err) {
567
615
  throw new OmaTrustError("NETWORK_ERROR", "Failed to submit attestation", { err });
568
616
  }
569
617
  }
570
- function buildDelegatedAttestationTypedData(params) {
571
- const dataWithHash = withAutoSubjectDidHash(params.schema, params.data);
572
- const encodedData = encodeAttestationData(params.schema, dataWithHash);
573
- const recipient = resolveRecipientAddress(dataWithHash);
574
- const expiration = toBigIntOrDefault(
575
- params.expirationTime ?? extractExpirationTime(dataWithHash),
576
- 0n
577
- );
618
+ function buildDelegatedTypedData(params) {
578
619
  return {
579
620
  domain: {
580
621
  name: "EAS",
@@ -599,17 +640,52 @@ function buildDelegatedAttestationTypedData(params) {
599
640
  message: {
600
641
  attester: params.attester,
601
642
  schema: params.schemaUid,
602
- recipient,
603
- expirationTime: expiration,
643
+ recipient: params.recipient,
644
+ expirationTime: toBigIntOrDefault(params.expirationTime, 0n),
604
645
  revocable: params.revocable ?? true,
605
646
  refUID: params.refUid ?? ZERO_UID,
606
- data: encodedData,
647
+ data: params.encodedData,
607
648
  value: toBigIntOrDefault(params.value, 0n),
608
649
  nonce: toBigIntOrDefault(params.nonce, 0n),
609
650
  deadline: toBigIntOrDefault(params.deadline, BigInt(Math.floor(Date.now() / 1e3) + 600))
610
651
  }
611
652
  };
612
653
  }
654
+ function buildDelegatedAttestationTypedData(params) {
655
+ const dataWithHash = withAutoSubjectDidHash(params.schema, params.data);
656
+ const encodedData = encodeAttestationData(params.schema, dataWithHash);
657
+ const recipient = resolveRecipientAddress(dataWithHash);
658
+ return buildDelegatedTypedData({
659
+ chainId: params.chainId,
660
+ easContractAddress: params.easContractAddress,
661
+ schemaUid: params.schemaUid,
662
+ encodedData,
663
+ recipient,
664
+ attester: params.attester,
665
+ nonce: params.nonce,
666
+ revocable: params.revocable,
667
+ expirationTime: params.expirationTime ?? extractExpirationTime(dataWithHash),
668
+ refUid: params.refUid,
669
+ value: params.value,
670
+ deadline: params.deadline
671
+ });
672
+ }
673
+ function buildDelegatedTypedDataFromEncoded(params) {
674
+ return buildDelegatedTypedData({
675
+ chainId: params.chainId,
676
+ easContractAddress: params.easContractAddress,
677
+ schemaUid: params.schemaUid,
678
+ encodedData: params.encodedData,
679
+ recipient: params.recipient,
680
+ attester: params.attester,
681
+ nonce: params.nonce,
682
+ revocable: params.revocable,
683
+ expirationTime: params.expirationTime,
684
+ refUid: params.refUid,
685
+ value: params.value,
686
+ deadline: params.deadline
687
+ });
688
+ }
613
689
  function splitSignature(signature) {
614
690
  try {
615
691
  const parsed = Signature.from(signature);
@@ -1100,6 +1176,8 @@ function verifyEip712Signature(typedData, signature) {
1100
1176
  throw new OmaTrustError("INVALID_INPUT", "Failed to verify EIP-712 signature", { err });
1101
1177
  }
1102
1178
  }
1179
+
1180
+ // src/reputation/proof/dns-txt-record.ts
1103
1181
  function parseDnsTxtRecord(record) {
1104
1182
  if (!record || typeof record !== "string") {
1105
1183
  throw new OmaTrustError("INVALID_INPUT", "record must be a non-empty string", { record });
@@ -1127,27 +1205,6 @@ function buildDnsTxtRecord(controllerDid) {
1127
1205
  const normalized = normalizeDid(controllerDid);
1128
1206
  return `v=1;controller=${normalized}`;
1129
1207
  }
1130
- async function verifyDnsTxtControllerDid(domain, expectedControllerDid) {
1131
- if (!domain || typeof domain !== "string") {
1132
- throw new OmaTrustError("INVALID_INPUT", "domain must be a non-empty string", { domain });
1133
- }
1134
- const expected = normalizeDid(expectedControllerDid);
1135
- const host = `_omatrust.${domain.toLowerCase().replace(/\.$/, "")}`;
1136
- let records;
1137
- try {
1138
- records = await resolveTxt(host);
1139
- } catch (err) {
1140
- throw new OmaTrustError("NETWORK_ERROR", "Failed to resolve DNS TXT records", { domain, err });
1141
- }
1142
- for (const recordParts of records) {
1143
- const record = recordParts.join("");
1144
- const parsed = parseDnsTxtRecord(record);
1145
- if (parsed.version === "1" && parsed.controller && normalizeDid(parsed.controller) === expected) {
1146
- return { valid: true, record };
1147
- }
1148
- }
1149
- return { valid: false, reason: "No TXT record matched expected controller DID" };
1150
- }
1151
1208
 
1152
1209
  // src/reputation/verify.ts
1153
1210
  function parseChainId(input) {
@@ -1428,6 +1485,9 @@ async function getSchemaDetails(schemaRegistry, schemaUid) {
1428
1485
  revocable: Boolean(details.revocable)
1429
1486
  };
1430
1487
  } catch (err) {
1488
+ if (isEasSchemaNotFoundError(err)) {
1489
+ throw new OmaTrustError("SCHEMA_NOT_FOUND", "Schema was not found", { schemaUid });
1490
+ }
1431
1491
  if (err instanceof OmaTrustError) {
1432
1492
  throw err;
1433
1493
  }
@@ -1611,6 +1671,27 @@ function createEvidencePointerProof(url) {
1611
1671
  issuedAt: Math.floor(Date.now() / 1e3)
1612
1672
  };
1613
1673
  }
1674
+ async function verifyDnsTxtControllerDid(domain, expectedControllerDid) {
1675
+ if (!domain || typeof domain !== "string") {
1676
+ throw new OmaTrustError("INVALID_INPUT", "domain must be a non-empty string", { domain });
1677
+ }
1678
+ const expected = normalizeDid(expectedControllerDid);
1679
+ const host = `_omatrust.${domain.toLowerCase().replace(/\.$/, "")}`;
1680
+ let records;
1681
+ try {
1682
+ records = await resolveTxt(host);
1683
+ } catch (err) {
1684
+ throw new OmaTrustError("NETWORK_ERROR", "Failed to resolve DNS TXT records", { domain, err });
1685
+ }
1686
+ for (const recordParts of records) {
1687
+ const record = recordParts.join("");
1688
+ const parsed = parseDnsTxtRecord(record);
1689
+ if (parsed.version === "1" && parsed.controller && normalizeDid(parsed.controller) === expected) {
1690
+ return { valid: true, record };
1691
+ }
1692
+ }
1693
+ return { valid: false, reason: "No TXT record matched expected controller DID" };
1694
+ }
1614
1695
 
1615
1696
  // src/app-registry/index.ts
1616
1697
  var app_registry_exports = {};