@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 +7 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +64 -55
- package/dist/index.mjs +64 -55
- package/package.json +9 -9
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
|
-
//
|
|
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
|
-
|
|
646
|
-
|
|
647
|
-
return await solanaChain.signMessage(message);
|
|
652
|
+
const chain = getSolanaChain();
|
|
653
|
+
return await chain.signMessage(message);
|
|
648
654
|
},
|
|
649
|
-
[
|
|
655
|
+
[getSolanaChain]
|
|
650
656
|
);
|
|
651
657
|
const signTransaction = (0, import_react4.useCallback)(
|
|
652
658
|
async (transaction) => {
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
return await solanaChain.signTransaction(transaction);
|
|
659
|
+
const chain = getSolanaChain();
|
|
660
|
+
return await chain.signTransaction(transaction);
|
|
656
661
|
},
|
|
657
|
-
[
|
|
662
|
+
[getSolanaChain]
|
|
658
663
|
);
|
|
659
664
|
const signAndSendTransaction = (0, import_react4.useCallback)(
|
|
660
665
|
async (transaction) => {
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
return await solanaChain.signAndSendTransaction(transaction);
|
|
666
|
+
const chain = getSolanaChain();
|
|
667
|
+
return await chain.signAndSendTransaction(transaction);
|
|
664
668
|
},
|
|
665
|
-
[
|
|
669
|
+
[getSolanaChain]
|
|
666
670
|
);
|
|
667
671
|
const connect = (0, import_react4.useCallback)(
|
|
668
672
|
async (options) => {
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
return await solanaChain.connect(options);
|
|
673
|
+
const chain = getSolanaChain();
|
|
674
|
+
return await chain.connect(options);
|
|
672
675
|
},
|
|
673
|
-
[
|
|
676
|
+
[getSolanaChain]
|
|
674
677
|
);
|
|
675
678
|
const disconnect = (0, import_react4.useCallback)(async () => {
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
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
|
-
|
|
683
|
-
|
|
684
|
-
return await solanaChain.switchNetwork?.(network);
|
|
684
|
+
const chain = getSolanaChain();
|
|
685
|
+
return await chain.switchNetwork?.(network);
|
|
685
686
|
},
|
|
686
|
-
[
|
|
687
|
+
[getSolanaChain]
|
|
687
688
|
);
|
|
688
689
|
const getPublicKey = (0, import_react4.useCallback)(async () => {
|
|
689
|
-
if (!
|
|
690
|
+
if (!sdk || !sdk.isConnected())
|
|
690
691
|
return null;
|
|
691
|
-
return await
|
|
692
|
-
}, [
|
|
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
|
-
|
|
726
|
-
|
|
727
|
-
return await ethereumChain.request(args);
|
|
733
|
+
const chain = getEthereumChain();
|
|
734
|
+
return await chain.request(args);
|
|
728
735
|
},
|
|
729
|
-
[
|
|
736
|
+
[getEthereumChain]
|
|
730
737
|
);
|
|
731
738
|
const signPersonalMessage = (0, import_react5.useCallback)(
|
|
732
739
|
async (message, address) => {
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
return await ethereumChain.signPersonalMessage(message, address);
|
|
740
|
+
const chain = getEthereumChain();
|
|
741
|
+
return await chain.signPersonalMessage(message, address);
|
|
736
742
|
},
|
|
737
|
-
[
|
|
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
|
-
|
|
742
|
-
|
|
743
|
-
return await ethereumChain.sendTransaction(transaction);
|
|
754
|
+
const chain = getEthereumChain();
|
|
755
|
+
return await chain.sendTransaction(transaction);
|
|
744
756
|
},
|
|
745
|
-
[
|
|
757
|
+
[getEthereumChain]
|
|
746
758
|
);
|
|
747
759
|
const switchChain = (0, import_react5.useCallback)(
|
|
748
760
|
async (chainId) => {
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
return await ethereumChain.switchChain(chainId);
|
|
761
|
+
const chain = getEthereumChain();
|
|
762
|
+
return await chain.switchChain(chainId);
|
|
752
763
|
},
|
|
753
|
-
[
|
|
764
|
+
[getEthereumChain]
|
|
754
765
|
);
|
|
755
766
|
const getChainId = (0, import_react5.useCallback)(async () => {
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
}, [ethereumChain]);
|
|
767
|
+
const chain = getEthereumChain();
|
|
768
|
+
return await chain.getChainId();
|
|
769
|
+
}, [getEthereumChain]);
|
|
760
770
|
const getAccounts = (0, import_react5.useCallback)(async () => {
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
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
|
-
|
|
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
|
|
788
|
+
return await chain.signTypedData(typedData, accounts[0]);
|
|
781
789
|
},
|
|
782
|
-
[
|
|
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
|
-
|
|
602
|
-
|
|
603
|
-
return await solanaChain.signMessage(message);
|
|
608
|
+
const chain = getSolanaChain();
|
|
609
|
+
return await chain.signMessage(message);
|
|
604
610
|
},
|
|
605
|
-
[
|
|
611
|
+
[getSolanaChain]
|
|
606
612
|
);
|
|
607
613
|
const signTransaction = useCallback3(
|
|
608
614
|
async (transaction) => {
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
return await solanaChain.signTransaction(transaction);
|
|
615
|
+
const chain = getSolanaChain();
|
|
616
|
+
return await chain.signTransaction(transaction);
|
|
612
617
|
},
|
|
613
|
-
[
|
|
618
|
+
[getSolanaChain]
|
|
614
619
|
);
|
|
615
620
|
const signAndSendTransaction = useCallback3(
|
|
616
621
|
async (transaction) => {
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
return await solanaChain.signAndSendTransaction(transaction);
|
|
622
|
+
const chain = getSolanaChain();
|
|
623
|
+
return await chain.signAndSendTransaction(transaction);
|
|
620
624
|
},
|
|
621
|
-
[
|
|
625
|
+
[getSolanaChain]
|
|
622
626
|
);
|
|
623
627
|
const connect = useCallback3(
|
|
624
628
|
async (options) => {
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
return await solanaChain.connect(options);
|
|
629
|
+
const chain = getSolanaChain();
|
|
630
|
+
return await chain.connect(options);
|
|
628
631
|
},
|
|
629
|
-
[
|
|
632
|
+
[getSolanaChain]
|
|
630
633
|
);
|
|
631
634
|
const disconnect = useCallback3(async () => {
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
}, [solanaChain]);
|
|
635
|
+
const chain = getSolanaChain();
|
|
636
|
+
return await chain.disconnect();
|
|
637
|
+
}, [getSolanaChain]);
|
|
636
638
|
const switchNetwork = useCallback3(
|
|
637
639
|
async (network) => {
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
return await solanaChain.switchNetwork?.(network);
|
|
640
|
+
const chain = getSolanaChain();
|
|
641
|
+
return await chain.switchNetwork?.(network);
|
|
641
642
|
},
|
|
642
|
-
[
|
|
643
|
+
[getSolanaChain]
|
|
643
644
|
);
|
|
644
645
|
const getPublicKey = useCallback3(async () => {
|
|
645
|
-
if (!
|
|
646
|
+
if (!sdk || !sdk.isConnected())
|
|
646
647
|
return null;
|
|
647
|
-
return await
|
|
648
|
-
}, [
|
|
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
|
-
|
|
682
|
-
|
|
683
|
-
return await ethereumChain.request(args);
|
|
689
|
+
const chain = getEthereumChain();
|
|
690
|
+
return await chain.request(args);
|
|
684
691
|
},
|
|
685
|
-
[
|
|
692
|
+
[getEthereumChain]
|
|
686
693
|
);
|
|
687
694
|
const signPersonalMessage = useCallback4(
|
|
688
695
|
async (message, address) => {
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
return await ethereumChain.signPersonalMessage(message, address);
|
|
696
|
+
const chain = getEthereumChain();
|
|
697
|
+
return await chain.signPersonalMessage(message, address);
|
|
692
698
|
},
|
|
693
|
-
[
|
|
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
|
-
|
|
698
|
-
|
|
699
|
-
return await ethereumChain.sendTransaction(transaction);
|
|
710
|
+
const chain = getEthereumChain();
|
|
711
|
+
return await chain.sendTransaction(transaction);
|
|
700
712
|
},
|
|
701
|
-
[
|
|
713
|
+
[getEthereumChain]
|
|
702
714
|
);
|
|
703
715
|
const switchChain = useCallback4(
|
|
704
716
|
async (chainId) => {
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
return await ethereumChain.switchChain(chainId);
|
|
717
|
+
const chain = getEthereumChain();
|
|
718
|
+
return await chain.switchChain(chainId);
|
|
708
719
|
},
|
|
709
|
-
[
|
|
720
|
+
[getEthereumChain]
|
|
710
721
|
);
|
|
711
722
|
const getChainId = useCallback4(async () => {
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
}, [ethereumChain]);
|
|
723
|
+
const chain = getEthereumChain();
|
|
724
|
+
return await chain.getChainId();
|
|
725
|
+
}, [getEthereumChain]);
|
|
716
726
|
const getAccounts = useCallback4(async () => {
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
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
|
-
|
|
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
|
|
744
|
+
return await chain.signTypedData(typedData, accounts[0]);
|
|
737
745
|
},
|
|
738
|
-
[
|
|
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.
|
|
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.
|
|
49
|
-
"@phantom/base64url": "^1.0.0-beta.
|
|
50
|
-
"@phantom/chains": "^1.0.0-beta.
|
|
51
|
-
"@phantom/client": "^1.0.0-beta.
|
|
52
|
-
"@phantom/constants": "^1.0.0-beta.
|
|
53
|
-
"@phantom/crypto": "^1.0.0-beta.
|
|
54
|
-
"@phantom/embedded-provider-core": "^1.0.0-beta.
|
|
55
|
-
"@phantom/sdk-types": "^1.0.0-beta.
|
|
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"
|