@injectivelabs/wallet-trezor 1.16.12 → 1.16.13-alpha.1
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/strategy/Base.d.ts +6 -5
- package/dist/cjs/strategy/Base.js +28 -49
- package/dist/cjs/strategy/TrezorBip32.d.ts +1 -1
- package/dist/cjs/strategy/TrezorBip32.js +1 -1
- package/dist/cjs/strategy/TrezorBip44.d.ts +1 -1
- package/dist/cjs/strategy/TrezorBip44.js +1 -1
- package/dist/cjs/strategy/hw/AccountManager.d.ts +3 -2
- package/dist/cjs/strategy/hw/AccountManager.js +5 -9
- package/dist/cjs/strategy/hw/index.d.ts +1 -1
- package/dist/cjs/strategy/hw/index.js +2 -2
- package/dist/cjs/strategy/hw/transport/base.d.ts +1 -1
- package/dist/cjs/strategy/hw/transport/base.js +1 -1
- package/dist/cjs/types.d.ts +10 -6
- package/dist/cjs/types.js +5 -6
- package/dist/esm/strategy/Base.d.ts +6 -5
- package/dist/esm/strategy/Base.js +29 -50
- package/dist/esm/strategy/TrezorBip32.d.ts +1 -1
- package/dist/esm/strategy/TrezorBip32.js +1 -1
- package/dist/esm/strategy/TrezorBip44.d.ts +1 -1
- package/dist/esm/strategy/TrezorBip44.js +1 -1
- package/dist/esm/strategy/hw/AccountManager.d.ts +3 -2
- package/dist/esm/strategy/hw/AccountManager.js +5 -6
- package/dist/esm/strategy/hw/index.d.ts +1 -1
- package/dist/esm/strategy/hw/index.js +1 -1
- package/dist/esm/strategy/hw/transport/base.d.ts +1 -1
- package/dist/esm/strategy/hw/transport/base.js +1 -1
- package/dist/esm/types.d.ts +10 -6
- package/dist/esm/types.js +5 -6
- package/package.json +7 -9
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { AccountAddress, EvmChainId } from '@injectivelabs/ts-types';
|
|
4
|
-
import {
|
|
1
|
+
import { WalletDeviceType, BaseConcreteStrategy } from '@injectivelabs/wallet-base';
|
|
2
|
+
import type { TrezorDerivationPathType } from '../types.js';
|
|
3
|
+
import type { AccountAddress, EvmChainId as EvmChainIdType } from '@injectivelabs/ts-types';
|
|
4
|
+
import type { TxRaw, TxResponse, AminoSignResponse, DirectSignResponse } from '@injectivelabs/sdk-ts';
|
|
5
|
+
import type { StdSignDoc, SendTransactionOptions, ConcreteWalletStrategy, ConcreteEvmWalletStrategyArgs } from '@injectivelabs/wallet-base';
|
|
5
6
|
export default class TrezorBase extends BaseConcreteStrategy implements ConcreteWalletStrategy {
|
|
6
7
|
private baseDerivationPath;
|
|
7
8
|
private trezor;
|
|
@@ -18,7 +19,7 @@ export default class TrezorBase extends BaseConcreteStrategy implements Concrete
|
|
|
18
19
|
getSessionOrConfirm(address: AccountAddress): Promise<string>;
|
|
19
20
|
sendEvmTransaction(txData: any, args: {
|
|
20
21
|
address: string;
|
|
21
|
-
evmChainId:
|
|
22
|
+
evmChainId: EvmChainIdType;
|
|
22
23
|
}): Promise<string>;
|
|
23
24
|
sendTransaction(transaction: TxRaw, options: SendTransactionOptions): Promise<TxResponse>;
|
|
24
25
|
signEip712TypedData(eip712json: string, address: AccountAddress): Promise<string>;
|
|
@@ -1,30 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
const viem_1 = require("viem");
|
|
4
|
+
const ts_types_1 = require("@injectivelabs/ts-types");
|
|
5
5
|
const sdk_ts_1 = require("@injectivelabs/sdk-ts");
|
|
6
|
+
const alchemy_sdk_1 = require("alchemy-sdk");
|
|
6
7
|
const exceptions_1 = require("@injectivelabs/exceptions");
|
|
7
8
|
const wallet_base_1 = require("@injectivelabs/wallet-base");
|
|
8
|
-
const ethereumjs_util_1 = require("ethereumjs-util");
|
|
9
|
-
const tx_1 = require("@ethereumjs/tx");
|
|
10
|
-
const common_1 = require("@ethereumjs/common");
|
|
11
|
-
const alchemy_sdk_1 = require("alchemy-sdk");
|
|
12
|
-
const ts_types_1 = require("@injectivelabs/ts-types");
|
|
13
9
|
const lib_js_1 = require("./lib.js");
|
|
14
10
|
const utils_js_1 = require("../utils.js");
|
|
15
11
|
const index_js_1 = require("./hw/index.js");
|
|
16
|
-
const getNetworkFromChainId = (chainId) => {
|
|
17
|
-
if (chainId === ts_types_1.EvmChainId.Goerli) {
|
|
18
|
-
return common_1.Chain.Goerli;
|
|
19
|
-
}
|
|
20
|
-
if (chainId === ts_types_1.EvmChainId.Sepolia) {
|
|
21
|
-
return common_1.Chain.Sepolia;
|
|
22
|
-
}
|
|
23
|
-
if (chainId === ts_types_1.EvmChainId.Kovan) {
|
|
24
|
-
return common_1.Chain.Goerli;
|
|
25
|
-
}
|
|
26
|
-
return common_1.Chain.Mainnet;
|
|
27
|
-
};
|
|
28
12
|
class TrezorBase extends wallet_base_1.BaseConcreteStrategy {
|
|
29
13
|
baseDerivationPath;
|
|
30
14
|
trezor;
|
|
@@ -70,7 +54,7 @@ class TrezorBase extends wallet_base_1.BaseConcreteStrategy {
|
|
|
70
54
|
const signedTransaction = await this.signEvmTransaction(txData, args);
|
|
71
55
|
try {
|
|
72
56
|
const alchemy = await this.getAlchemy(args.evmChainId);
|
|
73
|
-
const txReceipt = await alchemy.core.sendTransaction(
|
|
57
|
+
const txReceipt = await alchemy.core.sendTransaction(signedTransaction);
|
|
74
58
|
return txReceipt.hash;
|
|
75
59
|
}
|
|
76
60
|
catch (e) {
|
|
@@ -146,7 +130,6 @@ class TrezorBase extends wallet_base_1.BaseConcreteStrategy {
|
|
|
146
130
|
contextModule: wallet_base_1.WalletAction.SendTransaction,
|
|
147
131
|
});
|
|
148
132
|
}
|
|
149
|
-
// eslint-disable-next-line class-methods-use-this
|
|
150
133
|
async signCosmosTransaction(_transaction) {
|
|
151
134
|
throw new exceptions_1.WalletException(new Error('This wallet does not support signing Cosmos transactions'), {
|
|
152
135
|
code: exceptions_1.UnspecifiedErrorCode,
|
|
@@ -184,7 +167,6 @@ class TrezorBase extends wallet_base_1.BaseConcreteStrategy {
|
|
|
184
167
|
async getEvmTransactionReceipt(txHash) {
|
|
185
168
|
return Promise.resolve(txHash);
|
|
186
169
|
}
|
|
187
|
-
// eslint-disable-next-line class-methods-use-this
|
|
188
170
|
async getPubKey() {
|
|
189
171
|
throw new exceptions_1.WalletException(new Error('You can only fetch PubKey from Cosmos native wallets'));
|
|
190
172
|
}
|
|
@@ -193,33 +175,23 @@ class TrezorBase extends wallet_base_1.BaseConcreteStrategy {
|
|
|
193
175
|
const chainId = parseInt(args.evmChainId.toString(), 10);
|
|
194
176
|
const alchemy = await this.getAlchemy(args.evmChainId);
|
|
195
177
|
const nonce = await alchemy.core.getTransactionCount(args.address);
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
hardfork: common_1.Hardfork.London,
|
|
199
|
-
});
|
|
200
|
-
const eip1559TxData = {
|
|
201
|
-
from: txData.from,
|
|
202
|
-
data: txData.data,
|
|
178
|
+
// Create transaction data for Trezor API (still needs hex strings)
|
|
179
|
+
const trezorTxData = {
|
|
203
180
|
to: txData.to,
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
maxPriorityFeePerGas: (0, ethereumjs_util_1.addHexPrefix)(txData.maxPriorityFeePerGas || wallet_base_1.TIP_IN_GWEI.toString(16)),
|
|
209
|
-
};
|
|
210
|
-
const tx = tx_1.FeeMarketEIP1559Transaction.fromTxData(eip1559TxData, {
|
|
211
|
-
common,
|
|
212
|
-
});
|
|
213
|
-
const transaction = {
|
|
214
|
-
...tx.toJSON(),
|
|
181
|
+
value: (0, viem_1.toHex)(txData.value || 0),
|
|
182
|
+
gasLimit: (0, viem_1.toHex)(txData.gas),
|
|
183
|
+
nonce: (0, viem_1.toHex)(nonce),
|
|
184
|
+
data: txData.data || '0x',
|
|
215
185
|
chainId,
|
|
186
|
+
maxFeePerGas: (0, viem_1.toHex)(txData.gasPrice || txData.maxFeePerGas),
|
|
187
|
+
maxPriorityFeePerGas: (0, viem_1.toHex)(txData.maxPriorityFeePerGas || wallet_base_1.TIP_IN_GWEI),
|
|
216
188
|
};
|
|
217
189
|
try {
|
|
218
190
|
await this.trezor.connect();
|
|
219
191
|
const { derivationPath } = await this.getWalletForAddress(args.address);
|
|
220
192
|
const response = await TrezorConnect.ethereumSignTransaction({
|
|
221
193
|
path: derivationPath,
|
|
222
|
-
transaction,
|
|
194
|
+
transaction: trezorTxData,
|
|
223
195
|
});
|
|
224
196
|
if (!response.success) {
|
|
225
197
|
throw new exceptions_1.TrezorException(new Error((response.payload && response.payload.error) ||
|
|
@@ -229,15 +201,22 @@ class TrezorBase extends wallet_base_1.BaseConcreteStrategy {
|
|
|
229
201
|
contextModule: wallet_base_1.WalletAction.SignEvmTransaction,
|
|
230
202
|
});
|
|
231
203
|
}
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
204
|
+
// Create viem-compatible transaction data for serialization
|
|
205
|
+
const viemTxData = {
|
|
206
|
+
type: 'eip1559',
|
|
207
|
+
chainId,
|
|
208
|
+
nonce,
|
|
209
|
+
to: txData.to,
|
|
210
|
+
value: BigInt(txData.value || 0),
|
|
211
|
+
data: (txData.data || '0x'),
|
|
212
|
+
gas: BigInt(txData.gas),
|
|
213
|
+
maxFeePerGas: BigInt(txData.gasPrice || txData.maxFeePerGas),
|
|
214
|
+
maxPriorityFeePerGas: BigInt(txData.maxPriorityFeePerGas || wallet_base_1.TIP_IN_GWEI),
|
|
215
|
+
v: BigInt(response.payload.v),
|
|
216
|
+
r: response.payload.r,
|
|
217
|
+
s: response.payload.s,
|
|
237
218
|
};
|
|
238
|
-
return
|
|
239
|
-
common,
|
|
240
|
-
});
|
|
219
|
+
return (0, viem_1.serializeTransaction)(viemTxData);
|
|
241
220
|
}
|
|
242
221
|
catch (e) {
|
|
243
222
|
if (e instanceof exceptions_1.TrezorException) {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { ConcreteEvmWalletStrategyArgs } from '@injectivelabs/wallet-base';
|
|
2
1
|
import TrezorBase from './Base.js';
|
|
2
|
+
import type { ConcreteEvmWalletStrategyArgs } from '@injectivelabs/wallet-base';
|
|
3
3
|
export declare class TrezorBip32 extends TrezorBase {
|
|
4
4
|
constructor(args: ConcreteEvmWalletStrategyArgs);
|
|
5
5
|
}
|
|
@@ -4,8 +4,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.TrezorBip32 = void 0;
|
|
7
|
-
const types_js_1 = require("../types.js");
|
|
8
7
|
const Base_js_1 = __importDefault(require("./Base.js"));
|
|
8
|
+
const types_js_1 = require("../types.js");
|
|
9
9
|
class TrezorBip32 extends Base_js_1.default {
|
|
10
10
|
constructor(args) {
|
|
11
11
|
super({
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { ConcreteEvmWalletStrategyArgs } from '@injectivelabs/wallet-base';
|
|
2
1
|
import TrezorBase from './Base.js';
|
|
2
|
+
import type { ConcreteEvmWalletStrategyArgs } from '@injectivelabs/wallet-base';
|
|
3
3
|
export declare class TrezorBip44 extends TrezorBase {
|
|
4
4
|
constructor(args: ConcreteEvmWalletStrategyArgs);
|
|
5
5
|
}
|
|
@@ -4,8 +4,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.TrezorBip44 = void 0;
|
|
7
|
-
const types_js_1 = require("../types.js");
|
|
8
7
|
const Base_js_1 = __importDefault(require("./Base.js"));
|
|
8
|
+
const types_js_1 = require("../types.js");
|
|
9
9
|
class TrezorBip44 extends Base_js_1.default {
|
|
10
10
|
constructor(args) {
|
|
11
11
|
super({
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { TrezorDerivationPathType } from '../../types.js';
|
|
2
|
+
import type { AccountAddress } from '@injectivelabs/ts-types';
|
|
3
|
+
import type { TrezorWalletInfo } from '../../types.js';
|
|
3
4
|
export default class AccountManager {
|
|
4
5
|
private wallets;
|
|
5
6
|
constructor();
|
|
@@ -1,14 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
/* eslint-disable class-methods-use-this */
|
|
7
|
-
const hdkey_1 = __importDefault(require("hdkey"));
|
|
8
3
|
const exceptions_1 = require("@injectivelabs/exceptions");
|
|
9
4
|
const sdk_ts_1 = require("@injectivelabs/sdk-ts");
|
|
10
5
|
const wallet_base_1 = require("@injectivelabs/wallet-base");
|
|
11
|
-
const lib_js_1 = require("
|
|
6
|
+
const lib_js_1 = require("../lib.js");
|
|
12
7
|
const types_js_1 = require("../../types.js");
|
|
13
8
|
const addressOfHDKey = (hdKey) => {
|
|
14
9
|
const shouldSanitizePublicKey = true;
|
|
@@ -69,9 +64,10 @@ class AccountManager {
|
|
|
69
64
|
'Please make sure your Trezor is connected and unlocked'));
|
|
70
65
|
}
|
|
71
66
|
for (const item of result.payload) {
|
|
72
|
-
const hdKey =
|
|
73
|
-
|
|
74
|
-
|
|
67
|
+
const hdKey = {
|
|
68
|
+
publicKey: Buffer.from(item.publicKey, 'hex'),
|
|
69
|
+
chainCode: Buffer.from(item.chainCode, 'hex'),
|
|
70
|
+
};
|
|
75
71
|
const address = addressOfHDKey(hdKey);
|
|
76
72
|
this.wallets.push({
|
|
77
73
|
hdKey,
|
|
@@ -4,7 +4,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.BaseTrezorTransport = exports.TrezorTransportNoInit = void 0;
|
|
7
|
-
const transport_no_init_js_1 = __importDefault(require("./transport/transport-no-init.js"));
|
|
8
|
-
exports.TrezorTransportNoInit = transport_no_init_js_1.default;
|
|
9
7
|
const base_js_1 = __importDefault(require("./transport/base.js"));
|
|
10
8
|
exports.BaseTrezorTransport = base_js_1.default;
|
|
9
|
+
const transport_no_init_js_1 = __importDefault(require("./transport/transport-no-init.js"));
|
|
10
|
+
exports.TrezorTransportNoInit = transport_no_init_js_1.default;
|
|
@@ -3,8 +3,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const AccountManager_js_1 = __importDefault(require("./../AccountManager.js"));
|
|
7
6
|
const lib_js_1 = require("../../lib.js");
|
|
7
|
+
const AccountManager_js_1 = __importDefault(require("../AccountManager.js"));
|
|
8
8
|
const TREZOR_CONNECT_MANIFEST = {
|
|
9
9
|
email: 'contact@injectivelabs.org',
|
|
10
10
|
appUrl: 'https://injectivelabs.org',
|
package/dist/cjs/types.d.ts
CHANGED
|
@@ -1,11 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
Bip44 = "bip44",
|
|
5
|
-
Legacy = "legacy"
|
|
1
|
+
export interface HDNodeLike {
|
|
2
|
+
publicKey: Buffer;
|
|
3
|
+
chainCode: Buffer;
|
|
6
4
|
}
|
|
5
|
+
export declare const TrezorDerivationPathType: {
|
|
6
|
+
readonly Bip32: "bip32";
|
|
7
|
+
readonly Bip44: "bip44";
|
|
8
|
+
readonly Legacy: "legacy";
|
|
9
|
+
};
|
|
10
|
+
export type TrezorDerivationPathType = (typeof TrezorDerivationPathType)[keyof typeof TrezorDerivationPathType];
|
|
7
11
|
export interface TrezorWalletInfo {
|
|
8
12
|
address: string;
|
|
9
|
-
hdKey:
|
|
13
|
+
hdKey: HDNodeLike;
|
|
10
14
|
derivationPath: string;
|
|
11
15
|
}
|
package/dist/cjs/types.js
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.TrezorDerivationPathType = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
})(TrezorDerivationPathType || (exports.TrezorDerivationPathType = TrezorDerivationPathType = {}));
|
|
4
|
+
exports.TrezorDerivationPathType = {
|
|
5
|
+
Bip32: 'bip32',
|
|
6
|
+
Bip44: 'bip44',
|
|
7
|
+
Legacy: 'legacy',
|
|
8
|
+
};
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { AccountAddress, EvmChainId } from '@injectivelabs/ts-types';
|
|
4
|
-
import {
|
|
1
|
+
import { WalletDeviceType, BaseConcreteStrategy } from '@injectivelabs/wallet-base';
|
|
2
|
+
import type { TrezorDerivationPathType } from '../types.js';
|
|
3
|
+
import type { AccountAddress, EvmChainId as EvmChainIdType } from '@injectivelabs/ts-types';
|
|
4
|
+
import type { TxRaw, TxResponse, AminoSignResponse, DirectSignResponse } from '@injectivelabs/sdk-ts';
|
|
5
|
+
import type { StdSignDoc, SendTransactionOptions, ConcreteWalletStrategy, ConcreteEvmWalletStrategyArgs } from '@injectivelabs/wallet-base';
|
|
5
6
|
export default class TrezorBase extends BaseConcreteStrategy implements ConcreteWalletStrategy {
|
|
6
7
|
private baseDerivationPath;
|
|
7
8
|
private trezor;
|
|
@@ -18,7 +19,7 @@ export default class TrezorBase extends BaseConcreteStrategy implements Concrete
|
|
|
18
19
|
getSessionOrConfirm(address: AccountAddress): Promise<string>;
|
|
19
20
|
sendEvmTransaction(txData: any, args: {
|
|
20
21
|
address: string;
|
|
21
|
-
evmChainId:
|
|
22
|
+
evmChainId: EvmChainIdType;
|
|
22
23
|
}): Promise<string>;
|
|
23
24
|
sendTransaction(transaction: TxRaw, options: SendTransactionOptions): Promise<TxResponse>;
|
|
24
25
|
signEip712TypedData(eip712json: string, address: AccountAddress): Promise<string>;
|
|
@@ -1,28 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
import { toUtf8, TxGrpcApi
|
|
1
|
+
import { toHex, serializeTransaction } from 'viem';
|
|
2
|
+
import { EvmChainId } from '@injectivelabs/ts-types';
|
|
3
|
+
import { toUtf8, TxGrpcApi } from '@injectivelabs/sdk-ts';
|
|
4
|
+
import { Alchemy, Network as AlchemyNetwork } from 'alchemy-sdk';
|
|
4
5
|
import { ErrorType, WalletException, TrezorException, GeneralException, UnspecifiedErrorCode, TransactionException, } from '@injectivelabs/exceptions';
|
|
5
6
|
import { TIP_IN_GWEI, WalletAction, getKeyFromRpcUrl, WalletDeviceType, BaseConcreteStrategy, DEFAULT_BASE_DERIVATION_PATH, DEFAULT_ADDRESS_SEARCH_LIMIT, DEFAULT_NUM_ADDRESSES_TO_FETCH, } from '@injectivelabs/wallet-base';
|
|
6
|
-
import { addHexPrefix } from 'ethereumjs-util';
|
|
7
|
-
import { FeeMarketEIP1559Transaction } from '@ethereumjs/tx';
|
|
8
|
-
import { Common, Chain, Hardfork } from '@ethereumjs/common';
|
|
9
|
-
import { Alchemy, Network as AlchemyNetwork } from 'alchemy-sdk';
|
|
10
|
-
import { EvmChainId } from '@injectivelabs/ts-types';
|
|
11
7
|
import { loadTrezorConnect } from './lib.js';
|
|
12
8
|
import { transformTypedData } from '../utils.js';
|
|
13
9
|
import { BaseTrezorTransport } from './hw/index.js';
|
|
14
|
-
const getNetworkFromChainId = (chainId) => {
|
|
15
|
-
if (chainId === EvmChainId.Goerli) {
|
|
16
|
-
return Chain.Goerli;
|
|
17
|
-
}
|
|
18
|
-
if (chainId === EvmChainId.Sepolia) {
|
|
19
|
-
return Chain.Sepolia;
|
|
20
|
-
}
|
|
21
|
-
if (chainId === EvmChainId.Kovan) {
|
|
22
|
-
return Chain.Goerli;
|
|
23
|
-
}
|
|
24
|
-
return Chain.Mainnet;
|
|
25
|
-
};
|
|
26
10
|
export default class TrezorBase extends BaseConcreteStrategy {
|
|
27
11
|
baseDerivationPath;
|
|
28
12
|
trezor;
|
|
@@ -68,7 +52,7 @@ export default class TrezorBase extends BaseConcreteStrategy {
|
|
|
68
52
|
const signedTransaction = await this.signEvmTransaction(txData, args);
|
|
69
53
|
try {
|
|
70
54
|
const alchemy = await this.getAlchemy(args.evmChainId);
|
|
71
|
-
const txReceipt = await alchemy.core.sendTransaction(
|
|
55
|
+
const txReceipt = await alchemy.core.sendTransaction(signedTransaction);
|
|
72
56
|
return txReceipt.hash;
|
|
73
57
|
}
|
|
74
58
|
catch (e) {
|
|
@@ -144,7 +128,6 @@ export default class TrezorBase extends BaseConcreteStrategy {
|
|
|
144
128
|
contextModule: WalletAction.SendTransaction,
|
|
145
129
|
});
|
|
146
130
|
}
|
|
147
|
-
// eslint-disable-next-line class-methods-use-this
|
|
148
131
|
async signCosmosTransaction(_transaction) {
|
|
149
132
|
throw new WalletException(new Error('This wallet does not support signing Cosmos transactions'), {
|
|
150
133
|
code: UnspecifiedErrorCode,
|
|
@@ -182,7 +165,6 @@ export default class TrezorBase extends BaseConcreteStrategy {
|
|
|
182
165
|
async getEvmTransactionReceipt(txHash) {
|
|
183
166
|
return Promise.resolve(txHash);
|
|
184
167
|
}
|
|
185
|
-
// eslint-disable-next-line class-methods-use-this
|
|
186
168
|
async getPubKey() {
|
|
187
169
|
throw new WalletException(new Error('You can only fetch PubKey from Cosmos native wallets'));
|
|
188
170
|
}
|
|
@@ -191,33 +173,23 @@ export default class TrezorBase extends BaseConcreteStrategy {
|
|
|
191
173
|
const chainId = parseInt(args.evmChainId.toString(), 10);
|
|
192
174
|
const alchemy = await this.getAlchemy(args.evmChainId);
|
|
193
175
|
const nonce = await alchemy.core.getTransactionCount(args.address);
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
hardfork: Hardfork.London,
|
|
197
|
-
});
|
|
198
|
-
const eip1559TxData = {
|
|
199
|
-
from: txData.from,
|
|
200
|
-
data: txData.data,
|
|
176
|
+
// Create transaction data for Trezor API (still needs hex strings)
|
|
177
|
+
const trezorTxData = {
|
|
201
178
|
to: txData.to,
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
maxPriorityFeePerGas: addHexPrefix(txData.maxPriorityFeePerGas || TIP_IN_GWEI.toString(16)),
|
|
207
|
-
};
|
|
208
|
-
const tx = FeeMarketEIP1559Transaction.fromTxData(eip1559TxData, {
|
|
209
|
-
common,
|
|
210
|
-
});
|
|
211
|
-
const transaction = {
|
|
212
|
-
...tx.toJSON(),
|
|
179
|
+
value: toHex(txData.value || 0),
|
|
180
|
+
gasLimit: toHex(txData.gas),
|
|
181
|
+
nonce: toHex(nonce),
|
|
182
|
+
data: txData.data || '0x',
|
|
213
183
|
chainId,
|
|
184
|
+
maxFeePerGas: toHex(txData.gasPrice || txData.maxFeePerGas),
|
|
185
|
+
maxPriorityFeePerGas: toHex(txData.maxPriorityFeePerGas || TIP_IN_GWEI),
|
|
214
186
|
};
|
|
215
187
|
try {
|
|
216
188
|
await this.trezor.connect();
|
|
217
189
|
const { derivationPath } = await this.getWalletForAddress(args.address);
|
|
218
190
|
const response = await TrezorConnect.ethereumSignTransaction({
|
|
219
191
|
path: derivationPath,
|
|
220
|
-
transaction,
|
|
192
|
+
transaction: trezorTxData,
|
|
221
193
|
});
|
|
222
194
|
if (!response.success) {
|
|
223
195
|
throw new TrezorException(new Error((response.payload && response.payload.error) ||
|
|
@@ -227,15 +199,22 @@ export default class TrezorBase extends BaseConcreteStrategy {
|
|
|
227
199
|
contextModule: WalletAction.SignEvmTransaction,
|
|
228
200
|
});
|
|
229
201
|
}
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
202
|
+
// Create viem-compatible transaction data for serialization
|
|
203
|
+
const viemTxData = {
|
|
204
|
+
type: 'eip1559',
|
|
205
|
+
chainId,
|
|
206
|
+
nonce,
|
|
207
|
+
to: txData.to,
|
|
208
|
+
value: BigInt(txData.value || 0),
|
|
209
|
+
data: (txData.data || '0x'),
|
|
210
|
+
gas: BigInt(txData.gas),
|
|
211
|
+
maxFeePerGas: BigInt(txData.gasPrice || txData.maxFeePerGas),
|
|
212
|
+
maxPriorityFeePerGas: BigInt(txData.maxPriorityFeePerGas || TIP_IN_GWEI),
|
|
213
|
+
v: BigInt(response.payload.v),
|
|
214
|
+
r: response.payload.r,
|
|
215
|
+
s: response.payload.s,
|
|
235
216
|
};
|
|
236
|
-
return
|
|
237
|
-
common,
|
|
238
|
-
});
|
|
217
|
+
return serializeTransaction(viemTxData);
|
|
239
218
|
}
|
|
240
219
|
catch (e) {
|
|
241
220
|
if (e instanceof TrezorException) {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { ConcreteEvmWalletStrategyArgs } from '@injectivelabs/wallet-base';
|
|
2
1
|
import TrezorBase from './Base.js';
|
|
2
|
+
import type { ConcreteEvmWalletStrategyArgs } from '@injectivelabs/wallet-base';
|
|
3
3
|
export declare class TrezorBip32 extends TrezorBase {
|
|
4
4
|
constructor(args: ConcreteEvmWalletStrategyArgs);
|
|
5
5
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { ConcreteEvmWalletStrategyArgs } from '@injectivelabs/wallet-base';
|
|
2
1
|
import TrezorBase from './Base.js';
|
|
2
|
+
import type { ConcreteEvmWalletStrategyArgs } from '@injectivelabs/wallet-base';
|
|
3
3
|
export declare class TrezorBip44 extends TrezorBase {
|
|
4
4
|
constructor(args: ConcreteEvmWalletStrategyArgs);
|
|
5
5
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { TrezorDerivationPathType } from '../../types.js';
|
|
2
|
+
import type { AccountAddress } from '@injectivelabs/ts-types';
|
|
3
|
+
import type { TrezorWalletInfo } from '../../types.js';
|
|
3
4
|
export default class AccountManager {
|
|
4
5
|
private wallets;
|
|
5
6
|
constructor();
|
|
@@ -1,9 +1,7 @@
|
|
|
1
|
-
/* eslint-disable class-methods-use-this */
|
|
2
|
-
import HDNode from 'hdkey';
|
|
3
1
|
import { TrezorException } from '@injectivelabs/exceptions';
|
|
4
2
|
import { addHexPrefix, publicKeyToAddress } from '@injectivelabs/sdk-ts';
|
|
5
3
|
import { DEFAULT_NUM_ADDRESSES_TO_FETCH } from '@injectivelabs/wallet-base';
|
|
6
|
-
import { loadTrezorConnect } from '
|
|
4
|
+
import { loadTrezorConnect } from '../lib.js';
|
|
7
5
|
import { TrezorDerivationPathType } from '../../types.js';
|
|
8
6
|
const addressOfHDKey = (hdKey) => {
|
|
9
7
|
const shouldSanitizePublicKey = true;
|
|
@@ -64,9 +62,10 @@ export default class AccountManager {
|
|
|
64
62
|
'Please make sure your Trezor is connected and unlocked'));
|
|
65
63
|
}
|
|
66
64
|
for (const item of result.payload) {
|
|
67
|
-
const hdKey =
|
|
68
|
-
|
|
69
|
-
|
|
65
|
+
const hdKey = {
|
|
66
|
+
publicKey: Buffer.from(item.publicKey, 'hex'),
|
|
67
|
+
chainCode: Buffer.from(item.chainCode, 'hex'),
|
|
68
|
+
};
|
|
70
69
|
const address = addressOfHDKey(hdKey);
|
|
71
70
|
this.wallets.push({
|
|
72
71
|
hdKey,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import AccountManager from './../AccountManager.js';
|
|
2
1
|
import { loadTrezorConnect } from '../../lib.js';
|
|
2
|
+
import AccountManager from '../AccountManager.js';
|
|
3
3
|
const TREZOR_CONNECT_MANIFEST = {
|
|
4
4
|
email: 'contact@injectivelabs.org',
|
|
5
5
|
appUrl: 'https://injectivelabs.org',
|
package/dist/esm/types.d.ts
CHANGED
|
@@ -1,11 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
Bip44 = "bip44",
|
|
5
|
-
Legacy = "legacy"
|
|
1
|
+
export interface HDNodeLike {
|
|
2
|
+
publicKey: Buffer;
|
|
3
|
+
chainCode: Buffer;
|
|
6
4
|
}
|
|
5
|
+
export declare const TrezorDerivationPathType: {
|
|
6
|
+
readonly Bip32: "bip32";
|
|
7
|
+
readonly Bip44: "bip44";
|
|
8
|
+
readonly Legacy: "legacy";
|
|
9
|
+
};
|
|
10
|
+
export type TrezorDerivationPathType = (typeof TrezorDerivationPathType)[keyof typeof TrezorDerivationPathType];
|
|
7
11
|
export interface TrezorWalletInfo {
|
|
8
12
|
address: string;
|
|
9
|
-
hdKey:
|
|
13
|
+
hdKey: HDNodeLike;
|
|
10
14
|
derivationPath: string;
|
|
11
15
|
}
|
package/dist/esm/types.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
export
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
})(TrezorDerivationPathType || (TrezorDerivationPathType = {}));
|
|
1
|
+
export const TrezorDerivationPathType = {
|
|
2
|
+
Bip32: 'bip32',
|
|
3
|
+
Bip44: 'bip44',
|
|
4
|
+
Legacy: 'legacy',
|
|
5
|
+
};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@injectivelabs/wallet-trezor",
|
|
3
3
|
"description": "Trezor wallet strategy for use with @injectivelabs/wallet-core.",
|
|
4
|
-
"version": "1.16.
|
|
4
|
+
"version": "1.16.13-alpha.1",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"type": "module",
|
|
7
7
|
"author": {
|
|
@@ -57,17 +57,15 @@
|
|
|
57
57
|
},
|
|
58
58
|
"dependencies": {
|
|
59
59
|
"@bangjelkoski/trezor-connect-web": "^9.4.7-beta.1",
|
|
60
|
-
"@
|
|
61
|
-
"@
|
|
62
|
-
"@injectivelabs/
|
|
63
|
-
"@injectivelabs/
|
|
64
|
-
"@injectivelabs/ts-types": "1.16.12",
|
|
65
|
-
"@injectivelabs/wallet-base": "1.16.12",
|
|
60
|
+
"@injectivelabs/exceptions": "1.16.13-alpha.1",
|
|
61
|
+
"@injectivelabs/sdk-ts": "1.16.13-alpha.1",
|
|
62
|
+
"@injectivelabs/ts-types": "1.16.13-alpha.1",
|
|
63
|
+
"@injectivelabs/wallet-base": "1.16.13-alpha.1",
|
|
66
64
|
"alchemy-sdk": "^3.4.7",
|
|
67
|
-
"
|
|
65
|
+
"viem": "^2.33.2"
|
|
68
66
|
},
|
|
69
67
|
"devDependencies": {
|
|
70
68
|
"shx": "^0.3.3"
|
|
71
69
|
},
|
|
72
|
-
"gitHead": "
|
|
70
|
+
"gitHead": "feb3e8f6bd6fa67bb489c94f6373a8d68a9846ae"
|
|
73
71
|
}
|