@injectivelabs/wallet-trezor 1.16.2-alpha.1 → 1.16.2
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 +19 -18
- package/dist/cjs/strategy/Base.d.ts +6 -6
- package/dist/cjs/strategy/Base.js +24 -27
- 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 +3 -5
- package/dist/cjs/strategy/hw/index.d.ts +2 -1
- package/dist/cjs/strategy/hw/index.js +3 -1
- package/dist/cjs/strategy/hw/transport/base.js +0 -13
- package/dist/cjs/strategy/hw/transport/transport-init.d.ts +4 -0
- package/dist/cjs/strategy/hw/transport/transport-init.js +27 -0
- package/dist/esm/strategy/Base.d.ts +6 -6
- package/dist/esm/strategy/Base.js +21 -24
- 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 +2 -4
- package/dist/esm/strategy/hw/index.d.ts +2 -1
- package/dist/esm/strategy/hw/index.js +2 -1
- package/dist/esm/strategy/hw/transport/base.js +0 -13
- package/dist/esm/strategy/hw/transport/transport-init.d.ts +4 -0
- package/dist/esm/strategy/hw/transport/transport-init.js +21 -0
- package/package.json +12 -9
- package/dist/cjs/strategy/lib.d.ts +0 -3
- package/dist/cjs/strategy/lib.js +0 -45
- package/dist/esm/strategy/lib.d.ts +0 -3
- package/dist/esm/strategy/lib.js +0 -9
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
|
+
yarn add @injectivelabs/wallet-trezor
|
|
17
17
|
```
|
|
18
18
|
|
|
19
19
|
---
|
|
@@ -30,9 +30,10 @@ 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'
|
|
33
|
+
import { Wallet } from '@injectivelabs/wallet-base';
|
|
34
|
+
import { BaseWalletStrategy, MsgBroadcaster } from '@injectivelabs/wallet-core';
|
|
35
|
+
import { TrezorWalletStrategy } from '@injectivelabs/wallet-trezor';
|
|
36
|
+
|
|
36
37
|
|
|
37
38
|
const strategyArgs: WalletStrategyArguments = {
|
|
38
39
|
chainId: ChainId.Mainnet,
|
|
@@ -55,21 +56,21 @@ const msgBroadcaster = new MsgBroadcaster({
|
|
|
55
56
|
})
|
|
56
57
|
|
|
57
58
|
const sendTX = async () => {
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
}
|
|
59
|
+
const injectiveAddress = 'someInjectiveAddress'
|
|
60
|
+
|
|
61
|
+
const message = MsgSend.fromJSON({
|
|
62
|
+
srcInjectiveAddress: injectiveAddress,
|
|
63
|
+
dstInjectiveAddress: injectiveAddress,
|
|
64
|
+
amount: {
|
|
65
|
+
amount: '1',
|
|
66
|
+
denom: 'inj',
|
|
67
|
+
},
|
|
68
|
+
})
|
|
69
|
+
|
|
70
|
+
return await msgBroadcaster.broadcast({ msgs: message })
|
|
71
|
+
}
|
|
71
72
|
|
|
72
|
-
const result = await sendTX()
|
|
73
|
+
const result = await sendTX()
|
|
73
74
|
```
|
|
74
75
|
|
|
75
76
|
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 { AccountAddress, EthereumChainId } from '@injectivelabs/ts-types';
|
|
2
|
+
import { TxRaw, TxResponse, DirectSignResponse, AminoSignResponse } from '@injectivelabs/sdk-ts';
|
|
3
|
+
import { StdSignDoc, WalletDeviceType, BaseConcreteStrategy, ConcreteWalletStrategy, SendTransactionOptions, ConcreteEthereumWalletStrategyArgs } from '@injectivelabs/wallet-base';
|
|
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 ethereumOptions;
|
|
9
9
|
private alchemy;
|
|
10
10
|
private derivationPathType;
|
|
11
|
-
constructor(args:
|
|
11
|
+
constructor(args: ConcreteEthereumWalletStrategyArgs & {
|
|
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
|
+
ethereumChainId: EthereumChainId;
|
|
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
|
|
7
|
-
const wallet_base_1 = require("@injectivelabs/wallet-base");
|
|
5
|
+
const ts_types_1 = require("@injectivelabs/ts-types");
|
|
6
|
+
const alchemy_sdk_1 = require("alchemy-sdk");
|
|
8
7
|
const ethereumjs_util_1 = require("ethereumjs-util");
|
|
9
8
|
const tx_1 = require("@ethereumjs/tx");
|
|
10
9
|
const common_1 = require("@ethereumjs/common");
|
|
11
|
-
const
|
|
12
|
-
const
|
|
13
|
-
const
|
|
14
|
-
const
|
|
10
|
+
const trezor_connect_web_1 = require("@bangjelkoski/trezor-connect-web");
|
|
11
|
+
const exceptions_1 = require("@injectivelabs/exceptions");
|
|
12
|
+
const sdk_ts_1 = require("@injectivelabs/sdk-ts");
|
|
13
|
+
const wallet_base_1 = require("@injectivelabs/wallet-base");
|
|
15
14
|
const index_js_1 = require("./hw/index.js");
|
|
15
|
+
const utils_js_1 = require("../utils.js");
|
|
16
16
|
const getNetworkFromChainId = (chainId) => {
|
|
17
|
-
if (chainId === ts_types_1.
|
|
17
|
+
if (chainId === ts_types_1.EthereumChainId.Goerli) {
|
|
18
18
|
return common_1.Chain.Goerli;
|
|
19
19
|
}
|
|
20
|
-
if (chainId === ts_types_1.
|
|
20
|
+
if (chainId === ts_types_1.EthereumChainId.Sepolia) {
|
|
21
21
|
return common_1.Chain.Sepolia;
|
|
22
22
|
}
|
|
23
|
-
if (chainId === ts_types_1.
|
|
23
|
+
if (chainId === ts_types_1.EthereumChainId.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
|
+
ethereumOptions;
|
|
32
32
|
alchemy;
|
|
33
33
|
derivationPathType;
|
|
34
34
|
constructor(args) {
|
|
35
35
|
super(args);
|
|
36
|
-
this.evmOptions = args.evmOptions;
|
|
37
|
-
this.trezor = new index_js_1.BaseTrezorTransport();
|
|
38
|
-
this.derivationPathType = args.derivationPathType;
|
|
39
36
|
this.baseDerivationPath = wallet_base_1.DEFAULT_BASE_DERIVATION_PATH;
|
|
37
|
+
this.derivationPathType = args.derivationPathType;
|
|
38
|
+
this.trezor = new index_js_1.TrezorTransportInit();
|
|
39
|
+
this.ethereumOptions = args.ethereumOptions;
|
|
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.ethereumChainId);
|
|
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,7 +98,6 @@ 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)();
|
|
102
101
|
const object = JSON.parse(eip712json);
|
|
103
102
|
const compatibleObject = {
|
|
104
103
|
...object,
|
|
@@ -113,7 +112,7 @@ class TrezorBase extends wallet_base_1.BaseConcreteStrategy {
|
|
|
113
112
|
try {
|
|
114
113
|
await this.trezor.connect();
|
|
115
114
|
const { derivationPath } = await this.getWalletForAddress(address);
|
|
116
|
-
const response = await TrezorConnect.ethereumSignTypedData({
|
|
115
|
+
const response = await trezor_connect_web_1.TrezorConnect.ethereumSignTypedData({
|
|
117
116
|
path: derivationPath,
|
|
118
117
|
data: {
|
|
119
118
|
types: { EIP712Domain, ...otherTypes },
|
|
@@ -155,11 +154,10 @@ class TrezorBase extends wallet_base_1.BaseConcreteStrategy {
|
|
|
155
154
|
});
|
|
156
155
|
}
|
|
157
156
|
async signArbitrary(signer, data) {
|
|
158
|
-
const TrezorConnect = await (0, lib_js_1.loadTrezorConnect)();
|
|
159
157
|
try {
|
|
160
158
|
await this.trezor.connect();
|
|
161
159
|
const { derivationPath } = await this.getWalletForAddress(signer);
|
|
162
|
-
const response = await TrezorConnect.ethereumSignMessage({
|
|
160
|
+
const response = await trezor_connect_web_1.TrezorConnect.ethereumSignMessage({
|
|
163
161
|
path: derivationPath,
|
|
164
162
|
message: (0, sdk_ts_1.toUtf8)(data),
|
|
165
163
|
});
|
|
@@ -189,9 +187,8 @@ class TrezorBase extends wallet_base_1.BaseConcreteStrategy {
|
|
|
189
187
|
throw new exceptions_1.WalletException(new Error('You can only fetch PubKey from Cosmos native wallets'));
|
|
190
188
|
}
|
|
191
189
|
async signEvmTransaction(txData, args) {
|
|
192
|
-
const
|
|
193
|
-
const
|
|
194
|
-
const alchemy = await this.getAlchemy(args.evmChainId);
|
|
190
|
+
const chainId = parseInt(args.ethereumChainId.toString(), 10);
|
|
191
|
+
const alchemy = await this.getAlchemy(args.ethereumChainId);
|
|
195
192
|
const nonce = await alchemy.core.getTransactionCount(args.address);
|
|
196
193
|
const common = new common_1.Common({
|
|
197
194
|
chain: getNetworkFromChainId(chainId),
|
|
@@ -217,7 +214,7 @@ class TrezorBase extends wallet_base_1.BaseConcreteStrategy {
|
|
|
217
214
|
try {
|
|
218
215
|
await this.trezor.connect();
|
|
219
216
|
const { derivationPath } = await this.getWalletForAddress(args.address);
|
|
220
|
-
const response = await TrezorConnect.ethereumSignTransaction({
|
|
217
|
+
const response = await trezor_connect_web_1.TrezorConnect.ethereumSignTransaction({
|
|
221
218
|
path: derivationPath,
|
|
222
219
|
transaction,
|
|
223
220
|
});
|
|
@@ -263,19 +260,19 @@ class TrezorBase extends wallet_base_1.BaseConcreteStrategy {
|
|
|
263
260
|
}
|
|
264
261
|
return (await accountManager.getWalletForAddress(address));
|
|
265
262
|
}
|
|
266
|
-
async getAlchemy(
|
|
263
|
+
async getAlchemy(ethereumChainId) {
|
|
267
264
|
if (this.alchemy) {
|
|
268
265
|
return this.alchemy;
|
|
269
266
|
}
|
|
270
|
-
const options = this.
|
|
271
|
-
const chainId =
|
|
267
|
+
const options = this.ethereumOptions;
|
|
268
|
+
const chainId = ethereumChainId || options.ethereumChainId;
|
|
272
269
|
const url = options.rpcUrl || options.rpcUrls?.[chainId];
|
|
273
270
|
if (!url) {
|
|
274
271
|
throw new exceptions_1.GeneralException(new Error('Please pass rpcUrl within the ethereumOptions'));
|
|
275
272
|
}
|
|
276
273
|
this.alchemy = new alchemy_sdk_1.Alchemy({
|
|
277
274
|
apiKey: (0, wallet_base_1.getKeyFromRpcUrl)(url),
|
|
278
|
-
network: chainId === ts_types_1.
|
|
275
|
+
network: chainId === ts_types_1.EthereumChainId.Mainnet
|
|
279
276
|
? alchemy_sdk_1.Network.ETH_MAINNET
|
|
280
277
|
: alchemy_sdk_1.Network.ETH_SEPOLIA,
|
|
281
278
|
});
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ConcreteEthereumWalletStrategyArgs } 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: ConcreteEthereumWalletStrategyArgs);
|
|
5
5
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ConcreteEthereumWalletStrategyArgs } 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: ConcreteEthereumWalletStrategyArgs);
|
|
5
5
|
}
|
|
@@ -3,13 +3,12 @@ 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 */
|
|
7
6
|
const hdkey_1 = __importDefault(require("hdkey"));
|
|
8
7
|
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
|
|
12
|
-
const types_js_1 = require("../../types.js");
|
|
11
|
+
const trezor_connect_web_1 = require("@bangjelkoski/trezor-connect-web");
|
|
13
12
|
const addressOfHDKey = (hdKey) => {
|
|
14
13
|
const shouldSanitizePublicKey = true;
|
|
15
14
|
const derivedPublicKey = hdKey.publicKey;
|
|
@@ -48,7 +47,6 @@ class AccountManager {
|
|
|
48
47
|
return `${fullBaseDerivationPath}/0'/0/${index}`;
|
|
49
48
|
};
|
|
50
49
|
async getWalletsBasedOnIndex({ start, end, baseDerivationPath, derivationPathType, }) {
|
|
51
|
-
const TrezorConnect = await (0, lib_js_1.loadTrezorConnect)();
|
|
52
50
|
const pathsToFetch = [];
|
|
53
51
|
for (let index = start; index < end; index += 1) {
|
|
54
52
|
const path = this.getTrezorDerivationPathBasedOnType({
|
|
@@ -61,7 +59,7 @@ class AccountManager {
|
|
|
61
59
|
showOnTrezor: false,
|
|
62
60
|
});
|
|
63
61
|
}
|
|
64
|
-
const result = await TrezorConnect.ethereumGetPublicKey({
|
|
62
|
+
const result = await trezor_connect_web_1.TrezorConnect.ethereumGetPublicKey({
|
|
65
63
|
bundle: pathsToFetch,
|
|
66
64
|
});
|
|
67
65
|
if (!result.success) {
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import TrezorTransportInit from './transport/transport-init.js';
|
|
1
2
|
import TrezorTransportNoInit from './transport/transport-no-init.js';
|
|
2
3
|
import BaseTrezorTransport from './transport/base.js';
|
|
3
|
-
export { TrezorTransportNoInit, BaseTrezorTransport };
|
|
4
|
+
export { TrezorTransportInit, TrezorTransportNoInit, BaseTrezorTransport };
|
|
@@ -3,7 +3,9 @@ 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 = void 0;
|
|
6
|
+
exports.BaseTrezorTransport = exports.TrezorTransportNoInit = exports.TrezorTransportInit = void 0;
|
|
7
|
+
const transport_init_js_1 = __importDefault(require("./transport/transport-init.js"));
|
|
8
|
+
exports.TrezorTransportInit = transport_init_js_1.default;
|
|
7
9
|
const transport_no_init_js_1 = __importDefault(require("./transport/transport-no-init.js"));
|
|
8
10
|
exports.TrezorTransportNoInit = transport_no_init_js_1.default;
|
|
9
11
|
const base_js_1 = __importDefault(require("./transport/base.js"));
|
|
@@ -4,22 +4,9 @@ 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
|
-
};
|
|
12
7
|
class BaseTrezorTransport {
|
|
13
8
|
accountManager = null;
|
|
14
9
|
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
|
-
}
|
|
23
10
|
return Promise.resolve();
|
|
24
11
|
}
|
|
25
12
|
async getAccountManager() {
|
|
@@ -0,0 +1,27 @@
|
|
|
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,14 +1,14 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import { AccountAddress, EthereumChainId } from '@injectivelabs/ts-types';
|
|
2
|
+
import { TxRaw, TxResponse, DirectSignResponse, AminoSignResponse } from '@injectivelabs/sdk-ts';
|
|
3
|
+
import { StdSignDoc, WalletDeviceType, BaseConcreteStrategy, ConcreteWalletStrategy, SendTransactionOptions, ConcreteEthereumWalletStrategyArgs } from '@injectivelabs/wallet-base';
|
|
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 ethereumOptions;
|
|
9
9
|
private alchemy;
|
|
10
10
|
private derivationPathType;
|
|
11
|
-
constructor(args:
|
|
11
|
+
constructor(args: ConcreteEthereumWalletStrategyArgs & {
|
|
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
|
+
ethereumChainId: EthereumChainId;
|
|
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 {
|
|
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';
|
|
3
|
+
import { EthereumChainId } from '@injectivelabs/ts-types';
|
|
4
|
+
import { Alchemy, Network as AlchemyNetwork } from 'alchemy-sdk';
|
|
6
5
|
import { addHexPrefix } from 'ethereumjs-util';
|
|
7
6
|
import { FeeMarketEIP1559Transaction } from '@ethereumjs/tx';
|
|
8
7
|
import { Common, Chain, Hardfork } from '@ethereumjs/common';
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
8
|
+
import { TrezorConnect } from '@bangjelkoski/trezor-connect-web';
|
|
9
|
+
import { ErrorType, WalletException, TrezorException, GeneralException, TransactionException, UnspecifiedErrorCode, } from '@injectivelabs/exceptions';
|
|
10
|
+
import { toUtf8, TxGrpcApi, } from '@injectivelabs/sdk-ts';
|
|
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';
|
|
12
13
|
import { transformTypedData } from '../utils.js';
|
|
13
|
-
import { BaseTrezorTransport } from './hw/index.js';
|
|
14
14
|
const getNetworkFromChainId = (chainId) => {
|
|
15
|
-
if (chainId ===
|
|
15
|
+
if (chainId === EthereumChainId.Goerli) {
|
|
16
16
|
return Chain.Goerli;
|
|
17
17
|
}
|
|
18
|
-
if (chainId ===
|
|
18
|
+
if (chainId === EthereumChainId.Sepolia) {
|
|
19
19
|
return Chain.Sepolia;
|
|
20
20
|
}
|
|
21
|
-
if (chainId ===
|
|
21
|
+
if (chainId === EthereumChainId.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
|
+
ethereumOptions;
|
|
30
30
|
alchemy;
|
|
31
31
|
derivationPathType;
|
|
32
32
|
constructor(args) {
|
|
33
33
|
super(args);
|
|
34
|
-
this.evmOptions = args.evmOptions;
|
|
35
|
-
this.trezor = new BaseTrezorTransport();
|
|
36
|
-
this.derivationPathType = args.derivationPathType;
|
|
37
34
|
this.baseDerivationPath = DEFAULT_BASE_DERIVATION_PATH;
|
|
35
|
+
this.derivationPathType = args.derivationPathType;
|
|
36
|
+
this.trezor = new TrezorTransportInit();
|
|
37
|
+
this.ethereumOptions = args.ethereumOptions;
|
|
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.ethereumChainId);
|
|
71
71
|
const txReceipt = await alchemy.core.sendTransaction(addHexPrefix(signedTransaction.serialize().toString('hex')));
|
|
72
72
|
return txReceipt.hash;
|
|
73
73
|
}
|
|
@@ -96,7 +96,6 @@ export default class TrezorBase extends BaseConcreteStrategy {
|
|
|
96
96
|
return response;
|
|
97
97
|
}
|
|
98
98
|
async signEip712TypedData(eip712json, address) {
|
|
99
|
-
const TrezorConnect = await loadTrezorConnect();
|
|
100
99
|
const object = JSON.parse(eip712json);
|
|
101
100
|
const compatibleObject = {
|
|
102
101
|
...object,
|
|
@@ -153,7 +152,6 @@ export default class TrezorBase extends BaseConcreteStrategy {
|
|
|
153
152
|
});
|
|
154
153
|
}
|
|
155
154
|
async signArbitrary(signer, data) {
|
|
156
|
-
const TrezorConnect = await loadTrezorConnect();
|
|
157
155
|
try {
|
|
158
156
|
await this.trezor.connect();
|
|
159
157
|
const { derivationPath } = await this.getWalletForAddress(signer);
|
|
@@ -187,9 +185,8 @@ export default class TrezorBase extends BaseConcreteStrategy {
|
|
|
187
185
|
throw new WalletException(new Error('You can only fetch PubKey from Cosmos native wallets'));
|
|
188
186
|
}
|
|
189
187
|
async signEvmTransaction(txData, args) {
|
|
190
|
-
const
|
|
191
|
-
const
|
|
192
|
-
const alchemy = await this.getAlchemy(args.evmChainId);
|
|
188
|
+
const chainId = parseInt(args.ethereumChainId.toString(), 10);
|
|
189
|
+
const alchemy = await this.getAlchemy(args.ethereumChainId);
|
|
193
190
|
const nonce = await alchemy.core.getTransactionCount(args.address);
|
|
194
191
|
const common = new Common({
|
|
195
192
|
chain: getNetworkFromChainId(chainId),
|
|
@@ -261,19 +258,19 @@ export default class TrezorBase extends BaseConcreteStrategy {
|
|
|
261
258
|
}
|
|
262
259
|
return (await accountManager.getWalletForAddress(address));
|
|
263
260
|
}
|
|
264
|
-
async getAlchemy(
|
|
261
|
+
async getAlchemy(ethereumChainId) {
|
|
265
262
|
if (this.alchemy) {
|
|
266
263
|
return this.alchemy;
|
|
267
264
|
}
|
|
268
|
-
const options = this.
|
|
269
|
-
const chainId =
|
|
265
|
+
const options = this.ethereumOptions;
|
|
266
|
+
const chainId = ethereumChainId || options.ethereumChainId;
|
|
270
267
|
const url = options.rpcUrl || options.rpcUrls?.[chainId];
|
|
271
268
|
if (!url) {
|
|
272
269
|
throw new GeneralException(new Error('Please pass rpcUrl within the ethereumOptions'));
|
|
273
270
|
}
|
|
274
271
|
this.alchemy = new Alchemy({
|
|
275
272
|
apiKey: getKeyFromRpcUrl(url),
|
|
276
|
-
network: chainId ===
|
|
273
|
+
network: chainId === EthereumChainId.Mainnet
|
|
277
274
|
? AlchemyNetwork.ETH_MAINNET
|
|
278
275
|
: AlchemyNetwork.ETH_SEPOLIA,
|
|
279
276
|
});
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ConcreteEthereumWalletStrategyArgs } 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: ConcreteEthereumWalletStrategyArgs);
|
|
5
5
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ConcreteEthereumWalletStrategyArgs } 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: ConcreteEthereumWalletStrategyArgs);
|
|
5
5
|
}
|
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
/* eslint-disable class-methods-use-this */
|
|
2
1
|
import HDNode from 'hdkey';
|
|
3
2
|
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 {
|
|
7
|
-
import { TrezorDerivationPathType } from '../../types.js';
|
|
6
|
+
import { TrezorConnect } from '@bangjelkoski/trezor-connect-web';
|
|
8
7
|
const addressOfHDKey = (hdKey) => {
|
|
9
8
|
const shouldSanitizePublicKey = true;
|
|
10
9
|
const derivedPublicKey = hdKey.publicKey;
|
|
@@ -43,7 +42,6 @@ export default class AccountManager {
|
|
|
43
42
|
return `${fullBaseDerivationPath}/0'/0/${index}`;
|
|
44
43
|
};
|
|
45
44
|
async getWalletsBasedOnIndex({ start, end, baseDerivationPath, derivationPathType, }) {
|
|
46
|
-
const TrezorConnect = await loadTrezorConnect();
|
|
47
45
|
const pathsToFetch = [];
|
|
48
46
|
for (let index = start; index < end; index += 1) {
|
|
49
47
|
const path = this.getTrezorDerivationPathBasedOnType({
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import TrezorTransportInit from './transport/transport-init.js';
|
|
1
2
|
import TrezorTransportNoInit from './transport/transport-no-init.js';
|
|
2
3
|
import BaseTrezorTransport from './transport/base.js';
|
|
3
|
-
export { TrezorTransportNoInit, BaseTrezorTransport };
|
|
4
|
+
export { TrezorTransportInit, TrezorTransportNoInit, BaseTrezorTransport };
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import TrezorTransportInit from './transport/transport-init.js';
|
|
1
2
|
import TrezorTransportNoInit from './transport/transport-no-init.js';
|
|
2
3
|
import BaseTrezorTransport from './transport/base.js';
|
|
3
|
-
export { TrezorTransportNoInit, BaseTrezorTransport };
|
|
4
|
+
export { TrezorTransportInit, TrezorTransportNoInit, BaseTrezorTransport };
|
|
@@ -1,20 +1,7 @@
|
|
|
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
|
-
};
|
|
7
2
|
export default class BaseTrezorTransport {
|
|
8
3
|
accountManager = null;
|
|
9
4
|
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
|
-
}
|
|
18
5
|
return Promise.resolve();
|
|
19
6
|
}
|
|
20
7
|
async getAccountManager() {
|
|
@@ -0,0 +1,21 @@
|
|
|
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
|
+
}
|
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.2
|
|
4
|
+
"version": "1.16.2",
|
|
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": "yarn build:cjs && yarn build:esm && yarn 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 && yarn 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,17 +57,20 @@
|
|
|
57
57
|
},
|
|
58
58
|
"dependencies": {
|
|
59
59
|
"@bangjelkoski/trezor-connect-web": "^9.4.7-beta.1",
|
|
60
|
-
"@ethereumjs/common": "3.
|
|
60
|
+
"@ethereumjs/common": "3.1.1",
|
|
61
61
|
"@ethereumjs/tx": "^4.1.1",
|
|
62
|
-
"@injectivelabs/exceptions": "1.16.2
|
|
63
|
-
"@injectivelabs/sdk-ts": "1.16.2
|
|
64
|
-
"@injectivelabs/ts-types": "1.16.2
|
|
65
|
-
"@injectivelabs/wallet-base": "1.16.2
|
|
62
|
+
"@injectivelabs/exceptions": "^1.16.2",
|
|
63
|
+
"@injectivelabs/sdk-ts": "^1.16.2",
|
|
64
|
+
"@injectivelabs/ts-types": "^1.16.2",
|
|
65
|
+
"@injectivelabs/wallet-base": "^1.16.2",
|
|
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
|
-
"
|
|
72
|
+
"resolutions": {
|
|
73
|
+
"@ethereumjs/common": "3.1.1"
|
|
74
|
+
},
|
|
75
|
+
"gitHead": "56e3f6c8f399c2d881a65858e8e0b1b39828a917"
|
|
73
76
|
}
|
package/dist/cjs/strategy/lib.js
DELETED
|
@@ -1,45 +0,0 @@
|
|
|
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
|
-
}
|
package/dist/esm/strategy/lib.js
DELETED