@interest-protocol/vortex-sdk 12.0.3 → 13.0.0
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 +31 -17
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +31 -17
- package/dist/index.mjs.map +1 -1
- package/dist/utils/decrypt.d.ts +2 -2
- package/dist/utils/decrypt.d.ts.map +1 -1
- package/dist/vortex-api.d.ts +1 -1
- package/dist/vortex-api.d.ts.map +1 -1
- package/dist/vortex-api.types.d.ts +1 -2
- package/dist/vortex-api.types.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/__tests__/entities/keypair.spec.ts +102 -0
- package/src/utils/decrypt.ts +30 -16
- package/src/vortex-api.ts +8 -10
- package/src/vortex-api.types.ts +1 -2
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
|
-
|
|
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 =
|
|
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
|
|
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
|
-
|
|
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 =
|
|
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
|
|
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
|
-
|
|
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 =
|
|
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
|
}));
|
|
@@ -39823,9 +39837,6 @@ class VortexAPI {
|
|
|
39823
39837
|
if (args.op) {
|
|
39824
39838
|
params.set('op', args.op);
|
|
39825
39839
|
}
|
|
39826
|
-
if (args.page) {
|
|
39827
|
-
params.set('page', args.page.toString());
|
|
39828
|
-
}
|
|
39829
39840
|
if (args.limit) {
|
|
39830
39841
|
params.set('limit', args.limit.toString());
|
|
39831
39842
|
}
|
|
@@ -39836,20 +39847,23 @@ class VortexAPI {
|
|
|
39836
39847
|
async getAllCommitments(args) {
|
|
39837
39848
|
const sleepMs = Math.max(args.sleepMs ?? 200, 200);
|
|
39838
39849
|
const allCommitments = [];
|
|
39839
|
-
let
|
|
39850
|
+
let index = args.index;
|
|
39840
39851
|
let hasNext = true;
|
|
39841
39852
|
while (hasNext) {
|
|
39842
39853
|
const response = await this.getCommitments({
|
|
39843
39854
|
...args,
|
|
39844
|
-
|
|
39855
|
+
index,
|
|
39845
39856
|
apiKey: args.apiKey,
|
|
39846
39857
|
});
|
|
39847
39858
|
allCommitments.push(...response.data.items);
|
|
39848
|
-
hasNext = response.data.
|
|
39849
|
-
|
|
39850
|
-
|
|
39859
|
+
hasNext = response.data.hasNext;
|
|
39860
|
+
if (hasNext && response.data.items.length > 0) {
|
|
39861
|
+
index = response.data.items[response.data.items.length - 1].index + 1;
|
|
39851
39862
|
await new Promise((resolve) => setTimeout(resolve, sleepMs));
|
|
39852
39863
|
}
|
|
39864
|
+
else {
|
|
39865
|
+
hasNext = false;
|
|
39866
|
+
}
|
|
39853
39867
|
}
|
|
39854
39868
|
return allCommitments;
|
|
39855
39869
|
}
|