@interest-protocol/vortex-sdk 12.0.3 → 12.0.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.
package/dist/index.mjs CHANGED
@@ -39072,18 +39072,25 @@ class Utxo {
39072
39072
 
39073
39073
  const getUnspentUtxos = async ({ commitmentEvents, vortexKeypair, vortexSdk, vortexPool, }) => {
39074
39074
  const commitments = parseNewCommitmentEvent(commitmentEvents);
39075
- const allUtxos = [];
39076
39075
  const vortexObjectId = typeof vortexPool === 'string' ? vortexPool : vortexPool.objectId;
39076
+ const decryptedWithIndex = [];
39077
39077
  commitments.forEach((commitment) => {
39078
39078
  try {
39079
39079
  const utxo = vortexKeypair.decryptUtxo(commitment.encryptedOutput);
39080
- allUtxos.push(utxo);
39080
+ // Use index from chain (commitment.index) instead of decrypted index
39081
+ // to avoid concurrency/latency issues where encrypted index can be stale
39082
+ decryptedWithIndex.push({ utxo, chainIndex: commitment.index });
39081
39083
  }
39082
39084
  catch {
39083
39085
  // HMAC verification failed - wrong keypair
39084
39086
  }
39085
39087
  });
39086
- const utxos = allUtxos.map((utxo) => new Utxo({ ...utxo, keypair: vortexKeypair, vortexPool: vortexObjectId }));
39088
+ const utxos = decryptedWithIndex.map(({ utxo, chainIndex }) => new Utxo({
39089
+ ...utxo,
39090
+ index: chainIndex, // Override with on-chain index
39091
+ keypair: vortexKeypair,
39092
+ vortexPool: vortexObjectId,
39093
+ }));
39087
39094
  const nullifiers = utxos.map((utxo) => utxo.nullifier());
39088
39095
  const isNullifierSpentArray = await vortexSdk.areNullifiersSpent({
39089
39096
  nullifiers,
@@ -39093,7 +39100,7 @@ const getUnspentUtxos = async ({ commitmentEvents, vortexKeypair, vortexSdk, vor
39093
39100
  return unspentUtxos;
39094
39101
  };
39095
39102
  const getUnspentUtxosWithApi = async ({ commitments, vortexKeypair, vortexSdk, vortexPool, }) => {
39096
- const allUtxos = [];
39103
+ const decryptedWithIndex = [];
39097
39104
  const vortexObject = await vortexSdk.resolveVortexPool(vortexPool);
39098
39105
  commitments.forEach((commitment) => {
39099
39106
  invariant(normalizeStructTag(commitment.coinType) ===
@@ -39101,14 +39108,17 @@ const getUnspentUtxosWithApi = async ({ commitments, vortexKeypair, vortexSdk, v
39101
39108
  try {
39102
39109
  const encryptedOutputHex = toHex(Uint8Array.from(commitment.encryptedOutput));
39103
39110
  const utxo = vortexKeypair.decryptUtxo(encryptedOutputHex);
39104
- allUtxos.push(utxo);
39111
+ // Use index from chain (commitment.index) instead of decrypted index
39112
+ // to avoid concurrency/latency issues where encrypted index can be stale
39113
+ decryptedWithIndex.push({ utxo, chainIndex: BigInt(commitment.index) });
39105
39114
  }
39106
39115
  catch {
39107
39116
  // HMAC verification failed - wrong keypair
39108
39117
  }
39109
39118
  });
39110
- const utxos = allUtxos.map((utxo) => new Utxo({
39119
+ const utxos = decryptedWithIndex.map(({ utxo, chainIndex }) => new Utxo({
39111
39120
  ...utxo,
39121
+ index: chainIndex, // Override with on-chain index
39112
39122
  keypair: vortexKeypair,
39113
39123
  vortexPool: vortexObject.objectId,
39114
39124
  }));
@@ -39121,7 +39131,7 @@ const getUnspentUtxosWithApi = async ({ commitments, vortexKeypair, vortexSdk, v
39121
39131
  return unspentUtxos;
39122
39132
  };
39123
39133
  const getUnspentUtxosWithApiAndCommitments = async ({ commitments, vortexKeypair, vortexSdk, vortexPool, }) => {
39124
- const allUtxos = [];
39134
+ const decryptedWithIndex = [];
39125
39135
  const userCommitments = [];
39126
39136
  const vortexObject = await vortexSdk.resolveVortexPool(vortexPool);
39127
39137
  commitments.forEach((commitment) => {
@@ -39133,15 +39143,19 @@ const getUnspentUtxosWithApiAndCommitments = async ({ commitments, vortexKeypair
39133
39143
  userCommitments.push({
39134
39144
  coinType: commitment.coinType,
39135
39145
  encryptedOutput: commitment.encryptedOutput,
39146
+ index: commitment.index,
39136
39147
  });
39137
- allUtxos.push(utxo);
39148
+ // Use index from chain (commitment.index) instead of decrypted index
39149
+ // to avoid concurrency/latency issues where encrypted index can be stale
39150
+ decryptedWithIndex.push({ utxo, chainIndex: BigInt(commitment.index) });
39138
39151
  }
39139
39152
  catch {
39140
39153
  // HMAC verification failed - wrong keypair
39141
39154
  }
39142
39155
  });
39143
- const utxos = allUtxos.map((utxo) => new Utxo({
39156
+ const utxos = decryptedWithIndex.map(({ utxo, chainIndex }) => new Utxo({
39144
39157
  ...utxo,
39158
+ index: chainIndex, // Override with on-chain index
39145
39159
  keypair: vortexKeypair,
39146
39160
  vortexPool: vortexObject.objectId,
39147
39161
  }));