@entros/pulse-sdk 1.4.0 → 1.4.2

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.
package/dist/index.mjs CHANGED
@@ -1287,7 +1287,7 @@ function bytesToHex(bytes) {
1287
1287
  function hexToBytes(hex, expectedLen) {
1288
1288
  const trimmed = hex.startsWith("0x") || hex.startsWith("0X") ? hex.slice(2) : hex;
1289
1289
  if (trimmed.length !== expectedLen * 2) return null;
1290
- if (!/^[0-9a-fA-F]+$/.test(trimmed)) return null;
1290
+ if (!/^[0-9a-f]+$/.test(trimmed)) return null;
1291
1291
  const out = new Uint8Array(expectedLen);
1292
1292
  for (let i = 0; i < expectedLen; i += 1) {
1293
1293
  out[i] = parseInt(trimmed.substr(i * 2, 2), 16);
@@ -1314,6 +1314,26 @@ async function buildEd25519ReceiptIx(receipt) {
1314
1314
 
1315
1315
  // src/submit/wallet.ts
1316
1316
  async function requestSasAttestation(wallet, walletAddress, relayerUrl, relayerApiKey, serverNonce) {
1317
+ if (!serverNonce) {
1318
+ sdkLog("[Entros SDK] Skipping SAS attestation: no server-issued nonce");
1319
+ return void 0;
1320
+ }
1321
+ if (!wallet?.signMessage) {
1322
+ sdkLog("[Entros SDK] Skipping SAS attestation: wallet does not support signMessage");
1323
+ return void 0;
1324
+ }
1325
+ let signature;
1326
+ let message;
1327
+ try {
1328
+ const timestamp = Math.floor(Date.now() / 1e3);
1329
+ message = `Entros-ATTEST:${walletAddress}:${timestamp}`;
1330
+ const messageBytes = new TextEncoder().encode(message);
1331
+ const sigBytes = await wallet.signMessage(messageBytes);
1332
+ signature = Array.from(sigBytes).map((b) => b.toString(16).padStart(2, "0")).join("");
1333
+ } catch {
1334
+ sdkWarn("[Entros SDK] Wallet signMessage failed, skipping SAS attestation");
1335
+ return void 0;
1336
+ }
1317
1337
  try {
1318
1338
  const attestHeaders = {
1319
1339
  "Content-Type": "application/json"
@@ -1325,21 +1345,12 @@ async function requestSasAttestation(wallet, walletAddress, relayerUrl, relayerA
1325
1345
  const timer = setTimeout(() => controller.abort(), 15e3);
1326
1346
  const baseUrl = new URL(relayerUrl);
1327
1347
  const attestUrl = `${baseUrl.origin}/attest`;
1328
- const attestBody = { wallet_address: walletAddress };
1329
- if (serverNonce) attestBody.nonce = serverNonce;
1330
- if (wallet?.signMessage) {
1331
- try {
1332
- const timestamp = Math.floor(Date.now() / 1e3);
1333
- const attestMessage = `Entros-ATTEST:${walletAddress}:${timestamp}`;
1334
- const messageBytes = new TextEncoder().encode(attestMessage);
1335
- const sigBytes = await wallet.signMessage(messageBytes);
1336
- const sigHex = Array.from(sigBytes).map((b) => b.toString(16).padStart(2, "0")).join("");
1337
- attestBody.signature = sigHex;
1338
- attestBody.message = attestMessage;
1339
- } catch {
1340
- sdkWarn("Wallet signMessage failed, skipping ownership proof");
1341
- }
1342
- }
1348
+ const attestBody = {
1349
+ wallet_address: walletAddress,
1350
+ nonce: serverNonce,
1351
+ signature,
1352
+ message
1353
+ };
1343
1354
  const attestRes = await fetch(attestUrl, {
1344
1355
  method: "POST",
1345
1356
  headers: attestHeaders,
@@ -1555,21 +1566,22 @@ async function submitViaWallet(proof, commitment, options) {
1555
1566
  let ed25519Ix = null;
1556
1567
  if (options.signedReceipt) {
1557
1568
  ed25519Ix = await buildEd25519ReceiptIx(options.signedReceipt);
1558
- if (ed25519Ix) {
1559
- sdkLog(
1560
- "[Entros SDK] Bundling validator-signed mint receipt before mint_anchor"
1561
- );
1562
- } else {
1563
- sdkWarn(
1564
- "[Entros SDK] signedReceipt provided but failed to decode; minting without binding"
1565
- );
1569
+ if (!ed25519Ix) {
1570
+ return {
1571
+ success: false,
1572
+ error: "Validator returned a signed receipt that failed to decode (malformed hex or wrong byte length). Refusing to mint without a valid binding. The validator service may be misconfigured \u2014 check the validation-service logs."
1573
+ };
1566
1574
  }
1575
+ sdkLog(
1576
+ "[Entros SDK] Bundling validator-signed mint receipt before mint_anchor"
1577
+ );
1567
1578
  } else {
1568
1579
  sdkLog(
1569
- "[Entros SDK] No validator receipt available; minting without binding (Phase 3 log-only)"
1580
+ "[Entros SDK] No validator receipt available; minting without binding (on-chain check is log-only today)"
1570
1581
  );
1571
1582
  }
1572
1583
  const tx = new Transaction();
1584
+ tx.add(ComputeBudgetProgram.setComputeUnitLimit({ units: 2e5 }));
1573
1585
  if (ed25519Ix) tx.add(ed25519Ix);
1574
1586
  tx.add(mintAnchorIx);
1575
1587
  tx.feePayer = provider.wallet.publicKey;
@@ -2034,7 +2046,11 @@ async function extractFingerprintAndValidate(sensorData, config, walletAddress,
2034
2046
  if (successBody.signed_receipt) {
2035
2047
  signedReceipt = successBody.signed_receipt;
2036
2048
  }
2037
- } catch {
2049
+ } catch (err) {
2050
+ const msg = err instanceof Error ? err.message : String(err);
2051
+ sdkWarn(
2052
+ `[Entros SDK] /validate-features returned 200 but body was not parseable JSON; proceeding without receipt: ${msg}`
2053
+ );
2038
2054
  }
2039
2055
  } catch (err) {
2040
2056
  const msg = err instanceof Error ? err.message : String(err);