@injectivelabs/wallet-trezor 1.16.1-alpha.6 → 1.16.2-alpha.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/README.md +18 -19
- package/dist/cjs/strategy/Base.d.ts +6 -6
- package/dist/cjs/strategy/Base.js +27 -24
- package/dist/cjs/strategy/TrezorBip32.d.ts +2 -2
- package/dist/cjs/strategy/TrezorBip44.d.ts +2 -2
- package/dist/cjs/strategy/hw/AccountManager.js +5 -3
- package/dist/cjs/strategy/hw/index.d.ts +1 -2
- package/dist/cjs/strategy/hw/index.js +1 -3
- package/dist/cjs/strategy/hw/transport/base.js +13 -0
- package/dist/cjs/strategy/lib.d.ts +3 -0
- package/dist/cjs/strategy/lib.js +45 -0
- package/dist/esm/strategy/Base.d.ts +6 -6
- package/dist/esm/strategy/Base.js +24 -21
- package/dist/esm/strategy/TrezorBip32.d.ts +2 -2
- package/dist/esm/strategy/TrezorBip44.d.ts +2 -2
- package/dist/esm/strategy/hw/AccountManager.js +4 -2
- package/dist/esm/strategy/hw/index.d.ts +1 -2
- package/dist/esm/strategy/hw/index.js +1 -2
- package/dist/esm/strategy/hw/transport/base.js +13 -0
- package/dist/esm/strategy/lib.d.ts +3 -0
- package/dist/esm/strategy/lib.js +9 -0
- package/package.json +9 -12
- package/dist/cjs/strategy/hw/transport/transport-init.d.ts +0 -4
- package/dist/cjs/strategy/hw/transport/transport-init.js +0 -27
- package/dist/esm/strategy/hw/transport/transport-init.d.ts +0 -4
- package/dist/esm/strategy/hw/transport/transport-init.js +0 -21
package/README.md
CHANGED
|
@@ -13,7 +13,7 @@ _Package to use Trezor Wallets on Injective via the wallet strategy._
|
|
|
13
13
|
## 📚 Installation
|
|
14
14
|
|
|
15
15
|
```bash
|
|
16
|
-
|
|
16
|
+
pnpm add @injectivelabs/wallet-trezor
|
|
17
17
|
```
|
|
18
18
|
|
|
19
19
|
---
|
|
@@ -30,10 +30,9 @@ dependencies and implementations for their specific wallets.
|
|
|
30
30
|
Here's a brief example of how to use this package to send 1 INJ.:
|
|
31
31
|
|
|
32
32
|
```typescript
|
|
33
|
-
import { Wallet } from '@injectivelabs/wallet-base'
|
|
34
|
-
import { BaseWalletStrategy, MsgBroadcaster } from '@injectivelabs/wallet-core'
|
|
35
|
-
import { TrezorWalletStrategy } from '@injectivelabs/wallet-trezor'
|
|
36
|
-
|
|
33
|
+
import { Wallet } from '@injectivelabs/wallet-base'
|
|
34
|
+
import { BaseWalletStrategy, MsgBroadcaster } from '@injectivelabs/wallet-core'
|
|
35
|
+
import { TrezorWalletStrategy } from '@injectivelabs/wallet-trezor'
|
|
37
36
|
|
|
38
37
|
const strategyArgs: WalletStrategyArguments = {
|
|
39
38
|
chainId: ChainId.Mainnet,
|
|
@@ -56,21 +55,21 @@ const msgBroadcaster = new MsgBroadcaster({
|
|
|
56
55
|
})
|
|
57
56
|
|
|
58
57
|
const sendTX = async () => {
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
58
|
+
const injectiveAddress = 'someInjectiveAddress'
|
|
59
|
+
|
|
60
|
+
const message = MsgSend.fromJSON({
|
|
61
|
+
srcInjectiveAddress: injectiveAddress,
|
|
62
|
+
dstInjectiveAddress: injectiveAddress,
|
|
63
|
+
amount: {
|
|
64
|
+
amount: '1',
|
|
65
|
+
denom: 'inj',
|
|
66
|
+
},
|
|
67
|
+
})
|
|
68
|
+
|
|
69
|
+
return await msgBroadcaster.broadcast({ msgs: message })
|
|
70
|
+
}
|
|
72
71
|
|
|
73
|
-
|
|
72
|
+
const result = await sendTX()
|
|
74
73
|
```
|
|
75
74
|
|
|
76
75
|
Read more and find example usages on our [WalletStrategy Docs](https://docs.ts.injective.network/wallet/wallet-wallet-strategy)
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import { TxRaw, TxResponse, AminoSignResponse, DirectSignResponse } from '@injectivelabs/sdk-ts';
|
|
2
|
+
import { StdSignDoc, WalletDeviceType, BaseConcreteStrategy, SendTransactionOptions, ConcreteWalletStrategy, ConcreteEvmWalletStrategyArgs } from '@injectivelabs/wallet-base';
|
|
3
|
+
import { AccountAddress, EvmChainId } from '@injectivelabs/ts-types';
|
|
4
4
|
import { TrezorDerivationPathType } from '../types.js';
|
|
5
5
|
export default class TrezorBase extends BaseConcreteStrategy implements ConcreteWalletStrategy {
|
|
6
6
|
private baseDerivationPath;
|
|
7
7
|
private trezor;
|
|
8
|
-
private
|
|
8
|
+
private evmOptions;
|
|
9
9
|
private alchemy;
|
|
10
10
|
private derivationPathType;
|
|
11
|
-
constructor(args:
|
|
11
|
+
constructor(args: ConcreteEvmWalletStrategyArgs & {
|
|
12
12
|
derivationPathType: TrezorDerivationPathType;
|
|
13
13
|
});
|
|
14
14
|
getWalletDeviceType(): Promise<WalletDeviceType>;
|
|
@@ -18,7 +18,7 @@ export default class TrezorBase extends BaseConcreteStrategy implements Concrete
|
|
|
18
18
|
getSessionOrConfirm(address: AccountAddress): Promise<string>;
|
|
19
19
|
sendEvmTransaction(txData: any, args: {
|
|
20
20
|
address: string;
|
|
21
|
-
|
|
21
|
+
evmChainId: EvmChainId;
|
|
22
22
|
}): Promise<string>;
|
|
23
23
|
sendTransaction(transaction: TxRaw, options: SendTransactionOptions): Promise<TxResponse>;
|
|
24
24
|
signEip712TypedData(eip712json: string, address: AccountAddress): Promise<string>;
|
|
@@ -2,25 +2,25 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
/* eslint-disable camelcase */
|
|
4
4
|
/* eslint-disable class-methods-use-this */
|
|
5
|
-
const
|
|
6
|
-
const
|
|
5
|
+
const sdk_ts_1 = require("@injectivelabs/sdk-ts");
|
|
6
|
+
const exceptions_1 = require("@injectivelabs/exceptions");
|
|
7
|
+
const wallet_base_1 = require("@injectivelabs/wallet-base");
|
|
7
8
|
const ethereumjs_util_1 = require("ethereumjs-util");
|
|
8
9
|
const tx_1 = require("@ethereumjs/tx");
|
|
9
10
|
const common_1 = require("@ethereumjs/common");
|
|
10
|
-
const
|
|
11
|
-
const
|
|
12
|
-
const
|
|
13
|
-
const wallet_base_1 = require("@injectivelabs/wallet-base");
|
|
14
|
-
const index_js_1 = require("./hw/index.js");
|
|
11
|
+
const alchemy_sdk_1 = require("alchemy-sdk");
|
|
12
|
+
const ts_types_1 = require("@injectivelabs/ts-types");
|
|
13
|
+
const lib_js_1 = require("./lib.js");
|
|
15
14
|
const utils_js_1 = require("../utils.js");
|
|
15
|
+
const index_js_1 = require("./hw/index.js");
|
|
16
16
|
const getNetworkFromChainId = (chainId) => {
|
|
17
|
-
if (chainId === ts_types_1.
|
|
17
|
+
if (chainId === ts_types_1.EvmChainId.Goerli) {
|
|
18
18
|
return common_1.Chain.Goerli;
|
|
19
19
|
}
|
|
20
|
-
if (chainId === ts_types_1.
|
|
20
|
+
if (chainId === ts_types_1.EvmChainId.Sepolia) {
|
|
21
21
|
return common_1.Chain.Sepolia;
|
|
22
22
|
}
|
|
23
|
-
if (chainId === ts_types_1.
|
|
23
|
+
if (chainId === ts_types_1.EvmChainId.Kovan) {
|
|
24
24
|
return common_1.Chain.Goerli;
|
|
25
25
|
}
|
|
26
26
|
return common_1.Chain.Mainnet;
|
|
@@ -28,15 +28,15 @@ const getNetworkFromChainId = (chainId) => {
|
|
|
28
28
|
class TrezorBase extends wallet_base_1.BaseConcreteStrategy {
|
|
29
29
|
baseDerivationPath;
|
|
30
30
|
trezor;
|
|
31
|
-
|
|
31
|
+
evmOptions;
|
|
32
32
|
alchemy;
|
|
33
33
|
derivationPathType;
|
|
34
34
|
constructor(args) {
|
|
35
35
|
super(args);
|
|
36
|
-
this.
|
|
36
|
+
this.evmOptions = args.evmOptions;
|
|
37
|
+
this.trezor = new index_js_1.BaseTrezorTransport();
|
|
37
38
|
this.derivationPathType = args.derivationPathType;
|
|
38
|
-
this.
|
|
39
|
-
this.ethereumOptions = args.ethereumOptions;
|
|
39
|
+
this.baseDerivationPath = wallet_base_1.DEFAULT_BASE_DERIVATION_PATH;
|
|
40
40
|
}
|
|
41
41
|
async getWalletDeviceType() {
|
|
42
42
|
return Promise.resolve(wallet_base_1.WalletDeviceType.Hardware);
|
|
@@ -69,7 +69,7 @@ class TrezorBase extends wallet_base_1.BaseConcreteStrategy {
|
|
|
69
69
|
async sendEvmTransaction(txData, args) {
|
|
70
70
|
const signedTransaction = await this.signEvmTransaction(txData, args);
|
|
71
71
|
try {
|
|
72
|
-
const alchemy = await this.getAlchemy(args.
|
|
72
|
+
const alchemy = await this.getAlchemy(args.evmChainId);
|
|
73
73
|
const txReceipt = await alchemy.core.sendTransaction((0, ethereumjs_util_1.addHexPrefix)(signedTransaction.serialize().toString('hex')));
|
|
74
74
|
return txReceipt.hash;
|
|
75
75
|
}
|
|
@@ -98,6 +98,7 @@ class TrezorBase extends wallet_base_1.BaseConcreteStrategy {
|
|
|
98
98
|
return response;
|
|
99
99
|
}
|
|
100
100
|
async signEip712TypedData(eip712json, address) {
|
|
101
|
+
const TrezorConnect = await (0, lib_js_1.loadTrezorConnect)();
|
|
101
102
|
const object = JSON.parse(eip712json);
|
|
102
103
|
const compatibleObject = {
|
|
103
104
|
...object,
|
|
@@ -112,7 +113,7 @@ class TrezorBase extends wallet_base_1.BaseConcreteStrategy {
|
|
|
112
113
|
try {
|
|
113
114
|
await this.trezor.connect();
|
|
114
115
|
const { derivationPath } = await this.getWalletForAddress(address);
|
|
115
|
-
const response = await
|
|
116
|
+
const response = await TrezorConnect.ethereumSignTypedData({
|
|
116
117
|
path: derivationPath,
|
|
117
118
|
data: {
|
|
118
119
|
types: { EIP712Domain, ...otherTypes },
|
|
@@ -154,10 +155,11 @@ class TrezorBase extends wallet_base_1.BaseConcreteStrategy {
|
|
|
154
155
|
});
|
|
155
156
|
}
|
|
156
157
|
async signArbitrary(signer, data) {
|
|
158
|
+
const TrezorConnect = await (0, lib_js_1.loadTrezorConnect)();
|
|
157
159
|
try {
|
|
158
160
|
await this.trezor.connect();
|
|
159
161
|
const { derivationPath } = await this.getWalletForAddress(signer);
|
|
160
|
-
const response = await
|
|
162
|
+
const response = await TrezorConnect.ethereumSignMessage({
|
|
161
163
|
path: derivationPath,
|
|
162
164
|
message: (0, sdk_ts_1.toUtf8)(data),
|
|
163
165
|
});
|
|
@@ -187,8 +189,9 @@ class TrezorBase extends wallet_base_1.BaseConcreteStrategy {
|
|
|
187
189
|
throw new exceptions_1.WalletException(new Error('You can only fetch PubKey from Cosmos native wallets'));
|
|
188
190
|
}
|
|
189
191
|
async signEvmTransaction(txData, args) {
|
|
190
|
-
const
|
|
191
|
-
const
|
|
192
|
+
const TrezorConnect = await (0, lib_js_1.loadTrezorConnect)();
|
|
193
|
+
const chainId = parseInt(args.evmChainId.toString(), 10);
|
|
194
|
+
const alchemy = await this.getAlchemy(args.evmChainId);
|
|
192
195
|
const nonce = await alchemy.core.getTransactionCount(args.address);
|
|
193
196
|
const common = new common_1.Common({
|
|
194
197
|
chain: getNetworkFromChainId(chainId),
|
|
@@ -214,7 +217,7 @@ class TrezorBase extends wallet_base_1.BaseConcreteStrategy {
|
|
|
214
217
|
try {
|
|
215
218
|
await this.trezor.connect();
|
|
216
219
|
const { derivationPath } = await this.getWalletForAddress(args.address);
|
|
217
|
-
const response = await
|
|
220
|
+
const response = await TrezorConnect.ethereumSignTransaction({
|
|
218
221
|
path: derivationPath,
|
|
219
222
|
transaction,
|
|
220
223
|
});
|
|
@@ -260,19 +263,19 @@ class TrezorBase extends wallet_base_1.BaseConcreteStrategy {
|
|
|
260
263
|
}
|
|
261
264
|
return (await accountManager.getWalletForAddress(address));
|
|
262
265
|
}
|
|
263
|
-
async getAlchemy(
|
|
266
|
+
async getAlchemy(evmChainId) {
|
|
264
267
|
if (this.alchemy) {
|
|
265
268
|
return this.alchemy;
|
|
266
269
|
}
|
|
267
|
-
const options = this.
|
|
268
|
-
const chainId =
|
|
270
|
+
const options = this.evmOptions;
|
|
271
|
+
const chainId = evmChainId || options.evmChainId;
|
|
269
272
|
const url = options.rpcUrl || options.rpcUrls?.[chainId];
|
|
270
273
|
if (!url) {
|
|
271
274
|
throw new exceptions_1.GeneralException(new Error('Please pass rpcUrl within the ethereumOptions'));
|
|
272
275
|
}
|
|
273
276
|
this.alchemy = new alchemy_sdk_1.Alchemy({
|
|
274
277
|
apiKey: (0, wallet_base_1.getKeyFromRpcUrl)(url),
|
|
275
|
-
network: chainId === ts_types_1.
|
|
278
|
+
network: chainId === ts_types_1.EvmChainId.Mainnet
|
|
276
279
|
? alchemy_sdk_1.Network.ETH_MAINNET
|
|
277
280
|
: alchemy_sdk_1.Network.ETH_SEPOLIA,
|
|
278
281
|
});
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ConcreteEvmWalletStrategyArgs } from '@injectivelabs/wallet-base';
|
|
2
2
|
import TrezorBase from './Base.js';
|
|
3
3
|
export declare class TrezorBip32 extends TrezorBase {
|
|
4
|
-
constructor(args:
|
|
4
|
+
constructor(args: ConcreteEvmWalletStrategyArgs);
|
|
5
5
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ConcreteEvmWalletStrategyArgs } from '@injectivelabs/wallet-base';
|
|
2
2
|
import TrezorBase from './Base.js';
|
|
3
3
|
export declare class TrezorBip44 extends TrezorBase {
|
|
4
|
-
constructor(args:
|
|
4
|
+
constructor(args: ConcreteEvmWalletStrategyArgs);
|
|
5
5
|
}
|
|
@@ -3,12 +3,13 @@ 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
|
+
/* eslint-disable class-methods-use-this */
|
|
6
7
|
const hdkey_1 = __importDefault(require("hdkey"));
|
|
7
8
|
const exceptions_1 = require("@injectivelabs/exceptions");
|
|
8
|
-
const types_js_1 = require("../../types.js");
|
|
9
9
|
const sdk_ts_1 = require("@injectivelabs/sdk-ts");
|
|
10
10
|
const wallet_base_1 = require("@injectivelabs/wallet-base");
|
|
11
|
-
const
|
|
11
|
+
const lib_js_1 = require("./../lib.js");
|
|
12
|
+
const types_js_1 = require("../../types.js");
|
|
12
13
|
const addressOfHDKey = (hdKey) => {
|
|
13
14
|
const shouldSanitizePublicKey = true;
|
|
14
15
|
const derivedPublicKey = hdKey.publicKey;
|
|
@@ -47,6 +48,7 @@ class AccountManager {
|
|
|
47
48
|
return `${fullBaseDerivationPath}/0'/0/${index}`;
|
|
48
49
|
};
|
|
49
50
|
async getWalletsBasedOnIndex({ start, end, baseDerivationPath, derivationPathType, }) {
|
|
51
|
+
const TrezorConnect = await (0, lib_js_1.loadTrezorConnect)();
|
|
50
52
|
const pathsToFetch = [];
|
|
51
53
|
for (let index = start; index < end; index += 1) {
|
|
52
54
|
const path = this.getTrezorDerivationPathBasedOnType({
|
|
@@ -59,7 +61,7 @@ class AccountManager {
|
|
|
59
61
|
showOnTrezor: false,
|
|
60
62
|
});
|
|
61
63
|
}
|
|
62
|
-
const result = await
|
|
64
|
+
const result = await TrezorConnect.ethereumGetPublicKey({
|
|
63
65
|
bundle: pathsToFetch,
|
|
64
66
|
});
|
|
65
67
|
if (!result.success) {
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import TrezorTransportInit from './transport/transport-init.js';
|
|
2
1
|
import TrezorTransportNoInit from './transport/transport-no-init.js';
|
|
3
2
|
import BaseTrezorTransport from './transport/base.js';
|
|
4
|
-
export {
|
|
3
|
+
export { TrezorTransportNoInit, BaseTrezorTransport };
|
|
@@ -3,9 +3,7 @@ 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
|
-
exports.BaseTrezorTransport = exports.TrezorTransportNoInit =
|
|
7
|
-
const transport_init_js_1 = __importDefault(require("./transport/transport-init.js"));
|
|
8
|
-
exports.TrezorTransportInit = transport_init_js_1.default;
|
|
6
|
+
exports.BaseTrezorTransport = exports.TrezorTransportNoInit = void 0;
|
|
9
7
|
const transport_no_init_js_1 = __importDefault(require("./transport/transport-no-init.js"));
|
|
10
8
|
exports.TrezorTransportNoInit = transport_no_init_js_1.default;
|
|
11
9
|
const base_js_1 = __importDefault(require("./transport/base.js"));
|
|
@@ -4,9 +4,22 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
const AccountManager_js_1 = __importDefault(require("./../AccountManager.js"));
|
|
7
|
+
const lib_js_1 = require("../../lib.js");
|
|
8
|
+
const TREZOR_CONNECT_MANIFEST = {
|
|
9
|
+
email: 'contact@injectivelabs.org',
|
|
10
|
+
appUrl: 'https://injectivelabs.org',
|
|
11
|
+
};
|
|
7
12
|
class BaseTrezorTransport {
|
|
8
13
|
accountManager = null;
|
|
9
14
|
async connect() {
|
|
15
|
+
const TrezorConnect = await (0, lib_js_1.loadTrezorConnect)();
|
|
16
|
+
const settings = await TrezorConnect.getSettings();
|
|
17
|
+
if (!settings.success) {
|
|
18
|
+
TrezorConnect.init({
|
|
19
|
+
lazyLoad: true,
|
|
20
|
+
manifest: TREZOR_CONNECT_MANIFEST,
|
|
21
|
+
});
|
|
22
|
+
}
|
|
10
23
|
return Promise.resolve();
|
|
11
24
|
}
|
|
12
25
|
async getAccountManager() {
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.loadTrezorConnect = loadTrezorConnect;
|
|
37
|
+
let TrezorConnect;
|
|
38
|
+
async function loadTrezorConnect() {
|
|
39
|
+
if (!TrezorConnect) {
|
|
40
|
+
const module = await Promise.resolve().then(() => __importStar(require('@bangjelkoski/trezor-connect-web')));
|
|
41
|
+
TrezorConnect = (module.TrezorConnect ||
|
|
42
|
+
module.default.TrezorConnect);
|
|
43
|
+
}
|
|
44
|
+
return TrezorConnect;
|
|
45
|
+
}
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import { TxRaw, TxResponse, AminoSignResponse, DirectSignResponse } from '@injectivelabs/sdk-ts';
|
|
2
|
+
import { StdSignDoc, WalletDeviceType, BaseConcreteStrategy, SendTransactionOptions, ConcreteWalletStrategy, ConcreteEvmWalletStrategyArgs } from '@injectivelabs/wallet-base';
|
|
3
|
+
import { AccountAddress, EvmChainId } from '@injectivelabs/ts-types';
|
|
4
4
|
import { TrezorDerivationPathType } from '../types.js';
|
|
5
5
|
export default class TrezorBase extends BaseConcreteStrategy implements ConcreteWalletStrategy {
|
|
6
6
|
private baseDerivationPath;
|
|
7
7
|
private trezor;
|
|
8
|
-
private
|
|
8
|
+
private evmOptions;
|
|
9
9
|
private alchemy;
|
|
10
10
|
private derivationPathType;
|
|
11
|
-
constructor(args:
|
|
11
|
+
constructor(args: ConcreteEvmWalletStrategyArgs & {
|
|
12
12
|
derivationPathType: TrezorDerivationPathType;
|
|
13
13
|
});
|
|
14
14
|
getWalletDeviceType(): Promise<WalletDeviceType>;
|
|
@@ -18,7 +18,7 @@ export default class TrezorBase extends BaseConcreteStrategy implements Concrete
|
|
|
18
18
|
getSessionOrConfirm(address: AccountAddress): Promise<string>;
|
|
19
19
|
sendEvmTransaction(txData: any, args: {
|
|
20
20
|
address: string;
|
|
21
|
-
|
|
21
|
+
evmChainId: EvmChainId;
|
|
22
22
|
}): Promise<string>;
|
|
23
23
|
sendTransaction(transaction: TxRaw, options: SendTransactionOptions): Promise<TxResponse>;
|
|
24
24
|
signEip712TypedData(eip712json: string, address: AccountAddress): Promise<string>;
|
|
@@ -1,24 +1,24 @@
|
|
|
1
1
|
/* eslint-disable camelcase */
|
|
2
2
|
/* eslint-disable class-methods-use-this */
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
3
|
+
import { toUtf8, TxGrpcApi, } from '@injectivelabs/sdk-ts';
|
|
4
|
+
import { ErrorType, WalletException, TrezorException, GeneralException, UnspecifiedErrorCode, TransactionException, } from '@injectivelabs/exceptions';
|
|
5
|
+
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';
|
|
5
6
|
import { addHexPrefix } from 'ethereumjs-util';
|
|
6
7
|
import { FeeMarketEIP1559Transaction } from '@ethereumjs/tx';
|
|
7
8
|
import { Common, Chain, Hardfork } from '@ethereumjs/common';
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
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';
|
|
12
|
-
import { TrezorTransportInit } from './hw/index.js';
|
|
9
|
+
import { Alchemy, Network as AlchemyNetwork } from 'alchemy-sdk';
|
|
10
|
+
import { EvmChainId } from '@injectivelabs/ts-types';
|
|
11
|
+
import { loadTrezorConnect } from './lib.js';
|
|
13
12
|
import { transformTypedData } from '../utils.js';
|
|
13
|
+
import { BaseTrezorTransport } from './hw/index.js';
|
|
14
14
|
const getNetworkFromChainId = (chainId) => {
|
|
15
|
-
if (chainId ===
|
|
15
|
+
if (chainId === EvmChainId.Goerli) {
|
|
16
16
|
return Chain.Goerli;
|
|
17
17
|
}
|
|
18
|
-
if (chainId ===
|
|
18
|
+
if (chainId === EvmChainId.Sepolia) {
|
|
19
19
|
return Chain.Sepolia;
|
|
20
20
|
}
|
|
21
|
-
if (chainId ===
|
|
21
|
+
if (chainId === EvmChainId.Kovan) {
|
|
22
22
|
return Chain.Goerli;
|
|
23
23
|
}
|
|
24
24
|
return Chain.Mainnet;
|
|
@@ -26,15 +26,15 @@ const getNetworkFromChainId = (chainId) => {
|
|
|
26
26
|
export default class TrezorBase extends BaseConcreteStrategy {
|
|
27
27
|
baseDerivationPath;
|
|
28
28
|
trezor;
|
|
29
|
-
|
|
29
|
+
evmOptions;
|
|
30
30
|
alchemy;
|
|
31
31
|
derivationPathType;
|
|
32
32
|
constructor(args) {
|
|
33
33
|
super(args);
|
|
34
|
-
this.
|
|
34
|
+
this.evmOptions = args.evmOptions;
|
|
35
|
+
this.trezor = new BaseTrezorTransport();
|
|
35
36
|
this.derivationPathType = args.derivationPathType;
|
|
36
|
-
this.
|
|
37
|
-
this.ethereumOptions = args.ethereumOptions;
|
|
37
|
+
this.baseDerivationPath = DEFAULT_BASE_DERIVATION_PATH;
|
|
38
38
|
}
|
|
39
39
|
async getWalletDeviceType() {
|
|
40
40
|
return Promise.resolve(WalletDeviceType.Hardware);
|
|
@@ -67,7 +67,7 @@ export default class TrezorBase extends BaseConcreteStrategy {
|
|
|
67
67
|
async sendEvmTransaction(txData, args) {
|
|
68
68
|
const signedTransaction = await this.signEvmTransaction(txData, args);
|
|
69
69
|
try {
|
|
70
|
-
const alchemy = await this.getAlchemy(args.
|
|
70
|
+
const alchemy = await this.getAlchemy(args.evmChainId);
|
|
71
71
|
const txReceipt = await alchemy.core.sendTransaction(addHexPrefix(signedTransaction.serialize().toString('hex')));
|
|
72
72
|
return txReceipt.hash;
|
|
73
73
|
}
|
|
@@ -96,6 +96,7 @@ export default class TrezorBase extends BaseConcreteStrategy {
|
|
|
96
96
|
return response;
|
|
97
97
|
}
|
|
98
98
|
async signEip712TypedData(eip712json, address) {
|
|
99
|
+
const TrezorConnect = await loadTrezorConnect();
|
|
99
100
|
const object = JSON.parse(eip712json);
|
|
100
101
|
const compatibleObject = {
|
|
101
102
|
...object,
|
|
@@ -152,6 +153,7 @@ export default class TrezorBase extends BaseConcreteStrategy {
|
|
|
152
153
|
});
|
|
153
154
|
}
|
|
154
155
|
async signArbitrary(signer, data) {
|
|
156
|
+
const TrezorConnect = await loadTrezorConnect();
|
|
155
157
|
try {
|
|
156
158
|
await this.trezor.connect();
|
|
157
159
|
const { derivationPath } = await this.getWalletForAddress(signer);
|
|
@@ -185,8 +187,9 @@ export default class TrezorBase extends BaseConcreteStrategy {
|
|
|
185
187
|
throw new WalletException(new Error('You can only fetch PubKey from Cosmos native wallets'));
|
|
186
188
|
}
|
|
187
189
|
async signEvmTransaction(txData, args) {
|
|
188
|
-
const
|
|
189
|
-
const
|
|
190
|
+
const TrezorConnect = await loadTrezorConnect();
|
|
191
|
+
const chainId = parseInt(args.evmChainId.toString(), 10);
|
|
192
|
+
const alchemy = await this.getAlchemy(args.evmChainId);
|
|
190
193
|
const nonce = await alchemy.core.getTransactionCount(args.address);
|
|
191
194
|
const common = new Common({
|
|
192
195
|
chain: getNetworkFromChainId(chainId),
|
|
@@ -258,19 +261,19 @@ export default class TrezorBase extends BaseConcreteStrategy {
|
|
|
258
261
|
}
|
|
259
262
|
return (await accountManager.getWalletForAddress(address));
|
|
260
263
|
}
|
|
261
|
-
async getAlchemy(
|
|
264
|
+
async getAlchemy(evmChainId) {
|
|
262
265
|
if (this.alchemy) {
|
|
263
266
|
return this.alchemy;
|
|
264
267
|
}
|
|
265
|
-
const options = this.
|
|
266
|
-
const chainId =
|
|
268
|
+
const options = this.evmOptions;
|
|
269
|
+
const chainId = evmChainId || options.evmChainId;
|
|
267
270
|
const url = options.rpcUrl || options.rpcUrls?.[chainId];
|
|
268
271
|
if (!url) {
|
|
269
272
|
throw new GeneralException(new Error('Please pass rpcUrl within the ethereumOptions'));
|
|
270
273
|
}
|
|
271
274
|
this.alchemy = new Alchemy({
|
|
272
275
|
apiKey: getKeyFromRpcUrl(url),
|
|
273
|
-
network: chainId ===
|
|
276
|
+
network: chainId === EvmChainId.Mainnet
|
|
274
277
|
? AlchemyNetwork.ETH_MAINNET
|
|
275
278
|
: AlchemyNetwork.ETH_SEPOLIA,
|
|
276
279
|
});
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ConcreteEvmWalletStrategyArgs } from '@injectivelabs/wallet-base';
|
|
2
2
|
import TrezorBase from './Base.js';
|
|
3
3
|
export declare class TrezorBip32 extends TrezorBase {
|
|
4
|
-
constructor(args:
|
|
4
|
+
constructor(args: ConcreteEvmWalletStrategyArgs);
|
|
5
5
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ConcreteEvmWalletStrategyArgs } from '@injectivelabs/wallet-base';
|
|
2
2
|
import TrezorBase from './Base.js';
|
|
3
3
|
export declare class TrezorBip44 extends TrezorBase {
|
|
4
|
-
constructor(args:
|
|
4
|
+
constructor(args: ConcreteEvmWalletStrategyArgs);
|
|
5
5
|
}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
+
/* eslint-disable class-methods-use-this */
|
|
1
2
|
import HDNode from 'hdkey';
|
|
2
3
|
import { TrezorException } from '@injectivelabs/exceptions';
|
|
3
|
-
import { TrezorDerivationPathType } from '../../types.js';
|
|
4
4
|
import { addHexPrefix, publicKeyToAddress } from '@injectivelabs/sdk-ts';
|
|
5
5
|
import { DEFAULT_NUM_ADDRESSES_TO_FETCH } from '@injectivelabs/wallet-base';
|
|
6
|
-
import {
|
|
6
|
+
import { loadTrezorConnect } from './../lib.js';
|
|
7
|
+
import { TrezorDerivationPathType } from '../../types.js';
|
|
7
8
|
const addressOfHDKey = (hdKey) => {
|
|
8
9
|
const shouldSanitizePublicKey = true;
|
|
9
10
|
const derivedPublicKey = hdKey.publicKey;
|
|
@@ -42,6 +43,7 @@ export default class AccountManager {
|
|
|
42
43
|
return `${fullBaseDerivationPath}/0'/0/${index}`;
|
|
43
44
|
};
|
|
44
45
|
async getWalletsBasedOnIndex({ start, end, baseDerivationPath, derivationPathType, }) {
|
|
46
|
+
const TrezorConnect = await loadTrezorConnect();
|
|
45
47
|
const pathsToFetch = [];
|
|
46
48
|
for (let index = start; index < end; index += 1) {
|
|
47
49
|
const path = this.getTrezorDerivationPathBasedOnType({
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import TrezorTransportInit from './transport/transport-init.js';
|
|
2
1
|
import TrezorTransportNoInit from './transport/transport-no-init.js';
|
|
3
2
|
import BaseTrezorTransport from './transport/base.js';
|
|
4
|
-
export {
|
|
3
|
+
export { TrezorTransportNoInit, BaseTrezorTransport };
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import TrezorTransportInit from './transport/transport-init.js';
|
|
2
1
|
import TrezorTransportNoInit from './transport/transport-no-init.js';
|
|
3
2
|
import BaseTrezorTransport from './transport/base.js';
|
|
4
|
-
export {
|
|
3
|
+
export { TrezorTransportNoInit, BaseTrezorTransport };
|
|
@@ -1,7 +1,20 @@
|
|
|
1
1
|
import AccountManager from './../AccountManager.js';
|
|
2
|
+
import { loadTrezorConnect } from '../../lib.js';
|
|
3
|
+
const TREZOR_CONNECT_MANIFEST = {
|
|
4
|
+
email: 'contact@injectivelabs.org',
|
|
5
|
+
appUrl: 'https://injectivelabs.org',
|
|
6
|
+
};
|
|
2
7
|
export default class BaseTrezorTransport {
|
|
3
8
|
accountManager = null;
|
|
4
9
|
async connect() {
|
|
10
|
+
const TrezorConnect = await loadTrezorConnect();
|
|
11
|
+
const settings = await TrezorConnect.getSettings();
|
|
12
|
+
if (!settings.success) {
|
|
13
|
+
TrezorConnect.init({
|
|
14
|
+
lazyLoad: true,
|
|
15
|
+
manifest: TREZOR_CONNECT_MANIFEST,
|
|
16
|
+
});
|
|
17
|
+
}
|
|
5
18
|
return Promise.resolve();
|
|
6
19
|
}
|
|
7
20
|
async getAccountManager() {
|
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.2-alpha.0",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"type": "module",
|
|
7
7
|
"author": {
|
|
@@ -41,10 +41,10 @@
|
|
|
41
41
|
}
|
|
42
42
|
},
|
|
43
43
|
"scripts": {
|
|
44
|
-
"build": "
|
|
44
|
+
"build": "pnpm build:cjs && pnpm build:esm && pnpm build:post",
|
|
45
45
|
"build:cjs": "tsc --build --force tsconfig.build.json",
|
|
46
46
|
"build:esm": "tsc --build --force tsconfig.build.esm.json",
|
|
47
|
-
"build:watch": "tsc --build -w tsconfig.build.json && tsc -w --build tsconfig.build.esm.json &&
|
|
47
|
+
"build:watch": "tsc --build -w tsconfig.build.json && tsc -w --build tsconfig.build.esm.json && pnpm build:post",
|
|
48
48
|
"build:post": "shx cp ../../../etc/stub/package.json.stub dist/cjs/package.json && shx cp ../../../etc/stub/package.esm.json.stub dist/esm/package.json",
|
|
49
49
|
"clean": "tsc --build tsconfig.build.json --clean && tsc --build tsconfig.build.esm.json --clean && shx rm -rf coverage *.log junit.xml dist && jest --clearCache && shx mkdir -p dist",
|
|
50
50
|
"test": "jest",
|
|
@@ -57,20 +57,17 @@
|
|
|
57
57
|
},
|
|
58
58
|
"dependencies": {
|
|
59
59
|
"@bangjelkoski/trezor-connect-web": "^9.4.7-beta.1",
|
|
60
|
-
"@ethereumjs/common": "3.
|
|
60
|
+
"@ethereumjs/common": "3.2.0",
|
|
61
61
|
"@ethereumjs/tx": "^4.1.1",
|
|
62
|
-
"@injectivelabs/exceptions": "
|
|
63
|
-
"@injectivelabs/sdk-ts": "
|
|
64
|
-
"@injectivelabs/ts-types": "
|
|
65
|
-
"@injectivelabs/wallet-base": "
|
|
62
|
+
"@injectivelabs/exceptions": "1.16.2-alpha.0",
|
|
63
|
+
"@injectivelabs/sdk-ts": "1.16.2-alpha.0",
|
|
64
|
+
"@injectivelabs/ts-types": "1.16.2-alpha.0",
|
|
65
|
+
"@injectivelabs/wallet-base": "1.16.2-alpha.0",
|
|
66
66
|
"alchemy-sdk": "^3.4.7",
|
|
67
67
|
"hdkey": "^2.1.0"
|
|
68
68
|
},
|
|
69
69
|
"devDependencies": {
|
|
70
70
|
"shx": "^0.3.3"
|
|
71
71
|
},
|
|
72
|
-
"
|
|
73
|
-
"@ethereumjs/common": "3.1.1"
|
|
74
|
-
},
|
|
75
|
-
"gitHead": "2e0a988a094d8284191b29502dde14f9696e7932"
|
|
72
|
+
"gitHead": "0377b0c3b44d79b598d08ca01930057dc05d9c7a"
|
|
76
73
|
}
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const trezor_connect_web_1 = require("@bangjelkoski/trezor-connect-web");
|
|
7
|
-
const exceptions_1 = require("@injectivelabs/exceptions");
|
|
8
|
-
const base_js_1 = __importDefault(require("./base.js"));
|
|
9
|
-
const TREZOR_CONNECT_MANIFEST = {
|
|
10
|
-
email: 'contact@injectivelabs.org',
|
|
11
|
-
appUrl: 'https://injectivelabs.org',
|
|
12
|
-
};
|
|
13
|
-
class TrezorTransportInit extends base_js_1.default {
|
|
14
|
-
constructor() {
|
|
15
|
-
super();
|
|
16
|
-
try {
|
|
17
|
-
trezor_connect_web_1.TrezorConnect.init({
|
|
18
|
-
lazyLoad: true,
|
|
19
|
-
manifest: TREZOR_CONNECT_MANIFEST,
|
|
20
|
-
});
|
|
21
|
-
}
|
|
22
|
-
catch (e) {
|
|
23
|
-
throw new exceptions_1.WalletException(e);
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
exports.default = TrezorTransportInit;
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { TrezorConnect } from '@bangjelkoski/trezor-connect-web';
|
|
2
|
-
import { WalletException } from '@injectivelabs/exceptions';
|
|
3
|
-
import BaseTrezorTransport from './base.js';
|
|
4
|
-
const TREZOR_CONNECT_MANIFEST = {
|
|
5
|
-
email: 'contact@injectivelabs.org',
|
|
6
|
-
appUrl: 'https://injectivelabs.org',
|
|
7
|
-
};
|
|
8
|
-
export default class TrezorTransportInit extends BaseTrezorTransport {
|
|
9
|
-
constructor() {
|
|
10
|
-
super();
|
|
11
|
-
try {
|
|
12
|
-
TrezorConnect.init({
|
|
13
|
-
lazyLoad: true,
|
|
14
|
-
manifest: TREZOR_CONNECT_MANIFEST,
|
|
15
|
-
});
|
|
16
|
-
}
|
|
17
|
-
catch (e) {
|
|
18
|
-
throw new WalletException(e);
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
}
|