@phantom/embedded-provider-core 1.0.0-beta.1 → 1.0.0-beta.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/README.md +0 -2
- package/dist/index.d.mts +16 -7
- package/dist/index.d.ts +16 -7
- package/dist/index.js +112 -36
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +106 -30
- package/dist/index.mjs.map +1 -1
- package/package.json +8 -8
package/README.md
CHANGED
|
@@ -60,7 +60,6 @@ const config: EmbeddedProviderConfig = {
|
|
|
60
60
|
appId: "your-app-id",
|
|
61
61
|
embeddedWalletType: "user-wallet", // or 'app-wallet'
|
|
62
62
|
addressTypes: ["solana", "ethereum"],
|
|
63
|
-
solanaProvider: "web3js",
|
|
64
63
|
authOptions: {
|
|
65
64
|
authUrl: "https://auth.phantom.app",
|
|
66
65
|
redirectUrl: "https://your-app.com/callback",
|
|
@@ -276,7 +275,6 @@ interface EmbeddedProviderConfig {
|
|
|
276
275
|
addressTypes: [AddressType, ...AddressType[]]; // Supported blockchain addresses
|
|
277
276
|
|
|
278
277
|
// Optional
|
|
279
|
-
solanaProvider?: "web3js" | "kit"; // Solana library preference
|
|
280
278
|
authOptions?: {
|
|
281
279
|
authUrl?: string; // Custom auth URL
|
|
282
280
|
redirectUrl?: string; // OAuth redirect URL
|
package/dist/index.d.mts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { StamperWithKeyManagement } from '@phantom/sdk-types';
|
|
2
|
+
import { ClientSideSdkHeaders, NetworkId } from '@phantom/constants';
|
|
2
3
|
import { AddressType } from '@phantom/client';
|
|
3
|
-
import { NetworkId } from '@phantom/constants';
|
|
4
4
|
import { ParsedSignatureResult, ParsedTransactionResult } from '@phantom/parsers';
|
|
5
5
|
import { ISolanaChain, IEthereumChain, EthTransactionRequest } from '@phantom/chains';
|
|
6
6
|
|
|
@@ -92,6 +92,7 @@ interface PlatformAdapter {
|
|
|
92
92
|
authProvider: AuthProvider;
|
|
93
93
|
urlParamsAccessor: URLParamsAccessor;
|
|
94
94
|
stamper: StamperWithKeyManagement;
|
|
95
|
+
analyticsHeaders?: Partial<ClientSideSdkHeaders>;
|
|
95
96
|
}
|
|
96
97
|
interface DebugLogger {
|
|
97
98
|
info(category: string, message: string, data?: any): void;
|
|
@@ -115,6 +116,10 @@ interface SignMessageParams {
|
|
|
115
116
|
}
|
|
116
117
|
interface SignMessageResult extends ParsedSignatureResult {
|
|
117
118
|
}
|
|
119
|
+
interface SignTransactionParams {
|
|
120
|
+
transaction: any;
|
|
121
|
+
networkId: NetworkId;
|
|
122
|
+
}
|
|
118
123
|
interface SignAndSendTransactionParams {
|
|
119
124
|
transaction: any;
|
|
120
125
|
networkId: NetworkId;
|
|
@@ -130,13 +135,12 @@ interface EmbeddedProviderConfig {
|
|
|
130
135
|
apiBaseUrl: string;
|
|
131
136
|
appId: string;
|
|
132
137
|
organizationId: string;
|
|
133
|
-
authOptions
|
|
134
|
-
authUrl
|
|
135
|
-
redirectUrl
|
|
138
|
+
authOptions: {
|
|
139
|
+
authUrl: string;
|
|
140
|
+
redirectUrl: string;
|
|
136
141
|
};
|
|
137
142
|
embeddedWalletType: "app-wallet" | "user-wallet" | (string & Record<never, never>);
|
|
138
143
|
addressTypes: [AddressType, ...AddressType[]];
|
|
139
|
-
solanaProvider: "web3js" | "kit" | (string & Record<never, never>);
|
|
140
144
|
}
|
|
141
145
|
|
|
142
146
|
type EmbeddedProviderEvent = "connect" | "connect_start" | "connect_error" | "disconnect" | "error";
|
|
@@ -170,6 +174,7 @@ declare class EmbeddedProvider {
|
|
|
170
174
|
connect(authOptions?: AuthOptions): Promise<ConnectResult>;
|
|
171
175
|
disconnect(): Promise<void>;
|
|
172
176
|
signMessage(params: SignMessageParams): Promise<ParsedSignatureResult>;
|
|
177
|
+
signTransaction(params: SignTransactionParams): Promise<ParsedTransactionResult>;
|
|
173
178
|
signAndSendTransaction(params: SignAndSendTransactionParams): Promise<ParsedTransactionResult>;
|
|
174
179
|
getAddresses(): WalletAddress[];
|
|
175
180
|
isConnected(): boolean;
|
|
@@ -207,11 +212,14 @@ declare class EmbeddedSolanaChain implements ISolanaChain {
|
|
|
207
212
|
signature: Uint8Array;
|
|
208
213
|
publicKey: string;
|
|
209
214
|
}>;
|
|
210
|
-
signTransaction<T>(
|
|
215
|
+
signTransaction<T>(transaction: T): Promise<T>;
|
|
211
216
|
signAndSendTransaction<T>(transaction: T): Promise<{
|
|
212
217
|
signature: string;
|
|
213
218
|
}>;
|
|
214
219
|
signAllTransactions<T>(transactions: T[]): Promise<T[]>;
|
|
220
|
+
signAndSendAllTransactions<T>(transactions: T[]): Promise<{
|
|
221
|
+
signatures: string[];
|
|
222
|
+
}>;
|
|
215
223
|
connect(_options?: {
|
|
216
224
|
onlyIfTrusted?: boolean;
|
|
217
225
|
}): Promise<{
|
|
@@ -250,6 +258,7 @@ declare class EmbeddedEthereumChain implements IEthereumChain {
|
|
|
250
258
|
disconnect(): Promise<void>;
|
|
251
259
|
signPersonalMessage(message: string, address: string): Promise<string>;
|
|
252
260
|
signTypedData(typedData: any, address: string): Promise<string>;
|
|
261
|
+
signTransaction(transaction: EthTransactionRequest): Promise<string>;
|
|
253
262
|
sendTransaction(transaction: EthTransactionRequest): Promise<string>;
|
|
254
263
|
switchChain(chainId: number): Promise<void>;
|
|
255
264
|
getChainId(): Promise<number>;
|
|
@@ -279,4 +288,4 @@ declare const AUTHENTICATOR_EXPIRATION_TIME_MS: number;
|
|
|
279
288
|
*/
|
|
280
289
|
declare const AUTHENTICATOR_RENEWAL_WINDOW_MS: number;
|
|
281
290
|
|
|
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 };
|
|
291
|
+
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, SignTransactionParams, SignedTransaction, StamperInfo, URLParamsAccessor, WalletAddress, generateSessionId, retryWithBackoff };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { StamperWithKeyManagement } from '@phantom/sdk-types';
|
|
2
|
+
import { ClientSideSdkHeaders, NetworkId } from '@phantom/constants';
|
|
2
3
|
import { AddressType } from '@phantom/client';
|
|
3
|
-
import { NetworkId } from '@phantom/constants';
|
|
4
4
|
import { ParsedSignatureResult, ParsedTransactionResult } from '@phantom/parsers';
|
|
5
5
|
import { ISolanaChain, IEthereumChain, EthTransactionRequest } from '@phantom/chains';
|
|
6
6
|
|
|
@@ -92,6 +92,7 @@ interface PlatformAdapter {
|
|
|
92
92
|
authProvider: AuthProvider;
|
|
93
93
|
urlParamsAccessor: URLParamsAccessor;
|
|
94
94
|
stamper: StamperWithKeyManagement;
|
|
95
|
+
analyticsHeaders?: Partial<ClientSideSdkHeaders>;
|
|
95
96
|
}
|
|
96
97
|
interface DebugLogger {
|
|
97
98
|
info(category: string, message: string, data?: any): void;
|
|
@@ -115,6 +116,10 @@ interface SignMessageParams {
|
|
|
115
116
|
}
|
|
116
117
|
interface SignMessageResult extends ParsedSignatureResult {
|
|
117
118
|
}
|
|
119
|
+
interface SignTransactionParams {
|
|
120
|
+
transaction: any;
|
|
121
|
+
networkId: NetworkId;
|
|
122
|
+
}
|
|
118
123
|
interface SignAndSendTransactionParams {
|
|
119
124
|
transaction: any;
|
|
120
125
|
networkId: NetworkId;
|
|
@@ -130,13 +135,12 @@ interface EmbeddedProviderConfig {
|
|
|
130
135
|
apiBaseUrl: string;
|
|
131
136
|
appId: string;
|
|
132
137
|
organizationId: string;
|
|
133
|
-
authOptions
|
|
134
|
-
authUrl
|
|
135
|
-
redirectUrl
|
|
138
|
+
authOptions: {
|
|
139
|
+
authUrl: string;
|
|
140
|
+
redirectUrl: string;
|
|
136
141
|
};
|
|
137
142
|
embeddedWalletType: "app-wallet" | "user-wallet" | (string & Record<never, never>);
|
|
138
143
|
addressTypes: [AddressType, ...AddressType[]];
|
|
139
|
-
solanaProvider: "web3js" | "kit" | (string & Record<never, never>);
|
|
140
144
|
}
|
|
141
145
|
|
|
142
146
|
type EmbeddedProviderEvent = "connect" | "connect_start" | "connect_error" | "disconnect" | "error";
|
|
@@ -170,6 +174,7 @@ declare class EmbeddedProvider {
|
|
|
170
174
|
connect(authOptions?: AuthOptions): Promise<ConnectResult>;
|
|
171
175
|
disconnect(): Promise<void>;
|
|
172
176
|
signMessage(params: SignMessageParams): Promise<ParsedSignatureResult>;
|
|
177
|
+
signTransaction(params: SignTransactionParams): Promise<ParsedTransactionResult>;
|
|
173
178
|
signAndSendTransaction(params: SignAndSendTransactionParams): Promise<ParsedTransactionResult>;
|
|
174
179
|
getAddresses(): WalletAddress[];
|
|
175
180
|
isConnected(): boolean;
|
|
@@ -207,11 +212,14 @@ declare class EmbeddedSolanaChain implements ISolanaChain {
|
|
|
207
212
|
signature: Uint8Array;
|
|
208
213
|
publicKey: string;
|
|
209
214
|
}>;
|
|
210
|
-
signTransaction<T>(
|
|
215
|
+
signTransaction<T>(transaction: T): Promise<T>;
|
|
211
216
|
signAndSendTransaction<T>(transaction: T): Promise<{
|
|
212
217
|
signature: string;
|
|
213
218
|
}>;
|
|
214
219
|
signAllTransactions<T>(transactions: T[]): Promise<T[]>;
|
|
220
|
+
signAndSendAllTransactions<T>(transactions: T[]): Promise<{
|
|
221
|
+
signatures: string[];
|
|
222
|
+
}>;
|
|
215
223
|
connect(_options?: {
|
|
216
224
|
onlyIfTrusted?: boolean;
|
|
217
225
|
}): Promise<{
|
|
@@ -250,6 +258,7 @@ declare class EmbeddedEthereumChain implements IEthereumChain {
|
|
|
250
258
|
disconnect(): Promise<void>;
|
|
251
259
|
signPersonalMessage(message: string, address: string): Promise<string>;
|
|
252
260
|
signTypedData(typedData: any, address: string): Promise<string>;
|
|
261
|
+
signTransaction(transaction: EthTransactionRequest): Promise<string>;
|
|
253
262
|
sendTransaction(transaction: EthTransactionRequest): Promise<string>;
|
|
254
263
|
switchChain(chainId: number): Promise<void>;
|
|
255
264
|
getChainId(): Promise<number>;
|
|
@@ -279,4 +288,4 @@ declare const AUTHENTICATOR_EXPIRATION_TIME_MS: number;
|
|
|
279
288
|
*/
|
|
280
289
|
declare const AUTHENTICATOR_RENEWAL_WINDOW_MS: number;
|
|
281
290
|
|
|
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 };
|
|
291
|
+
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, SignTransactionParams, SignedTransaction, StamperInfo, URLParamsAccessor, WalletAddress, generateSessionId, retryWithBackoff };
|
package/dist/index.js
CHANGED
|
@@ -43,9 +43,9 @@ module.exports = __toCommonJS(src_exports);
|
|
|
43
43
|
|
|
44
44
|
// src/embedded-provider.ts
|
|
45
45
|
var import_client = require("@phantom/client");
|
|
46
|
-
var
|
|
47
|
-
var
|
|
48
|
-
var
|
|
46
|
+
var import_base64url2 = require("@phantom/base64url");
|
|
47
|
+
var import_bs582 = __toESM(require("bs58"));
|
|
48
|
+
var import_parsers2 = require("@phantom/parsers");
|
|
49
49
|
|
|
50
50
|
// src/constants.ts
|
|
51
51
|
var AUTHENTICATOR_EXPIRATION_TIME_MS = 7 * 24 * 60 * 60 * 1e3;
|
|
@@ -171,7 +171,8 @@ async function retryWithBackoff(operation, operationName, logger, maxRetries = 3
|
|
|
171
171
|
// src/chains/SolanaChain.ts
|
|
172
172
|
var import_eventemitter3 = require("eventemitter3");
|
|
173
173
|
var import_constants = require("@phantom/constants");
|
|
174
|
-
var
|
|
174
|
+
var import_bs58 = __toESM(require("bs58"));
|
|
175
|
+
var import_parsers = require("@phantom/parsers");
|
|
175
176
|
var EmbeddedSolanaChain = class {
|
|
176
177
|
constructor(provider) {
|
|
177
178
|
this.provider = provider;
|
|
@@ -202,15 +203,20 @@ var EmbeddedSolanaChain = class {
|
|
|
202
203
|
message: messageStr,
|
|
203
204
|
networkId: this.currentNetworkId
|
|
204
205
|
});
|
|
205
|
-
const signature = typeof result.signature === "string" ? new Uint8Array(
|
|
206
|
+
const signature = typeof result.signature === "string" ? new Uint8Array(import_bs58.default.decode(result.signature)) : result.signature;
|
|
206
207
|
return {
|
|
207
208
|
signature,
|
|
208
209
|
publicKey: this._publicKey || ""
|
|
209
210
|
};
|
|
210
211
|
}
|
|
211
|
-
signTransaction(
|
|
212
|
+
async signTransaction(transaction) {
|
|
212
213
|
this.ensureConnected();
|
|
213
|
-
|
|
214
|
+
const result = await this.provider.signTransaction({
|
|
215
|
+
transaction,
|
|
216
|
+
networkId: this.currentNetworkId
|
|
217
|
+
});
|
|
218
|
+
const signatureResult = (0, import_parsers.parseSolanaTransactionSignature)(result.rawTransaction);
|
|
219
|
+
return signatureResult.signature;
|
|
214
220
|
}
|
|
215
221
|
async signAndSendTransaction(transaction) {
|
|
216
222
|
this.ensureConnected();
|
|
@@ -227,6 +233,10 @@ var EmbeddedSolanaChain = class {
|
|
|
227
233
|
const results = await Promise.all(transactions.map((tx) => this.signTransaction(tx)));
|
|
228
234
|
return results;
|
|
229
235
|
}
|
|
236
|
+
async signAndSendAllTransactions(transactions) {
|
|
237
|
+
const results = await Promise.all(transactions.map((tx) => this.signAndSendTransaction(tx)));
|
|
238
|
+
return { signatures: results.map((result) => result.signature) };
|
|
239
|
+
}
|
|
230
240
|
connect(_options) {
|
|
231
241
|
if (!this.provider.isConnected()) {
|
|
232
242
|
throw new Error("Provider not connected. Call provider connect first.");
|
|
@@ -293,6 +303,8 @@ var EmbeddedSolanaChain = class {
|
|
|
293
303
|
// src/chains/EthereumChain.ts
|
|
294
304
|
var import_eventemitter32 = require("eventemitter3");
|
|
295
305
|
var import_constants2 = require("@phantom/constants");
|
|
306
|
+
var import_base64url = require("@phantom/base64url");
|
|
307
|
+
var import_buffer = require("buffer");
|
|
296
308
|
var EmbeddedEthereumChain = class {
|
|
297
309
|
constructor(provider) {
|
|
298
310
|
this.provider = provider;
|
|
@@ -349,6 +361,18 @@ var EmbeddedEthereumChain = class {
|
|
|
349
361
|
params: [address, JSON.stringify(typedData)]
|
|
350
362
|
});
|
|
351
363
|
}
|
|
364
|
+
async signTransaction(transaction) {
|
|
365
|
+
const result = await this.provider.signTransaction({
|
|
366
|
+
transaction,
|
|
367
|
+
networkId: this.currentNetworkId
|
|
368
|
+
});
|
|
369
|
+
try {
|
|
370
|
+
const signatureBytes = (0, import_base64url.base64urlDecode)(result.rawTransaction);
|
|
371
|
+
return "0x" + import_buffer.Buffer.from(signatureBytes).toString("hex");
|
|
372
|
+
} catch (error) {
|
|
373
|
+
return result.rawTransaction.startsWith("0x") ? result.rawTransaction : "0x" + result.rawTransaction;
|
|
374
|
+
}
|
|
375
|
+
}
|
|
352
376
|
async sendTransaction(transaction) {
|
|
353
377
|
const result = await this.provider.signAndSendTransaction({
|
|
354
378
|
transaction,
|
|
@@ -426,6 +450,17 @@ var EmbeddedEthereumChain = class {
|
|
|
426
450
|
});
|
|
427
451
|
return typedDataResult.signature;
|
|
428
452
|
}
|
|
453
|
+
case "eth_signTransaction": {
|
|
454
|
+
const [transaction] = args.params;
|
|
455
|
+
const networkIdFromTx = transaction.chainId ? (0, import_constants2.chainIdToNetworkId)(
|
|
456
|
+
typeof transaction.chainId === "number" ? transaction.chainId : parseInt(transaction.chainId, 16)
|
|
457
|
+
) : null;
|
|
458
|
+
const signResult = await this.provider.signTransaction({
|
|
459
|
+
transaction,
|
|
460
|
+
networkId: networkIdFromTx || this.currentNetworkId
|
|
461
|
+
});
|
|
462
|
+
return signResult.rawTransaction;
|
|
463
|
+
}
|
|
429
464
|
case "eth_sendTransaction": {
|
|
430
465
|
const [transaction] = args.params;
|
|
431
466
|
const networkIdFromTx = transaction.chainId ? (0, import_constants2.chainIdToNetworkId)(
|
|
@@ -473,6 +508,9 @@ var EmbeddedProvider = class {
|
|
|
473
508
|
this.eventListeners = /* @__PURE__ */ new Map();
|
|
474
509
|
this.logger = logger;
|
|
475
510
|
this.logger.log("EMBEDDED_PROVIDER", "Initializing EmbeddedProvider", { config });
|
|
511
|
+
if (config.embeddedWalletType === "app-wallet") {
|
|
512
|
+
throw new Error("app-wallet type is not currently supported. Please use 'user-wallet' instead.");
|
|
513
|
+
}
|
|
476
514
|
this.config = config;
|
|
477
515
|
this.platform = platform;
|
|
478
516
|
this.storage = platform.storage;
|
|
@@ -480,7 +518,6 @@ var EmbeddedProvider = class {
|
|
|
480
518
|
this.urlParamsAccessor = platform.urlParamsAccessor;
|
|
481
519
|
this.stamper = platform.stamper;
|
|
482
520
|
this.jwtAuth = new JWTAuth();
|
|
483
|
-
config.solanaProvider;
|
|
484
521
|
this.solana = new EmbeddedSolanaChain(this);
|
|
485
522
|
this.ethereum = new EmbeddedEthereumChain(this);
|
|
486
523
|
this.logger.info("EMBEDDED_PROVIDER", "EmbeddedProvider initialized");
|
|
@@ -747,7 +784,10 @@ var EmbeddedProvider = class {
|
|
|
747
784
|
this.logger.log("EMBEDDED_PROVIDER", "Creating temporary PhantomClient");
|
|
748
785
|
const tempClient = new import_client.PhantomClient(
|
|
749
786
|
{
|
|
750
|
-
apiBaseUrl: this.config.apiBaseUrl
|
|
787
|
+
apiBaseUrl: this.config.apiBaseUrl,
|
|
788
|
+
headers: {
|
|
789
|
+
...this.platform.analyticsHeaders || {}
|
|
790
|
+
}
|
|
751
791
|
},
|
|
752
792
|
this.stamper
|
|
753
793
|
);
|
|
@@ -759,8 +799,8 @@ var EmbeddedProvider = class {
|
|
|
759
799
|
publicKey: stamperInfo.publicKey,
|
|
760
800
|
platform: platformName
|
|
761
801
|
});
|
|
762
|
-
const base64urlPublicKey = (0,
|
|
763
|
-
const
|
|
802
|
+
const base64urlPublicKey = (0, import_base64url2.base64urlEncode)(import_bs582.default.decode(stamperInfo.publicKey));
|
|
803
|
+
const expiresInMs = AUTHENTICATOR_EXPIRATION_TIME_MS;
|
|
764
804
|
const username = `user-${shortPubKey}`;
|
|
765
805
|
const { organizationId } = await tempClient.createOrganization(organizationName, [
|
|
766
806
|
{
|
|
@@ -773,13 +813,13 @@ var EmbeddedProvider = class {
|
|
|
773
813
|
publicKey: base64urlPublicKey,
|
|
774
814
|
algorithm: "Ed25519"
|
|
775
815
|
// Commented for now until KMS supports fully expirable organizations
|
|
776
|
-
//
|
|
816
|
+
// expiresInMs: expiresInMs,
|
|
777
817
|
}
|
|
778
818
|
]
|
|
779
819
|
}
|
|
780
820
|
]);
|
|
781
821
|
this.logger.info("EMBEDDED_PROVIDER", "Organization created", { organizationId });
|
|
782
|
-
return { organizationId, stamperInfo,
|
|
822
|
+
return { organizationId, stamperInfo, expiresInMs, username };
|
|
783
823
|
}
|
|
784
824
|
async connect(authOptions) {
|
|
785
825
|
try {
|
|
@@ -808,8 +848,8 @@ var EmbeddedProvider = class {
|
|
|
808
848
|
}
|
|
809
849
|
this.validateAuthOptions(authOptions);
|
|
810
850
|
this.logger.info("EMBEDDED_PROVIDER", "No existing connection, creating new auth flow");
|
|
811
|
-
const { organizationId, stamperInfo,
|
|
812
|
-
const session = await this.handleAuthFlow(organizationId, stamperInfo, authOptions,
|
|
851
|
+
const { organizationId, stamperInfo, expiresInMs, username } = await this.createOrganizationAndStamper();
|
|
852
|
+
const session = await this.handleAuthFlow(organizationId, stamperInfo, authOptions, expiresInMs, username);
|
|
813
853
|
if (!session) {
|
|
814
854
|
return {
|
|
815
855
|
addresses: [],
|
|
@@ -892,7 +932,7 @@ var EmbeddedProvider = class {
|
|
|
892
932
|
walletId: this.walletId,
|
|
893
933
|
message: params.message
|
|
894
934
|
});
|
|
895
|
-
const parsedMessage = (0,
|
|
935
|
+
const parsedMessage = (0, import_parsers2.parseMessage)(params.message);
|
|
896
936
|
const session = await this.storage.getSession();
|
|
897
937
|
const derivationIndex = session?.accountDerivationIndex ?? 0;
|
|
898
938
|
const rawResponse = await this.client.signMessage({
|
|
@@ -905,7 +945,37 @@ var EmbeddedProvider = class {
|
|
|
905
945
|
walletId: this.walletId,
|
|
906
946
|
message: params.message
|
|
907
947
|
});
|
|
908
|
-
return (0,
|
|
948
|
+
return (0, import_parsers2.parseSignMessageResponse)(rawResponse, params.networkId);
|
|
949
|
+
}
|
|
950
|
+
async signTransaction(params) {
|
|
951
|
+
if (!this.client || !this.walletId) {
|
|
952
|
+
throw new Error("Not connected");
|
|
953
|
+
}
|
|
954
|
+
await this.ensureValidAuthenticator();
|
|
955
|
+
this.logger.info("EMBEDDED_PROVIDER", "Signing transaction", {
|
|
956
|
+
walletId: this.walletId,
|
|
957
|
+
networkId: params.networkId
|
|
958
|
+
});
|
|
959
|
+
const parsedTransaction = await (0, import_parsers2.parseTransactionToBase64Url)(params.transaction, params.networkId);
|
|
960
|
+
const session = await this.storage.getSession();
|
|
961
|
+
const derivationIndex = session?.accountDerivationIndex ?? 0;
|
|
962
|
+
this.logger.log("EMBEDDED_PROVIDER", "Parsed transaction for signing", {
|
|
963
|
+
walletId: this.walletId,
|
|
964
|
+
transaction: parsedTransaction,
|
|
965
|
+
derivationIndex
|
|
966
|
+
});
|
|
967
|
+
const rawResponse = await this.client.signTransaction({
|
|
968
|
+
walletId: this.walletId,
|
|
969
|
+
transaction: parsedTransaction.base64url,
|
|
970
|
+
networkId: params.networkId,
|
|
971
|
+
derivationIndex
|
|
972
|
+
});
|
|
973
|
+
this.logger.info("EMBEDDED_PROVIDER", "Transaction signed successfully", {
|
|
974
|
+
walletId: this.walletId,
|
|
975
|
+
networkId: params.networkId,
|
|
976
|
+
rawTransaction: rawResponse.rawTransaction
|
|
977
|
+
});
|
|
978
|
+
return await (0, import_parsers2.parseTransactionResponse)(rawResponse.rawTransaction, params.networkId);
|
|
909
979
|
}
|
|
910
980
|
async signAndSendTransaction(params) {
|
|
911
981
|
if (!this.client || !this.walletId) {
|
|
@@ -916,7 +986,7 @@ var EmbeddedProvider = class {
|
|
|
916
986
|
walletId: this.walletId,
|
|
917
987
|
networkId: params.networkId
|
|
918
988
|
});
|
|
919
|
-
const parsedTransaction = await (0,
|
|
989
|
+
const parsedTransaction = await (0, import_parsers2.parseTransactionToBase64Url)(params.transaction, params.networkId);
|
|
920
990
|
const session = await this.storage.getSession();
|
|
921
991
|
const derivationIndex = session?.accountDerivationIndex ?? 0;
|
|
922
992
|
this.logger.log("EMBEDDED_PROVIDER", "Parsed transaction for signing", {
|
|
@@ -936,7 +1006,7 @@ var EmbeddedProvider = class {
|
|
|
936
1006
|
hash: rawResponse.hash,
|
|
937
1007
|
rawTransaction: rawResponse.rawTransaction
|
|
938
1008
|
});
|
|
939
|
-
return await (0,
|
|
1009
|
+
return await (0, import_parsers2.parseTransactionResponse)(rawResponse.rawTransaction, params.networkId, rawResponse.hash);
|
|
940
1010
|
}
|
|
941
1011
|
getAddresses() {
|
|
942
1012
|
return this.addresses;
|
|
@@ -949,13 +1019,13 @@ var EmbeddedProvider = class {
|
|
|
949
1019
|
* It handles app-wallet creation directly or routes to JWT/redirect authentication for user-wallets.
|
|
950
1020
|
* Returns null for redirect flows since they don't complete synchronously.
|
|
951
1021
|
*/
|
|
952
|
-
async handleAuthFlow(organizationId, stamperInfo, authOptions,
|
|
1022
|
+
async handleAuthFlow(organizationId, stamperInfo, authOptions, expiresInMs, username) {
|
|
953
1023
|
if (this.config.embeddedWalletType === "user-wallet") {
|
|
954
1024
|
this.logger.info("EMBEDDED_PROVIDER", "Creating user-wallet, routing authentication", {
|
|
955
1025
|
authProvider: authOptions?.provider || "phantom-connect"
|
|
956
1026
|
});
|
|
957
1027
|
if (authOptions?.provider === "jwt") {
|
|
958
|
-
return await this.handleJWTAuth(organizationId, stamperInfo, authOptions,
|
|
1028
|
+
return await this.handleJWTAuth(organizationId, stamperInfo, authOptions, expiresInMs, username);
|
|
959
1029
|
} else {
|
|
960
1030
|
this.logger.info("EMBEDDED_PROVIDER", "Starting redirect-based authentication flow", {
|
|
961
1031
|
organizationId,
|
|
@@ -971,7 +1041,10 @@ var EmbeddedProvider = class {
|
|
|
971
1041
|
const tempClient = new import_client.PhantomClient(
|
|
972
1042
|
{
|
|
973
1043
|
apiBaseUrl: this.config.apiBaseUrl,
|
|
974
|
-
organizationId
|
|
1044
|
+
organizationId,
|
|
1045
|
+
headers: {
|
|
1046
|
+
...this.platform.analyticsHeaders || {}
|
|
1047
|
+
}
|
|
975
1048
|
},
|
|
976
1049
|
this.stamper
|
|
977
1050
|
);
|
|
@@ -992,7 +1065,7 @@ var EmbeddedProvider = class {
|
|
|
992
1065
|
createdAt: now,
|
|
993
1066
|
lastUsed: now,
|
|
994
1067
|
authenticatorCreatedAt: now,
|
|
995
|
-
authenticatorExpiresAt:
|
|
1068
|
+
authenticatorExpiresAt: Date.now() + expiresInMs,
|
|
996
1069
|
lastRenewalAttempt: void 0,
|
|
997
1070
|
username
|
|
998
1071
|
};
|
|
@@ -1005,7 +1078,7 @@ var EmbeddedProvider = class {
|
|
|
1005
1078
|
* We use this method to handle JWT-based authentication for user-wallets.
|
|
1006
1079
|
* It authenticates using the provided JWT token and creates a completed session.
|
|
1007
1080
|
*/
|
|
1008
|
-
async handleJWTAuth(organizationId, stamperInfo, authOptions,
|
|
1081
|
+
async handleJWTAuth(organizationId, stamperInfo, authOptions, expiresInMs, username) {
|
|
1009
1082
|
this.logger.info("EMBEDDED_PROVIDER", "Using JWT authentication flow");
|
|
1010
1083
|
if (!authOptions.jwtToken) {
|
|
1011
1084
|
this.logger.error("EMBEDDED_PROVIDER", "JWT token missing for JWT authentication");
|
|
@@ -1035,7 +1108,7 @@ var EmbeddedProvider = class {
|
|
|
1035
1108
|
createdAt: now,
|
|
1036
1109
|
lastUsed: now,
|
|
1037
1110
|
authenticatorCreatedAt: now,
|
|
1038
|
-
authenticatorExpiresAt:
|
|
1111
|
+
authenticatorExpiresAt: Date.now() + expiresInMs,
|
|
1039
1112
|
lastRenewalAttempt: void 0,
|
|
1040
1113
|
username
|
|
1041
1114
|
};
|
|
@@ -1051,8 +1124,8 @@ var EmbeddedProvider = class {
|
|
|
1051
1124
|
async handleRedirectAuth(organizationId, stamperInfo, authOptions, username) {
|
|
1052
1125
|
this.logger.info("EMBEDDED_PROVIDER", "Using Phantom Connect authentication flow (redirect-based)", {
|
|
1053
1126
|
provider: authOptions?.provider,
|
|
1054
|
-
hasRedirectUrl: !!this.config.authOptions
|
|
1055
|
-
authUrl: this.config.authOptions
|
|
1127
|
+
hasRedirectUrl: !!this.config.authOptions.redirectUrl,
|
|
1128
|
+
authUrl: this.config.authOptions.authUrl
|
|
1056
1129
|
});
|
|
1057
1130
|
const now = Date.now();
|
|
1058
1131
|
const sessionId = generateSessionId();
|
|
@@ -1086,16 +1159,16 @@ var EmbeddedProvider = class {
|
|
|
1086
1159
|
parentOrganizationId: this.config.organizationId,
|
|
1087
1160
|
appId: this.config.appId,
|
|
1088
1161
|
provider: authOptions?.provider,
|
|
1089
|
-
authUrl: this.config.authOptions
|
|
1162
|
+
authUrl: this.config.authOptions.authUrl
|
|
1090
1163
|
});
|
|
1091
1164
|
const authResult = await this.authProvider.authenticate({
|
|
1092
1165
|
organizationId,
|
|
1093
1166
|
appId: this.config.appId,
|
|
1094
1167
|
parentOrganizationId: this.config.organizationId,
|
|
1095
1168
|
provider: authOptions?.provider,
|
|
1096
|
-
redirectUrl: this.config.authOptions
|
|
1169
|
+
redirectUrl: this.config.authOptions.redirectUrl,
|
|
1097
1170
|
customAuthData: authOptions?.customAuthData,
|
|
1098
|
-
authUrl: this.config.authOptions
|
|
1171
|
+
authUrl: this.config.authOptions.authUrl,
|
|
1099
1172
|
sessionId
|
|
1100
1173
|
});
|
|
1101
1174
|
if (authResult && "walletId" in authResult) {
|
|
@@ -1190,8 +1263,8 @@ var EmbeddedProvider = class {
|
|
|
1190
1263
|
newKeyId: newKeyInfo.keyId,
|
|
1191
1264
|
newPublicKey: newKeyInfo.publicKey
|
|
1192
1265
|
});
|
|
1193
|
-
const base64urlPublicKey = (0,
|
|
1194
|
-
const
|
|
1266
|
+
const base64urlPublicKey = (0, import_base64url2.base64urlEncode)(import_bs582.default.decode(newKeyInfo.publicKey));
|
|
1267
|
+
const expiresInMs = AUTHENTICATOR_EXPIRATION_TIME_MS;
|
|
1195
1268
|
let authenticatorResult;
|
|
1196
1269
|
try {
|
|
1197
1270
|
authenticatorResult = await this.client.createAuthenticator({
|
|
@@ -1204,7 +1277,7 @@ var EmbeddedProvider = class {
|
|
|
1204
1277
|
publicKey: base64urlPublicKey,
|
|
1205
1278
|
algorithm: "Ed25519"
|
|
1206
1279
|
// Commented for now until KMS supports fully expiring organizations
|
|
1207
|
-
//
|
|
1280
|
+
// expiresInMs: expiresInMs,
|
|
1208
1281
|
},
|
|
1209
1282
|
replaceExpirable: true
|
|
1210
1283
|
});
|
|
@@ -1224,12 +1297,12 @@ var EmbeddedProvider = class {
|
|
|
1224
1297
|
const now = Date.now();
|
|
1225
1298
|
session.stamperInfo = newKeyInfo;
|
|
1226
1299
|
session.authenticatorCreatedAt = now;
|
|
1227
|
-
session.authenticatorExpiresAt =
|
|
1300
|
+
session.authenticatorExpiresAt = Date.now() + expiresInMs;
|
|
1228
1301
|
session.lastRenewalAttempt = now;
|
|
1229
1302
|
await this.storage.saveSession(session);
|
|
1230
1303
|
this.logger.info("EMBEDDED_PROVIDER", "Authenticator renewal completed successfully", {
|
|
1231
1304
|
newKeyId: newKeyInfo.keyId,
|
|
1232
|
-
expiresAt: new Date(
|
|
1305
|
+
expiresAt: new Date(Date.now() + expiresInMs).toISOString()
|
|
1233
1306
|
});
|
|
1234
1307
|
} catch (error) {
|
|
1235
1308
|
await this.stamper.rollbackRotation();
|
|
@@ -1252,7 +1325,10 @@ var EmbeddedProvider = class {
|
|
|
1252
1325
|
this.client = new import_client.PhantomClient(
|
|
1253
1326
|
{
|
|
1254
1327
|
apiBaseUrl: this.config.apiBaseUrl,
|
|
1255
|
-
organizationId: session.organizationId
|
|
1328
|
+
organizationId: session.organizationId,
|
|
1329
|
+
headers: {
|
|
1330
|
+
...this.platform.analyticsHeaders || {}
|
|
1331
|
+
}
|
|
1256
1332
|
},
|
|
1257
1333
|
this.stamper
|
|
1258
1334
|
);
|