@oma3/omatrust 0.1.0-alpha.3 → 0.1.0-alpha.5

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.
@@ -330,6 +330,53 @@ function resolveRecipientAddress(data) {
330
330
  return ethers.ZeroAddress;
331
331
  }
332
332
 
333
+ // src/reputation/eas-adapter.ts
334
+ function isRecord(value) {
335
+ return Boolean(value) && typeof value === "object";
336
+ }
337
+ function isHex32(value) {
338
+ return typeof value === "string" && /^0x[0-9a-fA-F]{64}$/.test(value);
339
+ }
340
+ function getEasTransactionReceipt(tx) {
341
+ if (!isRecord(tx)) {
342
+ return void 0;
343
+ }
344
+ const candidates = [tx.receipt, tx.tx, tx.transaction];
345
+ for (const candidate of candidates) {
346
+ if (isRecord(candidate)) {
347
+ return candidate;
348
+ }
349
+ }
350
+ return void 0;
351
+ }
352
+ function getEasTransactionHash(tx) {
353
+ const receipt = getEasTransactionReceipt(tx);
354
+ if (receipt) {
355
+ const receiptHash = receipt.hash;
356
+ if (isHex32(receiptHash)) {
357
+ return receiptHash;
358
+ }
359
+ const transactionHash = receipt.transactionHash;
360
+ if (isHex32(transactionHash)) {
361
+ return transactionHash;
362
+ }
363
+ }
364
+ if (isRecord(tx) && isHex32(tx.hash)) {
365
+ return tx.hash;
366
+ }
367
+ return void 0;
368
+ }
369
+ function isEasSchemaNotFoundError(err) {
370
+ if (!isRecord(err)) {
371
+ return false;
372
+ }
373
+ const message = err.message;
374
+ if (typeof message !== "string" || message.length === 0) {
375
+ return false;
376
+ }
377
+ return /schema not found/i.test(message);
378
+ }
379
+
333
380
  // src/reputation/submit.ts
334
381
  async function submitAttestation(params) {
335
382
  if (!params || typeof params !== "object") {
@@ -360,12 +407,12 @@ async function submitAttestation(params) {
360
407
  }
361
408
  });
362
409
  const uid = await tx.wait();
363
- const txAny = tx;
364
- const txHash = txAny.tx?.hash ?? txAny.hash ?? txAny.transaction?.hash ?? ZERO_UID;
410
+ const txHash = getEasTransactionHash(tx) ?? ZERO_UID;
411
+ const receipt = getEasTransactionReceipt(tx);
365
412
  return {
366
413
  uid,
367
414
  txHash,
368
- receipt: txAny.tx
415
+ receipt
369
416
  };
370
417
  } catch (err) {
371
418
  throw new OmaTrustError("NETWORK_ERROR", "Failed to submit attestation", { err });
@@ -518,7 +565,14 @@ async function submitDelegatedAttestation(params) {
518
565
  var EAS_EVENT_ABI = [
519
566
  "event Attested(address indexed recipient, address indexed attester, bytes32 uid, bytes32 indexed schemaUID)"
520
567
  ];
521
- function parseAttestation(attestation, schema) {
568
+ function parseEventTxHash(event) {
569
+ const txHash = event.transactionHash;
570
+ if (typeof txHash !== "string") {
571
+ return void 0;
572
+ }
573
+ return /^0x[0-9a-fA-F]{64}$/.test(txHash) ? txHash : void 0;
574
+ }
575
+ function parseAttestation(attestation, schema, txHash) {
522
576
  const rawData = attestation.data ?? "0x";
523
577
  const decoded = schema ? decodeAttestationData(schema, rawData) : {};
524
578
  const toBigIntSafe = (value) => {
@@ -538,6 +592,7 @@ function parseAttestation(attestation, schema) {
538
592
  schema: attestation.schema,
539
593
  attester: attestation.attester,
540
594
  recipient: attestation.recipient,
595
+ txHash,
541
596
  revocable: Boolean(attestation.revocable),
542
597
  revocationTime: toBigIntSafe(attestation.revocationTime),
543
598
  expirationTime: toBigIntSafe(attestation.expirationTime),
@@ -596,7 +651,7 @@ async function getAttestationsForDid(params) {
596
651
  if (!attestation || !attestation.uid) {
597
652
  continue;
598
653
  }
599
- results.push(parseAttestation(attestation));
654
+ results.push(parseAttestation(attestation, void 0, parseEventTxHash(event)));
600
655
  }
601
656
  results.sort((a, b) => Number(b.time - a.time));
602
657
  return results;
@@ -636,7 +691,7 @@ async function getLatestAttestations(params) {
636
691
  if (!attestation || !attestation.uid) {
637
692
  continue;
638
693
  }
639
- results.push(parseAttestation(attestation));
694
+ results.push(parseAttestation(attestation, void 0, parseEventTxHash(event)));
640
695
  }
641
696
  results.sort((a, b) => Number(b.time - a.time));
642
697
  return results.slice(0, params.limit ?? 20);
@@ -1241,6 +1296,9 @@ async function getSchemaDetails(schemaRegistry, schemaUid) {
1241
1296
  revocable: Boolean(details.revocable)
1242
1297
  };
1243
1298
  } catch (err) {
1299
+ if (isEasSchemaNotFoundError(err)) {
1300
+ throw new OmaTrustError("SCHEMA_NOT_FOUND", "Schema was not found", { schemaUid });
1301
+ }
1244
1302
  if (err instanceof OmaTrustError) {
1245
1303
  throw err;
1246
1304
  }