@gurge/sdk 0.3.23 → 0.3.24
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/common/src/data-structures/Hinkal/hinkalWithdraw.cjs +1 -1
- package/common/src/data-structures/Hinkal/hinkalWithdraw.mjs +30 -25
- package/common/src/data-structures/MultiThreadedUtxoUtils/MultiThreadedUtxoUtils.cjs +1 -1
- package/common/src/data-structures/MultiThreadedUtxoUtils/MultiThreadedUtxoUtils.mjs +42 -26
- package/common/src/functions/pre-transaction/buildCommitmentValidationData.cjs +1 -1
- package/common/src/functions/pre-transaction/buildCommitmentValidationData.mjs +42 -38
- package/common/src/functions/snarkjs/constructGeneralZkProof.cjs +1 -1
- package/common/src/functions/snarkjs/constructGeneralZkProof.mjs +17 -17
- package/common/src/functions/snarkjs/generateZkProof.cjs +1 -1
- package/common/src/functions/snarkjs/generateZkProof.mjs +4 -4
- package/common/src/functions/snarkjs/generateZkProofSelf.cjs +1 -1
- package/common/src/functions/snarkjs/generateZkProofSelf.mjs +4 -4
- package/common/src/functions/web3/events/getInputUtxoAndBalance.cjs +1 -1
- package/common/src/functions/web3/events/getInputUtxoAndBalance.mjs +73 -42
- package/common/src/functions/web3/events/getInputUtxosEnclave.cjs +1 -1
- package/common/src/functions/web3/events/getInputUtxosEnclave.mjs +21 -20
- package/common/src/functions/web3/events/getShieldedBalance.cjs +1 -1
- package/common/src/functions/web3/events/getShieldedBalance.mjs +56 -53
- package/common/src/webworker/package.json +1 -1
- package/common/src/webworker/performTaskWithWorker.cjs +1 -1
- package/common/src/webworker/performTaskWithWorker.mjs +14 -14
- package/common/src/webworker/viteWorkerURL.constant.cjs +3 -3
- package/common/src/webworker/viteWorkerURL.constant.mjs +3 -3
- package/package.json +1 -1
- package/sdk/package.json.cjs +1 -1
- package/sdk/package.json.mjs +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
const e=require(`../../constants/chains.constants.cjs`),t=require(`../../constants/protocol.constants.cjs`),n=require(`../../types/hinkal.types.cjs`),r=require(`../../error-handling/error-codes.constants.cjs`),i=require(`../../functions/utils/time.utils.cjs`),a=require(`../../types/external-action.types.cjs`),o=require(`../../functions/utils/
|
|
1
|
+
const e=require(`../../constants/chains.constants.cjs`),t=require(`../../constants/protocol.constants.cjs`),n=require(`../../types/hinkal.types.cjs`),r=require(`../../error-handling/error-codes.constants.cjs`),i=require(`../../functions/utils/time.utils.cjs`),a=require(`../../types/external-action.types.cjs`),o=require(`../../functions/utils/hinkalTiming.utils.cjs`),s=require(`../../functions/utils/tron.utils.cjs`),c=require(`../../functions/utils/token-check.utils.cjs`),l=require(`../../functions/web3/events/getShieldedBalance.cjs`),u=require(`../../functions/pre-transaction/outputUtxoProcessing.cjs`),d=require(`../../functions/pre-transaction/getVolatileTransferAmount.cjs`),f=require(`../../functions/pre-transaction/constructAdminData.cjs`),p=require(`../../functions/pre-transaction/getFeeStructure.cjs`);require(`../../functions/pre-transaction/index.cjs`);const m=require(`../../functions/utils/fees.utils.cjs`),h=require(`../../functions/snarkjs/constructGeneralZkProof.cjs`),g=require(`../../functions/web3/functionCalls/transactCallDirect.cjs`),_=require(`../../functions/web3/functionCalls/transactCallRelayer.cjs`),v=require(`../../functions/web3/functionCalls/transactCallDirectTron.cjs`),y=require(`../../functions/pre-transaction/merge-with-fee-structure.cjs`);var b=async(e,t,n,r)=>{let a=o.createHinkalTiming(`withdraw.utxos`),s=[...await l.addPaddingToUtxos(e,t,n,r)];a.log(`addPaddingToUtxos`,{inputCount:s[0]?.length});let c=[],d=i.getCurrentTimeInSeconds().toString();for(let t=0;t<n.length;t+=1){let{outputUtxos:n}=u.outputUtxoProcessing(e.userKeys,s[t],r[t],d);c.push(n)}return a.log(`outputUtxoProcessing`),{inputUtxosArray:s,outputUtxosArray:c}},x=async(i,l,u,x,S,C,w,T)=>{let E=o.createHinkalTiming(`withdraw`),D=c.validateAndGetChainId(l),O=e.isTronLike(D);E.log(`start`,{chainId:D,isRelayerOff:S,tokenCount:l.length});let k=s.addressToHexFormat(await i.getEthereumAddressByChain(D));E.log(`getEthereumAddress`);let A=l.map(e=>e.erc20TokenAddress),j=await d.modifyVolatileTokenAmountChanges(D,l,u);E.log(`modifyVolatileTokenAmountChanges`);let M=l[0];if(!M)throw Error(`Deposit Action: No Token Found`);let N;if(!S){let e=w??await p.getFeeStructure(D,C,A,a.ExternalActionId.Transact);N=await m.calculateModifiedFeeStructure(D,M,-j[0],e),await y.mergeWithFeeStructure(D,A,j,N),E.log(`feeStructure`,{feeToken:C})}let P={externalActionId:0n,externalAddress:s.addressToHexFormat(x),externalActionMetadata:`0x00`},[F,{inputUtxosArray:I,outputUtxosArray:L}]=await Promise.all([(async()=>{let e=o.createHinkalTiming(`withdraw.relay`),t=await i.getRandomRelay(D,!0);return e.log(`getRandomRelay`,{hasRelay:!!t}),t})(),b(i,D,A,j)]);if(E.log(`relay+utxos`,{hasRelay:!!F}),!S&&!F)throw Error(r.transactionErrorCodes.RELAYER_NOT_AVAILABLE);let{zkCallData:R,circomData:z,dimData:B,commitmentValidationData:V}=await h.constructZkProof(i.merkleTreeHinkalByChain[D],I,L,i.userKeys,P.externalActionId,P.externalAddress,P.externalActionMetadata,i.generateProofRemotely,N??n.zeroFeeStructure,S?t.zeroAddress:F,D,void 0,void 0,S?k:void 0);E.log(`constructZkProof`,{generateProofRemotely:i.generateProofRemotely});let H=O&&S?void 0:await s.reorderZkCallData(O,R,B,z);if(E.log(`reorderZkCallData`),S){if(!M)throw Error(`Withdraw Action: No Token Found`);if(O){let e=await v.transactCallDirectTron(i,D,j[0],M,R,z,B);return E.log(`transactCallDirectTron`,{txid:e}),E.log(`done`),e}let e=await g.transactCallDirect(i,D,j[0],M,R,z,B);return E.log(`transactCallDirect`,{txHash:e.hash}),E.log(`done`),e}let U=await _.transactCallRelayer(D,R,B,z,V,void 0,void 0,f.constructAdminData(T,D,A,j,k),H);return E.log(`transactCallRelayer`,{txHash:U}),E.log(`done`),U};exports.hinkalWithdraw=x;
|
|
@@ -4,14 +4,14 @@ import { zeroFeeStructure as n } from "../../types/hinkal.types.mjs";
|
|
|
4
4
|
import { transactionErrorCodes as r } from "../../error-handling/error-codes.constants.mjs";
|
|
5
5
|
import { getCurrentTimeInSeconds as i } from "../../functions/utils/time.utils.mjs";
|
|
6
6
|
import { ExternalActionId as a } from "../../types/external-action.types.mjs";
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
14
|
-
import {
|
|
7
|
+
import { createHinkalTiming as o } from "../../functions/utils/hinkalTiming.utils.mjs";
|
|
8
|
+
import { addressToHexFormat as s, reorderZkCallData as c } from "../../functions/utils/tron.utils.mjs";
|
|
9
|
+
import { validateAndGetChainId as l } from "../../functions/utils/token-check.utils.mjs";
|
|
10
|
+
import { addPaddingToUtxos as u } from "../../functions/web3/events/getShieldedBalance.mjs";
|
|
11
|
+
import { outputUtxoProcessing as d } from "../../functions/pre-transaction/outputUtxoProcessing.mjs";
|
|
12
|
+
import { modifyVolatileTokenAmountChanges as f } from "../../functions/pre-transaction/getVolatileTransferAmount.mjs";
|
|
13
|
+
import { constructAdminData as p } from "../../functions/pre-transaction/constructAdminData.mjs";
|
|
14
|
+
import { getFeeStructure as m } from "../../functions/pre-transaction/getFeeStructure.mjs";
|
|
15
15
|
import "../../functions/pre-transaction/index.mjs";
|
|
16
16
|
import { calculateModifiedFeeStructure as h } from "../../functions/utils/fees.utils.mjs";
|
|
17
17
|
import { constructZkProof as g } from "../../functions/snarkjs/constructGeneralZkProof.mjs";
|
|
@@ -21,42 +21,47 @@ import { transactCallDirectTron as y } from "../../functions/web3/functionCalls/
|
|
|
21
21
|
import { mergeWithFeeStructure as b } from "../../functions/pre-transaction/merge-with-fee-structure.mjs";
|
|
22
22
|
//#region libs/shared/common/src/data-structures/Hinkal/hinkalWithdraw.ts
|
|
23
23
|
var x = async (e, t, n, r) => {
|
|
24
|
-
let a = [...await
|
|
24
|
+
let a = o("withdraw.utxos"), s = [...await u(e, t, n, r)];
|
|
25
|
+
a.log("addPaddingToUtxos", { inputCount: s[0]?.length });
|
|
26
|
+
let c = [], l = i().toString();
|
|
25
27
|
for (let t = 0; t < n.length; t += 1) {
|
|
26
|
-
let { outputUtxos: n } =
|
|
27
|
-
|
|
28
|
+
let { outputUtxos: n } = d(e.userKeys, s[t], r[t], l);
|
|
29
|
+
c.push(n);
|
|
28
30
|
}
|
|
29
|
-
return {
|
|
30
|
-
inputUtxosArray:
|
|
31
|
-
outputUtxosArray:
|
|
31
|
+
return a.log("outputUtxoProcessing"), {
|
|
32
|
+
inputUtxosArray: s,
|
|
33
|
+
outputUtxosArray: c
|
|
32
34
|
};
|
|
33
|
-
}, S = async (i,
|
|
34
|
-
let D =
|
|
35
|
+
}, S = async (i, u, d, S, C, w, T, E) => {
|
|
36
|
+
let D = o("withdraw"), O = l(u), k = e(O);
|
|
35
37
|
D.log("start", {
|
|
36
38
|
chainId: O,
|
|
37
39
|
isRelayerOff: C,
|
|
38
|
-
tokenCount:
|
|
40
|
+
tokenCount: u.length
|
|
39
41
|
});
|
|
40
|
-
let A =
|
|
42
|
+
let A = s(await i.getEthereumAddressByChain(O));
|
|
41
43
|
D.log("getEthereumAddress");
|
|
42
|
-
let j =
|
|
44
|
+
let j = u.map((e) => e.erc20TokenAddress), M = await f(O, u, d);
|
|
43
45
|
D.log("modifyVolatileTokenAmountChanges");
|
|
44
|
-
let N =
|
|
46
|
+
let N = u[0];
|
|
45
47
|
if (!N) throw Error("Deposit Action: No Token Found");
|
|
46
48
|
let P;
|
|
47
49
|
if (!C) {
|
|
48
|
-
let e = T ?? await
|
|
50
|
+
let e = T ?? await m(O, w, j, a.Transact);
|
|
49
51
|
P = await h(O, N, -M[0], e), await b(O, j, M, P), D.log("feeStructure", { feeToken: w });
|
|
50
52
|
}
|
|
51
53
|
let F = {
|
|
52
54
|
externalActionId: 0n,
|
|
53
|
-
externalAddress:
|
|
55
|
+
externalAddress: s(S),
|
|
54
56
|
externalActionMetadata: "0x00"
|
|
55
|
-
}, [I, { inputUtxosArray: L, outputUtxosArray: R }] = await Promise.all([
|
|
57
|
+
}, [I, { inputUtxosArray: L, outputUtxosArray: R }] = await Promise.all([(async () => {
|
|
58
|
+
let e = o("withdraw.relay"), t = await i.getRandomRelay(O, !0);
|
|
59
|
+
return e.log("getRandomRelay", { hasRelay: !!t }), t;
|
|
60
|
+
})(), x(i, O, j, M)]);
|
|
56
61
|
if (D.log("relay+utxos", { hasRelay: !!I }), !C && !I) throw Error(r.RELAYER_NOT_AVAILABLE);
|
|
57
62
|
let { zkCallData: z, circomData: B, dimData: V, commitmentValidationData: H } = await g(i.merkleTreeHinkalByChain[O], L, R, i.userKeys, F.externalActionId, F.externalAddress, F.externalActionMetadata, i.generateProofRemotely, P ?? n, C ? t : I, O, void 0, void 0, C ? A : void 0);
|
|
58
63
|
D.log("constructZkProof", { generateProofRemotely: i.generateProofRemotely });
|
|
59
|
-
let U = k && C ? void 0 : await
|
|
64
|
+
let U = k && C ? void 0 : await c(k, z, V, B);
|
|
60
65
|
if (D.log("reorderZkCallData"), C) {
|
|
61
66
|
if (!N) throw Error("Withdraw Action: No Token Found");
|
|
62
67
|
if (k) {
|
|
@@ -66,7 +71,7 @@ var x = async (e, t, n, r) => {
|
|
|
66
71
|
let e = await _(i, O, M[0], N, z, B, V);
|
|
67
72
|
return D.log("transactCallDirect", { txHash: e.hash }), D.log("done"), e;
|
|
68
73
|
}
|
|
69
|
-
let W = await v(O, z, V, B, H, void 0, void 0,
|
|
74
|
+
let W = await v(O, z, V, B, H, void 0, void 0, p(E, O, j, M, A), U);
|
|
70
75
|
return D.log("transactCallRelayer", { txHash: W }), D.log("done"), W;
|
|
71
76
|
};
|
|
72
77
|
//#endregion
|
|
@@ -1 +1 @@
|
|
|
1
|
-
const e=require(`../../constants/vite.constants.cjs`),t=require(`../crypto-keys/keys.cjs`),n=require(`../utxo/Utxo.cjs`),r=require(`../../webworker/worker.registry.cjs`),
|
|
1
|
+
const e=require(`../../constants/vite.constants.cjs`),t=require(`../crypto-keys/keys.cjs`),n=require(`../utxo/Utxo.cjs`),r=require(`../../functions/utils/hinkalTiming.utils.cjs`),i=require(`../../webworker/worker.registry.cjs`),a=require(`../../webworker/performTaskWithWorker.cjs`),o=require(`../../webworker/utxoWorker/utxoWorker.types.cjs`);var s=16,c=class{NUM_WORKERS;NUM_WORKERS_BATCH_PROCESS;constructor(){e.isNode?(this.NUM_WORKERS=1,this.NUM_WORKERS_BATCH_PROCESS=1):(this.NUM_WORKERS=3,this.NUM_WORKERS_BATCH_PROCESS=Math.min(s,Math.ceil(navigator.deviceMemory??4)))}async createUtxoPromise(e){return await a.performTaskWithWorker({type:i.WorkerVariant.UTXO,payload:e})}async batchFilterUtxosWithNullifier(e,i){let a=r.createHinkalTiming(`utxoUtils.batchFilter`),s=this.sliceArrayIntoParts(e,this.NUM_WORKERS);a.log(`start`,{utxoCount:e.length,workers:s.length});let c=s.map(e=>this.createUtxoPromise({type:o.UtxoWorkerActionType.BATCH_FILTER_UTXOS_WITH_NULLIFIER,data:{utxos:e.map(e=>e.getConstructableParams()),nullifiers:i}})),l=await Promise.all(c);return l.forEach(e=>{t.stealthPairCacheDevice.mergeWithSerialized(e.stealthPairCache),t.stealthAddressCacheDevice.mergeWithSerialized(e.stealthAddressCache)}),a.log(`done`),l.flatMap(e=>e.utxoConstructors).map(e=>new n.Utxo(e))}async buildBatchProcess(e,t,i){let a=r.createHinkalTiming(`utxoUtils.buildBatchProcess`),s=this.sliceArrayIntoParts(e,this.NUM_WORKERS);a.log(`start`,{encryptedOutputs:e.length,workers:s.length});let c=s.map(e=>this.createUtxoPromise({type:o.UtxoWorkerActionType.BUILD_UTXOS,data:{signature:t.getSignature(),encryptedOutputs:e,chainId:i}})),l=(await Promise.all(c)).flat().map(e=>new n.Utxo(e));return a.log(`done`,{utxoCount:l.length}),l}sliceArrayIntoParts(e,t){let n=Math.ceil(e.length/t);return Array.from({length:t},(t,r)=>e.slice(n*r,n*(r+1))).filter(e=>e.length>0)}findLastOutput(e,t){let n=t;return e.forEach(e=>{e!==t&&(n=e)}),n}async batchProcess(e,t,n,i){let a=r.createHinkalTiming(`utxoUtils.batchProcess`),s=this.sliceArrayIntoParts(e,this.NUM_WORKERS_BATCH_PROCESS);a.log(`start`,{encryptedOutputs:e.length,workers:s.length});let c=n.getSignature(),l=s.map(e=>{let n={type:o.UtxoWorkerActionType.DECIPHER_OUTPUTS,data:{encryptedOutputs:e,lastOutput:t,signature:c,chainId:i}};return this.createUtxoPromise(n)}),u=await Promise.all(l),d=u.map(({additionalEncryptedOutputs:e})=>e).flat(),f=new Set,p=d.reduce((e,t)=>f.has(t.value)?e:(f.add(t.value),[...e,t]),[]),m={additionalEncryptedOutputs:p,lastOutput:this.findLastOutput(u.map(e=>e.lastOutput),t)??t};return a.log(`done`,{additionalEncryptedOutputs:p.length}),m}};exports.MultiThreadedUtxoUtils=c;
|
|
@@ -1,44 +1,55 @@
|
|
|
1
1
|
import { isNode as e } from "../../constants/vite.constants.mjs";
|
|
2
2
|
import { stealthAddressCacheDevice as t, stealthPairCacheDevice as n } from "../crypto-keys/keys.mjs";
|
|
3
3
|
import { Utxo as r } from "../utxo/Utxo.mjs";
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
4
|
+
import { createHinkalTiming as i } from "../../functions/utils/hinkalTiming.utils.mjs";
|
|
5
|
+
import { WorkerVariant as a } from "../../webworker/worker.registry.mjs";
|
|
6
|
+
import { performTaskWithWorker as o } from "../../webworker/performTaskWithWorker.mjs";
|
|
7
|
+
import { UtxoWorkerActionType as s } from "../../webworker/utxoWorker/utxoWorker.types.mjs";
|
|
7
8
|
//#region libs/shared/common/src/data-structures/MultiThreadedUtxoUtils/MultiThreadedUtxoUtils.ts
|
|
8
|
-
var
|
|
9
|
+
var c = 16, l = class {
|
|
9
10
|
NUM_WORKERS;
|
|
10
11
|
NUM_WORKERS_BATCH_PROCESS;
|
|
11
12
|
constructor() {
|
|
12
|
-
e ? (this.NUM_WORKERS = 1, this.NUM_WORKERS_BATCH_PROCESS = 1) : (this.NUM_WORKERS = 3, this.NUM_WORKERS_BATCH_PROCESS = Math.min(
|
|
13
|
+
e ? (this.NUM_WORKERS = 1, this.NUM_WORKERS_BATCH_PROCESS = 1) : (this.NUM_WORKERS = 3, this.NUM_WORKERS_BATCH_PROCESS = Math.min(c, Math.ceil(navigator.deviceMemory ?? 4)));
|
|
13
14
|
}
|
|
14
15
|
async createUtxoPromise(e) {
|
|
15
|
-
return await
|
|
16
|
-
type:
|
|
16
|
+
return await o({
|
|
17
|
+
type: a.UTXO,
|
|
17
18
|
payload: e
|
|
18
19
|
});
|
|
19
20
|
}
|
|
20
|
-
async batchFilterUtxosWithNullifier(e,
|
|
21
|
-
let
|
|
22
|
-
|
|
21
|
+
async batchFilterUtxosWithNullifier(e, a) {
|
|
22
|
+
let o = i("utxoUtils.batchFilter"), c = this.sliceArrayIntoParts(e, this.NUM_WORKERS);
|
|
23
|
+
o.log("start", {
|
|
24
|
+
utxoCount: e.length,
|
|
25
|
+
workers: c.length
|
|
26
|
+
});
|
|
27
|
+
let l = c.map((e) => this.createUtxoPromise({
|
|
28
|
+
type: s.BATCH_FILTER_UTXOS_WITH_NULLIFIER,
|
|
23
29
|
data: {
|
|
24
30
|
utxos: e.map((e) => e.getConstructableParams()),
|
|
25
|
-
nullifiers:
|
|
31
|
+
nullifiers: a
|
|
26
32
|
}
|
|
27
|
-
})),
|
|
28
|
-
return
|
|
33
|
+
})), u = await Promise.all(l);
|
|
34
|
+
return u.forEach((e) => {
|
|
29
35
|
n.mergeWithSerialized(e.stealthPairCache), t.mergeWithSerialized(e.stealthAddressCache);
|
|
30
|
-
}),
|
|
36
|
+
}), o.log("done"), u.flatMap((e) => e.utxoConstructors).map((e) => new r(e));
|
|
31
37
|
}
|
|
32
38
|
async buildBatchProcess(e, t, n) {
|
|
33
|
-
let i = this.sliceArrayIntoParts(e, this.NUM_WORKERS)
|
|
34
|
-
|
|
39
|
+
let a = i("utxoUtils.buildBatchProcess"), o = this.sliceArrayIntoParts(e, this.NUM_WORKERS);
|
|
40
|
+
a.log("start", {
|
|
41
|
+
encryptedOutputs: e.length,
|
|
42
|
+
workers: o.length
|
|
43
|
+
});
|
|
44
|
+
let c = o.map((e) => this.createUtxoPromise({
|
|
45
|
+
type: s.BUILD_UTXOS,
|
|
35
46
|
data: {
|
|
36
47
|
signature: t.getSignature(),
|
|
37
48
|
encryptedOutputs: e,
|
|
38
49
|
chainId: n
|
|
39
50
|
}
|
|
40
|
-
}));
|
|
41
|
-
return
|
|
51
|
+
})), l = (await Promise.all(c)).flat().map((e) => new r(e));
|
|
52
|
+
return a.log("done", { utxoCount: l.length }), l;
|
|
42
53
|
}
|
|
43
54
|
sliceArrayIntoParts(e, t) {
|
|
44
55
|
let n = Math.ceil(e.length / t);
|
|
@@ -51,23 +62,28 @@ var s = 16, c = class {
|
|
|
51
62
|
}), n;
|
|
52
63
|
}
|
|
53
64
|
async batchProcess(e, t, n, r) {
|
|
54
|
-
let
|
|
65
|
+
let a = i("utxoUtils.batchProcess"), o = this.sliceArrayIntoParts(e, this.NUM_WORKERS_BATCH_PROCESS);
|
|
66
|
+
a.log("start", {
|
|
67
|
+
encryptedOutputs: e.length,
|
|
68
|
+
workers: o.length
|
|
69
|
+
});
|
|
70
|
+
let c = n.getSignature(), l = o.map((e) => {
|
|
55
71
|
let n = {
|
|
56
|
-
type:
|
|
72
|
+
type: s.DECIPHER_OUTPUTS,
|
|
57
73
|
data: {
|
|
58
74
|
encryptedOutputs: e,
|
|
59
75
|
lastOutput: t,
|
|
60
|
-
signature:
|
|
76
|
+
signature: c,
|
|
61
77
|
chainId: r
|
|
62
78
|
}
|
|
63
79
|
};
|
|
64
80
|
return this.createUtxoPromise(n);
|
|
65
|
-
}),
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
lastOutput: this.findLastOutput(c.map((e) => e.lastOutput), t) ?? t
|
|
81
|
+
}), u = await Promise.all(l), d = u.map(({ additionalEncryptedOutputs: e }) => e).flat(), f = /* @__PURE__ */ new Set(), p = d.reduce((e, t) => f.has(t.value) ? e : (f.add(t.value), [...e, t]), []), m = {
|
|
82
|
+
additionalEncryptedOutputs: p,
|
|
83
|
+
lastOutput: this.findLastOutput(u.map((e) => e.lastOutput), t) ?? t
|
|
69
84
|
};
|
|
85
|
+
return a.log("done", { additionalEncryptedOutputs: p.length }), m;
|
|
70
86
|
}
|
|
71
87
|
};
|
|
72
88
|
//#endregion
|
|
73
|
-
export {
|
|
89
|
+
export { l as MultiThreadedUtxoUtils };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
const e=require(`../../constants/chains.constants.cjs`),t=require(`../../data-structures/crypto-keys/keys.cjs`),n=require(`../utils/solanaMint.utils.cjs`),r=require(`../snarkjs/common.snarkjs.cjs`),
|
|
1
|
+
const e=require(`../../constants/chains.constants.cjs`),t=require(`../../data-structures/crypto-keys/keys.cjs`),n=require(`../utils/solanaMint.utils.cjs`),r=require(`../utils/hinkalTiming.utils.cjs`),i=require(`../snarkjs/common.snarkjs.cjs`),a=require(`../../webworker/worker.registry.cjs`),o=require(`../../webworker/performTaskWithWorker.cjs`),s=require(`../../webworker/zkProofWorker/zkProofWorker.types.cjs`);var c=async(c,l,u,d)=>{let f=r.createHinkalTiming(`buildCommitmentValidationData`);if(i.hasOnlyZeroAmounts(d))return;let p=e.isSolanaLike(c),m=d.map(e=>e.map(e=>e.amount.toString())),h=d.map(e=>e.map(e=>e.timeStamp)),g=d.map(e=>e.map(e=>i.getUtxoCircuitInRandomization(e))),_=d.map(e=>e.map(e=>e.getConstructableParams())),v=d.map(e=>e.map(e=>e.amount===0n?`0`:BigInt(e.getCommitment()).toString())),y=await o.performTaskWithWorker({type:a.WorkerVariant.ZKProof,payload:{type:s.ZKProofWorkerActionType.BUILD_IN_NULLIFIERS,data:{inputUtxosSerialized:_}}});f.log(`buildInNullifiers`);let b=l.getShieldedPrivateKey(),x=l.getSpendingKeyPair().pubSpendingBJJPoint,S=p?u.map(e=>{let{compressedAddress:t}=n.formatMintAddress(e);return BigInt(t).toString()}):u.map(e=>BigInt(e).toString());d.forEach((e,n)=>{e.forEach((e,r)=>{let i=e.getStealthAddress(),a=e.spendingPublicKey??x,o=e.isNewStyle&&e.H0?t.UserKeys.getStealthAddressNewStyle(e.H0,b,a):t.UserKeys.getStealthAddress(BigInt(e.randomization),b);if(BigInt(i).toString()!==BigInt(o).toString())throw Error(`Commitment validation stealth mismatch at tokenIdx=${n}, utxoIdx=${r}`)})}),f.log(`stealthValidation`);let C={nullifyingPrivateKey:b,spendingPublicKey:x,erc20TokenAddresses:S,inAmounts:m,inRandomizations:g,inH0Ax:d.map(e=>e.map(e=>i.getUtxoCircuitH0Coords(e)[0].toString())),inH0Ay:d.map(e=>e.map(e=>i.getUtxoCircuitH0Coords(e)[1].toString())),isNewStyle:d.map(e=>e.map(e=>!!e.isNewStyle)),inTimeStamps:h,inCommitments:v,inNullifiers:y};if(!(!u.length||!d[0]?.length))return{tokenAddresses:S,inAmounts:m,inTimeStamps:h,inRandomizations:g,inCommitments:v,inNullifiers:y,verifierName:`commitmentCalculator${u.length}x${d[0].length}`,commitmentInput:C}},l=(e,t)=>{if(!(!e||!t))return{tokenAddresses:e.tokenAddresses,inAmounts:e.inAmounts,inTimeStamps:e.inTimeStamps,inRandomizations:e.inRandomizations,inCommitments:e.inCommitments,inNullifiers:e.inNullifiers,proof:{a:t.zkCallData[0],b:t.zkCallData[1],c:t.zkCallData[2]}}};exports.buildCommitmentValidationData=c,exports.buildCommitmentValidationDataFromProof=l;
|
|
@@ -1,53 +1,57 @@
|
|
|
1
1
|
import { isSolanaLike as e } from "../../constants/chains.constants.mjs";
|
|
2
2
|
import { UserKeys as t } from "../../data-structures/crypto-keys/keys.mjs";
|
|
3
3
|
import { formatMintAddress as n } from "../utils/solanaMint.utils.mjs";
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
4
|
+
import { createHinkalTiming as r } from "../utils/hinkalTiming.utils.mjs";
|
|
5
|
+
import { getUtxoCircuitH0Coords as i, getUtxoCircuitInRandomization as a, hasOnlyZeroAmounts as o } from "../snarkjs/common.snarkjs.mjs";
|
|
6
|
+
import { WorkerVariant as s } from "../../webworker/worker.registry.mjs";
|
|
7
|
+
import { performTaskWithWorker as c } from "../../webworker/performTaskWithWorker.mjs";
|
|
8
|
+
import { ZKProofWorkerActionType as l } from "../../webworker/zkProofWorker/zkProofWorker.types.mjs";
|
|
8
9
|
//#region libs/shared/common/src/functions/pre-transaction/buildCommitmentValidationData.ts
|
|
9
|
-
var
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
10
|
+
var u = async (u, d, f, p) => {
|
|
11
|
+
let m = r("buildCommitmentValidationData");
|
|
12
|
+
if (o(p)) return;
|
|
13
|
+
let h = e(u), g = p.map((e) => e.map((e) => e.amount.toString())), _ = p.map((e) => e.map((e) => e.timeStamp)), v = p.map((e) => e.map((e) => a(e))), y = p.map((e) => e.map((e) => e.getConstructableParams())), b = p.map((e) => e.map((e) => e.amount === 0n ? "0" : BigInt(e.getCommitment()).toString())), x = await c({
|
|
14
|
+
type: s.ZKProof,
|
|
13
15
|
payload: {
|
|
14
|
-
type:
|
|
15
|
-
data: { inputUtxosSerialized:
|
|
16
|
+
type: l.BUILD_IN_NULLIFIERS,
|
|
17
|
+
data: { inputUtxosSerialized: y }
|
|
16
18
|
}
|
|
17
|
-
})
|
|
19
|
+
});
|
|
20
|
+
m.log("buildInNullifiers");
|
|
21
|
+
let S = d.getShieldedPrivateKey(), C = d.getSpendingKeyPair().pubSpendingBJJPoint, w = h ? f.map((e) => {
|
|
18
22
|
let { compressedAddress: t } = n(e);
|
|
19
23
|
return BigInt(t).toString();
|
|
20
|
-
}) :
|
|
21
|
-
|
|
24
|
+
}) : f.map((e) => BigInt(e).toString());
|
|
25
|
+
p.forEach((e, n) => {
|
|
22
26
|
e.forEach((e, r) => {
|
|
23
|
-
let i = e.getStealthAddress(), a = e.spendingPublicKey ??
|
|
27
|
+
let i = e.getStealthAddress(), a = e.spendingPublicKey ?? C, o = e.isNewStyle && e.H0 ? t.getStealthAddressNewStyle(e.H0, S, a) : t.getStealthAddress(BigInt(e.randomization), S);
|
|
24
28
|
if (BigInt(i).toString() !== BigInt(o).toString()) throw Error(`Commitment validation stealth mismatch at tokenIdx=${n}, utxoIdx=${r}`);
|
|
25
29
|
});
|
|
26
|
-
});
|
|
27
|
-
let
|
|
28
|
-
nullifyingPrivateKey:
|
|
29
|
-
spendingPublicKey:
|
|
30
|
-
erc20TokenAddresses:
|
|
31
|
-
inAmounts:
|
|
32
|
-
inRandomizations:
|
|
33
|
-
inH0Ax:
|
|
34
|
-
inH0Ay:
|
|
35
|
-
isNewStyle:
|
|
36
|
-
inTimeStamps:
|
|
37
|
-
inCommitments:
|
|
38
|
-
inNullifiers:
|
|
30
|
+
}), m.log("stealthValidation");
|
|
31
|
+
let T = {
|
|
32
|
+
nullifyingPrivateKey: S,
|
|
33
|
+
spendingPublicKey: C,
|
|
34
|
+
erc20TokenAddresses: w,
|
|
35
|
+
inAmounts: g,
|
|
36
|
+
inRandomizations: v,
|
|
37
|
+
inH0Ax: p.map((e) => e.map((e) => i(e)[0].toString())),
|
|
38
|
+
inH0Ay: p.map((e) => e.map((e) => i(e)[1].toString())),
|
|
39
|
+
isNewStyle: p.map((e) => e.map((e) => !!e.isNewStyle)),
|
|
40
|
+
inTimeStamps: _,
|
|
41
|
+
inCommitments: b,
|
|
42
|
+
inNullifiers: x
|
|
39
43
|
};
|
|
40
|
-
if (!(!
|
|
41
|
-
tokenAddresses:
|
|
42
|
-
inAmounts:
|
|
43
|
-
inTimeStamps:
|
|
44
|
-
inRandomizations:
|
|
45
|
-
inCommitments:
|
|
46
|
-
inNullifiers:
|
|
47
|
-
verifierName: `commitmentCalculator${
|
|
48
|
-
commitmentInput:
|
|
44
|
+
if (!(!f.length || !p[0]?.length)) return {
|
|
45
|
+
tokenAddresses: w,
|
|
46
|
+
inAmounts: g,
|
|
47
|
+
inTimeStamps: _,
|
|
48
|
+
inRandomizations: v,
|
|
49
|
+
inCommitments: b,
|
|
50
|
+
inNullifiers: x,
|
|
51
|
+
verifierName: `commitmentCalculator${f.length}x${p[0].length}`,
|
|
52
|
+
commitmentInput: T
|
|
49
53
|
};
|
|
50
|
-
},
|
|
54
|
+
}, d = (e, t) => {
|
|
51
55
|
if (!(!e || !t)) return {
|
|
52
56
|
tokenAddresses: e.tokenAddresses,
|
|
53
57
|
inAmounts: e.inAmounts,
|
|
@@ -63,4 +67,4 @@ var l = async (l, u, d, f) => {
|
|
|
63
67
|
};
|
|
64
68
|
};
|
|
65
69
|
//#endregion
|
|
66
|
-
export {
|
|
70
|
+
export { u as buildCommitmentValidationData, d as buildCommitmentValidationDataFromProof };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
const e=require(`../../constants/chains.constants.cjs`),t=require(`../../constants/protocol.constants.cjs`),
|
|
1
|
+
const e=require(`../../constants/chains.constants.cjs`),t=require(`../../constants/protocol.constants.cjs`),ee=require(`../../crypto/poseidon.cjs`),n=require(`../web3/etherFunctions.cjs`),r=require(`../../data-structures/crypto-keys/keys.cjs`),i=require(`../utils/time.utils.cjs`),a=require(`../../types/external-action.types.cjs`),o=require(`../utils/hinkalTiming.utils.cjs`),s=require(`../../error-handling/logger.cjs`),c=require(`../utils/bit.operations.cjs`),l=require(`./common.snarkjs.cjs`),u=require(`./signedMessageHash.cjs`),te=require(`./generateCircomData.cjs`),ne=require(`../../data-structures/AccountActions/AccountActions.cjs`),d=require(`./generateMainAndCommitmentZkProof.cjs`),f=require(`./getMerkleTreeSiblingsAndRootHashes.cjs`),p=require(`../private-wallet/emporium.helpers.cjs`);var m=async(m,h,g,_,v,y,b,x,S,C=t.zeroAddress,w=e.chainIds.localhost,T=h.map(()=>!1),E=void 0,D,O)=>{let k=o.createHinkalTiming(`constructZkProof`),A=l.getZkProofVerifierName(h,g),j=l.calcAmountChanges(h,g),M=h.map(e=>e[0].erc20TokenAddress),N=l.calcEncryptedOutputs(g),P=t.defaultSignatureData,F=_.getShieldedPrivateKey(),{pubSpendingBJJPoint:I}=_.getSpendingKeyPair(),L=l.calcStealthAddressStructure(r.UserKeys.findCorrectRandomization(n.randomBigInt(31),F),F,_.getSpendingKeyPair().pubSpendingBJJPoint),{inCommitmentSiblings:re,inCommitmentSiblingSides:ie,rootHashHinkal:R,inNullifiers:z}=await f.getDataFromWorkers(w,m,h.map(e=>e.map(e=>e.getConstructableParams())));k.log(`getDataFromWorkers`,{verifierName:A,chainId:w});let B=l.buildOutCommitments(g),V=n.randomBigInt(31),H=ee.poseidonFunction(V),U=BigInt(g.length>0?g[0][0].timeStamp:i.getCurrentTimeInSeconds()),W={rootHashHinkal:R,spendingPublicKey:I,nullifyingPrivateKey:F,erc20TokenAddresses:M,amountChanges:j,inAmounts:h.map(e=>e.map(e=>e.amount.toString())),inRandomizations:h.map(e=>e.map(e=>l.getUtxoCircuitInRandomization(e))),inH0Ax:h.map(e=>e.map(e=>l.getUtxoCircuitH0Coords(e)[0].toString())),inH0Ay:h.map(e=>e.map(e=>l.getUtxoCircuitH0Coords(e)[1].toString())),isNewStyle:h.map(e=>e.map(e=>!!e.isNewStyle)),inTimeStamps:h.map(e=>e.map(e=>e.timeStamp)),inNullifiers:z,inCommitmentSiblings:re,inCommitmentSiblingSides:ie,outAmounts:g.map(e=>e.map(e=>e.amount.toString())),outTimeStamp:U,outPublicKeys:g.map(e=>e.map(e=>e.getStealthAddress())),outCommitments:B,calldataHash:0n,messageSeed:V,H0Ax:c.takeOffHighestBit(L.extraRandomization),H0Ay:L.H0},G=l.calcPublicSignalCount(A,W.erc20TokenAddresses,W.amountChanges,W.inNullifiers,W.outCommitments),K=l.calcAmountChanges(h,g,!0),q=l.getSlippageValues(K);s.Logger.log({publicSignalCount:G});let J=Array.isArray(b)?b:[b],ae=e.getOnchainChainId(w),oe=O?ne.AccountActions.getSignerAddressFromPrivateKey(ae,O):void 0,Y=v===a.ExternalActionId.Emporium?await p.encodeEmporiumMetadata(w,y??t.zeroAddress,O,J,H,oe):await p.encodeEmporiumMetadata(w,t.zeroAddress,void 0,v===0n?[]:J,H,t.zeroAddress);k.log(`encodeEmporiumMetadata`,{externalActionId:v.toString()}),W.calldataHash=l.createCallDataHash(G,C,y,v,Y,N,E,q,T,S,P,D);let X=u.computeSignedMessageHashEvm({rootHashHinkal:R,erc20TokenAddresses:M,amountChanges:j,outTimeStamp:U,inNullifiers:z,outCommitments:B,calldataHash:W.calldataHash,message:H,outH1Ay:L.H1,H0Ax:W.H0Ax,H0Ay:L.H0}),{R8:Z,S:se}=_.signEddsa(X);W.eddsaSignature=[Z[0],Z[1],se],W.signedMessageHash=X;let Q=A.startsWith(`mainEVMCircuitMin0`),$={outTimeStamp:U,calldataHash:W.calldataHash,messageSeed:V},{zkCallData:ce,commitmentValidationData:le}=await d.generateMainAndCommitmentZkProof(w,_,M,h,A,Q?$:W,x);k.log(`generateMainAndCommitmentZkProof`,{verifierName:A,generateProofRemotely:x});let ue=te.generateCircomData(B,z,R,K,M,g,N,G,v,y,Y,C,W.calldataHash,L,T,E,Q?Number(U):void 0,q,S,P,D),de={tokenNumber:h.length,nullifierAmount:h.length>0?h[0].length:0,outputAmount:g.length>0?g[0].length:0};return k.log(`done`),{zkCallData:ce,circomData:ue,dimData:de,encryptedOutputs:N,commitmentValidationData:le}};exports.constructZkProof=m;
|
|
@@ -5,31 +5,31 @@ import { randomBigInt as r } from "../web3/etherFunctions.mjs";
|
|
|
5
5
|
import { UserKeys as i } from "../../data-structures/crypto-keys/keys.mjs";
|
|
6
6
|
import { getCurrentTimeInSeconds as ne } from "../utils/time.utils.mjs";
|
|
7
7
|
import { ExternalActionId as re } from "../../types/external-action.types.mjs";
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
14
|
-
import {
|
|
8
|
+
import { createHinkalTiming as ie } from "../utils/hinkalTiming.utils.mjs";
|
|
9
|
+
import { Logger as ae } from "../../error-handling/logger.mjs";
|
|
10
|
+
import { takeOffHighestBit as oe } from "../utils/bit.operations.mjs";
|
|
11
|
+
import { buildOutCommitments as se, calcAmountChanges as a, calcEncryptedOutputs as o, calcPublicSignalCount as s, calcStealthAddressStructure as c, createCallDataHash as l, getSlippageValues as ce, getUtxoCircuitH0Coords as u, getUtxoCircuitInRandomization as le, getZkProofVerifierName as ue } from "./common.snarkjs.mjs";
|
|
12
|
+
import { computeSignedMessageHashEvm as de } from "./signedMessageHash.mjs";
|
|
13
|
+
import { generateCircomData as fe } from "./generateCircomData.mjs";
|
|
14
|
+
import { AccountActions as pe } from "../../data-structures/AccountActions/AccountActions.mjs";
|
|
15
15
|
import { generateMainAndCommitmentZkProof as me } from "./generateMainAndCommitmentZkProof.mjs";
|
|
16
16
|
import { getDataFromWorkers as d } from "./getMerkleTreeSiblingsAndRootHashes.mjs";
|
|
17
17
|
import { encodeEmporiumMetadata as f } from "../private-wallet/emporium.helpers.mjs";
|
|
18
18
|
//#region libs/shared/common/src/functions/snarkjs/constructGeneralZkProof.ts
|
|
19
19
|
var p = async (p, m, h, g, _, v, y, b, x, S = n, C = e.localhost, w = m.map(() => !1), T = void 0, E, D) => {
|
|
20
|
-
let O =
|
|
20
|
+
let O = ie("constructZkProof"), k = ue(m, h), A = a(m, h), j = m.map((e) => e[0].erc20TokenAddress), M = o(h), N = ee, P = g.getShieldedPrivateKey(), { pubSpendingBJJPoint: F } = g.getSpendingKeyPair(), I = c(i.findCorrectRandomization(r(31), P), P, g.getSpendingKeyPair().pubSpendingBJJPoint), { inCommitmentSiblings: L, inCommitmentSiblingSides: R, rootHashHinkal: z, inNullifiers: B } = await d(C, p, m.map((e) => e.map((e) => e.getConstructableParams())));
|
|
21
21
|
O.log("getDataFromWorkers", {
|
|
22
22
|
verifierName: k,
|
|
23
23
|
chainId: C
|
|
24
24
|
});
|
|
25
|
-
let V =
|
|
25
|
+
let V = se(h), H = r(31), U = te(H), W = BigInt(h.length > 0 ? h[0][0].timeStamp : ne()), G = {
|
|
26
26
|
rootHashHinkal: z,
|
|
27
27
|
spendingPublicKey: F,
|
|
28
28
|
nullifyingPrivateKey: P,
|
|
29
29
|
erc20TokenAddresses: j,
|
|
30
30
|
amountChanges: A,
|
|
31
31
|
inAmounts: m.map((e) => e.map((e) => e.amount.toString())),
|
|
32
|
-
inRandomizations: m.map((e) => e.map((e) =>
|
|
32
|
+
inRandomizations: m.map((e) => e.map((e) => le(e))),
|
|
33
33
|
inH0Ax: m.map((e) => e.map((e) => u(e)[0].toString())),
|
|
34
34
|
inH0Ay: m.map((e) => e.map((e) => u(e)[1].toString())),
|
|
35
35
|
isNewStyle: m.map((e) => e.map((e) => !!e.isNewStyle)),
|
|
@@ -43,13 +43,13 @@ var p = async (p, m, h, g, _, v, y, b, x, S = n, C = e.localhost, w = m.map(() =
|
|
|
43
43
|
outCommitments: V,
|
|
44
44
|
calldataHash: 0n,
|
|
45
45
|
messageSeed: H,
|
|
46
|
-
H0Ax:
|
|
46
|
+
H0Ax: oe(I.extraRandomization),
|
|
47
47
|
H0Ay: I.H0
|
|
48
|
-
}, K =
|
|
49
|
-
|
|
50
|
-
let Y = Array.isArray(y) ? y : [y], he = t(C), ge = D ?
|
|
51
|
-
O.log("encodeEmporiumMetadata", { externalActionId: _.toString() }), G.calldataHash =
|
|
52
|
-
let Z =
|
|
48
|
+
}, K = s(k, G.erc20TokenAddresses, G.amountChanges, G.inNullifiers, G.outCommitments), q = a(m, h, !0), J = ce(q);
|
|
49
|
+
ae.log({ publicSignalCount: K });
|
|
50
|
+
let Y = Array.isArray(y) ? y : [y], he = t(C), ge = D ? pe.getSignerAddressFromPrivateKey(he, D) : void 0, X = _ === re.Emporium ? await f(C, v ?? n, D, Y, U, ge) : await f(C, n, void 0, _ === 0n ? [] : Y, U, n);
|
|
51
|
+
O.log("encodeEmporiumMetadata", { externalActionId: _.toString() }), G.calldataHash = l(K, S, v, _, X, M, T, J, w, x, N, E);
|
|
52
|
+
let Z = de({
|
|
53
53
|
rootHashHinkal: z,
|
|
54
54
|
erc20TokenAddresses: j,
|
|
55
55
|
amountChanges: A,
|
|
@@ -76,7 +76,7 @@ var p = async (p, m, h, g, _, v, y, b, x, S = n, C = e.localhost, w = m.map(() =
|
|
|
76
76
|
verifierName: k,
|
|
77
77
|
generateProofRemotely: b
|
|
78
78
|
});
|
|
79
|
-
let xe =
|
|
79
|
+
let xe = fe(V, B, z, q, j, h, M, K, _, v, X, S, G.calldataHash, I, w, T, $ ? Number(W) : void 0, J, x, N, E), Se = {
|
|
80
80
|
tokenNumber: m.length,
|
|
81
81
|
nullifierAmount: m.length > 0 ? m[0].length : 0,
|
|
82
82
|
outputAmount: h.length > 0 ? h[0].length : 0
|
|
@@ -1 +1 @@
|
|
|
1
|
-
const e=require(`../utils/customEnclaveFunctionsRegister.cjs`),t=require(
|
|
1
|
+
const e=require(`../utils/customEnclaveFunctionsRegister.cjs`),t=require(`../utils/hinkalTiming.utils.cjs`),n=require(`../../error-handling/logger.cjs`),r=require(`./getZKFiles.cjs`),i=require(`./generateZkProofEnclave.cjs`),a=require(`./generateZkProofSelf.cjs`);var o=async(o,s,c,l)=>{let u=t.createHinkalTiming(`generateZkProof`);if(u.log(`start`,{remotely:!!l,verifierNames:s}),l)try{let t=e.getCustomProofGenerator();if(t){let e=await t(c,s.map(e=>r.getWASMFile(e,o)),s.map(e=>r.getZKeyFile(e,o)));return u.log(`customProofGenerator`,{verifierNames:s}),e.map(({zkCallData:e,publicSignals:t})=>({zkCallData:e,publicSignals:t}))}let n=await i.generateZkProofEnclave(o,s,c);return u.log(`enclave`,{verifierNames:s}),n}catch(e){n.Logger.error(`enclave proof error`,e),u.log(`enclave-failed-fallback-self`)}let d=await Promise.all(s.map((e,t)=>a.generateZkProofSelf(o,e,c[t])));return u.log(`self`,{verifierNames:s}),d};exports.generateZkProof=o;
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { getCustomProofGenerator as e } from "../utils/customEnclaveFunctionsRegister.mjs";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
2
|
+
import { createHinkalTiming as t } from "../utils/hinkalTiming.utils.mjs";
|
|
3
|
+
import { Logger as n } from "../../error-handling/logger.mjs";
|
|
4
4
|
import { getWASMFile as r, getZKeyFile as i } from "./getZKFiles.mjs";
|
|
5
5
|
import { generateZkProofEnclave as a } from "./generateZkProofEnclave.mjs";
|
|
6
6
|
import { generateZkProofSelf as o } from "./generateZkProofSelf.mjs";
|
|
7
7
|
//#region libs/shared/common/src/functions/snarkjs/generateZkProof.ts
|
|
8
8
|
var s = async (s, c, l, u) => {
|
|
9
|
-
let d =
|
|
9
|
+
let d = t("generateZkProof");
|
|
10
10
|
if (d.log("start", {
|
|
11
11
|
remotely: !!u,
|
|
12
12
|
verifierNames: c
|
|
@@ -22,7 +22,7 @@ var s = async (s, c, l, u) => {
|
|
|
22
22
|
let n = await a(s, c, l);
|
|
23
23
|
return d.log("enclave", { verifierNames: c }), n;
|
|
24
24
|
} catch (e) {
|
|
25
|
-
|
|
25
|
+
n.error("enclave proof error", e), d.log("enclave-failed-fallback-self");
|
|
26
26
|
}
|
|
27
27
|
let f = await Promise.all(c.map((e, t) => o(s, e, l[t])));
|
|
28
28
|
return d.log("self", { verifierNames: c }), f;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
const e=require(
|
|
1
|
+
const e=require(`../utils/hinkalTiming.utils.cjs`),t=require(`../../webworker/worker.registry.cjs`),n=require(`../../webworker/performTaskWithWorker.cjs`),r=require(`./getZKFiles.cjs`),i=require(`../../webworker/snarkjsWorker/snarkjsWorker.types.cjs`);var a=async(a,o,s)=>{let c=e.createHinkalTiming(`generateZkProofSelf:${o}`),l=r.getWASMFile(o,a),u=r.getZKeyFile(o,a);c.log(`start`,{chainId:a,wasmFilePath:l});let{publicSignals:d,zkCallData:f}=await n.performTaskWithWorker({type:t.WorkerVariant.SnarkJS,payload:{type:i.SnarkJSWorkerActionType.FULL_PROVE,data:{input:s,chainId:a,wasmFilePath:l,zKeyFilePath:u}}});return c.log(`worker-done`),{zkCallData:f,publicSignals:d}};exports.generateZkProofSelf=a;
|
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { createHinkalTiming as e } from "../utils/hinkalTiming.utils.mjs";
|
|
2
|
+
import { WorkerVariant as t } from "../../webworker/worker.registry.mjs";
|
|
3
3
|
import { performTaskWithWorker as n } from "../../webworker/performTaskWithWorker.mjs";
|
|
4
4
|
import { getWASMFile as r, getZKeyFile as i } from "./getZKFiles.mjs";
|
|
5
5
|
import { SnarkJSWorkerActionType as a } from "../../webworker/snarkjsWorker/snarkjsWorker.types.mjs";
|
|
6
6
|
//#region libs/shared/common/src/functions/snarkjs/generateZkProofSelf.ts
|
|
7
7
|
var o = async (o, s, c) => {
|
|
8
|
-
let l =
|
|
8
|
+
let l = e(`generateZkProofSelf:${s}`), u = r(s, o), d = i(s, o);
|
|
9
9
|
l.log("start", {
|
|
10
10
|
chainId: o,
|
|
11
11
|
wasmFilePath: u
|
|
12
12
|
});
|
|
13
13
|
let { publicSignals: f, zkCallData: p } = await n({
|
|
14
|
-
type:
|
|
14
|
+
type: t.SnarkJS,
|
|
15
15
|
payload: {
|
|
16
16
|
type: a.FULL_PROVE,
|
|
17
17
|
data: {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
require(`../../../../../_virtual/_rolldown/runtime.cjs`);const e=require(`../../../constants/chains.constants.cjs`),t=require(`../../utils/caseInsensitive.utils.cjs`),n=require(`../../../data-structures/utxo/Utxo.cjs`),r=require(`../../utils/upToDateState.cjs`),i=require(`../../utils/cacheFunctions.cjs`),a=require(`../../utils/encodeTokenWithId.cjs`),o=require(`../../utils/solanaMint.utils.cjs`),s=require(`./getInputUtxosEnclave.cjs`),
|
|
1
|
+
require(`../../../../../_virtual/_rolldown/runtime.cjs`);const e=require(`../../../constants/chains.constants.cjs`),t=require(`../../utils/caseInsensitive.utils.cjs`),n=require(`../../../data-structures/utxo/Utxo.cjs`),r=require(`../../utils/upToDateState.cjs`),i=require(`../../utils/cacheFunctions.cjs`),a=require(`../../utils/encodeTokenWithId.cjs`),o=require(`../../utils/solanaMint.utils.cjs`),s=require(`../../utils/hinkalTiming.utils.cjs`),c=require(`./getInputUtxosEnclave.cjs`),l=require(`../../utils/addresses.cjs`),u=require(`../../../API/scheduled-transactions-calls.cjs`),d=require(`../../utils/tron.utils.cjs`);var f=new(require(`async-mutex`)).Mutex,p=async(e,t)=>{if(e.allowParallelBalanceLocalDecryption)return t();let n=s.createHinkalTiming(`utxoDecrypt.mutex`);return f.isLocked()&&n.log(`waiting`),f.runExclusive(async()=>{n.log(`acquired`);try{return await t()}finally{n.log(`released`)}})},m=async(e,t,n,a,o,c,l,u,d)=>p(e,async()=>{let f=s.createHinkalTiming(`utxoDecrypt.local`);d+=1;let p=c.slice(d);f.log(`batchProcess-start`,{outputsSlice:p.length,lastOutputIndex:d});let{lastOutput:m,additionalEncryptedOutputs:h}=await e.utxoUtils.batchProcess(p,u,t,n);f.log(`batchProcess-done`,{additionalEncryptedOutputs:h.length});let g=[...l,...h];await r.checkAddressNotUpdated(e,a),i.setHinkalCache({lastOutput:m,encryptedOutputs:g},e,n,o),f.log(`cache-write`);let _=await e.utxoUtils.buildBatchProcess(g,t,n);return f.log(`buildBatchProcess-done`,{utxoCount:_.length}),_}),h=async(e,t,n,r)=>{let{utxos:a,encryptedOutputs:o,lastOutput:s}=await c.getInputUtxosEnclave(e,n,t);return i.setHinkalCache({encryptedOutputs:o,lastOutput:s},e,n,r),a},g=async(e,t,n,r,i,a,o,s,c)=>{try{return await h(e,t,n,i)}catch{return m(e,t,n,r,i,a,o,s,c)}},_=e=>{if(Array.isArray(e))return e;if(e!==void 0)return[e]},v=async(e,t,n)=>await e.utxoUtils.batchFilterUtxosWithNullifier(t,n),y=(e,t,r,i,a,o,s,c)=>{for(e.sort((e,t)=>e.amount<=t.amount?1:-1);e.length<t||e.length>t&&e.length<6;)if(e.push(new n.Utxo({amount:0n,erc20TokenAddress:o,mintAddress:c,nullifyingKey:i,spendingPublicKey:a,isNewStyle:!0})),r)for(;e.length>6;)e.splice(e.length-1)},b=async({hinkal:e,chainId:t,passedShieldedPublicKey:n=void 0,ethAddress:a=void 0,resetCacheBefore:o=!1,allowRemoteDecryption:c=!1,useBlockedUtxos:l=!1})=>{let u=a??await e.getEthereumAddress(),d=n??e.userKeys.getShieldedPublicKey(),{userKeys:f}=e,p=e.encryptedOutputsByChain[t],h=e.nullifiersByChain[t],_=Array.from(p);o&&i.resetCache(e,t,d);let{encryptedOutputs:y,lastOutput:b}=i.getHinkalCache(e,t,d);await r.checkAddressNotUpdated(e,u);let x=b!==``,S=_.findIndex(e=>e.value===b),C=S>-1,w=!x&&S===-1,T=e.areMerkleTreeUpdatesDisabled(),E=!T&&(C||!c&&w),D=!T&&c&&w,O=!E&&!D,k=s.createHinkalTiming(`getInputUtxoAndBalance`);k.log(`branch`,{decryptLocally:E,decryptRemotely:D,useCache:O,hinkalOutputs:_.length,cachedEncryptedOutputs:y.length,lastOutputIndex:S});let A=[];E?(A=await m(e,f,t,u,d,_,y,b,S),k.log(`decryptLocally-done`,{utxoCount:A.length})):D?(A=await g(e,f,t,u,d,_,y,b,S),k.log(`decryptRemotely-done`,{utxoCount:A.length})):O&&(A=await e.utxoUtils.buildBatchProcess(y,f,t),k.log(`useCache-buildBatchProcess-done`,{utxoCount:A.length})),await r.checkAddressNotUpdated(e,u);let j=await v(e,A,h);return k.log(`filterSpentUtxos-done`,{inputUtxos:j.length}),{inputUtxos:l?j.filter(e=>e.isBlocked):j.filter(e=>!e.isBlocked)}},x=async({hinkal:t,chainId:n,passedShieldedPublicKey:r=void 0,ethAddress:i=void 0,resetCacheBefore:a=!1,allowRemoteDecryption:o=!1})=>{let s=i??await t.getEthereumAddressByChain(n),c=l.hashEthereumAddress(e.isTronLike(n)?d.addressToHexFormat(s):s),{inputUtxos:f}=await b({hinkal:t,chainId:n,passedShieldedPublicKey:r,ethAddress:s,resetCacheBefore:a,allowRemoteDecryption:o,useBlockedUtxos:!0});if(!f.length)return{inputUtxos:[]};let{indexes:p}=await u.getScheduledTransactionsNullifierIndexes({hashedEthereumAddress:c,nullifiers:f.map(e=>e.getNullifier())});return{inputUtxos:p.map(e=>f[e]).filter(e=>!!e)}},S=async({hinkal:n,tokenWithId:r,minInput:i=2,sliceIfMore6:s=!0,chainId:c,passedShieldedPrivateKey:l=void 0,passedShieldedPublicKey:u=void 0,ethAddress:d=void 0,resetCacheBefore:f=!1,ensuredTokensWithId:p,allowRemoteDecryption:m=!1,useBlockedUtxos:h=!1})=>{let g=l??n.userKeys.getShieldedPrivateKey(),v=n.userKeys.getSpendingKeyPair().pubSpendingBJJPoint,{inputUtxos:S}=h?await x({hinkal:n,chainId:c,ethAddress:d,passedShieldedPrivateKey:l,resetCacheBefore:f,allowRemoteDecryption:m}):await b({hinkal:n,tokenWithId:r,minInput:i,sliceIfMore6:s,chainId:c,passedShieldedPrivateKey:l,passedShieldedPublicKey:u,ethAddress:d,resetCacheBefore:f,allowRemoteDecryption:m}),C=_(r),w=new Map;S.forEach(e=>{let n=e.getTokenAddress(c);if(C&&!C.some(e=>t.caseInsensitiveEqual(e.erc20TokenAddress,n)))return;let r=a.encodeTokenWithId(c,{erc20TokenAddress:n,tokenId:0}),i=w.get(r)??[];w.set(r,[...i,e])}),p?.forEach(e=>{let t=a.encodeTokenWithId(c,{erc20TokenAddress:e.erc20TokenAddress,tokenId:0});w.set(t,w.get(t)??[])});for(let[t,n]of w){let r=t.split(`-`)[0],a=Number(t.split(`-`)[1]),l=e.isSolanaLike(c),u=l?r:void 0;y(n,i,s,g,v,l?o.formatMintAddress(r).compressedAddress.toLowerCase():r.toLowerCase(),a,u)}return w};exports.attemptGetInputUtxosRemotely=g,exports.getInputUtxoAndBalance=b,exports.getInputUtxoAndBalanceOfStuckUtxos=x,exports.getInputUtxoAndBalancePerToken=S,exports.getInputUtxosRemotely=h;
|
|
@@ -5,35 +5,57 @@ import { checkAddressNotUpdated as i } from "../../utils/upToDateState.mjs";
|
|
|
5
5
|
import { getHinkalCache as a, resetCache as o, setHinkalCache as s } from "../../utils/cacheFunctions.mjs";
|
|
6
6
|
import { encodeTokenWithId as c } from "../../utils/encodeTokenWithId.mjs";
|
|
7
7
|
import { formatMintAddress as l } from "../../utils/solanaMint.utils.mjs";
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
8
|
+
import { createHinkalTiming as u } from "../../utils/hinkalTiming.utils.mjs";
|
|
9
|
+
import { getInputUtxosEnclave as d } from "./getInputUtxosEnclave.mjs";
|
|
10
|
+
import { hashEthereumAddress as f } from "../../utils/addresses.mjs";
|
|
11
|
+
import { getScheduledTransactionsNullifierIndexes as p } from "../../../API/scheduled-transactions-calls.mjs";
|
|
12
|
+
import { addressToHexFormat as m } from "../../utils/tron.utils.mjs";
|
|
13
|
+
import { Mutex as h } from "async-mutex";
|
|
13
14
|
//#region libs/shared/common/src/functions/web3/events/getInputUtxoAndBalance.ts
|
|
14
|
-
var
|
|
15
|
-
|
|
16
|
-
let
|
|
17
|
-
return
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
}
|
|
22
|
-
|
|
15
|
+
var g = new h(), _ = async (e, t) => {
|
|
16
|
+
if (e.allowParallelBalanceLocalDecryption) return t();
|
|
17
|
+
let n = u("utxoDecrypt.mutex");
|
|
18
|
+
return g.isLocked() && n.log("waiting"), g.runExclusive(async () => {
|
|
19
|
+
n.log("acquired");
|
|
20
|
+
try {
|
|
21
|
+
return await t();
|
|
22
|
+
} finally {
|
|
23
|
+
n.log("released");
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
}, v = async (e, t, n, r, a, o, c, l, d) => _(e, async () => {
|
|
27
|
+
let f = u("utxoDecrypt.local");
|
|
28
|
+
d += 1;
|
|
29
|
+
let p = o.slice(d);
|
|
30
|
+
f.log("batchProcess-start", {
|
|
31
|
+
outputsSlice: p.length,
|
|
32
|
+
lastOutputIndex: d
|
|
33
|
+
});
|
|
34
|
+
let { lastOutput: m, additionalEncryptedOutputs: h } = await e.utxoUtils.batchProcess(p, l, t, n);
|
|
35
|
+
f.log("batchProcess-done", { additionalEncryptedOutputs: h.length });
|
|
36
|
+
let g = [...c, ...h];
|
|
37
|
+
await i(e, r), s({
|
|
38
|
+
lastOutput: m,
|
|
39
|
+
encryptedOutputs: g
|
|
40
|
+
}, e, n, a), f.log("cache-write");
|
|
41
|
+
let _ = await e.utxoUtils.buildBatchProcess(g, t, n);
|
|
42
|
+
return f.log("buildBatchProcess-done", { utxoCount: _.length }), _;
|
|
43
|
+
}), y = async (e, t, n, r) => {
|
|
44
|
+
let { utxos: i, encryptedOutputs: a, lastOutput: o } = await d(e, n, t);
|
|
23
45
|
return s({
|
|
24
46
|
encryptedOutputs: a,
|
|
25
47
|
lastOutput: o
|
|
26
48
|
}, e, n, r), i;
|
|
27
|
-
},
|
|
49
|
+
}, b = async (e, t, n, r, i, a, o, s, c) => {
|
|
28
50
|
try {
|
|
29
|
-
return await
|
|
51
|
+
return await y(e, t, n, i);
|
|
30
52
|
} catch {
|
|
31
|
-
return
|
|
53
|
+
return v(e, t, n, r, i, a, o, s, c);
|
|
32
54
|
}
|
|
33
|
-
},
|
|
55
|
+
}, x = (e) => {
|
|
34
56
|
if (Array.isArray(e)) return e;
|
|
35
57
|
if (e !== void 0) return [e];
|
|
36
|
-
},
|
|
58
|
+
}, S = async (e, t, n) => await e.utxoUtils.batchFilterUtxosWithNullifier(t, n), C = (e, t, n, i, a, o, s, c) => {
|
|
37
59
|
for (e.sort((e, t) => e.amount <= t.amount ? 1 : -1); e.length < t || e.length > t && e.length < 6;) if (e.push(new r({
|
|
38
60
|
amount: 0n,
|
|
39
61
|
erc20TokenAddress: o,
|
|
@@ -42,17 +64,26 @@ var h = new m(), g = async (e, t) => e.allowParallelBalanceLocalDecryption ? t()
|
|
|
42
64
|
spendingPublicKey: a,
|
|
43
65
|
isNewStyle: !0
|
|
44
66
|
})), n) for (; e.length > 6;) e.splice(e.length - 1);
|
|
45
|
-
},
|
|
46
|
-
let
|
|
47
|
-
s && o(e, t,
|
|
48
|
-
let { encryptedOutputs:
|
|
49
|
-
await i(e,
|
|
50
|
-
let
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
67
|
+
}, w = async ({ hinkal: e, chainId: t, passedShieldedPublicKey: n = void 0, ethAddress: r = void 0, resetCacheBefore: s = !1, allowRemoteDecryption: c = !1, useBlockedUtxos: l = !1 }) => {
|
|
68
|
+
let d = r ?? await e.getEthereumAddress(), f = n ?? e.userKeys.getShieldedPublicKey(), { userKeys: p } = e, m = e.encryptedOutputsByChain[t], h = e.nullifiersByChain[t], g = Array.from(m);
|
|
69
|
+
s && o(e, t, f);
|
|
70
|
+
let { encryptedOutputs: _, lastOutput: y } = a(e, t, f);
|
|
71
|
+
await i(e, d);
|
|
72
|
+
let x = y !== "", C = g.findIndex((e) => e.value === y), w = C > -1, T = !x && C === -1, E = e.areMerkleTreeUpdatesDisabled(), D = !E && (w || !c && T), O = !E && c && T, k = !D && !O, A = u("getInputUtxoAndBalance");
|
|
73
|
+
A.log("branch", {
|
|
74
|
+
decryptLocally: D,
|
|
75
|
+
decryptRemotely: O,
|
|
76
|
+
useCache: k,
|
|
77
|
+
hinkalOutputs: g.length,
|
|
78
|
+
cachedEncryptedOutputs: _.length,
|
|
79
|
+
lastOutputIndex: C
|
|
80
|
+
});
|
|
81
|
+
let j = [];
|
|
82
|
+
D ? (j = await v(e, p, t, d, f, g, _, y, C), A.log("decryptLocally-done", { utxoCount: j.length })) : O ? (j = await b(e, p, t, d, f, g, _, y, C), A.log("decryptRemotely-done", { utxoCount: j.length })) : k && (j = await e.utxoUtils.buildBatchProcess(_, p, t), A.log("useCache-buildBatchProcess-done", { utxoCount: j.length })), await i(e, d);
|
|
83
|
+
let M = await S(e, j, h);
|
|
84
|
+
return A.log("filterSpentUtxos-done", { inputUtxos: M.length }), { inputUtxos: l ? M.filter((e) => e.isBlocked) : M.filter((e) => !e.isBlocked) };
|
|
85
|
+
}, T = async ({ hinkal: e, chainId: n, passedShieldedPublicKey: r = void 0, ethAddress: i = void 0, resetCacheBefore: a = !1, allowRemoteDecryption: o = !1 }) => {
|
|
86
|
+
let s = i ?? await e.getEthereumAddressByChain(n), c = f(t(n) ? m(s) : s), { inputUtxos: l } = await w({
|
|
56
87
|
hinkal: e,
|
|
57
88
|
chainId: n,
|
|
58
89
|
passedShieldedPublicKey: r,
|
|
@@ -62,20 +93,20 @@ var h = new m(), g = async (e, t) => e.allowParallelBalanceLocalDecryption ? t()
|
|
|
62
93
|
useBlockedUtxos: !0
|
|
63
94
|
});
|
|
64
95
|
if (!l.length) return { inputUtxos: [] };
|
|
65
|
-
let { indexes: u } = await
|
|
96
|
+
let { indexes: u } = await p({
|
|
66
97
|
hashedEthereumAddress: c,
|
|
67
98
|
nullifiers: l.map((e) => e.getNullifier())
|
|
68
99
|
});
|
|
69
100
|
return { inputUtxos: u.map((e) => l[e]).filter((e) => !!e) };
|
|
70
|
-
},
|
|
71
|
-
let g = s ?? t.userKeys.getShieldedPrivateKey(), _ = t.userKeys.getSpendingKeyPair().pubSpendingBJJPoint, { inputUtxos: v } = h ? await
|
|
101
|
+
}, E = async ({ hinkal: t, tokenWithId: r, minInput: i = 2, sliceIfMore6: a = !0, chainId: o, passedShieldedPrivateKey: s = void 0, passedShieldedPublicKey: u = void 0, ethAddress: d = void 0, resetCacheBefore: f = !1, ensuredTokensWithId: p, allowRemoteDecryption: m = !1, useBlockedUtxos: h = !1 }) => {
|
|
102
|
+
let g = s ?? t.userKeys.getShieldedPrivateKey(), _ = t.userKeys.getSpendingKeyPair().pubSpendingBJJPoint, { inputUtxos: v } = h ? await T({
|
|
72
103
|
hinkal: t,
|
|
73
104
|
chainId: o,
|
|
74
105
|
ethAddress: d,
|
|
75
106
|
passedShieldedPrivateKey: s,
|
|
76
107
|
resetCacheBefore: f,
|
|
77
108
|
allowRemoteDecryption: m
|
|
78
|
-
}) : await
|
|
109
|
+
}) : await w({
|
|
79
110
|
hinkal: t,
|
|
80
111
|
tokenWithId: r,
|
|
81
112
|
minInput: i,
|
|
@@ -86,27 +117,27 @@ var h = new m(), g = async (e, t) => e.allowParallelBalanceLocalDecryption ? t()
|
|
|
86
117
|
ethAddress: d,
|
|
87
118
|
resetCacheBefore: f,
|
|
88
119
|
allowRemoteDecryption: m
|
|
89
|
-
}), y =
|
|
120
|
+
}), y = x(r), b = /* @__PURE__ */ new Map();
|
|
90
121
|
v.forEach((e) => {
|
|
91
122
|
let t = e.getTokenAddress(o);
|
|
92
123
|
if (y && !y.some((e) => n(e.erc20TokenAddress, t))) return;
|
|
93
124
|
let r = c(o, {
|
|
94
125
|
erc20TokenAddress: t,
|
|
95
126
|
tokenId: 0
|
|
96
|
-
}), i =
|
|
97
|
-
|
|
127
|
+
}), i = b.get(r) ?? [];
|
|
128
|
+
b.set(r, [...i, e]);
|
|
98
129
|
}), p?.forEach((e) => {
|
|
99
130
|
let t = c(o, {
|
|
100
131
|
erc20TokenAddress: e.erc20TokenAddress,
|
|
101
132
|
tokenId: 0
|
|
102
133
|
});
|
|
103
|
-
|
|
134
|
+
b.set(t, b.get(t) ?? []);
|
|
104
135
|
});
|
|
105
|
-
for (let [t, n] of
|
|
136
|
+
for (let [t, n] of b) {
|
|
106
137
|
let r = t.split("-")[0], s = Number(t.split("-")[1]), c = e(o), u = c ? r : void 0;
|
|
107
|
-
|
|
138
|
+
C(n, i, a, g, _, c ? l(r).compressedAddress.toLowerCase() : r.toLowerCase(), s, u);
|
|
108
139
|
}
|
|
109
|
-
return
|
|
140
|
+
return b;
|
|
110
141
|
};
|
|
111
142
|
//#endregion
|
|
112
|
-
export {
|
|
143
|
+
export { b as attemptGetInputUtxosRemotely, w as getInputUtxoAndBalance, T as getInputUtxoAndBalanceOfStuckUtxos, E as getInputUtxoAndBalancePerToken, y as getInputUtxosRemotely };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
require(`../../../../../_virtual/_rolldown/runtime.cjs`);const e=require(`../../../constants/chains.constants.cjs`),t=require(`../../../data-structures/crypto-keys/keys.cjs`),n=require(`../../../data-structures/utxo/Utxo.cjs`),r=require(`../../utils/encryptInputForEnclave.cjs`),i=require(`../../utils/solanaMint.utils.cjs`),a=require(`../../utils/customEnclaveFunctionsRegister.cjs`);let
|
|
1
|
+
require(`../../../../../_virtual/_rolldown/runtime.cjs`);const e=require(`../../../constants/chains.constants.cjs`),t=require(`../../../data-structures/crypto-keys/keys.cjs`),n=require(`../../../data-structures/utxo/Utxo.cjs`),r=require(`../../utils/encryptInputForEnclave.cjs`),i=require(`../../utils/solanaMint.utils.cjs`),a=require(`../../utils/customEnclaveFunctionsRegister.cjs`),o=require(`../../utils/hinkalTiming.utils.cjs`);let s=require(`ethers`),c=require(`@solana/web3.js`);var l=e=>{if(!e)return;let t=s.ethers.getBytes(e);if(t.length!==32)return;let n=new c.PublicKey(t),r=n.toBase58(),{compressedAddress:a}=i.formatMintAddress(n);return{mintBase58:r,compressedAddress:a}},u=async(e,t,n)=>{let{keyCiphertext:i,inputCiphertext:a}=await r.makeEnclaveHandshakeAndEncryptUint8Array(n);return e.getAPI().decryptUtxoEnclaveCall(t,i,a)},d=async(r,i,c)=>{let d=o.createHinkalTiming(`getInputUtxosEnclave`),f=c.getShieldedPrivateKey(),{privateKey:p,publicKey:m}=t.UserKeys.getEncryptionKeyPair(f),h=c.getSpendingKeyPair().pubSpendingBJJPoint,g=s.ethers.solidityPacked([`uint256`,`uint256`,`uint256`],[m,p,f]),_=s.ethers.getBytes(g),v=a.getCustomUtxoDecryptor(),{utxos:y,lastOutput:b,encryptedOutputs:x}=await(v?v(i,_):u(r,i,_));return d.log(`decrypt-call-done`,{utxoCount:y.length}),{utxos:y.map(t=>{let r=t;if(e.isSolanaLike(i)){let e=l(t.mintAddress);if(!e)throw Error(`Invalid mint address`);r={...r,erc20TokenAddress:e.compressedAddress,mintAddress:e.mintBase58}}return new n.Utxo({...r,amount:BigInt(r.amount),randomization:r.randomization?BigInt(r.randomization):void 0,nullifyingKey:f,spendingPublicKey:h,isNewStyle:r.isNewStyle,H0:r.H0?[BigInt(r.H0[0]),BigInt(r.H0[1])]:void 0})}),encryptedOutputs:x,lastOutput:b}};exports.getInputUtxosEnclave=d;
|
|
@@ -4,36 +4,37 @@ import { Utxo as n } from "../../../data-structures/utxo/Utxo.mjs";
|
|
|
4
4
|
import { makeEnclaveHandshakeAndEncryptUint8Array as r } from "../../utils/encryptInputForEnclave.mjs";
|
|
5
5
|
import { formatMintAddress as i } from "../../utils/solanaMint.utils.mjs";
|
|
6
6
|
import { getCustomUtxoDecryptor as a } from "../../utils/customEnclaveFunctionsRegister.mjs";
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
7
|
+
import { createHinkalTiming as o } from "../../utils/hinkalTiming.utils.mjs";
|
|
8
|
+
import { ethers as s } from "ethers";
|
|
9
|
+
import { PublicKey as c } from "@solana/web3.js";
|
|
9
10
|
//#region libs/shared/common/src/functions/web3/events/getInputUtxosEnclave.ts
|
|
10
|
-
var
|
|
11
|
+
var l = (e) => {
|
|
11
12
|
if (!e) return;
|
|
12
|
-
let t =
|
|
13
|
+
let t = s.getBytes(e);
|
|
13
14
|
if (t.length !== 32) return;
|
|
14
|
-
let n = new
|
|
15
|
+
let n = new c(t), r = n.toBase58(), { compressedAddress: a } = i(n);
|
|
15
16
|
return {
|
|
16
17
|
mintBase58: r,
|
|
17
18
|
compressedAddress: a
|
|
18
19
|
};
|
|
19
|
-
},
|
|
20
|
+
}, u = async (e, t, n) => {
|
|
20
21
|
let { keyCiphertext: i, inputCiphertext: a } = await r(n);
|
|
21
22
|
return e.getAPI().decryptUtxoEnclaveCall(t, i, a);
|
|
22
|
-
},
|
|
23
|
-
let
|
|
23
|
+
}, d = async (r, i, c) => {
|
|
24
|
+
let d = o("getInputUtxosEnclave"), f = c.getShieldedPrivateKey(), { privateKey: p, publicKey: m } = t.getEncryptionKeyPair(f), h = c.getSpendingKeyPair().pubSpendingBJJPoint, g = s.solidityPacked([
|
|
24
25
|
"uint256",
|
|
25
26
|
"uint256",
|
|
26
27
|
"uint256"
|
|
27
28
|
], [
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
]),
|
|
32
|
-
return {
|
|
33
|
-
utxos:
|
|
29
|
+
m,
|
|
30
|
+
p,
|
|
31
|
+
f
|
|
32
|
+
]), _ = s.getBytes(g), v = a(), { utxos: y, lastOutput: b, encryptedOutputs: x } = await (v ? v(i, _) : u(r, i, _));
|
|
33
|
+
return d.log("decrypt-call-done", { utxoCount: y.length }), {
|
|
34
|
+
utxos: y.map((t) => {
|
|
34
35
|
let r = t;
|
|
35
36
|
if (e(i)) {
|
|
36
|
-
let e =
|
|
37
|
+
let e = l(t.mintAddress);
|
|
37
38
|
if (!e) throw Error("Invalid mint address");
|
|
38
39
|
r = {
|
|
39
40
|
...r,
|
|
@@ -45,15 +46,15 @@ var c = (e) => {
|
|
|
45
46
|
...r,
|
|
46
47
|
amount: BigInt(r.amount),
|
|
47
48
|
randomization: r.randomization ? BigInt(r.randomization) : void 0,
|
|
48
|
-
nullifyingKey:
|
|
49
|
-
spendingPublicKey:
|
|
49
|
+
nullifyingKey: f,
|
|
50
|
+
spendingPublicKey: h,
|
|
50
51
|
isNewStyle: r.isNewStyle,
|
|
51
52
|
H0: r.H0 ? [BigInt(r.H0[0]), BigInt(r.H0[1])] : void 0
|
|
52
53
|
});
|
|
53
54
|
}),
|
|
54
|
-
encryptedOutputs:
|
|
55
|
-
lastOutput:
|
|
55
|
+
encryptedOutputs: x,
|
|
56
|
+
lastOutput: b
|
|
56
57
|
};
|
|
57
58
|
};
|
|
58
59
|
//#endregion
|
|
59
|
-
export {
|
|
60
|
+
export { d as getInputUtxosEnclave };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
require(`../../../../../_virtual/_rolldown/runtime.cjs`);const e=require(`../../../constants/vite.constants.cjs`),t=require(`../../../constants/chains.constants.cjs`),n=require(`../../utils/caseInsensitive.utils.cjs`),r=require(`../../../error-handling/error-codes.constants.cjs`),i=require(`../etherFunctions.cjs`),a=require(`../../../data-structures/utxo/Utxo.cjs`),o=require(`../../../error-handling/customErrors/ErrorWithAmount.cjs`);require(`../../../error-handling/customErrors/index.cjs`);const s=require(`../../utils/encodeTokenWithId.cjs`),c=require(`../../utils/solanaMint.utils.cjs`),l=require(`./getInputUtxoAndBalance.cjs`),
|
|
1
|
+
require(`../../../../../_virtual/_rolldown/runtime.cjs`);const e=require(`../../../constants/vite.constants.cjs`),t=require(`../../../constants/chains.constants.cjs`),n=require(`../../utils/caseInsensitive.utils.cjs`),r=require(`../../../error-handling/error-codes.constants.cjs`),i=require(`../etherFunctions.cjs`),a=require(`../../../data-structures/utxo/Utxo.cjs`),o=require(`../../../error-handling/customErrors/ErrorWithAmount.cjs`);require(`../../../error-handling/customErrors/index.cjs`);const s=require(`../../utils/encodeTokenWithId.cjs`),c=require(`../../utils/solanaMint.utils.cjs`),l=require(`../../utils/hinkalTiming.utils.cjs`),u=require(`./getInputUtxoAndBalance.cjs`),d=require(`../../../data-structures/TokenDBs/PrivateTokensDB.cjs`),f=require(`../../utils/map.utils.cjs`),p=require(`../../utils/mutexes.utils.cjs`),m=require(`../../utils/erc20tokenFunctions.cjs`);let h=require(`async-mutex`);var g=async(t,r,i,a,o,s=!1,c,l=!1,g=!1)=>f.getOrCreateMapValue(t.balanceFetchingMutexByChain,r,()=>new h.Mutex).runExclusive(async()=>p.getChainBalanceFetchingMutex(r).runShared(async()=>{let{inputUtxos:f}=g?await u.getInputUtxoAndBalanceOfStuckUtxos({hinkal:t,chainId:r,ethAddress:o,passedShieldedPrivateKey:i,resetCacheBefore:s,allowRemoteDecryption:c}):await u.getInputUtxoAndBalance({hinkal:t,sliceIfMore6:!1,chainId:r,passedShieldedPrivateKey:i,passedShieldedPublicKey:a,ethAddress:o,resetCacheBefore:s,allowRemoteDecryption:c});l&&e.isExtension&&await d.privateTokensDB.fetchAndUpdatePrivateTokens(f.map(e=>e.getTokenAddress(r)).filter(e=>e!==void 0),r,o);let p=(e.isExtension?await d.privateTokensDB.getPrivateTokens(r,o):await m.getErc20TokensForChainAPI(r)).map(e=>({token:e,balance:f.reduce((t,i)=>{let a=e.erc20TokenAddress;return n.caseInsensitiveEqual(a,i.getTokenAddress(r))?t+i.amount:t},0n),timestamp:f.filter(t=>n.caseInsensitiveEqual(t.getTokenAddress(r),e.erc20TokenAddress))[0]?.timeStamp,nfts:[]})),h=new Map;return p.forEach(e=>{h.set(e.token.erc20TokenAddress.toLowerCase(),e)}),h})),_=async(e,n,d,f,p=6,h=d.map(()=>0),g=!1,_=!1)=>{let v=l.createHinkalTiming(`addPaddingToUtxos`),{userKeys:y}=e,b=y.getSpendingKeyPair().pubSpendingBJJPoint,x=[],S=[];if(d.length===0)return[];if(g){for(let e=0;e<d.length;e+=1){let r=t.isSolanaLike(n),i=r?d[e]:void 0,o=r?c.formatMintAddress(d[e]).compressedAddress:d[e];x.push(Array.from({length:p},()=>new a.Utxo({amount:0n,erc20TokenAddress:o,mintAddress:i,nullifyingKey:y.getShieldedPrivateKey(),spendingPublicKey:b,isNewStyle:!0})))}return x}let C=await u.getInputUtxoAndBalancePerToken({hinkal:e,sliceIfMore6:!1,ensuredTokensWithId:d.map((e,t)=>({erc20TokenAddress:d[t],tokenId:h[t]})),allowRemoteDecryption:e.generateProofRemotely,useBlockedUtxos:_,chainId:n});v.log(`getInputUtxoAndBalancePerToken`);let w=0;for(let e=0;e<d.length;e+=1){let t=C.get(s.encodeTokenWithId(n,{erc20TokenAddress:d[e],tokenId:h[e]}))??[];if(!t)throw Error(`Missing utxos for token`);w=Math.max(t.length,w),S.push(t)}if(w===2)return S;for(let[e,s]of S.entries())if(s.length>p){let t=s.slice(0,p),a=t.reduce((e,t)=>e+t.amount,0n);if(f[e]<0n&&a<-f[e]){let t=await m.getErc20TokenFromAPI(n,d[e]);if(!t)throw Error(`Token not found`);let s=t.decimals===18?6:2,c=Number(i.getAmountWithPrecision(a,t,s));throw new o.ErrorWithAmount(c,`${r.DIRECTLY_SHOW_MESSAGE_ERROR_CODES.UTXO_LIMITATIONS}. Please try again with ${c} ${t.symbol}, including gas fees.`)}x.push(t)}else if(s.length<=p){let r=[...s],i=p-s.length;for(;i>0;){--i;let o=t.isSolanaLike(n),s=o?d[e]:void 0,l=o?c.formatMintAddress(d[e]).compressedAddress:d[e];r.push(new a.Utxo({amount:0n,erc20TokenAddress:l,mintAddress:s,nullifyingKey:y.getShieldedPrivateKey(),spendingPublicKey:b,isNewStyle:!0}))}x.push(r)}return v.log(`padding-done`,{tokenCount:x.length}),x};exports.addPaddingToUtxos=_,exports.getShieldedBalance=g;
|
|
@@ -8,22 +8,23 @@ import { ErrorWithAmount as o } from "../../../error-handling/customErrors/Error
|
|
|
8
8
|
import "../../../error-handling/customErrors/index.mjs";
|
|
9
9
|
import { encodeTokenWithId as s } from "../../utils/encodeTokenWithId.mjs";
|
|
10
10
|
import { formatMintAddress as c } from "../../utils/solanaMint.utils.mjs";
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
14
|
-
import {
|
|
15
|
-
import {
|
|
16
|
-
import {
|
|
11
|
+
import { createHinkalTiming as l } from "../../utils/hinkalTiming.utils.mjs";
|
|
12
|
+
import { getInputUtxoAndBalance as u, getInputUtxoAndBalanceOfStuckUtxos as d, getInputUtxoAndBalancePerToken as f } from "./getInputUtxoAndBalance.mjs";
|
|
13
|
+
import { privateTokensDB as p } from "../../../data-structures/TokenDBs/PrivateTokensDB.mjs";
|
|
14
|
+
import { getOrCreateMapValue as m } from "../../utils/map.utils.mjs";
|
|
15
|
+
import { getChainBalanceFetchingMutex as h } from "../../utils/mutexes.utils.mjs";
|
|
16
|
+
import { getErc20TokenFromAPI as g, getErc20TokensForChainAPI as _ } from "../../utils/erc20tokenFunctions.mjs";
|
|
17
|
+
import { Mutex as v } from "async-mutex";
|
|
17
18
|
//#region libs/shared/common/src/functions/web3/events/getShieldedBalance.ts
|
|
18
|
-
var
|
|
19
|
-
let { inputUtxos:
|
|
19
|
+
var y = async (t, r, i, a, o, s = !1, c, l = !1, f = !1) => m(t.balanceFetchingMutexByChain, r, () => new v()).runExclusive(async () => h(r).runShared(async () => {
|
|
20
|
+
let { inputUtxos: m } = f ? await d({
|
|
20
21
|
hinkal: t,
|
|
21
22
|
chainId: r,
|
|
22
23
|
ethAddress: o,
|
|
23
24
|
passedShieldedPrivateKey: i,
|
|
24
25
|
resetCacheBefore: s,
|
|
25
26
|
allowRemoteDecryption: c
|
|
26
|
-
}) : await
|
|
27
|
+
}) : await u({
|
|
27
28
|
hinkal: t,
|
|
28
29
|
sliceIfMore6: !1,
|
|
29
30
|
chainId: r,
|
|
@@ -33,82 +34,84 @@ var v = async (t, r, i, a, o, s = !1, c, d = !1, h = !1) => p(t.balanceFetchingM
|
|
|
33
34
|
resetCacheBefore: s,
|
|
34
35
|
allowRemoteDecryption: c
|
|
35
36
|
});
|
|
36
|
-
|
|
37
|
-
let
|
|
37
|
+
l && e && await p.fetchAndUpdatePrivateTokens(m.map((e) => e.getTokenAddress(r)).filter((e) => e !== void 0), r, o);
|
|
38
|
+
let h = (e ? await p.getPrivateTokens(r, o) : await _(r)).map((e) => ({
|
|
38
39
|
token: e,
|
|
39
|
-
balance:
|
|
40
|
+
balance: m.reduce((t, i) => {
|
|
40
41
|
let a = e.erc20TokenAddress;
|
|
41
42
|
return n(a, i.getTokenAddress(r)) ? t + i.amount : t;
|
|
42
43
|
}, 0n),
|
|
43
|
-
timestamp:
|
|
44
|
+
timestamp: m.filter((t) => n(t.getTokenAddress(r), e.erc20TokenAddress))[0]?.timeStamp,
|
|
44
45
|
nfts: []
|
|
45
|
-
})),
|
|
46
|
-
return
|
|
47
|
-
|
|
48
|
-
}),
|
|
49
|
-
})),
|
|
50
|
-
let { userKeys:
|
|
51
|
-
if (
|
|
52
|
-
if (
|
|
53
|
-
for (let e = 0; e <
|
|
54
|
-
let r = t(n), i = r ?
|
|
55
|
-
|
|
46
|
+
})), g = /* @__PURE__ */ new Map();
|
|
47
|
+
return h.forEach((e) => {
|
|
48
|
+
g.set(e.token.erc20TokenAddress.toLowerCase(), e);
|
|
49
|
+
}), g;
|
|
50
|
+
})), b = async (e, n, u, d, p = 6, m = u.map(() => 0), h = !1, _ = !1) => {
|
|
51
|
+
let v = l("addPaddingToUtxos"), { userKeys: y } = e, b = y.getSpendingKeyPair().pubSpendingBJJPoint, x = [], S = [];
|
|
52
|
+
if (u.length === 0) return [];
|
|
53
|
+
if (h) {
|
|
54
|
+
for (let e = 0; e < u.length; e += 1) {
|
|
55
|
+
let r = t(n), i = r ? u[e] : void 0, o = r ? c(u[e]).compressedAddress : u[e];
|
|
56
|
+
x.push(Array.from({ length: p }, () => new a({
|
|
56
57
|
amount: 0n,
|
|
57
58
|
erc20TokenAddress: o,
|
|
58
59
|
mintAddress: i,
|
|
59
|
-
nullifyingKey:
|
|
60
|
-
spendingPublicKey:
|
|
60
|
+
nullifyingKey: y.getShieldedPrivateKey(),
|
|
61
|
+
spendingPublicKey: b,
|
|
61
62
|
isNewStyle: !0
|
|
62
63
|
})));
|
|
63
64
|
}
|
|
64
|
-
return
|
|
65
|
+
return x;
|
|
65
66
|
}
|
|
66
|
-
let
|
|
67
|
+
let C = await f({
|
|
67
68
|
hinkal: e,
|
|
68
69
|
sliceIfMore6: !1,
|
|
69
|
-
ensuredTokensWithId:
|
|
70
|
-
erc20TokenAddress:
|
|
71
|
-
tokenId:
|
|
70
|
+
ensuredTokensWithId: u.map((e, t) => ({
|
|
71
|
+
erc20TokenAddress: u[t],
|
|
72
|
+
tokenId: m[t]
|
|
72
73
|
})),
|
|
73
74
|
allowRemoteDecryption: e.generateProofRemotely,
|
|
74
|
-
useBlockedUtxos:
|
|
75
|
+
useBlockedUtxos: _,
|
|
75
76
|
chainId: n
|
|
76
|
-
})
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
77
|
+
});
|
|
78
|
+
v.log("getInputUtxoAndBalancePerToken");
|
|
79
|
+
let w = 0;
|
|
80
|
+
for (let e = 0; e < u.length; e += 1) {
|
|
81
|
+
let t = C.get(s(n, {
|
|
82
|
+
erc20TokenAddress: u[e],
|
|
83
|
+
tokenId: m[e]
|
|
81
84
|
})) ?? [];
|
|
82
85
|
if (!t) throw Error("Missing utxos for token");
|
|
83
|
-
|
|
86
|
+
w = Math.max(t.length, w), S.push(t);
|
|
84
87
|
}
|
|
85
|
-
if (
|
|
86
|
-
for (let [e, s] of
|
|
87
|
-
let t = s.slice(0,
|
|
88
|
-
if (
|
|
89
|
-
let t = await
|
|
88
|
+
if (w === 2) return S;
|
|
89
|
+
for (let [e, s] of S.entries()) if (s.length > p) {
|
|
90
|
+
let t = s.slice(0, p), a = t.reduce((e, t) => e + t.amount, 0n);
|
|
91
|
+
if (d[e] < 0n && a < -d[e]) {
|
|
92
|
+
let t = await g(n, u[e]);
|
|
90
93
|
if (!t) throw Error("Token not found");
|
|
91
94
|
let s = t.decimals === 18 ? 6 : 2, c = Number(i(a, t, s));
|
|
92
95
|
throw new o(c, `${r.UTXO_LIMITATIONS}. Please try again with ${c} ${t.symbol}, including gas fees.`);
|
|
93
96
|
}
|
|
94
|
-
|
|
95
|
-
} else if (s.length <=
|
|
96
|
-
let r = [...s], i =
|
|
97
|
+
x.push(t);
|
|
98
|
+
} else if (s.length <= p) {
|
|
99
|
+
let r = [...s], i = p - s.length;
|
|
97
100
|
for (; i > 0;) {
|
|
98
101
|
--i;
|
|
99
|
-
let o = t(n), s = o ?
|
|
102
|
+
let o = t(n), s = o ? u[e] : void 0, l = o ? c(u[e]).compressedAddress : u[e];
|
|
100
103
|
r.push(new a({
|
|
101
104
|
amount: 0n,
|
|
102
|
-
erc20TokenAddress:
|
|
105
|
+
erc20TokenAddress: l,
|
|
103
106
|
mintAddress: s,
|
|
104
|
-
nullifyingKey:
|
|
105
|
-
spendingPublicKey:
|
|
107
|
+
nullifyingKey: y.getShieldedPrivateKey(),
|
|
108
|
+
spendingPublicKey: b,
|
|
106
109
|
isNewStyle: !0
|
|
107
110
|
}));
|
|
108
111
|
}
|
|
109
|
-
|
|
112
|
+
x.push(r);
|
|
110
113
|
}
|
|
111
|
-
return
|
|
114
|
+
return v.log("padding-done", { tokenCount: x.length }), x;
|
|
112
115
|
};
|
|
113
116
|
//#endregion
|
|
114
|
-
export {
|
|
117
|
+
export { b as addPaddingToUtxos, y as getShieldedBalance };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
const e=require(`../constants/vite.constants.cjs`),t=require(`../constants/chains.constants.cjs`),n=require(
|
|
1
|
+
const e=require(`../constants/vite.constants.cjs`),t=require(`../constants/chains.constants.cjs`),n=require(`../functions/utils/hinkalTiming.utils.cjs`),r=require(`./workerFactory.cjs`);var i=async i=>{let a=i.payload?.type??`unknown`,o=n.createHinkalTiming(`worker:${i.type}:${a}`),s=await r.WorkerFactory.getWebWorker(i.type);return o.log(`spawned`),new Promise((n,r)=>{let a={};if(typeof window<`u`&&window.location){let{origin:e,protocol:t,host:n,port:r,hostname:i,href:o}=window.location;a={origin:e,protocol:t,host:n,port:r,hostname:i,href:o}}s.onMessage(e=>{o.log(`completed`),n(e),s.terminate()}),s.onError(e=>{o.log(`error`),r(e),s.terminate()});let c={payload:i.payload,metadata:{hostLocation:a,constants:{chains:{chainIds:t.chainIds},isDevelopment:e.isDevelopment}}};s.postMessage(c)})};exports.performTaskWithWorker=i;
|
|
@@ -1,39 +1,39 @@
|
|
|
1
1
|
import { isDevelopment as e } from "../constants/vite.constants.mjs";
|
|
2
2
|
import { chainIds as t } from "../constants/chains.constants.mjs";
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
3
|
+
import { createHinkalTiming as n } from "../functions/utils/hinkalTiming.utils.mjs";
|
|
4
|
+
import { WorkerFactory as r } from "./workerFactory.mjs";
|
|
5
5
|
//#region libs/shared/common/src/webworker/performTaskWithWorker.ts
|
|
6
6
|
var i = async (i) => {
|
|
7
|
-
let a =
|
|
8
|
-
return
|
|
9
|
-
let
|
|
7
|
+
let a = i.payload?.type ?? "unknown", o = n(`worker:${i.type}:${a}`), s = await r.getWebWorker(i.type);
|
|
8
|
+
return o.log("spawned"), new Promise((n, r) => {
|
|
9
|
+
let a = {};
|
|
10
10
|
if (typeof window < "u" && window.location) {
|
|
11
|
-
let { origin: e, protocol: t, host: n, port: r, hostname: i, href:
|
|
12
|
-
|
|
11
|
+
let { origin: e, protocol: t, host: n, port: r, hostname: i, href: o } = window.location;
|
|
12
|
+
a = {
|
|
13
13
|
origin: e,
|
|
14
14
|
protocol: t,
|
|
15
15
|
host: n,
|
|
16
16
|
port: r,
|
|
17
17
|
hostname: i,
|
|
18
|
-
href:
|
|
18
|
+
href: o
|
|
19
19
|
};
|
|
20
20
|
}
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
}),
|
|
24
|
-
|
|
21
|
+
s.onMessage((e) => {
|
|
22
|
+
o.log("completed"), n(e), s.terminate();
|
|
23
|
+
}), s.onError((e) => {
|
|
24
|
+
o.log("error"), r(e), s.terminate();
|
|
25
25
|
});
|
|
26
26
|
let c = {
|
|
27
27
|
payload: i.payload,
|
|
28
28
|
metadata: {
|
|
29
|
-
hostLocation:
|
|
29
|
+
hostLocation: a,
|
|
30
30
|
constants: {
|
|
31
31
|
chains: { chainIds: t },
|
|
32
32
|
isDevelopment: e
|
|
33
33
|
}
|
|
34
34
|
}
|
|
35
35
|
};
|
|
36
|
-
|
|
36
|
+
s.postMessage(c);
|
|
37
37
|
});
|
|
38
38
|
};
|
|
39
39
|
//#endregion
|
|
@@ -14,8 +14,8 @@
|
|
|
14
14
|
var e = /* @__PURE__ */ ((r) => (r.ZKProof = "ZKProof", r.SnarkJS = "SnarkJS", r.UTXO = "UTXO", r))(e || {});
|
|
15
15
|
|
|
16
16
|
const n = async () => ({
|
|
17
|
-
[e.ZKProof]: await getWorkerURL(domain + '/0.3.
|
|
18
|
-
[e.SnarkJS]: await getWorkerURL(domain + '/0.3.
|
|
19
|
-
[e.UTXO]: await getWorkerURL(domain + '/0.3.
|
|
17
|
+
[e.ZKProof]: await getWorkerURL(domain + '/0.3.24/' + 'zkProofWorkerLauncher.js'),
|
|
18
|
+
[e.SnarkJS]: await getWorkerURL(domain + '/0.3.24/' + 'snarkjsWorkerLauncher.js'),
|
|
19
|
+
[e.UTXO]: await getWorkerURL(domain + '/0.3.24/' + 'utxoWorkerLauncher.js'),
|
|
20
20
|
});
|
|
21
21
|
exports.getWorkerViteURL = n;
|
|
@@ -14,8 +14,8 @@
|
|
|
14
14
|
var e = /* @__PURE__ */ ((r) => (r.ZKProof = "ZKProof", r.SnarkJS = "SnarkJS", r.UTXO = "UTXO", r))(e || {});
|
|
15
15
|
|
|
16
16
|
const n = async () => ({
|
|
17
|
-
[e.ZKProof]: await getWorkerURL(domain + '/0.3.
|
|
18
|
-
[e.SnarkJS]: await getWorkerURL(domain + '/0.3.
|
|
19
|
-
[e.UTXO]: await getWorkerURL(domain + '/0.3.
|
|
17
|
+
[e.ZKProof]: await getWorkerURL(domain + '/0.3.24/' + 'zkProofWorkerLauncher.js'),
|
|
18
|
+
[e.SnarkJS]: await getWorkerURL(domain + '/0.3.24/' + 'snarkjsWorkerLauncher.js'),
|
|
19
|
+
[e.UTXO]: await getWorkerURL(domain + '/0.3.24/' + 'utxoWorkerLauncher.js'),
|
|
20
20
|
});
|
|
21
21
|
export { n as getWorkerViteURL };
|
package/package.json
CHANGED
package/sdk/package.json.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var e={name:`@gurge/sdk`,version:`0.3.
|
|
1
|
+
var e={name:`@gurge/sdk`,version:`0.3.23`,homepage:`hinkal.io`,author:{name:`Hinkal Protocol`},keywords:[`blockchain`,`privacy`,`zero-knowledge`,`stealth addresses`],exports:{".":{types:`./index.d.ts`,"react-native":`./index.cjs`,import:`./index.mjs`,default:`./index.cjs`},"./providers/WagmiProviderAdapter":{types:`./providers/WagmiProviderAdapter.d.ts`,"react-native":`./providers/WagmiProviderAdapter.cjs`,import:`./providers/WagmiProviderAdapter.mjs`,default:`./providers/WagmiProviderAdapter.cjs`},"./providers/EthersProviderAdapter":{types:`./providers/EthersProviderAdapter.d.ts`,"react-native":`./providers/EthersProviderAdapter.cjs`,import:`./providers/EthersProviderAdapter.mjs`,default:`./providers/EthersProviderAdapter.cjs`},"./providers/TronProviderAdapter":{types:`./providers/TronProviderAdapter.d.ts`,"react-native":`./providers/TronProviderAdapter.cjs`,import:`./providers/TronProviderAdapter.mjs`,default:`./providers/TronProviderAdapter.cjs`},"./providers/SolanaProviderAdapter":{types:`./providers/SolanaProviderAdapter.d.ts`,"react-native":`./providers/SolanaProviderAdapter.cjs`,import:`./providers/SolanaProviderAdapter.mjs`,default:`./providers/SolanaProviderAdapter.cjs`},"./providers/prepareEthersHinkal":{types:`./providers/prepareEthersHinkal.d.ts`,"react-native":`./providers/prepareEthersHinkal.cjs`,import:`./providers/prepareEthersHinkal.mjs`,default:`./providers/prepareEthersHinkal.cjs`},"./providers/prepareWagmiHinkal":{types:`./providers/prepareWagmiHinkal.d.ts`,"react-native":`./providers/prepareWagmiHinkal.cjs`,import:`./providers/prepareWagmiHinkal.mjs`,default:`./providers/prepareWagmiHinkal.cjs`},"./providers/prepareTronHinkal":{types:`./providers/prepareTronHinkal.d.ts`,"react-native":`./providers/prepareTronHinkal.cjs`,import:`./providers/prepareTronHinkal.mjs`,default:`./providers/prepareTronHinkal.cjs`},"./providers/prepareSolanaHinkal":{types:`./providers/prepareSolanaHinkal.d.ts`,"react-native":`./providers/prepareSolanaHinkal.cjs`,import:`./providers/prepareSolanaHinkal.mjs`,default:`./providers/prepareSolanaHinkal.cjs`},"./react-native/HinkalWebViewWorker":{types:`./react-native/HinkalWebViewWorker.d.ts`,"react-native":`./react-native/HinkalWebViewWorker.cjs`,import:`./react-native/HinkalWebViewWorker.mjs`,default:`./react-native/HinkalWebViewWorker.cjs`},"./react-native/metro-config":`./react-native/metro-config.js`,"./react-native/shims/*":`./react-native/shims/*`},types:`./index.d.ts`,scripts:{prebuild:`nx prebuild:workers`,build:`nx build`,lint:`nx lint`,test:`nx test`},devDependencies:{nx:`22.6.4`,vite:`^8.0.4`,"vite-plugin-dts":`^4.5.4`,"vite-tsconfig-paths":`^6.1.1`},dependencies:{"@coral-xyz/anchor":`^0.31.0`,"@solana/spl-token":`^0.4.14`,"@solana/web3.js":`^1.98.4`,"@solana/wallet-adapter-react":`^0.15.39`,axios:`^1.15.0`,"async-mutex":`^0.4.0`,bs58:`^6.0.0`,buffer:`6.0.3`,"circomlibjs-hinkal-fork":`^0.0.10`,dotenv:`^16.4.5`,ethers:`^6.15.0`,"idb-keyval":`6.2.1`,multiformats:`^9.4.2`,snarkjs:`0.7.5`,"libsodium-wrappers":`^0.8.2`,lodash:`^4.17.21`,tweetnacl:`^1.0.3`,process:`0.11.10`,"ua-parser-js":`^1.0.37`,uuid:`^9.0.1`,"node-forge":`^1.3.1`,"poseidon-lite":`^0.3.0`,tronweb:`^6.2.0`},peerDependencies:{wagmi:`2.13.3`,"@walletconnect/utils":`^2.17.2`,react:`*`,"react-native":`*`,"react-native-webview":`*`},peerDependenciesMeta:{wagmi:{optional:!0},"@walletconnect/utils":{optional:!0},react:{optional:!0},"react-native":{optional:!0},"react-native-webview":{optional:!0}}};exports.default=e;
|