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