@phantom/embedded-provider-core 0.1.10 → 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 +2 -3
- package/dist/index.d.mts +82 -8
- package/dist/index.d.ts +82 -8
- package/dist/index.js +349 -23
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +348 -24
- package/dist/index.mjs.map +1 -1
- package/package.json +11 -8
package/README.md
CHANGED
|
@@ -57,7 +57,7 @@ import {
|
|
|
57
57
|
// 1. Define your configuration
|
|
58
58
|
const config: EmbeddedProviderConfig = {
|
|
59
59
|
apiBaseUrl: "https://api.phantom.app",
|
|
60
|
-
|
|
60
|
+
appId: "your-app-id",
|
|
61
61
|
embeddedWalletType: "user-wallet", // or 'app-wallet'
|
|
62
62
|
addressTypes: ["solana", "ethereum"],
|
|
63
63
|
solanaProvider: "web3js",
|
|
@@ -271,7 +271,7 @@ try {
|
|
|
271
271
|
interface EmbeddedProviderConfig {
|
|
272
272
|
// Required
|
|
273
273
|
apiBaseUrl: string; // Phantom API base URL
|
|
274
|
-
|
|
274
|
+
appId: string;
|
|
275
275
|
embeddedWalletType: "app-wallet" | "user-wallet";
|
|
276
276
|
addressTypes: [AddressType, ...AddressType[]]; // Supported blockchain addresses
|
|
277
277
|
|
|
@@ -290,7 +290,6 @@ interface EmbeddedProviderConfig {
|
|
|
290
290
|
interface Session {
|
|
291
291
|
sessionId: string; // Unique session identifier
|
|
292
292
|
walletId: string; // Phantom wallet ID
|
|
293
|
-
organizationId: string; // Organization ID
|
|
294
293
|
keypair: {
|
|
295
294
|
// Cryptographic keypair
|
|
296
295
|
publicKey: string;
|
package/dist/index.d.mts
CHANGED
|
@@ -2,6 +2,7 @@ import { StamperWithKeyManagement } from '@phantom/sdk-types';
|
|
|
2
2
|
import { AddressType } from '@phantom/client';
|
|
3
3
|
import { NetworkId } from '@phantom/constants';
|
|
4
4
|
import { ParsedSignatureResult, ParsedTransactionResult } from '@phantom/parsers';
|
|
5
|
+
import { ISolanaChain, IEthereumChain, EthTransactionRequest } from '@phantom/chains';
|
|
5
6
|
|
|
6
7
|
interface Keypair {
|
|
7
8
|
publicKey: string;
|
|
@@ -17,6 +18,7 @@ interface Session {
|
|
|
17
18
|
sessionId: string;
|
|
18
19
|
walletId: string;
|
|
19
20
|
organizationId: string;
|
|
21
|
+
appId: string;
|
|
20
22
|
stamperInfo: StamperInfo;
|
|
21
23
|
keypair?: Keypair;
|
|
22
24
|
authProvider?: string;
|
|
@@ -65,21 +67,19 @@ interface AuthResult {
|
|
|
65
67
|
interface PhantomConnectOptions {
|
|
66
68
|
organizationId: string;
|
|
67
69
|
parentOrganizationId: string;
|
|
70
|
+
appId: string;
|
|
68
71
|
provider?: "google" | "apple";
|
|
69
72
|
redirectUrl?: string;
|
|
70
73
|
customAuthData?: Record<string, any>;
|
|
71
74
|
authUrl?: string;
|
|
72
75
|
sessionId: string;
|
|
73
|
-
appName?: string;
|
|
74
|
-
appLogo?: string;
|
|
75
76
|
}
|
|
76
77
|
interface JWTAuthOptions {
|
|
78
|
+
appId: string;
|
|
77
79
|
organizationId: string;
|
|
78
80
|
parentOrganizationId: string;
|
|
79
81
|
jwtToken: string;
|
|
80
82
|
customAuthData?: Record<string, any>;
|
|
81
|
-
appName?: string;
|
|
82
|
-
appLogo?: string;
|
|
83
83
|
}
|
|
84
84
|
interface AuthProvider {
|
|
85
85
|
authenticate(options: PhantomConnectOptions | JWTAuthOptions): Promise<void | AuthResult>;
|
|
@@ -128,6 +128,7 @@ interface AuthOptions {
|
|
|
128
128
|
}
|
|
129
129
|
interface EmbeddedProviderConfig {
|
|
130
130
|
apiBaseUrl: string;
|
|
131
|
+
appId: string;
|
|
131
132
|
organizationId: string;
|
|
132
133
|
authOptions?: {
|
|
133
134
|
authUrl?: string;
|
|
@@ -136,11 +137,9 @@ interface EmbeddedProviderConfig {
|
|
|
136
137
|
embeddedWalletType: "app-wallet" | "user-wallet" | (string & Record<never, never>);
|
|
137
138
|
addressTypes: [AddressType, ...AddressType[]];
|
|
138
139
|
solanaProvider: "web3js" | "kit" | (string & Record<never, never>);
|
|
139
|
-
appName?: string;
|
|
140
|
-
appLogo?: string;
|
|
141
140
|
}
|
|
142
141
|
|
|
143
|
-
type EmbeddedProviderEvent =
|
|
142
|
+
type EmbeddedProviderEvent = "connect" | "connect_start" | "connect_error" | "disconnect" | "error";
|
|
144
143
|
type EventCallback = (data?: any) => void;
|
|
145
144
|
declare class EmbeddedProvider {
|
|
146
145
|
private config;
|
|
@@ -154,6 +153,8 @@ declare class EmbeddedProvider {
|
|
|
154
153
|
private walletId;
|
|
155
154
|
private addresses;
|
|
156
155
|
private jwtAuth;
|
|
156
|
+
readonly solana: ISolanaChain;
|
|
157
|
+
readonly ethereum: IEthereumChain;
|
|
157
158
|
private eventListeners;
|
|
158
159
|
constructor(config: EmbeddedProviderConfig, platform: PlatformAdapter, logger: DebugLogger);
|
|
159
160
|
on(event: EmbeddedProviderEvent, callback: EventCallback): void;
|
|
@@ -189,6 +190,79 @@ declare function generateSessionId(): string;
|
|
|
189
190
|
|
|
190
191
|
declare function retryWithBackoff<T>(operation: () => Promise<T>, operationName: string, logger: DebugLogger, maxRetries?: number, baseDelay?: number): Promise<T>;
|
|
191
192
|
|
|
193
|
+
/**
|
|
194
|
+
* Embedded Solana chain implementation that is wallet adapter compliant
|
|
195
|
+
*/
|
|
196
|
+
declare class EmbeddedSolanaChain implements ISolanaChain {
|
|
197
|
+
private provider;
|
|
198
|
+
private currentNetworkId;
|
|
199
|
+
private _connected;
|
|
200
|
+
private _publicKey;
|
|
201
|
+
private eventEmitter;
|
|
202
|
+
constructor(provider: EmbeddedProvider);
|
|
203
|
+
get connected(): boolean;
|
|
204
|
+
get publicKey(): string | null;
|
|
205
|
+
private ensureConnected;
|
|
206
|
+
signMessage(message: string | Uint8Array): Promise<{
|
|
207
|
+
signature: Uint8Array;
|
|
208
|
+
publicKey: string;
|
|
209
|
+
}>;
|
|
210
|
+
signTransaction<T>(_transaction: T): Promise<T>;
|
|
211
|
+
signAndSendTransaction<T>(transaction: T): Promise<{
|
|
212
|
+
signature: string;
|
|
213
|
+
}>;
|
|
214
|
+
signAllTransactions<T>(transactions: T[]): Promise<T[]>;
|
|
215
|
+
connect(_options?: {
|
|
216
|
+
onlyIfTrusted?: boolean;
|
|
217
|
+
}): Promise<{
|
|
218
|
+
publicKey: string;
|
|
219
|
+
}>;
|
|
220
|
+
disconnect(): Promise<void>;
|
|
221
|
+
switchNetwork(network: "mainnet" | "devnet"): Promise<void>;
|
|
222
|
+
getPublicKey(): Promise<string | null>;
|
|
223
|
+
isConnected(): boolean;
|
|
224
|
+
private setupEventListeners;
|
|
225
|
+
private syncInitialState;
|
|
226
|
+
private updateConnectionState;
|
|
227
|
+
on(event: string, listener: (...args: any[]) => void): void;
|
|
228
|
+
off(event: string, listener: (...args: any[]) => void): void;
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
/**
|
|
232
|
+
* Embedded Ethereum chain implementation that is EIP-1193 compliant
|
|
233
|
+
*/
|
|
234
|
+
declare class EmbeddedEthereumChain implements IEthereumChain {
|
|
235
|
+
private provider;
|
|
236
|
+
private currentNetworkId;
|
|
237
|
+
private _connected;
|
|
238
|
+
private _accounts;
|
|
239
|
+
private eventEmitter;
|
|
240
|
+
constructor(provider: EmbeddedProvider);
|
|
241
|
+
get connected(): boolean;
|
|
242
|
+
get chainId(): string;
|
|
243
|
+
get accounts(): string[];
|
|
244
|
+
private ensureConnected;
|
|
245
|
+
request<T = any>(args: {
|
|
246
|
+
method: string;
|
|
247
|
+
params?: unknown[];
|
|
248
|
+
}): Promise<T>;
|
|
249
|
+
connect(): Promise<string[]>;
|
|
250
|
+
disconnect(): Promise<void>;
|
|
251
|
+
signPersonalMessage(message: string, address: string): Promise<string>;
|
|
252
|
+
signTypedData(typedData: any, address: string): Promise<string>;
|
|
253
|
+
sendTransaction(transaction: EthTransactionRequest): Promise<string>;
|
|
254
|
+
switchChain(chainId: number): Promise<void>;
|
|
255
|
+
getChainId(): Promise<number>;
|
|
256
|
+
getAccounts(): Promise<string[]>;
|
|
257
|
+
isConnected(): boolean;
|
|
258
|
+
private setupEventListeners;
|
|
259
|
+
private syncInitialState;
|
|
260
|
+
private updateConnectionState;
|
|
261
|
+
private handleEmbeddedRequest;
|
|
262
|
+
on(event: string, listener: (...args: any[]) => void): void;
|
|
263
|
+
off(event: string, listener: (...args: any[]) => void): void;
|
|
264
|
+
}
|
|
265
|
+
|
|
192
266
|
/**
|
|
193
267
|
* Constants for authenticator lifecycle management
|
|
194
268
|
*/
|
|
@@ -205,4 +279,4 @@ declare const AUTHENTICATOR_EXPIRATION_TIME_MS: number;
|
|
|
205
279
|
*/
|
|
206
280
|
declare const AUTHENTICATOR_RENEWAL_WINDOW_MS: number;
|
|
207
281
|
|
|
208
|
-
export { AUTHENTICATOR_EXPIRATION_TIME_MS, AUTHENTICATOR_RENEWAL_WINDOW_MS, AuthOptions, AuthProvider, AuthResult, ConnectResult, DebugLogger, EmbeddedProvider, EmbeddedProviderConfig, EmbeddedProviderEvent, EmbeddedStorage, EventCallback, JWTAuth, JWTAuthOptions, Keypair, PhantomConnectOptions, PlatformAdapter, Session, SignAndSendTransactionParams, SignMessageParams, SignMessageResult, SignedTransaction, StamperInfo, URLParamsAccessor, WalletAddress, generateSessionId, retryWithBackoff };
|
|
282
|
+
export { AUTHENTICATOR_EXPIRATION_TIME_MS, AUTHENTICATOR_RENEWAL_WINDOW_MS, AuthOptions, AuthProvider, AuthResult, ConnectResult, DebugLogger, EmbeddedEthereumChain, EmbeddedProvider, EmbeddedProviderConfig, EmbeddedProviderEvent, EmbeddedSolanaChain, EmbeddedStorage, EventCallback, JWTAuth, JWTAuthOptions, Keypair, PhantomConnectOptions, PlatformAdapter, Session, SignAndSendTransactionParams, SignMessageParams, SignMessageResult, SignedTransaction, StamperInfo, URLParamsAccessor, WalletAddress, generateSessionId, retryWithBackoff };
|
package/dist/index.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ import { StamperWithKeyManagement } from '@phantom/sdk-types';
|
|
|
2
2
|
import { AddressType } from '@phantom/client';
|
|
3
3
|
import { NetworkId } from '@phantom/constants';
|
|
4
4
|
import { ParsedSignatureResult, ParsedTransactionResult } from '@phantom/parsers';
|
|
5
|
+
import { ISolanaChain, IEthereumChain, EthTransactionRequest } from '@phantom/chains';
|
|
5
6
|
|
|
6
7
|
interface Keypair {
|
|
7
8
|
publicKey: string;
|
|
@@ -17,6 +18,7 @@ interface Session {
|
|
|
17
18
|
sessionId: string;
|
|
18
19
|
walletId: string;
|
|
19
20
|
organizationId: string;
|
|
21
|
+
appId: string;
|
|
20
22
|
stamperInfo: StamperInfo;
|
|
21
23
|
keypair?: Keypair;
|
|
22
24
|
authProvider?: string;
|
|
@@ -65,21 +67,19 @@ interface AuthResult {
|
|
|
65
67
|
interface PhantomConnectOptions {
|
|
66
68
|
organizationId: string;
|
|
67
69
|
parentOrganizationId: string;
|
|
70
|
+
appId: string;
|
|
68
71
|
provider?: "google" | "apple";
|
|
69
72
|
redirectUrl?: string;
|
|
70
73
|
customAuthData?: Record<string, any>;
|
|
71
74
|
authUrl?: string;
|
|
72
75
|
sessionId: string;
|
|
73
|
-
appName?: string;
|
|
74
|
-
appLogo?: string;
|
|
75
76
|
}
|
|
76
77
|
interface JWTAuthOptions {
|
|
78
|
+
appId: string;
|
|
77
79
|
organizationId: string;
|
|
78
80
|
parentOrganizationId: string;
|
|
79
81
|
jwtToken: string;
|
|
80
82
|
customAuthData?: Record<string, any>;
|
|
81
|
-
appName?: string;
|
|
82
|
-
appLogo?: string;
|
|
83
83
|
}
|
|
84
84
|
interface AuthProvider {
|
|
85
85
|
authenticate(options: PhantomConnectOptions | JWTAuthOptions): Promise<void | AuthResult>;
|
|
@@ -128,6 +128,7 @@ interface AuthOptions {
|
|
|
128
128
|
}
|
|
129
129
|
interface EmbeddedProviderConfig {
|
|
130
130
|
apiBaseUrl: string;
|
|
131
|
+
appId: string;
|
|
131
132
|
organizationId: string;
|
|
132
133
|
authOptions?: {
|
|
133
134
|
authUrl?: string;
|
|
@@ -136,11 +137,9 @@ interface EmbeddedProviderConfig {
|
|
|
136
137
|
embeddedWalletType: "app-wallet" | "user-wallet" | (string & Record<never, never>);
|
|
137
138
|
addressTypes: [AddressType, ...AddressType[]];
|
|
138
139
|
solanaProvider: "web3js" | "kit" | (string & Record<never, never>);
|
|
139
|
-
appName?: string;
|
|
140
|
-
appLogo?: string;
|
|
141
140
|
}
|
|
142
141
|
|
|
143
|
-
type EmbeddedProviderEvent =
|
|
142
|
+
type EmbeddedProviderEvent = "connect" | "connect_start" | "connect_error" | "disconnect" | "error";
|
|
144
143
|
type EventCallback = (data?: any) => void;
|
|
145
144
|
declare class EmbeddedProvider {
|
|
146
145
|
private config;
|
|
@@ -154,6 +153,8 @@ declare class EmbeddedProvider {
|
|
|
154
153
|
private walletId;
|
|
155
154
|
private addresses;
|
|
156
155
|
private jwtAuth;
|
|
156
|
+
readonly solana: ISolanaChain;
|
|
157
|
+
readonly ethereum: IEthereumChain;
|
|
157
158
|
private eventListeners;
|
|
158
159
|
constructor(config: EmbeddedProviderConfig, platform: PlatformAdapter, logger: DebugLogger);
|
|
159
160
|
on(event: EmbeddedProviderEvent, callback: EventCallback): void;
|
|
@@ -189,6 +190,79 @@ declare function generateSessionId(): string;
|
|
|
189
190
|
|
|
190
191
|
declare function retryWithBackoff<T>(operation: () => Promise<T>, operationName: string, logger: DebugLogger, maxRetries?: number, baseDelay?: number): Promise<T>;
|
|
191
192
|
|
|
193
|
+
/**
|
|
194
|
+
* Embedded Solana chain implementation that is wallet adapter compliant
|
|
195
|
+
*/
|
|
196
|
+
declare class EmbeddedSolanaChain implements ISolanaChain {
|
|
197
|
+
private provider;
|
|
198
|
+
private currentNetworkId;
|
|
199
|
+
private _connected;
|
|
200
|
+
private _publicKey;
|
|
201
|
+
private eventEmitter;
|
|
202
|
+
constructor(provider: EmbeddedProvider);
|
|
203
|
+
get connected(): boolean;
|
|
204
|
+
get publicKey(): string | null;
|
|
205
|
+
private ensureConnected;
|
|
206
|
+
signMessage(message: string | Uint8Array): Promise<{
|
|
207
|
+
signature: Uint8Array;
|
|
208
|
+
publicKey: string;
|
|
209
|
+
}>;
|
|
210
|
+
signTransaction<T>(_transaction: T): Promise<T>;
|
|
211
|
+
signAndSendTransaction<T>(transaction: T): Promise<{
|
|
212
|
+
signature: string;
|
|
213
|
+
}>;
|
|
214
|
+
signAllTransactions<T>(transactions: T[]): Promise<T[]>;
|
|
215
|
+
connect(_options?: {
|
|
216
|
+
onlyIfTrusted?: boolean;
|
|
217
|
+
}): Promise<{
|
|
218
|
+
publicKey: string;
|
|
219
|
+
}>;
|
|
220
|
+
disconnect(): Promise<void>;
|
|
221
|
+
switchNetwork(network: "mainnet" | "devnet"): Promise<void>;
|
|
222
|
+
getPublicKey(): Promise<string | null>;
|
|
223
|
+
isConnected(): boolean;
|
|
224
|
+
private setupEventListeners;
|
|
225
|
+
private syncInitialState;
|
|
226
|
+
private updateConnectionState;
|
|
227
|
+
on(event: string, listener: (...args: any[]) => void): void;
|
|
228
|
+
off(event: string, listener: (...args: any[]) => void): void;
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
/**
|
|
232
|
+
* Embedded Ethereum chain implementation that is EIP-1193 compliant
|
|
233
|
+
*/
|
|
234
|
+
declare class EmbeddedEthereumChain implements IEthereumChain {
|
|
235
|
+
private provider;
|
|
236
|
+
private currentNetworkId;
|
|
237
|
+
private _connected;
|
|
238
|
+
private _accounts;
|
|
239
|
+
private eventEmitter;
|
|
240
|
+
constructor(provider: EmbeddedProvider);
|
|
241
|
+
get connected(): boolean;
|
|
242
|
+
get chainId(): string;
|
|
243
|
+
get accounts(): string[];
|
|
244
|
+
private ensureConnected;
|
|
245
|
+
request<T = any>(args: {
|
|
246
|
+
method: string;
|
|
247
|
+
params?: unknown[];
|
|
248
|
+
}): Promise<T>;
|
|
249
|
+
connect(): Promise<string[]>;
|
|
250
|
+
disconnect(): Promise<void>;
|
|
251
|
+
signPersonalMessage(message: string, address: string): Promise<string>;
|
|
252
|
+
signTypedData(typedData: any, address: string): Promise<string>;
|
|
253
|
+
sendTransaction(transaction: EthTransactionRequest): Promise<string>;
|
|
254
|
+
switchChain(chainId: number): Promise<void>;
|
|
255
|
+
getChainId(): Promise<number>;
|
|
256
|
+
getAccounts(): Promise<string[]>;
|
|
257
|
+
isConnected(): boolean;
|
|
258
|
+
private setupEventListeners;
|
|
259
|
+
private syncInitialState;
|
|
260
|
+
private updateConnectionState;
|
|
261
|
+
private handleEmbeddedRequest;
|
|
262
|
+
on(event: string, listener: (...args: any[]) => void): void;
|
|
263
|
+
off(event: string, listener: (...args: any[]) => void): void;
|
|
264
|
+
}
|
|
265
|
+
|
|
192
266
|
/**
|
|
193
267
|
* Constants for authenticator lifecycle management
|
|
194
268
|
*/
|
|
@@ -205,4 +279,4 @@ declare const AUTHENTICATOR_EXPIRATION_TIME_MS: number;
|
|
|
205
279
|
*/
|
|
206
280
|
declare const AUTHENTICATOR_RENEWAL_WINDOW_MS: number;
|
|
207
281
|
|
|
208
|
-
export { AUTHENTICATOR_EXPIRATION_TIME_MS, AUTHENTICATOR_RENEWAL_WINDOW_MS, AuthOptions, AuthProvider, AuthResult, ConnectResult, DebugLogger, EmbeddedProvider, EmbeddedProviderConfig, EmbeddedProviderEvent, EmbeddedStorage, EventCallback, JWTAuth, JWTAuthOptions, Keypair, PhantomConnectOptions, PlatformAdapter, Session, SignAndSendTransactionParams, SignMessageParams, SignMessageResult, SignedTransaction, StamperInfo, URLParamsAccessor, WalletAddress, generateSessionId, retryWithBackoff };
|
|
282
|
+
export { AUTHENTICATOR_EXPIRATION_TIME_MS, AUTHENTICATOR_RENEWAL_WINDOW_MS, AuthOptions, AuthProvider, AuthResult, ConnectResult, DebugLogger, EmbeddedEthereumChain, EmbeddedProvider, EmbeddedProviderConfig, EmbeddedProviderEvent, EmbeddedSolanaChain, EmbeddedStorage, EventCallback, JWTAuth, JWTAuthOptions, Keypair, PhantomConnectOptions, PlatformAdapter, Session, SignAndSendTransactionParams, SignMessageParams, SignMessageResult, SignedTransaction, StamperInfo, URLParamsAccessor, WalletAddress, generateSessionId, retryWithBackoff };
|