@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.
@@ -323,6 +323,53 @@ function resolveRecipientAddress(data) {
323
323
  return ZeroAddress;
324
324
  }
325
325
 
326
+ // src/reputation/eas-adapter.ts
327
+ function isRecord(value) {
328
+ return Boolean(value) && typeof value === "object";
329
+ }
330
+ function isHex32(value) {
331
+ return typeof value === "string" && /^0x[0-9a-fA-F]{64}$/.test(value);
332
+ }
333
+ function getEasTransactionReceipt(tx) {
334
+ if (!isRecord(tx)) {
335
+ return void 0;
336
+ }
337
+ const candidates = [tx.receipt, tx.tx, tx.transaction];
338
+ for (const candidate of candidates) {
339
+ if (isRecord(candidate)) {
340
+ return candidate;
341
+ }
342
+ }
343
+ return void 0;
344
+ }
345
+ function getEasTransactionHash(tx) {
346
+ const receipt = getEasTransactionReceipt(tx);
347
+ if (receipt) {
348
+ const receiptHash = receipt.hash;
349
+ if (isHex32(receiptHash)) {
350
+ return receiptHash;
351
+ }
352
+ const transactionHash = receipt.transactionHash;
353
+ if (isHex32(transactionHash)) {
354
+ return transactionHash;
355
+ }
356
+ }
357
+ if (isRecord(tx) && isHex32(tx.hash)) {
358
+ return tx.hash;
359
+ }
360
+ return void 0;
361
+ }
362
+ function isEasSchemaNotFoundError(err) {
363
+ if (!isRecord(err)) {
364
+ return false;
365
+ }
366
+ const message = err.message;
367
+ if (typeof message !== "string" || message.length === 0) {
368
+ return false;
369
+ }
370
+ return /schema not found/i.test(message);
371
+ }
372
+
326
373
  // src/reputation/submit.ts
327
374
  async function submitAttestation(params) {
328
375
  if (!params || typeof params !== "object") {
@@ -353,12 +400,12 @@ async function submitAttestation(params) {
353
400
  }
354
401
  });
355
402
  const uid = await tx.wait();
356
- const txAny = tx;
357
- const txHash = txAny.tx?.hash ?? txAny.hash ?? txAny.transaction?.hash ?? ZERO_UID;
403
+ const txHash = getEasTransactionHash(tx) ?? ZERO_UID;
404
+ const receipt = getEasTransactionReceipt(tx);
358
405
  return {
359
406
  uid,
360
407
  txHash,
361
- receipt: txAny.tx
408
+ receipt
362
409
  };
363
410
  } catch (err) {
364
411
  throw new OmaTrustError("NETWORK_ERROR", "Failed to submit attestation", { err });
@@ -1234,6 +1281,9 @@ async function getSchemaDetails(schemaRegistry, schemaUid) {
1234
1281
  revocable: Boolean(details.revocable)
1235
1282
  };
1236
1283
  } catch (err) {
1284
+ if (isEasSchemaNotFoundError(err)) {
1285
+ throw new OmaTrustError("SCHEMA_NOT_FOUND", "Schema was not found", { schemaUid });
1286
+ }
1237
1287
  if (err instanceof OmaTrustError) {
1238
1288
  throw err;
1239
1289
  }