@oma3/omatrust 0.1.0-alpha.3 → 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.
@@ -329,6 +329,53 @@ function resolveRecipientAddress(data) {
329
329
  return ethers.ZeroAddress;
330
330
  }
331
331
 
332
+ // src/reputation/eas-adapter.ts
333
+ function isRecord(value) {
334
+ return Boolean(value) && typeof value === "object";
335
+ }
336
+ function isHex32(value) {
337
+ return typeof value === "string" && /^0x[0-9a-fA-F]{64}$/.test(value);
338
+ }
339
+ function getEasTransactionReceipt(tx) {
340
+ if (!isRecord(tx)) {
341
+ return void 0;
342
+ }
343
+ const candidates = [tx.receipt, tx.tx, tx.transaction];
344
+ for (const candidate of candidates) {
345
+ if (isRecord(candidate)) {
346
+ return candidate;
347
+ }
348
+ }
349
+ return void 0;
350
+ }
351
+ function getEasTransactionHash(tx) {
352
+ const receipt = getEasTransactionReceipt(tx);
353
+ if (receipt) {
354
+ const receiptHash = receipt.hash;
355
+ if (isHex32(receiptHash)) {
356
+ return receiptHash;
357
+ }
358
+ const transactionHash = receipt.transactionHash;
359
+ if (isHex32(transactionHash)) {
360
+ return transactionHash;
361
+ }
362
+ }
363
+ if (isRecord(tx) && isHex32(tx.hash)) {
364
+ return tx.hash;
365
+ }
366
+ return void 0;
367
+ }
368
+ function isEasSchemaNotFoundError(err) {
369
+ if (!isRecord(err)) {
370
+ return false;
371
+ }
372
+ const message = err.message;
373
+ if (typeof message !== "string" || message.length === 0) {
374
+ return false;
375
+ }
376
+ return /schema not found/i.test(message);
377
+ }
378
+
332
379
  // src/reputation/submit.ts
333
380
  async function submitAttestation(params) {
334
381
  if (!params || typeof params !== "object") {
@@ -359,12 +406,12 @@ async function submitAttestation(params) {
359
406
  }
360
407
  });
361
408
  const uid = await tx.wait();
362
- const txAny = tx;
363
- const txHash = txAny.tx?.hash ?? txAny.hash ?? txAny.transaction?.hash ?? ZERO_UID;
409
+ const txHash = getEasTransactionHash(tx) ?? ZERO_UID;
410
+ const receipt = getEasTransactionReceipt(tx);
364
411
  return {
365
412
  uid,
366
413
  txHash,
367
- receipt: txAny.tx
414
+ receipt
368
415
  };
369
416
  } catch (err) {
370
417
  throw new OmaTrustError("NETWORK_ERROR", "Failed to submit attestation", { err });
@@ -1240,6 +1287,9 @@ async function getSchemaDetails(schemaRegistry, schemaUid) {
1240
1287
  revocable: Boolean(details.revocable)
1241
1288
  };
1242
1289
  } catch (err) {
1290
+ if (isEasSchemaNotFoundError(err)) {
1291
+ throw new OmaTrustError("SCHEMA_NOT_FOUND", "Schema was not found", { schemaUid });
1292
+ }
1243
1293
  if (err instanceof OmaTrustError) {
1244
1294
  throw err;
1245
1295
  }