@injectivelabs/wallet-trezor 1.16.23 → 1.16.25-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.
Files changed (49) hide show
  1. package/dist/cjs/index.cjs +471 -0
  2. package/dist/cjs/index.d.cts +72 -0
  3. package/dist/cjs/package.json +2 -2
  4. package/dist/esm/index.d.ts +72 -3
  5. package/dist/esm/index.js +469 -3
  6. package/dist/esm/package.json +2 -2
  7. package/package.json +17 -17
  8. package/dist/cjs/index.d.ts +0 -3
  9. package/dist/cjs/index.js +0 -22
  10. package/dist/cjs/strategy/Base.d.ts +0 -44
  11. package/dist/cjs/strategy/Base.js +0 -299
  12. package/dist/cjs/strategy/TrezorBip32.d.ts +0 -5
  13. package/dist/cjs/strategy/TrezorBip32.js +0 -17
  14. package/dist/cjs/strategy/TrezorBip44.d.ts +0 -5
  15. package/dist/cjs/strategy/TrezorBip44.js +0 -17
  16. package/dist/cjs/strategy/hw/AccountManager.d.ts +0 -20
  17. package/dist/cjs/strategy/hw/AccountManager.js +0 -104
  18. package/dist/cjs/strategy/hw/index.d.ts +0 -3
  19. package/dist/cjs/strategy/hw/index.js +0 -10
  20. package/dist/cjs/strategy/hw/transport/base.d.ts +0 -6
  21. package/dist/cjs/strategy/hw/transport/base.js +0 -32
  22. package/dist/cjs/strategy/hw/transport/transport-no-init.d.ts +0 -4
  23. package/dist/cjs/strategy/hw/transport/transport-no-init.js +0 -12
  24. package/dist/cjs/strategy/lib.d.ts +0 -3
  25. package/dist/cjs/strategy/lib.js +0 -45
  26. package/dist/cjs/types.d.ts +0 -15
  27. package/dist/cjs/types.js +0 -8
  28. package/dist/cjs/utils.d.ts +0 -16
  29. package/dist/cjs/utils.js +0 -36
  30. package/dist/esm/strategy/Base.d.ts +0 -44
  31. package/dist/esm/strategy/Base.js +0 -296
  32. package/dist/esm/strategy/TrezorBip32.d.ts +0 -5
  33. package/dist/esm/strategy/TrezorBip32.js +0 -10
  34. package/dist/esm/strategy/TrezorBip44.d.ts +0 -5
  35. package/dist/esm/strategy/TrezorBip44.js +0 -10
  36. package/dist/esm/strategy/hw/AccountManager.d.ts +0 -20
  37. package/dist/esm/strategy/hw/AccountManager.js +0 -101
  38. package/dist/esm/strategy/hw/index.d.ts +0 -3
  39. package/dist/esm/strategy/hw/index.js +0 -3
  40. package/dist/esm/strategy/hw/transport/base.d.ts +0 -6
  41. package/dist/esm/strategy/hw/transport/base.js +0 -26
  42. package/dist/esm/strategy/hw/transport/transport-no-init.d.ts +0 -4
  43. package/dist/esm/strategy/hw/transport/transport-no-init.js +0 -6
  44. package/dist/esm/strategy/lib.d.ts +0 -3
  45. package/dist/esm/strategy/lib.js +0 -9
  46. package/dist/esm/types.d.ts +0 -15
  47. package/dist/esm/types.js +0 -5
  48. package/dist/esm/utils.d.ts +0 -16
  49. package/dist/esm/utils.js +0 -32
