@interest-protocol/vortex-sdk 8.0.0 → 8.1.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.
@@ -18,5 +18,9 @@ interface GetUnspentUtxosWithApiArgs {
18
18
  vortexPool: string | VortexPool;
19
19
  }
20
20
  export declare const getUnspentUtxosWithApi: ({ commitments, vortexKeypair, vortexSdk, vortexPool, }: GetUnspentUtxosWithApiArgs) => Promise<Utxo[]>;
21
+ export declare const getUnspentUtxosWithApiAndCommitments: ({ commitments, vortexKeypair, vortexSdk, vortexPool, }: GetUnspentUtxosWithApiArgs) => Promise<{
22
+ unspentUtxos: Utxo[];
23
+ userCommitments: Commitment[];
24
+ }>;
21
25
  export {};
22
26
  //# 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,EAAE,MAAM,GAAG,UAAU,CAAC;CACjC;AAED,eAAO,MAAM,eAAe,GAAU,6DAKnC,mBAAmB,oBAkCrB,CAAC;AAEF,UAAU,0BAA0B;IAClC,WAAW,EAAE,UAAU,EAAE,CAAC;IAC1B,aAAa,EAAE,aAAa,CAAC;IAC7B,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,MAAM,GAAG,UAAU,CAAC;CACjC;AAED,eAAO,MAAM,sBAAsB,GAAU,wDAK1C,0BAA0B,oBA2C5B,CAAC"}
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,EAAE,MAAM,GAAG,UAAU,CAAC;CACjC;AAED,eAAO,MAAM,eAAe,GAAU,6DAKnC,mBAAmB,oBAkCrB,CAAC;AAEF,UAAU,0BAA0B;IAClC,WAAW,EAAE,UAAU,EAAE,CAAC;IAC1B,aAAa,EAAE,aAAa,CAAC;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,0BAA0B;;;EA6C5B,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.1.0",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "module": "./dist/index.mjs",
@@ -37,8 +37,8 @@
37
37
  "rimraf": "^6.0.1",
38
38
  "ts-jest": "^29.1.1",
39
39
  "tsup": "^8.3.5",
40
- "@interest-protocol/typescript-config": "1.0.0",
41
- "@interest-protocol/prettier-config": "1.0.0"
40
+ "@interest-protocol/prettier-config": "1.0.0",
41
+ "@interest-protocol/typescript-config": "1.0.0"
42
42
  },
43
43
  "publishConfig": {
44
44
  "access": "public",
@@ -113,3 +113,55 @@ export const getUnspentUtxosWithApi = async ({
113
113
 
114
114
  return unspentUtxos;
115
115
  };
116
+
117
+ export const getUnspentUtxosWithApiAndCommitments = async ({
118
+ commitments,
119
+ vortexKeypair,
120
+ vortexSdk,
121
+ vortexPool,
122
+ }: GetUnspentUtxosWithApiArgs) => {
123
+ const allUtxos = [] as UtxoPayload[];
124
+ const userCommitments = [] as Commitment[];
125
+
126
+ const vortexObject = await vortexSdk.resolveVortexPool(vortexPool);
127
+
128
+ commitments.forEach((commitment) => {
129
+ invariant(
130
+ normalizeStructTag(commitment.coinType) ===
131
+ normalizeStructTag(vortexObject.coinType),
132
+ 'Commitment coin type does not match vortex pool coin type'
133
+ );
134
+ try {
135
+ const encryptedOutputHex = toHex(
136
+ Uint8Array.from(commitment.encryptedOutput)
137
+ );
138
+ const utxo = vortexKeypair.decryptUtxo(encryptedOutputHex);
139
+ userCommitments.push(commitment);
140
+ allUtxos.push(utxo);
141
+ } catch {
142
+ // Do nothing
143
+ }
144
+ });
145
+
146
+ const utxos = allUtxos.map(
147
+ (utxo) =>
148
+ new Utxo({
149
+ ...utxo,
150
+ keypair: vortexKeypair,
151
+ vortexPool: vortexObject.objectId,
152
+ })
153
+ );
154
+
155
+ const nullifiers = utxos.map((utxo) => utxo.nullifier());
156
+
157
+ const isNullifierSpentArray = await vortexSdk.areNullifiersSpent({
158
+ nullifiers,
159
+ vortexPool,
160
+ });
161
+
162
+ const unspentUtxos = utxos.filter(
163
+ (_, index) => !isNullifierSpentArray[index]
164
+ );
165
+
166
+ return { unspentUtxos, userCommitments };
167
+ };