@injectivelabs/wallet-trezor 1.16.24 → 1.16.25-alpha.1

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