@phantom/react-native-sdk 1.0.0-beta.0 → 1.0.0-beta.1
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 +6 -19
- package/dist/index.d.ts +11 -7
- package/dist/index.js +97 -85
- package/dist/index.mjs +97 -85
- package/package.json +9 -10
package/README.md
CHANGED
|
@@ -89,7 +89,7 @@ export default function App() {
|
|
|
89
89
|
return (
|
|
90
90
|
<PhantomProvider
|
|
91
91
|
config={{
|
|
92
|
-
|
|
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
|
```
|
|
@@ -342,7 +330,7 @@ import { PhantomProvider, AddressType } from "@phantom/react-native-sdk";
|
|
|
342
330
|
|
|
343
331
|
<PhantomProvider
|
|
344
332
|
config={{
|
|
345
|
-
|
|
333
|
+
appId: "app_123456789",
|
|
346
334
|
scheme: "myapp",
|
|
347
335
|
embeddedWalletType: "user-wallet",
|
|
348
336
|
addressTypes: [AddressType.solana],
|
|
@@ -360,7 +348,7 @@ import { PhantomProvider, AddressType } from "@phantom/react-native-sdk";
|
|
|
360
348
|
|
|
361
349
|
<PhantomProvider
|
|
362
350
|
config={{
|
|
363
|
-
|
|
351
|
+
appId: "app_123456789",
|
|
364
352
|
scheme: "mycompany-wallet",
|
|
365
353
|
embeddedWalletType: "user-wallet",
|
|
366
354
|
addressTypes: [AddressType.solana, AddressType.ethereum],
|
|
@@ -399,7 +387,7 @@ import { PhantomProvider, AddressType } from "@phantom/react-native-sdk";
|
|
|
399
387
|
import { PhantomProvider, AddressType } from '@phantom/react-native-sdk';
|
|
400
388
|
|
|
401
389
|
const testConfig = {
|
|
402
|
-
|
|
390
|
+
appId: "test-app",
|
|
403
391
|
scheme: "testapp",
|
|
404
392
|
embeddedWalletType: "app-wallet" as const,
|
|
405
393
|
addressTypes: [AddressType.solana],
|
|
@@ -456,7 +444,6 @@ import { PhantomProvider, type PhantomSDKConfig, type PhantomDebugConfig } from
|
|
|
456
444
|
function App() {
|
|
457
445
|
// SDK configuration - static, won't change when debug settings change
|
|
458
446
|
const config: PhantomSDKConfig = {
|
|
459
|
-
organizationId: "your-org-id",
|
|
460
447
|
scheme: "mywalletapp",
|
|
461
448
|
// ... other config
|
|
462
449
|
};
|
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<
|
|
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<
|
|
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,10 @@ declare function useEthereum(): {
|
|
|
95
99
|
method: string;
|
|
96
100
|
params?: unknown[];
|
|
97
101
|
}) => Promise<T>;
|
|
98
|
-
signPersonalMessage: (message: string, address: string) => Promise<
|
|
102
|
+
signPersonalMessage: (message: string, address: string) => Promise<string>;
|
|
99
103
|
signMessage: (message: string) => Promise<string>;
|
|
100
|
-
signTypedData: (typedData: any) => Promise<
|
|
101
|
-
sendTransaction: (transaction: EthTransactionRequest) => Promise<
|
|
104
|
+
signTypedData: (typedData: any) => Promise<string>;
|
|
105
|
+
sendTransaction: (transaction: EthTransactionRequest) => Promise<string>;
|
|
102
106
|
switchChain: (chainId: number) => Promise<void>;
|
|
103
107
|
getChainId: () => Promise<number>;
|
|
104
108
|
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
|
|
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
|
}
|
|
@@ -661,36 +640,51 @@ function useSolana() {
|
|
|
661
640
|
return null;
|
|
662
641
|
}
|
|
663
642
|
}, [sdk, isConnected]);
|
|
664
|
-
const signMessage = (0, import_react4.useCallback)(
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
643
|
+
const signMessage = (0, import_react4.useCallback)(
|
|
644
|
+
async (message) => {
|
|
645
|
+
if (!solanaChain)
|
|
646
|
+
throw new Error("Solana chain not available. Ensure SDK is connected.");
|
|
647
|
+
return await solanaChain.signMessage(message);
|
|
648
|
+
},
|
|
649
|
+
[solanaChain]
|
|
650
|
+
);
|
|
651
|
+
const signTransaction = (0, import_react4.useCallback)(
|
|
652
|
+
async (transaction) => {
|
|
653
|
+
if (!solanaChain)
|
|
654
|
+
throw new Error("Solana chain not available. Ensure SDK is connected.");
|
|
655
|
+
return await solanaChain.signTransaction(transaction);
|
|
656
|
+
},
|
|
657
|
+
[solanaChain]
|
|
658
|
+
);
|
|
659
|
+
const signAndSendTransaction = (0, import_react4.useCallback)(
|
|
660
|
+
async (transaction) => {
|
|
661
|
+
if (!solanaChain)
|
|
662
|
+
throw new Error("Solana chain not available. Ensure SDK is connected.");
|
|
663
|
+
return await solanaChain.signAndSendTransaction(transaction);
|
|
664
|
+
},
|
|
665
|
+
[solanaChain]
|
|
666
|
+
);
|
|
667
|
+
const connect = (0, import_react4.useCallback)(
|
|
668
|
+
async (options) => {
|
|
669
|
+
if (!solanaChain)
|
|
670
|
+
throw new Error("Solana chain not available. Ensure SDK is connected.");
|
|
671
|
+
return await solanaChain.connect(options);
|
|
672
|
+
},
|
|
673
|
+
[solanaChain]
|
|
674
|
+
);
|
|
684
675
|
const disconnect = (0, import_react4.useCallback)(async () => {
|
|
685
676
|
if (!solanaChain)
|
|
686
677
|
throw new Error("Solana chain not available. Ensure SDK is connected.");
|
|
687
678
|
return await solanaChain.disconnect();
|
|
688
679
|
}, [solanaChain]);
|
|
689
|
-
const switchNetwork = (0, import_react4.useCallback)(
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
680
|
+
const switchNetwork = (0, import_react4.useCallback)(
|
|
681
|
+
async (network) => {
|
|
682
|
+
if (!solanaChain)
|
|
683
|
+
throw new Error("Solana chain not available. Ensure SDK is connected.");
|
|
684
|
+
return await solanaChain.switchNetwork?.(network);
|
|
685
|
+
},
|
|
686
|
+
[solanaChain]
|
|
687
|
+
);
|
|
694
688
|
const getPublicKey = (0, import_react4.useCallback)(async () => {
|
|
695
689
|
if (!solanaChain)
|
|
696
690
|
return null;
|
|
@@ -726,26 +720,38 @@ function useEthereum() {
|
|
|
726
720
|
return null;
|
|
727
721
|
}
|
|
728
722
|
}, [sdk, isConnected]);
|
|
729
|
-
const request = (0, import_react5.useCallback)(
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
723
|
+
const request = (0, import_react5.useCallback)(
|
|
724
|
+
async (args) => {
|
|
725
|
+
if (!ethereumChain)
|
|
726
|
+
throw new Error("Ethereum chain not available. Ensure SDK is connected.");
|
|
727
|
+
return await ethereumChain.request(args);
|
|
728
|
+
},
|
|
729
|
+
[ethereumChain]
|
|
730
|
+
);
|
|
731
|
+
const signPersonalMessage = (0, import_react5.useCallback)(
|
|
732
|
+
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);
|
|
736
|
+
},
|
|
737
|
+
[ethereumChain]
|
|
738
|
+
);
|
|
739
|
+
const sendTransaction = (0, import_react5.useCallback)(
|
|
740
|
+
async (transaction) => {
|
|
741
|
+
if (!ethereumChain)
|
|
742
|
+
throw new Error("Ethereum chain not available. Ensure SDK is connected.");
|
|
743
|
+
return await ethereumChain.sendTransaction(transaction);
|
|
744
|
+
},
|
|
745
|
+
[ethereumChain]
|
|
746
|
+
);
|
|
747
|
+
const switchChain = (0, import_react5.useCallback)(
|
|
748
|
+
async (chainId) => {
|
|
749
|
+
if (!ethereumChain)
|
|
750
|
+
throw new Error("Ethereum chain not available. Ensure SDK is connected.");
|
|
751
|
+
return await ethereumChain.switchChain(chainId);
|
|
752
|
+
},
|
|
753
|
+
[ethereumChain]
|
|
754
|
+
);
|
|
749
755
|
const getChainId = (0, import_react5.useCallback)(async () => {
|
|
750
756
|
if (!ethereumChain)
|
|
751
757
|
throw new Error("Ethereum chain not available. Ensure SDK is connected.");
|
|
@@ -756,19 +762,25 @@ function useEthereum() {
|
|
|
756
762
|
throw new Error("Ethereum chain not available. Ensure SDK is connected.");
|
|
757
763
|
return await ethereumChain.getAccounts();
|
|
758
764
|
}, [ethereumChain]);
|
|
759
|
-
const signMessage = (0, import_react5.useCallback)(
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
765
|
+
const signMessage = (0, import_react5.useCallback)(
|
|
766
|
+
async (message) => {
|
|
767
|
+
const accounts = await getAccounts();
|
|
768
|
+
return await request({
|
|
769
|
+
method: "eth_sign",
|
|
770
|
+
params: [accounts[0], message]
|
|
771
|
+
});
|
|
772
|
+
},
|
|
773
|
+
[request, getAccounts]
|
|
774
|
+
);
|
|
775
|
+
const signTypedData = (0, import_react5.useCallback)(
|
|
776
|
+
async (typedData) => {
|
|
777
|
+
if (!ethereumChain)
|
|
778
|
+
throw new Error("Ethereum chain not available. Ensure SDK is connected.");
|
|
779
|
+
const accounts = await getAccounts();
|
|
780
|
+
return await ethereumChain.signTypedData(typedData, accounts[0]);
|
|
781
|
+
},
|
|
782
|
+
[ethereumChain, getAccounts]
|
|
783
|
+
);
|
|
772
784
|
return {
|
|
773
785
|
// Chain instance for advanced usage
|
|
774
786
|
ethereum: ethereumChain,
|
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
|
|
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
|
}
|
|
@@ -617,36 +596,51 @@ function useSolana() {
|
|
|
617
596
|
return null;
|
|
618
597
|
}
|
|
619
598
|
}, [sdk, isConnected]);
|
|
620
|
-
const signMessage = useCallback3(
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
599
|
+
const signMessage = useCallback3(
|
|
600
|
+
async (message) => {
|
|
601
|
+
if (!solanaChain)
|
|
602
|
+
throw new Error("Solana chain not available. Ensure SDK is connected.");
|
|
603
|
+
return await solanaChain.signMessage(message);
|
|
604
|
+
},
|
|
605
|
+
[solanaChain]
|
|
606
|
+
);
|
|
607
|
+
const signTransaction = useCallback3(
|
|
608
|
+
async (transaction) => {
|
|
609
|
+
if (!solanaChain)
|
|
610
|
+
throw new Error("Solana chain not available. Ensure SDK is connected.");
|
|
611
|
+
return await solanaChain.signTransaction(transaction);
|
|
612
|
+
},
|
|
613
|
+
[solanaChain]
|
|
614
|
+
);
|
|
615
|
+
const signAndSendTransaction = useCallback3(
|
|
616
|
+
async (transaction) => {
|
|
617
|
+
if (!solanaChain)
|
|
618
|
+
throw new Error("Solana chain not available. Ensure SDK is connected.");
|
|
619
|
+
return await solanaChain.signAndSendTransaction(transaction);
|
|
620
|
+
},
|
|
621
|
+
[solanaChain]
|
|
622
|
+
);
|
|
623
|
+
const connect = useCallback3(
|
|
624
|
+
async (options) => {
|
|
625
|
+
if (!solanaChain)
|
|
626
|
+
throw new Error("Solana chain not available. Ensure SDK is connected.");
|
|
627
|
+
return await solanaChain.connect(options);
|
|
628
|
+
},
|
|
629
|
+
[solanaChain]
|
|
630
|
+
);
|
|
640
631
|
const disconnect = useCallback3(async () => {
|
|
641
632
|
if (!solanaChain)
|
|
642
633
|
throw new Error("Solana chain not available. Ensure SDK is connected.");
|
|
643
634
|
return await solanaChain.disconnect();
|
|
644
635
|
}, [solanaChain]);
|
|
645
|
-
const switchNetwork = useCallback3(
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
636
|
+
const switchNetwork = useCallback3(
|
|
637
|
+
async (network) => {
|
|
638
|
+
if (!solanaChain)
|
|
639
|
+
throw new Error("Solana chain not available. Ensure SDK is connected.");
|
|
640
|
+
return await solanaChain.switchNetwork?.(network);
|
|
641
|
+
},
|
|
642
|
+
[solanaChain]
|
|
643
|
+
);
|
|
650
644
|
const getPublicKey = useCallback3(async () => {
|
|
651
645
|
if (!solanaChain)
|
|
652
646
|
return null;
|
|
@@ -682,26 +676,38 @@ function useEthereum() {
|
|
|
682
676
|
return null;
|
|
683
677
|
}
|
|
684
678
|
}, [sdk, isConnected]);
|
|
685
|
-
const request = useCallback4(
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
679
|
+
const request = useCallback4(
|
|
680
|
+
async (args) => {
|
|
681
|
+
if (!ethereumChain)
|
|
682
|
+
throw new Error("Ethereum chain not available. Ensure SDK is connected.");
|
|
683
|
+
return await ethereumChain.request(args);
|
|
684
|
+
},
|
|
685
|
+
[ethereumChain]
|
|
686
|
+
);
|
|
687
|
+
const signPersonalMessage = useCallback4(
|
|
688
|
+
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);
|
|
692
|
+
},
|
|
693
|
+
[ethereumChain]
|
|
694
|
+
);
|
|
695
|
+
const sendTransaction = useCallback4(
|
|
696
|
+
async (transaction) => {
|
|
697
|
+
if (!ethereumChain)
|
|
698
|
+
throw new Error("Ethereum chain not available. Ensure SDK is connected.");
|
|
699
|
+
return await ethereumChain.sendTransaction(transaction);
|
|
700
|
+
},
|
|
701
|
+
[ethereumChain]
|
|
702
|
+
);
|
|
703
|
+
const switchChain = useCallback4(
|
|
704
|
+
async (chainId) => {
|
|
705
|
+
if (!ethereumChain)
|
|
706
|
+
throw new Error("Ethereum chain not available. Ensure SDK is connected.");
|
|
707
|
+
return await ethereumChain.switchChain(chainId);
|
|
708
|
+
},
|
|
709
|
+
[ethereumChain]
|
|
710
|
+
);
|
|
705
711
|
const getChainId = useCallback4(async () => {
|
|
706
712
|
if (!ethereumChain)
|
|
707
713
|
throw new Error("Ethereum chain not available. Ensure SDK is connected.");
|
|
@@ -712,19 +718,25 @@ function useEthereum() {
|
|
|
712
718
|
throw new Error("Ethereum chain not available. Ensure SDK is connected.");
|
|
713
719
|
return await ethereumChain.getAccounts();
|
|
714
720
|
}, [ethereumChain]);
|
|
715
|
-
const signMessage = useCallback4(
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
721
|
+
const signMessage = useCallback4(
|
|
722
|
+
async (message) => {
|
|
723
|
+
const accounts = await getAccounts();
|
|
724
|
+
return await request({
|
|
725
|
+
method: "eth_sign",
|
|
726
|
+
params: [accounts[0], message]
|
|
727
|
+
});
|
|
728
|
+
},
|
|
729
|
+
[request, getAccounts]
|
|
730
|
+
);
|
|
731
|
+
const signTypedData = useCallback4(
|
|
732
|
+
async (typedData) => {
|
|
733
|
+
if (!ethereumChain)
|
|
734
|
+
throw new Error("Ethereum chain not available. Ensure SDK is connected.");
|
|
735
|
+
const accounts = await getAccounts();
|
|
736
|
+
return await ethereumChain.signTypedData(typedData, accounts[0]);
|
|
737
|
+
},
|
|
738
|
+
[ethereumChain, getAccounts]
|
|
739
|
+
);
|
|
728
740
|
return {
|
|
729
741
|
// Chain instance for advanced usage
|
|
730
742
|
ethereum: ethereumChain,
|
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.1",
|
|
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.
|
|
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/
|
|
56
|
-
"@phantom/sdk-types": "^1.0.0-beta.0",
|
|
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",
|
|
57
56
|
"@types/bs58": "^5.0.0",
|
|
58
57
|
"bs58": "^6.0.0",
|
|
59
58
|
"buffer": "^6.0.3"
|