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