@injectivelabs/wallet-turnkey 1.19.12 → 1.19.14
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 +30 -11
- package/dist/esm/index.js +30 -11
- package/package.json +6 -6
package/dist/cjs/index.cjs
CHANGED
|
@@ -362,12 +362,19 @@ async function createTurnkeyClient(metadata) {
|
|
|
362
362
|
|
|
363
363
|
//#endregion
|
|
364
364
|
//#region src/strategy/Eip1193Provider.ts
|
|
365
|
-
const
|
|
365
|
+
const parseChainId = (chainId) => {
|
|
366
|
+
if (typeof chainId === "number") return chainId;
|
|
367
|
+
if (chainId.startsWith("0x")) return parseInt(chainId.replace("0x", ""), 16);
|
|
368
|
+
return parseInt(chainId, 10);
|
|
369
|
+
};
|
|
370
|
+
const getEip1193ProviderForTurnkey = async (account, chainId, params = {}) => {
|
|
366
371
|
return new CustomEip1193Provider({
|
|
367
|
-
chainId:
|
|
372
|
+
chainId: parseChainId(chainId),
|
|
368
373
|
signTypedData: account.signTypedData.bind(account),
|
|
369
374
|
signMessage: account.signMessage.bind(account),
|
|
370
375
|
signTransaction: account.signTransaction.bind(account),
|
|
376
|
+
rpcUrl: params.rpcUrl,
|
|
377
|
+
rpcUrls: params.rpcUrls,
|
|
371
378
|
account,
|
|
372
379
|
address: account.address
|
|
373
380
|
});
|
|
@@ -379,6 +386,8 @@ var CustomEip1193Provider = class {
|
|
|
379
386
|
_defineProperty(this, "signTypedData", void 0);
|
|
380
387
|
_defineProperty(this, "signMessage", void 0);
|
|
381
388
|
_defineProperty(this, "signTransaction", void 0);
|
|
389
|
+
_defineProperty(this, "rpcUrl", void 0);
|
|
390
|
+
_defineProperty(this, "rpcUrls", void 0);
|
|
382
391
|
_defineProperty(this, "account", void 0);
|
|
383
392
|
_defineProperty(this, "address", void 0);
|
|
384
393
|
this.chainId = (_args$chainId = args.chainId) !== null && _args$chainId !== void 0 ? _args$chainId : 1;
|
|
@@ -386,15 +395,22 @@ var CustomEip1193Provider = class {
|
|
|
386
395
|
this.signMessage = args.signMessage;
|
|
387
396
|
this.account = args.account;
|
|
388
397
|
this.address = args.address;
|
|
398
|
+
this.rpcUrl = args.rpcUrl;
|
|
399
|
+
this.rpcUrls = args.rpcUrls;
|
|
389
400
|
this.signTransaction = args.signTransaction;
|
|
390
401
|
}
|
|
402
|
+
getRpcUrl() {
|
|
403
|
+
var _this$rpcUrls;
|
|
404
|
+
return ((_this$rpcUrls = this.rpcUrls) === null || _this$rpcUrls === void 0 ? void 0 : _this$rpcUrls[this.chainId]) || this.rpcUrl;
|
|
405
|
+
}
|
|
391
406
|
async requestAccounts() {
|
|
392
407
|
return [this.address];
|
|
393
408
|
}
|
|
394
409
|
getClient() {
|
|
395
410
|
return (0, __injectivelabs_wallet_base.getViemWalletClient)({
|
|
396
411
|
chainId: this.chainId,
|
|
397
|
-
account: this.account
|
|
412
|
+
account: this.account,
|
|
413
|
+
rpcUrl: this.getRpcUrl()
|
|
398
414
|
});
|
|
399
415
|
}
|
|
400
416
|
getChain() {
|
|
@@ -416,18 +432,18 @@ var CustomEip1193Provider = class {
|
|
|
416
432
|
if (!args.params) throw new Error("params is required");
|
|
417
433
|
return this.signMessage(args.params[0]);
|
|
418
434
|
}
|
|
419
|
-
if (args.method === "eth_chainId") return this.chainId
|
|
435
|
+
if (args.method === "eth_chainId") return `0x${this.chainId.toString(16)}`;
|
|
420
436
|
if (args.method === "wallet_switchEthereumChain") {
|
|
421
437
|
if (!args.params) throw new Error("params is required");
|
|
422
|
-
|
|
423
|
-
this.chainId = parseInt(chainId, 16);
|
|
438
|
+
this.chainId = parseChainId(args.params[0].chainId);
|
|
424
439
|
return true;
|
|
425
440
|
}
|
|
426
441
|
if (args.method === "eth_sendTransaction") {
|
|
427
442
|
if (!args.params) throw new Error("params is required");
|
|
428
443
|
const accountClient = (0, __injectivelabs_wallet_base.getViemWalletClient)({
|
|
429
444
|
chainId: this.chainId,
|
|
430
|
-
account: this.account
|
|
445
|
+
account: this.account,
|
|
446
|
+
rpcUrl: this.getRpcUrl()
|
|
431
447
|
});
|
|
432
448
|
const client = this.getClient();
|
|
433
449
|
const parseHexValue = (value) => {
|
|
@@ -452,7 +468,7 @@ var CustomEip1193Provider = class {
|
|
|
452
468
|
}
|
|
453
469
|
if (args.method === "eth_getTransactionCount") {
|
|
454
470
|
if (!args.params) throw new Error("params is required");
|
|
455
|
-
return `0x${(await (0, __injectivelabs_wallet_base.getViemPublicClient)(this.chainId).getTransactionCount({
|
|
471
|
+
return `0x${(await (0, __injectivelabs_wallet_base.getViemPublicClient)(this.chainId, this.getRpcUrl()).getTransactionCount({
|
|
456
472
|
address: this.address,
|
|
457
473
|
blockTag: "pending"
|
|
458
474
|
})).toString(16)}`;
|
|
@@ -550,7 +566,7 @@ var TurnkeyWalletStrategy = class extends __injectivelabs_wallet_base.BaseConcre
|
|
|
550
566
|
const options = this.evmOptions;
|
|
551
567
|
const turnkeyWallet = await this.getTurnkeyWallet();
|
|
552
568
|
const chainId = args.evmChainId || options.evmChainId;
|
|
553
|
-
const url =
|
|
569
|
+
const url = ((_options$rpcUrls = options.rpcUrls) === null || _options$rpcUrls === void 0 ? void 0 : _options$rpcUrls[chainId]) || options.rpcUrl;
|
|
554
570
|
if (!url) throw new __injectivelabs_exceptions.WalletException(/* @__PURE__ */ new Error("Please pass rpcUrl within the evmOptions"), {
|
|
555
571
|
code: __injectivelabs_exceptions.UnspecifiedErrorCode,
|
|
556
572
|
context: __injectivelabs_wallet_base.WalletAction.SendEvmTransaction
|
|
@@ -647,7 +663,7 @@ var TurnkeyWalletStrategy = class extends __injectivelabs_wallet_base.BaseConcre
|
|
|
647
663
|
var _options$rpcUrls2;
|
|
648
664
|
const options = this.evmOptions;
|
|
649
665
|
const chainId = evmChainId || options.evmChainId;
|
|
650
|
-
const url =
|
|
666
|
+
const url = ((_options$rpcUrls2 = options.rpcUrls) === null || _options$rpcUrls2 === void 0 ? void 0 : _options$rpcUrls2[chainId]) || options.rpcUrl;
|
|
651
667
|
if (!url) throw new __injectivelabs_exceptions.WalletException(/* @__PURE__ */ new Error("Please pass rpcUrl within the evmOptions"), {
|
|
652
668
|
code: __injectivelabs_exceptions.UnspecifiedErrorCode,
|
|
653
669
|
context: __injectivelabs_wallet_base.WalletAction.GetEvmTransactionReceipt
|
|
@@ -682,7 +698,10 @@ var TurnkeyWalletStrategy = class extends __injectivelabs_wallet_base.BaseConcre
|
|
|
682
698
|
async getEip1193Provider() {
|
|
683
699
|
const turnkeyWallet = await this.getTurnkeyWallet();
|
|
684
700
|
const checksumAddress = (0, viem.getAddress)((0, __injectivelabs_sdk_ts_utils.getEthereumAddress)((await turnkeyWallet.getAccounts())[0]));
|
|
685
|
-
return await getEip1193ProviderForTurnkey(await turnkeyWallet.getOrCreateAndGetAccount(checksumAddress), String(this.evmOptions.evmChainId)
|
|
701
|
+
return await getEip1193ProviderForTurnkey(await turnkeyWallet.getOrCreateAndGetAccount(checksumAddress), String(this.evmOptions.evmChainId), {
|
|
702
|
+
rpcUrl: this.evmOptions.rpcUrl,
|
|
703
|
+
rpcUrls: this.evmOptions.rpcUrls
|
|
704
|
+
});
|
|
686
705
|
}
|
|
687
706
|
};
|
|
688
707
|
|
package/dist/esm/index.js
CHANGED
|
@@ -362,12 +362,19 @@ async function createTurnkeyClient(metadata) {
|
|
|
362
362
|
|
|
363
363
|
//#endregion
|
|
364
364
|
//#region src/strategy/Eip1193Provider.ts
|
|
365
|
-
const
|
|
365
|
+
const parseChainId = (chainId) => {
|
|
366
|
+
if (typeof chainId === "number") return chainId;
|
|
367
|
+
if (chainId.startsWith("0x")) return parseInt(chainId.replace("0x", ""), 16);
|
|
368
|
+
return parseInt(chainId, 10);
|
|
369
|
+
};
|
|
370
|
+
const getEip1193ProviderForTurnkey = async (account, chainId, params = {}) => {
|
|
366
371
|
return new CustomEip1193Provider({
|
|
367
|
-
chainId:
|
|
372
|
+
chainId: parseChainId(chainId),
|
|
368
373
|
signTypedData: account.signTypedData.bind(account),
|
|
369
374
|
signMessage: account.signMessage.bind(account),
|
|
370
375
|
signTransaction: account.signTransaction.bind(account),
|
|
376
|
+
rpcUrl: params.rpcUrl,
|
|
377
|
+
rpcUrls: params.rpcUrls,
|
|
371
378
|
account,
|
|
372
379
|
address: account.address
|
|
373
380
|
});
|
|
@@ -379,6 +386,8 @@ var CustomEip1193Provider = class {
|
|
|
379
386
|
_defineProperty(this, "signTypedData", void 0);
|
|
380
387
|
_defineProperty(this, "signMessage", void 0);
|
|
381
388
|
_defineProperty(this, "signTransaction", void 0);
|
|
389
|
+
_defineProperty(this, "rpcUrl", void 0);
|
|
390
|
+
_defineProperty(this, "rpcUrls", void 0);
|
|
382
391
|
_defineProperty(this, "account", void 0);
|
|
383
392
|
_defineProperty(this, "address", void 0);
|
|
384
393
|
this.chainId = (_args$chainId = args.chainId) !== null && _args$chainId !== void 0 ? _args$chainId : 1;
|
|
@@ -386,15 +395,22 @@ var CustomEip1193Provider = class {
|
|
|
386
395
|
this.signMessage = args.signMessage;
|
|
387
396
|
this.account = args.account;
|
|
388
397
|
this.address = args.address;
|
|
398
|
+
this.rpcUrl = args.rpcUrl;
|
|
399
|
+
this.rpcUrls = args.rpcUrls;
|
|
389
400
|
this.signTransaction = args.signTransaction;
|
|
390
401
|
}
|
|
402
|
+
getRpcUrl() {
|
|
403
|
+
var _this$rpcUrls;
|
|
404
|
+
return ((_this$rpcUrls = this.rpcUrls) === null || _this$rpcUrls === void 0 ? void 0 : _this$rpcUrls[this.chainId]) || this.rpcUrl;
|
|
405
|
+
}
|
|
391
406
|
async requestAccounts() {
|
|
392
407
|
return [this.address];
|
|
393
408
|
}
|
|
394
409
|
getClient() {
|
|
395
410
|
return getViemWalletClient({
|
|
396
411
|
chainId: this.chainId,
|
|
397
|
-
account: this.account
|
|
412
|
+
account: this.account,
|
|
413
|
+
rpcUrl: this.getRpcUrl()
|
|
398
414
|
});
|
|
399
415
|
}
|
|
400
416
|
getChain() {
|
|
@@ -416,18 +432,18 @@ var CustomEip1193Provider = class {
|
|
|
416
432
|
if (!args.params) throw new Error("params is required");
|
|
417
433
|
return this.signMessage(args.params[0]);
|
|
418
434
|
}
|
|
419
|
-
if (args.method === "eth_chainId") return this.chainId
|
|
435
|
+
if (args.method === "eth_chainId") return `0x${this.chainId.toString(16)}`;
|
|
420
436
|
if (args.method === "wallet_switchEthereumChain") {
|
|
421
437
|
if (!args.params) throw new Error("params is required");
|
|
422
|
-
|
|
423
|
-
this.chainId = parseInt(chainId, 16);
|
|
438
|
+
this.chainId = parseChainId(args.params[0].chainId);
|
|
424
439
|
return true;
|
|
425
440
|
}
|
|
426
441
|
if (args.method === "eth_sendTransaction") {
|
|
427
442
|
if (!args.params) throw new Error("params is required");
|
|
428
443
|
const accountClient = getViemWalletClient({
|
|
429
444
|
chainId: this.chainId,
|
|
430
|
-
account: this.account
|
|
445
|
+
account: this.account,
|
|
446
|
+
rpcUrl: this.getRpcUrl()
|
|
431
447
|
});
|
|
432
448
|
const client = this.getClient();
|
|
433
449
|
const parseHexValue = (value) => {
|
|
@@ -452,7 +468,7 @@ var CustomEip1193Provider = class {
|
|
|
452
468
|
}
|
|
453
469
|
if (args.method === "eth_getTransactionCount") {
|
|
454
470
|
if (!args.params) throw new Error("params is required");
|
|
455
|
-
return `0x${(await getViemPublicClient(this.chainId).getTransactionCount({
|
|
471
|
+
return `0x${(await getViemPublicClient(this.chainId, this.getRpcUrl()).getTransactionCount({
|
|
456
472
|
address: this.address,
|
|
457
473
|
blockTag: "pending"
|
|
458
474
|
})).toString(16)}`;
|
|
@@ -550,7 +566,7 @@ var TurnkeyWalletStrategy = class extends BaseConcreteStrategy {
|
|
|
550
566
|
const options = this.evmOptions;
|
|
551
567
|
const turnkeyWallet = await this.getTurnkeyWallet();
|
|
552
568
|
const chainId = args.evmChainId || options.evmChainId;
|
|
553
|
-
const url =
|
|
569
|
+
const url = ((_options$rpcUrls = options.rpcUrls) === null || _options$rpcUrls === void 0 ? void 0 : _options$rpcUrls[chainId]) || options.rpcUrl;
|
|
554
570
|
if (!url) throw new WalletException(/* @__PURE__ */ new Error("Please pass rpcUrl within the evmOptions"), {
|
|
555
571
|
code: UnspecifiedErrorCode,
|
|
556
572
|
context: WalletAction.SendEvmTransaction
|
|
@@ -647,7 +663,7 @@ var TurnkeyWalletStrategy = class extends BaseConcreteStrategy {
|
|
|
647
663
|
var _options$rpcUrls2;
|
|
648
664
|
const options = this.evmOptions;
|
|
649
665
|
const chainId = evmChainId || options.evmChainId;
|
|
650
|
-
const url =
|
|
666
|
+
const url = ((_options$rpcUrls2 = options.rpcUrls) === null || _options$rpcUrls2 === void 0 ? void 0 : _options$rpcUrls2[chainId]) || options.rpcUrl;
|
|
651
667
|
if (!url) throw new WalletException(/* @__PURE__ */ new Error("Please pass rpcUrl within the evmOptions"), {
|
|
652
668
|
code: UnspecifiedErrorCode,
|
|
653
669
|
context: WalletAction.GetEvmTransactionReceipt
|
|
@@ -682,7 +698,10 @@ var TurnkeyWalletStrategy = class extends BaseConcreteStrategy {
|
|
|
682
698
|
async getEip1193Provider() {
|
|
683
699
|
const turnkeyWallet = await this.getTurnkeyWallet();
|
|
684
700
|
const checksumAddress = getAddress(getEthereumAddress((await turnkeyWallet.getAccounts())[0]));
|
|
685
|
-
return await getEip1193ProviderForTurnkey(await turnkeyWallet.getOrCreateAndGetAccount(checksumAddress), String(this.evmOptions.evmChainId)
|
|
701
|
+
return await getEip1193ProviderForTurnkey(await turnkeyWallet.getOrCreateAndGetAccount(checksumAddress), String(this.evmOptions.evmChainId), {
|
|
702
|
+
rpcUrl: this.evmOptions.rpcUrl,
|
|
703
|
+
rpcUrls: this.evmOptions.rpcUrls
|
|
704
|
+
});
|
|
686
705
|
}
|
|
687
706
|
};
|
|
688
707
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@injectivelabs/wallet-turnkey",
|
|
3
|
-
"version": "1.19.
|
|
3
|
+
"version": "1.19.14",
|
|
4
4
|
"description": "Turnkey wallet strategy for use with @injectivelabs/wallet-core.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"author": {
|
|
@@ -45,11 +45,11 @@
|
|
|
45
45
|
"@turnkey/sdk-browser": "5.2.3",
|
|
46
46
|
"@turnkey/viem": "0.9.10",
|
|
47
47
|
"viem": "^2.41.2",
|
|
48
|
-
"@injectivelabs/
|
|
49
|
-
"@injectivelabs/
|
|
50
|
-
"@injectivelabs/
|
|
51
|
-
"@injectivelabs/
|
|
52
|
-
"@injectivelabs/
|
|
48
|
+
"@injectivelabs/exceptions": "1.19.14",
|
|
49
|
+
"@injectivelabs/sdk-ts": "1.19.14",
|
|
50
|
+
"@injectivelabs/utils": "1.19.14",
|
|
51
|
+
"@injectivelabs/wallet-base": "1.19.14",
|
|
52
|
+
"@injectivelabs/ts-types": "1.19.14"
|
|
53
53
|
},
|
|
54
54
|
"publishConfig": {
|
|
55
55
|
"access": "public"
|