@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.
@@ -1 +1,2 @@
1
- export { A as AttestationQueryResult, C as CallControllerWitnessParams, a as CallControllerWitnessResult, b as ChainConstants, c as CreatePopEip712ProofParams, d as CreatePopJwsProofParams, D as Did, E as EvidencePointerProof, G as GetAttestationParams, e as GetLatestAttestationsParams, H as Hex, L as ListAttestationsParams, P as PopEip712Proof, f as PopJwsProof, g as PrepareDelegatedAttestationParams, h as PrepareDelegatedAttestationResult, j as ProofPurpose, k as ProofType, l as ProofWrapper, S as SchemaField, m as SubmitAttestationParams, n as SubmitAttestationResult, o as SubmitDelegatedAttestationParams, p as SubmitDelegatedAttestationResult, T as TxEncodedValueProof, q as TxInteractionProof, V as VerifyAttestationParams, r as VerifyAttestationResult, s as VerifyProofParams, t as VerifyProofResult, X as X402OfferProof, u as X402ReceiptProof, v as buildDelegatedAttestationTypedData, w as buildDnsTxtRecord, x as buildEip712Domain, y as calculateAverageUserReviewRating, z as calculateTransferAmount, B as calculateTransferAmountFromAddresses, F as callControllerWitness, I as constructSeed, J as createEvidencePointerProof, K as createPopEip712Proof, M as createPopJwsProof, N as createTxEncodedValueProof, O as createTxInteractionProof, Q as createX402OfferProof, R as createX402ReceiptProof, U as decodeAttestationData, W as deduplicateReviews, Y as encodeAttestationData, Z as extractAddressesFromDidDocument, _ as extractExpirationTime, $ as fetchDidDocument, a0 as formatSchemaUid, a1 as formatTransferAmount, a2 as getAttestation, a3 as getAttestationsForDid, a4 as getChainConstants, a5 as getExplorerAddressUrl, a6 as getExplorerTxUrl, a7 as getLatestAttestations, a8 as getMajorVersion, a9 as getOmaTrustProofEip712Types, aa as getSchemaDetails, ab as getSupportedChainIds, ac as hashSeed, ad as isChainSupported, ae as listAttestations, af as normalizeSchema, ag as parseDnsTxtRecord, ah as prepareDelegatedAttestation, ai as schemaToString, aj as splitSignature, ak as submitAttestation, al as submitDelegatedAttestation, am as verifyAttestation, an as verifyDidDocumentControllerDid, ao as verifyDnsTxtControllerDid, ap as verifyEip712Signature, aq as verifyProof, ar as verifySchemaExists } from '../index-ChbJxwOA.js';
1
+ export { A as AttestationQueryResult, B as BuildDelegatedTypedDataFromEncodedParams, C as CallControllerWitnessParams, a as CallControllerWitnessResult, b as ChainConstants, c as CreatePopEip712ProofParams, d as CreatePopJwsProofParams, D as Did, E as EvidencePointerProof, G as GetAttestationParams, e as GetLatestAttestationsParams, H as Hex, L as ListAttestationsParams, P as PopEip712Proof, f as PopJwsProof, g as PrepareDelegatedAttestationParams, h as PrepareDelegatedAttestationResult, i as ProofPurpose, j as ProofType, k as ProofWrapper, S as SchemaField, l as SubmitAttestationParams, m as SubmitAttestationResult, n as SubmitDelegatedAttestationParams, o as SubmitDelegatedAttestationResult, T as TxEncodedValueProof, p as TxInteractionProof, V as VerifyAttestationParams, q as VerifyAttestationResult, r as VerifyProofParams, s as VerifyProofResult, X as X402OfferProof, t as X402ReceiptProof, u as buildDelegatedAttestationTypedData, v as buildDelegatedTypedDataFromEncoded, w as buildDnsTxtRecord, x as buildEip712Domain, y as calculateAverageUserReviewRating, z as calculateTransferAmount, F as calculateTransferAmountFromAddresses, I as callControllerWitness, J as constructSeed, K as createEvidencePointerProof, M as createPopEip712Proof, N as createPopJwsProof, O as createTxEncodedValueProof, Q as createTxInteractionProof, R as createX402OfferProof, U as createX402ReceiptProof, W as decodeAttestationData, Y as deduplicateReviews, Z as encodeAttestationData, _ as extractAddressesFromDidDocument, $ as extractExpirationTime, a0 as fetchDidDocument, a1 as formatSchemaUid, a2 as formatTransferAmount, a3 as getAttestation, a4 as getAttestationsForDid, a5 as getChainConstants, a6 as getExplorerAddressUrl, a7 as getExplorerTxUrl, a8 as getLatestAttestations, a9 as getMajorVersion, aa as getOmaTrustProofEip712Types, ab as getSchemaDetails, ac as getSupportedChainIds, ad as hashSeed, ae as isChainSupported, af as listAttestations, ag as normalizeSchema, ah as parseDnsTxtRecord, ai as prepareDelegatedAttestation, aj as schemaToString, ak as splitSignature, al as submitAttestation, am as submitDelegatedAttestation, an as verifyAttestation, ao as verifyDidDocumentControllerDid, ap as verifyEip712Signature, aq as verifyProof, ar as verifySchemaExists } from '../eip712-C4a-JGko.js';
2
+ export { v as verifyDnsTxtControllerDid } from '../index-BDeQNCi_.js';
@@ -324,6 +324,53 @@ function resolveRecipientAddress(data) {
324
324
  return ZeroAddress;
325
325
  }
