@toruslabs/ethereum-controllers 8.17.0 → 9.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/lib.cjs/Account/AccountTrackerController.js +15 -7
- package/dist/lib.cjs/AccountAbstraction/AccountAbstractionController.js +4 -6
- package/dist/lib.cjs/Eip5792/walletGetCallsStatus.js +2 -2
- package/dist/lib.cjs/Eip5792/walletSendCalls.js +8 -9
- package/dist/lib.cjs/Eip7702/eip7702Utils.js +3 -3
- package/dist/lib.cjs/Gas/GasFeeController.js +3 -2
- package/dist/lib.cjs/Keyring/KeyringController.js +69 -40
- package/dist/lib.cjs/Message/utils.js +15 -14
- package/dist/lib.cjs/Nfts/NftHandler.js +54 -12
- package/dist/lib.cjs/Nfts/NftsController.js +1 -4
- package/dist/lib.cjs/Preferences/PreferencesController.js +2 -2
- package/dist/lib.cjs/Tokens/TokenHandler.js +39 -7
- package/dist/lib.cjs/Tokens/TokensController.js +15 -7
- package/dist/lib.cjs/Transaction/TransactionController.js +17 -20
- package/dist/lib.cjs/Transaction/TransactionGasUtil.js +11 -12
- package/dist/lib.cjs/Transaction/TransactionUtils.js +44 -39
- package/dist/lib.cjs/index.js +0 -1
- package/dist/lib.cjs/types/Account/AccountTrackerController.d.ts +1 -1
- package/dist/lib.cjs/types/AccountAbstraction/AccountAbstractionController.d.ts +1 -3
- package/dist/lib.cjs/types/Keyring/KeyringController.d.ts +4 -4
- package/dist/lib.cjs/types/Nfts/NftHandler.d.ts +4 -3
- package/dist/lib.cjs/types/Nfts/NftsController.d.ts +0 -1
- package/dist/lib.cjs/types/Tokens/TokenHandler.d.ts +4 -3
- package/dist/lib.cjs/types/Tokens/TokensController.d.ts +1 -1
- package/dist/lib.cjs/types/Transaction/TransactionUtils.d.ts +11 -3
- package/dist/lib.cjs/types/utils/abis.d.ts +544 -99
- package/dist/lib.cjs/types/utils/eip5792Types.d.ts +0 -1
- package/dist/lib.cjs/types/utils/hex.d.ts +9 -0
- package/dist/lib.cjs/types/utils/interfaces.d.ts +205 -2
- package/dist/lib.cjs/types/utils/transaction.d.ts +1 -1
- package/dist/lib.cjs/types/utils/viem.d.ts +8 -0
- package/dist/lib.cjs/utils/abis.js +12 -0
- package/dist/lib.cjs/utils/conversionUtils.js +3 -4
- package/dist/lib.cjs/utils/eip5792Types.js +0 -2
- package/dist/lib.cjs/utils/helpers.js +9 -8
- package/dist/lib.cjs/utils/hex.js +23 -0
- package/dist/lib.cjs/utils/transaction.js +7 -11
- package/dist/lib.cjs/utils/viem.js +214 -0
- package/dist/lib.esm/Account/AccountTrackerController.js +15 -7
- package/dist/lib.esm/AccountAbstraction/AccountAbstractionController.js +5 -7
- package/dist/lib.esm/Eip5792/walletGetCallsStatus.js +1 -1
- package/dist/lib.esm/Eip5792/walletSendCalls.js +9 -10
- package/dist/lib.esm/Eip7702/eip7702Utils.js +1 -1
- package/dist/lib.esm/Gas/GasFeeController.js +3 -2
- package/dist/lib.esm/Keyring/KeyringController.js +68 -40
- package/dist/lib.esm/Message/utils.js +13 -12
- package/dist/lib.esm/Network/createEthereumMiddleware.js +2 -2
- package/dist/lib.esm/Nfts/NftHandler.js +54 -12
- package/dist/lib.esm/Nfts/NftsController.js +1 -4
- package/dist/lib.esm/Preferences/PreferencesController.js +1 -1
- package/dist/lib.esm/Tokens/TokenHandler.js +39 -7
- package/dist/lib.esm/Tokens/TokensController.js +15 -7
- package/dist/lib.esm/Transaction/TransactionController.js +6 -9
- package/dist/lib.esm/Transaction/TransactionGasUtil.js +11 -12
- package/dist/lib.esm/Transaction/TransactionUtils.js +30 -26
- package/dist/lib.esm/index.js +2 -2
- package/dist/lib.esm/utils/abis.js +12 -0
- package/dist/lib.esm/utils/conversionUtils.js +2 -3
- package/dist/lib.esm/utils/eip5792Types.js +1 -2
- package/dist/lib.esm/utils/helpers.js +8 -7
- package/dist/lib.esm/utils/hex.js +21 -0
- package/dist/lib.esm/utils/interfaces.js +64 -0
- package/dist/lib.esm/utils/transaction.js +7 -11
- package/dist/lib.esm/utils/viem.js +214 -0
- package/package.json +13 -18
- package/dist/ethereumControllers.umd.min.js +0 -2
- package/dist/ethereumControllers.umd.min.js.LICENSE.txt +0 -50
|
@@ -2,15 +2,25 @@ import { Implementation, toMetaMaskSmartAccount } from "@metamask/smart-accounts
|
|
|
2
2
|
import { BASE_TX_EVENT_TYPE, BaseBlockTrackerState, BaseControllerEvents, BaseFormattedTransactionActivity, BaseTokenInfo, BaseTransactionEvents, MESSAGE_EVENTS, MessageStatus, NetworkConfig, NetworkState, PaymentTransaction, PollingBlockTrackerConfig, PopupWhitelabelData, ProviderConfig, TRANSACTION_TYPE, TransactionMeta, TransactionState, TransactionStatus, TX_CONFIRMED_EVENT_TYPE, TX_DROPPED_EVENT_TYPE, TX_EVENTS, TX_FAILED_EVENT_TYPE, TX_WARNING_EVENT_TYPE, User } from "@toruslabs/base-controllers";
|
|
3
3
|
import { JRPCRequest, Json } from "@web3auth/auth";
|
|
4
4
|
import { MutexInterface } from "async-mutex";
|
|
5
|
-
import { AccessList, TypedDataDomain, TypedDataField } from "ethers";
|
|
6
5
|
import { ToBiconomySmartAccountParameters, toEcdsaKernelSmartAccount, ToLightSmartAccountParameters, ToNexusSmartAccountParameters, toSafeSmartAccount, toSimpleSmartAccount, toTrustSmartAccount } from "permissionless/accounts";
|
|
7
|
-
import { Client, Hex, WalletClient } from "viem";
|
|
6
|
+
import { Client, Hex, Signature, WalletClient } from "viem";
|
|
8
7
|
import { createBundlerClient, createPaymasterClient, SmartAccount, UserOperationReceipt, WebAuthnAccount } from "viem/account-abstraction";
|
|
9
8
|
import { METHOD_TYPES, SMART_ACCOUNT, TRANSACTION_ENVELOPE_TYPES } from "./constants";
|
|
10
9
|
import { NestedTransactionMetadata } from "./eip5792Types";
|
|
11
10
|
import { Authorization } from "./eip7702Types";
|
|
12
11
|
export type { BatchTransactionParams, NestedTransactionMetadata, TransactionBatchRequest, TransactionBatchSingleRequest } from "./eip5792Types";
|
|
13
12
|
export type { Authorization, Eip7702Params, Eip7702WalletGetUpgradeStatusResponse, SignedAuthorization } from "./eip7702Types";
|
|
13
|
+
export type TypedDataField = {
|
|
14
|
+
name: string;
|
|
15
|
+
type: string;
|
|
16
|
+
};
|
|
17
|
+
export type TypedDataDomain = {
|
|
18
|
+
name?: string;
|
|
19
|
+
version?: string;
|
|
20
|
+
chainId?: number | string;
|
|
21
|
+
verifyingContract?: string;
|
|
22
|
+
salt?: string;
|
|
23
|
+
};
|
|
14
24
|
export type CustomTokenInfo = BaseTokenInfo & {
|
|
15
25
|
erc20: boolean;
|
|
16
26
|
customTokenId?: string;
|
|
@@ -61,6 +71,7 @@ export interface Message extends AbstractMessage {
|
|
|
61
71
|
messageParams: MessageParams;
|
|
62
72
|
}
|
|
63
73
|
export type SignTypedDataMessageV4 = {
|
|
74
|
+
primaryType: string;
|
|
64
75
|
types: Record<string, TypedDataField[]>;
|
|
65
76
|
domain: TypedDataDomain;
|
|
66
77
|
message: Record<string, unknown>;
|
|
@@ -504,3 +515,195 @@ export interface UserOperationGas {
|
|
|
504
515
|
* Type Def for function to query the deployment bytecode of an address. (eth_getCode)
|
|
505
516
|
*/
|
|
506
517
|
export type GetEthCodeFn = (address: `0x${string}`, chainId: `0x${string}`) => Promise<`0x${string}`>;
|
|
518
|
+
/**
|
|
519
|
+
* A [[HexString]] whose length is even, which ensures it is a valid
|
|
520
|
+
* representation of binary data.
|
|
521
|
+
*/
|
|
522
|
+
export type DataHexString = Hex;
|
|
523
|
+
/**
|
|
524
|
+
* An object that can be used to represent binary data.
|
|
525
|
+
*/
|
|
526
|
+
export type BytesLike = DataHexString | Uint8Array;
|
|
527
|
+
/**
|
|
528
|
+
* A BLOb object that can be passed for [[link-eip-4844]]
|
|
529
|
+
* transactions.
|
|
530
|
+
*
|
|
531
|
+
* It may have had its commitment and proof already provided
|
|
532
|
+
* or rely on an attached [[KzgLibrary]] to compute them.
|
|
533
|
+
*/
|
|
534
|
+
export type BlobLike = BytesLike | {
|
|
535
|
+
data: BytesLike;
|
|
536
|
+
proof: BytesLike;
|
|
537
|
+
commitment: BytesLike;
|
|
538
|
+
};
|
|
539
|
+
/**
|
|
540
|
+
* A KZG Library with the necessary functions to compute
|
|
541
|
+
* BLOb commitments and proofs.
|
|
542
|
+
*/
|
|
543
|
+
export interface KzgLibrary {
|
|
544
|
+
blobToKzgCommitment: (blob: Uint8Array) => Uint8Array;
|
|
545
|
+
computeBlobKzgProof: (blob: Uint8Array, commitment: Uint8Array) => Uint8Array;
|
|
546
|
+
}
|
|
547
|
+
/**
|
|
548
|
+
* A KZG Library with any of the various API configurations.
|
|
549
|
+
* As the library is still experimental and the API is not
|
|
550
|
+
* stable, depending on the version used the method names and
|
|
551
|
+
* signatures are still in flux.
|
|
552
|
+
*
|
|
553
|
+
* This allows any of the versions to be passed into Transaction
|
|
554
|
+
* while providing a stable external API.
|
|
555
|
+
*/
|
|
556
|
+
export type KzgLibraryLike = KzgLibrary | {
|
|
557
|
+
blobToKZGCommitment: (blob: string) => string;
|
|
558
|
+
computeBlobKZGProof: (blob: string, commitment: string) => string;
|
|
559
|
+
} | {
|
|
560
|
+
blobToKzgCommitment: (blob: string) => string | Uint8Array;
|
|
561
|
+
computeBlobProof: (blob: string, commitment: string) => string | Uint8Array;
|
|
562
|
+
};
|
|
563
|
+
/**
|
|
564
|
+
* Any type that can be used where a numeric value is needed.
|
|
565
|
+
*/
|
|
566
|
+
export type Numeric = number | bigint;
|
|
567
|
+
/**
|
|
568
|
+
* Any type that can be used where a big number is needed.
|
|
569
|
+
*/
|
|
570
|
+
export type BigNumberish = string | Numeric;
|
|
571
|
+
/**
|
|
572
|
+
* A SignatureLike
|
|
573
|
+
*
|
|
574
|
+
* @_docloc: api/crypto:Signing
|
|
575
|
+
*/
|
|
576
|
+
export type SignatureLike = Signature | string | {
|
|
577
|
+
r: string;
|
|
578
|
+
s: string;
|
|
579
|
+
v: BigNumberish;
|
|
580
|
+
yParity?: 0 | 1;
|
|
581
|
+
yParityAndS?: string;
|
|
582
|
+
} | {
|
|
583
|
+
r: string;
|
|
584
|
+
yParityAndS: string;
|
|
585
|
+
yParity?: 0 | 1;
|
|
586
|
+
s?: string;
|
|
587
|
+
v?: number;
|
|
588
|
+
} | {
|
|
589
|
+
r: string;
|
|
590
|
+
s: string;
|
|
591
|
+
yParity: 0 | 1;
|
|
592
|
+
v?: BigNumberish;
|
|
593
|
+
yParityAndS?: string;
|
|
594
|
+
};
|
|
595
|
+
/**
|
|
596
|
+
* A **TransactionLike** is an object which is appropriate as a loose
|
|
597
|
+
* input for many operations which will populate missing properties of
|
|
598
|
+
* a transaction.
|
|
599
|
+
*/
|
|
600
|
+
/**
|
|
601
|
+
* A single [[AccessList]] entry of storage keys (slots) for an address.
|
|
602
|
+
*/
|
|
603
|
+
export type AccessListEntry = {
|
|
604
|
+
address: string;
|
|
605
|
+
storageKeys: Array<string>;
|
|
606
|
+
};
|
|
607
|
+
/**
|
|
608
|
+
* An ordered collection of [[AccessList]] entries.
|
|
609
|
+
*/
|
|
610
|
+
export type AccessList = Array<AccessListEntry>;
|
|
611
|
+
/**
|
|
612
|
+
* Any ethers-supported access list structure.
|
|
613
|
+
*/
|
|
614
|
+
export type AccessListish = AccessList | Array<[string, Array<string>]> | Record<string, Array<string>>;
|
|
615
|
+
export interface AuthorizationLike {
|
|
616
|
+
address: string;
|
|
617
|
+
nonce: bigint;
|
|
618
|
+
chainId: bigint;
|
|
619
|
+
signature: SignatureLike;
|
|
620
|
+
}
|
|
621
|
+
export interface TransactionLike<A = string> {
|
|
622
|
+
/**
|
|
623
|
+
* The type.
|
|
624
|
+
*/
|
|
625
|
+
type?: null | number;
|
|
626
|
+
/**
|
|
627
|
+
* The recipient address or ``null`` for an ``init`` transaction.
|
|
628
|
+
*/
|
|
629
|
+
to?: null | A;
|
|
630
|
+
/**
|
|
631
|
+
* The sender.
|
|
632
|
+
*/
|
|
633
|
+
from?: null | A;
|
|
634
|
+
/**
|
|
635
|
+
* The nonce.
|
|
636
|
+
*/
|
|
637
|
+
nonce?: null | number;
|
|
638
|
+
/**
|
|
639
|
+
* The maximum amount of gas that can be used.
|
|
640
|
+
*/
|
|
641
|
+
gasLimit?: null | BigNumberish;
|
|
642
|
+
/**
|
|
643
|
+
* The gas price for legacy and berlin transactions.
|
|
644
|
+
*/
|
|
645
|
+
gasPrice?: null | BigNumberish;
|
|
646
|
+
/**
|
|
647
|
+
* The maximum priority fee per gas for london transactions.
|
|
648
|
+
*/
|
|
649
|
+
maxPriorityFeePerGas?: null | BigNumberish;
|
|
650
|
+
/**
|
|
651
|
+
* The maximum total fee per gas for london transactions.
|
|
652
|
+
*/
|
|
653
|
+
maxFeePerGas?: null | BigNumberish;
|
|
654
|
+
/**
|
|
655
|
+
* The data.
|
|
656
|
+
*/
|
|
657
|
+
data?: null | string;
|
|
658
|
+
/**
|
|
659
|
+
* The value (in wei) to send.
|
|
660
|
+
*/
|
|
661
|
+
value?: null | BigNumberish;
|
|
662
|
+
/**
|
|
663
|
+
* The chain ID the transaction is valid on.
|
|
664
|
+
*/
|
|
665
|
+
chainId?: null | BigNumberish;
|
|
666
|
+
/**
|
|
667
|
+
* The transaction hash.
|
|
668
|
+
*/
|
|
669
|
+
hash?: null | string;
|
|
670
|
+
/**
|
|
671
|
+
* The signature provided by the sender.
|
|
672
|
+
*/
|
|
673
|
+
signature?: null | SignatureLike;
|
|
674
|
+
/**
|
|
675
|
+
* The access list for berlin and london transactions.
|
|
676
|
+
*/
|
|
677
|
+
accessList?: null | AccessListish;
|
|
678
|
+
/**
|
|
679
|
+
* The maximum fee per blob gas (see [[link-eip-4844]]).
|
|
680
|
+
*/
|
|
681
|
+
maxFeePerBlobGas?: null | BigNumberish;
|
|
682
|
+
/**
|
|
683
|
+
* The versioned hashes (see [[link-eip-4844]]).
|
|
684
|
+
*/
|
|
685
|
+
blobVersionedHashes?: null | Array<string>;
|
|
686
|
+
/**
|
|
687
|
+
* The blobs (if any) attached to this transaction (see [[link-eip-4844]]).
|
|
688
|
+
*/
|
|
689
|
+
blobs?: null | Array<BlobLike>;
|
|
690
|
+
/**
|
|
691
|
+
* An external library for computing the KZG commitments and
|
|
692
|
+
* proofs necessary for EIP-4844 transactions (see [[link-eip-4844]]).
|
|
693
|
+
*
|
|
694
|
+
* This is generally ``null``, unless you are creating BLOb
|
|
695
|
+
* transactions.
|
|
696
|
+
*/
|
|
697
|
+
kzg?: null | KzgLibraryLike;
|
|
698
|
+
/**
|
|
699
|
+
* The [[link-eip-7594]] BLOb Wrapper Version used for PeerDAS.
|
|
700
|
+
*
|
|
701
|
+
* For networks that use EIP-7594, this property is required to
|
|
702
|
+
* serialize the sidecar correctly.
|
|
703
|
+
*/
|
|
704
|
+
blobWrapperVersion?: null | number;
|
|
705
|
+
/**
|
|
706
|
+
* The [[link-eip-7702]] authorizations (if any).
|
|
707
|
+
*/
|
|
708
|
+
authorizationList?: null | Array<AuthorizationLike>;
|
|
709
|
+
}
|
|
@@ -3,4 +3,4 @@ import { JRPCRequest } from "@web3auth/auth";
|
|
|
3
3
|
* Transaction decoder for analytics.
|
|
4
4
|
* Decodes eth_sendRawTransaction and eth_sendUserOperation requests.
|
|
5
5
|
*/
|
|
6
|
-
export declare const transactionDecoder: (req: JRPCRequest<unknown>, chainId: string) => [string, string]
|
|
6
|
+
export declare const transactionDecoder: (req: JRPCRequest<unknown>, chainId: string) => Promise<[sender: string, txHash: string]>;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { TransactionSerializable } from "viem";
|
|
2
|
+
import { TransactionLike } from "./interfaces";
|
|
3
|
+
/**
|
|
4
|
+
* Prepare transaction params for signing.
|
|
5
|
+
* @param tx - The transaction to prepare.
|
|
6
|
+
* @returns The prepared transaction.
|
|
7
|
+
*/
|
|
8
|
+
export declare function prepareViemTx(tx: TransactionLike): TransactionSerializable;
|
|
@@ -9,6 +9,7 @@ const erc20Abi = [{
|
|
|
9
9
|
type: "string"
|
|
10
10
|
}],
|
|
11
11
|
payable: false,
|
|
12
|
+
stateMutability: "view",
|
|
12
13
|
type: "function"
|
|
13
14
|
}, {
|
|
14
15
|
constant: false,
|
|
@@ -25,6 +26,7 @@ const erc20Abi = [{
|
|
|
25
26
|
type: "bool"
|
|
26
27
|
}],
|
|
27
28
|
payable: false,
|
|
29
|
+
stateMutability: "nonpayable",
|
|
28
30
|
type: "function"
|
|
29
31
|
}, {
|
|
30
32
|
constant: true,
|
|
@@ -35,6 +37,7 @@ const erc20Abi = [{
|
|
|
35
37
|
type: "uint256"
|
|
36
38
|
}],
|
|
37
39
|
payable: false,
|
|
40
|
+
stateMutability: "view",
|
|
38
41
|
type: "function"
|
|
39
42
|
}, {
|
|
40
43
|
constant: false,
|
|
@@ -54,6 +57,7 @@ const erc20Abi = [{
|
|
|
54
57
|
type: "bool"
|
|
55
58
|
}],
|
|
56
59
|
payable: false,
|
|
60
|
+
stateMutability: "nonpayable",
|
|
57
61
|
type: "function"
|
|
58
62
|
}, {
|
|
59
63
|
constant: true,
|
|
@@ -64,6 +68,7 @@ const erc20Abi = [{
|
|
|
64
68
|
type: "uint256"
|
|
65
69
|
}],
|
|
66
70
|
payable: false,
|
|
71
|
+
stateMutability: "view",
|
|
67
72
|
type: "function"
|
|
68
73
|
}, {
|
|
69
74
|
constant: true,
|
|
@@ -77,6 +82,7 @@ const erc20Abi = [{
|
|
|
77
82
|
type: "uint256"
|
|
78
83
|
}],
|
|
79
84
|
payable: false,
|
|
85
|
+
stateMutability: "view",
|
|
80
86
|
type: "function"
|
|
81
87
|
}, {
|
|
82
88
|
constant: true,
|
|
@@ -87,6 +93,7 @@ const erc20Abi = [{
|
|
|
87
93
|
type: "string"
|
|
88
94
|
}],
|
|
89
95
|
payable: false,
|
|
96
|
+
stateMutability: "view",
|
|
90
97
|
type: "function"
|
|
91
98
|
}, {
|
|
92
99
|
constant: false,
|
|
@@ -103,6 +110,7 @@ const erc20Abi = [{
|
|
|
103
110
|
type: "bool"
|
|
104
111
|
}],
|
|
105
112
|
payable: false,
|
|
113
|
+
stateMutability: "nonpayable",
|
|
106
114
|
type: "function"
|
|
107
115
|
}, {
|
|
108
116
|
constant: false,
|
|
@@ -122,6 +130,7 @@ const erc20Abi = [{
|
|
|
122
130
|
type: "bool"
|
|
123
131
|
}],
|
|
124
132
|
payable: false,
|
|
133
|
+
stateMutability: "nonpayable",
|
|
125
134
|
type: "function"
|
|
126
135
|
}, {
|
|
127
136
|
constant: true,
|
|
@@ -138,6 +147,7 @@ const erc20Abi = [{
|
|
|
138
147
|
type: "uint256"
|
|
139
148
|
}],
|
|
140
149
|
payable: false,
|
|
150
|
+
stateMutability: "view",
|
|
141
151
|
type: "function"
|
|
142
152
|
}, {
|
|
143
153
|
inputs: [{
|
|
@@ -153,9 +163,11 @@ const erc20Abi = [{
|
|
|
153
163
|
name: "_tokenSymbol",
|
|
154
164
|
type: "string"
|
|
155
165
|
}],
|
|
166
|
+
stateMutability: "nonpayable",
|
|
156
167
|
type: "constructor"
|
|
157
168
|
}, {
|
|
158
169
|
payable: false,
|
|
170
|
+
stateMutability: "nonpayable",
|
|
159
171
|
type: "fallback"
|
|
160
172
|
}];
|
|
161
173
|
const erc721Abi = [{
|
|
@@ -3,9 +3,8 @@
|
|
|
3
3
|
var _objectDestructuringEmpty = require('@babel/runtime/helpers/objectDestructuringEmpty');
|
|
4
4
|
var _objectSpread = require('@babel/runtime/helpers/objectSpread2');
|
|
5
5
|
var _objectWithoutProperties = require('@babel/runtime/helpers/objectWithoutProperties');
|
|
6
|
-
var util = require('@ethereumjs/util');
|
|
7
6
|
var bignumber_js = require('bignumber.js');
|
|
8
|
-
var
|
|
7
|
+
var hex = require('./hex.js');
|
|
9
8
|
|
|
10
9
|
const _excluded = ["aBase", "bBase"],
|
|
11
10
|
_excluded2 = ["aBase", "bBase"],
|
|
@@ -16,7 +15,7 @@ const BIG_NUMBER_GWEI_MULTIPLIER = new bignumber_js.BigNumber("1000000000");
|
|
|
16
15
|
const BIG_NUMBER_ETH_MULTIPLIER = new bignumber_js.BigNumber("1");
|
|
17
16
|
// Setter Maps
|
|
18
17
|
const toBigNumber = {
|
|
19
|
-
hex: n => new bignumber_js.BigNumber(
|
|
18
|
+
hex: n => new bignumber_js.BigNumber(hex.stripHexPrefix(n), 16),
|
|
20
19
|
dec: n => new bignumber_js.BigNumber(String(n), 10),
|
|
21
20
|
BN: n => new bignumber_js.BigNumber(n.toString(16), 16)
|
|
22
21
|
};
|
|
@@ -33,7 +32,7 @@ const toSpecifiedDenomination = {
|
|
|
33
32
|
const baseChange = {
|
|
34
33
|
hex: n => n.toString(16),
|
|
35
34
|
dec: n => new bignumber_js.BigNumber(n).toString(10),
|
|
36
|
-
BN: n => new
|
|
35
|
+
BN: n => new bignumber_js.BigNumber(n.toString(16))
|
|
37
36
|
};
|
|
38
37
|
// Utility function for checking base types
|
|
39
38
|
const isValidBase = base => Number.isInteger(base) && base > 1;
|
|
@@ -9,7 +9,6 @@ const EIP_5792_METHODS = {
|
|
|
9
9
|
WALLET_GET_CALLS_STATUS: "wallet_getCallsStatus",
|
|
10
10
|
WALLET_SHOW_CALLS_STATUS: "wallet_showCallsStatus"
|
|
11
11
|
};
|
|
12
|
-
const SUPPORTED_EIP_5792_VERSIONS = ["1.0", "2.0"];
|
|
13
12
|
const EIP5792ErrorCode = {
|
|
14
13
|
UnsupportedNonOptionalCapability: 5700,
|
|
15
14
|
UnsupportedChainId: 5710,
|
|
@@ -38,4 +37,3 @@ exports.EIP5792ErrorCode = EIP5792ErrorCode;
|
|
|
38
37
|
exports.EIP_5792_METHODS = EIP_5792_METHODS;
|
|
39
38
|
exports.Eip5792AtomicStatus = Eip5792AtomicStatus;
|
|
40
39
|
exports.GetCallsStatusCode = GetCallsStatusCode;
|
|
41
|
-
exports.SUPPORTED_EIP_5792_VERSIONS = SUPPORTED_EIP_5792_VERSIONS;
|
|
@@ -1,18 +1,19 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
var _objectSpread = require('@babel/runtime/helpers/objectSpread2');
|
|
4
|
-
var util = require('@ethereumjs/util');
|
|
5
4
|
var baseControllers = require('@toruslabs/base-controllers');
|
|
6
5
|
var bignumber_js = require('bignumber.js');
|
|
7
6
|
var log = require('loglevel');
|
|
7
|
+
var viem = require('viem');
|
|
8
8
|
var TransactionUtils = require('../Transaction/TransactionUtils.js');
|
|
9
9
|
var constants = require('./constants.js');
|
|
10
|
+
var hex = require('./hex.js');
|
|
10
11
|
|
|
11
|
-
function hexToBn(hex) {
|
|
12
|
-
return new bignumber_js.BigNumber(
|
|
12
|
+
function hexToBn(hex$1) {
|
|
13
|
+
return new bignumber_js.BigNumber(hex.stripHexPrefix(hex$1), 16);
|
|
13
14
|
}
|
|
14
15
|
function BNToHex(bn) {
|
|
15
|
-
return
|
|
16
|
+
return hex.addHexPrefix(bn.toString(16));
|
|
16
17
|
}
|
|
17
18
|
function getEtherScanHashLink(txHash, chainId) {
|
|
18
19
|
if (!constants.SUPPORTED_NETWORKS[chainId]) return "";
|
|
@@ -94,18 +95,18 @@ function formatTime(time) {
|
|
|
94
95
|
}
|
|
95
96
|
function isAddressByChainId(address, _chainId) {
|
|
96
97
|
// TOOD: add rsk network checks.
|
|
97
|
-
return
|
|
98
|
+
return viem.isAddress(address);
|
|
98
99
|
}
|
|
99
100
|
function toChecksumAddressByChainId(address, chainId) {
|
|
100
101
|
// TOOD: add rsk network checks.
|
|
101
102
|
if (!isAddressByChainId(address)) return address;
|
|
102
|
-
return
|
|
103
|
+
return viem.getAddress(address);
|
|
103
104
|
}
|
|
104
105
|
const GAS_LIMITS = {
|
|
105
106
|
// maximum gasLimit of a simple send
|
|
106
|
-
SIMPLE:
|
|
107
|
+
SIMPLE: viem.toHex(21000),
|
|
107
108
|
// a base estimate for token transfers.
|
|
108
|
-
BASE_TOKEN_ESTIMATE:
|
|
109
|
+
BASE_TOKEN_ESTIMATE: viem.toHex(100000)
|
|
109
110
|
};
|
|
110
111
|
function bnLessThan(a, b) {
|
|
111
112
|
if (a === null || a === undefined || b === null || b === undefined) {
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var viem = require('viem');
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Removes '0x' from a given `String` if present
|
|
7
|
+
*/
|
|
8
|
+
const stripHexPrefix = str => {
|
|
9
|
+
if (typeof str !== "string") throw new Error(`[stripHexPrefix] input must be type 'string', received ${typeof str}`);
|
|
10
|
+
return viem.isHex(str) ? str.slice(2) : str;
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* Adds "0x" to a given `string` if it does not already start with "0x".
|
|
14
|
+
*/
|
|
15
|
+
const addHexPrefix = str => {
|
|
16
|
+
if (typeof str !== "string") {
|
|
17
|
+
return str;
|
|
18
|
+
}
|
|
19
|
+
return viem.isHex(str) ? str : `0x${str}`;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
exports.addHexPrefix = addHexPrefix;
|
|
23
|
+
exports.stripHexPrefix = stripHexPrefix;
|
|
@@ -1,29 +1,25 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var common = require('@ethereumjs/common');
|
|
4
|
-
var tx = require('@ethereumjs/tx');
|
|
5
|
-
var util = require('@ethereumjs/util');
|
|
6
3
|
var log = require('loglevel');
|
|
4
|
+
var viem = require('viem');
|
|
7
5
|
var constants = require('./constants.js');
|
|
6
|
+
var hex = require('./hex.js');
|
|
8
7
|
|
|
9
8
|
/**
|
|
10
9
|
* Transaction decoder for analytics.
|
|
11
10
|
* Decodes eth_sendRawTransaction and eth_sendUserOperation requests.
|
|
12
11
|
*/
|
|
13
|
-
const transactionDecoder = (req, chainId) => {
|
|
12
|
+
const transactionDecoder = async (req, chainId) => {
|
|
14
13
|
let sender = "";
|
|
15
14
|
let txHash = "";
|
|
16
15
|
try {
|
|
17
16
|
if (req.method === constants.METHOD_TYPES.ETH_SEND_RAW_TRANSACTION) {
|
|
18
17
|
const rawTx = req.params[0];
|
|
19
|
-
const
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
chainId
|
|
23
|
-
}, common.Mainnet)
|
|
18
|
+
const normalizedRawTx = hex.addHexPrefix(rawTx);
|
|
19
|
+
sender = await viem.recoverTransactionAddress({
|
|
20
|
+
serializedTransaction: normalizedRawTx
|
|
24
21
|
});
|
|
25
|
-
|
|
26
|
-
txHash = util.bytesToHex(tx$1.hash());
|
|
22
|
+
txHash = viem.keccak256(normalizedRawTx);
|
|
27
23
|
} else if (req.method === constants.METHOD_TYPES.ETH_SEND_USER_OPERATION) {
|
|
28
24
|
const userOpReq = req;
|
|
29
25
|
sender = userOpReq.params.map(p => p.sender).join(",");
|