@injectivelabs/wallet-trezor 1.16.38-alpha.3 → 1.16.38-alpha.5
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.cjs +213 -0
- package/dist/cjs/index.d.cts +7 -1
- package/dist/esm/index.d.ts +7 -1
- package/dist/esm/index.js +214 -1
- package/package.json +6 -6
package/dist/cjs/index.cjs
CHANGED
|
@@ -201,6 +201,195 @@ var BaseTrezorTransport = class {
|
|
|
201
201
|
}
|
|
202
202
|
};
|
|
203
203
|
|
|
204
|
+
//#endregion
|
|
205
|
+
//#region src/strategy/Eip1193Provider.ts
|
|
206
|
+
var TrezorEip1193Provider = class {
|
|
207
|
+
constructor(trezor, params) {
|
|
208
|
+
_defineProperty(this, "trezor", void 0);
|
|
209
|
+
_defineProperty(this, "derivationPath", void 0);
|
|
210
|
+
_defineProperty(this, "address", void 0);
|
|
211
|
+
_defineProperty(this, "chainId", void 0);
|
|
212
|
+
this.trezor = trezor;
|
|
213
|
+
this.derivationPath = params.derivationPath || "m/44'/60'/0'/0/0";
|
|
214
|
+
this.chainId = parseInt(params.chainId || "1");
|
|
215
|
+
}
|
|
216
|
+
async getClient() {
|
|
217
|
+
return (0, __injectivelabs_wallet_base.getViemWalletClient)({
|
|
218
|
+
chainId: this.chainId,
|
|
219
|
+
account: await this.getAddress()
|
|
220
|
+
});
|
|
221
|
+
}
|
|
222
|
+
async setChainId(chainId) {
|
|
223
|
+
this.chainId = parseInt(chainId.replace("0x", ""), 16);
|
|
224
|
+
}
|
|
225
|
+
async getAddress() {
|
|
226
|
+
if (!this.address) {
|
|
227
|
+
const TrezorConnect = await loadTrezorConnect();
|
|
228
|
+
await this.trezor.connect();
|
|
229
|
+
const response = await TrezorConnect.ethereumGetAddress({
|
|
230
|
+
path: this.derivationPath,
|
|
231
|
+
showOnTrezor: false
|
|
232
|
+
});
|
|
233
|
+
if (!response.success) throw new Error(response.payload && response.payload.error || "Failed to get address from Trezor");
|
|
234
|
+
this.address = response.payload.address;
|
|
235
|
+
}
|
|
236
|
+
return this.address;
|
|
237
|
+
}
|
|
238
|
+
async signTypedData(data) {
|
|
239
|
+
const TrezorConnect = await loadTrezorConnect();
|
|
240
|
+
await this.trezor.connect();
|
|
241
|
+
const object = JSON.parse(data);
|
|
242
|
+
const { types: { EIP712Domain = [], ...otherTypes } = {}, message = {}, domain = {}, primaryType, domain_separator_hash, message_hash } = transformTypedData({
|
|
243
|
+
...object,
|
|
244
|
+
domain: {
|
|
245
|
+
...object.domain,
|
|
246
|
+
chainId: object.domain.chainId,
|
|
247
|
+
salt: "0"
|
|
248
|
+
}
|
|
249
|
+
});
|
|
250
|
+
const response = await TrezorConnect.ethereumSignTypedData({
|
|
251
|
+
path: this.derivationPath,
|
|
252
|
+
data: {
|
|
253
|
+
types: {
|
|
254
|
+
EIP712Domain,
|
|
255
|
+
...otherTypes
|
|
256
|
+
},
|
|
257
|
+
message,
|
|
258
|
+
domain,
|
|
259
|
+
primaryType
|
|
260
|
+
},
|
|
261
|
+
message_hash,
|
|
262
|
+
domain_separator_hash,
|
|
263
|
+
metamask_v4_compat: true
|
|
264
|
+
});
|
|
265
|
+
if ("code" in response.payload && response.payload.code === "Failure_ActionCancelled") throw new Error("Request rejected");
|
|
266
|
+
if (!response.success) throw new Error(response.payload && response.payload.error || "Unknown error");
|
|
267
|
+
return response.payload.signature;
|
|
268
|
+
}
|
|
269
|
+
async signTransaction(txData) {
|
|
270
|
+
const TrezorConnect = await loadTrezorConnect();
|
|
271
|
+
await this.trezor.connect();
|
|
272
|
+
const parseHexValue = (value) => {
|
|
273
|
+
if (typeof value === "string") {
|
|
274
|
+
const hexValue = value.startsWith("0x") ? value : `0x${value}`;
|
|
275
|
+
return BigInt(hexValue);
|
|
276
|
+
}
|
|
277
|
+
return BigInt(value);
|
|
278
|
+
};
|
|
279
|
+
const chainId = txData.chainId || this.chainId;
|
|
280
|
+
const valueBigInt = parseHexValue(txData.value || "0x0");
|
|
281
|
+
const gasBigInt = parseHexValue(txData.gas || txData.gasLimit);
|
|
282
|
+
const maxFeePerGasBigInt = parseHexValue(txData.maxFeePerGas);
|
|
283
|
+
const maxPriorityFeePerGasBigInt = parseHexValue(txData.maxPriorityFeePerGas);
|
|
284
|
+
const trezorTxData = {
|
|
285
|
+
to: txData.to,
|
|
286
|
+
value: (0, viem.toHex)(valueBigInt),
|
|
287
|
+
gasLimit: (0, viem.toHex)(gasBigInt),
|
|
288
|
+
nonce: (0, viem.toHex)(txData.nonce),
|
|
289
|
+
data: txData.data || "0x",
|
|
290
|
+
chainId,
|
|
291
|
+
maxFeePerGas: (0, viem.toHex)(maxFeePerGasBigInt),
|
|
292
|
+
maxPriorityFeePerGas: (0, viem.toHex)(maxPriorityFeePerGasBigInt)
|
|
293
|
+
};
|
|
294
|
+
const response = await TrezorConnect.ethereumSignTransaction({
|
|
295
|
+
path: this.derivationPath,
|
|
296
|
+
transaction: trezorTxData
|
|
297
|
+
});
|
|
298
|
+
if (!response.success) throw new Error(response.payload && response.payload.error || "Something happened while signing with Trezor");
|
|
299
|
+
return (0, viem.serializeTransaction)({
|
|
300
|
+
type: "eip1559",
|
|
301
|
+
chainId,
|
|
302
|
+
nonce: txData.nonce,
|
|
303
|
+
to: txData.to,
|
|
304
|
+
value: valueBigInt,
|
|
305
|
+
data: txData.data || "0x",
|
|
306
|
+
gas: gasBigInt,
|
|
307
|
+
maxFeePerGas: maxFeePerGasBigInt,
|
|
308
|
+
maxPriorityFeePerGas: maxPriorityFeePerGasBigInt,
|
|
309
|
+
v: BigInt(response.payload.v),
|
|
310
|
+
r: response.payload.r,
|
|
311
|
+
s: response.payload.s
|
|
312
|
+
});
|
|
313
|
+
}
|
|
314
|
+
async signMessage(message) {
|
|
315
|
+
const TrezorConnect = await loadTrezorConnect();
|
|
316
|
+
await this.trezor.connect();
|
|
317
|
+
const response = await TrezorConnect.ethereumSignMessage({
|
|
318
|
+
path: this.derivationPath,
|
|
319
|
+
message
|
|
320
|
+
});
|
|
321
|
+
if (!response.success) throw new Error(response.payload && response.payload.error || "Unknown error");
|
|
322
|
+
const signature = response.payload.signature;
|
|
323
|
+
return signature.startsWith("0x") ? signature : `0x${signature}`;
|
|
324
|
+
}
|
|
325
|
+
getChain() {
|
|
326
|
+
return (0, __injectivelabs_wallet_base.getEvmChainConfig)(this.chainId);
|
|
327
|
+
}
|
|
328
|
+
async request(args) {
|
|
329
|
+
if (args.method === "eth_requestAccounts") return [await this.getAddress()];
|
|
330
|
+
if (args.method === "eth_sign") {
|
|
331
|
+
if (!args.params[0]) throw new Error("Missing parameter for eth_sign");
|
|
332
|
+
return this.signMessage(args.params[0]);
|
|
333
|
+
}
|
|
334
|
+
if (args.method === "eth_signTransaction") {
|
|
335
|
+
if (!args.params[0]) throw new Error("Missing parameter for eth_signTransaction");
|
|
336
|
+
return this.signTransaction(args.params[0]);
|
|
337
|
+
}
|
|
338
|
+
if (args.method === "eth_signTypedData") {
|
|
339
|
+
if (!args.params[0]) throw new Error("Missing parameter for eth_signTypedData");
|
|
340
|
+
return this.signTypedData(args.params[0]);
|
|
341
|
+
}
|
|
342
|
+
if (args.method === "eth_chainId") return `0x${this.chainId.toString(16)}`;
|
|
343
|
+
if (args.method === "wallet_switchEthereumChain") {
|
|
344
|
+
var _args$params$;
|
|
345
|
+
return this.setChainId(((_args$params$ = args.params[0]) === null || _args$params$ === void 0 ? void 0 : _args$params$.chainId) || "0x1");
|
|
346
|
+
}
|
|
347
|
+
if (args.method === "eth_estimateGas") {
|
|
348
|
+
const client = (0, __injectivelabs_wallet_base.getViemPublicClient)(this.chainId);
|
|
349
|
+
const data = {
|
|
350
|
+
to: args.params[0].to,
|
|
351
|
+
value: args.params[0].value,
|
|
352
|
+
data: args.params[0].data,
|
|
353
|
+
account: await this.getAddress()
|
|
354
|
+
};
|
|
355
|
+
return `0x${(await client.estimateGas(data)).toString(16)}`;
|
|
356
|
+
}
|
|
357
|
+
if (args.method === "eth_getTransactionCount") {
|
|
358
|
+
if (!args.params) throw new Error("params is required");
|
|
359
|
+
return `0x${(await (0, __injectivelabs_wallet_base.getViemPublicClient)(this.chainId).getTransactionCount({
|
|
360
|
+
address: await this.getAddress(),
|
|
361
|
+
blockTag: "pending"
|
|
362
|
+
})).toString(16)}`;
|
|
363
|
+
}
|
|
364
|
+
if (args.method === "eth_sendTransaction") {
|
|
365
|
+
const address = await this.getAddress();
|
|
366
|
+
const walletClient = (0, __injectivelabs_wallet_base.getViemWalletClient)({
|
|
367
|
+
chainId: this.chainId,
|
|
368
|
+
account: address
|
|
369
|
+
});
|
|
370
|
+
const preparedTransaction = await walletClient.prepareTransactionRequest({ ...args.params[0] });
|
|
371
|
+
const signedTransaction = await this.signTransaction(preparedTransaction);
|
|
372
|
+
return await walletClient.sendRawTransaction({ serializedTransaction: signedTransaction });
|
|
373
|
+
}
|
|
374
|
+
return (await this.getClient()).request({
|
|
375
|
+
method: args.method,
|
|
376
|
+
params: args.params
|
|
377
|
+
});
|
|
378
|
+
}
|
|
379
|
+
on(_event, _listener) {
|
|
380
|
+
throw new Error("Method not implemented.");
|
|
381
|
+
}
|
|
382
|
+
once(_event, _listener) {
|
|
383
|
+
throw new Error("Method not implemented.");
|
|
384
|
+
}
|
|
385
|
+
removeListener(_event, _listener) {
|
|
386
|
+
throw new Error("Method not implemented.");
|
|
387
|
+
}
|
|
388
|
+
off(_event, _listener) {
|
|
389
|
+
throw new Error("Method not implemented.");
|
|
390
|
+
}
|
|
391
|
+
};
|
|
392
|
+
|
|
204
393
|
//#endregion
|
|
205
394
|
//#region src/strategy/Base.ts
|
|
206
395
|
var TrezorBase = class extends __injectivelabs_wallet_base.BaseConcreteStrategy {
|
|
@@ -238,6 +427,23 @@ var TrezorBase = class extends __injectivelabs_wallet_base.BaseConcreteStrategy
|
|
|
238
427
|
});
|
|
239
428
|
}
|
|
240
429
|
}
|
|
430
|
+
async getAddressesInfo() {
|
|
431
|
+
const { baseDerivationPath, derivationPathType } = this;
|
|
432
|
+
try {
|
|
433
|
+
await this.trezor.connect();
|
|
434
|
+
return (await (await this.trezor.getAccountManager()).getWallets(baseDerivationPath, derivationPathType)).map((k) => ({
|
|
435
|
+
address: k.address,
|
|
436
|
+
derivationPath: k.derivationPath,
|
|
437
|
+
baseDerivationPath: derivationPathType
|
|
438
|
+
}));
|
|
439
|
+
} catch (e) {
|
|
440
|
+
throw new __injectivelabs_exceptions.TrezorException(new Error(e.message), {
|
|
441
|
+
code: __injectivelabs_exceptions.UnspecifiedErrorCode,
|
|
442
|
+
type: __injectivelabs_exceptions.ErrorType.WalletError,
|
|
443
|
+
contextModule: __injectivelabs_wallet_base.WalletAction.GetAccounts
|
|
444
|
+
});
|
|
445
|
+
}
|
|
446
|
+
}
|
|
241
447
|
async getSessionOrConfirm(address) {
|
|
242
448
|
return Promise.resolve(`0x${(0, __injectivelabs_sdk_ts_utils.uint8ArrayToHex)((0, __injectivelabs_sdk_ts_utils.stringToUint8Array)(`Confirmation for ${address} at time: ${Date.now()}`))}`);
|
|
243
449
|
}
|
|
@@ -427,6 +633,13 @@ var TrezorBase = class extends __injectivelabs_wallet_base.BaseConcreteStrategy
|
|
|
427
633
|
}
|
|
428
634
|
return await accountManager.getWalletForAddress(address);
|
|
429
635
|
}
|
|
636
|
+
async getEip1193Provider() {
|
|
637
|
+
var _this$metadata;
|
|
638
|
+
return new TrezorEip1193Provider(this.trezor, {
|
|
639
|
+
chainId: this.evmOptions.evmChainId.toString(),
|
|
640
|
+
derivationPath: (_this$metadata = this.metadata) === null || _this$metadata === void 0 ? void 0 : _this$metadata.derivationPath
|
|
641
|
+
});
|
|
642
|
+
}
|
|
430
643
|
async getPublicClient(evmChainId) {
|
|
431
644
|
var _options$rpcUrls;
|
|
432
645
|
if (this.publicClient) return this.publicClient;
|
package/dist/cjs/index.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { BaseConcreteStrategy, ConcreteEvmWalletStrategyArgs, ConcreteWalletStrategy, SendTransactionOptions, StdSignDoc, WalletDeviceType } from "@injectivelabs/wallet-base";
|
|
1
|
+
import { BaseConcreteStrategy, ConcreteEvmWalletStrategyArgs, ConcreteWalletStrategy, Eip1193Provider, SendTransactionOptions, StdSignDoc, WalletDeviceType } from "@injectivelabs/wallet-base";
|
|
2
2
|
import { AccountAddress, EvmChainId } from "@injectivelabs/ts-types";
|
|
3
3
|
import { TxResponse } from "@injectivelabs/sdk-ts/core/tx";
|
|
4
4
|
import { AminoSignResponse, DirectSignResponse, TxRaw } from "@injectivelabs/sdk-ts/types";
|
|
@@ -34,6 +34,11 @@ declare class TrezorBase extends BaseConcreteStrategy implements ConcreteWalletS
|
|
|
34
34
|
enable(): Promise<boolean>;
|
|
35
35
|
disconnect(): Promise<void>;
|
|
36
36
|
getAddresses(): Promise<string[]>;
|
|
37
|
+
getAddressesInfo(): Promise<{
|
|
38
|
+
address: string;
|
|
39
|
+
derivationPath: string;
|
|
40
|
+
baseDerivationPath: string;
|
|
41
|
+
}[]>;
|
|
37
42
|
getSessionOrConfirm(address: AccountAddress): Promise<string>;
|
|
38
43
|
sendEvmTransaction(txData: any, args: {
|
|
39
44
|
address: string;
|
|
@@ -57,6 +62,7 @@ declare class TrezorBase extends BaseConcreteStrategy implements ConcreteWalletS
|
|
|
57
62
|
getPubKey(): Promise<string>;
|
|
58
63
|
private signEvmTransaction;
|
|
59
64
|
private getWalletForAddress;
|
|
65
|
+
getEip1193Provider(): Promise<Eip1193Provider>;
|
|
60
66
|
private getPublicClient;
|
|
61
67
|
}
|
|
62
68
|
//#endregion
|
package/dist/esm/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { TxResponse } from "@injectivelabs/sdk-ts/core/tx";
|
|
2
|
-
import { BaseConcreteStrategy, ConcreteEvmWalletStrategyArgs, ConcreteWalletStrategy, SendTransactionOptions, StdSignDoc, WalletDeviceType } from "@injectivelabs/wallet-base";
|
|
2
|
+
import { BaseConcreteStrategy, ConcreteEvmWalletStrategyArgs, ConcreteWalletStrategy, Eip1193Provider, SendTransactionOptions, StdSignDoc, WalletDeviceType } from "@injectivelabs/wallet-base";
|
|
3
3
|
import { AccountAddress, EvmChainId } from "@injectivelabs/ts-types";
|
|
4
4
|
import { AminoSignResponse, DirectSignResponse, TxRaw } from "@injectivelabs/sdk-ts/types";
|
|
5
5
|
|
|
@@ -34,6 +34,11 @@ declare class TrezorBase extends BaseConcreteStrategy implements ConcreteWalletS
|
|
|
34
34
|
enable(): Promise<boolean>;
|
|
35
35
|
disconnect(): Promise<void>;
|
|
36
36
|
getAddresses(): Promise<string[]>;
|
|
37
|
+
getAddressesInfo(): Promise<{
|
|
38
|
+
address: string;
|
|
39
|
+
derivationPath: string;
|
|
40
|
+
baseDerivationPath: string;
|
|
41
|
+
}[]>;
|
|
37
42
|
getSessionOrConfirm(address: AccountAddress): Promise<string>;
|
|
38
43
|
sendEvmTransaction(txData: any, args: {
|
|
39
44
|
address: string;
|
|
@@ -57,6 +62,7 @@ declare class TrezorBase extends BaseConcreteStrategy implements ConcreteWalletS
|
|
|
57
62
|
getPubKey(): Promise<string>;
|
|
58
63
|
private signEvmTransaction;
|
|
59
64
|
private getWalletForAddress;
|
|
65
|
+
getEip1193Provider(): Promise<Eip1193Provider>;
|
|
60
66
|
private getPublicClient;
|
|
61
67
|
}
|
|
62
68
|
//#endregion
|
package/dist/esm/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { serializeTransaction, toHex } from "viem";
|
|
2
2
|
import { TxGrpcApi } from "@injectivelabs/sdk-ts/core/tx";
|
|
3
|
-
import { BaseConcreteStrategy, DEFAULT_ADDRESS_SEARCH_LIMIT, DEFAULT_BASE_DERIVATION_PATH, DEFAULT_NUM_ADDRESSES_TO_FETCH, WalletAction, WalletDeviceType, getViemPublicClient } from "@injectivelabs/wallet-base";
|
|
3
|
+
import { BaseConcreteStrategy, DEFAULT_ADDRESS_SEARCH_LIMIT, DEFAULT_BASE_DERIVATION_PATH, DEFAULT_NUM_ADDRESSES_TO_FETCH, WalletAction, WalletDeviceType, getEvmChainConfig, getViemPublicClient, getViemWalletClient } from "@injectivelabs/wallet-base";
|
|
4
4
|
import { SignTypedDataVersionV4, TypedDataUtilsHashStruct, TypedDataUtilsSanitizeData, addHexPrefix, hexToUint8Array, publicKeyToAddress, sanitizeTypedData, stringToUint8Array, toUtf8, uint8ArrayToHex } from "@injectivelabs/sdk-ts/utils";
|
|
5
5
|
import { ErrorType, GeneralException, TransactionException, TrezorException, UnspecifiedErrorCode, WalletException } from "@injectivelabs/exceptions";
|
|
6
6
|
|
|
@@ -201,6 +201,195 @@ var BaseTrezorTransport = class {
|
|
|
201
201
|
}
|
|
202
202
|
};
|
|
203
203
|
|
|
204
|
+
//#endregion
|
|
205
|
+
//#region src/strategy/Eip1193Provider.ts
|
|
206
|
+
var TrezorEip1193Provider = class {
|
|
207
|
+
constructor(trezor, params) {
|
|
208
|
+
_defineProperty(this, "trezor", void 0);
|
|
209
|
+
_defineProperty(this, "derivationPath", void 0);
|
|
210
|
+
_defineProperty(this, "address", void 0);
|
|
211
|
+
_defineProperty(this, "chainId", void 0);
|
|
212
|
+
this.trezor = trezor;
|
|
213
|
+
this.derivationPath = params.derivationPath || "m/44'/60'/0'/0/0";
|
|
214
|
+
this.chainId = parseInt(params.chainId || "1");
|
|
215
|
+
}
|
|
216
|
+
async getClient() {
|
|
217
|
+
return getViemWalletClient({
|
|
218
|
+
chainId: this.chainId,
|
|
219
|
+
account: await this.getAddress()
|
|
220
|
+
});
|
|
221
|
+
}
|
|
222
|
+
async setChainId(chainId) {
|
|
223
|
+
this.chainId = parseInt(chainId.replace("0x", ""), 16);
|
|
224
|
+
}
|
|
225
|
+
async getAddress() {
|
|
226
|
+
if (!this.address) {
|
|
227
|
+
const TrezorConnect = await loadTrezorConnect();
|
|
228
|
+
await this.trezor.connect();
|
|
229
|
+
const response = await TrezorConnect.ethereumGetAddress({
|
|
230
|
+
path: this.derivationPath,
|
|
231
|
+
showOnTrezor: false
|
|
232
|
+
});
|
|
233
|
+
if (!response.success) throw new Error(response.payload && response.payload.error || "Failed to get address from Trezor");
|
|
234
|
+
this.address = response.payload.address;
|
|
235
|
+
}
|
|
236
|
+
return this.address;
|
|
237
|
+
}
|
|
238
|
+
async signTypedData(data) {
|
|
239
|
+
const TrezorConnect = await loadTrezorConnect();
|
|
240
|
+
await this.trezor.connect();
|
|
241
|
+
const object = JSON.parse(data);
|
|
242
|
+
const { types: { EIP712Domain = [], ...otherTypes } = {}, message = {}, domain = {}, primaryType, domain_separator_hash, message_hash } = transformTypedData({
|
|
243
|
+
...object,
|
|
244
|
+
domain: {
|
|
245
|
+
...object.domain,
|
|
246
|
+
chainId: object.domain.chainId,
|
|
247
|
+
salt: "0"
|
|
248
|
+
}
|
|
249
|
+
});
|
|
250
|
+
const response = await TrezorConnect.ethereumSignTypedData({
|
|
251
|
+
path: this.derivationPath,
|
|
252
|
+
data: {
|
|
253
|
+
types: {
|
|
254
|
+
EIP712Domain,
|
|
255
|
+
...otherTypes
|
|
256
|
+
},
|
|
257
|
+
message,
|
|
258
|
+
domain,
|
|
259
|
+
primaryType
|
|
260
|
+
},
|
|
261
|
+
message_hash,
|
|
262
|
+
domain_separator_hash,
|
|
263
|
+
metamask_v4_compat: true
|
|
264
|
+
});
|
|
265
|
+
if ("code" in response.payload && response.payload.code === "Failure_ActionCancelled") throw new Error("Request rejected");
|
|
266
|
+
if (!response.success) throw new Error(response.payload && response.payload.error || "Unknown error");
|
|
267
|
+
return response.payload.signature;
|
|
268
|
+
}
|
|
269
|
+
async signTransaction(txData) {
|
|
270
|
+
const TrezorConnect = await loadTrezorConnect();
|
|
271
|
+
await this.trezor.connect();
|
|
272
|
+
const parseHexValue = (value) => {
|
|
273
|
+
if (typeof value === "string") {
|
|
274
|
+
const hexValue = value.startsWith("0x") ? value : `0x${value}`;
|
|
275
|
+
return BigInt(hexValue);
|
|
276
|
+
}
|
|
277
|
+
return BigInt(value);
|
|
278
|
+
};
|
|
279
|
+
const chainId = txData.chainId || this.chainId;
|
|
280
|
+
const valueBigInt = parseHexValue(txData.value || "0x0");
|
|
281
|
+
const gasBigInt = parseHexValue(txData.gas || txData.gasLimit);
|
|
282
|
+
const maxFeePerGasBigInt = parseHexValue(txData.maxFeePerGas);
|
|
283
|
+
const maxPriorityFeePerGasBigInt = parseHexValue(txData.maxPriorityFeePerGas);
|
|
284
|
+
const trezorTxData = {
|
|
285
|
+
to: txData.to,
|
|
286
|
+
value: toHex(valueBigInt),
|
|
287
|
+
gasLimit: toHex(gasBigInt),
|
|
288
|
+
nonce: toHex(txData.nonce),
|
|
289
|
+
data: txData.data || "0x",
|
|
290
|
+
chainId,
|
|
291
|
+
maxFeePerGas: toHex(maxFeePerGasBigInt),
|
|
292
|
+
maxPriorityFeePerGas: toHex(maxPriorityFeePerGasBigInt)
|
|
293
|
+
};
|
|
294
|
+
const response = await TrezorConnect.ethereumSignTransaction({
|
|
295
|
+
path: this.derivationPath,
|
|
296
|
+
transaction: trezorTxData
|
|
297
|
+
});
|
|
298
|
+
if (!response.success) throw new Error(response.payload && response.payload.error || "Something happened while signing with Trezor");
|
|
299
|
+
return serializeTransaction({
|
|
300
|
+
type: "eip1559",
|
|
301
|
+
chainId,
|
|
302
|
+
nonce: txData.nonce,
|
|
303
|
+
to: txData.to,
|
|
304
|
+
value: valueBigInt,
|
|
305
|
+
data: txData.data || "0x",
|
|
306
|
+
gas: gasBigInt,
|
|
307
|
+
maxFeePerGas: maxFeePerGasBigInt,
|
|
308
|
+
maxPriorityFeePerGas: maxPriorityFeePerGasBigInt,
|
|
309
|
+
v: BigInt(response.payload.v),
|
|
310
|
+
r: response.payload.r,
|
|
311
|
+
s: response.payload.s
|
|
312
|
+
});
|
|
313
|
+
}
|
|
314
|
+
async signMessage(message) {
|
|
315
|
+
const TrezorConnect = await loadTrezorConnect();
|
|
316
|
+
await this.trezor.connect();
|
|
317
|
+
const response = await TrezorConnect.ethereumSignMessage({
|
|
318
|
+
path: this.derivationPath,
|
|
319
|
+
message
|
|
320
|
+
});
|
|
321
|
+
if (!response.success) throw new Error(response.payload && response.payload.error || "Unknown error");
|
|
322
|
+
const signature = response.payload.signature;
|
|
323
|
+
return signature.startsWith("0x") ? signature : `0x${signature}`;
|
|
324
|
+
}
|
|
325
|
+
getChain() {
|
|
326
|
+
return getEvmChainConfig(this.chainId);
|
|
327
|
+
}
|
|
328
|
+
async request(args) {
|
|
329
|
+
if (args.method === "eth_requestAccounts") return [await this.getAddress()];
|
|
330
|
+
if (args.method === "eth_sign") {
|
|
331
|
+
if (!args.params[0]) throw new Error("Missing parameter for eth_sign");
|
|
332
|
+
return this.signMessage(args.params[0]);
|
|
333
|
+
}
|
|
334
|
+
if (args.method === "eth_signTransaction") {
|
|
335
|
+
if (!args.params[0]) throw new Error("Missing parameter for eth_signTransaction");
|
|
336
|
+
return this.signTransaction(args.params[0]);
|
|
337
|
+
}
|
|
338
|
+
if (args.method === "eth_signTypedData") {
|
|
339
|
+
if (!args.params[0]) throw new Error("Missing parameter for eth_signTypedData");
|
|
340
|
+
return this.signTypedData(args.params[0]);
|
|
341
|
+
}
|
|
342
|
+
if (args.method === "eth_chainId") return `0x${this.chainId.toString(16)}`;
|
|
343
|
+
if (args.method === "wallet_switchEthereumChain") {
|
|
344
|
+
var _args$params$;
|
|
345
|
+
return this.setChainId(((_args$params$ = args.params[0]) === null || _args$params$ === void 0 ? void 0 : _args$params$.chainId) || "0x1");
|
|
346
|
+
}
|
|
347
|
+
if (args.method === "eth_estimateGas") {
|
|
348
|
+
const client = getViemPublicClient(this.chainId);
|
|
349
|
+
const data = {
|
|
350
|
+
to: args.params[0].to,
|
|
351
|
+
value: args.params[0].value,
|
|
352
|
+
data: args.params[0].data,
|
|
353
|
+
account: await this.getAddress()
|
|
354
|
+
};
|
|
355
|
+
return `0x${(await client.estimateGas(data)).toString(16)}`;
|
|
356
|
+
}
|
|
357
|
+
if (args.method === "eth_getTransactionCount") {
|
|
358
|
+
if (!args.params) throw new Error("params is required");
|
|
359
|
+
return `0x${(await getViemPublicClient(this.chainId).getTransactionCount({
|
|
360
|
+
address: await this.getAddress(),
|
|
361
|
+
blockTag: "pending"
|
|
362
|
+
})).toString(16)}`;
|
|
363
|
+
}
|
|
364
|
+
if (args.method === "eth_sendTransaction") {
|
|
365
|
+
const address = await this.getAddress();
|
|
366
|
+
const walletClient = getViemWalletClient({
|
|
367
|
+
chainId: this.chainId,
|
|
368
|
+
account: address
|
|
369
|
+
});
|
|
370
|
+
const preparedTransaction = await walletClient.prepareTransactionRequest({ ...args.params[0] });
|
|
371
|
+
const signedTransaction = await this.signTransaction(preparedTransaction);
|
|
372
|
+
return await walletClient.sendRawTransaction({ serializedTransaction: signedTransaction });
|
|
373
|
+
}
|
|
374
|
+
return (await this.getClient()).request({
|
|
375
|
+
method: args.method,
|
|
376
|
+
params: args.params
|
|
377
|
+
});
|
|
378
|
+
}
|
|
379
|
+
on(_event, _listener) {
|
|
380
|
+
throw new Error("Method not implemented.");
|
|
381
|
+
}
|
|
382
|
+
once(_event, _listener) {
|
|
383
|
+
throw new Error("Method not implemented.");
|
|
384
|
+
}
|
|
385
|
+
removeListener(_event, _listener) {
|
|
386
|
+
throw new Error("Method not implemented.");
|
|
387
|
+
}
|
|
388
|
+
off(_event, _listener) {
|
|
389
|
+
throw new Error("Method not implemented.");
|
|
390
|
+
}
|
|
391
|
+
};
|
|
392
|
+
|
|
204
393
|
//#endregion
|
|
205
394
|
//#region src/strategy/Base.ts
|
|
206
395
|
var TrezorBase = class extends BaseConcreteStrategy {
|
|
@@ -238,6 +427,23 @@ var TrezorBase = class extends BaseConcreteStrategy {
|
|
|
238
427
|
});
|
|
239
428
|
}
|
|
240
429
|
}
|
|
430
|
+
async getAddressesInfo() {
|
|
431
|
+
const { baseDerivationPath, derivationPathType } = this;
|
|
432
|
+
try {
|
|
433
|
+
await this.trezor.connect();
|
|
434
|
+
return (await (await this.trezor.getAccountManager()).getWallets(baseDerivationPath, derivationPathType)).map((k) => ({
|
|
435
|
+
address: k.address,
|
|
436
|
+
derivationPath: k.derivationPath,
|
|
437
|
+
baseDerivationPath: derivationPathType
|
|
438
|
+
}));
|
|
439
|
+
} catch (e) {
|
|
440
|
+
throw new TrezorException(new Error(e.message), {
|
|
441
|
+
code: UnspecifiedErrorCode,
|
|
442
|
+
type: ErrorType.WalletError,
|
|
443
|
+
contextModule: WalletAction.GetAccounts
|
|
444
|
+
});
|
|
445
|
+
}
|
|
446
|
+
}
|
|
241
447
|
async getSessionOrConfirm(address) {
|
|
242
448
|
return Promise.resolve(`0x${uint8ArrayToHex(stringToUint8Array(`Confirmation for ${address} at time: ${Date.now()}`))}`);
|
|
243
449
|
}
|
|
@@ -427,6 +633,13 @@ var TrezorBase = class extends BaseConcreteStrategy {
|
|
|
427
633
|
}
|
|
428
634
|
return await accountManager.getWalletForAddress(address);
|
|
429
635
|
}
|
|
636
|
+
async getEip1193Provider() {
|
|
637
|
+
var _this$metadata;
|
|
638
|
+
return new TrezorEip1193Provider(this.trezor, {
|
|
639
|
+
chainId: this.evmOptions.evmChainId.toString(),
|
|
640
|
+
derivationPath: (_this$metadata = this.metadata) === null || _this$metadata === void 0 ? void 0 : _this$metadata.derivationPath
|
|
641
|
+
});
|
|
642
|
+
}
|
|
430
643
|
async getPublicClient(evmChainId) {
|
|
431
644
|
var _options$rpcUrls;
|
|
432
645
|
if (this.publicClient) return this.publicClient;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@injectivelabs/wallet-trezor",
|
|
3
|
-
"version": "1.16.38-alpha.
|
|
3
|
+
"version": "1.16.38-alpha.5",
|
|
4
4
|
"description": "Trezor wallet strategy for use with @injectivelabs/wallet-core.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"author": {
|
|
@@ -40,11 +40,11 @@
|
|
|
40
40
|
"dependencies": {
|
|
41
41
|
"@trezor/connect": "^9.6.4",
|
|
42
42
|
"@trezor/connect-web": "^9.6.4",
|
|
43
|
-
"viem": "^2.
|
|
44
|
-
"@injectivelabs/exceptions": "1.16.38-alpha.
|
|
45
|
-
"@injectivelabs/ts
|
|
46
|
-
"@injectivelabs/
|
|
47
|
-
"@injectivelabs/wallet-base": "1.16.38-alpha.
|
|
43
|
+
"viem": "^2.41.2",
|
|
44
|
+
"@injectivelabs/exceptions": "1.16.38-alpha.3",
|
|
45
|
+
"@injectivelabs/sdk-ts": "1.16.38-alpha.5",
|
|
46
|
+
"@injectivelabs/ts-types": "1.16.38-alpha.2",
|
|
47
|
+
"@injectivelabs/wallet-base": "1.16.38-alpha.5"
|
|
48
48
|
},
|
|
49
49
|
"publishConfig": {
|
|
50
50
|
"access": "public"
|