326
326
 
327
+ // src/reputation/eas-adapter.ts
328
+ function isRecord(value) {
329
+ return Boolean(value) && typeof value === "object";
330
+ }
331
+ function isHex32(value) {
332
+ return typeof value === "string" && /^0x[0-9a-fA-F]{64}$/.test(value);
333
+ }
334
+ function getEasTransactionReceipt(tx) {
335
+ if (!isRecord(tx)) {
336
+ return void 0;
337
+ }
338
+ const candidates = [tx.receipt, tx.tx, tx.transaction];
339
+ for (const candidate of candidates) {
340
+ if (isRecord(candidate)) {
341
+ return candidate;
342
+ }
343
+ }
344
+ return void 0;
345
+ }
346
+ function getEasTransactionHash(tx) {
347
+ const receipt = getEasTransactionReceipt(tx);
348
+ if (receipt) {
349
+ const receiptHash = receipt.hash;
350
+ if (isHex32(receiptHash)) {
351
+ return receiptHash;
352
+ }
353
+ const transactionHash = receipt.transactionHash;
354
+ if (isHex32(transactionHash)) {
355
+ return transactionHash;
356
+ }
357
+ }
358
+ if (isRecord(tx) && isHex32(tx.hash)) {
359
+ return tx.hash;
360
+ }
361
+ return void 0;
362
+ }
363
+ function isEasSchemaNotFoundError(err) {
364
+ if (!isRecord(err)) {
365
+ return false;
366
+ }
367
+ const message = err.message;
368
+ if (typeof message !== "string" || message.length === 0) {
369
+ return false;
370
+ }
371
+ return /schema not found/i.test(message);
372
+ }
373
+
327
374
  // src/reputation/submit.ts
328
375
  async function submitAttestation(params) {
329
376
  if (!params || typeof params !== "object") {
@@ -354,25 +401,18 @@ async function submitAttestation(params) {
354
401
  }
355
402
  });
356
403
  const uid = await tx.wait();
357
- const txAny = tx;
358
- const txHash = txAny.tx?.hash ?? txAny.hash ?? txAny.transaction?.hash ?? ZERO_UID;
404
+ const txHash = getEasTransactionHash(tx) ?? ZERO_UID;
405
+ const receipt = getEasTransactionReceipt(tx);
359
406
  return {
360
407
  uid,
361
408
  txHash,
362
- receipt: txAny.tx
409
+ receipt
363
410
  };
364
411
  } catch (err) {
365
412
  throw new OmaTrustError("NETWORK_ERROR", "Failed to submit attestation", { err });
366
413
  }
367
414
  }
