@phantom/browser-sdk 0.0.2 → 0.0.3
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/dist/solana/index.d.ts +88 -1
- package/dist/solana/index.js +49 -1
- package/dist/solana/index.mjs +49 -1
- package/package.json +4 -1
package/dist/solana/index.d.ts
CHANGED
|
@@ -1,7 +1,94 @@
|
|
|
1
1
|
import { ChainPlugin } from '../index.js';
|
|
2
|
+
import { PublicKey, Transaction, VersionedTransaction, SendOptions } from '@solana/web3.js';
|
|
3
|
+
|
|
4
|
+
type SolanaSignInData = {
|
|
5
|
+
domain?: string;
|
|
6
|
+
address?: string;
|
|
7
|
+
statement?: string;
|
|
8
|
+
uri?: string;
|
|
9
|
+
version?: string;
|
|
10
|
+
chainId?: string;
|
|
11
|
+
nonce?: string;
|
|
12
|
+
issuedAt?: string;
|
|
13
|
+
expirationTime?: string;
|
|
14
|
+
notBefore?: string;
|
|
15
|
+
requestId?: string;
|
|
16
|
+
resources?: string[];
|
|
17
|
+
};
|
|
18
|
+
type DisplayEncoding = "utf8" | "hex";
|
|
19
|
+
interface PhantomSolanaProvider {
|
|
20
|
+
isPhantom: boolean;
|
|
21
|
+
publicKey: PublicKey | null;
|
|
22
|
+
isConnected: boolean;
|
|
23
|
+
connect: (opts?: {
|
|
24
|
+
onlyIfTrusted?: boolean;
|
|
25
|
+
}) => Promise<{
|
|
26
|
+
publicKey: PublicKey;
|
|
27
|
+
}>;
|
|
28
|
+
disconnect: () => Promise<void>;
|
|
29
|
+
signMessage: (message: Uint8Array, display?: DisplayEncoding) => Promise<{
|
|
30
|
+
signature: Uint8Array;
|
|
31
|
+
publicKey: PublicKey;
|
|
32
|
+
}>;
|
|
33
|
+
signIn: (signInData: SolanaSignInData) => Promise<{
|
|
34
|
+
address: PublicKey;
|
|
35
|
+
signature: Uint8Array;
|
|
36
|
+
signedMessage: Uint8Array;
|
|
37
|
+
}>;
|
|
38
|
+
signAndSendTransaction: (transaction: Transaction | VersionedTransaction, options?: SendOptions) => Promise<{
|
|
39
|
+
signature: string;
|
|
40
|
+
publicKey?: string;
|
|
41
|
+
}>;
|
|
42
|
+
signAllTransactions: (transactions: (Transaction | VersionedTransaction)[]) => Promise<(Transaction | VersionedTransaction)[]>;
|
|
43
|
+
signTransaction: (transaction: Transaction | VersionedTransaction) => Promise<Transaction | VersionedTransaction>;
|
|
44
|
+
}
|
|
45
|
+
interface SolanaOperationOptions {
|
|
46
|
+
getProvider?: () => PhantomSolanaProvider | null;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Signs a message using the Phantom provider.
|
|
51
|
+
* @param message The message to sign (as a Uint8Array).
|
|
52
|
+
* @param display The display encoding for the message (optional, defaults to utf8).
|
|
53
|
+
* @param options Optional parameters, including a custom getProvider function.
|
|
54
|
+
* @returns A promise that resolves with the signature and public key.
|
|
55
|
+
* @throws Error if Phantom provider is not found or if the operation fails.
|
|
56
|
+
*/
|
|
57
|
+
declare function signMessage(message: Uint8Array, display?: DisplayEncoding, options?: SolanaOperationOptions): Promise<{
|
|
58
|
+
signature: Uint8Array;
|
|
59
|
+
publicKey: PublicKey;
|
|
60
|
+
}>;
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Signs in with Solana using the Phantom provider.
|
|
64
|
+
* @param signInData The sign-in data.
|
|
65
|
+
* @param options Optional parameters, including a custom getProvider function.
|
|
66
|
+
* @returns A promise that resolves with the address, signature, and signed message.
|
|
67
|
+
* @throws Error if Phantom provider is not found or if the operation fails.
|
|
68
|
+
*/
|
|
69
|
+
declare function signIn(signInData: SolanaSignInData, options?: SolanaOperationOptions): Promise<{
|
|
70
|
+
address: PublicKey;
|
|
71
|
+
signature: Uint8Array;
|
|
72
|
+
signedMessage: Uint8Array;
|
|
73
|
+
}>;
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Signs and sends a transaction using the Phantom provider.
|
|
77
|
+
* @param transaction The transaction to sign and send.
|
|
78
|
+
* @param options Options for sending the transaction and other operations.
|
|
79
|
+
* @returns A promise that resolves with the transaction signature and optionally the public key.
|
|
80
|
+
* @throws Error if Phantom provider is not found or if the operation fails.
|
|
81
|
+
*/
|
|
82
|
+
declare function signAndSendTransaction(transaction: Transaction | VersionedTransaction, operationOptions?: SolanaOperationOptions): Promise<{
|
|
83
|
+
signature: string;
|
|
84
|
+
publicKey?: string;
|
|
85
|
+
}>;
|
|
2
86
|
|
|
3
87
|
type Solana = {
|
|
4
|
-
getProvider: () =>
|
|
88
|
+
getProvider: () => PhantomSolanaProvider | null;
|
|
89
|
+
signMessage: typeof signMessage;
|
|
90
|
+
signIn: typeof signIn;
|
|
91
|
+
signAndSendTransaction: typeof signAndSendTransaction;
|
|
5
92
|
};
|
|
6
93
|
declare function createSolanaPlugin(): ChainPlugin<Solana>;
|
|
7
94
|
|
package/dist/solana/index.js
CHANGED
|
@@ -29,9 +29,57 @@ function getProvider() {
|
|
|
29
29
|
return window.phantom?.solana ?? null;
|
|
30
30
|
}
|
|
31
31
|
|
|
32
|
+
// src/solana/signMessage.ts
|
|
33
|
+
async function signMessage(message, display, options) {
|
|
34
|
+
const getProviderFn = options?.getProvider || getProvider;
|
|
35
|
+
const provider = getProviderFn();
|
|
36
|
+
if (!provider) {
|
|
37
|
+
throw new Error("Phantom provider not found.");
|
|
38
|
+
}
|
|
39
|
+
if (!provider.signMessage) {
|
|
40
|
+
throw new Error("The connected provider does not support signMessage.");
|
|
41
|
+
}
|
|
42
|
+
if (!provider.isConnected) {
|
|
43
|
+
throw new Error("Provider is not connected.");
|
|
44
|
+
}
|
|
45
|
+
return provider.signMessage(message, display);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// src/solana/signIn.ts
|
|
49
|
+
async function signIn(signInData, options) {
|
|
50
|
+
const getProviderFn = options?.getProvider || getProvider;
|
|
51
|
+
const provider = getProviderFn();
|
|
52
|
+
if (!provider) {
|
|
53
|
+
throw new Error("Phantom provider not found.");
|
|
54
|
+
}
|
|
55
|
+
if (!provider.signIn) {
|
|
56
|
+
throw new Error("The connected provider does not support signIn.");
|
|
57
|
+
}
|
|
58
|
+
return provider.signIn(signInData);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// src/solana/signAndSendTransaction.ts
|
|
62
|
+
async function signAndSendTransaction(transaction, operationOptions) {
|
|
63
|
+
const getProviderFn = operationOptions?.getProvider || getProvider;
|
|
64
|
+
const provider = getProviderFn();
|
|
65
|
+
if (!provider) {
|
|
66
|
+
throw new Error("Phantom provider not found.");
|
|
67
|
+
}
|
|
68
|
+
if (!provider.signAndSendTransaction) {
|
|
69
|
+
throw new Error("The connected provider does not support signAndSendTransaction.");
|
|
70
|
+
}
|
|
71
|
+
if (!provider.isConnected) {
|
|
72
|
+
throw new Error("Provider is not connected.");
|
|
73
|
+
}
|
|
74
|
+
return provider.signAndSendTransaction(transaction);
|
|
75
|
+
}
|
|
76
|
+
|
|
32
77
|
// src/solana/plugin.ts
|
|
33
78
|
var solana = {
|
|
34
|
-
getProvider
|
|
79
|
+
getProvider,
|
|
80
|
+
signMessage,
|
|
81
|
+
signIn,
|
|
82
|
+
signAndSendTransaction
|
|
35
83
|
};
|
|
36
84
|
function createSolanaPlugin() {
|
|
37
85
|
return {
|
package/dist/solana/index.mjs
CHANGED
|
@@ -3,9 +3,57 @@ function getProvider() {
|
|
|
3
3
|
return window.phantom?.solana ?? null;
|
|
4
4
|
}
|
|
5
5
|
|
|
6
|
+
// src/solana/signMessage.ts
|
|
7
|
+
async function signMessage(message, display, options) {
|
|
8
|
+
const getProviderFn = options?.getProvider || getProvider;
|
|
9
|
+
const provider = getProviderFn();
|
|
10
|
+
if (!provider) {
|
|
11
|
+
throw new Error("Phantom provider not found.");
|
|
12
|
+
}
|
|
13
|
+
if (!provider.signMessage) {
|
|
14
|
+
throw new Error("The connected provider does not support signMessage.");
|
|
15
|
+
}
|
|
16
|
+
if (!provider.isConnected) {
|
|
17
|
+
throw new Error("Provider is not connected.");
|
|
18
|
+
}
|
|
19
|
+
return provider.signMessage(message, display);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
// src/solana/signIn.ts
|
|
23
|
+
async function signIn(signInData, options) {
|
|
24
|
+
const getProviderFn = options?.getProvider || getProvider;
|
|
25
|
+
const provider = getProviderFn();
|
|
26
|
+
if (!provider) {
|
|
27
|
+
throw new Error("Phantom provider not found.");
|
|
28
|
+
}
|
|
29
|
+
if (!provider.signIn) {
|
|
30
|
+
throw new Error("The connected provider does not support signIn.");
|
|
31
|
+
}
|
|
32
|
+
return provider.signIn(signInData);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// src/solana/signAndSendTransaction.ts
|
|
36
|
+
async function signAndSendTransaction(transaction, operationOptions) {
|
|
37
|
+
const getProviderFn = operationOptions?.getProvider || getProvider;
|
|
38
|
+
const provider = getProviderFn();
|
|
39
|
+
if (!provider) {
|
|
40
|
+
throw new Error("Phantom provider not found.");
|
|
41
|
+
}
|
|
42
|
+
if (!provider.signAndSendTransaction) {
|
|
43
|
+
throw new Error("The connected provider does not support signAndSendTransaction.");
|
|
44
|
+
}
|
|
45
|
+
if (!provider.isConnected) {
|
|
46
|
+
throw new Error("Provider is not connected.");
|
|
47
|
+
}
|
|
48
|
+
return provider.signAndSendTransaction(transaction);
|
|
49
|
+
}
|
|
50
|
+
|
|
6
51
|
// src/solana/plugin.ts
|
|
7
52
|
var solana = {
|
|
8
|
-
getProvider
|
|
53
|
+
getProvider,
|
|
54
|
+
signMessage,
|
|
55
|
+
signIn,
|
|
56
|
+
signAndSendTransaction
|
|
9
57
|
};
|
|
10
58
|
function createSolanaPlugin() {
|
|
11
59
|
return {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@phantom/browser-sdk",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.3",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"module": "dist/index.mjs",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -30,5 +30,8 @@
|
|
|
30
30
|
"eslint": "8.53.0",
|
|
31
31
|
"tsup": "^6.7.0",
|
|
32
32
|
"typescript": "^5.0.4"
|
|
33
|
+
},
|
|
34
|
+
"dependencies": {
|
|
35
|
+
"@solana/web3.js": "^1.98.2"
|
|
33
36
|
}
|
|
34
37
|
}
|