@deserialize/multi-vm-wallet 1.5.22 → 1.5.32
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/IChainWallet.d.ts +11 -7
- package/dist/IChainWallet.js +15 -6
- package/dist/constant.js +40 -48
- package/dist/evm/evm.d.ts +19 -1
- package/dist/evm/evm.js +88 -31
- package/dist/evm/utils.d.ts +1 -0
- package/dist/evm/utils.js +8 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +2 -1
- package/dist/svm/svm.d.ts +17 -1
- package/dist/svm/svm.js +71 -21
- package/dist/test.js +7 -1
- package/dist/types.d.ts +4 -0
- package/dist/walletBip32.js +0 -3
- package/package.json +1 -1
- package/utils/IChainWallet.ts +76 -15
- package/utils/constant.ts +41 -51
- package/utils/evm/evm.ts +369 -290
- package/utils/evm/utils.ts +12 -0
- package/utils/index.ts +2 -2
- package/utils/savings/svm-savings.ts +1 -1
- package/utils/svm/svm.ts +344 -24
- package/utils/test.ts +9 -5
- package/utils/types.ts +6 -2
- package/utils/utils.ts +7 -0
- package/utils/walletBip32.ts +3 -3
package/dist/test.js
CHANGED
|
@@ -234,10 +234,16 @@ const testSavingsPocketMultiChain = async () => {
|
|
|
234
234
|
console.log('\n✅ Multi-Chain Savings Test Complete\n');
|
|
235
235
|
};
|
|
236
236
|
const testEntropy = () => {
|
|
237
|
-
const p = evm_1.EVMVM.convertFromEntropyToPrivateKey("
|
|
237
|
+
const p = evm_1.EVMVM.convertFromEntropyToPrivateKey("thishgbmytesentropystringis32bytes!hjkjkhknkjtdyftgkh,jryctdrfygh");
|
|
238
238
|
console.log('p: ', p);
|
|
239
239
|
const res = new evm_1.EVMChainWallet(evmChainConfig, p, 0);
|
|
240
240
|
console.log('res: ', res);
|
|
241
241
|
};
|
|
242
|
+
const testAddressClass = async () => {
|
|
243
|
+
const evmAddressClass = new evm_1.EVMChainAddress(evmChainConfig, "0xC9C1D854b82BA9b4FB6f6D58E9EF3d1fAEd601AA", 0);
|
|
244
|
+
const res = await evmAddressClass.getNativeBalance();
|
|
245
|
+
console.log('res: ', res);
|
|
246
|
+
};
|
|
247
|
+
testAddressClass();
|
|
242
248
|
const RPC_URL = chainConfig.rpcUrl;
|
|
243
249
|
const connection = new web3_js_1.Connection(RPC_URL);
|
package/dist/types.d.ts
CHANGED
|
@@ -16,8 +16,12 @@ export interface ChainWalletConfig {
|
|
|
16
16
|
confirmationNo?: number;
|
|
17
17
|
testnet?: boolean;
|
|
18
18
|
vmType: vmTypes;
|
|
19
|
+
savings?: ChainSavingConfig;
|
|
19
20
|
aaSupport?: AA_SupportConfig;
|
|
20
21
|
}
|
|
22
|
+
export interface ChainSavingConfig {
|
|
23
|
+
tokens: string[];
|
|
24
|
+
}
|
|
21
25
|
export interface AA_SupportConfig {
|
|
22
26
|
enabled: boolean;
|
|
23
27
|
entryPoints: {
|
package/dist/walletBip32.js
CHANGED
|
@@ -110,9 +110,6 @@ function derivePathEclipticCurve(path, seed) {
|
|
|
110
110
|
.split("/")
|
|
111
111
|
.slice(1)
|
|
112
112
|
.map((seg) => {
|
|
113
|
-
if (!seg.endsWith("'")) {
|
|
114
|
-
throw new Error("Only hardened derivation is supported");
|
|
115
|
-
}
|
|
116
113
|
return parseInt(seg.slice(0, -1), 10) + 0x80000000;
|
|
117
114
|
});
|
|
118
115
|
let hmacResult = (0, hmac_1.hmac)(sha2_1.sha512, buffer_1.Buffer.from("ed25519 seed"), seed);
|
package/package.json
CHANGED
package/utils/IChainWallet.ts
CHANGED
|
@@ -3,36 +3,26 @@ import { PriceResponse } from "./price.types";
|
|
|
3
3
|
import { SVMTransactionHistoryItem } from "./svm/transactionParsing";
|
|
4
4
|
import { Balance, ChainWalletConfig, NFTInfo, TokenInfo, TransactionResult, UserTokenBalance, NFT } from "./types";
|
|
5
5
|
|
|
6
|
-
export abstract class
|
|
7
|
-
|
|
6
|
+
export abstract class ChainAddress<AddressType, ConnectionType> {
|
|
7
|
+
|
|
8
8
|
config: ChainWalletConfig;
|
|
9
9
|
address: AddressType;
|
|
10
10
|
index: number | undefined
|
|
11
11
|
connection: ConnectionType | undefined
|
|
12
12
|
|
|
13
|
-
constructor(config: ChainWalletConfig,
|
|
13
|
+
constructor(config: ChainWalletConfig, address: AddressType, index?: number) {
|
|
14
14
|
this.config = config;
|
|
15
|
-
this.
|
|
16
|
-
this.address = this.generateAddress(privateKey);
|
|
15
|
+
this.address = address;
|
|
17
16
|
this.index = index;
|
|
18
17
|
|
|
19
18
|
}
|
|
20
19
|
|
|
21
|
-
abstract generateAddress(privateKey: PrivateKeyType): AddressType;
|
|
22
20
|
abstract getNativeBalance(): Promise<Balance>;
|
|
23
21
|
abstract getTokenBalance(tokenAddress: AddressType): Promise<Balance>;
|
|
24
|
-
abstract transferNative(to: AddressType, amount: number): Promise<TransactionResult>;
|
|
25
|
-
abstract transferToken(tokenAddress: TokenInfo, to: AddressType, amount: number): Promise<TransactionResult>;
|
|
26
|
-
abstract swap(tokenAddress: TokenInfo, to: AddressType, amount: number, slippage?: number): Promise<TransactionResult>;
|
|
27
22
|
abstract discoverToken(): Promise<UserTokenBalance<AddressType>[]>;
|
|
28
23
|
abstract discoverNFT(): Promise<NFT[]>;
|
|
29
24
|
abstract getTransactionHistory(): Promise<(SVMTransactionHistoryItem | EVMTransactionHistoryItem)[]>;
|
|
30
25
|
abstract getPrices(tokenAddresses: string[]): Promise<PriceResponse>
|
|
31
|
-
// abstract transferNFT(contractAddress: AddressType, tokenId: string, to: string): Promise<TransactionResult>;
|
|
32
|
-
// abstract getTokenInfo(tokenAddress: string): Promise<TokenInfo>;
|
|
33
|
-
// abstract getNFTInfo(contractAddress: string, tokenId: string): Promise<NFTInfo>;
|
|
34
|
-
// abstract getTransactionHistory(): Promise<any[]>;
|
|
35
|
-
|
|
36
26
|
getAddress(): AddressType {
|
|
37
27
|
return this.address;
|
|
38
28
|
}
|
|
@@ -42,6 +32,77 @@ export abstract class ChainWallet<AddressType, PrivateKeyType, ConnectionType> {
|
|
|
42
32
|
|
|
43
33
|
|
|
44
34
|
|
|
45
|
-
abstract convertFromEntropyToPrivateKey(entropy: string): PrivateKeyType
|
|
46
35
|
|
|
36
|
+
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export abstract class ChainWallet<
|
|
40
|
+
AddressType,
|
|
41
|
+
PrivateKeyType,
|
|
42
|
+
ConnectionType
|
|
43
|
+
> extends ChainAddress<AddressType, ConnectionType> {
|
|
44
|
+
|
|
45
|
+
protected privateKey: PrivateKeyType;
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Protected constructor so wallets are created through factories
|
|
49
|
+
*/
|
|
50
|
+
constructor(
|
|
51
|
+
config: ChainWalletConfig,
|
|
52
|
+
address: AddressType,
|
|
53
|
+
privateKey: PrivateKeyType,
|
|
54
|
+
index?: number
|
|
55
|
+
) {
|
|
56
|
+
super(config, address, index);
|
|
57
|
+
|
|
58
|
+
this.privateKey = privateKey;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Each chain must implement how an address is derived
|
|
63
|
+
*/
|
|
64
|
+
protected abstract generateAddress(
|
|
65
|
+
privateKey: PrivateKeyType
|
|
66
|
+
): AddressType;
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Transfer native coin (ETH, SOL, etc.)
|
|
70
|
+
*/
|
|
71
|
+
abstract transferNative(
|
|
72
|
+
to: AddressType,
|
|
73
|
+
amount: number
|
|
74
|
+
): Promise<TransactionResult>;
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Transfer ERC20 / SPL token
|
|
78
|
+
*/
|
|
79
|
+
abstract transferToken(
|
|
80
|
+
tokenAddress: TokenInfo,
|
|
81
|
+
to: AddressType,
|
|
82
|
+
amount: number
|
|
83
|
+
): Promise<TransactionResult>;
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Swap tokens
|
|
87
|
+
*/
|
|
88
|
+
abstract swap(
|
|
89
|
+
tokenAddress: TokenInfo,
|
|
90
|
+
to: AddressType,
|
|
91
|
+
amount: number,
|
|
92
|
+
slippage?: number
|
|
93
|
+
): Promise<TransactionResult>;
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Convert entropy/mnemonic → private key
|
|
97
|
+
*/
|
|
98
|
+
abstract convertFromEntropyToPrivateKey(
|
|
99
|
+
entropy: string
|
|
100
|
+
): PrivateKeyType;
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Expose private key only internally if needed
|
|
104
|
+
*/
|
|
105
|
+
protected getPrivateKey(): PrivateKeyType {
|
|
106
|
+
return this.privateKey;
|
|
107
|
+
}
|
|
47
108
|
}
|
package/utils/constant.ts
CHANGED
|
@@ -1,35 +1,7 @@
|
|
|
1
|
-
import { base } from "viem/chains";
|
|
1
|
+
import { arbitrum, base, optimism } from "viem/chains";
|
|
2
2
|
import { ChainWalletConfig } from "./types";
|
|
3
3
|
|
|
4
4
|
export const DefaultChains: ChainWalletConfig[] = [{
|
|
5
|
-
|
|
6
|
-
chainId: 24101,
|
|
7
|
-
name: "Incentiv",
|
|
8
|
-
rpcUrl: "https://rpc.incentiv.io",
|
|
9
|
-
explorerUrl: "https://explorer.incentiv.io",
|
|
10
|
-
nativeToken: {
|
|
11
|
-
name: "Incentiv",
|
|
12
|
-
symbol: "CENT",
|
|
13
|
-
decimals: 18,
|
|
14
|
-
},
|
|
15
|
-
testnet: false,
|
|
16
|
-
logoUrl: "https://incentiv.io/wp-content/uploads/2024/09/cropped-Favicon-1-32x32.png",
|
|
17
|
-
vmType: "EVM"
|
|
18
|
-
}, {
|
|
19
|
-
|
|
20
|
-
chainId: 16661,
|
|
21
|
-
name: "0G",
|
|
22
|
-
rpcUrl: "https://evmrpc.0g.ai",
|
|
23
|
-
explorerUrl: "https://chainscan.0g.ai/",
|
|
24
|
-
nativeToken: {
|
|
25
|
-
name: "OG Mainnet",
|
|
26
|
-
symbol: "0G",
|
|
27
|
-
decimals: 18,
|
|
28
|
-
},
|
|
29
|
-
testnet: false,
|
|
30
|
-
logoUrl: "https://chainscan.0g.ai/static/media/zg-logo-new.b22d59dabf457524325ca81c29a4e055.svg",
|
|
31
|
-
vmType: "EVM"
|
|
32
|
-
}, {
|
|
33
5
|
chainId: 123456789,
|
|
34
6
|
name: "Solana",
|
|
35
7
|
rpcUrl: "https://solana-mainnet.g.alchemy.com/v2/TFdA4BilCnKIwaqtypk0d",
|
|
@@ -41,7 +13,10 @@ export const DefaultChains: ChainWalletConfig[] = [{
|
|
|
41
13
|
},
|
|
42
14
|
testnet: false,
|
|
43
15
|
logoUrl: "https://solana.com/src/img/branding/solanaLogoMark.svg",
|
|
44
|
-
vmType: "SVM"
|
|
16
|
+
vmType: "SVM",
|
|
17
|
+
savings: {
|
|
18
|
+
tokens: []
|
|
19
|
+
}
|
|
45
20
|
}
|
|
46
21
|
, {
|
|
47
22
|
chainId: 1,
|
|
@@ -68,7 +43,10 @@ export const DefaultChains: ChainWalletConfig[] = [{
|
|
|
68
43
|
},
|
|
69
44
|
testnet: false,
|
|
70
45
|
logoUrl: "https://bscscan.com/assets/bsc/images/svg/logos/token-light.svg?v=25.10.5.0",
|
|
71
|
-
vmType: "EVM"
|
|
46
|
+
vmType: "EVM",
|
|
47
|
+
savings: {
|
|
48
|
+
tokens: []
|
|
49
|
+
}
|
|
72
50
|
},
|
|
73
51
|
|
|
74
52
|
// {
|
|
@@ -98,36 +76,45 @@ export const DefaultChains: ChainWalletConfig[] = [{
|
|
|
98
76
|
},
|
|
99
77
|
testnet: base.testnet,
|
|
100
78
|
logoUrl: "https://avatars.githubusercontent.com/u/108554348?s=200&v=4",
|
|
101
|
-
vmType: "EVM"
|
|
79
|
+
vmType: "EVM",
|
|
80
|
+
savings: {
|
|
81
|
+
tokens: []
|
|
82
|
+
}
|
|
102
83
|
},
|
|
103
84
|
|
|
104
85
|
{
|
|
105
|
-
chainId:
|
|
106
|
-
name:
|
|
107
|
-
rpcUrl:
|
|
108
|
-
explorerUrl:
|
|
86
|
+
chainId: arbitrum.id,
|
|
87
|
+
name: arbitrum.name,
|
|
88
|
+
rpcUrl: arbitrum.rpcUrls.default.http[0],
|
|
89
|
+
explorerUrl: arbitrum.blockExplorers?.default.url,
|
|
109
90
|
nativeToken: {
|
|
110
|
-
name:
|
|
111
|
-
symbol:
|
|
112
|
-
decimals:
|
|
91
|
+
name: arbitrum.nativeCurrency.name,
|
|
92
|
+
symbol: arbitrum.nativeCurrency.symbol,
|
|
93
|
+
decimals: arbitrum.nativeCurrency.decimals,
|
|
113
94
|
},
|
|
114
95
|
testnet: false,
|
|
115
|
-
logoUrl: "https://
|
|
116
|
-
vmType: "EVM"
|
|
96
|
+
logoUrl: "https://avatars.githubusercontent.com/u/119917794?s=280&v=4",
|
|
97
|
+
vmType: "EVM",
|
|
98
|
+
savings: {
|
|
99
|
+
tokens: []
|
|
100
|
+
}
|
|
117
101
|
},
|
|
118
102
|
{
|
|
119
|
-
chainId:
|
|
120
|
-
name:
|
|
121
|
-
rpcUrl:
|
|
122
|
-
explorerUrl:
|
|
103
|
+
chainId: optimism.id,
|
|
104
|
+
name: optimism.name,
|
|
105
|
+
rpcUrl: optimism.rpcUrls.default.http[0],
|
|
106
|
+
explorerUrl: optimism.blockExplorers?.default.url,
|
|
123
107
|
nativeToken: {
|
|
124
|
-
name:
|
|
125
|
-
symbol:
|
|
126
|
-
decimals:
|
|
108
|
+
name: optimism.nativeCurrency.name,
|
|
109
|
+
symbol: optimism.nativeCurrency.symbol,
|
|
110
|
+
decimals: optimism.nativeCurrency.decimals,
|
|
127
111
|
},
|
|
128
112
|
testnet: false,
|
|
129
|
-
logoUrl: "https://
|
|
130
|
-
vmType: "EVM"
|
|
113
|
+
logoUrl: "https://avatars.githubusercontent.com/u/58791460?s=280&v=4",
|
|
114
|
+
vmType: "EVM",
|
|
115
|
+
savings: {
|
|
116
|
+
tokens: []
|
|
117
|
+
}
|
|
131
118
|
},
|
|
132
119
|
|
|
133
120
|
//add for polygon
|
|
@@ -143,7 +130,10 @@ export const DefaultChains: ChainWalletConfig[] = [{
|
|
|
143
130
|
},
|
|
144
131
|
testnet: false,
|
|
145
132
|
logoUrl: "https://polygonscan.com/images/svg/brands/polygon-light.svg?v=0.0.36",
|
|
146
|
-
vmType: "EVM"
|
|
133
|
+
vmType: "EVM",
|
|
134
|
+
savings: {
|
|
135
|
+
tokens: []
|
|
136
|
+
}
|
|
147
137
|
}
|
|
148
138
|
|
|
149
139
|
|