368
- function buildDelegatedAttestationTypedData(params) {
369
- const dataWithHash = withAutoSubjectDidHash(params.schema, params.data);
370
- const encodedData = encodeAttestationData(params.schema, dataWithHash);
371
- const recipient = resolveRecipientAddress(dataWithHash);
372
- const expiration = toBigIntOrDefault(
373
- params.expirationTime ?? extractExpirationTime(dataWithHash),
374
- 0n
375
- );
415
+ function buildDelegatedTypedData(params) {
376
416
  return {
377
417
  domain: {
378
418
  name: "EAS",
@@ -397,17 +437,52 @@ function buildDelegatedAttestationTypedData(params) {
397
437
  message: {
398
438
  attester: params.attester,
399
439
  schema: params.schemaUid,
400
- recipient,
401
- expirationTime: expiration,
440
+ recipient: params.recipient,
441
+ expirationTime: toBigIntOrDefault(params.expirationTime, 0n),
402
442
  revocable: params.revocable ?? true,
403
443
  refUID: params.refUid ?? ZERO_UID,
404
- data: encodedData,
444
+ data: params.encodedData,
405
445
  value: toBigIntOrDefault(params.value, 0n),
406
446
  nonce: toBigIntOrDefault(params.nonce, 0n),
407
447
  deadline: toBigIntOrDefault(params.deadline, BigInt(Math.floor(Date.now() / 1e3) + 600))
408
448
  }
409
449
  };
410
450
  }
451
+ function buildDelegatedAttestationTypedData(params) {
452
+ const dataWithHash = withAutoSubjectDidHash(params.schema, params.data);
453
+ const encodedData = encodeAttestationData(params.schema, dataWithHash);
454
+ const recipient = resolveRecipientAddress(dataWithHash);
455
+ return buildDelegatedTypedData({
456
+ chainId: params.chainId,
457
+ easContractAddress: params.easContractAddress,
458
+ schemaUid: params.schemaUid,
459
+ encodedData,
460
+ recipient,
461
+ attester: params.attester,
462
+ nonce: params.nonce,
463
+ revocable: params.revocable,
464
+ expirationTime: params.expirationTime ?? extractExpirationTime(dataWithHash),
465
+ refUid: params.refUid,
466
+ value: params.value,
467
+ deadline: params.deadline
468
+ });
469
+ }
470
+ function buildDelegatedTypedDataFromEncoded(params) {
471
+ return buildDelegatedTypedData({
472
+ chainId: params.chainId,
473
+ easContractAddress: params.easContractAddress,
474
+ schemaUid: params.schemaUid,
475
+ encodedData: params.encodedData,
476
+ recipient: params.recipient,
477
+ attester: params.attester,
478
+ nonce: params.nonce,
479
+ revocable: params.revocable,
480
+ expirationTime: params.expirationTime,
481
+ refUid: params.refUid,
482
+ value: params.value,
483
+ deadline: params.deadline
484
+ });
485
+ }
411
486
  function splitSignature(signature) {
412
487
  try {
413
488
  const parsed = Signature.from(signature);
@@ -898,6 +973,8 @@ function verifyEip712Signature(typedData, signature) {
898
973
  throw new OmaTrustError("INVALID_INPUT", "Failed to verify EIP-712 signature", { err });
899
974
  }
900
975
  }
976
+
977
+ // src/reputation/proof/dns-txt-record.ts
901
978
  function parseDnsTxtRecord(record) {
902
979
  if (!record || typeof record !== "string") {
903
980
  throw new OmaTrustError("INVALID_INPUT", "record must be a non-empty string", { record });
@@ -925,27 +1002,6 @@ function buildDnsTxtRecord(controllerDid) {
925
1002
  const normalized = normalizeDid(controllerDid);
926
1003
  return `v=1;controller=${normalized}`;
927
1004
  }
928
- async function verifyDnsTxtControllerDid(domain, expectedControllerDid) {
929
- if (!domain || typeof domain !== "string") {
930
- throw new OmaTrustError("INVALID_INPUT", "domain must be a non-empty string", { domain });
931
- }
932
- const expected = normalizeDid(expectedControllerDid);
933
- const host = `_omatrust.${domain.toLowerCase().replace(/\.$/, "")}`;
934
- let records;
935
- try {
936
- records = await resolveTxt(host);
937
- } catch (err) {
938
- throw new OmaTrustError("NETWORK_ERROR", "Failed to resolve DNS TXT records", { domain, err });
939
- }
940
- for (const recordParts of records) {
941
- const record = recordParts.join("");
942
- const parsed = parseDnsTxtRecord(record);
943
- if (parsed.version === "1" && parsed.controller && normalizeDid(parsed.controller) === expected) {
944
- return { valid: true, record };
945
- }
946
- }
947
- return { valid: false, reason: "No TXT record matched expected controller DID" };
948
- }
949
1005
 
950
1006
  // src/reputation/verify.ts
951
1007
  function parseChainId(input) {
@@ -1226,6 +1282,9 @@ async function getSchemaDetails(schemaRegistry, schemaUid) {
1226
1282
  revocable: Boolean(details.revocable)
1227
1283
  };
1228
1284
  } catch (err) {
1285
+ if (isEasSchemaNotFoundError(err)) {
1286
+ throw new OmaTrustError("SCHEMA_NOT_FOUND", "Schema was not found", { schemaUid });
1287
+ }
1229
1288
  if (err instanceof OmaTrustError) {
1230
1289
  throw err;
1231
1290
  }
@@ -1409,7 +1468,28 @@ function createEvidencePointerProof(url) {
1409
1468
  issuedAt: Math.floor(Date.now() / 1e3)
1410
1469
  };
1411
1470
  }
1471
+ async function verifyDnsTxtControllerDid(domain, expectedControllerDid) {
1472
+ if (!domain || typeof domain !== "string") {
1473
+ throw new OmaTrustError("INVALID_INPUT", "domain must be a non-empty string", { domain });
1474
+ }
1475
+ const expected = normalizeDid(expectedControllerDid);
1476
+ const host = `_omatrust.${domain.toLowerCase().replace(/\.$/, "")}`;
1477
+ let records;
1478
+ try {
1479
+ records = await resolveTxt(host);
1480
+ } catch (err) {
1481
+ throw new OmaTrustError("NETWORK_ERROR", "Failed to resolve DNS TXT records", { domain, err });
1482
+ }
1483
+ for (const recordParts of records) {
1484
+ const record = recordParts.join("");
1485
+ const parsed = parseDnsTxtRecord(record);
1486
+ if (parsed.version === "1" && parsed.controller && normalizeDid(parsed.controller) === expected) {
1487
+ return { valid: true, record };
1488
+ }
1489
+ }
1490
+ return { valid: false, reason: "No TXT record matched expected controller DID" };
1491
+ }
1412
1492
 
1413
- export { buildDelegatedAttestationTypedData, buildDnsTxtRecord, buildEip712Domain, calculateAverageUserReviewRating, calculateTransferAmount, calculateTransferAmountFromAddresses, callControllerWitness, constructSeed, createEvidencePointerProof, createPopEip712Proof, createPopJwsProof, createTxEncodedValueProof, createTxInteractionProof, createX402OfferProof, createX402ReceiptProof, decodeAttestationData, deduplicateReviews, encodeAttestationData, extractAddressesFromDidDocument, extractExpirationTime, fetchDidDocument, formatSchemaUid, formatTransferAmount, getAttestation, getAttestationsForDid, getChainConstants, getExplorerAddressUrl, getExplorerTxUrl, getLatestAttestations, getMajorVersion, getOmaTrustProofEip712Types, getSchemaDetails, getSupportedChainIds, hashSeed, isChainSupported, listAttestations, normalizeSchema, parseDnsTxtRecord, prepareDelegatedAttestation, schemaToString, splitSignature, submitAttestation, submitDelegatedAttestation, verifyAttestation, verifyDidDocumentControllerDid, verifyDnsTxtControllerDid, verifyEip712Signature, verifyProof, verifySchemaExists };
1493
+ export { buildDelegatedAttestationTypedData, buildDelegatedTypedDataFromEncoded, buildDnsTxtRecord, buildEip712Domain, calculateAverageUserReviewRating, calculateTransferAmount, calculateTransferAmountFromAddresses, callControllerWitness, constructSeed, createEvidencePointerProof, createPopEip712Proof, createPopJwsProof, createTxEncodedValueProof, createTxInteractionProof, createX402OfferProof, createX402ReceiptProof, decodeAttestationData, deduplicateReviews, encodeAttestationData, extractAddressesFromDidDocument, extractExpirationTime, fetchDidDocument, formatSchemaUid, formatTransferAmount, getAttestation, getAttestationsForDid, getChainConstants, getExplorerAddressUrl, getExplorerTxUrl, getLatestAttestations, getMajorVersion, getOmaTrustProofEip712Types, getSchemaDetails, getSupportedChainIds, hashSeed, isChainSupported, listAttestations, normalizeSchema, parseDnsTxtRecord, prepareDelegatedAttestation, schemaToString, splitSignature, submitAttestation, submitDelegatedAttestation, verifyAttestation, verifyDidDocumentControllerDid, verifyDnsTxtControllerDid, verifyEip712Signature, verifyProof, verifySchemaExists };
1414
1494
  //# sourceMappingURL=index.js.map
1415
1495
  //# sourceMappingURL=index.js.map