@injectivelabs/wallet-trezor 0.0.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.
Files changed (52) hide show
  1. package/README.md +111 -0
  2. package/dist/cjs/index.d.ts +3 -0
  3. package/dist/cjs/index.d.ts.map +1 -0
  4. package/dist/cjs/index.js +21 -0
  5. package/dist/cjs/index.js.map +1 -0
  6. package/dist/cjs/package.json +3 -0
  7. package/dist/cjs/strategy/hw/AccountManager.d.ts +17 -0
  8. package/dist/cjs/strategy/hw/AccountManager.d.ts.map +1 -0
  9. package/dist/cjs/strategy/hw/AccountManager.js +85 -0
  10. package/dist/cjs/strategy/hw/AccountManager.js.map +1 -0
  11. package/dist/cjs/strategy/hw/index.d.ts +11 -0
  12. package/dist/cjs/strategy/hw/index.d.ts.map +1 -0
  13. package/dist/cjs/strategy/hw/index.js +75 -0
  14. package/dist/cjs/strategy/hw/index.js.map +1 -0
  15. package/dist/cjs/strategy/strategy.d.ts +38 -0
  16. package/dist/cjs/strategy/strategy.d.ts.map +1 -0
  17. package/dist/cjs/strategy/strategy.js +315 -0
  18. package/dist/cjs/strategy/strategy.js.map +1 -0
  19. package/dist/cjs/types.d.ts +7 -0
  20. package/dist/cjs/types.d.ts.map +1 -0
  21. package/dist/cjs/types.js +3 -0
  22. package/dist/cjs/types.js.map +1 -0
  23. package/dist/cjs/utils.d.ts +17 -0
  24. package/dist/cjs/utils.d.ts.map +1 -0
  25. package/dist/cjs/utils.js +48 -0
  26. package/dist/cjs/utils.js.map +1 -0
  27. package/dist/esm/index.d.ts +3 -0
  28. package/dist/esm/index.d.ts.map +1 -0
  29. package/dist/esm/index.js +3 -0
  30. package/dist/esm/index.js.map +1 -0
  31. package/dist/esm/package.json +3 -0
  32. package/dist/esm/strategy/hw/AccountManager.d.ts +17 -0
  33. package/dist/esm/strategy/hw/AccountManager.d.ts.map +1 -0
  34. package/dist/esm/strategy/hw/AccountManager.js +68 -0
  35. package/dist/esm/strategy/hw/AccountManager.js.map +1 -0
  36. package/dist/esm/strategy/hw/index.d.ts +11 -0
  37. package/dist/esm/strategy/hw/index.d.ts.map +1 -0
  38. package/dist/esm/strategy/hw/index.js +54 -0
  39. package/dist/esm/strategy/hw/index.js.map +1 -0
  40. package/dist/esm/strategy/strategy.d.ts +38 -0
  41. package/dist/esm/strategy/strategy.d.ts.map +1 -0
  42. package/dist/esm/strategy/strategy.js +272 -0
  43. package/dist/esm/strategy/strategy.js.map +1 -0
  44. package/dist/esm/types.d.ts +7 -0
  45. package/dist/esm/types.d.ts.map +1 -0
  46. package/dist/esm/types.js +2 -0
  47. package/dist/esm/types.js.map +1 -0
  48. package/dist/esm/utils.d.ts +17 -0
  49. package/dist/esm/utils.d.ts.map +1 -0
  50. package/dist/esm/utils.js +48 -0
  51. package/dist/esm/utils.js.map +1 -0
  52. package/package.json +66 -0
