@interest-protocol/vortex-sdk 8.0.0 → 8.2.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.
@@ -17,6 +17,16 @@ interface GetUnspentUtxosWithApiArgs {
17
17
  vortexSdk: Vortex;
18
18
  vortexPool: string | VortexPool;
19
19
  }
20
+ interface GetUnspentUtxosWithApiAndCommitmentsArgs {
21
+ commitments: Pick<Commitment, 'coinType' | 'encryptedOutput'>[];
22
+ vortexKeypair: VortexKeypair;
23
+ vortexSdk: Vortex;
24
+ vortexPool: string | VortexPool;
25
+ }
20
26
  export declare const getUnspentUtxosWithApi: ({ commitments, vortexKeypair, vortexSdk, vortexPool, }: GetUnspentUtxosWithApiArgs) => Promise<Utxo[]>;
27
+ export declare const getUnspentUtxosWithApiAndCommitments: ({ commitments, vortexKeypair, vortexSdk, vortexPool, }: GetUnspentUtxosWithApiAndCommitmentsArgs) => Promise<{
28
+ unspentUtxos: Utxo[];
29
+ userCommitments: Pick<Commitment, "coinType" | "encryptedOutput">[];
30
+ }>;
21
31
  export {};
22
32
  //# sourceMappingURL=decrypt.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"decrypt.d.ts","sourceRoot":"","sources":["../../src/utils/decrypt.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAErD,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAEjD,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AAExC,OAAO,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AACnC,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAG7C,UAAU,mBAAmB;IAC3B,gBAAgB,EAAE,eAAe,CAAC;IAClC,aAAa,EAAE,aAAa,CAAC;IAC7B,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU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C;IAC7B,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,MAAM,GAAG,UAAU,CAAC;CACjC;AAED,eAAO,MAAM,sBAAsB,GAAU,wDAK1C,0BAA0B,oBA2C5B,CAAC;AAEF,eAAO,MAAM,oCAAoC,GAAU,wDAKxD,wCAAwC;;;EAmD1C,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@interest-protocol/vortex-sdk",
3
- "version": "8.0.0",
3
+ "version": "8.2.0",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "module": "./dist/index.mjs",
@@ -64,6 +64,13 @@ interface GetUnspentUtxosWithApiArgs {
64
64
  vortexPool: string | VortexPool;
65
65
  }
66
66
 
67
+ interface GetUnspentUtxosWithApiAndCommitmentsArgs {
68
+ commitments: Pick<Commitment, 'coinType' | 'encryptedOutput'>[];
69
+ vortexKeypair: VortexKeypair;
70
+ vortexSdk: Vortex;
71
+ vortexPool: string | VortexPool;
72
+ }
73
+
67
74
  export const getUnspentUtxosWithApi = async ({
68
75
  commitments,
69
76
  vortexKeypair,
@@ -113,3 +120,61 @@ export const getUnspentUtxosWithApi = async ({
113
120
 
114
121
  return unspentUtxos;
115
122
  };
123
+
124
+ export const getUnspentUtxosWithApiAndCommitments = async ({
125
+ commitments,
126
+ vortexKeypair,
127
+ vortexSdk,
128
+ vortexPool,
129
+ }: GetUnspentUtxosWithApiAndCommitmentsArgs) => {
130
+ const allUtxos = [] as UtxoPayload[];
131
+ const userCommitments = [] as Pick<
132
+ Commitment,
133
+ 'coinType' | 'encryptedOutput'
134
+ >[];
135
+
136
+ const vortexObject = await vortexSdk.resolveVortexPool(vortexPool);
137
+
138
+ commitments.forEach((commitment) => {
139
+ invariant(
140
+ normalizeStructTag(commitment.coinType) ===
141
+ normalizeStructTag(vortexObject.coinType),
142
+ 'Commitment coin type does not match vortex pool coin type'
143
+ );
144
+ try {
145
+ const encryptedOutputHex = toHex(
146
+ Uint8Array.from(commitment.encryptedOutput)
147
+ );
148
+ const utxo = vortexKeypair.decryptUtxo(encryptedOutputHex);
149
+ userCommitments.push({
150
+ coinType: commitment.coinType,
151
+ encryptedOutput: commitment.encryptedOutput,
152
+ });
153
+ allUtxos.push(utxo);
154
+ } catch {
155
+ // Do nothing
156
+ }
157
+ });
158
+
159
+ const utxos = allUtxos.map(
160
+ (utxo) =>
161
+ new Utxo({
162
+ ...utxo,
163
+ keypair: vortexKeypair,
164
+ vortexPool: vortexObject.objectId,
165
+ })
166
+ );
167
+
168
+ const nullifiers = utxos.map((utxo) => utxo.nullifier());
169
+
170
+ const isNullifierSpentArray = await vortexSdk.areNullifiersSpent({
171
+ nullifiers,
172
+ vortexPool,
173
+ });
174
+
175
+ const unspentUtxos = utxos.filter(
176
+ (_, index) => !isNullifierSpentArray[index]
177
+ );
178
+
179
+ return { unspentUtxos, userCommitments };
180
+ };