@injectivelabs/wallet-trezor 1.17.2-alpha.1 → 1.17.2-alpha.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/index.cjs +50 -12
- package/dist/esm/index.js +50 -12
- package/package.json +9 -5
package/dist/cjs/index.cjs
CHANGED
|
@@ -13,10 +13,14 @@ const TrezorDerivationPathType = {
|
|
|
13
13
|
|
|
14
14
|
//#endregion
|
|
15
15
|
//#region src/strategy/lib.ts
|
|
16
|
+
let cachedTrezorConnect = null;
|
|
16
17
|
async function loadTrezorConnect() {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
18
|
+
if (!cachedTrezorConnect) {
|
|
19
|
+
var _default;
|
|
20
|
+
const module$1 = await import("@trezor/connect-web");
|
|
21
|
+
cachedTrezorConnect = (module$1 === null || module$1 === void 0 || (_default = module$1.default) === null || _default === void 0 ? void 0 : _default.default) || module$1.default;
|
|
22
|
+
}
|
|
23
|
+
return cachedTrezorConnect;
|
|
20
24
|
}
|
|
21
25
|
|
|
22
26
|
//#endregion
|
|
@@ -182,24 +186,54 @@ const TREZOR_CONNECT_MANIFEST = {
|
|
|
182
186
|
appUrl: "https://injectivelabs.org",
|
|
183
187
|
appName: "Injective Labs"
|
|
184
188
|
};
|
|
185
|
-
var BaseTrezorTransport = class {
|
|
189
|
+
var BaseTrezorTransport = class BaseTrezorTransport {
|
|
186
190
|
constructor() {
|
|
187
191
|
_defineProperty(this, "accountManager", null);
|
|
188
192
|
}
|
|
189
193
|
async connect() {
|
|
194
|
+
if (BaseTrezorTransport.initPromise) return BaseTrezorTransport.initPromise;
|
|
195
|
+
if (BaseTrezorTransport.isInitialized) return Promise.resolve();
|
|
196
|
+
BaseTrezorTransport.initPromise = this.initializeTrezorConnect();
|
|
197
|
+
try {
|
|
198
|
+
await BaseTrezorTransport.initPromise;
|
|
199
|
+
BaseTrezorTransport.isInitialized = true;
|
|
200
|
+
} finally {
|
|
201
|
+
BaseTrezorTransport.initPromise = null;
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
async initializeTrezorConnect() {
|
|
190
205
|
const TrezorConnect = await loadTrezorConnect();
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
206
|
+
try {
|
|
207
|
+
await TrezorConnect.init({
|
|
208
|
+
manifest: TREZOR_CONNECT_MANIFEST,
|
|
209
|
+
coreMode: "popup",
|
|
210
|
+
interactionTimeout: 600
|
|
211
|
+
});
|
|
212
|
+
} catch (error) {
|
|
213
|
+
BaseTrezorTransport.isInitialized = false;
|
|
214
|
+
throw error;
|
|
215
|
+
}
|
|
197
216
|
}
|
|
198
217
|
async getAccountManager() {
|
|
199
218
|
if (!this.accountManager) this.accountManager = new AccountManager();
|
|
200
219
|
return this.accountManager;
|
|
201
220
|
}
|
|
221
|
+
/**
|
|
222
|
+
* Resets the initialization state. Call this if you need to reinitialize
|
|
223
|
+
* TrezorConnect (e.g., after a connection error or when switching contexts).
|
|
224
|
+
*/
|
|
225
|
+
static async reset() {
|
|
226
|
+
if (BaseTrezorTransport.isInitialized) {
|
|
227
|
+
var _TrezorConnect$dispos;
|
|
228
|
+
const TrezorConnect = await loadTrezorConnect();
|
|
229
|
+
await ((_TrezorConnect$dispos = TrezorConnect.dispose) === null || _TrezorConnect$dispos === void 0 ? void 0 : _TrezorConnect$dispos.call(TrezorConnect));
|
|
230
|
+
BaseTrezorTransport.isInitialized = false;
|
|
231
|
+
BaseTrezorTransport.initPromise = null;
|
|
232
|
+
}
|
|
233
|
+
}
|
|
202
234
|
};
|
|
235
|
+
_defineProperty(BaseTrezorTransport, "isInitialized", false);
|
|
236
|
+
_defineProperty(BaseTrezorTransport, "initPromise", null);
|
|
203
237
|
|
|
204
238
|
//#endregion
|
|
205
239
|
//#region src/strategy/Eip1193Provider.ts
|
|
@@ -427,7 +461,9 @@ var TrezorBase = class extends __injectivelabs_wallet_base.BaseConcreteStrategy
|
|
|
427
461
|
await this.trezor.connect();
|
|
428
462
|
return (await (await this.trezor.getAccountManager()).getWallets(baseDerivationPath, derivationPathType)).map((k) => k.address);
|
|
429
463
|
} catch (e) {
|
|
430
|
-
|
|
464
|
+
const errorMessage = e.message || "Unknown error";
|
|
465
|
+
const message = errorMessage.includes("Initialize") || errorMessage.includes("Handshake") || errorMessage.includes("Init_") ? `Trezor connection failed: ${errorMessage}. Please ensure your Trezor device is connected, unlocked, and that pop-ups are allowed for this site.` : errorMessage;
|
|
466
|
+
throw new __injectivelabs_exceptions.TrezorException(new Error(message), {
|
|
431
467
|
code: __injectivelabs_exceptions.UnspecifiedErrorCode,
|
|
432
468
|
type: __injectivelabs_exceptions.ErrorType.WalletError,
|
|
433
469
|
contextModule: __injectivelabs_wallet_base.WalletAction.GetAccounts
|
|
@@ -444,7 +480,9 @@ var TrezorBase = class extends __injectivelabs_wallet_base.BaseConcreteStrategy
|
|
|
444
480
|
baseDerivationPath: derivationPathType
|
|
445
481
|
}));
|
|
446
482
|
} catch (e) {
|
|
447
|
-
|
|
483
|
+
const errorMessage = e.message || "Unknown error";
|
|
484
|
+
const message = errorMessage.includes("Initialize") || errorMessage.includes("Handshake") || errorMessage.includes("Init_") ? `Trezor connection failed: ${errorMessage}. Please ensure your Trezor device is connected, unlocked, and that pop-ups are allowed for this site.` : errorMessage;
|
|
485
|
+
throw new __injectivelabs_exceptions.TrezorException(new Error(message), {
|
|
448
486
|
code: __injectivelabs_exceptions.UnspecifiedErrorCode,
|
|
449
487
|
type: __injectivelabs_exceptions.ErrorType.WalletError,
|
|
450
488
|
contextModule: __injectivelabs_wallet_base.WalletAction.GetAccounts
|
package/dist/esm/index.js
CHANGED
|
@@ -13,10 +13,14 @@ const TrezorDerivationPathType = {
|
|
|
13
13
|
|
|
14
14
|
//#endregion
|
|
15
15
|
//#region src/strategy/lib.ts
|
|
16
|
+
let cachedTrezorConnect = null;
|
|
16
17
|
async function loadTrezorConnect() {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
18
|
+
if (!cachedTrezorConnect) {
|
|
19
|
+
var _default;
|
|
20
|
+
const module = await import("@trezor/connect-web");
|
|
21
|
+
cachedTrezorConnect = (module === null || module === void 0 || (_default = module.default) === null || _default === void 0 ? void 0 : _default.default) || module.default;
|
|
22
|
+
}
|
|
23
|
+
return cachedTrezorConnect;
|
|
20
24
|
}
|
|
21
25
|
|
|
22
26
|
//#endregion
|
|
@@ -182,24 +186,54 @@ const TREZOR_CONNECT_MANIFEST = {
|
|
|
182
186
|
appUrl: "https://injectivelabs.org",
|
|
183
187
|
appName: "Injective Labs"
|
|
184
188
|
};
|
|
185
|
-
var BaseTrezorTransport = class {
|
|
189
|
+
var BaseTrezorTransport = class BaseTrezorTransport {
|
|
186
190
|
constructor() {
|
|
187
191
|
_defineProperty(this, "accountManager", null);
|
|
188
192
|
}
|
|
189
193
|
async connect() {
|
|
194
|
+
if (BaseTrezorTransport.initPromise) return BaseTrezorTransport.initPromise;
|
|
195
|
+
if (BaseTrezorTransport.isInitialized) return Promise.resolve();
|
|
196
|
+
BaseTrezorTransport.initPromise = this.initializeTrezorConnect();
|
|
197
|
+
try {
|
|
198
|
+
await BaseTrezorTransport.initPromise;
|
|
199
|
+
BaseTrezorTransport.isInitialized = true;
|
|
200
|
+
} finally {
|
|
201
|
+
BaseTrezorTransport.initPromise = null;
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
async initializeTrezorConnect() {
|
|
190
205
|
const TrezorConnect = await loadTrezorConnect();
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
206
|
+
try {
|
|
207
|
+
await TrezorConnect.init({
|
|
208
|
+
manifest: TREZOR_CONNECT_MANIFEST,
|
|
209
|
+
coreMode: "popup",
|
|
210
|
+
interactionTimeout: 600
|
|
211
|
+
});
|
|
212
|
+
} catch (error) {
|
|
213
|
+
BaseTrezorTransport.isInitialized = false;
|
|
214
|
+
throw error;
|
|
215
|
+
}
|
|
197
216
|
}
|
|
198
217
|
async getAccountManager() {
|
|
199
218
|
if (!this.accountManager) this.accountManager = new AccountManager();
|
|
200
219
|
return this.accountManager;
|
|
201
220
|
}
|
|
221
|
+
/**
|
|
222
|
+
* Resets the initialization state. Call this if you need to reinitialize
|
|
223
|
+
* TrezorConnect (e.g., after a connection error or when switching contexts).
|
|
224
|
+
*/
|
|
225
|
+
static async reset() {
|
|
226
|
+
if (BaseTrezorTransport.isInitialized) {
|
|
227
|
+
var _TrezorConnect$dispos;
|
|
228
|
+
const TrezorConnect = await loadTrezorConnect();
|
|
229
|
+
await ((_TrezorConnect$dispos = TrezorConnect.dispose) === null || _TrezorConnect$dispos === void 0 ? void 0 : _TrezorConnect$dispos.call(TrezorConnect));
|
|
230
|
+
BaseTrezorTransport.isInitialized = false;
|
|
231
|
+
BaseTrezorTransport.initPromise = null;
|
|
232
|
+
}
|
|
233
|
+
}
|
|
202
234
|
};
|
|
235
|
+
_defineProperty(BaseTrezorTransport, "isInitialized", false);
|
|
236
|
+
_defineProperty(BaseTrezorTransport, "initPromise", null);
|
|
203
237
|
|
|
204
238
|
//#endregion
|
|
205
239
|
//#region src/strategy/Eip1193Provider.ts
|
|
@@ -427,7 +461,9 @@ var TrezorBase = class extends BaseConcreteStrategy {
|
|
|
427
461
|
await this.trezor.connect();
|
|
428
462
|
return (await (await this.trezor.getAccountManager()).getWallets(baseDerivationPath, derivationPathType)).map((k) => k.address);
|
|
429
463
|
} catch (e) {
|
|
430
|
-
|
|
464
|
+
const errorMessage = e.message || "Unknown error";
|
|
465
|
+
const message = errorMessage.includes("Initialize") || errorMessage.includes("Handshake") || errorMessage.includes("Init_") ? `Trezor connection failed: ${errorMessage}. Please ensure your Trezor device is connected, unlocked, and that pop-ups are allowed for this site.` : errorMessage;
|
|
466
|
+
throw new TrezorException(new Error(message), {
|
|
431
467
|
code: UnspecifiedErrorCode,
|
|
432
468
|
type: ErrorType.WalletError,
|
|
433
469
|
contextModule: WalletAction.GetAccounts
|
|
@@ -444,7 +480,9 @@ var TrezorBase = class extends BaseConcreteStrategy {
|
|
|
444
480
|
baseDerivationPath: derivationPathType
|
|
445
481
|
}));
|
|
446
482
|
} catch (e) {
|
|
447
|
-
|
|
483
|
+
const errorMessage = e.message || "Unknown error";
|
|
484
|
+
const message = errorMessage.includes("Initialize") || errorMessage.includes("Handshake") || errorMessage.includes("Init_") ? `Trezor connection failed: ${errorMessage}. Please ensure your Trezor device is connected, unlocked, and that pop-ups are allowed for this site.` : errorMessage;
|
|
485
|
+
throw new TrezorException(new Error(message), {
|
|
448
486
|
code: UnspecifiedErrorCode,
|
|
449
487
|
type: ErrorType.WalletError,
|
|
450
488
|
contextModule: WalletAction.GetAccounts
|
package/package.json
CHANGED
|
@@ -1,12 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@injectivelabs/wallet-trezor",
|
|
3
|
-
"version": "1.17.2-alpha.
|
|
3
|
+
"version": "1.17.2-alpha.10",
|
|
4
4
|
"description": "Trezor wallet strategy for use with @injectivelabs/wallet-core.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"author": {
|
|
7
7
|
"name": "InjectiveLabs",
|
|
8
8
|
"email": "admin@injectivelabs.org"
|
|
9
9
|
},
|
|
10
|
+
"repository": {
|
|
11
|
+
"type": "git",
|
|
12
|
+
"url": "https://github.com/InjectiveLabs/injective-ts"
|
|
13
|
+
},
|
|
10
14
|
"type": "module",
|
|
11
15
|
"sideEffects": false,
|
|
12
16
|
"exports": {
|
|
@@ -41,10 +45,10 @@
|
|
|
41
45
|
"@trezor/connect": "^9.6.4",
|
|
42
46
|
"@trezor/connect-web": "^9.6.4",
|
|
43
47
|
"viem": "^2.41.2",
|
|
44
|
-
"@injectivelabs/
|
|
45
|
-
"@injectivelabs/
|
|
46
|
-
"@injectivelabs/ts-types": "1.17.2-alpha.
|
|
47
|
-
"@injectivelabs/
|
|
48
|
+
"@injectivelabs/exceptions": "1.17.2-alpha.10",
|
|
49
|
+
"@injectivelabs/sdk-ts": "1.17.2-alpha.10",
|
|
50
|
+
"@injectivelabs/ts-types": "1.17.2-alpha.10",
|
|
51
|
+
"@injectivelabs/wallet-base": "1.17.2-alpha.10"
|
|
48
52
|
},
|
|
49
53
|
"publishConfig": {
|
|
50
54
|
"access": "public"
|