@phantom/react-native-sdk 1.0.0-beta.0 → 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
@@ -89,7 +89,7 @@ export default function App() {
89
89
  return (
90
90
  <PhantomProvider
91
91
  config={{
92
- organizationId: "your-organization-id",
92
+ appId: "your-app-id",
93
93
  scheme: "mywalletapp", // Must match app.json scheme
94
94
  embeddedWalletType: "user-wallet",
95
95
  addressTypes: [AddressType.solana],
@@ -98,7 +98,6 @@ export default function App() {
98
98
  authOptions: {
99
99
  redirectUrl: "mywalletapp://phantom-auth-callback",
100
100
  },
101
- appName: "My Wallet App", // Optional branding
102
101
  }}
103
102
  >
104
103
  <YourAppContent />
@@ -172,17 +171,9 @@ export function WalletScreen() {
172
171
  </Text>
173
172
  ))}
174
173
 
175
- <Button
176
- title="Sign Solana Message"
177
- onPress={handleSignSolanaMessage}
178
- style={{ marginTop: 10 }}
179
- />
174
+ <Button title="Sign Solana Message" onPress={handleSignSolanaMessage} style={{ marginTop: 10 }} />
180
175
 
181
- <Button
182
- title="Sign Ethereum Message"
183
- onPress={handleSignEthereumMessage}
184
- style={{ marginTop: 10 }}
185
- />
176
+ <Button title="Sign Ethereum Message" onPress={handleSignEthereumMessage} style={{ marginTop: 10 }} />
186
177
 
187
178
  <Button title="Disconnect" onPress={disconnect} style={{ marginTop: 10 }} />
188
179
  </View>
@@ -206,7 +197,6 @@ The main provider component that initializes the SDK and provides context to all
206
197
 
207
198
  ```typescript
208
199
  interface PhantomSDKConfig {
209
- organizationId: string; // Your Phantom organization ID
210
200
  scheme: string; // Custom URL scheme for your app
211
201
  embeddedWalletType: "user-wallet" | "app-wallet";
212
202
  addressTypes: [AddressType, ...AddressType[]]; // e.g., [AddressType.solana]
@@ -216,8 +206,6 @@ interface PhantomSDKConfig {
216
206
  authUrl?: string; // Custom auth URL (optional)
217
207
  redirectUrl?: string; // Custom redirect URL (optional)
218
208
  };
219
- appName?: string; // Optional app name for branding
220
- appLogo?: string; // Optional app logo URL for branding
221
209
  autoConnect?: boolean; // Auto-connect to existing session on SDK instantiation (default: true)
222
210
  }
223
211
  ```
@@ -259,6 +247,9 @@ const solana = useSolana();
259
247
  // Sign a message
260
248
  const signature = await solana.signMessage("Hello Solana!");
261
249
 
250
+ // Sign a transaction (without sending)
251
+ const signedTx = await solana.signTransaction(transaction);
252
+
262
253
  // Sign and send a transaction
263
254
  const result = await solana.signAndSendTransaction(transaction);
264
255
  ```
@@ -276,7 +267,10 @@ const accounts = await ethereum.getAccounts();
276
267
  // Sign a personal message
277
268
  const signature = await ethereum.signPersonalMessage("Hello Ethereum!", accounts[0]);
278
269
 
279
- // Send a transaction
270
+ // Sign a transaction (without sending)
271
+ const signedTx = await ethereum.signTransaction(transactionData);
272
+
273
+ // Sign and send a transaction
280
274
  const result = await ethereum.sendTransaction(transactionData);
281
275
 
282
276
  // Get current chain ID
@@ -342,7 +336,7 @@ import { PhantomProvider, AddressType } from "@phantom/react-native-sdk";
342
336
 
343
337
  <PhantomProvider
344
338
  config={{
345
- organizationId: "org_123456789",
339
+ appId: "app_123456789",
346
340
  scheme: "myapp",
347
341
  embeddedWalletType: "user-wallet",
348
342
  addressTypes: [AddressType.solana],
@@ -360,7 +354,7 @@ import { PhantomProvider, AddressType } from "@phantom/react-native-sdk";
360
354
 
361
355
  <PhantomProvider
362
356
  config={{
363
- organizationId: "org_123456789",
357
+ appId: "app_123456789",
364
358
  scheme: "mycompany-wallet",
365
359
  embeddedWalletType: "user-wallet",
366
360
  addressTypes: [AddressType.solana, AddressType.ethereum],
@@ -399,7 +393,7 @@ import { PhantomProvider, AddressType } from "@phantom/react-native-sdk";
399
393
  import { PhantomProvider, AddressType } from '@phantom/react-native-sdk';
400
394
 
401
395
  const testConfig = {
402
- organizationId: "test-org",
396
+ appId: "test-app",
403
397
  scheme: "testapp",
404
398
  embeddedWalletType: "app-wallet" as const,
405
399
  addressTypes: [AddressType.solana],
@@ -456,7 +450,6 @@ import { PhantomProvider, type PhantomSDKConfig, type PhantomDebugConfig } from
456
450
  function App() {
457
451
  // SDK configuration - static, won't change when debug settings change
458
452
  const config: PhantomSDKConfig = {
459
- organizationId: "your-org-id",
460
453
  scheme: "mywalletapp",
461
454
  // ... other config
462
455
  };
package/dist/index.d.ts CHANGED
@@ -4,7 +4,6 @@ import * as _phantom_embedded_provider_core from '@phantom/embedded-provider-cor
4
4
  import { EmbeddedProviderConfig, EmbeddedProvider, WalletAddress, ConnectResult } from '@phantom/embedded-provider-core';
5
5
  export { ConnectResult, SignAndSendTransactionParams, SignMessageParams, SignMessageResult, SignedTransaction, WalletAddress } from '@phantom/embedded-provider-core';
6
6
  import { ISolanaChain, IEthereumChain, EthTransactionRequest } from '@phantom/chains';
7
- import { ParsedSignatureResult, ParsedTransactionResult } from '@phantom/parsers';
8
7
  export { AddressType } from '@phantom/client';
9
8
  export { NetworkId } from '@phantom/constants';
10
9
 
@@ -69,16 +68,21 @@ declare function useAccounts(): {
69
68
  */
70
69
  declare function useSolana(): {
71
70
  solana: ISolanaChain | null;
72
- signMessage: (message: string | Uint8Array) => Promise<ParsedSignatureResult>;
71
+ signMessage: (message: string | Uint8Array) => Promise<{
72
+ signature: Uint8Array;
73
+ publicKey: string;
74
+ }>;
73
75
  signTransaction: <T>(transaction: T) => Promise<T>;
74
- signAndSendTransaction: <T>(transaction: T) => Promise<ParsedTransactionResult>;
76
+ signAndSendTransaction: <T>(transaction: T) => Promise<{
77
+ signature: string;
78
+ }>;
75
79
  connect: (options?: {
76
80
  onlyIfTrusted?: boolean;
77
81
  }) => Promise<{
78
82
  publicKey: string;
79
83
  }>;
80
84
  disconnect: () => Promise<void>;
81
- switchNetwork: (network: "mainnet" | "devnet") => Promise<void>;
85
+ switchNetwork: (network: "mainnet" | "devnet") => Promise<void | undefined>;
82
86
  getPublicKey: () => Promise<string | null>;
83
87
  isAvailable: boolean;
84
88
  isConnected: boolean;
@@ -95,10 +99,11 @@ declare function useEthereum(): {
95
99
  method: string;
96
100
  params?: unknown[];
97
101
  }) => Promise<T>;
98
- signPersonalMessage: (message: string, address: string) => Promise<ParsedSignatureResult>;
102
+ signPersonalMessage: (message: string, address: string) => Promise<string>;
99
103
  signMessage: (message: string) => Promise<string>;
100
- signTypedData: (typedData: any) => Promise<ParsedSignatureResult>;
101
- sendTransaction: (transaction: EthTransactionRequest) => Promise<ParsedTransactionResult>;
104
+ signTransaction: (transaction: EthTransactionRequest) => Promise<string>;
105
+ signTypedData: (typedData: any) => Promise<string>;
106
+ sendTransaction: (transaction: EthTransactionRequest) => Promise<string>;
102
107
  switchChain: (chainId: number) => Promise<void>;
103
108
  getChainId: () => Promise<number>;
104
109
  getAccounts: () => Promise<string[]>;
package/dist/index.js CHANGED
@@ -103,35 +103,22 @@ var ExpoAuthProvider = class {
103
103
  return;
104
104
  }
105
105
  const phantomOptions = options;
106
- const {
107
- authUrl,
108
- redirectUrl,
109
- organizationId,
110
- parentOrganizationId,
111
- sessionId,
112
- provider,
113
- customAuthData,
114
- appName,
115
- appLogo
116
- } = phantomOptions;
106
+ const { authUrl, redirectUrl, organizationId, parentOrganizationId, sessionId, provider, customAuthData, appId } = phantomOptions;
117
107
  if (!redirectUrl) {
118
108
  throw new Error("redirectUrl is required for web browser authentication");
119
109
  }
120
- if (!organizationId || !sessionId) {
121
- throw new Error("organizationId and sessionId are required for authentication");
110
+ if (!organizationId || !sessionId || !appId) {
111
+ throw new Error("organizationId, sessionId and appId are required for authentication");
122
112
  }
123
113
  try {
124
114
  const baseUrl = authUrl || DEFAULT_AUTH_URL;
125
115
  const params = new URLSearchParams({
126
116
  organization_id: organizationId,
127
117
  parent_organization_id: parentOrganizationId,
118
+ app_id: appId,
128
119
  redirect_uri: redirectUrl,
129
120
  session_id: sessionId,
130
- clear_previous_session: "true",
131
- app_name: appName || "",
132
- // Optional app name
133
- app_logo: appLogo || ""
134
- // Optional app logo URL
121
+ clear_previous_session: "true"
135
122
  });
136
123
  if (provider) {
137
124
  console.log("[ExpoAuthProvider] Provider specified, will skip selection", { provider });
@@ -560,15 +547,7 @@ function PhantomProvider({ children, config, debugConfig }) {
560
547
  walletId,
561
548
  setWalletId
562
549
  }),
563
- [
564
- sdk,
565
- isConnected,
566
- isConnecting,
567
- connectError,
568
- addresses,
569
- walletId,
570
- setWalletId
571
- ]
550
+ [sdk, isConnected, isConnecting, connectError, addresses, walletId, setWalletId]
572
551
  );
573
552
  return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(PhantomContext.Provider, { value, children });
574
553
  }
@@ -652,6 +631,13 @@ function useAccounts() {
652
631
  var import_react4 = require("react");
653
632
  function useSolana() {
654
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]);
655
641
  const solanaChain = (0, import_react4.useMemo)(() => {
656
642
  if (!sdk || !isConnected)
657
643
  return null;
@@ -661,41 +647,50 @@ function useSolana() {
661
647
  return null;
662
648
  }
663
649
  }, [sdk, isConnected]);
664
- const signMessage = (0, import_react4.useCallback)(async (message) => {
665
- if (!solanaChain)
666
- throw new Error("Solana chain not available. Ensure SDK is connected.");
667
- return await solanaChain.signMessage(message);
668
- }, [solanaChain]);
669
- const signTransaction = (0, import_react4.useCallback)(async (transaction) => {
670
- if (!solanaChain)
671
- throw new Error("Solana chain not available. Ensure SDK is connected.");
672
- return await solanaChain.signTransaction(transaction);
673
- }, [solanaChain]);
674
- const signAndSendTransaction = (0, import_react4.useCallback)(async (transaction) => {
675
- if (!solanaChain)
676
- throw new Error("Solana chain not available. Ensure SDK is connected.");
677
- return await solanaChain.signAndSendTransaction(transaction);
678
- }, [solanaChain]);
679
- const connect = (0, import_react4.useCallback)(async (options) => {
680
- if (!solanaChain)
681
- throw new Error("Solana chain not available. Ensure SDK is connected.");
682
- return await solanaChain.connect(options);
683
- }, [solanaChain]);
650
+ const signMessage = (0, import_react4.useCallback)(
651
+ async (message) => {
652
+ const chain = getSolanaChain();
653
+ return await chain.signMessage(message);
654
+ },
655
+ [getSolanaChain]
656
+ );
657
+ const signTransaction = (0, import_react4.useCallback)(
658
+ async (transaction) => {
659
+ const chain = getSolanaChain();
660
+ return await chain.signTransaction(transaction);
661
+ },
662
+ [getSolanaChain]
663
+ );
664
+ const signAndSendTransaction = (0, import_react4.useCallback)(
665
+ async (transaction) => {
666
+ const chain = getSolanaChain();
667
+ return await chain.signAndSendTransaction(transaction);
668
+ },
669
+ [getSolanaChain]
670
+ );
671
+ const connect = (0, import_react4.useCallback)(
672
+ async (options) => {
673
+ const chain = getSolanaChain();
674
+ return await chain.connect(options);
675
+ },
676
+ [getSolanaChain]
677
+ );
684
678
  const disconnect = (0, import_react4.useCallback)(async () => {
685
- if (!solanaChain)
686
- throw new Error("Solana chain not available. Ensure SDK is connected.");
687
- return await solanaChain.disconnect();
688
- }, [solanaChain]);
689
- const switchNetwork = (0, import_react4.useCallback)(async (network) => {
690
- if (!solanaChain)
691
- throw new Error("Solana chain not available. Ensure SDK is connected.");
692
- return await solanaChain.switchNetwork(network);
693
- }, [solanaChain]);
679
+ const chain = getSolanaChain();
680
+ return await chain.disconnect();
681
+ }, [getSolanaChain]);
682
+ const switchNetwork = (0, import_react4.useCallback)(
683
+ async (network) => {
684
+ const chain = getSolanaChain();
685
+ return await chain.switchNetwork?.(network);
686
+ },
687
+ [getSolanaChain]
688
+ );
694
689
  const getPublicKey = (0, import_react4.useCallback)(async () => {
695
- if (!solanaChain)
690
+ if (!sdk || !sdk.isConnected())
696
691
  return null;
697
- return await solanaChain.getPublicKey();
698
- }, [solanaChain]);
692
+ return await sdk.solana.getPublicKey();
693
+ }, [sdk]);
699
694
  return {
700
695
  // Chain instance for advanced usage
701
696
  solana: solanaChain,
@@ -717,6 +712,13 @@ function useSolana() {
717
712
  var import_react5 = require("react");
718
713
  function useEthereum() {
719
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]);
720
722
  const ethereumChain = (0, import_react5.useMemo)(() => {
721
723
  if (!sdk || !isConnected)
722
724
  return null;
@@ -726,49 +728,67 @@ function useEthereum() {
726
728
  return null;
727
729
  }
728
730
  }, [sdk, isConnected]);
729
- const request = (0, import_react5.useCallback)(async (args) => {
730
- if (!ethereumChain)
731
- throw new Error("Ethereum chain not available. Ensure SDK is connected.");
732
- return await ethereumChain.request(args);
733
- }, [ethereumChain]);
734
- const signPersonalMessage = (0, import_react5.useCallback)(async (message, address) => {
735
- if (!ethereumChain)
736
- throw new Error("Ethereum chain not available. Ensure SDK is connected.");
737
- return await ethereumChain.signPersonalMessage(message, address);
738
- }, [ethereumChain]);
739
- const sendTransaction = (0, import_react5.useCallback)(async (transaction) => {
740
- if (!ethereumChain)
741
- throw new Error("Ethereum chain not available. Ensure SDK is connected.");
742
- return await ethereumChain.sendTransaction(transaction);
743
- }, [ethereumChain]);
744
- const switchChain = (0, import_react5.useCallback)(async (chainId) => {
745
- if (!ethereumChain)
746
- throw new Error("Ethereum chain not available. Ensure SDK is connected.");
747
- return await ethereumChain.switchChain(chainId);
748
- }, [ethereumChain]);
731
+ const request = (0, import_react5.useCallback)(
732
+ async (args) => {
733
+ const chain = getEthereumChain();
734
+ return await chain.request(args);
735
+ },
736
+ [getEthereumChain]
737
+ );
738
+ const signPersonalMessage = (0, import_react5.useCallback)(
739
+ async (message, address) => {
740
+ const chain = getEthereumChain();
741
+ return await chain.signPersonalMessage(message, address);
742
+ },
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]
751
+ );
752
+ const sendTransaction = (0, import_react5.useCallback)(
753
+ async (transaction) => {
754
+ const chain = getEthereumChain();
755
+ return await chain.sendTransaction(transaction);
756
+ },
757
+ [getEthereumChain]
758
+ );
759
+ const switchChain = (0, import_react5.useCallback)(
760
+ async (chainId) => {
761
+ const chain = getEthereumChain();
762
+ return await chain.switchChain(chainId);
763
+ },
764
+ [getEthereumChain]
765
+ );
749
766
  const getChainId = (0, import_react5.useCallback)(async () => {
750
- if (!ethereumChain)
751
- throw new Error("Ethereum chain not available. Ensure SDK is connected.");
752
- return await ethereumChain.getChainId();
753
- }, [ethereumChain]);
767
+ const chain = getEthereumChain();
768
+ return await chain.getChainId();
769
+ }, [getEthereumChain]);
754
770
  const getAccounts = (0, import_react5.useCallback)(async () => {
755
- if (!ethereumChain)
756
- throw new Error("Ethereum chain not available. Ensure SDK is connected.");
757
- return await ethereumChain.getAccounts();
758
- }, [ethereumChain]);
759
- const signMessage = (0, import_react5.useCallback)(async (message) => {
760
- const accounts = await getAccounts();
761
- return await request({
762
- method: "eth_sign",
763
- params: [accounts[0], message]
764
- });
765
- }, [request, getAccounts]);
766
- const signTypedData = (0, import_react5.useCallback)(async (typedData) => {
767
- if (!ethereumChain)
768
- throw new Error("Ethereum chain not available. Ensure SDK is connected.");
769
- const accounts = await getAccounts();
770
- return await ethereumChain.signTypedData(typedData, accounts[0]);
771
- }, [ethereumChain, getAccounts]);
771
+ const chain = getEthereumChain();
772
+ return await chain.getAccounts();
773
+ }, [getEthereumChain]);
774
+ const signMessage = (0, import_react5.useCallback)(
775
+ async (message) => {
776
+ const accounts = await getAccounts();
777
+ return await request({
778
+ method: "eth_sign",
779
+ params: [accounts[0], message]
780
+ });
781
+ },
782
+ [request, getAccounts]
783
+ );
784
+ const signTypedData = (0, import_react5.useCallback)(
785
+ async (typedData) => {
786
+ const chain = getEthereumChain();
787
+ const accounts = await getAccounts();
788
+ return await chain.signTypedData(typedData, accounts[0]);
789
+ },
790
+ [getEthereumChain, getAccounts]
791
+ );
772
792
  return {
773
793
  // Chain instance for advanced usage
774
794
  ethereum: ethereumChain,
@@ -777,6 +797,7 @@ function useEthereum() {
777
797
  // Convenient methods
778
798
  signPersonalMessage,
779
799
  signMessage,
800
+ signTransaction,
780
801
  signTypedData,
781
802
  sendTransaction,
782
803
  switchChain,
package/dist/index.mjs CHANGED
@@ -59,35 +59,22 @@ var ExpoAuthProvider = class {
59
59
  return;
60
60
  }
61
61
  const phantomOptions = options;
62
- const {
63
- authUrl,
64
- redirectUrl,
65
- organizationId,
66
- parentOrganizationId,
67
- sessionId,
68
- provider,
69
- customAuthData,
70
- appName,
71
- appLogo
72
- } = phantomOptions;
62
+ const { authUrl, redirectUrl, organizationId, parentOrganizationId, sessionId, provider, customAuthData, appId } = phantomOptions;
73
63
  if (!redirectUrl) {
74
64
  throw new Error("redirectUrl is required for web browser authentication");
75
65
  }
76
- if (!organizationId || !sessionId) {
77
- throw new Error("organizationId and sessionId are required for authentication");
66
+ if (!organizationId || !sessionId || !appId) {
67
+ throw new Error("organizationId, sessionId and appId are required for authentication");
78
68
  }
79
69
  try {
80
70
  const baseUrl = authUrl || DEFAULT_AUTH_URL;
81
71
  const params = new URLSearchParams({
82
72
  organization_id: organizationId,
83
73
  parent_organization_id: parentOrganizationId,
74
+ app_id: appId,
84
75
  redirect_uri: redirectUrl,
85
76
  session_id: sessionId,
86
- clear_previous_session: "true",
87
- app_name: appName || "",
88
- // Optional app name
89
- app_logo: appLogo || ""
90
- // Optional app logo URL
77
+ clear_previous_session: "true"
91
78
  });
92
79
  if (provider) {
93
80
  console.log("[ExpoAuthProvider] Provider specified, will skip selection", { provider });
@@ -516,15 +503,7 @@ function PhantomProvider({ children, config, debugConfig }) {
516
503
  walletId,
517
504
  setWalletId
518
505
  }),
519
- [
520
- sdk,
521
- isConnected,
522
- isConnecting,
523
- connectError,
524
- addresses,
525
- walletId,
526
- setWalletId
527
- ]
506
+ [sdk, isConnected, isConnecting, connectError, addresses, walletId, setWalletId]
528
507
  );
529
508
  return /* @__PURE__ */ jsx(PhantomContext.Provider, { value, children });
530
509
  }
@@ -608,6 +587,13 @@ function useAccounts() {
608
587
  import { useCallback as useCallback3, useMemo as useMemo2 } from "react";
609
588
  function useSolana() {
610
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]);
611
597
  const solanaChain = useMemo2(() => {
612
598
  if (!sdk || !isConnected)
613
599
  return null;
@@ -617,41 +603,50 @@ function useSolana() {
617
603
  return null;
618
604
  }
619
605
  }, [sdk, isConnected]);
620
- const signMessage = useCallback3(async (message) => {
621
- if (!solanaChain)
622
- throw new Error("Solana chain not available. Ensure SDK is connected.");
623
- return await solanaChain.signMessage(message);
624
- }, [solanaChain]);
625
- const signTransaction = useCallback3(async (transaction) => {
626
- if (!solanaChain)
627
- throw new Error("Solana chain not available. Ensure SDK is connected.");
628
- return await solanaChain.signTransaction(transaction);
629
- }, [solanaChain]);
630
- const signAndSendTransaction = useCallback3(async (transaction) => {
631
- if (!solanaChain)
632
- throw new Error("Solana chain not available. Ensure SDK is connected.");
633
- return await solanaChain.signAndSendTransaction(transaction);
634
- }, [solanaChain]);
635
- const connect = useCallback3(async (options) => {
636
- if (!solanaChain)
637
- throw new Error("Solana chain not available. Ensure SDK is connected.");
638
- return await solanaChain.connect(options);
639
- }, [solanaChain]);
606
+ const signMessage = useCallback3(
607
+ async (message) => {
608
+ const chain = getSolanaChain();
609
+ return await chain.signMessage(message);
610
+ },
611
+ [getSolanaChain]
612
+ );
613
+ const signTransaction = useCallback3(
614
+ async (transaction) => {
615
+ const chain = getSolanaChain();
616
+ return await chain.signTransaction(transaction);
617
+ },
618
+ [getSolanaChain]
619
+ );
620
+ const signAndSendTransaction = useCallback3(
621
+ async (transaction) => {
622
+ const chain = getSolanaChain();
623
+ return await chain.signAndSendTransaction(transaction);
624
+ },
625
+ [getSolanaChain]
626
+ );
627
+ const connect = useCallback3(
628
+ async (options) => {
629
+ const chain = getSolanaChain();
630
+ return await chain.connect(options);
631
+ },
632
+ [getSolanaChain]
633
+ );
640
634
  const disconnect = useCallback3(async () => {
641
- if (!solanaChain)
642
- throw new Error("Solana chain not available. Ensure SDK is connected.");
643
- return await solanaChain.disconnect();
644
- }, [solanaChain]);
645
- const switchNetwork = useCallback3(async (network) => {
646
- if (!solanaChain)
647
- throw new Error("Solana chain not available. Ensure SDK is connected.");
648
- return await solanaChain.switchNetwork(network);
649
- }, [solanaChain]);
635
+ const chain = getSolanaChain();
636
+ return await chain.disconnect();
637
+ }, [getSolanaChain]);
638
+ const switchNetwork = useCallback3(
639
+ async (network) => {
640
+ const chain = getSolanaChain();
641
+ return await chain.switchNetwork?.(network);
642
+ },
643
+ [getSolanaChain]
644
+ );
650
645
  const getPublicKey = useCallback3(async () => {
651
- if (!solanaChain)
646
+ if (!sdk || !sdk.isConnected())
652
647
  return null;
653
- return await solanaChain.getPublicKey();
654
- }, [solanaChain]);
648
+ return await sdk.solana.getPublicKey();
649
+ }, [sdk]);
655
650
  return {
656
651
  // Chain instance for advanced usage
657
652
  solana: solanaChain,
@@ -673,6 +668,13 @@ function useSolana() {
673
668
  import { useCallback as useCallback4, useMemo as useMemo3 } from "react";
674
669
  function useEthereum() {
675
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]);
676
678
  const ethereumChain = useMemo3(() => {
677
679
  if (!sdk || !isConnected)
678
680
  return null;
@@ -682,49 +684,67 @@ function useEthereum() {
682
684
  return null;
683
685
  }
684
686
  }, [sdk, isConnected]);
685
- const request = useCallback4(async (args) => {
686
- if (!ethereumChain)
687
- throw new Error("Ethereum chain not available. Ensure SDK is connected.");
688
- return await ethereumChain.request(args);
689
- }, [ethereumChain]);
690
- const signPersonalMessage = useCallback4(async (message, address) => {
691
- if (!ethereumChain)
692
- throw new Error("Ethereum chain not available. Ensure SDK is connected.");
693
- return await ethereumChain.signPersonalMessage(message, address);
694
- }, [ethereumChain]);
695
- const sendTransaction = useCallback4(async (transaction) => {
696
- if (!ethereumChain)
697
- throw new Error("Ethereum chain not available. Ensure SDK is connected.");
698
- return await ethereumChain.sendTransaction(transaction);
699
- }, [ethereumChain]);
700
- const switchChain = useCallback4(async (chainId) => {
701
- if (!ethereumChain)
702
- throw new Error("Ethereum chain not available. Ensure SDK is connected.");
703
- return await ethereumChain.switchChain(chainId);
704
- }, [ethereumChain]);
687
+ const request = useCallback4(
688
+ async (args) => {
689
+ const chain = getEthereumChain();
690
+ return await chain.request(args);
691
+ },
692
+ [getEthereumChain]
693
+ );
694
+ const signPersonalMessage = useCallback4(
695
+ async (message, address) => {
696
+ const chain = getEthereumChain();
697
+ return await chain.signPersonalMessage(message, address);
698
+ },
699
+ [getEthereumChain]
700
+ );
701
+ const signTransaction = useCallback4(
702
+ async (transaction) => {
703
+ const chain = getEthereumChain();
704
+ return await chain.signTransaction(transaction);
705
+ },
706
+ [getEthereumChain]
707
+ );
708
+ const sendTransaction = useCallback4(
709
+ async (transaction) => {
710
+ const chain = getEthereumChain();
711
+ return await chain.sendTransaction(transaction);
712
+ },
713
+ [getEthereumChain]
714
+ );
715
+ const switchChain = useCallback4(
716
+ async (chainId) => {
717
+ const chain = getEthereumChain();
718
+ return await chain.switchChain(chainId);
719
+ },
720
+ [getEthereumChain]
721
+ );
705
722
  const getChainId = useCallback4(async () => {
706
- if (!ethereumChain)
707
- throw new Error("Ethereum chain not available. Ensure SDK is connected.");
708
- return await ethereumChain.getChainId();
709
- }, [ethereumChain]);
723
+ const chain = getEthereumChain();
724
+ return await chain.getChainId();
725
+ }, [getEthereumChain]);
710
726
  const getAccounts = useCallback4(async () => {
711
- if (!ethereumChain)
712
- throw new Error("Ethereum chain not available. Ensure SDK is connected.");
713
- return await ethereumChain.getAccounts();
714
- }, [ethereumChain]);
715
- const signMessage = useCallback4(async (message) => {
716
- const accounts = await getAccounts();
717
- return await request({
718
- method: "eth_sign",
719
- params: [accounts[0], message]
720
- });
721
- }, [request, getAccounts]);
722
- const signTypedData = useCallback4(async (typedData) => {
723
- if (!ethereumChain)
724
- throw new Error("Ethereum chain not available. Ensure SDK is connected.");
725
- const accounts = await getAccounts();
726
- return await ethereumChain.signTypedData(typedData, accounts[0]);
727
- }, [ethereumChain, getAccounts]);
727
+ const chain = getEthereumChain();
728
+ return await chain.getAccounts();
729
+ }, [getEthereumChain]);
730
+ const signMessage = useCallback4(
731
+ async (message) => {
732
+ const accounts = await getAccounts();
733
+ return await request({
734
+ method: "eth_sign",
735
+ params: [accounts[0], message]
736
+ });
737
+ },
738
+ [request, getAccounts]
739
+ );
740
+ const signTypedData = useCallback4(
741
+ async (typedData) => {
742
+ const chain = getEthereumChain();
743
+ const accounts = await getAccounts();
744
+ return await chain.signTypedData(typedData, accounts[0]);
745
+ },
746
+ [getEthereumChain, getAccounts]
747
+ );
728
748
  return {
729
749
  // Chain instance for advanced usage
730
750
  ethereum: ethereumChain,
@@ -733,6 +753,7 @@ function useEthereum() {
733
753
  // Convenient methods
734
754
  signPersonalMessage,
735
755
  signMessage,
756
+ signTransaction,
736
757
  signTypedData,
737
758
  sendTransaction,
738
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.0",
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,15 +45,14 @@
45
45
  "directory": "packages/react-native-sdk"
46
46
  },
47
47
  "dependencies": {
48
- "@phantom/api-key-stamper": "^1.0.0-beta.0",
49
- "@phantom/base64url": "^1.0.0-beta.0",
50
- "@phantom/chains": "^1.0.0-beta.0",
51
- "@phantom/client": "^1.0.0-beta.0",
52
- "@phantom/constants": "^1.0.0-beta.0",
53
- "@phantom/crypto": "^1.0.0-beta.0",
54
- "@phantom/embedded-provider-core": "^1.0.0-beta.0",
55
- "@phantom/parsers": "^1.0.0-beta.0",
56
- "@phantom/sdk-types": "^1.0.0-beta.0",
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",
57
56
  "@types/bs58": "^5.0.0",
58
57
  "bs58": "^6.0.0",
59
58
  "buffer": "^6.0.3"