@injectivelabs/wallet-turnkey 1.20.65 → 1.20.67
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 +5 -200
- package/dist/esm/index.js +6 -201
- package/package.json +6 -6
package/dist/cjs/index.cjs
CHANGED
|
@@ -478,186 +478,6 @@ async function createTurnkeyClient(metadata) {
|
|
|
478
478
|
};
|
|
479
479
|
}
|
|
480
480
|
|
|
481
|
-
//#endregion
|
|
482
|
-
//#region src/strategy/Eip1193Provider.ts
|
|
483
|
-
const signTypedDataMethods = new Set([
|
|
484
|
-
"eth_signTypedData",
|
|
485
|
-
"eth_signTypedData_v3",
|
|
486
|
-
"eth_signTypedData_v4"
|
|
487
|
-
]);
|
|
488
|
-
const signMessageMethods = new Set([
|
|
489
|
-
"eth_sign",
|
|
490
|
-
"personal_sign",
|
|
491
|
-
"eth_signMessage"
|
|
492
|
-
]);
|
|
493
|
-
const sendTransactionMethods = new Set(["eth_sendTransaction", "wallet_sendTransaction"]);
|
|
494
|
-
const parseChainId = (chainId) => {
|
|
495
|
-
if (typeof chainId === "number") return chainId;
|
|
496
|
-
if (chainId.startsWith("0x")) return parseInt(chainId.replace("0x", ""), 16);
|
|
497
|
-
return parseInt(chainId, 10);
|
|
498
|
-
};
|
|
499
|
-
const isEthAddress = (value) => typeof value === "string" && /^0x[a-fA-F0-9]{40}$/.test(value);
|
|
500
|
-
const getTypedDataParam = (method, params) => {
|
|
501
|
-
if (!(params === null || params === void 0 ? void 0 : params.length)) throw new Error("params is required");
|
|
502
|
-
const typedData = isEthAddress(params[0]) ? params[1] : params[0];
|
|
503
|
-
if (typedData == null || typeof typedData === "string" && typedData.length === 0 || typeof typedData !== "string" && typeof typedData !== "object") throw new Error(`Missing typed data parameter for ${method}`);
|
|
504
|
-
const parsedTypedData = (() => {
|
|
505
|
-
if (typeof typedData !== "string") return typedData;
|
|
506
|
-
try {
|
|
507
|
-
return JSON.parse(typedData);
|
|
508
|
-
} catch (_unused) {
|
|
509
|
-
throw new Error(`Invalid typed data parameter for ${method}`);
|
|
510
|
-
}
|
|
511
|
-
})();
|
|
512
|
-
if (!parsedTypedData || typeof parsedTypedData !== "object" || Array.isArray(parsedTypedData) || !parsedTypedData.domain || !parsedTypedData.types || typeof parsedTypedData.primaryType !== "string" || !("message" in parsedTypedData)) throw new Error(`Invalid typed data parameter for ${method}`);
|
|
513
|
-
return parsedTypedData;
|
|
514
|
-
};
|
|
515
|
-
const getMessageParam = (method, params) => {
|
|
516
|
-
if (!(params === null || params === void 0 ? void 0 : params.length)) throw new Error("params is required");
|
|
517
|
-
let message = params[0];
|
|
518
|
-
if (method === "eth_sign") message = params[1];
|
|
519
|
-
if (method === "personal_sign" && isEthAddress(params[0])) message = params[1];
|
|
520
|
-
if (!(message instanceof Uint8Array) && (typeof message !== "string" || message.length === 0) && !(message && typeof message === "object" && "message" in message)) throw new Error(`Missing message parameter for ${method}`);
|
|
521
|
-
return message;
|
|
522
|
-
};
|
|
523
|
-
const getSignableMessage = (message) => {
|
|
524
|
-
if (message && typeof message === "object" && "message" in message) return message;
|
|
525
|
-
if (message instanceof Uint8Array || typeof message === "string" && message.startsWith("0x")) return { message: { raw: message } };
|
|
526
|
-
return { message };
|
|
527
|
-
};
|
|
528
|
-
const getEip1193ProviderForTurnkey = async (account, chainId, params = {}) => {
|
|
529
|
-
var _account$sign;
|
|
530
|
-
return new CustomEip1193Provider({
|
|
531
|
-
chainId: parseChainId(chainId),
|
|
532
|
-
sign: (_account$sign = account.sign) === null || _account$sign === void 0 ? void 0 : _account$sign.bind(account),
|
|
533
|
-
signTypedData: account.signTypedData.bind(account),
|
|
534
|
-
signMessage: account.signMessage.bind(account),
|
|
535
|
-
signTransaction: account.signTransaction.bind(account),
|
|
536
|
-
rpcUrl: params.rpcUrl,
|
|
537
|
-
rpcUrls: params.rpcUrls,
|
|
538
|
-
account,
|
|
539
|
-
address: account.address
|
|
540
|
-
});
|
|
541
|
-
};
|
|
542
|
-
var CustomEip1193Provider = class {
|
|
543
|
-
constructor(args) {
|
|
544
|
-
var _args$chainId;
|
|
545
|
-
_defineProperty(this, "chainId", void 0);
|
|
546
|
-
_defineProperty(this, "sign", void 0);
|
|
547
|
-
_defineProperty(this, "signTypedData", void 0);
|
|
548
|
-
_defineProperty(this, "signMessage", void 0);
|
|
549
|
-
_defineProperty(this, "signTransaction", void 0);
|
|
550
|
-
_defineProperty(this, "rpcUrl", void 0);
|
|
551
|
-
_defineProperty(this, "rpcUrls", void 0);
|
|
552
|
-
_defineProperty(this, "account", void 0);
|
|
553
|
-
_defineProperty(this, "address", void 0);
|
|
554
|
-
this.chainId = (_args$chainId = args.chainId) !== null && _args$chainId !== void 0 ? _args$chainId : 1;
|
|
555
|
-
this.sign = args.sign;
|
|
556
|
-
this.signTypedData = args.signTypedData;
|
|
557
|
-
this.signMessage = args.signMessage;
|
|
558
|
-
this.account = args.account;
|
|
559
|
-
this.address = args.address;
|
|
560
|
-
this.rpcUrl = args.rpcUrl;
|
|
561
|
-
this.rpcUrls = args.rpcUrls;
|
|
562
|
-
this.signTransaction = args.signTransaction;
|
|
563
|
-
}
|
|
564
|
-
getRpcUrl() {
|
|
565
|
-
var _this$rpcUrls;
|
|
566
|
-
return ((_this$rpcUrls = this.rpcUrls) === null || _this$rpcUrls === void 0 ? void 0 : _this$rpcUrls[this.chainId]) || this.rpcUrl;
|
|
567
|
-
}
|
|
568
|
-
async requestAccounts() {
|
|
569
|
-
return [this.address];
|
|
570
|
-
}
|
|
571
|
-
getClient() {
|
|
572
|
-
return (0, __injectivelabs_wallet_base.getViemWalletClient)({
|
|
573
|
-
chainId: this.chainId,
|
|
574
|
-
account: this.account,
|
|
575
|
-
rpcUrl: this.getRpcUrl()
|
|
576
|
-
});
|
|
577
|
-
}
|
|
578
|
-
getChain() {
|
|
579
|
-
return (0, __injectivelabs_wallet_base.getEvmChainConfig)(this.chainId);
|
|
580
|
-
}
|
|
581
|
-
on(_event, _listener) {
|
|
582
|
-
throw new Error("Not implemented");
|
|
583
|
-
}
|
|
584
|
-
removeListener(..._args) {
|
|
585
|
-
throw new Error("Not implemented!");
|
|
586
|
-
}
|
|
587
|
-
async request(args) {
|
|
588
|
-
if (args.method === "eth_requestAccounts" || args.method === "eth_accounts") return this.requestAccounts();
|
|
589
|
-
if (signTypedDataMethods.has(args.method)) {
|
|
590
|
-
const typedData = getTypedDataParam(args.method, args.params);
|
|
591
|
-
if (this.sign) {
|
|
592
|
-
const typedDataHash = (0, viem.hashTypedData)({
|
|
593
|
-
domain: {
|
|
594
|
-
...typedData.domain,
|
|
595
|
-
chainId: typedData.domain.chainId != null ? parseChainId(typedData.domain.chainId) : void 0
|
|
596
|
-
},
|
|
597
|
-
types: typedData.types,
|
|
598
|
-
primaryType: typedData.primaryType,
|
|
599
|
-
message: typedData.message
|
|
600
|
-
});
|
|
601
|
-
return this.sign({ hash: typedDataHash });
|
|
602
|
-
}
|
|
603
|
-
return this.signTypedData(typedData);
|
|
604
|
-
}
|
|
605
|
-
if (signMessageMethods.has(args.method)) {
|
|
606
|
-
const message = getMessageParam(args.method, args.params);
|
|
607
|
-
return this.signMessage(getSignableMessage(message));
|
|
608
|
-
}
|
|
609
|
-
if (args.method === "eth_signTransaction") {
|
|
610
|
-
if (!args.params) throw new Error("params is required");
|
|
611
|
-
return this.signTransaction(args.params[0]);
|
|
612
|
-
}
|
|
613
|
-
if (args.method === "eth_chainId") return `0x${this.chainId.toString(16)}`;
|
|
614
|
-
if (args.method === "wallet_switchEthereumChain") {
|
|
615
|
-
if (!args.params) throw new Error("params is required");
|
|
616
|
-
this.chainId = parseChainId(args.params[0].chainId);
|
|
617
|
-
return true;
|
|
618
|
-
}
|
|
619
|
-
if (sendTransactionMethods.has(args.method)) {
|
|
620
|
-
if (!args.params) throw new Error("params is required");
|
|
621
|
-
const accountClient = (0, __injectivelabs_wallet_base.getViemWalletClient)({
|
|
622
|
-
chainId: this.chainId,
|
|
623
|
-
account: this.account,
|
|
624
|
-
rpcUrl: this.getRpcUrl()
|
|
625
|
-
});
|
|
626
|
-
const client = this.getClient();
|
|
627
|
-
const parseHexValue = (value) => {
|
|
628
|
-
if (typeof value === "string") {
|
|
629
|
-
const hexValue = value.startsWith("0x") ? value : `0x${value}`;
|
|
630
|
-
return BigInt(hexValue);
|
|
631
|
-
}
|
|
632
|
-
return BigInt(value);
|
|
633
|
-
};
|
|
634
|
-
const processedTransaction = { ...args.params[0] };
|
|
635
|
-
for (const field of [
|
|
636
|
-
"value",
|
|
637
|
-
"gas",
|
|
638
|
-
"gasLimit",
|
|
639
|
-
"gasPrice",
|
|
640
|
-
"maxFeePerGas",
|
|
641
|
-
"maxPriorityFeePerGas"
|
|
642
|
-
]) if (processedTransaction[field] !== void 0) processedTransaction[field] = parseHexValue(processedTransaction[field]);
|
|
643
|
-
const preparedTransaction = await accountClient.prepareTransactionRequest(processedTransaction);
|
|
644
|
-
const signedTransaction = await this.signTransaction(preparedTransaction);
|
|
645
|
-
return await client.sendRawTransaction({ serializedTransaction: signedTransaction });
|
|
646
|
-
}
|
|
647
|
-
if (args.method === "eth_getTransactionCount") {
|
|
648
|
-
if (!args.params) throw new Error("params is required");
|
|
649
|
-
return `0x${(await (0, __injectivelabs_wallet_base.getViemPublicClient)(this.chainId, this.getRpcUrl()).getTransactionCount({
|
|
650
|
-
address: this.address,
|
|
651
|
-
blockTag: "pending"
|
|
652
|
-
})).toString(16)}`;
|
|
653
|
-
}
|
|
654
|
-
return this.getClient().request({
|
|
655
|
-
method: args.method,
|
|
656
|
-
params: args.params
|
|
657
|
-
});
|
|
658
|
-
}
|
|
659
|
-
};
|
|
660
|
-
|
|
661
481
|
//#endregion
|
|
662
482
|
//#region src/strategy/strategy.ts
|
|
663
483
|
var TurnkeyWalletStrategy = class extends __injectivelabs_wallet_base.BaseConcreteStrategy {
|
|
@@ -764,28 +584,13 @@ var TurnkeyWalletStrategy = class extends __injectivelabs_wallet_base.BaseConcre
|
|
|
764
584
|
code: __injectivelabs_exceptions.UnspecifiedErrorCode,
|
|
765
585
|
context: __injectivelabs_wallet_base.WalletAction.SendEvmTransaction
|
|
766
586
|
});
|
|
587
|
+
const account = await turnkeyWallet.getOrCreateAndGetAccount((0, viem.getAddress)(args.address));
|
|
767
588
|
const accountClient = (0, __injectivelabs_wallet_base.getViemWalletClient)({
|
|
768
589
|
chainId,
|
|
769
|
-
account
|
|
590
|
+
account,
|
|
770
591
|
rpcUrl: url
|
|
771
592
|
});
|
|
772
|
-
const
|
|
773
|
-
if (typeof value === "string") {
|
|
774
|
-
const hexValue = value.startsWith("0x") ? value : `0x${value}`;
|
|
775
|
-
return BigInt(hexValue);
|
|
776
|
-
}
|
|
777
|
-
return BigInt(value);
|
|
778
|
-
};
|
|
779
|
-
const processedTransaction = { ...transaction };
|
|
780
|
-
for (const field of [
|
|
781
|
-
"value",
|
|
782
|
-
"gas",
|
|
783
|
-
"gasLimit",
|
|
784
|
-
"gasPrice",
|
|
785
|
-
"maxFeePerGas",
|
|
786
|
-
"maxPriorityFeePerGas"
|
|
787
|
-
]) if (processedTransaction[field] !== void 0) processedTransaction[field] = parseHexValue(processedTransaction[field]);
|
|
788
|
-
const { account: _, ...transactionToSign } = await accountClient.prepareTransactionRequest(processedTransaction);
|
|
593
|
+
const { account: _, ...transactionToSign } = await accountClient.prepareTransactionRequest((0, __injectivelabs_wallet_base.toViemTransactionRequest)(transaction, account.address, chainId));
|
|
789
594
|
const signedTransaction = await accountClient.signTransaction(transactionToSign);
|
|
790
595
|
return await accountClient.sendRawTransaction({ serializedTransaction: signedTransaction });
|
|
791
596
|
} catch (e) {
|
|
@@ -844,7 +649,7 @@ var TurnkeyWalletStrategy = class extends __injectivelabs_wallet_base.BaseConcre
|
|
|
844
649
|
try {
|
|
845
650
|
const turnkeyWallet = await this.getTurnkeyWallet();
|
|
846
651
|
const checksumAddress = (0, viem.getAddress)((0, __injectivelabs_sdk_ts_utils.getEthereumAddress)(signer));
|
|
847
|
-
return await (await
|
|
652
|
+
return await (await (0, __injectivelabs_wallet_base.getEip1193ProviderForAccount)(await turnkeyWallet.getOrCreateAndGetAccount(checksumAddress), String(this.evmOptions.evmChainId), {
|
|
848
653
|
rpcUrl: this.evmOptions.rpcUrl,
|
|
849
654
|
rpcUrls: this.evmOptions.rpcUrls
|
|
850
655
|
})).request({
|
|
@@ -905,7 +710,7 @@ var TurnkeyWalletStrategy = class extends __injectivelabs_wallet_base.BaseConcre
|
|
|
905
710
|
async getEip1193Provider() {
|
|
906
711
|
const turnkeyWallet = await this.getTurnkeyWallet();
|
|
907
712
|
const checksumAddress = (0, viem.getAddress)((0, __injectivelabs_sdk_ts_utils.getEthereumAddress)((await turnkeyWallet.getAccounts())[0]));
|
|
908
|
-
return await
|
|
713
|
+
return await (0, __injectivelabs_wallet_base.getEip1193ProviderForAccount)(await turnkeyWallet.getOrCreateAndGetAccount(checksumAddress), String(this.evmOptions.evmChainId), {
|
|
909
714
|
rpcUrl: this.evmOptions.rpcUrl,
|
|
910
715
|
rpcUrls: this.evmOptions.rpcUrls
|
|
911
716
|
});
|
package/dist/esm/index.js
CHANGED
|
@@ -2,7 +2,7 @@ import { getAddress, hashTypedData } from "viem";
|
|
|
2
2
|
import { HttpRestClient } from "@injectivelabs/utils";
|
|
3
3
|
import { getEthereumAddress, getInjectiveAddress, sha256, toUtf8 } from "@injectivelabs/sdk-ts/utils";
|
|
4
4
|
import { CosmosWalletException, ErrorType, GeneralException, TurnkeyWalletSessionException, UnspecifiedErrorCode, WalletException } from "@injectivelabs/exceptions";
|
|
5
|
-
import { BaseConcreteStrategy, TurnkeyProvider, WalletAction, WalletDeviceType, broadcastTxRaw,
|
|
5
|
+
import { BaseConcreteStrategy, TurnkeyProvider, WalletAction, WalletDeviceType, broadcastTxRaw, getEip1193ProviderForAccount, getViemPublicClient, getViemWalletClient, toViemTransactionRequest } from "@injectivelabs/wallet-base";
|
|
6
6
|
import { createAccount } from "@turnkey/viem";
|
|
7
7
|
import { SessionType, Turnkey } from "@turnkey/sdk-browser";
|
|
8
8
|
|
|
@@ -478,186 +478,6 @@ async function createTurnkeyClient(metadata) {
|
|
|
478
478
|
};
|
|
479
479
|
}
|
|
480
480
|
|
|
481
|
-
//#endregion
|
|
482
|
-
//#region src/strategy/Eip1193Provider.ts
|
|
483
|
-
const signTypedDataMethods = new Set([
|
|
484
|
-
"eth_signTypedData",
|
|
485
|
-
"eth_signTypedData_v3",
|
|
486
|
-
"eth_signTypedData_v4"
|
|
487
|
-
]);
|
|
488
|
-
const signMessageMethods = new Set([
|
|
489
|
-
"eth_sign",
|
|
490
|
-
"personal_sign",
|
|
491
|
-
"eth_signMessage"
|
|
492
|
-
]);
|
|
493
|
-
const sendTransactionMethods = new Set(["eth_sendTransaction", "wallet_sendTransaction"]);
|
|
494
|
-
const parseChainId = (chainId) => {
|
|
495
|
-
if (typeof chainId === "number") return chainId;
|
|
496
|
-
if (chainId.startsWith("0x")) return parseInt(chainId.replace("0x", ""), 16);
|
|
497
|
-
return parseInt(chainId, 10);
|
|
498
|
-
};
|
|
499
|
-
const isEthAddress = (value) => typeof value === "string" && /^0x[a-fA-F0-9]{40}$/.test(value);
|
|
500
|
-
const getTypedDataParam = (method, params) => {
|
|
501
|
-
if (!(params === null || params === void 0 ? void 0 : params.length)) throw new Error("params is required");
|
|
502
|
-
const typedData = isEthAddress(params[0]) ? params[1] : params[0];
|
|
503
|
-
if (typedData == null || typeof typedData === "string" && typedData.length === 0 || typeof typedData !== "string" && typeof typedData !== "object") throw new Error(`Missing typed data parameter for ${method}`);
|
|
504
|
-
const parsedTypedData = (() => {
|
|
505
|
-
if (typeof typedData !== "string") return typedData;
|
|
506
|
-
try {
|
|
507
|
-
return JSON.parse(typedData);
|
|
508
|
-
} catch (_unused) {
|
|
509
|
-
throw new Error(`Invalid typed data parameter for ${method}`);
|
|
510
|
-
}
|
|
511
|
-
})();
|
|
512
|
-
if (!parsedTypedData || typeof parsedTypedData !== "object" || Array.isArray(parsedTypedData) || !parsedTypedData.domain || !parsedTypedData.types || typeof parsedTypedData.primaryType !== "string" || !("message" in parsedTypedData)) throw new Error(`Invalid typed data parameter for ${method}`);
|
|
513
|
-
return parsedTypedData;
|
|
514
|
-
};
|
|
515
|
-
const getMessageParam = (method, params) => {
|
|
516
|
-
if (!(params === null || params === void 0 ? void 0 : params.length)) throw new Error("params is required");
|
|
517
|
-
let message = params[0];
|
|
518
|
-
if (method === "eth_sign") message = params[1];
|
|
519
|
-
if (method === "personal_sign" && isEthAddress(params[0])) message = params[1];
|
|
520
|
-
if (!(message instanceof Uint8Array) && (typeof message !== "string" || message.length === 0) && !(message && typeof message === "object" && "message" in message)) throw new Error(`Missing message parameter for ${method}`);
|
|
521
|
-
return message;
|
|
522
|
-
};
|
|
523
|
-
const getSignableMessage = (message) => {
|
|
524
|
-
if (message && typeof message === "object" && "message" in message) return message;
|
|
525
|
-
if (message instanceof Uint8Array || typeof message === "string" && message.startsWith("0x")) return { message: { raw: message } };
|
|
526
|
-
return { message };
|
|
527
|
-
};
|
|
528
|
-
const getEip1193ProviderForTurnkey = async (account, chainId, params = {}) => {
|
|
529
|
-
var _account$sign;
|
|
530
|
-
return new CustomEip1193Provider({
|
|
531
|
-
chainId: parseChainId(chainId),
|
|
532
|
-
sign: (_account$sign = account.sign) === null || _account$sign === void 0 ? void 0 : _account$sign.bind(account),
|
|
533
|
-
signTypedData: account.signTypedData.bind(account),
|
|
534
|
-
signMessage: account.signMessage.bind(account),
|
|
535
|
-
signTransaction: account.signTransaction.bind(account),
|
|
536
|
-
rpcUrl: params.rpcUrl,
|
|
537
|
-
rpcUrls: params.rpcUrls,
|
|
538
|
-
account,
|
|
539
|
-
address: account.address
|
|
540
|
-
});
|
|
541
|
-
};
|
|
542
|
-
var CustomEip1193Provider = class {
|
|
543
|
-
constructor(args) {
|
|
544
|
-
var _args$chainId;
|
|
545
|
-
_defineProperty(this, "chainId", void 0);
|
|
546
|
-
_defineProperty(this, "sign", void 0);
|
|
547
|
-
_defineProperty(this, "signTypedData", void 0);
|
|
548
|
-
_defineProperty(this, "signMessage", void 0);
|
|
549
|
-
_defineProperty(this, "signTransaction", void 0);
|
|
550
|
-
_defineProperty(this, "rpcUrl", void 0);
|
|
551
|
-
_defineProperty(this, "rpcUrls", void 0);
|
|
552
|
-
_defineProperty(this, "account", void 0);
|
|
553
|
-
_defineProperty(this, "address", void 0);
|
|
554
|
-
this.chainId = (_args$chainId = args.chainId) !== null && _args$chainId !== void 0 ? _args$chainId : 1;
|
|
555
|
-
this.sign = args.sign;
|
|
556
|
-
this.signTypedData = args.signTypedData;
|
|
557
|
-
this.signMessage = args.signMessage;
|
|
558
|
-
this.account = args.account;
|
|
559
|
-
this.address = args.address;
|
|
560
|
-
this.rpcUrl = args.rpcUrl;
|
|
561
|
-
this.rpcUrls = args.rpcUrls;
|
|
562
|
-
this.signTransaction = args.signTransaction;
|
|
563
|
-
}
|
|
564
|
-
getRpcUrl() {
|
|
565
|
-
var _this$rpcUrls;
|
|
566
|
-
return ((_this$rpcUrls = this.rpcUrls) === null || _this$rpcUrls === void 0 ? void 0 : _this$rpcUrls[this.chainId]) || this.rpcUrl;
|
|
567
|
-
}
|
|
568
|
-
async requestAccounts() {
|
|
569
|
-
return [this.address];
|
|
570
|
-
}
|
|
571
|
-
getClient() {
|
|
572
|
-
return getViemWalletClient({
|
|
573
|
-
chainId: this.chainId,
|
|
574
|
-
account: this.account,
|
|
575
|
-
rpcUrl: this.getRpcUrl()
|
|
576
|
-
});
|
|
577
|
-
}
|
|
578
|
-
getChain() {
|
|
579
|
-
return getEvmChainConfig(this.chainId);
|
|
580
|
-
}
|
|
581
|
-
on(_event, _listener) {
|
|
582
|
-
throw new Error("Not implemented");
|
|
583
|
-
}
|
|
584
|
-
removeListener(..._args) {
|
|
585
|
-
throw new Error("Not implemented!");
|
|
586
|
-
}
|
|
587
|
-
async request(args) {
|
|
588
|
-
if (args.method === "eth_requestAccounts" || args.method === "eth_accounts") return this.requestAccounts();
|
|
589
|
-
if (signTypedDataMethods.has(args.method)) {
|
|
590
|
-
const typedData = getTypedDataParam(args.method, args.params);
|
|
591
|
-
if (this.sign) {
|
|
592
|
-
const typedDataHash = hashTypedData({
|
|
593
|
-
domain: {
|
|
594
|
-
...typedData.domain,
|
|
595
|
-
chainId: typedData.domain.chainId != null ? parseChainId(typedData.domain.chainId) : void 0
|
|
596
|
-
},
|
|
597
|
-
types: typedData.types,
|
|
598
|
-
primaryType: typedData.primaryType,
|
|
599
|
-
message: typedData.message
|
|
600
|
-
});
|
|
601
|
-
return this.sign({ hash: typedDataHash });
|
|
602
|
-
}
|
|
603
|
-
return this.signTypedData(typedData);
|
|
604
|
-
}
|
|
605
|
-
if (signMessageMethods.has(args.method)) {
|
|
606
|
-
const message = getMessageParam(args.method, args.params);
|
|
607
|
-
return this.signMessage(getSignableMessage(message));
|
|
608
|
-
}
|
|
609
|
-
if (args.method === "eth_signTransaction") {
|
|
610
|
-
if (!args.params) throw new Error("params is required");
|
|
611
|
-
return this.signTransaction(args.params[0]);
|
|
612
|
-
}
|
|
613
|
-
if (args.method === "eth_chainId") return `0x${this.chainId.toString(16)}`;
|
|
614
|
-
if (args.method === "wallet_switchEthereumChain") {
|
|
615
|
-
if (!args.params) throw new Error("params is required");
|
|
616
|
-
this.chainId = parseChainId(args.params[0].chainId);
|
|
617
|
-
return true;
|
|
618
|
-
}
|
|
619
|
-
if (sendTransactionMethods.has(args.method)) {
|
|
620
|
-
if (!args.params) throw new Error("params is required");
|
|
621
|
-
const accountClient = getViemWalletClient({
|
|
622
|
-
chainId: this.chainId,
|
|
623
|
-
account: this.account,
|
|
624
|
-
rpcUrl: this.getRpcUrl()
|
|
625
|
-
});
|
|
626
|
-
const client = this.getClient();
|
|
627
|
-
const parseHexValue = (value) => {
|
|
628
|
-
if (typeof value === "string") {
|
|
629
|
-
const hexValue = value.startsWith("0x") ? value : `0x${value}`;
|
|
630
|
-
return BigInt(hexValue);
|
|
631
|
-
}
|
|
632
|
-
return BigInt(value);
|
|
633
|
-
};
|
|
634
|
-
const processedTransaction = { ...args.params[0] };
|
|
635
|
-
for (const field of [
|
|
636
|
-
"value",
|
|
637
|
-
"gas",
|
|
638
|
-
"gasLimit",
|
|
639
|
-
"gasPrice",
|
|
640
|
-
"maxFeePerGas",
|
|
641
|
-
"maxPriorityFeePerGas"
|
|
642
|
-
]) if (processedTransaction[field] !== void 0) processedTransaction[field] = parseHexValue(processedTransaction[field]);
|
|
643
|
-
const preparedTransaction = await accountClient.prepareTransactionRequest(processedTransaction);
|
|
644
|
-
const signedTransaction = await this.signTransaction(preparedTransaction);
|
|
645
|
-
return await client.sendRawTransaction({ serializedTransaction: signedTransaction });
|
|
646
|
-
}
|
|
647
|
-
if (args.method === "eth_getTransactionCount") {
|
|
648
|
-
if (!args.params) throw new Error("params is required");
|
|
649
|
-
return `0x${(await getViemPublicClient(this.chainId, this.getRpcUrl()).getTransactionCount({
|
|
650
|
-
address: this.address,
|
|
651
|
-
blockTag: "pending"
|
|
652
|
-
})).toString(16)}`;
|
|
653
|
-
}
|
|
654
|
-
return this.getClient().request({
|
|
655
|
-
method: args.method,
|
|
656
|
-
params: args.params
|
|
657
|
-
});
|
|
658
|
-
}
|
|
659
|
-
};
|
|
660
|
-
|
|
661
481
|
//#endregion
|
|
662
482
|
//#region src/strategy/strategy.ts
|
|
663
483
|
var TurnkeyWalletStrategy = class extends BaseConcreteStrategy {
|
|
@@ -764,28 +584,13 @@ var TurnkeyWalletStrategy = class extends BaseConcreteStrategy {
|
|
|
764
584
|
code: UnspecifiedErrorCode,
|
|
765
585
|
context: WalletAction.SendEvmTransaction
|
|
766
586
|
});
|
|
587
|
+
const account = await turnkeyWallet.getOrCreateAndGetAccount(getAddress(args.address));
|
|
767
588
|
const accountClient = getViemWalletClient({
|
|
768
589
|
chainId,
|
|
769
|
-
account
|
|
590
|
+
account,
|
|
770
591
|
rpcUrl: url
|
|
771
592
|
});
|
|
772
|
-
const
|
|
773
|
-
if (typeof value === "string") {
|
|
774
|
-
const hexValue = value.startsWith("0x") ? value : `0x${value}`;
|
|
775
|
-
return BigInt(hexValue);
|
|
776
|
-
}
|
|
777
|
-
return BigInt(value);
|
|
778
|
-
};
|
|
779
|
-
const processedTransaction = { ...transaction };
|
|
780
|
-
for (const field of [
|
|
781
|
-
"value",
|
|
782
|
-
"gas",
|
|
783
|
-
"gasLimit",
|
|
784
|
-
"gasPrice",
|
|
785
|
-
"maxFeePerGas",
|
|
786
|
-
"maxPriorityFeePerGas"
|
|
787
|
-
]) if (processedTransaction[field] !== void 0) processedTransaction[field] = parseHexValue(processedTransaction[field]);
|
|
788
|
-
const { account: _, ...transactionToSign } = await accountClient.prepareTransactionRequest(processedTransaction);
|
|
593
|
+
const { account: _, ...transactionToSign } = await accountClient.prepareTransactionRequest(toViemTransactionRequest(transaction, account.address, chainId));
|
|
789
594
|
const signedTransaction = await accountClient.signTransaction(transactionToSign);
|
|
790
595
|
return await accountClient.sendRawTransaction({ serializedTransaction: signedTransaction });
|
|
791
596
|
} catch (e) {
|
|
@@ -844,7 +649,7 @@ var TurnkeyWalletStrategy = class extends BaseConcreteStrategy {
|
|
|
844
649
|
try {
|
|
845
650
|
const turnkeyWallet = await this.getTurnkeyWallet();
|
|
846
651
|
const checksumAddress = getAddress(getEthereumAddress(signer));
|
|
847
|
-
return await (await
|
|
652
|
+
return await (await getEip1193ProviderForAccount(await turnkeyWallet.getOrCreateAndGetAccount(checksumAddress), String(this.evmOptions.evmChainId), {
|
|
848
653
|
rpcUrl: this.evmOptions.rpcUrl,
|
|
849
654
|
rpcUrls: this.evmOptions.rpcUrls
|
|
850
655
|
})).request({
|
|
@@ -905,7 +710,7 @@ var TurnkeyWalletStrategy = class extends BaseConcreteStrategy {
|
|
|
905
710
|
async getEip1193Provider() {
|
|
906
711
|
const turnkeyWallet = await this.getTurnkeyWallet();
|
|
907
712
|
const checksumAddress = getAddress(getEthereumAddress((await turnkeyWallet.getAccounts())[0]));
|
|
908
|
-
return await
|
|
713
|
+
return await getEip1193ProviderForAccount(await turnkeyWallet.getOrCreateAndGetAccount(checksumAddress), String(this.evmOptions.evmChainId), {
|
|
909
714
|
rpcUrl: this.evmOptions.rpcUrl,
|
|
910
715
|
rpcUrls: this.evmOptions.rpcUrls
|
|
911
716
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@injectivelabs/wallet-turnkey",
|
|
3
|
-
"version": "1.20.
|
|
3
|
+
"version": "1.20.67",
|
|
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.16.1",
|
|
46
46
|
"@turnkey/viem": "0.13.1",
|
|
47
47
|
"viem": "^2.54.6",
|
|
48
|
-
"@injectivelabs/exceptions": "1.20.
|
|
49
|
-
"@injectivelabs/
|
|
50
|
-
"@injectivelabs/
|
|
51
|
-
"@injectivelabs/utils": "1.20.
|
|
52
|
-
"@injectivelabs/
|
|
48
|
+
"@injectivelabs/exceptions": "1.20.67",
|
|
49
|
+
"@injectivelabs/ts-types": "1.20.67",
|
|
50
|
+
"@injectivelabs/wallet-base": "1.20.67",
|
|
51
|
+
"@injectivelabs/utils": "1.20.67",
|
|
52
|
+
"@injectivelabs/sdk-ts": "1.20.67"
|
|
53
53
|
},
|
|
54
54
|
"publishConfig": {
|
|
55
55
|
"access": "public"
|