package/README.md ADDED
@@ -0,0 +1,111 @@
1
+ # 🌟 Injective Protocol - Trezor Wallet Strategy
2
+
3
+ <!-- TODO -->
4
+
5
+ [![downloads](https://img.shields.io/npm/dm/@injectivelabs/wallet-ts.svg)](https://www.npmjs.com/package/@injectivelabs/wallet-ts)
6
+ [![npm-version](https://img.shields.io/npm/v/@injectivelabs/wallet-ts.svg)](https://www.npmjs.com/package/@injectivelabs/wallet-ts)
7
+ [![license](https://img.shields.io/npm/l/express.svg)]()
8
+
9
+ _Package to use Trezor Wallets on Injective via the wallet strategy._
10
+
11
+ ---
12
+
13
+ ## 📚 Installation
14
+
15
+ ```bash
16
+ yarn add @injectivelabs/wallet-trezor
17
+ ```
18
+
19
+ ---
20
+
21
+ ## 📖 Documentation
22
+
23
+ Injective's wallet packages are intended to make it easy for developers to choose exactly what wallets - and subsequent dependencies - they
24
+ want to include in their projects.
25
+
26
+ Regardless of which wallet package(s) you choose to use you must also have `@injectivelabs/wallet-core` and `@injectivelabs/wallet-base`
27
+ installed. These contain all of the types and core wallet functionality, with the separate wallet packages only providing the necessary
28
+ dependencies and implementations for their specific wallets.
29
+
30
+ Here's a brief example of how to use this package to send 1 INJ.:
31
+
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
+
37
+
38
+ const strategyArgs: WalletStrategyArguments = {
39
+ chainId: ChainId.Mainnet,
40
+ wallet: Wallet.Trezor,
41
+ strategies: {
42
+ [Wallet.Trezor]: new TrezorWalletStrategy({
43
+ chainId: ChainId.Mainnet,
44
+ ethereumOptions: {
45
+ ethereumChainId: EthereumChainId.Mainnet,
46
+ },
47
+ }),
48
+ },
49
+ }
50
+ const walletStrategy = new BaseWalletStrategy(strategyArgs)
51
+
52
+ const msgBroadcaster = new MsgBroadcaster({
53
+ walletStrategy,
54
+ simulateTx: true,
55
+ network: Network.Mainnet,
56
+ })
57
+
58
+ const sendTX = async () => {
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
+ }
72
+
73
+ const result = await sendTX()
74
+ ```
75
+
76
+ Read more and find example usages on our [WalletStrategy Docs](https://docs.ts.injective.network/wallet/wallet-wallet-strategy)
77
+
78
+ ---
79
+
80
+ ## 📜 Contribution
81
+
82
+ **Contribution guides and practices will be available once there is a stable foundation of the whole package set within the `injective-ts` repo.**
83
+
84
+ ---
85
+
86
+ ## ⛑ Support
87
+
88
+ Reach out to us at one of the following places!
89
+
90
+ - Website at <a href="https://injective.com" target="_blank">`injective.com`</a>
91
+ - Twitter at <a href="https://twitter.com/Injective_" target="_blank">`@Injective`</a>
92
+ - Discord at <a href="https://discord.com/invite/NK4qdbv" target="_blank">`Discord`</a>
93
+ - Telegram at <a href="https://t.me/joininjective" target="_blank">`Telegram`</a>
94
+
95
+ ---
96
+
97
+ ## 🔓 License
98
+
99
+ Copyright © 2021 - 2022 Injective Labs Inc. (https://injectivelabs.org/)
100
+
101
+ <a href="https://iili.io/mNneZN.md.png"><img src="https://iili.io/mNneZN.md.png" style="width: 300px; max-width: 100%; height: auto" />
102
+
103
+ Originally released by Injective Labs Inc. under: <br />
104
+ Apache License <br />
105
+ Version 2.0, January 2004 <br />
106
+ http://www.apache.org/licenses/
107
+
108
+ <p>&nbsp;</p>
109
+ <div align="center">
110
+ <sub><em>Powering the future of decentralized finance.</em></sub>
111
+ </div>
@@ -0,0 +1,3 @@
1
+ export { TrezorWallet as TrezorWalletStrategy } from './strategy/strategy';
2
+ export * from './types';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,IAAI,oBAAoB,EAAE,MAAM,qBAAqB,CAAA;AAE1E,cAAc,SAAS,CAAA"}
@@ -0,0 +1,21 @@
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ exports.TrezorWalletStrategy = void 0;
18
+ var strategy_1 = require("./strategy/strategy");
19
+ Object.defineProperty(exports, "TrezorWalletStrategy", { enumerable: true, get: function () { return strategy_1.TrezorWallet; } });
20
+ __exportStar(require("./types"), exports);
21
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,gDAA0E;AAAjE,gHAAA,YAAY,OAAwB;AAE7C,0CAAuB"}
@@ -0,0 +1,3 @@
1
+ {
2
+ "type": "commonjs"
3
+ }
@@ -0,0 +1,17 @@
1
+ import { AccountAddress } from '@injectivelabs/ts-types';
2
+ import HDNode from 'hdkey';
3
+ import { TrezorWalletInfo } from '../../types';
4
+ export default class AccountManager {
5
+ private wallets;
6
+ private hdKey;
7
+ constructor(hdKey: HDNode);
8
+ getWallets(): Promise<TrezorWalletInfo[]>;
9
+ private getWalletsBasedOnIndex;
10
+ private hasWallets;
11
+ private hasWalletsInOffset;
12
+ private getOffset;
13
+ hasWalletForAddress(address: AccountAddress): boolean;
14
+ getWalletForAddress(address: AccountAddress): Promise<TrezorWalletInfo | undefined>;
15
+ reset(): void;
16
+ }
17
+ //# sourceMappingURL=AccountManager.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AccountManager.d.ts","sourceRoot":"","sources":["../../../../src/strategy/hw/AccountManager.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAA;AACxD,OAAO,MAAM,MAAM,OAAO,CAAA;AAE1B,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAA;AAkB9C,MAAM,CAAC,OAAO,OAAO,cAAc;IACjC,OAAO,CAAC,OAAO,CAAyB;IAExC,OAAO,CAAC,KAAK,CAAQ;gBAET,KAAK,EAAE,MAAM;IAKnB,UAAU,IAAI,OAAO,CAAC,gBAAgB,EAAE,CAAC;YAiBjC,sBAAsB;IAoBpC,OAAO,CAAC,UAAU;IAIlB,OAAO,CAAC,kBAAkB;IAI1B,OAAO,CAAC,SAAS;IAWjB,mBAAmB,CAAC,OAAO,EAAE,cAAc,GAAG,OAAO;IAQ/C,mBAAmB,CACvB,OAAO,EAAE,cAAc,GACtB,OAAO,CAAC,gBAAgB,GAAG,SAAS,CAAC;IAMxC,KAAK;CAGN"}
@@ -0,0 +1,85 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ const ethereumjs_util_1 = require("ethereumjs-util");
13
+ const wallet_base_1 = require("@injectivelabs/wallet-base");
14
+ const addressOfHDKey = (hdKey) => {
15
+ const shouldSanitizePublicKey = true;
16
+ const derivedPublicKey = hdKey.publicKey;
17
+ const ethereumAddressWithoutPrefix = (0, ethereumjs_util_1.publicToAddress)(derivedPublicKey, shouldSanitizePublicKey).toString('hex');
18
+ const address = (0, ethereumjs_util_1.addHexPrefix)(ethereumAddressWithoutPrefix);
19
+ return address;
20
+ };
21
+ class AccountManager {
22
+ constructor(hdKey) {
23
+ this.wallets = [];
24
+ this.wallets = [];
25
+ this.hdKey = hdKey;
26
+ }
27
+ getWallets() {
28
+ return __awaiter(this, void 0, void 0, function* () {
29
+ const { start, end } = this.getOffset();
30
+ /**
31
+ * 1. Wallets are not yet fetched at all,
32
+ * 2. Wallets are not yet fetched for that offset
33
+ */
34
+ if (!this.hasWallets() || !this.hasWalletsInOffset(start)) {
35
+ yield this.getWalletsBasedOnIndex({
36
+ start,
37
+ end,
38
+ });
39
+ }
40
+ return this.wallets.slice(start, end);
41
+ });
42
+ }
43
+ getWalletsBasedOnIndex(_a) {
44
+ return __awaiter(this, arguments, void 0, function* ({ start, end, }) {
45
+ for (let index = start; index < end; index += 1) {
46
+ const path = `m/${index}`;
47
+ const hdKey = this.hdKey.derive(path);
48
+ const address = addressOfHDKey(hdKey);
49
+ this.wallets.push({
50
+ hdKey,
51
+ address: address.toLowerCase(),
52
+ derivationPath: `${wallet_base_1.DEFAULT_BASE_DERIVATION_PATH}/0'/0/${index}`,
53
+ });
54
+ }
55
+ });
56
+ }
57
+ hasWallets() {
58
+ return this.wallets.length > 0;
59
+ }
60
+ hasWalletsInOffset(offset) {
61
+ return this.wallets.length > offset;
62
+ }
63
+ getOffset() {
64
+ const totalWallets = this.wallets.length;
65
+ const nextBatchStart = totalWallets;
66
+ const nextBatchEnd = totalWallets + wallet_base_1.DEFAULT_NUM_ADDRESSES_TO_FETCH;
67
+ return {
68
+ start: nextBatchStart,
69
+ end: nextBatchEnd,
70
+ };
71
+ }
72
+ hasWalletForAddress(address) {
73
+ return (this.wallets.find((wallet) => wallet.address.toLowerCase() === address.toLowerCase()) !== undefined);
74
+ }
75
+ getWalletForAddress(address) {
76
+ return __awaiter(this, void 0, void 0, function* () {
77
+ return this.wallets.find((wallet) => wallet.address.toLowerCase() === address.toLowerCase());
78
+ });
79
+ }
80
+ reset() {
81
+ this.wallets = [];
82
+ }
83
+ }
84
+ exports.default = AccountManager;
85
+ //# sourceMappingURL=AccountManager.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AccountManager.js","sourceRoot":"","sources":["../../../../src/strategy/hw/AccountManager.ts"],"names":[],"mappings":";;;;;;;;;;;AAGA,qDAA+D;AAE/D,4DAGmC;AAEnC,MAAM,cAAc,GAAG,CAAC,KAAa,EAAU,EAAE;IAC/C,MAAM,uBAAuB,GAAG,IAAI,CAAA;IACpC,MAAM,gBAAgB,GAAG,KAAK,CAAC,SAAS,CAAA;IACxC,MAAM,4BAA4B,G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AAS,KAAK,EAAE;iBAChE,CAAC,CAAA;YACJ,CAAC;QACH,CAAC;KAAA;IAEO,UAAU;QAChB,OAAO,IAAI,CAAC,OAAO,CAAC,MAAM,GAAG,CAAC,CAAA;IAChC,CAAC;IAEO,kBAAkB,CAAC,MAAc;QACvC,OAAO,IAAI,CAAC,OAAO,CAAC,MAAM,GAAG,MAAM,CAAA;IACrC,CAAC;IAEO,SAAS;QACf,MAAM,YAAY,GAAG,IAAI,CAAC,OAAO,CAAC,MAAM,CAAA;QACxC,MAAM,cAAc,GAAG,YAAY,CAAA;QACnC,MAAM,YAAY,GAAG,YAAY,GAAG,4CAA8B,CAAA;QAElE,OAAO;YACL,KAAK,EAAE,cAAc;YACrB,GAAG,EAAE,YAAY;SAClB,CAAA;IACH,CAAC;IAED,mBAAmB,CAAC,OAAuB;QACzC,OAAO,CACL,IAAI,CAAC,OAAO,CAAC,IAAI,CACf,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,OAAO,CAAC,WAAW,EAAE,KAAK,OAAO,CAAC,WAAW,EAAE,CACnE,KAAK,SAAS,CAChB,CAAA;IACH,CAAC;IAEK,mBAAmB,CACvB,OAAuB;;YAEvB,OAAO,IAAI,CAAC,OAAO,CAAC,IAAI,CACtB,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,OAAO,CAAC,WAAW,EAAE,KAAK,OAAO,CAAC,WAAW,EAAE,CACnE,CAAA;QACH,CAAC;KAAA;IAED,KAAK;QACH,IAAI,CAAC,OAAO,GAAG,EAAE,CAAA;IACnB,CAAC;CACF;AArFD,iCAqFC"}
@@ -0,0 +1,11 @@
1
+ import AccountManager from './AccountManager';
2
+ export default class TrezorTransport {
3
+ private accountManager;
4
+ private hdKey;
5
+ constructor();
6
+ connect(): Promise<void>;
7
+ getAccountManager(): Promise<AccountManager>;
8
+ private isUnlocked;
9
+ private init;
10
+ }
11
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/strategy/hw/index.ts"],"names":[],"mappings":"AAGA,OAAO,cAAc,MAAM,kBAAkB,CAAA;AAU7C,MAAM,CAAC,OAAO,OAAO,eAAe;IAClC,OAAO,CAAC,cAAc,CAA8B;IAEpD,OAAO,CAAC,KAAK,CAAuB;;IAM9B,OAAO;IAIP,iBAAiB,IAAI,OAAO,CAAC,cAAc,CAAC;IAQlD,OAAO,CAAC,UAAU;YAIJ,IAAI;CAmCnB"}
@@ -0,0 +1,75 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ const connect_web_1 = __importDefault(require("@trezor/connect-web"));
16
+ const hdkey_1 = __importDefault(require("hdkey"));
17
+ const wallet_base_1 = require("@injectivelabs/wallet-base");
18
+ const AccountManager_1 = __importDefault(require("./AccountManager"));
19
+ // @ts-ignore
20
+ const trezorConnect = connect_web_1.default.default || connect_web_1.default;
21
+ const TREZOR_CONNECT_MANIFEST = {
22
+ email: 'contact@injectivelabs.org',
23
+ appUrl: 'https://injectivelabs.org',
24
+ };
25
+ class TrezorTransport {
26
+ constructor() {
27
+ this.accountManager = null;
28
+ this.hdKey = new hdkey_1.default();
29
+ trezorConnect.init({ lazyLoad: true, manifest: TREZOR_CONNECT_MANIFEST });
30
+ }
31
+ connect() {
32
+ return __awaiter(this, void 0, void 0, function* () {
33
+ yield this.init();
34
+ });
35
+ }
36
+ getAccountManager() {
37
+ return __awaiter(this, void 0, void 0, function* () {
38
+ if (!this.accountManager) {
39
+ this.accountManager = new AccountManager_1.default(this.hdKey);
40
+ }
41
+ return this.accountManager;
42
+ });
43
+ }
44
+ isUnlocked() {
45
+ return Boolean(this.hdKey && this.hdKey.publicKey);
46
+ }
47
+ init() {
48
+ return __awaiter(this, void 0, void 0, function* () {
49
+ if (this.isUnlocked()) {
50
+ return Promise.resolve();
51
+ }
52
+ return new Promise((resolve, reject) => {
53
+ connect_web_1.default.getPublicKey({
54
+ path: `${wallet_base_1.DEFAULT_BASE_DERIVATION_PATH}/0'/0`,
55
+ coin: 'ETH',
56
+ })
57
+ .then((response) => {
58
+ if (!response.success) {
59
+ return reject(new Error((response.payload && response.payload.error) ||
60
+ 'Please make sure your Trezor is connected and unlocked'));
61
+ }
62
+ this.hdKey.publicKey = Buffer.from(response.payload.publicKey, 'hex');
63
+ this.hdKey.chainCode = Buffer.from(response.payload.chainCode, 'hex');
64
+ return resolve(connect_web_1.default);
65
+ })
66
+ .catch((e) => {
67
+ reject(new Error((e && e.toString()) ||
68
+ 'Please make sure your Trezor is connected and unlocked'));
69
+ });
70
+ });
71
+ });
72
+ }
73
+ }
74
+ exports.default = TrezorTransport;
75
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/strategy/hw/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAAA,sEAA+C;AAC/C,kDAA0B;AAC1B,4DAAyE;AACzE,sEAA6C;AAE7C,aAAa;AACb,MAAM,aAAa,GAAG,qBAAa,CAAC,OAAO,IAAI,qBAAa,CAAA;AAE5D,MAAM,uBAAuB,GAAG;IAC9B,KAAK,EAAE,2BAA2B;IAClC,MAAM,EAAE,2BAA2B;CACpC,CAAA;AAED,MAAqB,eAAe;IAKlC;QAJQ,mBA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CAAC,CAAA;oBACrE,IAAI,CAAC,KAAK,CAAC,SAAS,GAAG,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,SAAS,EAAE,KAAK,CAAC,CAAA;oBAErE,OAAO,OAAO,CAAC,qBAAa,CAAC,CAAA;gBAC/B,CAAC,CAAC;qBACD,KAAK,CAAC,CAAC,CAAM,EAAE,EAAE;oBAChB,MAAM,CACJ,IAAI,KAAK,CACP,CAAC,CAAC,IAAI,CAAC,CAAC,QAAQ,EAAE,CAAC;wBACjB,wDAAwD,CAC3D,CACF,CAAA;gBACH,CAAC,CAAC,CAAA;YACN,CAAC,CAAC,CAAA;QACJ,CAAC;KAAA;CACF;AA5DD,kCA4DC"}
@@ -0,0 +1,38 @@
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
+ export declare class TrezorWallet extends BaseConcreteStrategy implements ConcreteWalletStrategy {
5
+ private trezor;
6
+ private ethereumOptions;
7
+ private alchemy;
8
+ constructor(args: ConcreteEthereumWalletStrategyArgs);
9
+ getWalletDeviceType(): Promise<WalletDeviceType>;
10
+ enable(): Promise<boolean>;
11
+ disconnect(): Promise<void>;
12
+ getAddresses(): Promise<string[]>;
13
+ getSessionOrConfirm(address: AccountAddress): Promise<string>;
14
+ sendEthereumTransaction(txData: any, options: {
15
+ address: string;
16
+ ethereumChainId: EthereumChainId;
17
+ }): Promise<string>;
18
+ sendTransaction(transaction: TxRaw, options: SendTransactionOptions): Promise<TxResponse>;
19
+ signEip712TypedData(eip712json: string, address: AccountAddress): Promise<string>;
20
+ signAminoCosmosTransaction(_transaction: {
21
+ address: string;
22
+ signDoc: StdSignDoc;
23
+ }): Promise<AminoSignResponse>;
24
+ signCosmosTransaction(_transaction: {
25
+ txRaw: TxRaw;
26
+ accountNumber: number;
27
+ chainId: string;
28
+ address: string;
29
+ }): Promise<DirectSignResponse>;
30
+ signArbitrary(signer: AccountAddress, data: string | Uint8Array): Promise<string>;
31
+ getEthereumChainId(): Promise<string>;
32
+ getEthereumTransactionReceipt(txHash: string): Promise<string>;
33
+ getPubKey(): Promise<string>;
34
+ private signEthereumTransaction;
35
+ private getWalletForAddress;
36
+ private getAlchemy;
37
+ }
38
+ //# sourceMappingURL=strategy.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"strategy.d.ts","sourceRoot":"","sources":["../../../src/strategy/strategy.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAA;AAczE,OAAO,EACL,KAAK,EAGL,UAAU,EACV,kBAAkB,EAClB,iBAAiB,EAClB,MAAM,uBAAuB,CAAA;AAC9B,OAAO,EACL,UAAU,EAIV,gBAAgB,EAChB,oBAAoB,EACpB,sBAAsB,EACtB,sBAAsB,EAItB,kCAAkC,EACnC,MAAM,4BAA4B,CAAA;AAiCnC,qBAAa,YACX,SAAQ,oBACR,YAAW,sBAAsB;IAEjC,OAAO,CAAC,MAAM,CAAU;IAExB,OAAO,CAAC,eAAe,CAA+B;IAEtD,OAAO,CAAC,OAAO,CAAqB;gBAExB,IAAI,EAAE,kCAAkC;IAM9C,mBAAmB,IAAI,OAAO,CAAC,gBAAgB,CAAC;IAIhD,MAAM,IAAI,OAAO,CAAC,OAAO,CAAC;IAInB,UAAU;IAIV,YAAY,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC;IAgBxC,mBAAmB,CAAC,OAAO,EAAE,cAAc,GAAG,OAAO,CAAC,MAAM,CAAC;IAQ7D,uBAAuB,CAC3B,MAAM,EAAE,GAAG,EACX,OAAO,EAAE;QAAE,OAAO,EAAE,MAAM,CAAC;QAAC,eAAe,EAAE,eAAe,CAAA;KAAE,GAC7D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