@phantom/embedded-provider-core 1.0.0 → 1.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/index.d.mts +4 -8
- package/dist/index.d.ts +4 -8
- package/dist/index.js +24 -46
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +24 -46
- package/dist/index.mjs.map +1 -1
- package/package.json +9 -9
package/dist/index.d.mts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { AddressType, SpendingLimitError } from '@phantom/client';
|
|
2
2
|
import { NetworkId, ClientSideSdkHeaders } from '@phantom/constants';
|
|
3
3
|
import { ParsedSignatureResult, ParsedTransactionResult } from '@phantom/parsers';
|
|
4
|
-
import { StamperWithKeyManagement, Transaction, VersionedTransaction } from '@phantom/sdk-types';
|
|
4
|
+
import { Algorithm, StamperWithKeyManagement, Transaction, VersionedTransaction } from '@phantom/sdk-types';
|
|
5
5
|
import { ISolanaChain, IEthereumChain, EthTransactionRequest } from '@phantom/chain-interfaces';
|
|
6
6
|
|
|
7
7
|
interface WalletAddress {
|
|
@@ -123,6 +123,7 @@ interface PhantomConnectOptions {
|
|
|
123
123
|
sessionId: string;
|
|
124
124
|
clearPreviousSession?: boolean;
|
|
125
125
|
allowRefresh?: boolean;
|
|
126
|
+
algorithm?: Algorithm;
|
|
126
127
|
}
|
|
127
128
|
interface AuthProvider {
|
|
128
129
|
authenticate(options: PhantomConnectOptions): Promise<void | AuthResult>;
|
|
@@ -163,6 +164,7 @@ interface ConnectStartEventData {
|
|
|
163
164
|
authOptions?: {
|
|
164
165
|
provider?: string;
|
|
165
166
|
};
|
|
167
|
+
walletId?: string;
|
|
166
168
|
}
|
|
167
169
|
interface ConnectErrorEventData {
|
|
168
170
|
error: string;
|
|
@@ -240,12 +242,11 @@ declare function retryWithBackoff<T>(operation: () => Promise<T>, operationName:
|
|
|
240
242
|
declare class EmbeddedSolanaChain implements ISolanaChain {
|
|
241
243
|
private provider;
|
|
242
244
|
private currentNetworkId;
|
|
243
|
-
private _connected;
|
|
244
245
|
private _publicKey;
|
|
245
246
|
private eventEmitter;
|
|
246
247
|
constructor(provider: EmbeddedProvider);
|
|
247
|
-
get connected(): boolean;
|
|
248
248
|
get publicKey(): string | null;
|
|
249
|
+
get isConnected(): boolean;
|
|
249
250
|
private ensureConnected;
|
|
250
251
|
signMessage(message: string | Uint8Array): Promise<{
|
|
251
252
|
signature: Uint8Array;
|
|
@@ -266,11 +267,8 @@ declare class EmbeddedSolanaChain implements ISolanaChain {
|
|
|
266
267
|
}>;
|
|
267
268
|
disconnect(): Promise<void>;
|
|
268
269
|
switchNetwork(network: "mainnet" | "devnet"): Promise<void>;
|
|
269
|
-
getPublicKey(): Promise<string | null>;
|
|
270
|
-
isConnected(): boolean;
|
|
271
270
|
private setupEventListeners;
|
|
272
271
|
private syncInitialState;
|
|
273
|
-
private updateConnectionState;
|
|
274
272
|
on(event: string, listener: (...args: any[]) => void): void;
|
|
275
273
|
off(event: string, listener: (...args: any[]) => void): void;
|
|
276
274
|
}
|
|
@@ -281,11 +279,9 @@ declare class EmbeddedSolanaChain implements ISolanaChain {
|
|
|
281
279
|
declare class EmbeddedEthereumChain implements IEthereumChain {
|
|
282
280
|
private provider;
|
|
283
281
|
private currentNetworkId;
|
|
284
|
-
private _connected;
|
|
285
282
|
private _accounts;
|
|
286
283
|
private eventEmitter;
|
|
287
284
|
constructor(provider: EmbeddedProvider);
|
|
288
|
-
get connected(): boolean;
|
|
289
285
|
get chainId(): string;
|
|
290
286
|
get accounts(): string[];
|
|
291
287
|
private ensureConnected;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { AddressType, SpendingLimitError } from '@phantom/client';
|
|
2
2
|
import { NetworkId, ClientSideSdkHeaders } from '@phantom/constants';
|
|
3
3
|
import { ParsedSignatureResult, ParsedTransactionResult } from '@phantom/parsers';
|
|
4
|
-
import { StamperWithKeyManagement, Transaction, VersionedTransaction } from '@phantom/sdk-types';
|
|
4
|
+
import { Algorithm, StamperWithKeyManagement, Transaction, VersionedTransaction } from '@phantom/sdk-types';
|
|
5
5
|
import { ISolanaChain, IEthereumChain, EthTransactionRequest } from '@phantom/chain-interfaces';
|
|
6
6
|
|
|
7
7
|
interface WalletAddress {
|
|
@@ -123,6 +123,7 @@ interface PhantomConnectOptions {
|
|
|
123
123
|
sessionId: string;
|
|
124
124
|
clearPreviousSession?: boolean;
|
|
125
125
|
allowRefresh?: boolean;
|
|
126
|
+
algorithm?: Algorithm;
|
|
126
127
|
}
|
|
127
128
|
interface AuthProvider {
|
|
128
129
|
authenticate(options: PhantomConnectOptions): Promise<void | AuthResult>;
|
|
@@ -163,6 +164,7 @@ interface ConnectStartEventData {
|
|
|
163
164
|
authOptions?: {
|
|
164
165
|
provider?: string;
|
|
165
166
|
};
|
|
167
|
+
walletId?: string;
|
|
166
168
|
}
|
|
167
169
|
interface ConnectErrorEventData {
|
|
168
170
|
error: string;
|
|
@@ -240,12 +242,11 @@ declare function retryWithBackoff<T>(operation: () => Promise<T>, operationName:
|
|
|
240
242
|
declare class EmbeddedSolanaChain implements ISolanaChain {
|
|
241
243
|
private provider;
|
|
242
244
|
private currentNetworkId;
|
|
243
|
-
private _connected;
|
|
244
245
|
private _publicKey;
|
|
245
246
|
private eventEmitter;
|
|
246
247
|
constructor(provider: EmbeddedProvider);
|
|
247
|
-
get connected(): boolean;
|
|
248
248
|
get publicKey(): string | null;
|
|
249
|
+
get isConnected(): boolean;
|
|
249
250
|
private ensureConnected;
|
|
250
251
|
signMessage(message: string | Uint8Array): Promise<{
|
|
251
252
|
signature: Uint8Array;
|
|
@@ -266,11 +267,8 @@ declare class EmbeddedSolanaChain implements ISolanaChain {
|
|
|
266
267
|
}>;
|
|
267
268
|
disconnect(): Promise<void>;
|
|
268
269
|
switchNetwork(network: "mainnet" | "devnet"): Promise<void>;
|
|
269
|
-
getPublicKey(): Promise<string | null>;
|
|
270
|
-
isConnected(): boolean;
|
|
271
270
|
private setupEventListeners;
|
|
272
271
|
private syncInitialState;
|
|
273
|
-
private updateConnectionState;
|
|
274
272
|
on(event: string, listener: (...args: any[]) => void): void;
|
|
275
273
|
off(event: string, listener: (...args: any[]) => void): void;
|
|
276
274
|
}
|
|
@@ -281,11 +279,9 @@ declare class EmbeddedSolanaChain implements ISolanaChain {
|
|
|
281
279
|
declare class EmbeddedEthereumChain implements IEthereumChain {
|
|
282
280
|
private provider;
|
|
283
281
|
private currentNetworkId;
|
|
284
|
-
private _connected;
|
|
285
282
|
private _accounts;
|
|
286
283
|
private eventEmitter;
|
|
287
284
|
constructor(provider: EmbeddedProvider);
|
|
288
|
-
get connected(): boolean;
|
|
289
285
|
get chainId(): string;
|
|
290
286
|
get accounts(): string[];
|
|
291
287
|
private ensureConnected;
|
package/dist/index.js
CHANGED
|
@@ -63,21 +63,19 @@ var EmbeddedSolanaChain = class {
|
|
|
63
63
|
constructor(provider) {
|
|
64
64
|
this.provider = provider;
|
|
65
65
|
this.currentNetworkId = import_constants.NetworkId.SOLANA_MAINNET;
|
|
66
|
-
this._connected = false;
|
|
67
66
|
this._publicKey = null;
|
|
68
67
|
this.eventEmitter = new import_eventemitter3.EventEmitter();
|
|
69
68
|
this.setupEventListeners();
|
|
70
69
|
this.syncInitialState();
|
|
71
70
|
}
|
|
72
|
-
// Wallet adapter compliant properties
|
|
73
|
-
get connected() {
|
|
74
|
-
return this._connected;
|
|
75
|
-
}
|
|
76
71
|
get publicKey() {
|
|
77
72
|
return this._publicKey;
|
|
78
73
|
}
|
|
74
|
+
get isConnected() {
|
|
75
|
+
return this._publicKey !== null;
|
|
76
|
+
}
|
|
79
77
|
ensureConnected() {
|
|
80
|
-
if (!this.
|
|
78
|
+
if (!this.isConnected) {
|
|
81
79
|
throw new Error("Solana chain not available. Ensure SDK is connected.");
|
|
82
80
|
}
|
|
83
81
|
}
|
|
@@ -135,7 +133,7 @@ var EmbeddedSolanaChain = class {
|
|
|
135
133
|
const solanaAddr = addresses.find((a) => a.addressType === "Solana");
|
|
136
134
|
if (!solanaAddr)
|
|
137
135
|
throw new Error("No Solana address found");
|
|
138
|
-
this.
|
|
136
|
+
this._publicKey = solanaAddr.address;
|
|
139
137
|
return Promise.resolve({ publicKey: solanaAddr.address });
|
|
140
138
|
}
|
|
141
139
|
async disconnect() {
|
|
@@ -145,41 +143,25 @@ var EmbeddedSolanaChain = class {
|
|
|
145
143
|
this.currentNetworkId = network === "mainnet" ? import_constants.NetworkId.SOLANA_MAINNET : import_constants.NetworkId.SOLANA_DEVNET;
|
|
146
144
|
return Promise.resolve();
|
|
147
145
|
}
|
|
148
|
-
getPublicKey() {
|
|
149
|
-
if (!this.provider.isConnected())
|
|
150
|
-
return Promise.resolve(null);
|
|
151
|
-
const addresses = this.provider.getAddresses();
|
|
152
|
-
const solanaAddr = addresses.find((a) => a.addressType === "Solana");
|
|
153
|
-
return Promise.resolve(solanaAddr?.address || null);
|
|
154
|
-
}
|
|
155
|
-
isConnected() {
|
|
156
|
-
return this._connected && this.provider.isConnected();
|
|
157
|
-
}
|
|
158
146
|
setupEventListeners() {
|
|
159
147
|
this.provider.on("connect", (data) => {
|
|
160
148
|
const solanaAddress = data.addresses?.find((addr) => addr.addressType === "Solana");
|
|
161
149
|
if (solanaAddress) {
|
|
162
|
-
this.
|
|
150
|
+
this._publicKey = solanaAddress.address;
|
|
163
151
|
this.eventEmitter.emit("connect", solanaAddress.address);
|
|
164
152
|
}
|
|
165
153
|
});
|
|
166
154
|
this.provider.on("disconnect", () => {
|
|
167
|
-
this.
|
|
155
|
+
this._publicKey = null;
|
|
168
156
|
this.eventEmitter.emit("disconnect");
|
|
169
157
|
});
|
|
170
158
|
}
|
|
171
159
|
syncInitialState() {
|
|
172
|
-
if (this.provider.isConnected())
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
updateConnectionState(connected, publicKey) {
|
|
181
|
-
this._connected = connected;
|
|
182
|
-
this._publicKey = publicKey;
|
|
160
|
+
if (!this.provider.isConnected())
|
|
161
|
+
return;
|
|
162
|
+
const addresses = this.provider.getAddresses();
|
|
163
|
+
const solanaAddr = addresses.find((a) => a.addressType === "Solana");
|
|
164
|
+
this._publicKey = solanaAddr?.address || null;
|
|
183
165
|
}
|
|
184
166
|
// Event methods for interface compliance
|
|
185
167
|
on(event, listener) {
|
|
@@ -197,16 +179,11 @@ var EmbeddedEthereumChain = class {
|
|
|
197
179
|
constructor(provider) {
|
|
198
180
|
this.provider = provider;
|
|
199
181
|
this.currentNetworkId = import_constants2.NetworkId.ETHEREUM_MAINNET;
|
|
200
|
-
this._connected = false;
|
|
201
182
|
this._accounts = [];
|
|
202
183
|
this.eventEmitter = new import_eventemitter32.EventEmitter();
|
|
203
184
|
this.setupEventListeners();
|
|
204
185
|
this.syncInitialState();
|
|
205
186
|
}
|
|
206
|
-
// EIP-1193 compliant properties
|
|
207
|
-
get connected() {
|
|
208
|
-
return this._connected;
|
|
209
|
-
}
|
|
210
187
|
get chainId() {
|
|
211
188
|
const chainId = (0, import_constants2.networkIdToChainId)(this.currentNetworkId) || 1;
|
|
212
189
|
return `0x${chainId.toString(16)}`;
|
|
@@ -230,7 +207,7 @@ var EmbeddedEthereumChain = class {
|
|
|
230
207
|
}
|
|
231
208
|
const addresses = this.provider.getAddresses();
|
|
232
209
|
const ethAddresses = addresses.filter((a) => a.addressType === "Ethereum").map((a) => a.address);
|
|
233
|
-
this.updateConnectionState(
|
|
210
|
+
this.updateConnectionState(ethAddresses);
|
|
234
211
|
return Promise.resolve(ethAddresses);
|
|
235
212
|
}
|
|
236
213
|
async disconnect() {
|
|
@@ -296,19 +273,19 @@ var EmbeddedEthereumChain = class {
|
|
|
296
273
|
return this.request({ method: "eth_accounts" });
|
|
297
274
|
}
|
|
298
275
|
isConnected() {
|
|
299
|
-
return this.
|
|
276
|
+
return this.provider.isConnected() && this._accounts.length > 0;
|
|
300
277
|
}
|
|
301
278
|
setupEventListeners() {
|
|
302
279
|
this.provider.on("connect", (data) => {
|
|
303
280
|
const ethAddresses = data.addresses?.filter((addr) => addr.addressType === "Ethereum")?.map((addr) => addr.address) || [];
|
|
304
281
|
if (ethAddresses.length > 0) {
|
|
305
|
-
this.updateConnectionState(
|
|
282
|
+
this.updateConnectionState(ethAddresses);
|
|
306
283
|
this.eventEmitter.emit("connect", { chainId: this.chainId });
|
|
307
284
|
this.eventEmitter.emit("accountsChanged", ethAddresses);
|
|
308
285
|
}
|
|
309
286
|
});
|
|
310
287
|
this.provider.on("disconnect", () => {
|
|
311
|
-
this.updateConnectionState(
|
|
288
|
+
this.updateConnectionState([]);
|
|
312
289
|
this.eventEmitter.emit("disconnect", { code: 4900, message: "Provider disconnected" });
|
|
313
290
|
this.eventEmitter.emit("accountsChanged", []);
|
|
314
291
|
});
|
|
@@ -318,12 +295,11 @@ var EmbeddedEthereumChain = class {
|
|
|
318
295
|
const addresses = this.provider.getAddresses();
|
|
319
296
|
const ethAddresses = addresses.filter((a) => a.addressType === "Ethereum").map((a) => a.address);
|
|
320
297
|
if (ethAddresses.length > 0) {
|
|
321
|
-
this.updateConnectionState(
|
|
298
|
+
this.updateConnectionState(ethAddresses);
|
|
322
299
|
}
|
|
323
300
|
}
|
|
324
301
|
}
|
|
325
|
-
updateConnectionState(
|
|
326
|
-
this._connected = connected;
|
|
302
|
+
updateConnectionState(accounts) {
|
|
327
303
|
this._accounts = accounts;
|
|
328
304
|
}
|
|
329
305
|
async handleEmbeddedRequest(args) {
|
|
@@ -463,7 +439,7 @@ var EmbeddedProvider = class {
|
|
|
463
439
|
if (!this.eventListeners.has(event)) {
|
|
464
440
|
this.eventListeners.set(event, /* @__PURE__ */ new Set());
|
|
465
441
|
}
|
|
466
|
-
this.eventListeners.get(event)
|
|
442
|
+
this.eventListeners.get(event)?.add(callback);
|
|
467
443
|
this.logger.log("EMBEDDED_PROVIDER", "Event listener added", { event });
|
|
468
444
|
}
|
|
469
445
|
off(event, callback) {
|
|
@@ -787,7 +763,7 @@ var EmbeddedProvider = class {
|
|
|
787
763
|
authenticatorName: `auth-${shortPubKey}`,
|
|
788
764
|
authenticatorKind: "keypair",
|
|
789
765
|
publicKey: base64urlPublicKey,
|
|
790
|
-
algorithm:
|
|
766
|
+
algorithm: this.stamper.algorithm,
|
|
791
767
|
expiresInMs
|
|
792
768
|
}
|
|
793
769
|
]
|
|
@@ -1243,8 +1219,9 @@ var EmbeddedProvider = class {
|
|
|
1243
1219
|
// OAuth session management - defaults to allowing refresh unless user explicitly logged out
|
|
1244
1220
|
clearPreviousSession: shouldClearPreviousSession,
|
|
1245
1221
|
// true only after logout
|
|
1246
|
-
allowRefresh: !shouldClearPreviousSession
|
|
1222
|
+
allowRefresh: !shouldClearPreviousSession,
|
|
1247
1223
|
// false only after logout
|
|
1224
|
+
algorithm: this.stamper.algorithm
|
|
1248
1225
|
});
|
|
1249
1226
|
if (authResult && "walletId" in authResult) {
|
|
1250
1227
|
this.logger.info("EMBEDDED_PROVIDER", "Authentication completed after redirect", {
|
|
@@ -1354,7 +1331,8 @@ var EmbeddedProvider = class {
|
|
|
1354
1331
|
apiBaseUrl: this.config.apiBaseUrl,
|
|
1355
1332
|
organizationId: session.organizationId,
|
|
1356
1333
|
headers: {
|
|
1357
|
-
...this.platform.analyticsHeaders || {}
|
|
1334
|
+
...this.platform.analyticsHeaders || {},
|
|
1335
|
+
...session.authUserId ? { "x-auth-user-id": session.authUserId } : {}
|
|
1358
1336
|
}
|
|
1359
1337
|
},
|
|
1360
1338
|
this.stamper
|