@injectivelabs/wallet-turnkey 1.20.65-alpha.0 → 1.20.66

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