@@ -0,0 +1,471 @@
1
+ let __injectivelabs_utils = require("@injectivelabs/utils");
2
+ let viem = require("viem");
3
+ let __injectivelabs_ts_types = require("@injectivelabs/ts-types");
4
+ let alchemy_sdk = require("alchemy-sdk");
5
+ let __injectivelabs_sdk_ts = require("@injectivelabs/sdk-ts");
6
+ let __injectivelabs_exceptions = require("@injectivelabs/exceptions");
7
+ let __injectivelabs_wallet_base = require("@injectivelabs/wallet-base");
8
+
9
+ //#region src/types.ts
10
+ const TrezorDerivationPathType = {
11
+ Bip32: "bip32",
12
+ Bip44: "bip44",
13
+ Legacy: "legacy"
14
+ };
15
+
16
+ //#endregion
17
+ //#region src/strategy/lib.ts
18
+ let TrezorConnect;
19
+ async function loadTrezorConnect() {
20
+ if (!TrezorConnect) {
21
+ const module$1 = await import("@bangjelkoski/trezor-connect-web");
22
+ TrezorConnect = module$1.TrezorConnect || module$1.default.TrezorConnect;
23
+ }
24
+ return TrezorConnect;
25
+ }
26
+
27
+ //#endregion
28
+ //#region src/utils.ts
29
+ /**
30
+ * Calculates the domain_separator_hash and message_hash from an EIP-712 Typed Data object.
31
+ *
32
+ * The Trezor Model 1 does not currently support constructing the hash on the device,
33
+ * so this function pre-computes them.
34
+ *
35
+ * @template {TypedMessage} T
36
+ * @param {T} data - The EIP-712 Typed Data object.
37
+ * @param {boolean} metamask_v4_compat - Set to `true` for compatibility with Metamask's signTypedData_v4 function.
38
+ * @returns {{domain_separator_hash: string, message_hash?: string} & T} The hashes.
39
+ */
40
+ const transformTypedData = (data, metamask_v4_compat = true) => {
41
+ if (!metamask_v4_compat) throw new __injectivelabs_exceptions.TrezorException(/* @__PURE__ */ new Error("Trezor: Only version 4 of typed data signing is supported"));
42
+ const version = __injectivelabs_sdk_ts.SignTypedDataVersionV4;
43
+ const { types, primaryType, domain, message } = (0, __injectivelabs_sdk_ts.TypedDataUtilsSanitizeData)(data);
44
+ const domainSeparatorHash = (0, __injectivelabs_sdk_ts.TypedDataUtilsHashStruct)("EIP712Domain", (0, __injectivelabs_sdk_ts.sanitizeTypedData)(domain), types, version).toString("hex");
45
+ let messageHash = null;
46
+ if (primaryType !== "EIP712Domain") messageHash = (0, __injectivelabs_sdk_ts.TypedDataUtilsHashStruct)(primaryType, (0, __injectivelabs_sdk_ts.sanitizeTypedData)(message), {
47
+ ...types,
48
+ domain: (0, __injectivelabs_sdk_ts.sanitizeTypedData)(domain)
49
+ }, version).toString("hex");
50
+ return {
51
+ domain_separator_hash: domainSeparatorHash,
52
+ message_hash: messageHash,
53
+ ...data
54
+ };
55
+ };
56
+
57
+ //#endregion
58
+ //#region \0@oxc-project+runtime@0.96.0/helpers/typeof.js
59
+ function _typeof(o) {
60
+ "@babel/helpers - typeof";
61
+ return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o$1) {
62
+ return typeof o$1;
63
+ } : function(o$1) {
64
+ return o$1 && "function" == typeof Symbol && o$1.constructor === Symbol && o$1 !== Symbol.prototype ? "symbol" : typeof o$1;
65
+ }, _typeof(o);
66
+ }
67
+
68
+ //#endregion
69
+ //#region \0@oxc-project+runtime@0.96.0/helpers/toPrimitive.js
70
+ function toPrimitive(t, r) {
71
+ if ("object" != _typeof(t) || !t) return t;
72
+ var e = t[Symbol.toPrimitive];
73
+ if (void 0 !== e) {
74
+ var i = e.call(t, r || "default");
75
+ if ("object" != _typeof(i)) return i;
76
+ throw new TypeError("@@toPrimitive must return a primitive value.");
77
+ }
78
+ return ("string" === r ? String : Number)(t);
79
+ }
80
+
81
+ //#endregion
82
+ //#region \0@oxc-project+runtime@0.96.0/helpers/toPropertyKey.js
83
+ function toPropertyKey(t) {
84
+ var i = toPrimitive(t, "string");
85
+ return "symbol" == _typeof(i) ? i : i + "";
86
+ }
87
+
88
+ //#endregion
89
+ //#region \0@oxc-project+runtime@0.96.0/helpers/defineProperty.js
90
+ function _defineProperty(e, r, t) {
91
+ return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
92
+ value: t,
93
+ enumerable: !0,
94
+ configurable: !0,
95
+ writable: !0
96
+ }) : e[r] = t, e;
97
+ }
98
+
99
+ //#endregion
100
+ //#region src/strategy/hw/AccountManager.ts
101
+ const addressOfHDKey = (hdKey) => {
102
+ const shouldSanitizePublicKey = true;
103
+ const derivedPublicKey = hdKey.publicKey;
104
+ return (0, __injectivelabs_sdk_ts.addHexPrefix)((0, __injectivelabs_sdk_ts.uint8ArrayToHex)((0, __injectivelabs_sdk_ts.publicKeyToAddress)(derivedPublicKey, shouldSanitizePublicKey)));
105
+ };
106
+ var AccountManager = class {
107
+ constructor() {
108
+ _defineProperty(this, "wallets", []);
109
+ _defineProperty(this, "getTrezorDerivationPathBasedOnType", ({ fullBaseDerivationPath, derivationPathType, index }) => {
110
+ if (derivationPathType === TrezorDerivationPathType.Bip44) return `${fullBaseDerivationPath}/${index}'/0/0`;
111
+ if (derivationPathType === TrezorDerivationPathType.Legacy) return `m/${index}`;
112
+ return `${fullBaseDerivationPath}/0'/0/${index}`;
113
+ });
114
+ this.wallets = [];
115
+ }
116
+ async getWallets(baseDerivationPath, derivationPathType) {
117
+ const { start, end } = this.getOffset();
118
+ /**
119
+ * 1. Wallets are not yet fetched at all,
120
+ * 2. Wallets are not yet fetched for that offset
121
+ */
122
+ if (!this.hasWallets() || !this.hasWalletsInOffset(start)) await this.getWalletsBasedOnIndex({
123
+ start,
124
+ end,
125
+ baseDerivationPath,
126
+ derivationPathType
127
+ });
128
+ return this.wallets.slice(start, end);
129
+ }
130
+ async getWalletsBasedOnIndex({ start, end, baseDerivationPath, derivationPathType }) {
131
+ const TrezorConnect$1 = await loadTrezorConnect();
132
+ const pathsToFetch = [];
133
+ for (let index = start; index < end; index += 1) {
134
+ const path = this.getTrezorDerivationPathBasedOnType({
135
+ fullBaseDerivationPath: baseDerivationPath,
136
+ derivationPathType,
137
+ index
138
+ });
139
+ pathsToFetch.push({
140
+ path,
141
+ showOnTrezor: false
142
+ });
143
+ }
144
+ const result = await TrezorConnect$1.ethereumGetPublicKey({ bundle: pathsToFetch });
145
+ if (!result.success) throw new __injectivelabs_exceptions.TrezorException(new Error(result.payload && result.payload.error || "Please make sure your Trezor is connected and unlocked"));
146
+ for (const item of result.payload) {
147
+ const hdKey = {
148
+ publicKey: (0, __injectivelabs_sdk_ts.hexToUint8Array)(item.publicKey),
149
+ chainCode: (0, __injectivelabs_sdk_ts.hexToUint8Array)(item.chainCode)
150
+ };
151
+ const address = addressOfHDKey(hdKey);
152
+ this.wallets.push({
153
+ hdKey,
154
+ derivationPath: item.serializedPath,
155
+ address: address.toLowerCase()
156
+ });
157
+ }
158
+ }
159
+ hasWallets() {
160
+ return this.wallets.length > 0;
161
+ }
162
+ hasWalletsInOffset(offset) {
163
+ return this.wallets.length > offset;
164
+ }
165
+ getOffset() {
166
+ const totalWallets = this.wallets.length;
167
+ return {
168
+ start: totalWallets,
169
+ end: totalWallets + __injectivelabs_wallet_base.DEFAULT_NUM_ADDRESSES_TO_FETCH
170
+ };
171
+ }
172
+ hasWalletForAddress(address) {
173
+ return this.wallets.find((wallet) => wallet.address.toLowerCase() === address.toLowerCase()) !== void 0;
174
+ }
175
+ async getWalletForAddress(address) {
176
+ return this.wallets.find((wallet) => wallet.address.toLowerCase() === address.toLowerCase());
177
+ }
178
+ reset() {
179
+ this.wallets = [];
180
+ }
181
+ };
182
+
183
+ //#endregion
184
+ //#region src/strategy/hw/transport/base.ts
185
+ const TREZOR_CONNECT_MANIFEST = {
186
+ email: "contact@injectivelabs.org",
187
+ appUrl: "https://injectivelabs.org"
188
+ };
189
+ var BaseTrezorTransport = class {
190
+ constructor() {
191
+ _defineProperty(this, "accountManager", null);
192
+ }
193
+ async connect() {
194
+ const TrezorConnect$1 = await loadTrezorConnect();
195
+ if (!(await TrezorConnect$1.getSettings()).success) TrezorConnect$1.init({
196
+ lazyLoad: true,
197
+ manifest: TREZOR_CONNECT_MANIFEST
198
+ });
199
+ return Promise.resolve();
200
+ }
201
+ async getAccountManager() {
202
+ if (!this.accountManager) this.accountManager = new AccountManager();
203
+ return this.accountManager;
204
+ }
205
+ };
206
+
207
+ //#endregion
208
+ //#region src/strategy/Base.ts
209
+ var TrezorBase = class extends __injectivelabs_wallet_base.BaseConcreteStrategy {
210
+ constructor(args) {
211
+ super(args);
212
+ _defineProperty(this, "baseDerivationPath", void 0);
213
+ _defineProperty(this, "trezor", void 0);
214
+ _defineProperty(this, "evmOptions", void 0);
215
+ _defineProperty(this, "alchemy", void 0);
216
+ _defineProperty(this, "derivationPathType", void 0);
217
+ this.evmOptions = args.evmOptions;
218
+ this.trezor = new BaseTrezorTransport();
219
+ this.derivationPathType = args.derivationPathType;
220
+ this.baseDerivationPath = __injectivelabs_wallet_base.DEFAULT_BASE_DERIVATION_PATH;
221
+ }
222
+ async getWalletDeviceType() {
223
+ return Promise.resolve(__injectivelabs_wallet_base.WalletDeviceType.Hardware);
224
+ }
225
+ async enable() {
226
+ return Promise.resolve(true);
227
+ }
228
+ async disconnect() {
229
+ return Promise.resolve();
230
+ }
231
+ async getAddresses() {
232
+ const { baseDerivationPath, derivationPathType } = this;
233
+ try {
234
+ await this.trezor.connect();
235
+ return (await (await this.trezor.getAccountManager()).getWallets(baseDerivationPath, derivationPathType)).map((k) => k.address);
236
+ } catch (e) {
237
+ throw new __injectivelabs_exceptions.TrezorException(new Error(e.message), {
238
+ code: __injectivelabs_exceptions.UnspecifiedErrorCode,
239
+ type: __injectivelabs_exceptions.ErrorType.WalletError,
240
+ contextModule: __injectivelabs_wallet_base.WalletAction.GetAccounts
241
+ });
242
+ }
243
+ }
244
+ async getSessionOrConfirm(address) {
245
+ return Promise.resolve(`0x${(0, __injectivelabs_sdk_ts.uint8ArrayToHex)((0, __injectivelabs_sdk_ts.stringToUint8Array)(`Confirmation for ${address} at time: ${Date.now()}`))}`);
246
+ }
247
+ async sendEvmTransaction(txData, args) {
248
+ const signedTransaction = await this.signEvmTransaction(txData, args);
249
+ try {
250
+ return await (await (await this.getAlchemy(args.evmChainId)).config.getProvider()).send("eth_sendRawTransaction", [signedTransaction]);
251
+ } catch (e) {
252
+ throw new __injectivelabs_exceptions.TrezorException(new Error(e.message), {
253
+ code: __injectivelabs_exceptions.UnspecifiedErrorCode,
254
+ type: __injectivelabs_exceptions.ErrorType.WalletError,
255
+ contextModule: __injectivelabs_wallet_base.WalletAction.SendEvmTransaction
256
+ });
257
+ }
258
+ }
259
+ async sendTransaction(transaction, options) {
260
+ const { endpoints, txTimeout } = options;
261
+ if (!endpoints) throw new __injectivelabs_exceptions.WalletException(/* @__PURE__ */ new Error("You have to pass endpoints.grpc within the options for using Ethereum native wallets"));
262
+ const response = await new __injectivelabs_sdk_ts.TxGrpcApi(endpoints.grpc).broadcast(transaction, { txTimeout });
263
+ if (response.code !== 0) throw new __injectivelabs_exceptions.TransactionException(new Error(response.rawLog), {
264
+ code: __injectivelabs_exceptions.UnspecifiedErrorCode,
265
+ contextCode: response.code,
266
+ contextModule: response.codespace
267
+ });
268
+ return response;
269
+ }
270
+ async signEip712TypedData(eip712json, address) {
271
+ const TrezorConnect$1 = await loadTrezorConnect();
272
+ const object = JSON.parse(eip712json);
273
+ const { types: { EIP712Domain = [],...otherTypes } = {}, message = {}, domain = {}, primaryType, domain_separator_hash, message_hash } = transformTypedData({
274
+ ...object,
275
+ domain: {
276
+ ...object.domain,
277
+ chainId: object.domain.chainId,
278
+ salt: "0"
279
+ }
280
+ });
281
+ try {
282
+ await this.trezor.connect();
283
+ const { derivationPath } = await this.getWalletForAddress(address);
284
+ const response = await TrezorConnect$1.ethereumSignTypedData({
285
+ path: derivationPath,
286
+ data: {
287
+ types: {
288
+ EIP712Domain,
289
+ ...otherTypes
290
+ },
291
+ message,
292
+ domain,
293
+ primaryType
294
+ },
295
+ message_hash,
296
+ domain_separator_hash,
297
+ metamask_v4_compat: true
298
+ });
299
+ if (!response.success) throw new Error(response.payload && response.payload.error || "Unknown error");
300
+ return response.payload.signature;
301
+ } catch (e) {
302
+ throw new __injectivelabs_exceptions.TrezorException(new Error(e.message), {
303
+ code: __injectivelabs_exceptions.UnspecifiedErrorCode,
304
+ type: __injectivelabs_exceptions.ErrorType.WalletError,
305
+ contextModule: __injectivelabs_wallet_base.WalletAction.SignTransaction
306
+ });
307
+ }
308
+ }
309
+ async signAminoCosmosTransaction(_transaction) {
310
+ throw new __injectivelabs_exceptions.WalletException(/* @__PURE__ */ new Error("This wallet does not support signing Cosmos transactions"), {
311
+ code: __injectivelabs_exceptions.UnspecifiedErrorCode,
312
+ type: __injectivelabs_exceptions.ErrorType.WalletError,
313
+ contextModule: __injectivelabs_wallet_base.WalletAction.SendTransaction
314
+ });
315
+ }
316
+ async signCosmosTransaction(_transaction) {
317
+ throw new __injectivelabs_exceptions.WalletException(/* @__PURE__ */ new Error("This wallet does not support signing Cosmos transactions"), {
318
+ code: __injectivelabs_exceptions.UnspecifiedErrorCode,
319
+ type: __injectivelabs_exceptions.ErrorType.WalletError,
320
+ contextModule: __injectivelabs_wallet_base.WalletAction.SendTransaction
321
+ });
322
+ }
323
+ async signArbitrary(signer, data) {
324
+ const TrezorConnect$1 = await loadTrezorConnect();
325
+ try {
326
+ await this.trezor.connect();
327
+ const { derivationPath } = await this.getWalletForAddress(signer);
328
+ const response = await TrezorConnect$1.ethereumSignMessage({
329
+ path: derivationPath,
330
+ message: (0, __injectivelabs_sdk_ts.toUtf8)(data)
331
+ });
332
+ if (!response.success) throw new Error(response.payload && response.payload.error || "Unknown error");
333
+ return response.payload.signature;
334
+ } catch (e) {
335
+ throw new __injectivelabs_exceptions.TrezorException(new Error(e.message), {
336
+ code: __injectivelabs_exceptions.UnspecifiedErrorCode,
337
+ type: __injectivelabs_exceptions.ErrorType.WalletError,
338
+ contextModule: __injectivelabs_wallet_base.WalletAction.SignTransaction
339
+ });
340
+ }
341
+ }
342
+ async getEthereumChainId() {
343
+ return (await (await this.getAlchemy()).config.getProvider()).network.chainId.toString();
344
+ }
345
+ async getEvmTransactionReceipt(txHash, evmChainId) {
346
+ const provider = await (await this.getAlchemy(evmChainId)).config.getProvider();
347
+ const interval = 3e3;
348
+ const maxAttempts = 10;
349
+ let attempts = 0;
350
+ while (attempts < maxAttempts) {
351
+ attempts++;
352
+ await (0, __injectivelabs_utils.sleep)(interval);
353
+ try {
354
+ if (await provider.send("eth_getTransactionReceipt", [txHash])) return txHash;
355
+ } catch (_unused) {}
356
+ }
357
+ throw new Error(`Failed to retrieve transaction receipt for txHash: ${txHash}`);
358
+ }
359
+ async getPubKey() {
360
+ throw new __injectivelabs_exceptions.WalletException(/* @__PURE__ */ new Error("You can only fetch PubKey from Cosmos native wallets"));
361
+ }
362
+ async signEvmTransaction(txData, args) {
363
+ const TrezorConnect$1 = await loadTrezorConnect();
364
+ const chainId = parseInt(args.evmChainId.toString(), 10);
365
+ const nonce = await (await this.getAlchemy(args.evmChainId)).core.getTransactionCount(args.address);
366
+ const parseHexValue = (value) => {
367
+ if (typeof value === "string") {
368
+ const hexValue = value.startsWith("0x") ? value : `0x${value}`;
369
+ return BigInt(hexValue);
370
+ }
371
+ return BigInt(value);
372
+ };
373
+ const valueBigInt = parseHexValue(txData.value || "0x0");
374
+ const gasBigInt = parseHexValue(txData.gas);
375
+ const maxFeePerGasBigInt = parseHexValue(txData.maxFeePerGas);
376
+ const maxPriorityFeePerGasBigInt = parseHexValue(txData.maxPriorityFeePerGas);
377
+ const trezorTxData = {
378
+ to: txData.to,
379
+ value: (0, viem.toHex)(valueBigInt),
380
+ gasLimit: (0, viem.toHex)(gasBigInt),
381
+ nonce: (0, viem.toHex)(nonce),
382
+ data: txData.data || "0x",
383
+ chainId,
384
+ maxFeePerGas: (0, viem.toHex)(maxFeePerGasBigInt),
385
+ maxPriorityFeePerGas: (0, viem.toHex)(maxPriorityFeePerGasBigInt)
386
+ };
387
+ try {
388
+ await this.trezor.connect();
389
+ const { derivationPath } = await this.getWalletForAddress(args.address);
390
+ const response = await TrezorConnect$1.ethereumSignTransaction({
391
+ path: derivationPath,
392
+ transaction: trezorTxData
393
+ });
394
+ if (!response.success) throw new __injectivelabs_exceptions.TrezorException(new Error(response.payload && response.payload.error || "Something happened while signing with Trezor"), {
395
+ code: __injectivelabs_exceptions.UnspecifiedErrorCode,
396
+ type: __injectivelabs_exceptions.ErrorType.WalletError,
397
+ contextModule: __injectivelabs_wallet_base.WalletAction.SignEvmTransaction
398
+ });
399
+ return (0, viem.serializeTransaction)({
400
+ type: "eip1559",
401
+ chainId,
402
+ nonce,
403
+ to: txData.to,
404
+ value: valueBigInt,
405
+ data: txData.data || "0x",
406
+ gas: gasBigInt,
407
+ maxFeePerGas: maxFeePerGasBigInt,
408
+ maxPriorityFeePerGas: maxPriorityFeePerGasBigInt,
409
+ v: BigInt(response.payload.v),
410
+ r: response.payload.r,
411
+ s: response.payload.s
412
+ });
413
+ } catch (e) {
414
+ if (e instanceof __injectivelabs_exceptions.TrezorException) throw e;
415
+ throw new __injectivelabs_exceptions.TrezorException(new Error(e.message), {
416
+ code: __injectivelabs_exceptions.UnspecifiedErrorCode,
417
+ type: __injectivelabs_exceptions.ErrorType.WalletError,
418
+ contextModule: __injectivelabs_wallet_base.WalletAction.SignEvmTransaction
419
+ });
420
+ }
421
+ }
422
+ async getWalletForAddress(address) {
423
+ const { baseDerivationPath, derivationPathType } = this;
424
+ const accountManager = await this.trezor.getAccountManager();
425
+ if (!accountManager.hasWalletForAddress(address)) for (let i = 0; i < __injectivelabs_wallet_base.DEFAULT_ADDRESS_SEARCH_LIMIT / __injectivelabs_wallet_base.DEFAULT_NUM_ADDRESSES_TO_FETCH; i += 1) {
426
+ await accountManager.getWallets(baseDerivationPath, derivationPathType);
427
+ if (accountManager.hasWalletForAddress(address)) return await accountManager.getWalletForAddress(address);
428
+ }
429
+ return await accountManager.getWalletForAddress(address);
430
+ }
431
+ async getAlchemy(evmChainId) {
432
+ var _options$rpcUrls;
433
+ if (this.alchemy) return this.alchemy;
434
+ const options = this.evmOptions;
435
+ const chainId = evmChainId || options.evmChainId;
436
+ const url = options.rpcUrl || ((_options$rpcUrls = options.rpcUrls) === null || _options$rpcUrls === void 0 ? void 0 : _options$rpcUrls[chainId]);
437
+ if (!url) throw new __injectivelabs_exceptions.GeneralException(/* @__PURE__ */ new Error("Please pass rpcUrl within the ethereumOptions"));
438
+ this.alchemy = new alchemy_sdk.Alchemy({
439
+ apiKey: (0, __injectivelabs_wallet_base.getKeyFromRpcUrl)(url),
440
+ network: chainId === __injectivelabs_ts_types.EvmChainId.Mainnet ? alchemy_sdk.Network.ETH_MAINNET : alchemy_sdk.Network.ETH_SEPOLIA
441
+ });
442
+ return this.alchemy;
443
+ }
444
+ };
445
+
446
+ //#endregion
447
+ //#region src/strategy/TrezorBip32.ts
448
+ var TrezorBip32 = class extends TrezorBase {
449
+ constructor(args) {
450
+ super({
451
+ ...args,
452
+ derivationPathType: TrezorDerivationPathType.Bip32
453
+ });
454
+ }
455
+ };
456
+
457
+ //#endregion
458
+ //#region src/strategy/TrezorBip44.ts
459
+ var TrezorBip44 = class extends TrezorBase {
460
+ constructor(args) {
461
+ super({
462
+ ...args,
463
+ derivationPathType: TrezorDerivationPathType.Bip44
464
+ });
465
+ }
466
+ };
467
+
468
+ //#endregion
469
+ exports.TrezorBip32Strategy = TrezorBip32;
470
+ exports.TrezorBip44Strategy = TrezorBip44;
471
+ exports.TrezorDerivationPathType = TrezorDerivationPathType;
@@ -0,0 +1,72 @@
1
+ import { AccountAddress, EvmChainId } from "@injectivelabs/ts-types";
2
+ import { BaseConcreteStrategy, ConcreteEvmWalletStrategyArgs, ConcreteWalletStrategy, SendTransactionOptions, StdSignDoc, WalletDeviceType } from "@injectivelabs/wallet-base";
3
+ import { AminoSignResponse, DirectSignResponse, TxRaw, TxResponse } from "@injectivelabs/sdk-ts";
4
+
5
+ //#region src/types.d.ts
6
+ interface HDNodeLike {
7
+ publicKey: Uint8Array;
8
+ chainCode: Uint8Array;
9
+ }
10
+ declare const TrezorDerivationPathType: {
11
+ readonly Bip32: "bip32";
12
+ readonly Bip44: "bip44";
13
+ readonly Legacy: "legacy";
14
+ };
15
+ type TrezorDerivationPathType = (typeof TrezorDerivationPathType)[keyof typeof TrezorDerivationPathType];
16
+ interface TrezorWalletInfo {
17
+ address: string;
18
+ hdKey: HDNodeLike;
19
+ derivationPath: string;
20
+ }
21
+ //#endregion
22
+ //#region src/strategy/Base.d.ts
23
+ declare class TrezorBase extends BaseConcreteStrategy implements ConcreteWalletStrategy {
24
+ private baseDerivationPath;
25
+ private trezor;
26
+ private evmOptions;
27
+ private alchemy;
28
+ private derivationPathType;
29
+ constructor(args: ConcreteEvmWalletStrategyArgs & {
30
+ derivationPathType: TrezorDerivationPathType;
31
+ });
32
+ getWalletDeviceType(): Promise<WalletDeviceType>;
33
+ enable(): Promise<boolean>;
34
+ disconnect(): Promise<void>;
35
+ getAddresses(): Promise<string[]>;
36
+ getSessionOrConfirm(address: AccountAddress): Promise<string>;
37
+ sendEvmTransaction(txData: any, args: {
38
+ address: string;
39
+ evmChainId: EvmChainId;
40
+ }): Promise<string>;
41
+ sendTransaction(transaction: TxRaw, options: SendTransactionOptions): Promise<TxResponse>;
42
+ signEip712TypedData(eip712json: string, address: AccountAddress): Promise<string>;
43
+ signAminoCosmosTransaction(_transaction: {
44
+ address: string;
45
+ signDoc: StdSignDoc;
46
+ }): Promise<AminoSignResponse>;
47
+ signCosmosTransaction(_transaction: {
48
+ txRaw: TxRaw;
49
+ accountNumber: number;
50
+ chainId: string;
51
+ address: string;
52
+ }): Promise<DirectSignResponse>;
53
+ signArbitrary(signer: AccountAddress, data: string | Uint8Array): Promise<string>;
54
+ getEthereumChainId(): Promise<string>;
55
+ getEvmTransactionReceipt(txHash: string, evmChainId?: EvmChainId): Promise<string>;
56
+ getPubKey(): Promise<string>;
57
+ private signEvmTransaction;
58
+ private getWalletForAddress;
59
+ private getAlchemy;
60
+ }
61
+ //#endregion
62
+ //#region src/strategy/TrezorBip32.d.ts
63
+ declare class TrezorBip32 extends TrezorBase {
64
+ constructor(args: ConcreteEvmWalletStrategyArgs);
65
+ }
66
+ //#endregion
67
+ //#region src/strategy/TrezorBip44.d.ts
68
+ declare class TrezorBip44 extends TrezorBase {
69
+ constructor(args: ConcreteEvmWalletStrategyArgs);
70
+ }
71
+ //#endregion
72
+ export { HDNodeLike, TrezorBip32 as TrezorBip32Strategy, TrezorBip44 as TrezorBip44Strategy, TrezorDerivationPathType, TrezorWalletInfo };
@@ -1,3 +1,3 @@
1
1
  {
2
- "type": "commonjs"
3
- }
2
+ "type": "commonjs"
3
+ }
@@ -1,3 +1,72 @@
1
- export { TrezorBip32 as TrezorBip32Strategy } from './strategy/TrezorBip32.js';
2
- export { TrezorBip44 as TrezorBip44Strategy } from './strategy/TrezorBip44.js';
3
- export * from './types.js';
1
+ import { AccountAddress, EvmChainId } from "@injectivelabs/ts-types";
2
+ import { AminoSignResponse, DirectSignResponse, TxRaw, TxResponse } from "@injectivelabs/sdk-ts";
3
+ import { BaseConcreteStrategy, ConcreteEvmWalletStrategyArgs, ConcreteWalletStrategy, SendTransactionOptions, StdSignDoc, WalletDeviceType } from "@injectivelabs/wallet-base";
4
+
5
+ //#region src/types.d.ts
6
+ interface HDNodeLike {
7
+ publicKey: Uint8Array;
8
+ chainCode: Uint8Array;
9
+ }
10
+ declare const TrezorDerivationPathType: {
11
+ readonly Bip32: "bip32";
12
+ readonly Bip44: "bip44";
13
+ readonly Legacy: "legacy";
14
+ };
15
+ type TrezorDerivationPathType = (typeof TrezorDerivationPathType)[keyof typeof TrezorDerivationPathType];
16
+ interface TrezorWalletInfo {
17
+ address: string;
18
+ hdKey: HDNodeLike;
19
+ derivationPath: string;
20
+ }
21
+ //#endregion
22
+ //#region src/strategy/Base.d.ts
23
+ declare class TrezorBase extends BaseConcreteStrategy implements ConcreteWalletStrategy {
24
+ private baseDerivationPath;
25
+ private trezor;
26
+ private evmOptions;
27
+ private alchemy;
28
+ private derivationPathType;
29
+ constructor(args: ConcreteEvmWalletStrategyArgs & {
30
+ derivationPathType: TrezorDerivationPathType;
31
+ });
32
+ getWalletDeviceType(): Promise<WalletDeviceType>;
33
+ enable(): Promise<boolean>;
34
+ disconnect(): Promise<void>;
35
+ getAddresses(): Promise<string[]>;
36
+ getSessionOrConfirm(address: AccountAddress): Promise<string>;
37
+ sendEvmTransaction(txData: any, args: {
38
+ address: string;
39
+ evmChainId: EvmChainId;
40
+ }): Promise<string>;
41
+ sendTransaction(transaction: TxRaw, options: SendTransactionOptions): Promise<TxResponse>;
42
+ signEip712TypedData(eip712json: string, address: AccountAddress): Promise<string>;
43
+ signAminoCosmosTransaction(_transaction: {
44
+ address: string;
45
+ signDoc: StdSignDoc;
46
+ }): Promise<AminoSignResponse>;
47
+ signCosmosTransaction(_transaction: {
48
+ txRaw: TxRaw;
49
+ accountNumber: number;
50
+ chainId: string;
51
+ address: string;
52
+ }): Promise<DirectSignResponse>;
53
+ signArbitrary(signer: AccountAddress, data: string | Uint8Array): Promise<string>;
54
+ getEthereumChainId(): Promise<string>;
55
+ getEvmTransactionReceipt(txHash: string, evmChainId?: EvmChainId): Promise<string>;
56
+ getPubKey(): Promise<string>;
57
+ private signEvmTransaction;
58
+ private getWalletForAddress;
59
+ private getAlchemy;
60
+ }
61
+ //#endregion
62
+ //#region src/strategy/TrezorBip32.d.ts
63
+ declare class TrezorBip32 extends TrezorBase {
64
+ constructor(args: ConcreteEvmWalletStrategyArgs);
65
+ }
66
+ //#endregion
67
+ //#region src/strategy/TrezorBip44.d.ts
68
+ declare class TrezorBip44 extends TrezorBase {
69
+ constructor(args: ConcreteEvmWalletStrategyArgs);
70
+ }
71
+ //#endregion
72
+ export { HDNodeLike, TrezorBip32 as TrezorBip32Strategy, TrezorBip44 as TrezorBip44Strategy, TrezorDerivationPathType, TrezorWalletInfo };