@exodus/web3-ethereum 12.16.0 → 12.18.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/lib/rpc-handlers/createEVMDeps.js +59 -55
- package/lib/types.d.ts +3 -0
- package/package.json +2 -2
|
@@ -9,7 +9,7 @@ async function getDefaultPurposeForLedger(asset) {
|
|
|
9
9
|
return purposes[0];
|
|
10
10
|
}
|
|
11
11
|
const createEVMDepsFactory = ({ analytics, blockchainMetadata, }) => {
|
|
12
|
-
return ({ assetName, origin, getAsset, getAddress: _getAddress, getSupportedChainIds, getPrivateKey, getFeeData: getFeeConfig, getCustomFeeRate, getActiveWalletAccount, simulateEthereumTransactions, getActiveWalletAccountData, transactionSigner, getLedgerDevice, }) => {
|
|
12
|
+
return ({ assetName, chainId: _chainId, origin, getAsset, getAddress: _getAddress, getSupportedChainIds, getPrivateKey, getFeeData: getFeeConfig, getCustomFeeRate, getActiveWalletAccount, simulateEthereumTransactions, getActiveWalletAccountData, transactionSigner, messageSigner: _messageSigner, getLedgerDevice, onEthWalletWatchAssetRequest: _onEthWalletWatchAssetRequest, }) => {
|
|
13
13
|
const asset = getAsset(assetName);
|
|
14
14
|
const server = getServer(asset);
|
|
15
15
|
const forwardRequest = async ({ method, params }) => {
|
|
@@ -90,64 +90,68 @@ const createEVMDepsFactory = ({ analytics, blockchainMetadata, }) => {
|
|
|
90
90
|
}
|
|
91
91
|
return feeData;
|
|
92
92
|
};
|
|
93
|
-
const trackWalletWatchAssetUse =
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
if (
|
|
113
|
-
throw new
|
|
93
|
+
const trackWalletWatchAssetUse = _onEthWalletWatchAssetRequest
|
|
94
|
+
? _onEthWalletWatchAssetRequest
|
|
95
|
+
: async (assetDetails) => {
|
|
96
|
+
// TODO: do we still need this? If yes, this ...assetDetails expansion is no bueno
|
|
97
|
+
// why is this not always returning true in browser?
|
|
98
|
+
analytics.track({
|
|
99
|
+
event: 'DappWalletWatchAsset',
|
|
100
|
+
properties: {
|
|
101
|
+
...assetDetails,
|
|
102
|
+
dappDomain: origin,
|
|
103
|
+
},
|
|
104
|
+
});
|
|
105
|
+
return true;
|
|
106
|
+
};
|
|
107
|
+
const messageSigner = _messageSigner
|
|
108
|
+
? _messageSigner
|
|
109
|
+
: {
|
|
110
|
+
signMessage: async ({ baseAssetName, walletAccount, message, }) => {
|
|
111
|
+
const { rawMessage, EIP712Message } = message;
|
|
112
|
+
if (rawMessage && EIP712Message) {
|
|
113
|
+
throw new InvalidInputError("Can't set both rawMessage and EIP712Message");
|
|
114
114
|
}
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
115
|
+
if (walletAccount.source === 'exodus') {
|
|
116
|
+
if (!getPrivateKey) {
|
|
117
|
+
throw new Error('`getPrivateKey` should be provided to sign with Exodus accounts.');
|
|
118
|
+
}
|
|
119
|
+
const { privateKey } = await getPrivateKey(assetName);
|
|
120
|
+
if (rawMessage) {
|
|
121
|
+
return hex0xStringToBuffer(signMessage(bufferToHex0xString(rawMessage), privateKey));
|
|
122
|
+
}
|
|
123
|
+
if (EIP712Message) {
|
|
124
|
+
const typedDataVersion = Array.isArray(EIP712Message)
|
|
125
|
+
? SignTypedDataVersion.V1
|
|
126
|
+
: SignTypedDataVersion.V4;
|
|
127
|
+
return hex0xStringToBuffer(signTypedData(EIP712Message, privateKey, typedDataVersion));
|
|
128
|
+
}
|
|
118
129
|
}
|
|
119
|
-
if (
|
|
120
|
-
const
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
130
|
+
else if (getLedgerDevice) {
|
|
131
|
+
const device = await getLedgerDevice();
|
|
132
|
+
const purpose = await getDefaultPurposeForLedger(asset);
|
|
133
|
+
const { derivationPath } = await getAsset(assetName).baseAsset.api.getKeyIdentifier({
|
|
134
|
+
compatibilityMode: 'ledger',
|
|
135
|
+
purpose,
|
|
136
|
+
accountIndex: 0,
|
|
137
|
+
chainIndex: 0,
|
|
138
|
+
addressIndex: 0,
|
|
139
|
+
});
|
|
140
|
+
const signedMessage = await device.signMessage({
|
|
141
|
+
assetName: baseAssetName,
|
|
142
|
+
derivationPath,
|
|
143
|
+
message: {
|
|
144
|
+
rawMessage,
|
|
145
|
+
EIP712Message,
|
|
146
|
+
},
|
|
147
|
+
});
|
|
148
|
+
return Buffer.from(signedMessage);
|
|
124
149
|
}
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
const purpose = await getDefaultPurposeForLedger(asset);
|
|
129
|
-
const { derivationPath } = await getAsset(assetName).baseAsset.api.getKeyIdentifier({
|
|
130
|
-
compatibilityMode: 'ledger',
|
|
131
|
-
purpose,
|
|
132
|
-
accountIndex: 0,
|
|
133
|
-
chainIndex: 0,
|
|
134
|
-
addressIndex: 0,
|
|
135
|
-
});
|
|
136
|
-
const signedMessage = await device.signMessage({
|
|
137
|
-
assetName: baseAssetName,
|
|
138
|
-
derivationPath,
|
|
139
|
-
message: {
|
|
140
|
-
rawMessage,
|
|
141
|
-
EIP712Message,
|
|
142
|
-
},
|
|
143
|
-
});
|
|
144
|
-
return Buffer.from(signedMessage);
|
|
145
|
-
}
|
|
146
|
-
throw new InvalidInputError();
|
|
147
|
-
},
|
|
148
|
-
};
|
|
150
|
+
throw new InvalidInputError();
|
|
151
|
+
},
|
|
152
|
+
};
|
|
149
153
|
return {
|
|
150
|
-
chainId: 'undefined',
|
|
154
|
+
chainId: _chainId || 'undefined',
|
|
151
155
|
forwardRequest,
|
|
152
156
|
sendRawTransaction,
|
|
153
157
|
getAddress,
|
package/lib/types.d.ts
CHANGED
|
@@ -27,6 +27,7 @@ export interface CreateEvmDepsFactoryParams {
|
|
|
27
27
|
declare type SimulateTransactionsFn = (params: EthSimulateTransactionParams) => Promise<EthAggregatedTransactionSimulationResult>;
|
|
28
28
|
export interface CreateEvmDepsParams {
|
|
29
29
|
assetName: string;
|
|
30
|
+
chainId?: string;
|
|
30
31
|
origin: string;
|
|
31
32
|
getAddress: (assetName: string) => Promise<string>;
|
|
32
33
|
getActiveWalletAccount: () => Promise<string>;
|
|
@@ -40,8 +41,10 @@ export interface CreateEvmDepsParams {
|
|
|
40
41
|
simulateEthereumTransactions: SimulateTransactionsFn;
|
|
41
42
|
getActiveWalletAccountData: GetActiveWalletAccountData;
|
|
42
43
|
transactionSigner: EVMTransactionSignerModule;
|
|
44
|
+
messageSigner?: EVMMessageSigner;
|
|
43
45
|
getLedgerDevice?: GetLedgerDevice;
|
|
44
46
|
addEthereumChain?: (param: AddEthereumChainParameter) => Promise<null>;
|
|
47
|
+
onEthWalletWatchAssetRequest?: (param: EthWalletWatchAsset) => Promise<boolean>;
|
|
45
48
|
}
|
|
46
49
|
export declare type EVMFactory = (params: CreateEvmDepsParams) => EVMDeps;
|
|
47
50
|
export declare type EVMTransactionSignerModule = ITransactionSignerModule<EVMUnsignedTransaction>;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@exodus/web3-ethereum",
|
|
3
3
|
"description": "Apps connectivity library for EVM-compatible chains.",
|
|
4
|
-
"version": "12.
|
|
4
|
+
"version": "12.18.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"sideEffects": false,
|
|
7
7
|
"module": "lib/index.js",
|
|
@@ -51,5 +51,5 @@
|
|
|
51
51
|
"@exodus/web3-validation": "^1.38.0",
|
|
52
52
|
"@wallet-standard/base": "^1.0.1"
|
|
53
53
|
},
|
|
54
|
-
"gitHead": "
|
|
54
|
+
"gitHead": "9d986c3e15d2a445722ec8d62a40fc386eb672c7"
|
|
55
55
|
}
|