@phantom/embedded-provider-core 1.0.5 → 1.0.7
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 +10 -13
- package/dist/index.d.ts +10 -13
- package/dist/index.js +52 -38
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +52 -38
- package/dist/index.mjs.map +1 -1
- package/package.json +10 -10
package/dist/index.d.mts
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
import { AddressType, SpendingLimitError } from '@phantom/client';
|
|
1
|
+
import { AddressType, PresignTransactionContext, SpendingLimitError } from '@phantom/client';
|
|
2
2
|
import { NetworkId, ClientSideSdkHeaders } from '@phantom/constants';
|
|
3
3
|
import { ParsedSignatureResult, ParsedTransactionResult } from '@phantom/parsers';
|
|
4
4
|
import { Algorithm, StamperWithKeyManagement, Transaction, VersionedTransaction } from '@phantom/sdk-types';
|
|
5
|
-
import { ISolanaChain, IEthereumChain, EthTransactionRequest } from '@phantom/chain-interfaces';
|
|
5
|
+
import { ISolanaChain, IEthereumChain, SignAndSendTransactionOptions, EthTransactionRequest } from '@phantom/chain-interfaces';
|
|
6
|
+
import { Logger } from '@phantom/utils';
|
|
7
|
+
export { Logger as DebugLogger } from '@phantom/utils';
|
|
6
8
|
|
|
7
9
|
interface WalletAddress {
|
|
8
10
|
addressType: AddressType;
|
|
@@ -32,6 +34,7 @@ interface SignTransactionParams {
|
|
|
32
34
|
interface SignAndSendTransactionParams {
|
|
33
35
|
transaction: any;
|
|
34
36
|
networkId: NetworkId;
|
|
37
|
+
presignTransaction?: (transaction: string, context: PresignTransactionContext) => Promise<string>;
|
|
35
38
|
}
|
|
36
39
|
interface SignedTransaction extends ParsedTransactionResult {
|
|
37
40
|
}
|
|
@@ -157,12 +160,6 @@ interface PlatformAdapter {
|
|
|
157
160
|
stamper: StamperWithKeyManagement;
|
|
158
161
|
analyticsHeaders?: Partial<ClientSideSdkHeaders>;
|
|
159
162
|
}
|
|
160
|
-
interface DebugLogger {
|
|
161
|
-
info(category: string, message: string, data?: any): void;
|
|
162
|
-
warn(category: string, message: string, data?: any): void;
|
|
163
|
-
error(category: string, message: string, data?: any): void;
|
|
164
|
-
log(category: string, message: string, data?: any): void;
|
|
165
|
-
}
|
|
166
163
|
|
|
167
164
|
type EmbeddedProviderEvent = "connect" | "connect_start" | "connect_error" | "disconnect" | "error" | "spending_limit_reached";
|
|
168
165
|
interface ConnectEventData extends ConnectResult {
|
|
@@ -208,7 +205,7 @@ declare class EmbeddedProvider {
|
|
|
208
205
|
readonly solana: ISolanaChain;
|
|
209
206
|
readonly ethereum: IEthereumChain;
|
|
210
207
|
private eventListeners;
|
|
211
|
-
constructor(config: EmbeddedProviderConfig, platform: PlatformAdapter, logger:
|
|
208
|
+
constructor(config: EmbeddedProviderConfig, platform: PlatformAdapter, logger: Logger);
|
|
212
209
|
on<K extends EmbeddedProviderEvent>(event: K, callback: EventCallback<EmbeddedProviderEventMap[K]>): void;
|
|
213
210
|
off<K extends EmbeddedProviderEvent>(event: K, callback: EventCallback<EmbeddedProviderEventMap[K]>): void;
|
|
214
211
|
private emit;
|
|
@@ -248,7 +245,7 @@ declare class EmbeddedProvider {
|
|
|
248
245
|
|
|
249
246
|
declare function generateSessionId(): string;
|
|
250
247
|
|
|
251
|
-
declare function retryWithBackoff<T>(operation: () => Promise<T>, operationName: string, logger:
|
|
248
|
+
declare function retryWithBackoff<T>(operation: () => Promise<T>, operationName: string, logger: Logger, maxRetries?: number, baseDelay?: number): Promise<T>;
|
|
252
249
|
|
|
253
250
|
/**
|
|
254
251
|
* Embedded Solana chain implementation that is wallet adapter compliant
|
|
@@ -267,7 +264,7 @@ declare class EmbeddedSolanaChain implements ISolanaChain {
|
|
|
267
264
|
publicKey: string;
|
|
268
265
|
}>;
|
|
269
266
|
signTransaction(transaction: Transaction | VersionedTransaction): Promise<Transaction | VersionedTransaction>;
|
|
270
|
-
signAndSendTransaction(transaction: Transaction | VersionedTransaction): Promise<{
|
|
267
|
+
signAndSendTransaction(transaction: Transaction | VersionedTransaction, options?: SignAndSendTransactionOptions): Promise<{
|
|
271
268
|
signature: string;
|
|
272
269
|
}>;
|
|
273
270
|
signAllTransactions(transactions: (Transaction | VersionedTransaction)[]): Promise<(Transaction | VersionedTransaction)[]>;
|
|
@@ -323,7 +320,7 @@ declare class EmbeddedEthereumChain implements IEthereumChain {
|
|
|
323
320
|
|
|
324
321
|
/**
|
|
325
322
|
* How long an authenticator is valid before it expires (in milliseconds)
|
|
326
|
-
* Default:
|
|
323
|
+
* Default: 31 days
|
|
327
324
|
* For testing: Use smaller values like 5 * 60 * 1000 (5 minutes)
|
|
328
325
|
*/
|
|
329
326
|
declare const AUTHENTICATOR_EXPIRATION_TIME_MS: number;
|
|
@@ -335,4 +332,4 @@ declare const AUTHENTICATOR_EXPIRATION_TIME_MS: number;
|
|
|
335
332
|
declare const AUTHENTICATOR_RENEWAL_WINDOW_MS: number;
|
|
336
333
|
declare const EMBEDDED_PROVIDER_AUTH_TYPES: EmbeddedProviderAuthType[];
|
|
337
334
|
|
|
338
|
-
export { AUTHENTICATOR_EXPIRATION_TIME_MS, AUTHENTICATOR_RENEWAL_WINDOW_MS, AuthOptions, AuthProvider, AuthResult, ConnectErrorEventData, ConnectEventData, ConnectResult, ConnectStartEventData,
|
|
335
|
+
export { AUTHENTICATOR_EXPIRATION_TIME_MS, AUTHENTICATOR_RENEWAL_WINDOW_MS, AuthOptions, AuthProvider, AuthResult, ConnectErrorEventData, ConnectEventData, ConnectResult, ConnectStartEventData, DisconnectEventData, EMBEDDED_PROVIDER_AUTH_TYPES, EmbeddedEthereumChain, EmbeddedProvider, EmbeddedProviderAuthType, EmbeddedProviderConfig, EmbeddedProviderEvent, EmbeddedProviderEventMap, EmbeddedSolanaChain, EmbeddedStorage, EventCallback, Keypair, PhantomAppAuthOptions, PhantomAppProvider, PhantomConnectOptions, PlatformAdapter, Session, SignAndSendTransactionParams, SignMessageParams, SignMessageResult, SignTransactionParams, SignTypedDataV4Params, SignedTransaction, StamperInfo, URLParamsAccessor, WalletAddress, generateSessionId, retryWithBackoff };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
import { AddressType, SpendingLimitError } from '@phantom/client';
|
|
1
|
+
import { AddressType, PresignTransactionContext, SpendingLimitError } from '@phantom/client';
|
|
2
2
|
import { NetworkId, ClientSideSdkHeaders } from '@phantom/constants';
|
|
3
3
|
import { ParsedSignatureResult, ParsedTransactionResult } from '@phantom/parsers';
|
|
4
4
|
import { Algorithm, StamperWithKeyManagement, Transaction, VersionedTransaction } from '@phantom/sdk-types';
|
|
5
|
-
import { ISolanaChain, IEthereumChain, EthTransactionRequest } from '@phantom/chain-interfaces';
|
|
5
|
+
import { ISolanaChain, IEthereumChain, SignAndSendTransactionOptions, EthTransactionRequest } from '@phantom/chain-interfaces';
|
|
6
|
+
import { Logger } from '@phantom/utils';
|
|
7
|
+
export { Logger as DebugLogger } from '@phantom/utils';
|
|
6
8
|
|
|
7
9
|
interface WalletAddress {
|
|
8
10
|
addressType: AddressType;
|
|
@@ -32,6 +34,7 @@ interface SignTransactionParams {
|
|
|
32
34
|
interface SignAndSendTransactionParams {
|
|
33
35
|
transaction: any;
|
|
34
36
|
networkId: NetworkId;
|
|
37
|
+
presignTransaction?: (transaction: string, context: PresignTransactionContext) => Promise<string>;
|
|
35
38
|
}
|
|
36
39
|
interface SignedTransaction extends ParsedTransactionResult {
|
|
37
40
|
}
|
|
@@ -157,12 +160,6 @@ interface PlatformAdapter {
|
|
|
157
160
|
stamper: StamperWithKeyManagement;
|
|
158
161
|
analyticsHeaders?: Partial<ClientSideSdkHeaders>;
|
|
159
162
|
}
|
|
160
|
-
interface DebugLogger {
|
|
161
|
-
info(category: string, message: string, data?: any): void;
|
|
162
|
-
warn(category: string, message: string, data?: any): void;
|
|
163
|
-
error(category: string, message: string, data?: any): void;
|
|
164
|
-
log(category: string, message: string, data?: any): void;
|
|
165
|
-
}
|
|
166
163
|
|
|
167
164
|
type EmbeddedProviderEvent = "connect" | "connect_start" | "connect_error" | "disconnect" | "error" | "spending_limit_reached";
|
|
168
165
|
interface ConnectEventData extends ConnectResult {
|
|
@@ -208,7 +205,7 @@ declare class EmbeddedProvider {
|
|
|
208
205
|
readonly solana: ISolanaChain;
|
|
209
206
|
readonly ethereum: IEthereumChain;
|
|
210
207
|
private eventListeners;
|
|
211
|
-
constructor(config: EmbeddedProviderConfig, platform: PlatformAdapter, logger:
|
|
208
|
+
constructor(config: EmbeddedProviderConfig, platform: PlatformAdapter, logger: Logger);
|
|
212
209
|
on<K extends EmbeddedProviderEvent>(event: K, callback: EventCallback<EmbeddedProviderEventMap[K]>): void;
|
|
213
210
|
off<K extends EmbeddedProviderEvent>(event: K, callback: EventCallback<EmbeddedProviderEventMap[K]>): void;
|
|
214
211
|
private emit;
|
|
@@ -248,7 +245,7 @@ declare class EmbeddedProvider {
|
|
|
248
245
|
|
|
249
246
|
declare function generateSessionId(): string;
|
|
250
247
|
|
|
251
|
-
declare function retryWithBackoff<T>(operation: () => Promise<T>, operationName: string, logger:
|
|
248
|
+
declare function retryWithBackoff<T>(operation: () => Promise<T>, operationName: string, logger: Logger, maxRetries?: number, baseDelay?: number): Promise<T>;
|
|
252
249
|
|
|
253
250
|
/**
|
|
254
251
|
* Embedded Solana chain implementation that is wallet adapter compliant
|
|
@@ -267,7 +264,7 @@ declare class EmbeddedSolanaChain implements ISolanaChain {
|
|
|
267
264
|
publicKey: string;
|
|
268
265
|
}>;
|
|
269
266
|
signTransaction(transaction: Transaction | VersionedTransaction): Promise<Transaction | VersionedTransaction>;
|
|
270
|
-
signAndSendTransaction(transaction: Transaction | VersionedTransaction): Promise<{
|
|
267
|
+
signAndSendTransaction(transaction: Transaction | VersionedTransaction, options?: SignAndSendTransactionOptions): Promise<{
|
|
271
268
|
signature: string;
|
|
272
269
|
}>;
|
|
273
270
|
signAllTransactions(transactions: (Transaction | VersionedTransaction)[]): Promise<(Transaction | VersionedTransaction)[]>;
|
|
@@ -323,7 +320,7 @@ declare class EmbeddedEthereumChain implements IEthereumChain {
|
|
|
323
320
|
|
|
324
321
|
/**
|
|
325
322
|
* How long an authenticator is valid before it expires (in milliseconds)
|
|
326
|
-
* Default:
|
|
323
|
+
* Default: 31 days
|
|
327
324
|
* For testing: Use smaller values like 5 * 60 * 1000 (5 minutes)
|
|
328
325
|
*/
|
|
329
326
|
declare const AUTHENTICATOR_EXPIRATION_TIME_MS: number;
|
|
@@ -335,4 +332,4 @@ declare const AUTHENTICATOR_EXPIRATION_TIME_MS: number;
|
|
|
335
332
|
declare const AUTHENTICATOR_RENEWAL_WINDOW_MS: number;
|
|
336
333
|
declare const EMBEDDED_PROVIDER_AUTH_TYPES: EmbeddedProviderAuthType[];
|
|
337
334
|
|
|
338
|
-
export { AUTHENTICATOR_EXPIRATION_TIME_MS, AUTHENTICATOR_RENEWAL_WINDOW_MS, AuthOptions, AuthProvider, AuthResult, ConnectErrorEventData, ConnectEventData, ConnectResult, ConnectStartEventData,
|
|
335
|
+
export { AUTHENTICATOR_EXPIRATION_TIME_MS, AUTHENTICATOR_RENEWAL_WINDOW_MS, AuthOptions, AuthProvider, AuthResult, ConnectErrorEventData, ConnectEventData, ConnectResult, ConnectStartEventData, DisconnectEventData, EMBEDDED_PROVIDER_AUTH_TYPES, EmbeddedEthereumChain, EmbeddedProvider, EmbeddedProviderAuthType, EmbeddedProviderConfig, EmbeddedProviderEvent, EmbeddedProviderEventMap, EmbeddedSolanaChain, EmbeddedStorage, EventCallback, Keypair, PhantomAppAuthOptions, PhantomAppProvider, PhantomConnectOptions, PlatformAdapter, Session, SignAndSendTransactionParams, SignMessageParams, SignMessageResult, SignTransactionParams, SignTypedDataV4Params, SignedTransaction, StamperInfo, URLParamsAccessor, WalletAddress, generateSessionId, retryWithBackoff };
|
package/dist/index.js
CHANGED
|
@@ -50,7 +50,7 @@ var import_buffer = require("buffer");
|
|
|
50
50
|
var import_bs582 = __toESM(require("bs58"));
|
|
51
51
|
|
|
52
52
|
// src/constants.ts
|
|
53
|
-
var AUTHENTICATOR_EXPIRATION_TIME_MS =
|
|
53
|
+
var AUTHENTICATOR_EXPIRATION_TIME_MS = 31 * 24 * 60 * 60 * 1e3;
|
|
54
54
|
var AUTHENTICATOR_RENEWAL_WINDOW_MS = 2 * 24 * 60 * 60 * 1e3;
|
|
55
55
|
var EMBEDDED_PROVIDER_AUTH_TYPES = ["google", "apple", "phantom"];
|
|
56
56
|
|
|
@@ -105,11 +105,12 @@ var EmbeddedSolanaChain = class {
|
|
|
105
105
|
}
|
|
106
106
|
return signedTransaction;
|
|
107
107
|
}
|
|
108
|
-
async signAndSendTransaction(transaction) {
|
|
108
|
+
async signAndSendTransaction(transaction, options) {
|
|
109
109
|
this.ensureConnected();
|
|
110
110
|
const result = await this.provider.signAndSendTransaction({
|
|
111
111
|
transaction,
|
|
112
|
-
networkId: this.currentNetworkId
|
|
112
|
+
networkId: this.currentNetworkId,
|
|
113
|
+
presignTransaction: options?.presignTransaction
|
|
113
114
|
});
|
|
114
115
|
if (!result.hash) {
|
|
115
116
|
throw new Error("Transaction not submitted");
|
|
@@ -375,7 +376,7 @@ async function retryWithBackoff(operation, operationName, logger, maxRetries = 3
|
|
|
375
376
|
let lastError;
|
|
376
377
|
for (let attempt = 1; attempt <= maxRetries; attempt++) {
|
|
377
378
|
try {
|
|
378
|
-
logger.
|
|
379
|
+
logger.debug("EMBEDDED_PROVIDER", `Attempting ${operationName}`, {
|
|
379
380
|
attempt,
|
|
380
381
|
maxRetries
|
|
381
382
|
});
|
|
@@ -394,7 +395,7 @@ async function retryWithBackoff(operation, operationName, logger, maxRetries = 3
|
|
|
394
395
|
break;
|
|
395
396
|
}
|
|
396
397
|
const delay = baseDelay * Math.pow(2, attempt - 1);
|
|
397
|
-
logger.
|
|
398
|
+
logger.debug("EMBEDDED_PROVIDER", `Retrying ${operationName} in ${delay}ms`, {
|
|
398
399
|
attempt: attempt + 1,
|
|
399
400
|
delay
|
|
400
401
|
});
|
|
@@ -410,6 +411,16 @@ function generateSessionId() {
|
|
|
410
411
|
}
|
|
411
412
|
|
|
412
413
|
// src/embedded-provider.ts
|
|
414
|
+
var noopLogger = {
|
|
415
|
+
info: () => {
|
|
416
|
+
},
|
|
417
|
+
warn: () => {
|
|
418
|
+
},
|
|
419
|
+
error: () => {
|
|
420
|
+
},
|
|
421
|
+
debug: () => {
|
|
422
|
+
}
|
|
423
|
+
};
|
|
413
424
|
var EmbeddedProvider = class {
|
|
414
425
|
constructor(config, platform, logger) {
|
|
415
426
|
this.client = null;
|
|
@@ -417,7 +428,7 @@ var EmbeddedProvider = class {
|
|
|
417
428
|
this.addresses = [];
|
|
418
429
|
this.eventListeners = /* @__PURE__ */ new Map();
|
|
419
430
|
this.logger = logger;
|
|
420
|
-
this.logger.
|
|
431
|
+
this.logger.debug("EMBEDDED_PROVIDER", "Initializing EmbeddedProvider", { config });
|
|
421
432
|
if (config.embeddedWalletType === "app-wallet") {
|
|
422
433
|
throw new Error("app-wallet type is not currently supported. Please use 'user-wallet' instead.");
|
|
423
434
|
}
|
|
@@ -440,19 +451,19 @@ var EmbeddedProvider = class {
|
|
|
440
451
|
this.eventListeners.set(event, /* @__PURE__ */ new Set());
|
|
441
452
|
}
|
|
442
453
|
this.eventListeners.get(event)?.add(callback);
|
|
443
|
-
this.logger.
|
|
454
|
+
this.logger.debug("EMBEDDED_PROVIDER", "Event listener added", { event });
|
|
444
455
|
}
|
|
445
456
|
off(event, callback) {
|
|
446
457
|
const listeners = this.eventListeners.get(event);
|
|
447
458
|
if (listeners) {
|
|
448
459
|
listeners.delete(callback);
|
|
449
|
-
this.logger.
|
|
460
|
+
this.logger.debug("EMBEDDED_PROVIDER", "Event listener removed", { event });
|
|
450
461
|
}
|
|
451
462
|
}
|
|
452
463
|
emit(event, data) {
|
|
453
464
|
const listeners = this.eventListeners.get(event);
|
|
454
465
|
if (listeners && listeners.size > 0) {
|
|
455
|
-
this.logger.
|
|
466
|
+
this.logger.debug("EMBEDDED_PROVIDER", "Emitting event", { event, listenerCount: listeners.size, data });
|
|
456
467
|
listeners.forEach((callback) => {
|
|
457
468
|
try {
|
|
458
469
|
callback(data);
|
|
@@ -520,7 +531,7 @@ var EmbeddedProvider = class {
|
|
|
520
531
|
async validateAndCleanSession(session) {
|
|
521
532
|
if (!session)
|
|
522
533
|
return null;
|
|
523
|
-
this.logger.
|
|
534
|
+
this.logger.debug("EMBEDDED_PROVIDER", "Found existing session, validating", {
|
|
524
535
|
sessionId: session.sessionId,
|
|
525
536
|
status: session.status,
|
|
526
537
|
walletId: session.walletId
|
|
@@ -566,11 +577,11 @@ var EmbeddedProvider = class {
|
|
|
566
577
|
* Returns ConnectResult if connection succeeds, null if should continue with new auth flow.
|
|
567
578
|
*/
|
|
568
579
|
async tryExistingConnection(isAutoConnect) {
|
|
569
|
-
this.logger.
|
|
580
|
+
this.logger.debug("EMBEDDED_PROVIDER", "Getting existing session");
|
|
570
581
|
let session = await this.storage.getSession();
|
|
571
582
|
session = await this.validateAndCleanSession(session);
|
|
572
583
|
if (!session) {
|
|
573
|
-
this.logger.
|
|
584
|
+
this.logger.debug("EMBEDDED_PROVIDER", "No existing session found");
|
|
574
585
|
return null;
|
|
575
586
|
}
|
|
576
587
|
if (session.status === "completed") {
|
|
@@ -599,7 +610,7 @@ var EmbeddedProvider = class {
|
|
|
599
610
|
});
|
|
600
611
|
return result;
|
|
601
612
|
}
|
|
602
|
-
this.logger.
|
|
613
|
+
this.logger.debug("EMBEDDED_PROVIDER", "No completed session found, checking for redirect resume");
|
|
603
614
|
if (this.authProvider.resumeAuthFromRedirect) {
|
|
604
615
|
const authResult = await this.authProvider.resumeAuthFromRedirect(session.authProvider);
|
|
605
616
|
if (authResult) {
|
|
@@ -649,7 +660,7 @@ var EmbeddedProvider = class {
|
|
|
649
660
|
return false;
|
|
650
661
|
}
|
|
651
662
|
if (!session.walletId || !session.organizationId || !session.stamperInfo) {
|
|
652
|
-
this.logger.
|
|
663
|
+
this.logger.debug("EMBEDDED_PROVIDER", "Session missing required fields", {
|
|
653
664
|
hasWalletId: !!session.walletId,
|
|
654
665
|
hasOrganizationId: !!session.organizationId,
|
|
655
666
|
hasStamperInfo: !!session.stamperInfo
|
|
@@ -657,23 +668,23 @@ var EmbeddedProvider = class {
|
|
|
657
668
|
return false;
|
|
658
669
|
}
|
|
659
670
|
if (session.status !== "completed") {
|
|
660
|
-
this.logger.
|
|
671
|
+
this.logger.debug("EMBEDDED_PROVIDER", "Session not completed", { status: session.status });
|
|
661
672
|
return false;
|
|
662
673
|
}
|
|
663
674
|
if (!session.authenticatorExpiresAt) {
|
|
664
|
-
this.logger.
|
|
675
|
+
this.logger.debug("EMBEDDED_PROVIDER", "Session invalid - missing authenticator timing", {
|
|
665
676
|
sessionId: session.sessionId
|
|
666
677
|
});
|
|
667
678
|
return false;
|
|
668
679
|
}
|
|
669
680
|
if (Date.now() >= session.authenticatorExpiresAt) {
|
|
670
|
-
this.logger.
|
|
681
|
+
this.logger.debug("EMBEDDED_PROVIDER", "Authenticator expired, session invalid", {
|
|
671
682
|
authenticatorExpiresAt: new Date(session.authenticatorExpiresAt).toISOString(),
|
|
672
683
|
now: (/* @__PURE__ */ new Date()).toISOString()
|
|
673
684
|
});
|
|
674
685
|
return false;
|
|
675
686
|
}
|
|
676
|
-
this.logger.
|
|
687
|
+
this.logger.debug("EMBEDDED_PROVIDER", "Session is valid", {
|
|
677
688
|
sessionId: session.sessionId,
|
|
678
689
|
walletId: session.walletId,
|
|
679
690
|
authenticatorExpires: new Date(session.authenticatorExpiresAt).toISOString()
|
|
@@ -687,7 +698,7 @@ var EmbeddedProvider = class {
|
|
|
687
698
|
*/
|
|
688
699
|
async autoConnect() {
|
|
689
700
|
try {
|
|
690
|
-
this.logger.
|
|
701
|
+
this.logger.debug("EMBEDDED_PROVIDER", "Starting auto-connect attempt");
|
|
691
702
|
this.emit("connect_start", { source: "auto-connect" });
|
|
692
703
|
const result = await this.tryExistingConnection(true);
|
|
693
704
|
if (result) {
|
|
@@ -701,7 +712,7 @@ var EmbeddedProvider = class {
|
|
|
701
712
|
});
|
|
702
713
|
return;
|
|
703
714
|
}
|
|
704
|
-
this.logger.
|
|
715
|
+
this.logger.debug("EMBEDDED_PROVIDER", "Auto-connect failed: no valid session found");
|
|
705
716
|
this.emit("connect_error", {
|
|
706
717
|
error: "No valid session found",
|
|
707
718
|
source: "auto-connect"
|
|
@@ -722,11 +733,11 @@ var EmbeddedProvider = class {
|
|
|
722
733
|
* This is the first step when no existing session is found and we need to set up a new wallet.
|
|
723
734
|
*/
|
|
724
735
|
async initializeStamper() {
|
|
725
|
-
this.logger.
|
|
736
|
+
this.logger.debug("EMBEDDED_PROVIDER", "Initializing stamper");
|
|
726
737
|
await this.stamper.init();
|
|
727
|
-
this.logger.
|
|
738
|
+
this.logger.debug("EMBEDDED_PROVIDER", "Resetting keypair to avoid conflicts with existing keypairs");
|
|
728
739
|
const stamperInfo = await this.stamper.resetKeyPair();
|
|
729
|
-
this.logger.
|
|
740
|
+
this.logger.debug("EMBEDDED_PROVIDER", "Stamper initialized with fresh keypair", {
|
|
730
741
|
publicKey: stamperInfo.publicKey,
|
|
731
742
|
keyId: stamperInfo.keyId,
|
|
732
743
|
algorithm: this.stamper.algorithm
|
|
@@ -743,12 +754,13 @@ var EmbeddedProvider = class {
|
|
|
743
754
|
apiBaseUrl: this.config.apiBaseUrl,
|
|
744
755
|
headers: {
|
|
745
756
|
...this.platform.analyticsHeaders || {}
|
|
746
|
-
}
|
|
757
|
+
},
|
|
758
|
+
logger: noopLogger
|
|
747
759
|
});
|
|
748
760
|
const platformName = this.platform.name || "unknown";
|
|
749
761
|
const shortPubKey = stamperInfo.publicKey.slice(0, 8);
|
|
750
762
|
const organizationName = `${this.config.appId.substring(0, 8)}-${platformName}-${shortPubKey}`;
|
|
751
|
-
this.logger.
|
|
763
|
+
this.logger.debug("EMBEDDED_PROVIDER", "Creating organization for app-wallet", {
|
|
752
764
|
organizationName,
|
|
753
765
|
publicKey: stamperInfo.publicKey,
|
|
754
766
|
platform: platformName
|
|
@@ -868,7 +880,7 @@ var EmbeddedProvider = class {
|
|
|
868
880
|
async disconnect(shouldClearPreviousSession = true) {
|
|
869
881
|
const wasConnected = this.client !== null;
|
|
870
882
|
await this.storage.setShouldClearPreviousSession(shouldClearPreviousSession);
|
|
871
|
-
this.logger.
|
|
883
|
+
this.logger.debug("EMBEDDED_PROVIDER", "Set flag to clear previous session on next login");
|
|
872
884
|
await this.storage.clearSession();
|
|
873
885
|
this.client = null;
|
|
874
886
|
this.walletId = null;
|
|
@@ -985,7 +997,7 @@ var EmbeddedProvider = class {
|
|
|
985
997
|
const parsedTransaction = await (0, import_parsers2.parseToKmsTransaction)(params.transaction, params.networkId);
|
|
986
998
|
const session = await this.storage.getSession();
|
|
987
999
|
const derivationIndex = session?.accountDerivationIndex ?? 0;
|
|
988
|
-
this.logger.
|
|
1000
|
+
this.logger.debug("EMBEDDED_PROVIDER", "Parsed transaction for signing", {
|
|
989
1001
|
walletId: this.walletId,
|
|
990
1002
|
transaction: parsedTransaction,
|
|
991
1003
|
derivationIndex
|
|
@@ -1024,7 +1036,7 @@ var EmbeddedProvider = class {
|
|
|
1024
1036
|
const parsedTransaction = await (0, import_parsers2.parseToKmsTransaction)(params.transaction, params.networkId);
|
|
1025
1037
|
const session = await this.storage.getSession();
|
|
1026
1038
|
const derivationIndex = session?.accountDerivationIndex ?? 0;
|
|
1027
|
-
this.logger.
|
|
1039
|
+
this.logger.debug("EMBEDDED_PROVIDER", "Parsed transaction for signing", {
|
|
1028
1040
|
walletId: this.walletId,
|
|
1029
1041
|
transaction: parsedTransaction,
|
|
1030
1042
|
derivationIndex
|
|
@@ -1042,7 +1054,8 @@ var EmbeddedProvider = class {
|
|
|
1042
1054
|
transaction: transactionPayload,
|
|
1043
1055
|
networkId: params.networkId,
|
|
1044
1056
|
derivationIndex,
|
|
1045
|
-
account
|
|
1057
|
+
account,
|
|
1058
|
+
presignTransaction: params.presignTransaction
|
|
1046
1059
|
}).catch((error) => this.handleSigningError(error));
|
|
1047
1060
|
this.logger.info("EMBEDDED_PROVIDER", "Transaction signed and sent successfully", {
|
|
1048
1061
|
walletId: this.walletId,
|
|
@@ -1088,7 +1101,8 @@ var EmbeddedProvider = class {
|
|
|
1088
1101
|
organizationId,
|
|
1089
1102
|
headers: {
|
|
1090
1103
|
...this.platform.analyticsHeaders || {}
|
|
1091
|
-
}
|
|
1104
|
+
},
|
|
1105
|
+
logger: noopLogger
|
|
1092
1106
|
},
|
|
1093
1107
|
this.stamper
|
|
1094
1108
|
);
|
|
@@ -1167,7 +1181,7 @@ var EmbeddedProvider = class {
|
|
|
1167
1181
|
lastRenewalAttempt: void 0,
|
|
1168
1182
|
authUserId: authResult.authUserId
|
|
1169
1183
|
};
|
|
1170
|
-
this.logger.
|
|
1184
|
+
this.logger.debug("EMBEDDED_PROVIDER", "Saving Phantom session");
|
|
1171
1185
|
await this.storage.saveSession(session);
|
|
1172
1186
|
return session;
|
|
1173
1187
|
}
|
|
@@ -1202,7 +1216,7 @@ var EmbeddedProvider = class {
|
|
|
1202
1216
|
authenticatorExpiresAt: now + AUTHENTICATOR_EXPIRATION_TIME_MS,
|
|
1203
1217
|
lastRenewalAttempt: void 0
|
|
1204
1218
|
};
|
|
1205
|
-
this.logger.
|
|
1219
|
+
this.logger.debug("EMBEDDED_PROVIDER", "Saving temporary session before redirect", {
|
|
1206
1220
|
sessionId: tempSession.sessionId,
|
|
1207
1221
|
tempWalletId: tempSession.walletId
|
|
1208
1222
|
});
|
|
@@ -1249,14 +1263,14 @@ var EmbeddedProvider = class {
|
|
|
1249
1263
|
const now2 = Date.now();
|
|
1250
1264
|
tempSession.authenticatorCreatedAt = now2;
|
|
1251
1265
|
tempSession.authenticatorExpiresAt = now2 + authResult.expiresInMs;
|
|
1252
|
-
this.logger.
|
|
1266
|
+
this.logger.debug("EMBEDDED_PROVIDER", "Updated authenticator expiration from immediate auth response", {
|
|
1253
1267
|
expiresInMs: authResult.expiresInMs,
|
|
1254
1268
|
expiresAt: new Date(tempSession.authenticatorExpiresAt).toISOString()
|
|
1255
1269
|
});
|
|
1256
1270
|
}
|
|
1257
1271
|
await this.storage.saveSession(tempSession);
|
|
1258
1272
|
await this.storage.setShouldClearPreviousSession(false);
|
|
1259
|
-
this.logger.
|
|
1273
|
+
this.logger.debug("EMBEDDED_PROVIDER", "Cleared logout flag after successful authentication");
|
|
1260
1274
|
return tempSession;
|
|
1261
1275
|
}
|
|
1262
1276
|
this.logger.info("EMBEDDED_PROVIDER", "Redirect authentication initiated, waiting for redirect completion");
|
|
@@ -1279,14 +1293,14 @@ var EmbeddedProvider = class {
|
|
|
1279
1293
|
const now = Date.now();
|
|
1280
1294
|
session.authenticatorCreatedAt = now;
|
|
1281
1295
|
session.authenticatorExpiresAt = now + authResult.expiresInMs;
|
|
1282
|
-
this.logger.
|
|
1296
|
+
this.logger.debug("EMBEDDED_PROVIDER", "Updated authenticator expiration from auth response", {
|
|
1283
1297
|
expiresInMs: authResult.expiresInMs,
|
|
1284
1298
|
expiresAt: new Date(session.authenticatorExpiresAt).toISOString()
|
|
1285
1299
|
});
|
|
1286
1300
|
}
|
|
1287
1301
|
await this.storage.saveSession(session);
|
|
1288
1302
|
await this.storage.setShouldClearPreviousSession(false);
|
|
1289
|
-
this.logger.
|
|
1303
|
+
this.logger.debug("EMBEDDED_PROVIDER", "Cleared logout flag after successful authentication");
|
|
1290
1304
|
await this.initializeClientFromSession(session);
|
|
1291
1305
|
await this.ensureValidAuthenticator();
|
|
1292
1306
|
return {
|
|
@@ -1313,7 +1327,7 @@ var EmbeddedProvider = class {
|
|
|
1313
1327
|
throw new Error("Invalid session - missing authenticator timing");
|
|
1314
1328
|
}
|
|
1315
1329
|
const timeUntilExpiry = session.authenticatorExpiresAt - now;
|
|
1316
|
-
this.logger.
|
|
1330
|
+
this.logger.debug("EMBEDDED_PROVIDER", "Checking authenticator expiration", {
|
|
1317
1331
|
expiresAt: new Date(session.authenticatorExpiresAt).toISOString(),
|
|
1318
1332
|
timeUntilExpiry
|
|
1319
1333
|
});
|
|
@@ -1328,7 +1342,7 @@ var EmbeddedProvider = class {
|
|
|
1328
1342
|
* This is the final step that sets up the provider's client state and retrieves available addresses.
|
|
1329
1343
|
*/
|
|
1330
1344
|
async initializeClientFromSession(session) {
|
|
1331
|
-
this.logger.
|
|
1345
|
+
this.logger.debug("EMBEDDED_PROVIDER", "Initializing PhantomClient from session", {
|
|
1332
1346
|
organizationId: session.organizationId,
|
|
1333
1347
|
walletId: session.walletId,
|
|
1334
1348
|
appId: session.appId
|