@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.
@@ -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 });
@@ -1241,6 +1288,9 @@ async function getSchemaDetails(schemaRegistry, schemaUid) {
1241
1288
  revocable: Boolean(details.revocable)
1242
1289
  };
1243
1290
  } catch (err) {
1291
+ if (isEasSchemaNotFoundError(err)) {
1292
+ throw new OmaTrustError("SCHEMA_NOT_FOUND", "Schema was not found", { schemaUid });
1293
+ }
1244
1294
  if (err instanceof OmaTrustError) {
1245
1295
  throw err;
1246
1296
  }