seismic-viem 1.1.2 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/_cjs/index.js +486 -169
- package/dist/_esm/index.js +414 -102
- package/dist/_types/actions/wallet.d.ts +20 -10
- package/dist/_types/chain.d.ts +50 -3
- package/dist/_types/client.d.ts +24 -5
- package/dist/_types/contract/abi.d.ts +7 -1
- package/dist/_types/contract/calldata.d.ts +16 -0
- package/dist/_types/contract/contract.d.ts +36 -19
- package/dist/_types/contract/read.d.ts +25 -1
- package/dist/_types/contract/write.d.ts +43 -42
- package/dist/_types/index.d.ts +6 -5
- package/dist/_types/tx/sendShielded.d.ts +49 -0
- package/dist/_types/tx/sendTransparent.d.ts +16 -0
- package/dist/_types/{signedCall.d.ts → tx/signedCall.d.ts} +17 -11
- package/dist/_types/tx/types.d.ts +15 -0
- package/package.json +1 -1
- package/dist/_types/request.d.ts +0 -4
- package/dist/_types/sendTransaction.d.ts +0 -56
package/dist/_cjs/index.js
CHANGED
|
@@ -32,6 +32,8 @@ __export(exports_src, {
|
|
|
32
32
|
watchSRC20EventsWithKey: () => watchSRC20EventsWithKey,
|
|
33
33
|
watchSRC20Events: () => watchSRC20Events,
|
|
34
34
|
txExplorerUrl: () => txExplorerUrl,
|
|
35
|
+
transparentWriteContract: () => transparentWriteContract,
|
|
36
|
+
transparentReadContract: () => transparentReadContract,
|
|
35
37
|
tokenExplorerUrl: () => tokenExplorerUrl,
|
|
36
38
|
stringifyBigInt: () => stringifyBigInt,
|
|
37
39
|
src20WalletActions: () => src20WalletActions,
|
|
@@ -61,6 +63,7 @@ __export(exports_src, {
|
|
|
61
63
|
localSeismicDevnet: () => localSeismicDevnet,
|
|
62
64
|
hdfkPrecompile: () => hdfkPrecompile,
|
|
63
65
|
hdfk: () => hdfk,
|
|
66
|
+
hasShieldedParams: () => hasShieldedParams,
|
|
64
67
|
getShieldedContract: () => getShieldedContract,
|
|
65
68
|
getPlaintextCalldata: () => getPlaintextCalldata,
|
|
66
69
|
getKeyHash: () => getKeyHash,
|
|
@@ -219,12 +222,14 @@ var seismicTxTypedData = (tx) => {
|
|
|
219
222
|
if (tx.signedRead === undefined) {
|
|
220
223
|
throw new Error("Seismic transactions require signedRead");
|
|
221
224
|
}
|
|
225
|
+
const isCreate = tx.to === undefined || tx.to === null;
|
|
222
226
|
const message = {
|
|
223
227
|
chainId: tx.chainId,
|
|
224
228
|
nonce: tx.nonce !== undefined ? BigInt(tx.nonce) : undefined,
|
|
225
229
|
gasPrice: tx.gasPrice && BigInt(tx.gasPrice),
|
|
226
230
|
gasLimit: tx.gas && BigInt(tx.gas),
|
|
227
|
-
to: tx.to,
|
|
231
|
+
to: isCreate ? "0x0000000000000000000000000000000000000000" : tx.to,
|
|
232
|
+
isCreate,
|
|
228
233
|
value: tx.value ? BigInt(tx.value) : 0n,
|
|
229
234
|
input: tx.data ?? "0x",
|
|
230
235
|
encryptionPubkey: tx.encryptionPubkey,
|
|
@@ -248,6 +253,7 @@ var seismicTxTypedData = (tx) => {
|
|
|
248
253
|
{ name: "gasPrice", type: "uint128" },
|
|
249
254
|
{ name: "gasLimit", type: "uint64" },
|
|
250
255
|
{ name: "to", type: "address" },
|
|
256
|
+
{ name: "isCreate", type: "bool" },
|
|
251
257
|
{ name: "value", type: "uint256" },
|
|
252
258
|
{ name: "input", type: "bytes" },
|
|
253
259
|
{ name: "encryptionPubkey", type: "bytes" },
|
|
@@ -283,13 +289,14 @@ var signSeismicTxTypedData = async (client, tx) => {
|
|
|
283
289
|
};
|
|
284
290
|
|
|
285
291
|
// src/metadata.ts
|
|
292
|
+
var DEFAULT_SEISMIC_BLOCKS_WINDOW = 100n;
|
|
286
293
|
var fillNonce = async (client, parameters) => {
|
|
287
294
|
let account = import_accounts.parseAccount(parameters.account || client.account);
|
|
288
295
|
const { nonce: nonce_ } = parameters;
|
|
289
296
|
if (nonce_ !== undefined) {
|
|
290
297
|
return nonce_;
|
|
291
298
|
}
|
|
292
|
-
const { blockNumber, blockTag = "
|
|
299
|
+
const { blockNumber, blockTag = "pending" } = parameters;
|
|
293
300
|
let args = {
|
|
294
301
|
address: account.address,
|
|
295
302
|
blockTag
|
|
@@ -303,7 +310,7 @@ var inferTypedDataTx = (typedDataTx, account) => {
|
|
|
303
310
|
if (typedDataTx !== undefined) {
|
|
304
311
|
return typedDataTx;
|
|
305
312
|
}
|
|
306
|
-
return account.type === "json-rpc";
|
|
313
|
+
return account.type === "json-rpc" || account.type === "local";
|
|
307
314
|
};
|
|
308
315
|
var buildTxSeismicMetadata = async (client, {
|
|
309
316
|
account: paramsAcct,
|
|
@@ -311,7 +318,7 @@ var buildTxSeismicMetadata = async (client, {
|
|
|
311
318
|
to,
|
|
312
319
|
value = 0n,
|
|
313
320
|
encryptionNonce,
|
|
314
|
-
blocksWindow =
|
|
321
|
+
blocksWindow = DEFAULT_SEISMIC_BLOCKS_WINDOW,
|
|
315
322
|
recentBlockHash,
|
|
316
323
|
expiresAtBlock,
|
|
317
324
|
typedDataTx,
|
|
@@ -420,7 +427,8 @@ var serializeSeismicTransaction = (tx, signature) => {
|
|
|
420
427
|
messageVersion = 0,
|
|
421
428
|
recentBlockHash,
|
|
422
429
|
expiresAtBlock,
|
|
423
|
-
signedRead = false
|
|
430
|
+
signedRead = false,
|
|
431
|
+
authorizationList
|
|
424
432
|
} = tx;
|
|
425
433
|
if (chainId === undefined) {
|
|
426
434
|
throw new Error("Seismic transactions require chainId");
|
|
@@ -466,6 +474,14 @@ var serializeSeismicTransaction = (tx, signature) => {
|
|
|
466
474
|
import_viem4.toHex(expiresAtBlock),
|
|
467
475
|
signedRead ? "0x01" : "0x",
|
|
468
476
|
data ?? "0x",
|
|
477
|
+
(authorizationList ?? []).map((auth) => [
|
|
478
|
+
auth.chainId ? import_viem4.toHex(auth.chainId) : "0x",
|
|
479
|
+
auth.contractAddress,
|
|
480
|
+
auth.nonce ? import_viem4.toHex(auth.nonce) : "0x",
|
|
481
|
+
auth.yParity ? import_viem4.toHex(auth.yParity) : "0x",
|
|
482
|
+
auth.r,
|
|
483
|
+
auth.s
|
|
484
|
+
]),
|
|
469
485
|
...toYParitySignatureArray(tx, signature)
|
|
470
486
|
];
|
|
471
487
|
const rlpEncoded = import_viem4.toRlp(rlpArray);
|
|
@@ -485,13 +501,27 @@ var seismicRpcSchema = [estimateGasRpcSchema, callRpcSchema];
|
|
|
485
501
|
var hasSeismicFields = (request) => {
|
|
486
502
|
return request.encryptionPubkey !== undefined && request.encryptionNonce !== undefined && request.messageVersion !== undefined && request.recentBlockHash !== undefined && request.expiresAtBlock !== undefined && request.signedRead !== undefined;
|
|
487
503
|
};
|
|
504
|
+
var formatAuthorizationList = (authorizationList) => authorizationList.map((authorization) => ({
|
|
505
|
+
address: authorization.contractAddress,
|
|
506
|
+
r: authorization.r,
|
|
507
|
+
s: authorization.s,
|
|
508
|
+
chainId: import_viem4.toHex(authorization.chainId),
|
|
509
|
+
nonce: import_viem4.toHex(authorization.nonce),
|
|
510
|
+
...typeof authorization.yParity !== "undefined" ? { yParity: import_viem4.toHex(authorization.yParity) } : {},
|
|
511
|
+
...typeof authorization.v !== "undefined" && typeof authorization.yParity === "undefined" ? { v: import_viem4.toHex(authorization.v) } : {}
|
|
512
|
+
}));
|
|
488
513
|
var fmtRpcRequest = (request) => {
|
|
489
514
|
if (request.type === "seismic") {
|
|
515
|
+
const { authorizationList, ...legacyCompatibleRequest } = request;
|
|
490
516
|
const seismicFmt = import_viem4.formatTransactionRequest({
|
|
491
|
-
...
|
|
517
|
+
...legacyCompatibleRequest,
|
|
492
518
|
type: "legacy"
|
|
493
519
|
});
|
|
494
|
-
return {
|
|
520
|
+
return {
|
|
521
|
+
...seismicFmt,
|
|
522
|
+
type: SEISMIC_TX_TYPE,
|
|
523
|
+
...authorizationList ? { authorizationList: formatAuthorizationList(authorizationList) } : {}
|
|
524
|
+
};
|
|
495
525
|
}
|
|
496
526
|
const { type, ...fmt } = import_viem4.formatTransactionRequest(request);
|
|
497
527
|
if (hasSeismicFields(request)) {
|
|
@@ -606,11 +636,11 @@ var sanvil = /* @__PURE__ */ import_viem4.defineChain({
|
|
|
606
636
|
testnet: true
|
|
607
637
|
});
|
|
608
638
|
// src/contract/contract.ts
|
|
609
|
-
var
|
|
610
|
-
var import_actions4 = require("viem/actions");
|
|
639
|
+
var import_viem13 = require("viem");
|
|
611
640
|
|
|
612
641
|
// src/contract/read.ts
|
|
613
642
|
var import_viem9 = require("viem");
|
|
643
|
+
var import_actions3 = require("viem/actions");
|
|
614
644
|
var import_utils2 = require("viem/utils");
|
|
615
645
|
|
|
616
646
|
// src/contract/abi.ts
|
|
@@ -658,6 +688,12 @@ var remapSeismicParam = (param) => {
|
|
|
658
688
|
}
|
|
659
689
|
return { shielded: false, type: ty };
|
|
660
690
|
};
|
|
691
|
+
function hasShieldedParams(abi, functionName) {
|
|
692
|
+
const abiItem = import_viem5.getAbiItem({ abi, name: functionName });
|
|
693
|
+
if (!abiItem?.inputs)
|
|
694
|
+
return false;
|
|
695
|
+
return abiItem.inputs.some((param) => remapSeismicParam(param).shielded);
|
|
696
|
+
}
|
|
661
697
|
var remapSeismicAbiInputs = (abiFunction) => {
|
|
662
698
|
return {
|
|
663
699
|
type: abiFunction.type,
|
|
@@ -670,7 +706,7 @@ var remapSeismicAbiInputs = (abiFunction) => {
|
|
|
670
706
|
};
|
|
671
707
|
};
|
|
672
708
|
|
|
673
|
-
// src/signedCall.ts
|
|
709
|
+
// src/tx/signedCall.ts
|
|
674
710
|
var import_viem8 = require("viem");
|
|
675
711
|
var import_actions2 = require("viem/actions");
|
|
676
712
|
var import_utils = require("viem/utils");
|
|
@@ -701,9 +737,9 @@ function getRevertErrorData(err) {
|
|
|
701
737
|
return typeof error?.data === "object" ? error.data?.data : error.data;
|
|
702
738
|
}
|
|
703
739
|
|
|
704
|
-
// src/signedCall.ts
|
|
740
|
+
// src/tx/signedCall.ts
|
|
705
741
|
var doSignedCall = async (client, seismicTx, { block }) => {
|
|
706
|
-
if (client.account?.type === "json-rpc") {
|
|
742
|
+
if (client.account?.type === "json-rpc" || client.account?.type === "local") {
|
|
707
743
|
const { typedData, signature } = await signSeismicTxTypedData(client, seismicTx);
|
|
708
744
|
const response2 = await client.publicRequest({
|
|
709
745
|
method: "eth_call",
|
|
@@ -727,18 +763,19 @@ var prepareAccount = (paramsAccount, clientAccount) => {
|
|
|
727
763
|
}
|
|
728
764
|
return account;
|
|
729
765
|
};
|
|
730
|
-
async function signedCall(client, args, {
|
|
766
|
+
async function signedCall(client, args, {
|
|
767
|
+
blocksWindow,
|
|
768
|
+
encryptionNonce,
|
|
769
|
+
recentBlockHash,
|
|
770
|
+
expiresAtBlock
|
|
771
|
+
} = {}) {
|
|
731
772
|
const {
|
|
732
773
|
account: account_ = client.account,
|
|
733
|
-
batch = Boolean(client.batch?.multicall),
|
|
734
774
|
blockNumber,
|
|
735
775
|
blockTag = "latest",
|
|
736
776
|
accessList,
|
|
737
777
|
blobs,
|
|
738
|
-
code,
|
|
739
778
|
data: plaintextCalldata,
|
|
740
|
-
factory,
|
|
741
|
-
factoryData,
|
|
742
779
|
gas = 30000000,
|
|
743
780
|
gasPrice,
|
|
744
781
|
maxFeePerBlobGas,
|
|
@@ -782,6 +819,8 @@ async function signedCall(client, args, { blocksWindow = 100n, encryptionNonce }
|
|
|
782
819
|
to,
|
|
783
820
|
blocksWindow,
|
|
784
821
|
encryptionNonce,
|
|
822
|
+
recentBlockHash,
|
|
823
|
+
expiresAtBlock,
|
|
785
824
|
signedRead: true
|
|
786
825
|
});
|
|
787
826
|
const encryptedCalldata = await client.encrypt(plaintextCalldata, metadata);
|
|
@@ -831,6 +870,20 @@ async function signedCall(client, args, { blocksWindow = 100n, encryptionNonce }
|
|
|
831
870
|
}
|
|
832
871
|
|
|
833
872
|
// src/contract/read.ts
|
|
873
|
+
async function smartReadContract(walletClient, readClient, parameters, securityParams, forcedAccount) {
|
|
874
|
+
const readArgs = parameters;
|
|
875
|
+
if (hasShieldedParams(readArgs.abi, readArgs.functionName)) {
|
|
876
|
+
const account = forcedAccount ?? walletClient?.account;
|
|
877
|
+
if (!walletClient || !account) {
|
|
878
|
+
throw new Error("Wallet must have an account to perform signed reads");
|
|
879
|
+
}
|
|
880
|
+
return signedReadContract(walletClient, {
|
|
881
|
+
...parameters,
|
|
882
|
+
account
|
|
883
|
+
}, securityParams);
|
|
884
|
+
}
|
|
885
|
+
return import_actions3.readContract(readClient, parameters);
|
|
886
|
+
}
|
|
834
887
|
async function signedReadContract(client, parameters, securityParams) {
|
|
835
888
|
const {
|
|
836
889
|
abi,
|
|
@@ -857,20 +910,58 @@ async function signedReadContract(client, parameters, securityParams) {
|
|
|
857
910
|
data: data || "0x"
|
|
858
911
|
});
|
|
859
912
|
}
|
|
913
|
+
async function transparentReadContract(client, parameters) {
|
|
914
|
+
const {
|
|
915
|
+
abi,
|
|
916
|
+
functionName,
|
|
917
|
+
args = [],
|
|
918
|
+
address,
|
|
919
|
+
...rest
|
|
920
|
+
} = parameters;
|
|
921
|
+
const seismicAbi = import_viem9.getAbiItem({ abi, name: functionName });
|
|
922
|
+
const selector = import_viem9.toFunctionSelector(import_utils2.formatAbiItem(seismicAbi));
|
|
923
|
+
const ethAbi = remapSeismicAbiInputs(seismicAbi);
|
|
924
|
+
const encodedParams = import_viem9.encodeAbiParameters(ethAbi.inputs, args).slice(2);
|
|
925
|
+
const data = `${selector}${encodedParams}`;
|
|
926
|
+
const callOptions = rest;
|
|
927
|
+
const { data: result } = await client.call({
|
|
928
|
+
to: address,
|
|
929
|
+
data,
|
|
930
|
+
...callOptions
|
|
931
|
+
});
|
|
932
|
+
return import_viem9.decodeFunctionResult({
|
|
933
|
+
abi,
|
|
934
|
+
args,
|
|
935
|
+
functionName,
|
|
936
|
+
data: result || "0x"
|
|
937
|
+
});
|
|
938
|
+
}
|
|
860
939
|
|
|
861
940
|
// src/contract/write.ts
|
|
862
|
-
var
|
|
863
|
-
var
|
|
941
|
+
var import_viem12 = require("viem");
|
|
942
|
+
var import_actions5 = require("viem/actions");
|
|
864
943
|
|
|
865
|
-
// src/
|
|
866
|
-
var
|
|
867
|
-
var import_actions3 = require("viem/actions");
|
|
944
|
+
// src/contract/calldata.ts
|
|
945
|
+
var import_viem10 = require("viem");
|
|
868
946
|
var import_utils3 = require("viem/utils");
|
|
947
|
+
var getPlaintextCalldata = (parameters) => {
|
|
948
|
+
const { abi, functionName, args = [] } = parameters;
|
|
949
|
+
const seismicAbi = import_viem10.getAbiItem({ abi, name: functionName });
|
|
950
|
+
const selector = import_viem10.toFunctionSelector(import_utils3.formatAbiItem(seismicAbi));
|
|
951
|
+
const ethAbi = remapSeismicAbiInputs(seismicAbi);
|
|
952
|
+
const encodedParams = import_viem10.encodeAbiParameters(ethAbi.inputs, args).slice(2);
|
|
953
|
+
return `${selector}${encodedParams}`;
|
|
954
|
+
};
|
|
955
|
+
|
|
956
|
+
// src/tx/sendShielded.ts
|
|
957
|
+
var import_accounts2 = require("viem/accounts");
|
|
958
|
+
var import_actions4 = require("viem/actions");
|
|
959
|
+
var import_utils4 = require("viem/utils");
|
|
869
960
|
|
|
870
961
|
// src/error/account.ts
|
|
871
|
-
var
|
|
962
|
+
var import_viem11 = require("viem");
|
|
872
963
|
|
|
873
|
-
class AccountNotFoundError extends
|
|
964
|
+
class AccountNotFoundError extends import_viem11.BaseError {
|
|
874
965
|
constructor({ docsPath } = {}) {
|
|
875
966
|
super([
|
|
876
967
|
"Could not find an Account to execute with this Action.",
|
|
@@ -884,7 +975,7 @@ class AccountNotFoundError extends import_viem10.BaseError {
|
|
|
884
975
|
}
|
|
885
976
|
}
|
|
886
977
|
|
|
887
|
-
class AccountTypeNotSupportedError extends
|
|
978
|
+
class AccountTypeNotSupportedError extends import_viem11.BaseError {
|
|
888
979
|
constructor({
|
|
889
980
|
docsPath,
|
|
890
981
|
metaMessages,
|
|
@@ -898,8 +989,13 @@ class AccountTypeNotSupportedError extends import_viem10.BaseError {
|
|
|
898
989
|
}
|
|
899
990
|
}
|
|
900
991
|
|
|
901
|
-
// src/
|
|
902
|
-
async function sendShieldedTransaction(client, parameters, {
|
|
992
|
+
// src/tx/sendShielded.ts
|
|
993
|
+
async function sendShieldedTransaction(client, parameters, {
|
|
994
|
+
blocksWindow,
|
|
995
|
+
encryptionNonce,
|
|
996
|
+
recentBlockHash,
|
|
997
|
+
expiresAtBlock
|
|
998
|
+
} = {}) {
|
|
903
999
|
const {
|
|
904
1000
|
account: account_ = client.account,
|
|
905
1001
|
chain = client.chain,
|
|
@@ -930,7 +1026,7 @@ async function sendShieldedTransaction(client, parameters, { blocksWindow = 100n
|
|
|
930
1026
|
maxPriorityFeePerGas,
|
|
931
1027
|
to: parameters.to
|
|
932
1028
|
};
|
|
933
|
-
|
|
1029
|
+
import_utils4.assertRequest(assertRequestParams);
|
|
934
1030
|
const to = await (async () => {
|
|
935
1031
|
if (parameters.to)
|
|
936
1032
|
return parameters.to;
|
|
@@ -944,19 +1040,25 @@ async function sendShieldedTransaction(client, parameters, { blocksWindow = 100n
|
|
|
944
1040
|
value,
|
|
945
1041
|
blocksWindow,
|
|
946
1042
|
signedRead: false,
|
|
947
|
-
encryptionNonce
|
|
1043
|
+
encryptionNonce,
|
|
1044
|
+
recentBlockHash,
|
|
1045
|
+
expiresAtBlock
|
|
948
1046
|
});
|
|
949
1047
|
const encryptedCalldata = await client.encrypt(plaintextCalldata, metadata);
|
|
950
|
-
const
|
|
951
|
-
const
|
|
952
|
-
|
|
1048
|
+
const resolvedGasPrice = gasPrice ?? maxFeePerGas ?? await client.getGasPrice();
|
|
1049
|
+
const resolvedGas = gas ?? await estimateShieldedGas(client, {
|
|
1050
|
+
encryptedData: encryptedCalldata,
|
|
1051
|
+
metadata,
|
|
1052
|
+
gasPrice: resolvedGasPrice
|
|
1053
|
+
});
|
|
1054
|
+
const prepRequest = {
|
|
953
1055
|
accessList,
|
|
954
1056
|
authorizationList,
|
|
955
1057
|
blobs,
|
|
956
1058
|
chainId: metadata.legacyFields.chainId,
|
|
957
|
-
data:
|
|
1059
|
+
data: plaintextCalldata,
|
|
958
1060
|
from: account.address,
|
|
959
|
-
gas,
|
|
1061
|
+
gas: resolvedGas,
|
|
960
1062
|
gasPrice,
|
|
961
1063
|
maxFeePerBlobGas,
|
|
962
1064
|
maxFeePerGas,
|
|
@@ -964,24 +1066,27 @@ async function sendShieldedTransaction(client, parameters, { blocksWindow = 100n
|
|
|
964
1066
|
nonce: metadata.legacyFields.nonce,
|
|
965
1067
|
to,
|
|
966
1068
|
value,
|
|
967
|
-
type: "legacy",
|
|
968
1069
|
...rest
|
|
969
1070
|
};
|
|
970
|
-
const
|
|
1071
|
+
const viemPreparedTx = await import_actions4.prepareTransactionRequest(client, prepRequest);
|
|
971
1072
|
const preparedTx = {
|
|
972
1073
|
...viemPreparedTx,
|
|
1074
|
+
...metadata.seismicElements,
|
|
1075
|
+
data: encryptedCalldata,
|
|
1076
|
+
gasPrice: resolvedGasPrice,
|
|
973
1077
|
type: "seismic"
|
|
974
1078
|
};
|
|
975
1079
|
if (metadata.seismicElements.messageVersion === TYPED_DATA_MESSAGE_VERSION) {
|
|
976
1080
|
const { typedData, signature } = await signSeismicTxTypedData(client, preparedTx);
|
|
977
|
-
const action =
|
|
1081
|
+
const action = import_utils4.getAction(client, import_actions4.sendRawTransaction, "sendRawTransaction");
|
|
978
1082
|
return await action({
|
|
979
1083
|
serializedTransaction: { data: typedData, signature }
|
|
980
1084
|
});
|
|
981
|
-
} else {
|
|
982
|
-
const serializedTransaction = await account.signTransaction(preparedTx, { serializer: serializeSeismicTransaction });
|
|
983
|
-
return await import_actions3.sendRawTransaction(client, { serializedTransaction });
|
|
984
1085
|
}
|
|
1086
|
+
const serializedTransaction = await account.signTransaction(preparedTx, {
|
|
1087
|
+
serializer: serializeSeismicTransaction
|
|
1088
|
+
});
|
|
1089
|
+
return await import_actions4.sendRawTransaction(client, { serializedTransaction });
|
|
985
1090
|
}
|
|
986
1091
|
if (account?.type === "smart")
|
|
987
1092
|
throw new AccountTypeNotSupportedError({
|
|
@@ -996,7 +1101,7 @@ async function sendShieldedTransaction(client, parameters, { blocksWindow = 100n
|
|
|
996
1101
|
} catch (err) {
|
|
997
1102
|
if (err instanceof AccountTypeNotSupportedError)
|
|
998
1103
|
throw err;
|
|
999
|
-
throw
|
|
1104
|
+
throw import_utils4.getTransactionError(err, {
|
|
1000
1105
|
...parameters,
|
|
1001
1106
|
account,
|
|
1002
1107
|
chain: chain || undefined,
|
|
@@ -1004,39 +1109,78 @@ async function sendShieldedTransaction(client, parameters, { blocksWindow = 100n
|
|
|
1004
1109
|
});
|
|
1005
1110
|
}
|
|
1006
1111
|
}
|
|
1112
|
+
async function estimateShieldedGas(client, {
|
|
1113
|
+
encryptedData,
|
|
1114
|
+
metadata,
|
|
1115
|
+
gasPrice
|
|
1116
|
+
}) {
|
|
1117
|
+
const block = await client.getBlock({ blockTag: "latest" });
|
|
1118
|
+
const blockGasLimit = block.gasLimit;
|
|
1119
|
+
const tempTx = {
|
|
1120
|
+
type: "seismic",
|
|
1121
|
+
chainId: metadata.legacyFields.chainId,
|
|
1122
|
+
nonce: metadata.legacyFields.nonce,
|
|
1123
|
+
gasPrice,
|
|
1124
|
+
gas: blockGasLimit,
|
|
1125
|
+
to: metadata.legacyFields.to ?? undefined,
|
|
1126
|
+
value: metadata.legacyFields.value,
|
|
1127
|
+
data: encryptedData,
|
|
1128
|
+
...metadata.seismicElements
|
|
1129
|
+
};
|
|
1130
|
+
const isEip712 = metadata.seismicElements.messageVersion === TYPED_DATA_MESSAGE_VERSION;
|
|
1131
|
+
if (isEip712) {
|
|
1132
|
+
const { typedData, signature } = await signSeismicTxTypedData(client, tempTx);
|
|
1133
|
+
const response2 = await client.request({
|
|
1134
|
+
method: "eth_estimateGas",
|
|
1135
|
+
params: [{ data: typedData, signature }]
|
|
1136
|
+
});
|
|
1137
|
+
return BigInt(response2);
|
|
1138
|
+
}
|
|
1139
|
+
const serializedTransaction = await client.account.signTransaction(tempTx, {
|
|
1140
|
+
serializer: serializeSeismicTransaction
|
|
1141
|
+
});
|
|
1142
|
+
const response = await client.request({
|
|
1143
|
+
method: "eth_estimateGas",
|
|
1144
|
+
params: [serializedTransaction]
|
|
1145
|
+
});
|
|
1146
|
+
return BigInt(response);
|
|
1147
|
+
}
|
|
1007
1148
|
|
|
1008
1149
|
// src/contract/write.ts
|
|
1009
|
-
|
|
1010
|
-
const
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1150
|
+
async function smartWriteContract(client, parameters) {
|
|
1151
|
+
const writeArgs = parameters;
|
|
1152
|
+
if (hasShieldedParams(writeArgs.abi, writeArgs.functionName)) {
|
|
1153
|
+
return shieldedWriteContract(client, parameters);
|
|
1154
|
+
}
|
|
1155
|
+
return import_actions5.writeContract(client, parameters);
|
|
1156
|
+
}
|
|
1157
|
+
async function transparentWriteContract(client, parameters) {
|
|
1158
|
+
const {
|
|
1159
|
+
abi: _abi,
|
|
1160
|
+
functionName: _fn,
|
|
1161
|
+
args: _args,
|
|
1162
|
+
address,
|
|
1163
|
+
...txOptions
|
|
1164
|
+
} = parameters;
|
|
1165
|
+
const data = getPlaintextCalldata(parameters);
|
|
1166
|
+
return client.sendTransaction({
|
|
1023
1167
|
to: address,
|
|
1024
|
-
data
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
gas,
|
|
1028
|
-
gasPrice
|
|
1029
|
-
};
|
|
1168
|
+
data,
|
|
1169
|
+
...txOptions
|
|
1170
|
+
});
|
|
1030
1171
|
}
|
|
1031
|
-
async function shieldedWriteContract(client, parameters) {
|
|
1172
|
+
async function shieldedWriteContract(client, parameters, securityParams) {
|
|
1032
1173
|
const plaintextCalldata = getPlaintextCalldata(parameters);
|
|
1033
|
-
const request =
|
|
1034
|
-
return sendShieldedTransaction(client, request);
|
|
1174
|
+
const request = buildShieldedWriteRequest(client, parameters, plaintextCalldata);
|
|
1175
|
+
return sendShieldedTransaction(client, request, securityParams);
|
|
1035
1176
|
}
|
|
1036
|
-
async function shieldedWriteContractDebug(client, parameters, checkContractDeployed, {
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1177
|
+
async function shieldedWriteContractDebug(client, parameters, checkContractDeployed, securityParams = {}) {
|
|
1178
|
+
const {
|
|
1179
|
+
blocksWindow,
|
|
1180
|
+
encryptionNonce: userEncNonce,
|
|
1181
|
+
recentBlockHash,
|
|
1182
|
+
expiresAtBlock
|
|
1183
|
+
} = securityParams;
|
|
1040
1184
|
if (checkContractDeployed) {
|
|
1041
1185
|
const code = await client.getCode({ address: parameters.address });
|
|
1042
1186
|
if (code === undefined) {
|
|
@@ -1044,7 +1188,7 @@ async function shieldedWriteContractDebug(client, parameters, checkContractDeplo
|
|
|
1044
1188
|
}
|
|
1045
1189
|
}
|
|
1046
1190
|
const plaintextCalldata = getPlaintextCalldata(parameters);
|
|
1047
|
-
const request =
|
|
1191
|
+
const request = buildShieldedWriteRequest(client, parameters, plaintextCalldata);
|
|
1048
1192
|
const encryptionNonce = userEncNonce ?? randomEncryptionNonce();
|
|
1049
1193
|
const metadata = await buildTxSeismicMetadata(client, {
|
|
1050
1194
|
account: parameters.account || client.account,
|
|
@@ -1053,30 +1197,46 @@ async function shieldedWriteContractDebug(client, parameters, checkContractDeplo
|
|
|
1053
1197
|
value: request.value,
|
|
1054
1198
|
encryptionNonce,
|
|
1055
1199
|
blocksWindow,
|
|
1200
|
+
recentBlockHash,
|
|
1201
|
+
expiresAtBlock,
|
|
1056
1202
|
signedRead: false
|
|
1057
1203
|
});
|
|
1058
1204
|
const txHash = await sendShieldedTransaction(client, request, {
|
|
1059
|
-
|
|
1060
|
-
|
|
1205
|
+
encryptionNonce,
|
|
1206
|
+
recentBlockHash: metadata.seismicElements.recentBlockHash,
|
|
1207
|
+
expiresAtBlock: metadata.seismicElements.expiresAtBlock
|
|
1061
1208
|
});
|
|
1062
1209
|
return {
|
|
1063
1210
|
plaintextTx: {
|
|
1064
1211
|
to: request.to || null,
|
|
1065
1212
|
data: plaintextCalldata,
|
|
1066
|
-
type:
|
|
1213
|
+
type: import_viem12.numberToHex(SEISMIC_TX_TYPE),
|
|
1067
1214
|
nonce: request.nonce,
|
|
1068
1215
|
gas: request.gas,
|
|
1069
1216
|
gasPrice: request.gasPrice,
|
|
1070
1217
|
value: request.value
|
|
1071
1218
|
},
|
|
1072
1219
|
shieldedTx: {
|
|
1073
|
-
type:
|
|
1220
|
+
type: import_viem12.numberToHex(SEISMIC_TX_TYPE),
|
|
1074
1221
|
...request,
|
|
1075
1222
|
...metadata.seismicElements
|
|
1076
1223
|
},
|
|
1077
1224
|
txHash
|
|
1078
1225
|
};
|
|
1079
1226
|
}
|
|
1227
|
+
function buildShieldedWriteRequest(client, parameters, plaintextCalldata) {
|
|
1228
|
+
const { address, gas, gasPrice, value, nonce } = parameters;
|
|
1229
|
+
return {
|
|
1230
|
+
account: client.account,
|
|
1231
|
+
chain: undefined,
|
|
1232
|
+
to: address,
|
|
1233
|
+
data: plaintextCalldata,
|
|
1234
|
+
nonce,
|
|
1235
|
+
value,
|
|
1236
|
+
gas,
|
|
1237
|
+
gasPrice
|
|
1238
|
+
};
|
|
1239
|
+
}
|
|
1080
1240
|
|
|
1081
1241
|
// src/viem-internal/function.ts
|
|
1082
1242
|
function getFunctionParameters(values) {
|
|
@@ -1092,7 +1252,7 @@ function getShieldedContract({
|
|
|
1092
1252
|
address,
|
|
1093
1253
|
client
|
|
1094
1254
|
}) {
|
|
1095
|
-
const viemContract =
|
|
1255
|
+
const viemContract = import_viem13.getContract({ abi, address, client });
|
|
1096
1256
|
const walletClient = (() => {
|
|
1097
1257
|
if (!client)
|
|
1098
1258
|
return;
|
|
@@ -1100,6 +1260,17 @@ function getShieldedContract({
|
|
|
1100
1260
|
return client.wallet;
|
|
1101
1261
|
return client;
|
|
1102
1262
|
})();
|
|
1263
|
+
const readClient = (() => {
|
|
1264
|
+
if (!client)
|
|
1265
|
+
return;
|
|
1266
|
+
if ("public" in client) {
|
|
1267
|
+
return client.public;
|
|
1268
|
+
}
|
|
1269
|
+
if ("wallet" in client) {
|
|
1270
|
+
return client.wallet;
|
|
1271
|
+
}
|
|
1272
|
+
return client;
|
|
1273
|
+
})();
|
|
1103
1274
|
const transparentWriteAction = new Proxy({}, {
|
|
1104
1275
|
get(_, functionName) {
|
|
1105
1276
|
return (...parameters) => {
|
|
@@ -1107,7 +1278,7 @@ function getShieldedContract({
|
|
|
1107
1278
|
throw new Error("Must provide wallet client to call Contract.write");
|
|
1108
1279
|
}
|
|
1109
1280
|
const { args, options } = getFunctionParameters(parameters);
|
|
1110
|
-
return
|
|
1281
|
+
return transparentWriteContract(walletClient, {
|
|
1111
1282
|
abi,
|
|
1112
1283
|
address,
|
|
1113
1284
|
functionName,
|
|
@@ -1149,6 +1320,22 @@ function getShieldedContract({
|
|
|
1149
1320
|
...options
|
|
1150
1321
|
});
|
|
1151
1322
|
}
|
|
1323
|
+
function smartWrite({
|
|
1324
|
+
functionName,
|
|
1325
|
+
args,
|
|
1326
|
+
...options
|
|
1327
|
+
}) {
|
|
1328
|
+
if (walletClient === undefined) {
|
|
1329
|
+
throw new Error("Must provide wallet client to call Contract.write");
|
|
1330
|
+
}
|
|
1331
|
+
return smartWriteContract(walletClient, {
|
|
1332
|
+
abi,
|
|
1333
|
+
address,
|
|
1334
|
+
functionName,
|
|
1335
|
+
args,
|
|
1336
|
+
...options
|
|
1337
|
+
});
|
|
1338
|
+
}
|
|
1152
1339
|
const shieldedWriteAction = new Proxy({}, {
|
|
1153
1340
|
get(_, functionName) {
|
|
1154
1341
|
return (...parameters) => {
|
|
@@ -1183,25 +1370,29 @@ function getShieldedContract({
|
|
|
1183
1370
|
}
|
|
1184
1371
|
return signedReadContract(walletClient, params);
|
|
1185
1372
|
}
|
|
1186
|
-
|
|
1373
|
+
function smartRead(params) {
|
|
1374
|
+
if (readClient === undefined) {
|
|
1375
|
+
throw new Error("Must provide a client to call Contract.read");
|
|
1376
|
+
}
|
|
1377
|
+
return smartReadContract(walletClient, readClient, params, undefined, walletClient?.account);
|
|
1378
|
+
}
|
|
1379
|
+
const transparentReadAction = new Proxy({}, {
|
|
1187
1380
|
get(_, functionName) {
|
|
1188
1381
|
return (...parameters) => {
|
|
1189
1382
|
const { args, options } = getFunctionParameters(parameters);
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
address,
|
|
1194
|
-
functionName,
|
|
1195
|
-
args,
|
|
1196
|
-
...options
|
|
1197
|
-
});
|
|
1383
|
+
const opts = options;
|
|
1384
|
+
if (opts?.account !== undefined) {
|
|
1385
|
+
throw new Error("Contract.tread is always transparent. Seismic zeroes out `from` on transparent `eth_call`, so `account` would be ignored on the node and cause silent bugs. Remove `account` or use `contract.sread`.");
|
|
1198
1386
|
}
|
|
1199
|
-
|
|
1387
|
+
if (readClient === undefined) {
|
|
1388
|
+
throw new Error("Must provide a client to call Contract.tread");
|
|
1389
|
+
}
|
|
1390
|
+
return transparentReadContract(readClient, {
|
|
1200
1391
|
abi,
|
|
1201
1392
|
address,
|
|
1202
1393
|
functionName,
|
|
1203
1394
|
args,
|
|
1204
|
-
...
|
|
1395
|
+
...opts
|
|
1205
1396
|
});
|
|
1206
1397
|
};
|
|
1207
1398
|
}
|
|
@@ -1216,7 +1407,7 @@ function getShieldedContract({
|
|
|
1216
1407
|
const params = getFunctionParameters(parameters);
|
|
1217
1408
|
const { args } = params;
|
|
1218
1409
|
const {
|
|
1219
|
-
options: { account, ...options }
|
|
1410
|
+
options: { account: _account, ...options }
|
|
1220
1411
|
} = params;
|
|
1221
1412
|
return signedRead({
|
|
1222
1413
|
abi,
|
|
@@ -1229,20 +1420,50 @@ function getShieldedContract({
|
|
|
1229
1420
|
};
|
|
1230
1421
|
}
|
|
1231
1422
|
});
|
|
1423
|
+
const smartReadAction = new Proxy({}, {
|
|
1424
|
+
get(_, functionName) {
|
|
1425
|
+
return (...parameters) => {
|
|
1426
|
+
const { args, options } = getFunctionParameters(parameters);
|
|
1427
|
+
return smartRead({
|
|
1428
|
+
abi,
|
|
1429
|
+
address,
|
|
1430
|
+
functionName,
|
|
1431
|
+
args,
|
|
1432
|
+
...options
|
|
1433
|
+
});
|
|
1434
|
+
};
|
|
1435
|
+
}
|
|
1436
|
+
});
|
|
1437
|
+
const smartWriteAction = new Proxy({}, {
|
|
1438
|
+
get(_, functionName) {
|
|
1439
|
+
return (...parameters) => {
|
|
1440
|
+
const { args, options } = getFunctionParameters(parameters);
|
|
1441
|
+
return smartWrite({
|
|
1442
|
+
abi,
|
|
1443
|
+
address,
|
|
1444
|
+
functionName,
|
|
1445
|
+
args,
|
|
1446
|
+
...options
|
|
1447
|
+
});
|
|
1448
|
+
};
|
|
1449
|
+
}
|
|
1450
|
+
});
|
|
1232
1451
|
const contract = viemContract;
|
|
1233
1452
|
contract.twrite = transparentWriteAction;
|
|
1234
|
-
contract.tread =
|
|
1235
|
-
contract.
|
|
1453
|
+
contract.tread = transparentReadAction;
|
|
1454
|
+
contract.swrite = shieldedWriteAction;
|
|
1455
|
+
contract.sread = signedReadAction;
|
|
1456
|
+
contract.write = smartWriteAction;
|
|
1457
|
+
contract.read = smartReadAction;
|
|
1236
1458
|
contract.dwrite = shieldedWriteDebugAction;
|
|
1237
|
-
contract.read = signedReadAction;
|
|
1238
1459
|
return contract;
|
|
1239
1460
|
}
|
|
1240
1461
|
// src/client.ts
|
|
1241
|
-
var
|
|
1242
|
-
var
|
|
1462
|
+
var import_viem24 = require("viem");
|
|
1463
|
+
var import_accounts4 = require("viem/accounts");
|
|
1243
1464
|
|
|
1244
1465
|
// src/actions/depositContract.ts
|
|
1245
|
-
var
|
|
1466
|
+
var import_actions6 = require("viem/actions");
|
|
1246
1467
|
|
|
1247
1468
|
// src/abis/depositContract.ts
|
|
1248
1469
|
var depositContractAbi = [
|
|
@@ -1330,19 +1551,19 @@ var depositContractAbi = [
|
|
|
1330
1551
|
// src/actions/depositContract.ts
|
|
1331
1552
|
var DEPOSIT_CONTRACT_ADDRESS = "0x00000000219ab540356cBB839Cbe05303d7705Fa";
|
|
1332
1553
|
var depositContractPublicActions = (client) => ({
|
|
1333
|
-
getDepositRoot: async (args) =>
|
|
1554
|
+
getDepositRoot: async (args) => import_actions6.readContract(client, {
|
|
1334
1555
|
abi: depositContractAbi,
|
|
1335
1556
|
address: args.address || DEPOSIT_CONTRACT_ADDRESS,
|
|
1336
1557
|
functionName: "get_deposit_root"
|
|
1337
1558
|
}),
|
|
1338
|
-
getDepositCount: async (args) =>
|
|
1559
|
+
getDepositCount: async (args) => import_actions6.readContract(client, {
|
|
1339
1560
|
abi: depositContractAbi,
|
|
1340
1561
|
address: args.address || DEPOSIT_CONTRACT_ADDRESS,
|
|
1341
1562
|
functionName: "get_deposit_count"
|
|
1342
1563
|
})
|
|
1343
1564
|
});
|
|
1344
1565
|
var depositContractWalletActions = (client) => ({
|
|
1345
|
-
deposit: async (args) =>
|
|
1566
|
+
deposit: async (args) => import_actions6.writeContract(client, {
|
|
1346
1567
|
abi: depositContractAbi,
|
|
1347
1568
|
address: args.address || DEPOSIT_CONTRACT_ADDRESS,
|
|
1348
1569
|
functionName: "deposit",
|
|
@@ -1359,7 +1580,7 @@ var depositContractWalletActions = (client) => ({
|
|
|
1359
1580
|
});
|
|
1360
1581
|
|
|
1361
1582
|
// src/crypto/aead.ts
|
|
1362
|
-
var
|
|
1583
|
+
var import_viem14 = require("viem");
|
|
1363
1584
|
var encodeSeismicMetadataAsAAD = ({
|
|
1364
1585
|
sender,
|
|
1365
1586
|
legacyFields: { chainId, nonce, to, value },
|
|
@@ -1374,22 +1595,22 @@ var encodeSeismicMetadataAsAAD = ({
|
|
|
1374
1595
|
}) => {
|
|
1375
1596
|
const fields = [
|
|
1376
1597
|
sender,
|
|
1377
|
-
|
|
1378
|
-
nonce === 0 ? "0x" :
|
|
1598
|
+
import_viem14.toHex(chainId),
|
|
1599
|
+
nonce === 0 ? "0x" : import_viem14.toHex(nonce),
|
|
1379
1600
|
to ?? "0x",
|
|
1380
|
-
value === 0n ? "0x" :
|
|
1601
|
+
value === 0n ? "0x" : import_viem14.toHex(value),
|
|
1381
1602
|
encryptionPubkey,
|
|
1382
1603
|
encryptionNonce === "0x00" || encryptionNonce === "0x0" ? "0x" : encryptionNonce,
|
|
1383
|
-
messageVersion === 0 ? "0x" :
|
|
1604
|
+
messageVersion === 0 ? "0x" : import_viem14.toHex(messageVersion),
|
|
1384
1605
|
recentBlockHash,
|
|
1385
|
-
|
|
1606
|
+
import_viem14.toHex(expiresAtBlock),
|
|
1386
1607
|
signedRead ? "0x01" : "0x"
|
|
1387
1608
|
];
|
|
1388
|
-
return
|
|
1609
|
+
return import_viem14.toRlp(fields, "bytes");
|
|
1389
1610
|
};
|
|
1390
1611
|
|
|
1391
1612
|
// src/crypto/aes.ts
|
|
1392
|
-
var
|
|
1613
|
+
var import_viem15 = require("viem");
|
|
1393
1614
|
|
|
1394
1615
|
// ../../node_modules/@noble/hashes/esm/_assert.js
|
|
1395
1616
|
function anumber2(n) {
|
|
@@ -3425,7 +3646,7 @@ var _0n5 = BigInt(0);
|
|
|
3425
3646
|
var Point = secp256k1.ProjectivePoint;
|
|
3426
3647
|
|
|
3427
3648
|
// ../../node_modules/@noble/hashes/esm/hkdf.js
|
|
3428
|
-
function
|
|
3649
|
+
function extract2(hash, ikm, salt) {
|
|
3429
3650
|
ahash(hash);
|
|
3430
3651
|
if (salt === undefined)
|
|
3431
3652
|
salt = new Uint8Array(hash.outputLen);
|
|
@@ -3457,7 +3678,7 @@ function expand(hash, prk, info, length = 32) {
|
|
|
3457
3678
|
HKDF_COUNTER.fill(0);
|
|
3458
3679
|
return okm.slice(0, length);
|
|
3459
3680
|
}
|
|
3460
|
-
var hkdf = (hash, ikm, salt, info, length) => expand(hash,
|
|
3681
|
+
var hkdf = (hash, ikm, salt, info, length) => expand(hash, extract2(hash, ikm, salt), info, length);
|
|
3461
3682
|
|
|
3462
3683
|
// src/crypto/aes.ts
|
|
3463
3684
|
class AesGcmCrypto {
|
|
@@ -3466,7 +3687,7 @@ class AesGcmCrypto {
|
|
|
3466
3687
|
U64_SIZE = 8;
|
|
3467
3688
|
constructor(key) {
|
|
3468
3689
|
this.key = key;
|
|
3469
|
-
const keyBuffer =
|
|
3690
|
+
const keyBuffer = import_viem15.hexToBytes(key);
|
|
3470
3691
|
if (keyBuffer.length !== 32) {
|
|
3471
3692
|
throw new Error("Key must be 32 bytes (256 bits)");
|
|
3472
3693
|
}
|
|
@@ -3481,34 +3702,34 @@ class AesGcmCrypto {
|
|
|
3481
3702
|
return nonceBuffer;
|
|
3482
3703
|
}
|
|
3483
3704
|
validateAndConvertNonce(nonce) {
|
|
3484
|
-
const nonceBuffer =
|
|
3705
|
+
const nonceBuffer = import_viem15.hexToBytes(nonce);
|
|
3485
3706
|
if (nonceBuffer.length !== this.NONCE_LENGTH) {
|
|
3486
3707
|
throw new Error("Nonce must be 12 bytes");
|
|
3487
3708
|
}
|
|
3488
3709
|
return nonceBuffer;
|
|
3489
3710
|
}
|
|
3490
3711
|
createNonce(num) {
|
|
3491
|
-
return
|
|
3712
|
+
return import_viem15.bytesToHex(this.numberToNonce(num));
|
|
3492
3713
|
}
|
|
3493
3714
|
async encrypt(plaintext, nonce, aad) {
|
|
3494
3715
|
if (!plaintext || plaintext === "0x") {
|
|
3495
3716
|
return "0x";
|
|
3496
3717
|
}
|
|
3497
3718
|
const nonceBuffer = new Uint8Array(typeof nonce === "string" ? this.validateAndConvertNonce(nonce) : this.numberToNonce(nonce));
|
|
3498
|
-
const key =
|
|
3499
|
-
const plaintextBytes =
|
|
3719
|
+
const key = import_viem15.hexToBytes(this.key);
|
|
3720
|
+
const plaintextBytes = import_viem15.hexToBytes(plaintext);
|
|
3500
3721
|
const ciphertextBytes = await gcm(key, nonceBuffer, aad).encrypt(plaintextBytes);
|
|
3501
|
-
return
|
|
3722
|
+
return import_viem15.bytesToHex(ciphertextBytes);
|
|
3502
3723
|
}
|
|
3503
3724
|
async decrypt(ciphertext, nonce, aad) {
|
|
3504
3725
|
if (!ciphertext || ciphertext === "0x") {
|
|
3505
3726
|
return "0x";
|
|
3506
3727
|
}
|
|
3507
3728
|
const nonceBuffer = new Uint8Array(typeof nonce === "string" ? this.validateAndConvertNonce(nonce) : this.numberToNonce(nonce));
|
|
3508
|
-
const key =
|
|
3509
|
-
const ciphertextBytes =
|
|
3729
|
+
const key = import_viem15.hexToBytes(this.key);
|
|
3730
|
+
const ciphertextBytes = import_viem15.hexToBytes(ciphertext);
|
|
3510
3731
|
const plaintextBytes = await gcm(key, nonceBuffer, aad).decrypt(ciphertextBytes);
|
|
3511
|
-
return
|
|
3732
|
+
return import_viem15.bytesToHex(plaintextBytes);
|
|
3512
3733
|
}
|
|
3513
3734
|
}
|
|
3514
3735
|
var sharedSecretPoint = ({
|
|
@@ -3521,15 +3742,15 @@ var sharedSecretPoint = ({
|
|
|
3521
3742
|
var sharedKeyFromPoint = (sharedSecret) => {
|
|
3522
3743
|
const version = sharedSecret[63] & 1 | 2;
|
|
3523
3744
|
const finalSecret = sha2562.create().update(new Uint8Array([version])).update(sharedSecret.slice(0, 32)).digest();
|
|
3524
|
-
return
|
|
3745
|
+
return import_viem15.bytesToHex(finalSecret).slice(2);
|
|
3525
3746
|
};
|
|
3526
3747
|
var generateSharedKey = (inputs) => {
|
|
3527
3748
|
const sharedSecret = sharedSecretPoint(inputs);
|
|
3528
3749
|
return sharedKeyFromPoint(sharedSecret);
|
|
3529
3750
|
};
|
|
3530
3751
|
var deriveAesKey = (sharedSecret) => {
|
|
3531
|
-
const derivedKey = hkdf(sha2562,
|
|
3532
|
-
return
|
|
3752
|
+
const derivedKey = hkdf(sha2562, import_viem15.hexToBytes(`0x${sharedSecret}`), new Uint8Array(0), new TextEncoder().encode("aes-gcm key"), 32);
|
|
3753
|
+
return import_viem15.bytesToHex(derivedKey);
|
|
3533
3754
|
};
|
|
3534
3755
|
var generateAesKey = (aesKeys) => {
|
|
3535
3756
|
const sharedSecret = generateSharedKey(aesKeys);
|
|
@@ -3619,13 +3840,13 @@ var tokenExplorerUrl = ({
|
|
|
3619
3840
|
};
|
|
3620
3841
|
|
|
3621
3842
|
// src/precompiles/aes.ts
|
|
3622
|
-
var
|
|
3843
|
+
var import_viem17 = require("viem");
|
|
3623
3844
|
|
|
3624
3845
|
// src/precompiles/precompile.ts
|
|
3625
|
-
var
|
|
3846
|
+
var import_viem16 = require("viem");
|
|
3626
3847
|
var BASE_TX_GAS_COST = 21000n;
|
|
3627
3848
|
var calldataGasCost = (data) => {
|
|
3628
|
-
const dataBytes =
|
|
3849
|
+
const dataBytes = import_viem16.hexToBytes(data);
|
|
3629
3850
|
const nonZeroBytes = dataBytes.filter((b) => b !== 0).length;
|
|
3630
3851
|
return 4n * BigInt(dataBytes.length) + 12n * BigInt(nonZeroBytes);
|
|
3631
3852
|
};
|
|
@@ -3672,7 +3893,7 @@ var AES_GCM_PER_BLOCK = 30n;
|
|
|
3672
3893
|
var MIN_AES_PLAINTEXT_LENGTH = 0;
|
|
3673
3894
|
var MIN_AES_CIPHERTEXT_LENGTH = 16;
|
|
3674
3895
|
var aesGcmGasCost = (value) => {
|
|
3675
|
-
const valueBytes =
|
|
3896
|
+
const valueBytes = import_viem17.isHex(value) ? import_viem17.hexToBytes(value) : import_viem17.stringToBytes(value);
|
|
3676
3897
|
return calcLinearGasCost({
|
|
3677
3898
|
bus: 16,
|
|
3678
3899
|
len: valueBytes.length,
|
|
@@ -3682,21 +3903,21 @@ var aesGcmGasCost = (value) => {
|
|
|
3682
3903
|
};
|
|
3683
3904
|
var validateParams = (args, encryption) => {
|
|
3684
3905
|
const [aesKey, nonce, input] = args;
|
|
3685
|
-
const aesKeyBytes =
|
|
3906
|
+
const aesKeyBytes = import_viem17.hexToBytes(aesKey);
|
|
3686
3907
|
if (aesKeyBytes.length !== 32) {
|
|
3687
3908
|
throw new Error(`Invalid AES key: expected 32 bytes but found ${aesKeyBytes.length}`);
|
|
3688
3909
|
}
|
|
3689
|
-
const nonceBytes =
|
|
3910
|
+
const nonceBytes = import_viem17.numberToBytes(nonce, { size: 12 });
|
|
3690
3911
|
if (nonceBytes.length !== 12) {
|
|
3691
3912
|
throw new Error(`Invalid nonce: expected 12 bytes but found ${nonceBytes.length}`);
|
|
3692
3913
|
}
|
|
3693
3914
|
if (encryption) {
|
|
3694
|
-
const plaintextBytes =
|
|
3915
|
+
const plaintextBytes = import_viem17.stringToBytes(input);
|
|
3695
3916
|
if (plaintextBytes.length < MIN_AES_PLAINTEXT_LENGTH) {
|
|
3696
3917
|
throw new Error(`Invalid plaintext: expected at least ${MIN_AES_PLAINTEXT_LENGTH} bytes but found ${plaintextBytes.length}`);
|
|
3697
3918
|
}
|
|
3698
3919
|
} else {
|
|
3699
|
-
const ciphertextBytes =
|
|
3920
|
+
const ciphertextBytes = import_viem17.hexToBytes(input);
|
|
3700
3921
|
if (ciphertextBytes.length < MIN_AES_CIPHERTEXT_LENGTH) {
|
|
3701
3922
|
throw new Error(`Invalid ciphertext: expected at least ${MIN_AES_CIPHERTEXT_LENGTH} bytes but found ${ciphertextBytes.length}`);
|
|
3702
3923
|
}
|
|
@@ -3708,21 +3929,21 @@ var aesGcmEncryptPrecompile = {
|
|
|
3708
3929
|
gasCost: (args) => aesGcmGasCost(args.plaintext),
|
|
3709
3930
|
encodeParams: (args) => {
|
|
3710
3931
|
const [aesKey, nonce, plaintext] = validateParams([args.aesKey, args.nonce, args.plaintext], true);
|
|
3711
|
-
const nonceHex =
|
|
3712
|
-
const plaintextHex =
|
|
3932
|
+
const nonceHex = import_viem17.numberToHex(nonce, { size: 12 });
|
|
3933
|
+
const plaintextHex = import_viem17.stringToHex(plaintext);
|
|
3713
3934
|
return `${aesKey}${nonceHex.slice(2)}${plaintextHex.slice(2)}`;
|
|
3714
3935
|
},
|
|
3715
|
-
decodeResult: (result) =>
|
|
3936
|
+
decodeResult: (result) => import_viem17.trim(result)
|
|
3716
3937
|
};
|
|
3717
3938
|
var aesGcmDecryptPrecompile = {
|
|
3718
3939
|
address: AES_GCM_DECRYPT_ADDRESS,
|
|
3719
3940
|
gasCost: (args) => aesGcmGasCost(args.ciphertext),
|
|
3720
3941
|
encodeParams: (args) => {
|
|
3721
3942
|
const [aesKey, nonce, cipherText] = validateParams([args.aesKey, args.nonce, args.ciphertext], false);
|
|
3722
|
-
const nonceHex =
|
|
3943
|
+
const nonceHex = import_viem17.numberToHex(nonce, { size: 12 });
|
|
3723
3944
|
return `${aesKey}${nonceHex.slice(2)}${cipherText.slice(2)}`;
|
|
3724
3945
|
},
|
|
3725
|
-
decodeResult: (result) =>
|
|
3946
|
+
decodeResult: (result) => import_viem17.hexToString(import_viem17.trim(result))
|
|
3726
3947
|
};
|
|
3727
3948
|
var aesGcmEncrypt = async (client, args) => {
|
|
3728
3949
|
return callPrecompile({
|
|
@@ -3740,10 +3961,10 @@ var aesGcmDecrypt = async (client, args) => {
|
|
|
3740
3961
|
};
|
|
3741
3962
|
|
|
3742
3963
|
// src/precompiles/ecdh.ts
|
|
3743
|
-
var
|
|
3964
|
+
var import_viem19 = require("viem");
|
|
3744
3965
|
|
|
3745
3966
|
// src/precompiles/hkdf.ts
|
|
3746
|
-
var
|
|
3967
|
+
var import_viem18 = require("viem");
|
|
3747
3968
|
var HKDF_ADDRESS = "0x0000000000000000000000000000000000000068";
|
|
3748
3969
|
var SHA256_BASE_GAS = 60n;
|
|
3749
3970
|
var SHA256_PER_WORD = 12n;
|
|
@@ -3752,7 +3973,7 @@ var SHARED_SECRET_GAS = 3000n;
|
|
|
3752
3973
|
var hdfkPrecompile = {
|
|
3753
3974
|
address: HKDF_ADDRESS,
|
|
3754
3975
|
gasCost: (ikmHex) => {
|
|
3755
|
-
const ikmBytes =
|
|
3976
|
+
const ikmBytes = import_viem18.isHex(ikmHex) ? import_viem18.hexToBytes(ikmHex) : import_viem18.stringToBytes(ikmHex);
|
|
3756
3977
|
const linearGasCost = calcLinearGasCost({
|
|
3757
3978
|
bus: 32,
|
|
3758
3979
|
len: ikmBytes.length,
|
|
@@ -3762,13 +3983,13 @@ var hdfkPrecompile = {
|
|
|
3762
3983
|
return 2n * linearGasCost + HKDF_EXPAND_COST_GAS;
|
|
3763
3984
|
},
|
|
3764
3985
|
encodeParams: (input) => {
|
|
3765
|
-
if (
|
|
3986
|
+
if (import_viem18.isHex(input)) {
|
|
3766
3987
|
return input;
|
|
3767
3988
|
}
|
|
3768
|
-
return
|
|
3989
|
+
return import_viem18.stringToHex(input);
|
|
3769
3990
|
},
|
|
3770
3991
|
decodeResult: (result) => {
|
|
3771
|
-
const [output] =
|
|
3992
|
+
const [output] = import_viem18.decodeAbiParameters([{ type: "bytes32" }], result);
|
|
3772
3993
|
return output;
|
|
3773
3994
|
}
|
|
3774
3995
|
};
|
|
@@ -3785,7 +4006,7 @@ var ECDH_ADDRESS = "0x0000000000000000000000000000000000000065";
|
|
|
3785
4006
|
var SECRET_KEY_LENGTH = 32;
|
|
3786
4007
|
var PUBLIC_KEY_LENGTH = 33;
|
|
3787
4008
|
var validateKey = (key, sk) => {
|
|
3788
|
-
const bytes =
|
|
4009
|
+
const bytes = import_viem19.hexToBytes(key);
|
|
3789
4010
|
const expectedLength = sk ? SECRET_KEY_LENGTH : PUBLIC_KEY_LENGTH;
|
|
3790
4011
|
if (bytes.length !== expectedLength) {
|
|
3791
4012
|
throw new Error(`Invalid ${sk ? "secret" : "public"} key: must be ${expectedLength} bytes (received ${bytes.length})`);
|
|
@@ -3800,7 +4021,7 @@ var ecdhPrecompile = {
|
|
|
3800
4021
|
return `${sk}${pk.slice(2)}`;
|
|
3801
4022
|
},
|
|
3802
4023
|
decodeResult: (result) => {
|
|
3803
|
-
const [output] =
|
|
4024
|
+
const [output] = import_viem19.decodeAbiParameters([{ type: "bytes32" }], result);
|
|
3804
4025
|
return output;
|
|
3805
4026
|
}
|
|
3806
4027
|
};
|
|
@@ -3813,7 +4034,7 @@ var ecdh = async (client, args) => {
|
|
|
3813
4034
|
};
|
|
3814
4035
|
|
|
3815
4036
|
// src/precompiles/rng.ts
|
|
3816
|
-
var
|
|
4037
|
+
var import_viem20 = require("viem");
|
|
3817
4038
|
var RNG_ADDRESS = "0x0000000000000000000000000000000000000064";
|
|
3818
4039
|
var RNG_INIT_BASE_GAS = 3500n;
|
|
3819
4040
|
var STROBE_128_WORD_GAS = 5n;
|
|
@@ -3821,9 +4042,9 @@ var persToBytes = (pers) => {
|
|
|
3821
4042
|
if (!pers) {
|
|
3822
4043
|
return new Uint8Array;
|
|
3823
4044
|
}
|
|
3824
|
-
if (
|
|
3825
|
-
return
|
|
3826
|
-
} else if (
|
|
4045
|
+
if (import_viem20.isHex(pers)) {
|
|
4046
|
+
return import_viem20.hexToBytes(pers);
|
|
4047
|
+
} else if (import_viem20.isBytes(pers)) {
|
|
3827
4048
|
return pers;
|
|
3828
4049
|
}
|
|
3829
4050
|
throw new Error("Invalid pers: must be a hex or bytes array");
|
|
@@ -3850,15 +4071,15 @@ var rngPrecompile = {
|
|
|
3850
4071
|
if (BigInt(numBytes) > 32n) {
|
|
3851
4072
|
throw new Error("Invalid length: must be less than or equal to 32");
|
|
3852
4073
|
}
|
|
3853
|
-
const encodedBytes =
|
|
4074
|
+
const encodedBytes = import_viem20.numberToHex(numBytes, { size: 4 });
|
|
3854
4075
|
if (!pers) {
|
|
3855
4076
|
return encodedBytes;
|
|
3856
4077
|
}
|
|
3857
|
-
const encodedPers =
|
|
4078
|
+
const encodedPers = import_viem20.bytesToHex(persToBytes(pers));
|
|
3858
4079
|
return `${encodedBytes}${encodedPers.slice(2)}`;
|
|
3859
4080
|
},
|
|
3860
4081
|
decodeResult: (result) => {
|
|
3861
|
-
const [output] =
|
|
4082
|
+
const [output] = import_viem20.decodeAbiParameters([{ type: "uint256" }], import_viem20.pad(result));
|
|
3862
4083
|
return output;
|
|
3863
4084
|
}
|
|
3864
4085
|
};
|
|
@@ -3871,7 +4092,7 @@ var rng = async (client, args) => {
|
|
|
3871
4092
|
};
|
|
3872
4093
|
|
|
3873
4094
|
// src/precompiles/secp256k1.ts
|
|
3874
|
-
var
|
|
4095
|
+
var import_viem21 = require("viem");
|
|
3875
4096
|
var SECP256K1_SIG_ADDRESS = "0x0000000000000000000000000000000000000069";
|
|
3876
4097
|
var SECP256K1_SIG_BASE_GAS = 3000n;
|
|
3877
4098
|
var secp256k1SigPrecompile = {
|
|
@@ -3883,9 +4104,9 @@ var secp256k1SigPrecompile = {
|
|
|
3883
4104
|
{ name: "messageHash", type: "bytes32" }
|
|
3884
4105
|
];
|
|
3885
4106
|
const skHex = sk;
|
|
3886
|
-
return
|
|
4107
|
+
return import_viem21.encodeAbiParameters(params, [skHex, import_viem21.hashMessage(message)]);
|
|
3887
4108
|
},
|
|
3888
|
-
decodeResult:
|
|
4109
|
+
decodeResult: import_viem21.parseSignature
|
|
3889
4110
|
};
|
|
3890
4111
|
var secp256k1Sig = async (client, args) => {
|
|
3891
4112
|
return callPrecompile({
|
|
@@ -4133,7 +4354,7 @@ function parseEncryptedData(encryptedData) {
|
|
|
4133
4354
|
}
|
|
4134
4355
|
|
|
4135
4356
|
// src/actions/src20/directory.ts
|
|
4136
|
-
var
|
|
4357
|
+
var import_viem22 = require("viem");
|
|
4137
4358
|
|
|
4138
4359
|
// src/abis/directory.ts
|
|
4139
4360
|
var DIRECTORY_ADDRESS = "0x1000000000000000000000000000000000000004";
|
|
@@ -4211,7 +4432,7 @@ async function registerKey(client, aesKey) {
|
|
|
4211
4432
|
return withTimeout(txPromise, TX_TIMEOUT_MS);
|
|
4212
4433
|
}
|
|
4213
4434
|
function computeKeyHash(aesKey) {
|
|
4214
|
-
return
|
|
4435
|
+
return import_viem22.keccak256(aesKey);
|
|
4215
4436
|
}
|
|
4216
4437
|
|
|
4217
4438
|
// src/actions/src20/watchSRC20Events.ts
|
|
@@ -4348,47 +4569,143 @@ var src20WalletActions = (client) => ({
|
|
|
4348
4569
|
watchSRC20Events: (params) => watchSRC20Events(client, params)
|
|
4349
4570
|
});
|
|
4350
4571
|
|
|
4572
|
+
// src/tx/sendTransparent.ts
|
|
4573
|
+
var import_accounts3 = require("viem/accounts");
|
|
4574
|
+
var import_actions7 = require("viem/actions");
|
|
4575
|
+
var import_utils13 = require("viem/utils");
|
|
4576
|
+
var DEFAULT_SIGNED_ESTIMATE_GAS_LIMIT = 30000000n;
|
|
4577
|
+
async function sendTransparentTransaction(client, parameters) {
|
|
4578
|
+
const {
|
|
4579
|
+
account: account_ = client.account,
|
|
4580
|
+
chain = client.chain,
|
|
4581
|
+
accessList,
|
|
4582
|
+
authorizationList,
|
|
4583
|
+
blobs,
|
|
4584
|
+
data,
|
|
4585
|
+
gas,
|
|
4586
|
+
gasPrice,
|
|
4587
|
+
maxFeePerBlobGas,
|
|
4588
|
+
maxFeePerGas,
|
|
4589
|
+
maxPriorityFeePerGas,
|
|
4590
|
+
nonce,
|
|
4591
|
+
value,
|
|
4592
|
+
...rest
|
|
4593
|
+
} = parameters;
|
|
4594
|
+
if (typeof account_ === "undefined")
|
|
4595
|
+
throw new AccountNotFoundError({
|
|
4596
|
+
docsPath: "/docs/actions/wallet/sendTransaction"
|
|
4597
|
+
});
|
|
4598
|
+
const account = account_ ? import_accounts3.parseAccount(account_) : null;
|
|
4599
|
+
try {
|
|
4600
|
+
import_utils13.assertRequest(parameters);
|
|
4601
|
+
const to = await (async () => {
|
|
4602
|
+
if (parameters.to)
|
|
4603
|
+
return parameters.to;
|
|
4604
|
+
return;
|
|
4605
|
+
})();
|
|
4606
|
+
if (account?.type !== "local") {
|
|
4607
|
+
return await import_actions7.sendTransaction(client, parameters);
|
|
4608
|
+
}
|
|
4609
|
+
const request = await import_actions7.prepareTransactionRequest(client, {
|
|
4610
|
+
account,
|
|
4611
|
+
accessList,
|
|
4612
|
+
authorizationList,
|
|
4613
|
+
blobs,
|
|
4614
|
+
chain,
|
|
4615
|
+
data,
|
|
4616
|
+
gasPrice,
|
|
4617
|
+
maxFeePerBlobGas,
|
|
4618
|
+
maxFeePerGas,
|
|
4619
|
+
maxPriorityFeePerGas,
|
|
4620
|
+
nonce,
|
|
4621
|
+
nonceManager: account.nonceManager,
|
|
4622
|
+
parameters: [
|
|
4623
|
+
"blobVersionedHashes",
|
|
4624
|
+
"chainId",
|
|
4625
|
+
"fees",
|
|
4626
|
+
"nonce",
|
|
4627
|
+
"type",
|
|
4628
|
+
"sidecars"
|
|
4629
|
+
],
|
|
4630
|
+
value,
|
|
4631
|
+
...rest,
|
|
4632
|
+
to
|
|
4633
|
+
});
|
|
4634
|
+
const serializer = chain?.serializers?.transaction;
|
|
4635
|
+
const gasEstimate = gas ?? BigInt(await client.request({
|
|
4636
|
+
method: "eth_estimateGas",
|
|
4637
|
+
params: [
|
|
4638
|
+
await account.signTransaction({
|
|
4639
|
+
...request,
|
|
4640
|
+
gas: DEFAULT_SIGNED_ESTIMATE_GAS_LIMIT
|
|
4641
|
+
}, { serializer })
|
|
4642
|
+
]
|
|
4643
|
+
}, { retryCount: 0 }));
|
|
4644
|
+
const serializedTransaction = await account.signTransaction({
|
|
4645
|
+
...request,
|
|
4646
|
+
gas: gasEstimate
|
|
4647
|
+
}, { serializer });
|
|
4648
|
+
return await import_utils13.getAction(client, import_actions7.sendRawTransaction, "sendRawTransaction")({
|
|
4649
|
+
serializedTransaction
|
|
4650
|
+
});
|
|
4651
|
+
} catch (err) {
|
|
4652
|
+
throw import_utils13.getTransactionError(err, {
|
|
4653
|
+
...parameters,
|
|
4654
|
+
account,
|
|
4655
|
+
chain: parameters.chain || undefined
|
|
4656
|
+
});
|
|
4657
|
+
}
|
|
4658
|
+
}
|
|
4659
|
+
|
|
4351
4660
|
// src/actions/wallet.ts
|
|
4352
|
-
var import_actions6 = require("viem/actions");
|
|
4353
4661
|
var shieldedWalletActions = (client) => {
|
|
4354
4662
|
return {
|
|
4355
|
-
|
|
4356
|
-
|
|
4357
|
-
|
|
4358
|
-
|
|
4663
|
+
sendTransaction: (args) => sendTransparentTransaction(client, args),
|
|
4664
|
+
writeContract: (args) => smartWriteContract(client, args),
|
|
4665
|
+
swriteContract: (args, securityParams) => shieldedWriteContract(client, args, securityParams),
|
|
4666
|
+
twriteContract: (args) => transparentWriteContract(client, args),
|
|
4667
|
+
dwriteContract: (args, securityParams) => {
|
|
4668
|
+
const debugResult = shieldedWriteContractDebug(client, args, undefined, securityParams);
|
|
4359
4669
|
return debugResult;
|
|
4360
4670
|
},
|
|
4361
|
-
readContract: (args
|
|
4362
|
-
|
|
4671
|
+
readContract: (args) => smartReadContract(client, client, args),
|
|
4672
|
+
sreadContract: (args, securityParams) => signedReadContract(client, args, securityParams),
|
|
4673
|
+
treadContract: (args) => {
|
|
4674
|
+
const readArgs = args;
|
|
4675
|
+
if (readArgs.account !== undefined) {
|
|
4676
|
+
throw new Error("walletClient.treadContract is always transparent. Seismic zeroes out `from` on transparent `eth_call`, so `account` would be ignored on the node and cause silent bugs. Remove `account` or use `walletClient.sreadContract`.");
|
|
4677
|
+
}
|
|
4678
|
+
return transparentReadContract(client, args);
|
|
4679
|
+
},
|
|
4363
4680
|
signedCall: (args, securityParams) => signedCall(client, args, securityParams),
|
|
4364
4681
|
sendShieldedTransaction: (args, securityParams) => sendShieldedTransaction(client, args, securityParams)
|
|
4365
4682
|
};
|
|
4366
4683
|
};
|
|
4367
4684
|
|
|
4368
4685
|
// src/crypto/secp.ts
|
|
4369
|
-
var
|
|
4686
|
+
var import_viem23 = require("viem");
|
|
4370
4687
|
var compressPublicKey = (uncompressedKey) => {
|
|
4371
4688
|
const cleanKey = uncompressedKey.replace("0x", "");
|
|
4372
4689
|
if (cleanKey.length !== 130) {
|
|
4373
4690
|
throw new Error("Invalid uncompressed public key length");
|
|
4374
4691
|
}
|
|
4375
4692
|
const pt = secp256k1.ProjectivePoint.fromHex(cleanKey);
|
|
4376
|
-
return
|
|
4693
|
+
return import_viem23.bytesToHex(pt.toRawBytes(true));
|
|
4377
4694
|
};
|
|
4378
4695
|
|
|
4379
4696
|
// src/client.ts
|
|
4380
4697
|
var getEncryption = (networkPk, clientSk) => {
|
|
4381
|
-
const encryptionPrivateKey = clientSk ??
|
|
4698
|
+
const encryptionPrivateKey = clientSk ?? import_accounts4.generatePrivateKey();
|
|
4382
4699
|
const aesKey = generateAesKey({
|
|
4383
4700
|
privateKey: encryptionPrivateKey,
|
|
4384
4701
|
networkPublicKey: networkPk
|
|
4385
4702
|
});
|
|
4386
|
-
const uncompressedPk =
|
|
4703
|
+
const uncompressedPk = import_accounts4.privateKeyToAccount(encryptionPrivateKey).publicKey;
|
|
4387
4704
|
const encryptionPublicKey = compressPublicKey(uncompressedPk);
|
|
4388
4705
|
return { encryptionPrivateKey, encryptionPublicKey, aesKey };
|
|
4389
4706
|
};
|
|
4390
4707
|
var createShieldedPublicClient = (parameters) => {
|
|
4391
|
-
const viemPublicClient =
|
|
4708
|
+
const viemPublicClient = import_viem24.createPublicClient(parameters);
|
|
4392
4709
|
return viemPublicClient.extend(shieldedPublicActions).extend(depositContractPublicActions).extend(src20PublicActions);
|
|
4393
4710
|
};
|
|
4394
4711
|
var getSeismicClients = async ({
|
|
@@ -4404,12 +4721,12 @@ var getSeismicClients = async ({
|
|
|
4404
4721
|
});
|
|
4405
4722
|
const networkPublicKey = await pubClient.getTeePublicKey();
|
|
4406
4723
|
const { aesKey, encryptionPublicKey } = getEncryption(networkPublicKey, encryptionSk);
|
|
4407
|
-
const wallet =
|
|
4724
|
+
const wallet = import_viem24.createClient({
|
|
4408
4725
|
account,
|
|
4409
4726
|
chain,
|
|
4410
4727
|
transport,
|
|
4411
4728
|
rpcSchema: seismicRpcSchema
|
|
4412
|
-
}).extend(
|
|
4729
|
+
}).extend(import_viem24.walletActions).extend(() => import_viem24.publicActions(pubClient)).extend(() => encryptionActions(aesKey, encryptionPublicKey)).extend(() => shieldedPublicActions(pubClient)).extend(shieldedWalletActions).extend(depositContractWalletActions).extend(src20WalletActions);
|
|
4413
4730
|
return {
|
|
4414
4731
|
public: pubClient,
|
|
4415
4732
|
wallet
|
|
@@ -4432,11 +4749,11 @@ var createShieldedWalletClient = async ({
|
|
|
4432
4749
|
return clients.wallet;
|
|
4433
4750
|
};
|
|
4434
4751
|
// src/faucet.ts
|
|
4435
|
-
var
|
|
4436
|
-
var DEFAULT_MIN_BALANCE_WEI =
|
|
4752
|
+
var import_utils14 = require("viem/utils");
|
|
4753
|
+
var DEFAULT_MIN_BALANCE_WEI = import_utils14.parseEther("0.5");
|
|
4437
4754
|
var parseMinBalance = (minBalanceWei, minBalanceEther) => {
|
|
4438
4755
|
if (minBalanceWei && minBalanceEther) {
|
|
4439
|
-
if (BigInt(minBalanceWei) !==
|
|
4756
|
+
if (BigInt(minBalanceWei) !== import_utils14.parseEther(minBalanceEther.toString())) {
|
|
4440
4757
|
console.warn("Both minBalanceWei and minBalanceEther provided, using minBalanceWei");
|
|
4441
4758
|
}
|
|
4442
4759
|
}
|
|
@@ -4444,7 +4761,7 @@ var parseMinBalance = (minBalanceWei, minBalanceEther) => {
|
|
|
4444
4761
|
return BigInt(minBalanceWei);
|
|
4445
4762
|
}
|
|
4446
4763
|
if (minBalanceEther) {
|
|
4447
|
-
return
|
|
4764
|
+
return import_utils14.parseEther(minBalanceEther.toString());
|
|
4448
4765
|
}
|
|
4449
4766
|
return DEFAULT_MIN_BALANCE_WEI;
|
|
4450
4767
|
};
|