@hinkal/common 0.1.32 → 0.1.34
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/constants/deploy-data/deploy-data-localhost.json.cjs +1 -1
- package/constants/deploy-data/deploy-data-localhost.json.mjs +4 -4
- package/constants/fees.constants.cjs +1 -1
- package/constants/fees.constants.mjs +22 -22
- package/constants/token-data/localhostRegistry.json.cjs +1 -1
- package/constants/token-data/localhostRegistry.json.mjs +18 -44
- package/crypto/babyJub.cjs +1 -1
- package/crypto/babyJub.mjs +4 -4
- package/crypto/poseidon.cjs +1 -1
- package/crypto/poseidon.mjs +12 -12
- package/crypto/preProcessing.cjs +1 -1
- package/crypto/preProcessing.mjs +5 -7
- package/data-structures/Hinkal/Hinkal.cjs +1 -1
- package/data-structures/Hinkal/Hinkal.d.ts +1 -0
- package/data-structures/Hinkal/Hinkal.mjs +16 -16
- package/data-structures/Hinkal/IHinkal.d.ts +2 -1
- package/data-structures/Hinkal/hinkalActionBeefy.cjs +1 -1
- package/data-structures/Hinkal/hinkalActionBeefy.mjs +18 -20
- package/data-structures/Hinkal/hinkalActionConvex.cjs +1 -1
- package/data-structures/Hinkal/hinkalActionConvex.mjs +18 -21
- package/data-structures/Hinkal/hinkalActionLidoEth.cjs +1 -1
- package/data-structures/Hinkal/hinkalActionLidoEth.mjs +31 -31
- package/data-structures/Hinkal/hinkalActionPendle.cjs +1 -1
- package/data-structures/Hinkal/hinkalActionPendle.mjs +77 -80
- package/data-structures/Hinkal/hinkalActionPendleLP.cjs +1 -1
- package/data-structures/Hinkal/hinkalActionPendleLP.mjs +34 -34
- package/data-structures/Hinkal/hinkalActionStake.cjs +1 -1
- package/data-structures/Hinkal/hinkalActionStake.mjs +49 -53
- package/data-structures/Hinkal/hinkalActionVolatile.cjs +1 -1
- package/data-structures/Hinkal/hinkalActionVolatile.mjs +38 -44
- package/data-structures/Hinkal/hinkalDeposit.cjs +1 -1
- package/data-structures/Hinkal/hinkalDeposit.mjs +27 -28
- package/data-structures/Hinkal/hinkalPrivateWallet.cjs +1 -1
- package/data-structures/Hinkal/hinkalPrivateWallet.mjs +8 -11
- package/data-structures/crypto-keys/encryptDecryptUtxo.cjs +1 -1
- package/data-structures/crypto-keys/encryptDecryptUtxo.mjs +9 -8
- package/data-structures/crypto-keys/keys.cjs +1 -1
- package/data-structures/crypto-keys/keys.mjs +7 -6
- package/data-structures/event-service/AbstractAccessTokenSnapshotService.cjs +1 -1
- package/data-structures/event-service/AbstractAccessTokenSnapshotService.mjs +6 -9
- package/data-structures/event-service/AbstractCommitmentsSnapshotService.cjs +1 -4
- package/data-structures/event-service/AbstractCommitmentsSnapshotService.mjs +18 -26
- package/data-structures/snapshot/ClientAccessTokenSnapshotService.cjs +1 -1
- package/data-structures/snapshot/ClientAccessTokenSnapshotService.mjs +9 -12
- package/data-structures/snapshot/ClientCommitmentsSnapshotService.cjs +1 -1
- package/data-structures/snapshot/ClientCommitmentsSnapshotService.mjs +9 -12
- package/data-structures/snapshot/ClientNullifierSnapshotService.cjs +1 -1
- package/data-structures/snapshot/ClientNullifierSnapshotService.mjs +3 -6
- package/data-structures/transactions-manager/TransactionsManager.cjs +1 -1
- package/data-structures/transactions-manager/TransactionsManager.mjs +67 -75
- package/data-structures/transactions-manager/history/getVolatileData.cjs +1 -1
- package/data-structures/transactions-manager/history/getVolatileData.mjs +13 -13
- package/data-structures/volatile-helper/VolatileHelper.cjs +1 -1
- package/data-structures/volatile-helper/VolatileHelper.mjs +60 -60
- package/error-handling/error-codes.constants.cjs +1 -1
- package/error-handling/error-codes.constants.d.ts +2 -0
- package/error-handling/error-codes.constants.mjs +2 -0
- package/functions/pre-transaction/getFlatFees.cjs +1 -1
- package/functions/pre-transaction/getFlatFees.mjs +42 -42
- package/functions/pre-transaction/outputUtxoProcessing.cjs +1 -1
- package/functions/pre-transaction/outputUtxoProcessing.mjs +5 -8
- package/functions/pre-transaction/process-gas-estimates.cjs +1 -1
- package/functions/pre-transaction/process-gas-estimates.mjs +17 -26
- package/functions/pre-transaction/processAmountChanges.cjs +1 -1
- package/functions/pre-transaction/processAmountChanges.mjs +10 -13
- package/functions/protocols/pendle.helpers.cjs +1 -1
- package/functions/protocols/pendle.helpers.mjs +37 -39
- package/functions/snarkjs/constructGeneralZkProof.cjs +1 -1
- package/functions/snarkjs/constructGeneralZkProof.mjs +35 -37
- package/functions/staking/index.cjs +1 -1
- package/functions/staking/index.mjs +22 -24
- package/functions/utils/cacheFunctions.cjs +1 -1
- package/functions/utils/cacheFunctions.mjs +27 -30
- package/functions/utils/index.d.ts +1 -0
- package/functions/utils/process.utils.cjs +1 -1
- package/functions/utils/process.utils.mjs +16 -2
- package/functions/utils/resolve-sync.utils.cjs +1 -1
- package/functions/utils/resolve-sync.utils.d.ts +0 -1
- package/functions/utils/resolve-sync.utils.mjs +3 -12
- package/functions/web3/events/getShieldedBalance.cjs +2 -2
- package/functions/web3/events/getShieldedBalance.mjs +25 -25
- package/functions/web3/functionCalls/transactCallDirect.cjs +1 -1
- package/functions/web3/functionCalls/transactCallDirect.mjs +15 -15
- package/functions/web3/functionCalls/transactCallRelayer.cjs +1 -1
- package/functions/web3/functionCalls/transactCallRelayer.mjs +2 -2
- package/functions/web3/odosAPI.cjs +1 -1
- package/functions/web3/odosAPI.mjs +11 -14
- package/functions/web3/oneInchAPI.cjs +1 -1
- package/functions/web3/oneInchAPI.mjs +7 -10
- package/functions/web3/runContractFunction.cjs +1 -1
- package/functions/web3/runContractFunction.mjs +35 -38
- package/functions/web3/uniswapAPI.cjs +1 -1
- package/functions/web3/uniswapAPI.mjs +30 -33
- package/index.cjs +1 -1
- package/index.mjs +281 -277
- package/package.json +3 -5
- package/providers/prepareEthersHinkal.cjs +1 -1
- package/providers/prepareEthersHinkal.mjs +5 -4
- package/providers/prepareWagmiv1Hinkal.cjs +1 -1
- package/providers/prepareWagmiv1Hinkal.mjs +5 -4
- package/webworker/snarkjsWorker/snarkjsWorkerLauncher.cjs +1 -1
- package/webworker/snarkjsWorker/snarkjsWorkerLauncher.mjs +1 -1
- package/webworker/snarkjsWorker/snarkjsWorkerLogic.cjs +1 -1
- package/webworker/snarkjsWorker/snarkjsWorkerLogic.mjs +16 -17
- package/webworker/utxoWorker/utxoWorkerLauncher.cjs +1 -1
- package/webworker/utxoWorker/utxoWorkerLauncher.mjs +1 -1
- package/webworker/zkProofWorker/zkProofWorkerLauncher.cjs +1 -1
- package/webworker/zkProofWorker/zkProofWorkerLauncher.mjs +1 -1
|
@@ -1,122 +1,118 @@
|
|
|
1
|
-
import { ownerPublicKey as
|
|
2
|
-
import { encryptStake as T, createStakeCommitment as
|
|
3
|
-
import { getERC20Token as
|
|
4
|
-
import { randomBigInt as
|
|
5
|
-
import { outputUtxoProcessing as
|
|
6
|
-
import { constructZkProof as
|
|
7
|
-
import { addPaddingToUtxos as
|
|
8
|
-
import { Utxo as
|
|
1
|
+
import { ownerPublicKey as v, zeroAddress as h } from "../../constants/protocol.constants.mjs";
|
|
2
|
+
import { encryptStake as T, createStakeCommitment as B, encodeHStakeMetadata as O } from "../../functions/staking/index.mjs";
|
|
3
|
+
import { getERC20Token as b, getHToken as z } from "../../functions/utils/erc20tokenFunctions.mjs";
|
|
4
|
+
import { randomBigInt as j } from "../../functions/web3/etherFunctions.mjs";
|
|
5
|
+
import { outputUtxoProcessing as M } from "../../functions/pre-transaction/outputUtxoProcessing.mjs";
|
|
6
|
+
import { constructZkProof as N } from "../../functions/snarkjs/constructGeneralZkProof.mjs";
|
|
7
|
+
import { addPaddingToUtxos as Z } from "../../functions/web3/events/getShieldedBalance.mjs";
|
|
8
|
+
import { Utxo as u } from "../utxo/Utxo.mjs";
|
|
9
9
|
import "../../types/circom-data.types.mjs";
|
|
10
10
|
import { ContractType as k } from "../../types/ethereum-network.types.mjs";
|
|
11
|
-
import { ExternalActionId as
|
|
11
|
+
import { ExternalActionId as q } from "../../types/external-action.types.mjs";
|
|
12
12
|
import "../../types/transactions.types.mjs";
|
|
13
13
|
import "../../types/curve.types.mjs";
|
|
14
|
-
import { HinkalStakeMode as
|
|
14
|
+
import { HinkalStakeMode as y } from "../../types/hinkal.stake.types.mjs";
|
|
15
15
|
import "ethers";
|
|
16
|
-
import { UserKeys as
|
|
17
|
-
import "
|
|
16
|
+
import { UserKeys as G } from "../crypto-keys/keys.mjs";
|
|
17
|
+
import "../crypto-keys/encryptDecryptUtxo.mjs";
|
|
18
18
|
import { transactCallDirect as w } from "../../functions/web3/functionCalls/transactCallDirect.mjs";
|
|
19
|
-
const
|
|
20
|
-
const A = await t.getEthereumAddress(),
|
|
21
|
-
if (!
|
|
19
|
+
const pt = async (t, g, e, a, s) => {
|
|
20
|
+
const A = await t.getEthereumAddress(), c = b(g[0], t.getCurrentChainId());
|
|
21
|
+
if (!c)
|
|
22
22
|
throw Error("Deposit Action: No Token Found");
|
|
23
|
-
const m = a ===
|
|
24
|
-
|
|
25
|
-
const { erc20TokenAddress: E } = s, r = [
|
|
26
|
-
...await q(
|
|
23
|
+
const m = a === y.Stake, n = a === y.Unstake, { erc20TokenAddress: U } = c, r = [
|
|
24
|
+
...await Z(
|
|
27
25
|
t,
|
|
28
|
-
|
|
26
|
+
g,
|
|
29
27
|
e,
|
|
30
28
|
2,
|
|
31
29
|
void 0,
|
|
32
|
-
a !==
|
|
30
|
+
a !== y.Deposit
|
|
33
31
|
)
|
|
34
32
|
];
|
|
35
33
|
if (m || n) {
|
|
36
|
-
r[0][0] =
|
|
34
|
+
r[0][0] = u.createFrom(r[0][0], {
|
|
37
35
|
amount: e[0] * (m ? 1n : -1n),
|
|
38
36
|
isStakeOrUnstakeInput: !0
|
|
39
37
|
});
|
|
40
38
|
for (let o = 0; o < r.length; o += 1)
|
|
41
39
|
for (let i = 0; i < r[o].length; i += 1)
|
|
42
|
-
o === 0 && i === 0 || (r[o][i] =
|
|
40
|
+
o === 0 && i === 0 || (r[o][i] = u.createFrom(r[o][i], { amount: 0n }));
|
|
43
41
|
}
|
|
44
|
-
const { outputUtxos:
|
|
45
|
-
|
|
46
|
-
(o) =>
|
|
42
|
+
const { outputUtxos: E } = M(t.userKeys, r[0], e[0]), p = [
|
|
43
|
+
E.map(
|
|
44
|
+
(o) => u.createFrom(o, {
|
|
47
45
|
isStake: m,
|
|
48
46
|
isUnstakeOutput: n
|
|
49
47
|
})
|
|
50
48
|
)
|
|
51
49
|
];
|
|
52
|
-
n && (p[0][0] =
|
|
50
|
+
n && (p[0][0] = u.createFrom(p[0][0], {
|
|
53
51
|
amount: 0n,
|
|
54
52
|
isUnstakeOutput: n
|
|
55
53
|
}));
|
|
56
|
-
const
|
|
54
|
+
const K = [!1], d = j(30), H = G.getEncryptionKeyPair(t.userKeys.getShieldedPrivateKey()), I = T(d, s, v), P = T(d, s, H.publicKey), D = n ? 0n : B(
|
|
57
55
|
!0,
|
|
58
|
-
|
|
56
|
+
s,
|
|
59
57
|
d,
|
|
60
|
-
|
|
58
|
+
U,
|
|
61
59
|
e[0],
|
|
62
60
|
BigInt(p[0][0].timeStamp)
|
|
63
|
-
),
|
|
61
|
+
), F = O(
|
|
64
62
|
m ? 0 : 1,
|
|
65
|
-
|
|
63
|
+
D,
|
|
66
64
|
A,
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
), C = t.getContractWithSigner(k.HinkalWrapper2),
|
|
70
|
-
console.log("external action address", u.address);
|
|
71
|
-
const { zkCallData: S, dimData: x, circomData: l } = await Z(
|
|
65
|
+
I,
|
|
66
|
+
P
|
|
67
|
+
), C = t.getContractWithSigner(k.HinkalWrapper2), f = t.getContractWithSigner(k.HinkalStakeExternalAction), { zkCallData: S, dimData: l, circomData: x } = await N(
|
|
72
68
|
t.merkleTreeHinkal,
|
|
73
69
|
t.merkleTreeAccessToken,
|
|
74
70
|
r,
|
|
75
71
|
p,
|
|
76
72
|
t.userKeys,
|
|
77
73
|
"swapperME1x2x1",
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
74
|
+
q.HinkalStake,
|
|
75
|
+
f.address,
|
|
76
|
+
F,
|
|
77
|
+
h,
|
|
82
78
|
t.getCurrentChainId(),
|
|
83
|
-
|
|
79
|
+
K,
|
|
84
80
|
void 0,
|
|
85
81
|
void 0,
|
|
86
82
|
{
|
|
87
|
-
stakedTokenRecipient:
|
|
83
|
+
stakedTokenRecipient: s,
|
|
88
84
|
stakeBlinding: d,
|
|
89
85
|
mode: a,
|
|
90
86
|
depositorAddress: A
|
|
91
87
|
}
|
|
92
88
|
);
|
|
93
|
-
if (
|
|
94
|
-
const o = z(
|
|
89
|
+
if (n) {
|
|
90
|
+
const o = z(c, t.getCurrentChainId());
|
|
95
91
|
if (!o)
|
|
96
92
|
throw new Error("hToken not found");
|
|
97
|
-
const
|
|
93
|
+
const W = (await t.getContractWithFetcher(k.HToken, o.erc20TokenAddress).previewWithdraw(-e[0])).toBigInt();
|
|
98
94
|
return w(
|
|
99
95
|
t,
|
|
100
|
-
|
|
96
|
+
W,
|
|
101
97
|
o,
|
|
102
98
|
S,
|
|
103
|
-
l,
|
|
104
99
|
x,
|
|
105
|
-
|
|
100
|
+
l,
|
|
101
|
+
f,
|
|
106
102
|
C
|
|
107
103
|
);
|
|
108
104
|
}
|
|
109
105
|
return w(
|
|
110
106
|
t,
|
|
111
107
|
e[0],
|
|
112
|
-
|
|
108
|
+
c,
|
|
113
109
|
S,
|
|
114
|
-
l,
|
|
115
110
|
x,
|
|
116
|
-
|
|
111
|
+
l,
|
|
112
|
+
f,
|
|
117
113
|
C
|
|
118
114
|
);
|
|
119
115
|
};
|
|
120
116
|
export {
|
|
121
|
-
|
|
117
|
+
pt as hinkalActionStake
|
|
122
118
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const V=require("../../constants/protocol.constants.cjs"),
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const V=require("../../constants/protocol.constants.cjs"),m=require("../../functions/utils/erc20tokenFunctions.cjs"),P=require("../../functions/pre-transaction/getFlatFees.cjs"),U=require("../../functions/pre-transaction/outputUtxoProcessing.cjs"),H=require("../../functions/snarkjs/constructGeneralZkProof.cjs"),N=require("../../functions/web3/events/getShieldedBalance.cjs"),f=require("../../functions/web3/functionCalls/transactCallDirect.cjs"),W=require("../../functions/web3/functionCalls/transactCallRelayer.cjs"),b=require("../../functions/web3/functionCalls/estimateGasRelayer.cjs"),E=require("../volatile-helper/VolatileHelper.cjs"),n=require("../../types/hinkal.types.cjs"),q=require("../../types/ethereum-network.types.cjs"),M=require("../../types/external-action.types.cjs"),z=require("../../error-handling/error-codes.constants.cjs"),G=async(t,a,e,D,R)=>{const{action:r,isRelayerOff:i,recipientAddress:T,baseExternalActionId:I,baseExternalActionMetadata:S}=D,p=m.getERC20Token(a[0],t.getCurrentChainId());if(!p)throw Error("Deposit Action: No Token Found");const A=[...e],F=[...a];let g=[],y=e.map(()=>0n);({erc20Addresses:a,amountChanges:e,onChainCreation:g}=await E.VolatileHelper.processVolatileData(t.getCurrentChainId(),r,a,e));const c=await E.VolatileHelper.getVolatileExternalData(t,r,A,T,I,S);if(!c)throw Error("No External Action Data");(r===n.VolatileAction.Withdraw&&!i||r===n.VolatileAction.Swap)&&({flatFees:y}=await P.getFlatFees(t.getCurrentChainId(),F,M.ExternalActionId.Volatile,A,r),r===n.VolatileAction.Swap&&(e[1]=0n));const d=[...await N.addPaddingToUtxos(t,a,e)],_=`swapperM${e.length.toString()}x${d[0].length}x1`,w=[];for(let o=0;o<a.length;o+=1){const{outputUtxos:x}=U.outputUtxoProcessing(t.userKeys,d[o],e[o]);w.push(x)}const C=r===n.VolatileAction.Deposit||i?V.zeroAddress:await t.getRandomRelay();if(!i&&!C)throw Error(z.transactionErrorCodes.RELAYER_NOT_AVAILABLE);const{zkCallData:s,circomData:l,dimData:u}=await H.constructZkProof(t.merkleTreeHinkal,t.merkleTreeAccessToken,d,w,t.userKeys,_,c.externalActionId,c.externalAddress,c.externalActionMetadata,i?V.zeroAddress:C,t.getCurrentChainId(),g,y);if(r===n.VolatileAction.Deposit){const o=t.getContractWithSigner(q.ContractType.VolatileVault),x=t.getContractWithSigner(q.ContractType.HinkalWrapper);return await f.transactCallDirect(t,A[0],p,s,l,u,o,x)}return r===n.VolatileAction.Withdraw&&i?await f.transactCallDirect(t,e[0],p,s,l,u):R?await b.estimateGasRelayer(t,s,u,l):await W.transactCallRelayer(t.getCurrentChainId(),s,u,l)};exports.hinkalActionVolatile=G;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { zeroAddress as
|
|
2
|
-
import { getERC20Token as
|
|
1
|
+
import { zeroAddress as E } from "../../constants/protocol.constants.mjs";
|
|
2
|
+
import { getERC20Token as F } from "../../functions/utils/erc20tokenFunctions.mjs";
|
|
3
3
|
import { getFlatFees as N } from "../../functions/pre-transaction/getFlatFees.mjs";
|
|
4
4
|
import { outputUtxoProcessing as H } from "../../functions/pre-transaction/outputUtxoProcessing.mjs";
|
|
5
5
|
import { constructZkProof as L } from "../../functions/snarkjs/constructGeneralZkProof.mjs";
|
|
@@ -12,79 +12,73 @@ import { VolatileAction as i } from "../../types/hinkal.types.mjs";
|
|
|
12
12
|
import { ContractType as D } from "../../types/ethereum-network.types.mjs";
|
|
13
13
|
import { ExternalActionId as z } from "../../types/external-action.types.mjs";
|
|
14
14
|
import { transactionErrorCodes as K } from "../../error-handling/error-codes.constants.mjs";
|
|
15
|
-
const
|
|
16
|
-
const { action:
|
|
15
|
+
const rt = async (t, a, r, R, T) => {
|
|
16
|
+
const { action: o, isRelayerOff: n, recipientAddress: I, baseExternalActionId: V, baseExternalActionMetadata: S } = R, m = F(a[0], t.getCurrentChainId());
|
|
17
17
|
if (!m)
|
|
18
18
|
throw Error("Deposit Action: No Token Found");
|
|
19
|
-
const
|
|
20
|
-
let
|
|
21
|
-
({ erc20Addresses: a, amountChanges:
|
|
19
|
+
const f = [...r], U = [...a];
|
|
20
|
+
let w = [], A = r.map(() => 0n);
|
|
21
|
+
({ erc20Addresses: a, amountChanges: r, onChainCreation: w } = await C.processVolatileData(
|
|
22
22
|
t.getCurrentChainId(),
|
|
23
|
-
|
|
23
|
+
o,
|
|
24
24
|
a,
|
|
25
|
-
|
|
26
|
-
))
|
|
25
|
+
r
|
|
26
|
+
));
|
|
27
27
|
const c = await C.getVolatileExternalData(
|
|
28
28
|
t,
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
V,
|
|
29
|
+
o,
|
|
30
|
+
f,
|
|
32
31
|
I,
|
|
33
|
-
|
|
32
|
+
V,
|
|
33
|
+
S
|
|
34
34
|
);
|
|
35
35
|
if (!c)
|
|
36
36
|
throw Error("No External Action Data");
|
|
37
|
-
(
|
|
37
|
+
(o === i.Withdraw && !n || o === i.Swap) && ({ flatFees: A } = await N(
|
|
38
38
|
t.getCurrentChainId(),
|
|
39
|
-
|
|
39
|
+
U,
|
|
40
40
|
z.Volatile,
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
),
|
|
44
|
-
|
|
45
|
-
erc20Addresses: a,
|
|
46
|
-
amountChanges: o,
|
|
47
|
-
originalAmountChanges: l,
|
|
48
|
-
externalActionData: c
|
|
49
|
-
}));
|
|
50
|
-
const g = [...await M(t, a, o)], U = `swapperM${o.length.toString()}x${g[0].length}x1`, d = [];
|
|
41
|
+
f,
|
|
42
|
+
o
|
|
43
|
+
), o === i.Swap && (r[1] = 0n));
|
|
44
|
+
const x = [...await M(t, a, r)], W = `swapperM${r.length.toString()}x${x[0].length}x1`, g = [];
|
|
51
45
|
for (let e = 0; e < a.length; e += 1) {
|
|
52
|
-
const { outputUtxos:
|
|
53
|
-
|
|
46
|
+
const { outputUtxos: d } = H(t.userKeys, x[e], r[e]);
|
|
47
|
+
g.push(d);
|
|
54
48
|
}
|
|
55
|
-
const
|
|
56
|
-
if (!n && !
|
|
49
|
+
const u = o === i.Deposit || n ? E : await t.getRandomRelay();
|
|
50
|
+
if (!n && !u)
|
|
57
51
|
throw Error(K.RELAYER_NOT_AVAILABLE);
|
|
58
|
-
const { zkCallData: s, circomData: p, dimData:
|
|
52
|
+
const { zkCallData: s, circomData: p, dimData: l } = await L(
|
|
59
53
|
t.merkleTreeHinkal,
|
|
60
54
|
t.merkleTreeAccessToken,
|
|
55
|
+
x,
|
|
61
56
|
g,
|
|
62
|
-
d,
|
|
63
57
|
t.userKeys,
|
|
64
|
-
|
|
58
|
+
W,
|
|
65
59
|
c.externalActionId,
|
|
66
60
|
c.externalAddress,
|
|
67
61
|
c.externalActionMetadata,
|
|
68
|
-
n ?
|
|
62
|
+
n ? E : u,
|
|
69
63
|
t.getCurrentChainId(),
|
|
70
|
-
|
|
71
|
-
|
|
64
|
+
w,
|
|
65
|
+
A
|
|
72
66
|
);
|
|
73
|
-
if (
|
|
74
|
-
const e = t.getContractWithSigner(D.VolatileVault),
|
|
75
|
-
return
|
|
67
|
+
if (o === i.Deposit) {
|
|
68
|
+
const e = t.getContractWithSigner(D.VolatileVault), d = t.getContractWithSigner(D.HinkalWrapper);
|
|
69
|
+
return await y(
|
|
76
70
|
t,
|
|
77
|
-
|
|
71
|
+
f[0],
|
|
78
72
|
m,
|
|
79
73
|
s,
|
|
80
74
|
p,
|
|
81
|
-
|
|
75
|
+
l,
|
|
82
76
|
e,
|
|
83
|
-
|
|
77
|
+
d
|
|
84
78
|
);
|
|
85
79
|
}
|
|
86
|
-
return
|
|
80
|
+
return o === i.Withdraw && n ? await y(t, r[0], m, s, p, l) : T ? await b(t, s, l, p) : await P(t.getCurrentChainId(), s, l, p);
|
|
87
81
|
};
|
|
88
82
|
export {
|
|
89
|
-
|
|
83
|
+
rt as hinkalActionVolatile
|
|
90
84
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const T=require("../../constants/protocol.constants.cjs"),C=require("../../functions/utils/erc20tokenFunctions.cjs"),
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const T=require("../../constants/protocol.constants.cjs"),C=require("../../functions/utils/erc20tokenFunctions.cjs"),I=require("../../functions/pre-transaction/outputUtxoProcessing.cjs"),D=require("../../functions/snarkjs/constructGeneralZkProof.cjs"),f=require("../../functions/web3/events/getShieldedBalance.cjs"),h=require("../../functions/web3/functionCalls/transactCallDirect.cjs"),y=require("../utxo/Utxo.cjs"),k=require("../../error-handling/error-codes.constants.cjs"),q=async(t,n,r)=>{const a=C.getERC20Token(n[0],t.getCurrentChainId());if(!a)throw Error("Deposit Action: No Token Found");const c=r[0],e={externalActionId:0n,externalAddress:await t.getEthereumAddress(),externalActionMetadata:"0x00"},o=[...await f.addPaddingToUtxos(t,n,r)],d=`swapperM${r.length.toString()}x${o[0].length}x1`,i=[];for(let s=0;s<n.length;s+=1){const{outputUtxos:p}=I.outputUtxoProcessing(t.userKeys,o[s],r[s]);i.push(p)}const{zkCallData:l,circomData:x,dimData:g}=await D.constructZkProof(t.merkleTreeHinkal,t.merkleTreeAccessToken,o,i,t.userKeys,d,e.externalActionId,e.externalAddress,e.externalActionMetadata,T.zeroAddress,t.getCurrentChainId());return await h.transactCallDirect(t,c,a,l,x,g)},S=async(t,n,r,a)=>{const[c,e,o]=a.split(","),d=!c||!e||!o,i=e?.substring(0,2)!=="0x"||o?.substring(0,2)!=="0x",l=o?.length!==66||e?.length>66||e?.length<64,x=a?.includes('"');if(d||i||l||x)throw Error(k.transactionErrorCodes.RECIPIENT_FORMAT_INCORRECT);const g=[BigInt(c)],A=[e],s=n.map(u=>[new y.Utxo({amount:0n,erc20TokenAddress:u,shieldedPrivateKey:t.userKeys.getShieldedPrivateKey()}),new y.Utxo({amount:0n,erc20TokenAddress:u,shieldedPrivateKey:t.userKeys.getShieldedPrivateKey()})]),p=`swapperM${r.length.toString()}x${s[0].length}x1`,P=n.map((u,m)=>[new y.Utxo({amount:r[m],erc20TokenAddress:u,randomization:g[m],stealthAddress:A[m],encryptionKey:o})]),{zkCallData:U,circomData:E,dimData:K}=await D.constructZkProof(t.merkleTreeHinkal,t.merkleTreeAccessToken,s,P,t.userKeys,p,0n,await t.getEthereumAddress(),"0x00",T.zeroAddress,t.getCurrentChainId()),w=C.getERC20Token(n[0],t.getCurrentChainId());if(!w)throw Error("Withdraw Action: No Token Found");return await h.transactCallDirect(t,r[0],w,U,E,K)};exports.hinkalDeposit=q;exports.hinkalDepositForOther=S;
|
|
@@ -1,53 +1,52 @@
|
|
|
1
|
-
import { zeroAddress as
|
|
2
|
-
import { getERC20Token as
|
|
1
|
+
import { zeroAddress as T } from "../../constants/protocol.constants.mjs";
|
|
2
|
+
import { getERC20Token as f } from "../../functions/utils/erc20tokenFunctions.mjs";
|
|
3
3
|
import { outputUtxoProcessing as P } from "../../functions/pre-transaction/outputUtxoProcessing.mjs";
|
|
4
4
|
import { constructZkProof as C } from "../../functions/snarkjs/constructGeneralZkProof.mjs";
|
|
5
5
|
import { addPaddingToUtxos as U } from "../../functions/web3/events/getShieldedBalance.mjs";
|
|
6
6
|
import { transactCallDirect as D } from "../../functions/web3/functionCalls/transactCallDirect.mjs";
|
|
7
7
|
import { Utxo as A } from "../utxo/Utxo.mjs";
|
|
8
8
|
import { transactionErrorCodes as z } from "../../error-handling/error-codes.constants.mjs";
|
|
9
|
-
const k = async (t, n,
|
|
10
|
-
const a =
|
|
9
|
+
const k = async (t, n, r) => {
|
|
10
|
+
const a = f(n[0], t.getCurrentChainId());
|
|
11
11
|
if (!a)
|
|
12
12
|
throw Error("Deposit Action: No Token Found");
|
|
13
|
-
const i =
|
|
13
|
+
const i = r[0], e = {
|
|
14
14
|
externalActionId: 0n,
|
|
15
15
|
externalAddress: await t.getEthereumAddress(),
|
|
16
16
|
externalActionMetadata: "0x00"
|
|
17
|
-
},
|
|
17
|
+
}, o = [...await U(t, n, r)], m = `swapperM${r.length.toString()}x${o[0].length}x1`, c = [];
|
|
18
18
|
for (let s = 0; s < n.length; s += 1) {
|
|
19
|
-
const { outputUtxos:
|
|
20
|
-
c.push(
|
|
19
|
+
const { outputUtxos: l } = P(t.userKeys, o[s], r[s]);
|
|
20
|
+
c.push(l);
|
|
21
21
|
}
|
|
22
|
-
const { zkCallData: u, circomData:
|
|
22
|
+
const { zkCallData: u, circomData: p, dimData: x } = await C(
|
|
23
23
|
t.merkleTreeHinkal,
|
|
24
24
|
t.merkleTreeAccessToken,
|
|
25
|
-
|
|
25
|
+
o,
|
|
26
26
|
c,
|
|
27
27
|
t.userKeys,
|
|
28
28
|
m,
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
29
|
+
e.externalActionId,
|
|
30
|
+
e.externalAddress,
|
|
31
|
+
e.externalActionMetadata,
|
|
32
|
+
T,
|
|
33
33
|
t.getCurrentChainId()
|
|
34
34
|
);
|
|
35
|
-
return
|
|
36
|
-
}, H = async (t, n,
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
if (m || c || u || l)
|
|
35
|
+
return await D(t, i, a, u, p, x);
|
|
36
|
+
}, H = async (t, n, r, a) => {
|
|
37
|
+
const [i, e, o] = a.split(","), m = !i || !e || !o, c = e?.substring(0, 2) !== "0x" || o?.substring(0, 2) !== "0x", u = o?.length !== 66 || e?.length > 66 || e?.length < 64, p = a?.includes('"');
|
|
38
|
+
if (m || c || u || p)
|
|
40
39
|
throw Error(z.RECIPIENT_FORMAT_INCORRECT);
|
|
41
|
-
const
|
|
40
|
+
const x = [BigInt(i)], y = [e], s = n.map((d) => [
|
|
42
41
|
new A({ amount: 0n, erc20TokenAddress: d, shieldedPrivateKey: t.userKeys.getShieldedPrivateKey() }),
|
|
43
42
|
new A({ amount: 0n, erc20TokenAddress: d, shieldedPrivateKey: t.userKeys.getShieldedPrivateKey() })
|
|
44
|
-
]),
|
|
43
|
+
]), l = `swapperM${r.length.toString()}x${s[0].length}x1`, E = n.map((d, g) => [
|
|
45
44
|
new A({
|
|
46
|
-
amount:
|
|
45
|
+
amount: r[g],
|
|
47
46
|
erc20TokenAddress: d,
|
|
48
|
-
randomization:
|
|
47
|
+
randomization: x[g],
|
|
49
48
|
stealthAddress: y[g],
|
|
50
|
-
encryptionKey:
|
|
49
|
+
encryptionKey: o
|
|
51
50
|
})
|
|
52
51
|
]), { zkCallData: K, circomData: h, dimData: I } = await C(
|
|
53
52
|
t.merkleTreeHinkal,
|
|
@@ -55,16 +54,16 @@ const k = async (t, n, e) => {
|
|
|
55
54
|
s,
|
|
56
55
|
E,
|
|
57
56
|
t.userKeys,
|
|
58
|
-
|
|
57
|
+
l,
|
|
59
58
|
0n,
|
|
60
59
|
await t.getEthereumAddress(),
|
|
61
60
|
"0x00",
|
|
62
|
-
|
|
61
|
+
T,
|
|
63
62
|
t.getCurrentChainId()
|
|
64
|
-
), w =
|
|
63
|
+
), w = f(n[0], t.getCurrentChainId());
|
|
65
64
|
if (!w)
|
|
66
65
|
throw Error("Withdraw Action: No Token Found");
|
|
67
|
-
return await D(t,
|
|
66
|
+
return await D(t, r[0], w, K, h, I);
|
|
68
67
|
};
|
|
69
68
|
export {
|
|
70
69
|
k as hinkalDeposit,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const f=require("../../constants/chains.constants.cjs"),x=require("../../error-handling/error-codes.constants.cjs");require("ethers");require("axios");require("../../constants/vite.constants.cjs");require("../../types/circom-data.types.cjs");const A=require("../../types/external-action.types.cjs");require("../../types/transactions.types.cjs");require("../../types/curve.types.cjs");require("circomlibjs
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const f=require("../../constants/chains.constants.cjs"),x=require("../../error-handling/error-codes.constants.cjs");require("ethers");require("axios");require("../../constants/vite.constants.cjs");require("../../types/circom-data.types.cjs");const A=require("../../types/external-action.types.cjs");require("../../types/transactions.types.cjs");require("../../types/curve.types.cjs");require("circomlibjs");require("../../constants/reorg-depths.constants.cjs");const C=require("../../functions/snarkjs/constructEmporiumProof.cjs"),P=require("../../functions/pre-transaction/processAmountChanges.cjs"),R=require("../../functions/pre-transaction/outputUtxoProcessing.cjs"),w=require("../../functions/web3/events/getShieldedBalance.cjs"),U=require("../../functions/web3/functionCalls/estimateGasRelayer.cjs"),I=require("../../functions/web3/functionCalls/transactCallRelayer.cjs"),T=async(e,o,r,d,q=[],p,y=!1)=>{const a=o.map(t=>0n);r=P.processAmountChanges({erc20Addresses:o,amountChanges:r,flatFees:a,feeUnit:void 0,externalActionId:A.ExternalActionId.Emporium});const s=[...await w.addPaddingToUtxos(e,o,r)],i=[];for(let t=0;t<o.length;t+=1){const{outputUtxos:E}=R.outputUtxoProcessing(e.userKeys,s[t],r[t]);i.push(E)}const n=await e.getRandomRelay();if(!n)throw Error(x.transactionErrorCodes.RELAYER_NOT_AVAILABLE);const{contractData:g}=f.networkRegistry[e.getCurrentChainId()],{emporiumAddress:c}=g;if(!c)throw Error("No Emporium Address Provided");const{zkCallData:u,circomData:l,dimData:m}=await C.constructEmporiumProof(e.merkleTreeHinkal,e.merkleTreeAccessToken,s,i,e.userKeys,r.length,s[0].length,c,q,n,e.getCurrentChainId(),d,a,p);return y?await U.estimateGasRelayer(e,u,m,l):await I.transactCallRelayer(e.getCurrentChainId(),u,m,l)};exports.hinkalPrivateWallet=T;
|
|
@@ -7,10 +7,7 @@ import "../../types/circom-data.types.mjs";
|
|
|
7
7
|
import { ExternalActionId as w } from "../../types/external-action.types.mjs";
|
|
8
8
|
import "../../types/transactions.types.mjs";
|
|
9
9
|
import "../../types/curve.types.mjs";
|
|
10
|
-
import "circomlibjs
|
|
11
|
-
import "libsodium-wrappers";
|
|
12
|
-
import "process";
|
|
13
|
-
import "buffer";
|
|
10
|
+
import "circomlibjs";
|
|
14
11
|
import "../../constants/reorg-depths.constants.mjs";
|
|
15
12
|
import { constructEmporiumProof as R } from "../../functions/snarkjs/constructEmporiumProof.mjs";
|
|
16
13
|
import { processAmountChanges as U } from "../../functions/pre-transaction/processAmountChanges.mjs";
|
|
@@ -18,7 +15,7 @@ import { outputUtxoProcessing as C } from "../../functions/pre-transaction/outpu
|
|
|
18
15
|
import { addPaddingToUtxos as I } from "../../functions/web3/events/getShieldedBalance.mjs";
|
|
19
16
|
import { estimateGasRelayer as P } from "../../functions/web3/functionCalls/estimateGasRelayer.mjs";
|
|
20
17
|
import { transactCallRelayer as T } from "../../functions/web3/functionCalls/transactCallRelayer.mjs";
|
|
21
|
-
const
|
|
18
|
+
const M = async (t, e, o, u, d = [], l, E = !1) => {
|
|
22
19
|
const m = e.map((r) => 0n);
|
|
23
20
|
o = U({
|
|
24
21
|
erc20Addresses: e,
|
|
@@ -35,10 +32,10 @@ const X = async (t, e, o, u, d = [], l, E = !1) => {
|
|
|
35
32
|
const s = await t.getRandomRelay();
|
|
36
33
|
if (!s)
|
|
37
34
|
throw Error(A.RELAYER_NOT_AVAILABLE);
|
|
38
|
-
const { contractData: x } = g[t.getCurrentChainId()], { emporiumAddress:
|
|
39
|
-
if (!
|
|
35
|
+
const { contractData: x } = g[t.getCurrentChainId()], { emporiumAddress: n } = x;
|
|
36
|
+
if (!n)
|
|
40
37
|
throw Error("No Emporium Address Provided");
|
|
41
|
-
const { zkCallData:
|
|
38
|
+
const { zkCallData: p, circomData: c, dimData: f } = await R(
|
|
42
39
|
t.merkleTreeHinkal,
|
|
43
40
|
t.merkleTreeAccessToken,
|
|
44
41
|
i,
|
|
@@ -46,7 +43,7 @@ const X = async (t, e, o, u, d = [], l, E = !1) => {
|
|
|
46
43
|
t.userKeys,
|
|
47
44
|
o.length,
|
|
48
45
|
i[0].length,
|
|
49
|
-
|
|
46
|
+
n,
|
|
50
47
|
d,
|
|
51
48
|
s,
|
|
52
49
|
t.getCurrentChainId(),
|
|
@@ -54,8 +51,8 @@ const X = async (t, e, o, u, d = [], l, E = !1) => {
|
|
|
54
51
|
m,
|
|
55
52
|
l
|
|
56
53
|
);
|
|
57
|
-
return E ? await P(t,
|
|
54
|
+
return E ? await P(t, p, f, c) : await T(t.getCurrentChainId(), p, f, c);
|
|
58
55
|
};
|
|
59
56
|
export {
|
|
60
|
-
|
|
57
|
+
M as hinkalPrivateWallet
|
|
61
58
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("ethers"),
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("ethers"),f=require("libsodium-wrappers"),l=require("../utxo/Utxo.cjs"),u=require("./keys.cjs");(async()=>await f.ready)();const p=(e,s)=>{const i=[Buffer.from(t.ethers.utils.hexlify(s?0n:e.amount)),Buffer.from(t.ethers.utils.hexlify(e.erc20TokenAddress)),Buffer.from(t.ethers.utils.hexlify(e.randomization)),Buffer.from(e.getStealthAddress()),Buffer.from(t.ethers.utils.hexlify(BigInt(e.timeStamp)))];e.tokenId>0&&i.push(Buffer.from(t.ethers.utils.hexlify(e.tokenId)));const n=Buffer.concat(i);return f.crypto_box_seal(n,t.ethers.utils.arrayify(e.getEncryptionKey()))},d=(e,s)=>{const{publicKey:i,privateKey:n}=u.UserKeys.getEncryptionKeyPair(s.getShieldedPrivateKey()),c=f.crypto_box_seal_open(e,t.ethers.utils.arrayify(i),t.ethers.utils.arrayify(n)),r=Buffer.from(c).toString("utf-8").split("0x").filter(o=>o.length!==0).map((o,y)=>{let a;return[0,2,4,5].includes(y)?a=BigInt(`0x${o}`):[1,3].includes(y)&&(a=`0x${o}`),a});return{amount:r[0],erc20TokenAddress:r[1],randomization:r[2],stealthAddress:r[3],shieldedPrivateKey:s.getShieldedPrivateKey(),timeStamp:r[4].toString(),tokenId:r[5]?Number(r[5]):0}},h=(e,s)=>new l.Utxo(d(e,s));exports.decryptUtxo=h;exports.decryptUtxoConstructorArgs=d;exports.encryptUtxo=p;
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { ethers as t } from "ethers";
|
|
2
|
-
import
|
|
3
|
-
import { Utxo as
|
|
4
|
-
import { UserKeys as
|
|
2
|
+
import a from "libsodium-wrappers";
|
|
3
|
+
import { Utxo as d } from "../utxo/Utxo.mjs";
|
|
4
|
+
import { UserKeys as l } from "./keys.mjs";
|
|
5
|
+
(async () => await a.ready)();
|
|
5
6
|
const B = (e, i) => {
|
|
6
7
|
const o = [
|
|
7
8
|
Buffer.from(t.utils.hexlify(i ? 0n : e.amount)),
|
|
@@ -12,15 +13,15 @@ const B = (e, i) => {
|
|
|
12
13
|
];
|
|
13
14
|
e.tokenId > 0 && o.push(Buffer.from(t.utils.hexlify(e.tokenId)));
|
|
14
15
|
const n = Buffer.concat(o);
|
|
15
|
-
return
|
|
16
|
+
return a.crypto_box_seal(n, t.utils.arrayify(e.getEncryptionKey()));
|
|
16
17
|
}, m = (e, i) => {
|
|
17
|
-
const { publicKey: o, privateKey: n } =
|
|
18
|
+
const { publicKey: o, privateKey: n } = l.getEncryptionKeyPair(i.getShieldedPrivateKey()), y = a.crypto_box_seal_open(
|
|
18
19
|
e,
|
|
19
20
|
t.utils.arrayify(o),
|
|
20
21
|
t.utils.arrayify(n)
|
|
21
|
-
), r = Buffer.from(
|
|
22
|
+
), r = Buffer.from(y).toString("utf-8").split("0x").filter((f) => f.length !== 0).map((f, c) => {
|
|
22
23
|
let s;
|
|
23
|
-
return [0, 2, 4, 5].includes(
|
|
24
|
+
return [0, 2, 4, 5].includes(c) ? s = BigInt(`0x${f}`) : [1, 3].includes(c) && (s = `0x${f}`), s;
|
|
24
25
|
});
|
|
25
26
|
return {
|
|
26
27
|
amount: r[0],
|
|
@@ -32,7 +33,7 @@ const B = (e, i) => {
|
|
|
32
33
|
tokenId: r[5] ? Number(r[5]) : 0
|
|
33
34
|
// tokenId
|
|
34
35
|
};
|
|
35
|
-
}, x = (e, i) => new
|
|
36
|
+
}, x = (e, i) => new d(m(e, i));
|
|
36
37
|
export {
|
|
37
38
|
x as decryptUtxo,
|
|
38
39
|
m as decryptUtxoConstructorArgs,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const u=require("ethers"),
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const u=require("ethers"),d=require("libsodium-wrappers"),g=require("../../constants/protocol.constants.cjs"),S=require("../../crypto/babyJub.cjs"),o=require("../../crypto/poseidon.cjs"),h=require("../../functions/utils/memoize.utils.cjs"),c=require("./keyUtils.cjs");(async()=>await d.ready)();const p={privateKey:"",publicKey:""};class K{signature;constructor(e){this.signature=e}getSignature(){return this.requireSignature(),this.signature}setSignature(e){this.signature=e}requireSignature(){if(!this.signature)throw Error("No signature provided")}verifyMessage(e){return this.requireSignature(),u.utils.verifyMessage(e,this.signature)}getShieldedPrivateKey=()=>(this.requireSignature(),u.ethers.utils.keccak256(this.signature));getShieldedPublicKey=()=>(this.requireSignature(),o.poseidonHash(this.getShieldedPrivateKey()));getAccessKey=()=>(this.requireSignature(),o.poseidonHash(this.getShieldedPrivateKey(),this.getShieldedPublicKey()));getWalletSalt=e=>(this.requireSignature(),o.poseidonHash(this.getShieldedPublicKey(),this.getShieldedPrivateKey(),e));getBackendToken=()=>(this.requireSignature(),o.poseidonHash(this.getAccessKey(),this.getShieldedPublicKey()));static getRandomizedStealthPair=h.memoizeFunc((e,i)=>{const t=S.babyJubInstance(),s=BigInt(i)%g.CIRCOM_P,n=e*s%g.CIRCOM_P,r=t.mulPointEscalar(t.Base8,e),a=t.mulPointEscalar(t.Base8,n),l=[BigInt(t.F.toString(r[0])),BigInt(t.F.toString(r[1]))],y=[BigInt(t.F.toString(a[0])),BigInt(t.F.toString(a[1]))];return{H0:l,H1:y}});static getStealthAddressCompressedPoints=(e,i)=>{const{H0:t,H1:s}=this.getRandomizedStealthPair(e,i),[n,r]=[t,s].map(a=>BigInt(a[1])+2n**255n*c.getCircomSign(a[0]));return{h0:n,h1:r}};static getStealthAddress=h.memoizeFunc((e,i)=>{const{H0:t,H1:s}=this.getRandomizedStealthPair(e,i),r=[2n*c.getCircomSign(t[0])+c.getCircomSign(s[0]),t[1],s[1]];return o.poseidonHash(...r)});static getStealthAddressWithEKey=(e,i)=>({stealthAddress:this.getStealthAddress(e,i),encryptionKey:this.getEncryptionKeyPair(i).publicKey});static checkSignature=(e,i,t,s)=>{const{h0:n,h1:r}=this.getStealthAddressCompressedPoints(e,s);return i===n&&t===r};static getEncryptionKeyPair=e=>{const i=d.crypto_box_seed_keypair(u.ethers.utils.arrayify(e));return{privateKey:u.ethers.utils.hexlify(i.privateKey),publicKey:u.ethers.utils.hexlify(i.publicKey)}}}exports.EncryptionKeyPairDefaultValue=p;exports.UserKeys=K;
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import { utils as
|
|
2
|
-
import
|
|
1
|
+
import { utils as S, ethers as o } from "ethers";
|
|
2
|
+
import d from "libsodium-wrappers";
|
|
3
3
|
import { CIRCOM_P as h } from "../../constants/protocol.constants.mjs";
|
|
4
4
|
import { babyJubInstance as m } from "../../crypto/babyJub.mjs";
|
|
5
5
|
import { poseidonHash as u } from "../../crypto/poseidon.mjs";
|
|
6
6
|
import { memoizeFunc as c } from "../../functions/utils/memoize.utils.mjs";
|
|
7
7
|
import { getCircomSign as g } from "./keyUtils.mjs";
|
|
8
|
+
(async () => await d.ready)();
|
|
8
9
|
const q = {
|
|
9
10
|
privateKey: "",
|
|
10
11
|
publicKey: ""
|
|
@@ -25,7 +26,7 @@ class H {
|
|
|
25
26
|
throw Error("No signature provided");
|
|
26
27
|
}
|
|
27
28
|
verifyMessage(t) {
|
|
28
|
-
return this.requireSignature(),
|
|
29
|
+
return this.requireSignature(), S.verifyMessage(t, this.signature);
|
|
29
30
|
}
|
|
30
31
|
/**
|
|
31
32
|
* get shielded private key from message signature used to login to the application,
|
|
@@ -53,8 +54,8 @@ class H {
|
|
|
53
54
|
getBackendToken = () => (this.requireSignature(), u(this.getAccessKey(), this.getShieldedPublicKey()));
|
|
54
55
|
static getRandomizedStealthPair = c(
|
|
55
56
|
(t, i) => {
|
|
56
|
-
const e = m(), r = BigInt(i) % h, n = t * r % h, s = e.mulPointEscalar(e.Base8, t), a = e.mulPointEscalar(e.Base8, n),
|
|
57
|
-
return { H0:
|
|
57
|
+
const e = m(), r = BigInt(i) % h, n = t * r % h, s = e.mulPointEscalar(e.Base8, t), a = e.mulPointEscalar(e.Base8, n), l = [BigInt(e.F.toString(s[0])), BigInt(e.F.toString(s[1]))], y = [BigInt(e.F.toString(a[0])), BigInt(e.F.toString(a[1]))];
|
|
58
|
+
return { H0: l, H1: y };
|
|
58
59
|
}
|
|
59
60
|
);
|
|
60
61
|
static getStealthAddressCompressedPoints = (t, i) => {
|
|
@@ -76,7 +77,7 @@ class H {
|
|
|
76
77
|
* and must correspond to 32 bytes
|
|
77
78
|
*/
|
|
78
79
|
static getEncryptionKeyPair = (t) => {
|
|
79
|
-
const i =
|
|
80
|
+
const i = d.crypto_box_seed_keypair(o.utils.arrayify(t));
|
|
80
81
|
return {
|
|
81
82
|
privateKey: o.utils.hexlify(i.privateKey),
|
|
82
83
|
publicKey: o.utils.hexlify(i.publicKey)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const l=require("../../constants/protocol.constants.cjs"),c=require("../../crypto/poseidon.cjs");require("circomlibjs
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const l=require("../../constants/protocol.constants.cjs"),c=require("../../crypto/poseidon.cjs");require("circomlibjs");const n=require("../../functions/utils/amounts.utils.cjs"),o=require("../merkle-tree/MerkleTree.cjs"),A=require("./AbstractSnapshotService.cjs");class u extends A.AbstractSnapshotService{constructor(e,s,r,d){super(e,{name:"NewAccessKeyAdded",args:["accessKey","index","senderAddress"]},s,r,d)}_merkleTree;_senderAddresses;_senderAddressIndexMap;get merkleTree(){return this._merkleTree}get senderAddresses(){return this._senderAddresses}get senderAddressIndexMap(){return this._senderAddressIndexMap}serializeSnapshot(e){return{merkleTree:e.payload.merkleTree.toJSON(),senderAddresses:Array.from(e.payload.senderAddresses),latestBlockNumber:e.latestBlockNumber,reserveBlockNumber:e.reserveBlockNumber,senderAddressIndexMap:Array.from(e.payload.senderAddressIndexMap).map(([s,r])=>({address:s,index:r}))}}deserializeSnapshot(e){let s,r;if(e.latestBlockNumber&&e.merkleTree){const d=new Map(Object.entries(e.merkleTree.tree).map(([t,a])=>[BigInt(t),BigInt(a)]));s=o.MerkleTree.createWithData(d,n.toBigInt(e.merkleTree.index),n.toBigInt(e.merkleTree.count),c.poseidonFunction,25n,0n)}else s=o.MerkleTree.create(c.poseidonFunction,25n,0n);return e.latestBlockNumber&&e.senderAddressIndexMap?r=new Map(e.senderAddressIndexMap.map(({address:d,index:t})=>[d,t])):r=new Map,{latestBlockNumber:e.latestBlockNumber??0,reserveBlockNumber:e.reserveBlockNumber??0,payload:{merkleTree:s,senderAddresses:e.senderAddresses??[],senderAddressIndexMap:r}}}acceptEvent(e,s){try{return this._merkleTree.insert(e.accessKey,e.index),this._senderAddressIndexMap.set(e.senderAddress,Math.max(Number(e.index),this._senderAddressIndexMap.get(e.senderAddress)??0)),this._senderAddresses.includes(e.senderAddress)||this._senderAddresses.push(e.senderAddress),e.accessKey===0n&&e.senderAddress===l.zeroAddress&&this._merkleTree.remove(e.index),!0}catch(r){return console.error(r),!1}}mapEvent(e){const{accessKey:s,index:r,senderAddress:d}=e;return{accessKey:n.toBigInt(s),index:n.toBigInt(r),senderAddress:d}}getSnapshotPayload(){return{merkleTree:this._merkleTree,senderAddresses:this._senderAddresses,senderAddressIndexMap:this._senderAddressIndexMap}}populateSnapshot({payload:{merkleTree:e,senderAddresses:s,senderAddressIndexMap:r}}){this._merkleTree=e,this._senderAddresses=s,this._senderAddressIndexMap=r}}exports.AbstractAccessTokenSnapshotService=u;
|