@phantom/react-native-sdk 1.0.0-beta.1 → 1.0.0-beta.2

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/README.md CHANGED
@@ -247,6 +247,9 @@ const solana = useSolana();
247
247
  // Sign a message
248
248
  const signature = await solana.signMessage("Hello Solana!");
249
249
 
250
+ // Sign a transaction (without sending)
251
+ const signedTx = await solana.signTransaction(transaction);
252
+
250
253
  // Sign and send a transaction
251
254
  const result = await solana.signAndSendTransaction(transaction);
252
255
  ```
@@ -264,7 +267,10 @@ const accounts = await ethereum.getAccounts();
264
267
  // Sign a personal message
265
268
  const signature = await ethereum.signPersonalMessage("Hello Ethereum!", accounts[0]);
266
269
 
267
- // Send a transaction
270
+ // Sign a transaction (without sending)
271
+ const signedTx = await ethereum.signTransaction(transactionData);
272
+
273
+ // Sign and send a transaction
268
274
  const result = await ethereum.sendTransaction(transactionData);
269
275
 
270
276
  // Get current chain ID
package/dist/index.d.ts CHANGED
@@ -101,6 +101,7 @@ declare function useEthereum(): {
101
101
  }) => Promise<T>;
102
102
  signPersonalMessage: (message: string, address: string) => Promise<string>;
103
103
  signMessage: (message: string) => Promise<string>;
104
+ signTransaction: (transaction: EthTransactionRequest) => Promise<string>;
104
105
  signTypedData: (typedData: any) => Promise<string>;
105
106
  sendTransaction: (transaction: EthTransactionRequest) => Promise<string>;
106
107
  switchChain: (chainId: number) => Promise<void>;
package/dist/index.js CHANGED
@@ -631,6 +631,13 @@ function useAccounts() {
631
631
  var import_react4 = require("react");
632
632
  function useSolana() {
633
633
  const { sdk, isConnected } = usePhantom();
634
+ const getSolanaChain = (0, import_react4.useCallback)(() => {
635
+ if (!sdk)
636
+ throw new Error("Phantom SDK not initialized.");
637
+ if (!sdk.isConnected())
638
+ throw new Error("Phantom SDK not connected. Call connect() first.");
639
+ return sdk.solana;
640
+ }, [sdk]);
634
641
  const solanaChain = (0, import_react4.useMemo)(() => {
635
642
  if (!sdk || !isConnected)
636
643
  return null;
@@ -642,54 +649,48 @@ function useSolana() {
642
649
  }, [sdk, isConnected]);
643
650
  const signMessage = (0, import_react4.useCallback)(
644
651
  async (message) => {
645
- if (!solanaChain)
646
- throw new Error("Solana chain not available. Ensure SDK is connected.");
647
- return await solanaChain.signMessage(message);
652
+ const chain = getSolanaChain();
653
+ return await chain.signMessage(message);
648
654
  },
649
- [solanaChain]
655
+ [getSolanaChain]
650
656
  );
651
657
  const signTransaction = (0, import_react4.useCallback)(
652
658
  async (transaction) => {
653
- if (!solanaChain)
654
- throw new Error("Solana chain not available. Ensure SDK is connected.");
655
- return await solanaChain.signTransaction(transaction);
659
+ const chain = getSolanaChain();
660
+ return await chain.signTransaction(transaction);
656
661
  },
657
- [solanaChain]
662
+ [getSolanaChain]
658
663
  );
659
664
  const signAndSendTransaction = (0, import_react4.useCallback)(
660
665
  async (transaction) => {
661
- if (!solanaChain)
662
- throw new Error("Solana chain not available. Ensure SDK is connected.");
663
- return await solanaChain.signAndSendTransaction(transaction);
666
+ const chain = getSolanaChain();
667
+ return await chain.signAndSendTransaction(transaction);
664
668
  },
665
- [solanaChain]
669
+ [getSolanaChain]
666
670
  );
667
671
  const connect = (0, import_react4.useCallback)(
668
672
  async (options) => {
669
- if (!solanaChain)
670
- throw new Error("Solana chain not available. Ensure SDK is connected.");
671
- return await solanaChain.connect(options);
673
+ const chain = getSolanaChain();
674
+ return await chain.connect(options);
672
675
  },
673
- [solanaChain]
676
+ [getSolanaChain]
674
677
  );
675
678
  const disconnect = (0, import_react4.useCallback)(async () => {
676
- if (!solanaChain)
677
- throw new Error("Solana chain not available. Ensure SDK is connected.");
678
- return await solanaChain.disconnect();
679
- }, [solanaChain]);
679
+ const chain = getSolanaChain();
680
+ return await chain.disconnect();
681
+ }, [getSolanaChain]);
680
682
  const switchNetwork = (0, import_react4.useCallback)(
681
683
  async (network) => {
682
- if (!solanaChain)
683
- throw new Error("Solana chain not available. Ensure SDK is connected.");
684
- return await solanaChain.switchNetwork?.(network);
684
+ const chain = getSolanaChain();
685
+ return await chain.switchNetwork?.(network);
685
686
  },
686
- [solanaChain]
687
+ [getSolanaChain]
687
688
  );
688
689
  const getPublicKey = (0, import_react4.useCallback)(async () => {
689
- if (!solanaChain)
690
+ if (!sdk || !sdk.isConnected())
690
691
  return null;
691
- return await solanaChain.getPublicKey();
692
- }, [solanaChain]);
692
+ return await sdk.solana.getPublicKey();
693
+ }, [sdk]);
693
694
  return {
694
695
  // Chain instance for advanced usage
695
696
  solana: solanaChain,
@@ -711,6 +712,13 @@ function useSolana() {
711
712
  var import_react5 = require("react");
712
713
  function useEthereum() {
713
714
  const { sdk, isConnected } = usePhantom();
715
+ const getEthereumChain = (0, import_react5.useCallback)(() => {
716
+ if (!sdk)
717
+ throw new Error("Phantom SDK not initialized.");
718
+ if (!sdk.isConnected())
719
+ throw new Error("Phantom SDK not connected. Call connect() first.");
720
+ return sdk.ethereum;
721
+ }, [sdk]);
714
722
  const ethereumChain = (0, import_react5.useMemo)(() => {
715
723
  if (!sdk || !isConnected)
716
724
  return null;
@@ -722,46 +730,47 @@ function useEthereum() {
722
730
  }, [sdk, isConnected]);
723
731
  const request = (0, import_react5.useCallback)(
724
732
  async (args) => {
725
- if (!ethereumChain)
726
- throw new Error("Ethereum chain not available. Ensure SDK is connected.");
727
- return await ethereumChain.request(args);
733
+ const chain = getEthereumChain();
734
+ return await chain.request(args);
728
735
  },
729
- [ethereumChain]
736
+ [getEthereumChain]
730
737
  );
731
738
  const signPersonalMessage = (0, import_react5.useCallback)(
732
739
  async (message, address) => {
733
- if (!ethereumChain)
734
- throw new Error("Ethereum chain not available. Ensure SDK is connected.");
735
- return await ethereumChain.signPersonalMessage(message, address);
740
+ const chain = getEthereumChain();
741
+ return await chain.signPersonalMessage(message, address);
736
742
  },
737
- [ethereumChain]
743
+ [getEthereumChain]
744
+ );
745
+ const signTransaction = (0, import_react5.useCallback)(
746
+ async (transaction) => {
747
+ const chain = getEthereumChain();
748
+ return await chain.signTransaction(transaction);
749
+ },
750
+ [getEthereumChain]
738
751
  );
739
752
  const sendTransaction = (0, import_react5.useCallback)(
740
753
  async (transaction) => {
741
- if (!ethereumChain)
742
- throw new Error("Ethereum chain not available. Ensure SDK is connected.");
743
- return await ethereumChain.sendTransaction(transaction);
754
+ const chain = getEthereumChain();
755
+ return await chain.sendTransaction(transaction);
744
756
  },
745
- [ethereumChain]
757
+ [getEthereumChain]
746
758
  );
747
759
  const switchChain = (0, import_react5.useCallback)(
748
760
  async (chainId) => {
749
- if (!ethereumChain)
750
- throw new Error("Ethereum chain not available. Ensure SDK is connected.");
751
- return await ethereumChain.switchChain(chainId);
761
+ const chain = getEthereumChain();
762
+ return await chain.switchChain(chainId);
752
763
  },
753
- [ethereumChain]
764
+ [getEthereumChain]
754
765
  );
755
766
  const getChainId = (0, import_react5.useCallback)(async () => {
756
- if (!ethereumChain)
757
- throw new Error("Ethereum chain not available. Ensure SDK is connected.");
758
- return await ethereumChain.getChainId();
759
- }, [ethereumChain]);
767
+ const chain = getEthereumChain();
768
+ return await chain.getChainId();
769
+ }, [getEthereumChain]);
760
770
  const getAccounts = (0, import_react5.useCallback)(async () => {
761
- if (!ethereumChain)
762
- throw new Error("Ethereum chain not available. Ensure SDK is connected.");
763
- return await ethereumChain.getAccounts();
764
- }, [ethereumChain]);
771
+ const chain = getEthereumChain();
772
+ return await chain.getAccounts();
773
+ }, [getEthereumChain]);
765
774
  const signMessage = (0, import_react5.useCallback)(
766
775
  async (message) => {
767
776
  const accounts = await getAccounts();
@@ -774,12 +783,11 @@ function useEthereum() {
774
783
  );
775
784
  const signTypedData = (0, import_react5.useCallback)(
776
785
  async (typedData) => {
777
- if (!ethereumChain)
778
- throw new Error("Ethereum chain not available. Ensure SDK is connected.");
786
+ const chain = getEthereumChain();
779
787
  const accounts = await getAccounts();
780
- return await ethereumChain.signTypedData(typedData, accounts[0]);
788
+ return await chain.signTypedData(typedData, accounts[0]);
781
789
  },
782
- [ethereumChain, getAccounts]
790
+ [getEthereumChain, getAccounts]
783
791
  );
784
792
  return {
785
793
  // Chain instance for advanced usage
@@ -789,6 +797,7 @@ function useEthereum() {
789
797
  // Convenient methods
790
798
  signPersonalMessage,
791
799
  signMessage,
800
+ signTransaction,
792
801
  signTypedData,
793
802
  sendTransaction,
794
803
  switchChain,
package/dist/index.mjs CHANGED
@@ -587,6 +587,13 @@ function useAccounts() {
587
587
  import { useCallback as useCallback3, useMemo as useMemo2 } from "react";
588
588
  function useSolana() {
589
589
  const { sdk, isConnected } = usePhantom();
590
+ const getSolanaChain = useCallback3(() => {
591
+ if (!sdk)
592
+ throw new Error("Phantom SDK not initialized.");
593
+ if (!sdk.isConnected())
594
+ throw new Error("Phantom SDK not connected. Call connect() first.");
595
+ return sdk.solana;
596
+ }, [sdk]);
590
597
  const solanaChain = useMemo2(() => {
591
598
  if (!sdk || !isConnected)
592
599
  return null;
@@ -598,54 +605,48 @@ function useSolana() {
598
605
  }, [sdk, isConnected]);
599
606
  const signMessage = useCallback3(
600
607
  async (message) => {
601
- if (!solanaChain)
602
- throw new Error("Solana chain not available. Ensure SDK is connected.");
603
- return await solanaChain.signMessage(message);
608
+ const chain = getSolanaChain();
609
+ return await chain.signMessage(message);
604
610
  },
605
- [solanaChain]
611
+ [getSolanaChain]
606
612
  );
607
613
  const signTransaction = useCallback3(
608
614
  async (transaction) => {
609
- if (!solanaChain)
610
- throw new Error("Solana chain not available. Ensure SDK is connected.");
611
- return await solanaChain.signTransaction(transaction);
615
+ const chain = getSolanaChain();
616
+ return await chain.signTransaction(transaction);
612
617
  },
613
- [solanaChain]
618
+ [getSolanaChain]
614
619
  );
615
620
  const signAndSendTransaction = useCallback3(
616
621
  async (transaction) => {
617
- if (!solanaChain)
618
- throw new Error("Solana chain not available. Ensure SDK is connected.");
619
- return await solanaChain.signAndSendTransaction(transaction);
622
+ const chain = getSolanaChain();
623
+ return await chain.signAndSendTransaction(transaction);
620
624
  },
621
- [solanaChain]
625
+ [getSolanaChain]
622
626
  );
623
627
  const connect = useCallback3(
624
628
  async (options) => {
625
- if (!solanaChain)
626
- throw new Error("Solana chain not available. Ensure SDK is connected.");
627
- return await solanaChain.connect(options);
629
+ const chain = getSolanaChain();
630
+ return await chain.connect(options);
628
631
  },
629
- [solanaChain]
632
+ [getSolanaChain]
630
633
  );
631
634
  const disconnect = useCallback3(async () => {
632
- if (!solanaChain)
633
- throw new Error("Solana chain not available. Ensure SDK is connected.");
634
- return await solanaChain.disconnect();
635
- }, [solanaChain]);
635
+ const chain = getSolanaChain();
636
+ return await chain.disconnect();
637
+ }, [getSolanaChain]);
636
638
  const switchNetwork = useCallback3(
637
639
  async (network) => {
638
- if (!solanaChain)
639
- throw new Error("Solana chain not available. Ensure SDK is connected.");
640
- return await solanaChain.switchNetwork?.(network);
640
+ const chain = getSolanaChain();
641
+ return await chain.switchNetwork?.(network);
641
642
  },
642
- [solanaChain]
643
+ [getSolanaChain]
643
644
  );
644
645
  const getPublicKey = useCallback3(async () => {
645
- if (!solanaChain)
646
+ if (!sdk || !sdk.isConnected())
646
647
  return null;
647
- return await solanaChain.getPublicKey();
648
- }, [solanaChain]);
648
+ return await sdk.solana.getPublicKey();
649
+ }, [sdk]);
649
650
  return {
650
651
  // Chain instance for advanced usage
651
652
  solana: solanaChain,
@@ -667,6 +668,13 @@ function useSolana() {
667
668
  import { useCallback as useCallback4, useMemo as useMemo3 } from "react";
668
669
  function useEthereum() {
669
670
  const { sdk, isConnected } = usePhantom();
671
+ const getEthereumChain = useCallback4(() => {
672
+ if (!sdk)
673
+ throw new Error("Phantom SDK not initialized.");
674
+ if (!sdk.isConnected())
675
+ throw new Error("Phantom SDK not connected. Call connect() first.");
676
+ return sdk.ethereum;
677
+ }, [sdk]);
670
678
  const ethereumChain = useMemo3(() => {
671
679
  if (!sdk || !isConnected)
672
680
  return null;
@@ -678,46 +686,47 @@ function useEthereum() {
678
686
  }, [sdk, isConnected]);
679
687
  const request = useCallback4(
680
688
  async (args) => {
681
- if (!ethereumChain)
682
- throw new Error("Ethereum chain not available. Ensure SDK is connected.");
683
- return await ethereumChain.request(args);
689
+ const chain = getEthereumChain();
690
+ return await chain.request(args);
684
691
  },
685
- [ethereumChain]
692
+ [getEthereumChain]
686
693
  );
687
694
  const signPersonalMessage = useCallback4(
688
695
  async (message, address) => {
689
- if (!ethereumChain)
690
- throw new Error("Ethereum chain not available. Ensure SDK is connected.");
691
- return await ethereumChain.signPersonalMessage(message, address);
696
+ const chain = getEthereumChain();
697
+ return await chain.signPersonalMessage(message, address);
692
698
  },
693
- [ethereumChain]
699
+ [getEthereumChain]
700
+ );
701
+ const signTransaction = useCallback4(
702
+ async (transaction) => {
703
+ const chain = getEthereumChain();
704
+ return await chain.signTransaction(transaction);
705
+ },
706
+ [getEthereumChain]
694
707
  );
695
708
  const sendTransaction = useCallback4(
696
709
  async (transaction) => {
697
- if (!ethereumChain)
698
- throw new Error("Ethereum chain not available. Ensure SDK is connected.");
699
- return await ethereumChain.sendTransaction(transaction);
710
+ const chain = getEthereumChain();
711
+ return await chain.sendTransaction(transaction);
700
712
  },
701
- [ethereumChain]
713
+ [getEthereumChain]
702
714
  );
703
715
  const switchChain = useCallback4(
704
716
  async (chainId) => {
705
- if (!ethereumChain)
706
- throw new Error("Ethereum chain not available. Ensure SDK is connected.");
707
- return await ethereumChain.switchChain(chainId);
717
+ const chain = getEthereumChain();
718
+ return await chain.switchChain(chainId);
708
719
  },
709
- [ethereumChain]
720
+ [getEthereumChain]
710
721
  );
711
722
  const getChainId = useCallback4(async () => {
712
- if (!ethereumChain)
713
- throw new Error("Ethereum chain not available. Ensure SDK is connected.");
714
- return await ethereumChain.getChainId();
715
- }, [ethereumChain]);
723
+ const chain = getEthereumChain();
724
+ return await chain.getChainId();
725
+ }, [getEthereumChain]);
716
726
  const getAccounts = useCallback4(async () => {
717
- if (!ethereumChain)
718
- throw new Error("Ethereum chain not available. Ensure SDK is connected.");
719
- return await ethereumChain.getAccounts();
720
- }, [ethereumChain]);
727
+ const chain = getEthereumChain();
728
+ return await chain.getAccounts();
729
+ }, [getEthereumChain]);
721
730
  const signMessage = useCallback4(
722
731
  async (message) => {
723
732
  const accounts = await getAccounts();
@@ -730,12 +739,11 @@ function useEthereum() {
730
739
  );
731
740
  const signTypedData = useCallback4(
732
741
  async (typedData) => {
733
- if (!ethereumChain)
734
- throw new Error("Ethereum chain not available. Ensure SDK is connected.");
742
+ const chain = getEthereumChain();
735
743
  const accounts = await getAccounts();
736
- return await ethereumChain.signTypedData(typedData, accounts[0]);
744
+ return await chain.signTypedData(typedData, accounts[0]);
737
745
  },
738
- [ethereumChain, getAccounts]
746
+ [getEthereumChain, getAccounts]
739
747
  );
740
748
  return {
741
749
  // Chain instance for advanced usage
@@ -745,6 +753,7 @@ function useEthereum() {
745
753
  // Convenient methods
746
754
  signPersonalMessage,
747
755
  signMessage,
756
+ signTransaction,
748
757
  signTypedData,
749
758
  sendTransaction,
750
759
  switchChain,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@phantom/react-native-sdk",
3
- "version": "1.0.0-beta.1",
3
+ "version": "1.0.0-beta.2",
4
4
  "description": "Phantom Wallet SDK for React Native and Expo applications",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
@@ -45,14 +45,14 @@
45
45
  "directory": "packages/react-native-sdk"
46
46
  },
47
47
  "dependencies": {
48
- "@phantom/api-key-stamper": "^1.0.0-beta.1",
49
- "@phantom/base64url": "^1.0.0-beta.1",
50
- "@phantom/chains": "^1.0.0-beta.1",
51
- "@phantom/client": "^1.0.0-beta.1",
52
- "@phantom/constants": "^1.0.0-beta.1",
53
- "@phantom/crypto": "^1.0.0-beta.1",
54
- "@phantom/embedded-provider-core": "^1.0.0-beta.1",
55
- "@phantom/sdk-types": "^1.0.0-beta.1",
48
+ "@phantom/api-key-stamper": "^1.0.0-beta.2",
49
+ "@phantom/base64url": "^1.0.0-beta.2",
50
+ "@phantom/chains": "^1.0.0-beta.2",
51
+ "@phantom/client": "^1.0.0-beta.2",
52
+ "@phantom/constants": "^1.0.0-beta.2",
53
+ "@phantom/crypto": "^1.0.0-beta.2",
54
+ "@phantom/embedded-provider-core": "^1.0.0-beta.2",
55
+ "@phantom/sdk-types": "^1.0.0-beta.2",
56
56
  "@types/bs58": "^5.0.0",
57
57
  "bs58": "^6.0.0",
58
58
  "buffer": "^6.0.3"