@phantom/embedded-provider-core 1.0.0-beta.1 → 1.0.0-beta.10
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 +25 -15
- package/dist/index.d.ts +25 -15
- package/dist/index.js +139 -44
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +139 -44
- package/dist/index.mjs.map +1 -1
- package/package.json +9 -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,8 +1,8 @@
|
|
|
1
|
-
import { StamperWithKeyManagement } from '@phantom/sdk-types';
|
|
1
|
+
import { StamperWithKeyManagement, Transaction, VersionedTransaction } 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
|
-
import { ISolanaChain, IEthereumChain, EthTransactionRequest } from '@phantom/
|
|
5
|
+
import { ISolanaChain, IEthereumChain, EthTransactionRequest } from '@phantom/chain-interfaces';
|
|
6
6
|
|
|
7
7
|
interface Keypair {
|
|
8
8
|
publicKey: string;
|
|
@@ -66,7 +66,6 @@ interface AuthResult {
|
|
|
66
66
|
}
|
|
67
67
|
interface PhantomConnectOptions {
|
|
68
68
|
organizationId: string;
|
|
69
|
-
parentOrganizationId: string;
|
|
70
69
|
appId: string;
|
|
71
70
|
provider?: "google" | "apple";
|
|
72
71
|
redirectUrl?: string;
|
|
@@ -77,7 +76,6 @@ interface PhantomConnectOptions {
|
|
|
77
76
|
interface JWTAuthOptions {
|
|
78
77
|
appId: string;
|
|
79
78
|
organizationId: string;
|
|
80
|
-
parentOrganizationId: string;
|
|
81
79
|
jwtToken: string;
|
|
82
80
|
customAuthData?: Record<string, any>;
|
|
83
81
|
}
|
|
@@ -92,6 +90,7 @@ interface PlatformAdapter {
|
|
|
92
90
|
authProvider: AuthProvider;
|
|
93
91
|
urlParamsAccessor: URLParamsAccessor;
|
|
94
92
|
stamper: StamperWithKeyManagement;
|
|
93
|
+
analyticsHeaders?: Partial<ClientSideSdkHeaders>;
|
|
95
94
|
}
|
|
96
95
|
interface DebugLogger {
|
|
97
96
|
info(category: string, message: string, data?: any): void;
|
|
@@ -115,6 +114,10 @@ interface SignMessageParams {
|
|
|
115
114
|
}
|
|
116
115
|
interface SignMessageResult extends ParsedSignatureResult {
|
|
117
116
|
}
|
|
117
|
+
interface SignTransactionParams {
|
|
118
|
+
transaction: any;
|
|
119
|
+
networkId: NetworkId;
|
|
120
|
+
}
|
|
118
121
|
interface SignAndSendTransactionParams {
|
|
119
122
|
transaction: any;
|
|
120
123
|
networkId: NetworkId;
|
|
@@ -129,14 +132,12 @@ interface AuthOptions {
|
|
|
129
132
|
interface EmbeddedProviderConfig {
|
|
130
133
|
apiBaseUrl: string;
|
|
131
134
|
appId: string;
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
redirectUrl?: string;
|
|
135
|
+
authOptions: {
|
|
136
|
+
authUrl: string;
|
|
137
|
+
redirectUrl: string;
|
|
136
138
|
};
|
|
137
139
|
embeddedWalletType: "app-wallet" | "user-wallet" | (string & Record<never, never>);
|
|
138
|
-
addressTypes:
|
|
139
|
-
solanaProvider: "web3js" | "kit" | (string & Record<never, never>);
|
|
140
|
+
addressTypes: AddressType[];
|
|
140
141
|
}
|
|
141
142
|
|
|
142
143
|
type EmbeddedProviderEvent = "connect" | "connect_start" | "connect_error" | "disconnect" | "error";
|
|
@@ -160,6 +161,10 @@ declare class EmbeddedProvider {
|
|
|
160
161
|
on(event: EmbeddedProviderEvent, callback: EventCallback): void;
|
|
161
162
|
off(event: EmbeddedProviderEvent, callback: EventCallback): void;
|
|
162
163
|
private emit;
|
|
164
|
+
/**
|
|
165
|
+
* Get the appropriate address for a given network ID from available addresses
|
|
166
|
+
*/
|
|
167
|
+
private getAddressForNetwork;
|
|
163
168
|
private getAndFilterWalletAddresses;
|
|
164
169
|
private validateAndCleanSession;
|
|
165
170
|
private tryExistingConnection;
|
|
@@ -170,6 +175,7 @@ declare class EmbeddedProvider {
|
|
|
170
175
|
connect(authOptions?: AuthOptions): Promise<ConnectResult>;
|
|
171
176
|
disconnect(): Promise<void>;
|
|
172
177
|
signMessage(params: SignMessageParams): Promise<ParsedSignatureResult>;
|
|
178
|
+
signTransaction(params: SignTransactionParams): Promise<ParsedTransactionResult>;
|
|
173
179
|
signAndSendTransaction(params: SignAndSendTransactionParams): Promise<ParsedTransactionResult>;
|
|
174
180
|
getAddresses(): WalletAddress[];
|
|
175
181
|
isConnected(): boolean;
|
|
@@ -207,11 +213,14 @@ declare class EmbeddedSolanaChain implements ISolanaChain {
|
|
|
207
213
|
signature: Uint8Array;
|
|
208
214
|
publicKey: string;
|
|
209
215
|
}>;
|
|
210
|
-
signTransaction
|
|
211
|
-
signAndSendTransaction
|
|
216
|
+
signTransaction(_transaction: Transaction | VersionedTransaction): Promise<Transaction | VersionedTransaction>;
|
|
217
|
+
signAndSendTransaction(transaction: Transaction | VersionedTransaction): Promise<{
|
|
212
218
|
signature: string;
|
|
213
219
|
}>;
|
|
214
|
-
signAllTransactions
|
|
220
|
+
signAllTransactions(_transactions: (Transaction | VersionedTransaction)[]): Promise<(Transaction | VersionedTransaction)[]>;
|
|
221
|
+
signAndSendAllTransactions(transactions: (Transaction | VersionedTransaction)[]): Promise<{
|
|
222
|
+
signatures: string[];
|
|
223
|
+
}>;
|
|
215
224
|
connect(_options?: {
|
|
216
225
|
onlyIfTrusted?: boolean;
|
|
217
226
|
}): Promise<{
|
|
@@ -250,6 +259,7 @@ declare class EmbeddedEthereumChain implements IEthereumChain {
|
|
|
250
259
|
disconnect(): Promise<void>;
|
|
251
260
|
signPersonalMessage(message: string, address: string): Promise<string>;
|
|
252
261
|
signTypedData(typedData: any, address: string): Promise<string>;
|
|
262
|
+
signTransaction(transaction: EthTransactionRequest): Promise<string>;
|
|
253
263
|
sendTransaction(transaction: EthTransactionRequest): Promise<string>;
|
|
254
264
|
switchChain(chainId: number): Promise<void>;
|
|
255
265
|
getChainId(): Promise<number>;
|
|
@@ -279,4 +289,4 @@ declare const AUTHENTICATOR_EXPIRATION_TIME_MS: number;
|
|
|
279
289
|
*/
|
|
280
290
|
declare const AUTHENTICATOR_RENEWAL_WINDOW_MS: number;
|
|
281
291
|
|
|
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 };
|
|
292
|
+
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,8 +1,8 @@
|
|
|
1
|
-
import { StamperWithKeyManagement } from '@phantom/sdk-types';
|
|
1
|
+
import { StamperWithKeyManagement, Transaction, VersionedTransaction } 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
|
-
import { ISolanaChain, IEthereumChain, EthTransactionRequest } from '@phantom/
|
|
5
|
+
import { ISolanaChain, IEthereumChain, EthTransactionRequest } from '@phantom/chain-interfaces';
|
|
6
6
|
|
|
7
7
|
interface Keypair {
|
|
8
8
|
publicKey: string;
|
|
@@ -66,7 +66,6 @@ interface AuthResult {
|
|
|
66
66
|
}
|
|
67
67
|
interface PhantomConnectOptions {
|
|
68
68
|
organizationId: string;
|
|
69
|
-
parentOrganizationId: string;
|
|
70
69
|
appId: string;
|
|
71
70
|
provider?: "google" | "apple";
|
|
72
71
|
redirectUrl?: string;
|
|
@@ -77,7 +76,6 @@ interface PhantomConnectOptions {
|
|
|
77
76
|
interface JWTAuthOptions {
|
|
78
77
|
appId: string;
|
|
79
78
|
organizationId: string;
|
|
80
|
-
parentOrganizationId: string;
|
|
81
79
|
jwtToken: string;
|
|
82
80
|
customAuthData?: Record<string, any>;
|
|
83
81
|
}
|
|
@@ -92,6 +90,7 @@ interface PlatformAdapter {
|
|
|
92
90
|
authProvider: AuthProvider;
|
|
93
91
|
urlParamsAccessor: URLParamsAccessor;
|
|
94
92
|
stamper: StamperWithKeyManagement;
|
|
93
|
+
analyticsHeaders?: Partial<ClientSideSdkHeaders>;
|
|
95
94
|
}
|
|
96
95
|
interface DebugLogger {
|
|
97
96
|
info(category: string, message: string, data?: any): void;
|
|
@@ -115,6 +114,10 @@ interface SignMessageParams {
|
|
|
115
114
|
}
|
|
116
115
|
interface SignMessageResult extends ParsedSignatureResult {
|
|
117
116
|
}
|
|
117
|
+
interface SignTransactionParams {
|
|
118
|
+
transaction: any;
|
|
119
|
+
networkId: NetworkId;
|
|
120
|
+
}
|
|
118
121
|
interface SignAndSendTransactionParams {
|
|
119
122
|
transaction: any;
|
|
120
123
|
networkId: NetworkId;
|
|
@@ -129,14 +132,12 @@ interface AuthOptions {
|
|
|
129
132
|
interface EmbeddedProviderConfig {
|
|
130
133
|
apiBaseUrl: string;
|
|
131
134
|
appId: string;
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
redirectUrl?: string;
|
|
135
|
+
authOptions: {
|
|
136
|
+
authUrl: string;
|
|
137
|
+
redirectUrl: string;
|
|
136
138
|
};
|
|
137
139
|
embeddedWalletType: "app-wallet" | "user-wallet" | (string & Record<never, never>);
|
|
138
|
-
addressTypes:
|
|
139
|
-
solanaProvider: "web3js" | "kit" | (string & Record<never, never>);
|
|
140
|
+
addressTypes: AddressType[];
|
|
140
141
|
}
|
|
141
142
|
|
|
142
143
|
type EmbeddedProviderEvent = "connect" | "connect_start" | "connect_error" | "disconnect" | "error";
|
|
@@ -160,6 +161,10 @@ declare class EmbeddedProvider {
|
|
|
160
161
|
on(event: EmbeddedProviderEvent, callback: EventCallback): void;
|
|
161
162
|
off(event: EmbeddedProviderEvent, callback: EventCallback): void;
|
|
162
163
|
private emit;
|
|
164
|
+
/**
|
|
165
|
+
* Get the appropriate address for a given network ID from available addresses
|
|
166
|
+
*/
|
|
167
|
+
private getAddressForNetwork;
|
|
163
168
|
private getAndFilterWalletAddresses;
|
|
164
169
|
private validateAndCleanSession;
|
|
165
170
|
private tryExistingConnection;
|
|
@@ -170,6 +175,7 @@ declare class EmbeddedProvider {
|
|
|
170
175
|
connect(authOptions?: AuthOptions): Promise<ConnectResult>;
|
|
171
176
|
disconnect(): Promise<void>;
|
|
172
177
|
signMessage(params: SignMessageParams): Promise<ParsedSignatureResult>;
|
|
178
|
+
signTransaction(params: SignTransactionParams): Promise<ParsedTransactionResult>;
|
|
173
179
|
signAndSendTransaction(params: SignAndSendTransactionParams): Promise<ParsedTransactionResult>;
|
|
174
180
|
getAddresses(): WalletAddress[];
|
|
175
181
|
isConnected(): boolean;
|
|
@@ -207,11 +213,14 @@ declare class EmbeddedSolanaChain implements ISolanaChain {
|
|
|
207
213
|
signature: Uint8Array;
|
|
208
214
|
publicKey: string;
|
|
209
215
|
}>;
|
|
210
|
-
signTransaction
|
|
211
|
-
signAndSendTransaction
|
|
216
|
+
signTransaction(_transaction: Transaction | VersionedTransaction): Promise<Transaction | VersionedTransaction>;
|
|
217
|
+
signAndSendTransaction(transaction: Transaction | VersionedTransaction): Promise<{
|
|
212
218
|
signature: string;
|
|
213
219
|
}>;
|
|
214
|
-
signAllTransactions
|
|
220
|
+
signAllTransactions(_transactions: (Transaction | VersionedTransaction)[]): Promise<(Transaction | VersionedTransaction)[]>;
|
|
221
|
+
signAndSendAllTransactions(transactions: (Transaction | VersionedTransaction)[]): Promise<{
|
|
222
|
+
signatures: string[];
|
|
223
|
+
}>;
|
|
215
224
|
connect(_options?: {
|
|
216
225
|
onlyIfTrusted?: boolean;
|
|
217
226
|
}): Promise<{
|
|
@@ -250,6 +259,7 @@ declare class EmbeddedEthereumChain implements IEthereumChain {
|
|
|
250
259
|
disconnect(): Promise<void>;
|
|
251
260
|
signPersonalMessage(message: string, address: string): Promise<string>;
|
|
252
261
|
signTypedData(typedData: any, address: string): Promise<string>;
|
|
262
|
+
signTransaction(transaction: EthTransactionRequest): Promise<string>;
|
|
253
263
|
sendTransaction(transaction: EthTransactionRequest): Promise<string>;
|
|
254
264
|
switchChain(chainId: number): Promise<void>;
|
|
255
265
|
getChainId(): Promise<number>;
|
|
@@ -279,4 +289,4 @@ declare const AUTHENTICATOR_EXPIRATION_TIME_MS: number;
|
|
|
279
289
|
*/
|
|
280
290
|
declare const AUTHENTICATOR_RENEWAL_WINDOW_MS: number;
|
|
281
291
|
|
|
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 };
|
|
292
|
+
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,8 +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
|
|
46
|
+
var import_utils = require("@phantom/utils");
|
|
47
|
+
var import_base64url2 = require("@phantom/base64url");
|
|
48
|
+
var import_bs582 = __toESM(require("bs58"));
|
|
48
49
|
var import_parsers = require("@phantom/parsers");
|
|
49
50
|
|
|
50
51
|
// src/constants.ts
|
|
@@ -70,8 +71,7 @@ var JWTAuth = class {
|
|
|
70
71
|
"X-PHANTOM-APPID": options.appId
|
|
71
72
|
},
|
|
72
73
|
body: JSON.stringify({
|
|
73
|
-
|
|
74
|
-
parentOrganizationId: options.parentOrganizationId,
|
|
74
|
+
appId: options.appId,
|
|
75
75
|
customAuthData: options.customAuthData
|
|
76
76
|
})
|
|
77
77
|
});
|
|
@@ -171,7 +171,7 @@ 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
175
|
var EmbeddedSolanaChain = class {
|
|
176
176
|
constructor(provider) {
|
|
177
177
|
this.provider = provider;
|
|
@@ -202,15 +202,14 @@ var EmbeddedSolanaChain = class {
|
|
|
202
202
|
message: messageStr,
|
|
203
203
|
networkId: this.currentNetworkId
|
|
204
204
|
});
|
|
205
|
-
const signature = typeof result.signature === "string" ? new Uint8Array(
|
|
205
|
+
const signature = typeof result.signature === "string" ? new Uint8Array(import_bs58.default.decode(result.signature)) : result.signature;
|
|
206
206
|
return {
|
|
207
207
|
signature,
|
|
208
208
|
publicKey: this._publicKey || ""
|
|
209
209
|
};
|
|
210
210
|
}
|
|
211
211
|
signTransaction(_transaction) {
|
|
212
|
-
|
|
213
|
-
throw new Error("signTransaction not yet implemented for embedded provider");
|
|
212
|
+
return Promise.reject(new Error("signTransaction is not supported in embedded provider. Use signAndSendTransaction instead."));
|
|
214
213
|
}
|
|
215
214
|
async signAndSendTransaction(transaction) {
|
|
216
215
|
this.ensureConnected();
|
|
@@ -223,9 +222,12 @@ var EmbeddedSolanaChain = class {
|
|
|
223
222
|
}
|
|
224
223
|
return { signature: result.hash };
|
|
225
224
|
}
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
225
|
+
signAllTransactions(_transactions) {
|
|
226
|
+
return Promise.reject(new Error("signAllTransactions is not supported in embedded provider. Use signAndSendAllTransactions instead."));
|
|
227
|
+
}
|
|
228
|
+
async signAndSendAllTransactions(transactions) {
|
|
229
|
+
const results = await Promise.all(transactions.map((tx) => this.signAndSendTransaction(tx)));
|
|
230
|
+
return { signatures: results.map((result) => result.signature) };
|
|
229
231
|
}
|
|
230
232
|
connect(_options) {
|
|
231
233
|
if (!this.provider.isConnected()) {
|
|
@@ -293,6 +295,8 @@ var EmbeddedSolanaChain = class {
|
|
|
293
295
|
// src/chains/EthereumChain.ts
|
|
294
296
|
var import_eventemitter32 = require("eventemitter3");
|
|
295
297
|
var import_constants2 = require("@phantom/constants");
|
|
298
|
+
var import_base64url = require("@phantom/base64url");
|
|
299
|
+
var import_buffer = require("buffer");
|
|
296
300
|
var EmbeddedEthereumChain = class {
|
|
297
301
|
constructor(provider) {
|
|
298
302
|
this.provider = provider;
|
|
@@ -349,6 +353,18 @@ var EmbeddedEthereumChain = class {
|
|
|
349
353
|
params: [address, JSON.stringify(typedData)]
|
|
350
354
|
});
|
|
351
355
|
}
|
|
356
|
+
async signTransaction(transaction) {
|
|
357
|
+
const result = await this.provider.signTransaction({
|
|
358
|
+
transaction,
|
|
359
|
+
networkId: this.currentNetworkId
|
|
360
|
+
});
|
|
361
|
+
try {
|
|
362
|
+
const signatureBytes = (0, import_base64url.base64urlDecode)(result.rawTransaction);
|
|
363
|
+
return "0x" + import_buffer.Buffer.from(signatureBytes).toString("hex");
|
|
364
|
+
} catch (error) {
|
|
365
|
+
return result.rawTransaction.startsWith("0x") ? result.rawTransaction : "0x" + result.rawTransaction;
|
|
366
|
+
}
|
|
367
|
+
}
|
|
352
368
|
async sendTransaction(transaction) {
|
|
353
369
|
const result = await this.provider.signAndSendTransaction({
|
|
354
370
|
transaction,
|
|
@@ -426,6 +442,17 @@ var EmbeddedEthereumChain = class {
|
|
|
426
442
|
});
|
|
427
443
|
return typedDataResult.signature;
|
|
428
444
|
}
|
|
445
|
+
case "eth_signTransaction": {
|
|
446
|
+
const [transaction] = args.params;
|
|
447
|
+
const networkIdFromTx = transaction.chainId ? (0, import_constants2.chainIdToNetworkId)(
|
|
448
|
+
typeof transaction.chainId === "number" ? transaction.chainId : parseInt(transaction.chainId, 16)
|
|
449
|
+
) : null;
|
|
450
|
+
const signResult = await this.provider.signTransaction({
|
|
451
|
+
transaction,
|
|
452
|
+
networkId: networkIdFromTx || this.currentNetworkId
|
|
453
|
+
});
|
|
454
|
+
return signResult.rawTransaction;
|
|
455
|
+
}
|
|
429
456
|
case "eth_sendTransaction": {
|
|
430
457
|
const [transaction] = args.params;
|
|
431
458
|
const networkIdFromTx = transaction.chainId ? (0, import_constants2.chainIdToNetworkId)(
|
|
@@ -473,6 +500,9 @@ var EmbeddedProvider = class {
|
|
|
473
500
|
this.eventListeners = /* @__PURE__ */ new Map();
|
|
474
501
|
this.logger = logger;
|
|
475
502
|
this.logger.log("EMBEDDED_PROVIDER", "Initializing EmbeddedProvider", { config });
|
|
503
|
+
if (config.embeddedWalletType === "app-wallet") {
|
|
504
|
+
throw new Error("app-wallet type is not currently supported. Please use 'user-wallet' instead.");
|
|
505
|
+
}
|
|
476
506
|
this.config = config;
|
|
477
507
|
this.platform = platform;
|
|
478
508
|
this.storage = platform.storage;
|
|
@@ -480,7 +510,6 @@ var EmbeddedProvider = class {
|
|
|
480
510
|
this.urlParamsAccessor = platform.urlParamsAccessor;
|
|
481
511
|
this.stamper = platform.stamper;
|
|
482
512
|
this.jwtAuth = new JWTAuth();
|
|
483
|
-
config.solanaProvider;
|
|
484
513
|
this.solana = new EmbeddedSolanaChain(this);
|
|
485
514
|
this.ethereum = new EmbeddedEthereumChain(this);
|
|
486
515
|
this.logger.info("EMBEDDED_PROVIDER", "EmbeddedProvider initialized");
|
|
@@ -515,6 +544,35 @@ var EmbeddedProvider = class {
|
|
|
515
544
|
});
|
|
516
545
|
}
|
|
517
546
|
}
|
|
547
|
+
/**
|
|
548
|
+
* Get the appropriate address for a given network ID from available addresses
|
|
549
|
+
*/
|
|
550
|
+
getAddressForNetwork(networkId) {
|
|
551
|
+
const network = networkId.split(":")[0].toLowerCase();
|
|
552
|
+
let targetAddressType;
|
|
553
|
+
switch (network) {
|
|
554
|
+
case "solana":
|
|
555
|
+
targetAddressType = import_client.AddressType.solana;
|
|
556
|
+
break;
|
|
557
|
+
case "eip155":
|
|
558
|
+
targetAddressType = import_client.AddressType.ethereum;
|
|
559
|
+
break;
|
|
560
|
+
case "bitcoin":
|
|
561
|
+
case "btc":
|
|
562
|
+
targetAddressType = import_client.AddressType.bitcoinSegwit;
|
|
563
|
+
break;
|
|
564
|
+
case "sui":
|
|
565
|
+
targetAddressType = import_client.AddressType.sui;
|
|
566
|
+
break;
|
|
567
|
+
default:
|
|
568
|
+
targetAddressType = import_client.AddressType.ethereum;
|
|
569
|
+
break;
|
|
570
|
+
}
|
|
571
|
+
const matchingAddress = this.addresses.find(
|
|
572
|
+
(addr) => addr.addressType.toLowerCase() === targetAddressType.toLowerCase()
|
|
573
|
+
);
|
|
574
|
+
return matchingAddress?.address;
|
|
575
|
+
}
|
|
518
576
|
async getAndFilterWalletAddresses(walletId) {
|
|
519
577
|
const session = await this.storage.getSession();
|
|
520
578
|
const derivationIndex = session?.accountDerivationIndex ?? 0;
|
|
@@ -747,21 +805,24 @@ var EmbeddedProvider = class {
|
|
|
747
805
|
this.logger.log("EMBEDDED_PROVIDER", "Creating temporary PhantomClient");
|
|
748
806
|
const tempClient = new import_client.PhantomClient(
|
|
749
807
|
{
|
|
750
|
-
apiBaseUrl: this.config.apiBaseUrl
|
|
808
|
+
apiBaseUrl: this.config.apiBaseUrl,
|
|
809
|
+
headers: {
|
|
810
|
+
...this.platform.analyticsHeaders || {}
|
|
811
|
+
}
|
|
751
812
|
},
|
|
752
813
|
this.stamper
|
|
753
814
|
);
|
|
754
815
|
const platformName = this.platform.name || "unknown";
|
|
755
816
|
const shortPubKey = stamperInfo.publicKey.slice(0, 8);
|
|
756
|
-
const organizationName = `${this.config.
|
|
817
|
+
const organizationName = `${this.config.appId.substring(0, 8)}-${platformName}-${shortPubKey}`;
|
|
757
818
|
this.logger.log("EMBEDDED_PROVIDER", "Creating organization", {
|
|
758
819
|
organizationName,
|
|
759
820
|
publicKey: stamperInfo.publicKey,
|
|
760
821
|
platform: platformName
|
|
761
822
|
});
|
|
762
|
-
const base64urlPublicKey = (0,
|
|
763
|
-
const
|
|
764
|
-
const username = `user-${
|
|
823
|
+
const base64urlPublicKey = (0, import_base64url2.base64urlEncode)(import_bs582.default.decode(stamperInfo.publicKey));
|
|
824
|
+
const expiresInMs = AUTHENTICATOR_EXPIRATION_TIME_MS;
|
|
825
|
+
const username = `user-${(0, import_utils.randomUUID)()}`;
|
|
765
826
|
const { organizationId } = await tempClient.createOrganization(organizationName, [
|
|
766
827
|
{
|
|
767
828
|
username,
|
|
@@ -773,13 +834,13 @@ var EmbeddedProvider = class {
|
|
|
773
834
|
publicKey: base64urlPublicKey,
|
|
774
835
|
algorithm: "Ed25519"
|
|
775
836
|
// Commented for now until KMS supports fully expirable organizations
|
|
776
|
-
//
|
|
837
|
+
// expiresInMs: expiresInMs,
|
|
777
838
|
}
|
|
778
839
|
]
|
|
779
840
|
}
|
|
780
841
|
]);
|
|
781
842
|
this.logger.info("EMBEDDED_PROVIDER", "Organization created", { organizationId });
|
|
782
|
-
return { organizationId, stamperInfo,
|
|
843
|
+
return { organizationId, stamperInfo, expiresInMs, username };
|
|
783
844
|
}
|
|
784
845
|
async connect(authOptions) {
|
|
785
846
|
try {
|
|
@@ -808,8 +869,8 @@ var EmbeddedProvider = class {
|
|
|
808
869
|
}
|
|
809
870
|
this.validateAuthOptions(authOptions);
|
|
810
871
|
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,
|
|
872
|
+
const { organizationId, stamperInfo, expiresInMs, username } = await this.createOrganizationAndStamper();
|
|
873
|
+
const session = await this.handleAuthFlow(organizationId, stamperInfo, authOptions, expiresInMs, username);
|
|
813
874
|
if (!session) {
|
|
814
875
|
return {
|
|
815
876
|
addresses: [],
|
|
@@ -907,6 +968,37 @@ var EmbeddedProvider = class {
|
|
|
907
968
|
});
|
|
908
969
|
return (0, import_parsers.parseSignMessageResponse)(rawResponse, params.networkId);
|
|
909
970
|
}
|
|
971
|
+
async signTransaction(params) {
|
|
972
|
+
if (!this.client || !this.walletId) {
|
|
973
|
+
throw new Error("Not connected");
|
|
974
|
+
}
|
|
975
|
+
await this.ensureValidAuthenticator();
|
|
976
|
+
this.logger.info("EMBEDDED_PROVIDER", "Signing transaction", {
|
|
977
|
+
walletId: this.walletId,
|
|
978
|
+
networkId: params.networkId
|
|
979
|
+
});
|
|
980
|
+
const parsedTransaction = await (0, import_parsers.parseTransactionToBase64Url)(params.transaction, params.networkId);
|
|
981
|
+
const session = await this.storage.getSession();
|
|
982
|
+
const derivationIndex = session?.accountDerivationIndex ?? 0;
|
|
983
|
+
this.logger.log("EMBEDDED_PROVIDER", "Parsed transaction for signing", {
|
|
984
|
+
walletId: this.walletId,
|
|
985
|
+
transaction: parsedTransaction,
|
|
986
|
+
derivationIndex
|
|
987
|
+
});
|
|
988
|
+
const rawResponse = await this.client.signTransaction({
|
|
989
|
+
walletId: this.walletId,
|
|
990
|
+
transaction: parsedTransaction.base64url,
|
|
991
|
+
networkId: params.networkId,
|
|
992
|
+
derivationIndex,
|
|
993
|
+
account: this.getAddressForNetwork(params.networkId)
|
|
994
|
+
});
|
|
995
|
+
this.logger.info("EMBEDDED_PROVIDER", "Transaction signed successfully", {
|
|
996
|
+
walletId: this.walletId,
|
|
997
|
+
networkId: params.networkId,
|
|
998
|
+
rawTransaction: rawResponse.rawTransaction
|
|
999
|
+
});
|
|
1000
|
+
return await (0, import_parsers.parseTransactionResponse)(rawResponse.rawTransaction, params.networkId);
|
|
1001
|
+
}
|
|
910
1002
|
async signAndSendTransaction(params) {
|
|
911
1003
|
if (!this.client || !this.walletId) {
|
|
912
1004
|
throw new Error("Not connected");
|
|
@@ -928,7 +1020,8 @@ var EmbeddedProvider = class {
|
|
|
928
1020
|
walletId: this.walletId,
|
|
929
1021
|
transaction: parsedTransaction.base64url,
|
|
930
1022
|
networkId: params.networkId,
|
|
931
|
-
derivationIndex
|
|
1023
|
+
derivationIndex,
|
|
1024
|
+
account: this.getAddressForNetwork(params.networkId)
|
|
932
1025
|
});
|
|
933
1026
|
this.logger.info("EMBEDDED_PROVIDER", "Transaction signed and sent successfully", {
|
|
934
1027
|
walletId: this.walletId,
|
|
@@ -949,17 +1042,16 @@ var EmbeddedProvider = class {
|
|
|
949
1042
|
* It handles app-wallet creation directly or routes to JWT/redirect authentication for user-wallets.
|
|
950
1043
|
* Returns null for redirect flows since they don't complete synchronously.
|
|
951
1044
|
*/
|
|
952
|
-
async handleAuthFlow(organizationId, stamperInfo, authOptions,
|
|
1045
|
+
async handleAuthFlow(organizationId, stamperInfo, authOptions, expiresInMs, username) {
|
|
953
1046
|
if (this.config.embeddedWalletType === "user-wallet") {
|
|
954
1047
|
this.logger.info("EMBEDDED_PROVIDER", "Creating user-wallet, routing authentication", {
|
|
955
1048
|
authProvider: authOptions?.provider || "phantom-connect"
|
|
956
1049
|
});
|
|
957
1050
|
if (authOptions?.provider === "jwt") {
|
|
958
|
-
return await this.handleJWTAuth(organizationId, stamperInfo, authOptions,
|
|
1051
|
+
return await this.handleJWTAuth(organizationId, stamperInfo, authOptions, expiresInMs, username);
|
|
959
1052
|
} else {
|
|
960
1053
|
this.logger.info("EMBEDDED_PROVIDER", "Starting redirect-based authentication flow", {
|
|
961
1054
|
organizationId,
|
|
962
|
-
parentOrganizationId: this.config.organizationId,
|
|
963
1055
|
provider: authOptions?.provider
|
|
964
1056
|
});
|
|
965
1057
|
return await this.handleRedirectAuth(organizationId, stamperInfo, authOptions, username);
|
|
@@ -971,7 +1063,10 @@ var EmbeddedProvider = class {
|
|
|
971
1063
|
const tempClient = new import_client.PhantomClient(
|
|
972
1064
|
{
|
|
973
1065
|
apiBaseUrl: this.config.apiBaseUrl,
|
|
974
|
-
organizationId
|
|
1066
|
+
organizationId,
|
|
1067
|
+
headers: {
|
|
1068
|
+
...this.platform.analyticsHeaders || {}
|
|
1069
|
+
}
|
|
975
1070
|
},
|
|
976
1071
|
this.stamper
|
|
977
1072
|
);
|
|
@@ -992,7 +1087,7 @@ var EmbeddedProvider = class {
|
|
|
992
1087
|
createdAt: now,
|
|
993
1088
|
lastUsed: now,
|
|
994
1089
|
authenticatorCreatedAt: now,
|
|
995
|
-
authenticatorExpiresAt:
|
|
1090
|
+
authenticatorExpiresAt: Date.now() + expiresInMs,
|
|
996
1091
|
lastRenewalAttempt: void 0,
|
|
997
1092
|
username
|
|
998
1093
|
};
|
|
@@ -1005,7 +1100,7 @@ var EmbeddedProvider = class {
|
|
|
1005
1100
|
* We use this method to handle JWT-based authentication for user-wallets.
|
|
1006
1101
|
* It authenticates using the provided JWT token and creates a completed session.
|
|
1007
1102
|
*/
|
|
1008
|
-
async handleJWTAuth(organizationId, stamperInfo, authOptions,
|
|
1103
|
+
async handleJWTAuth(organizationId, stamperInfo, authOptions, expiresInMs, username) {
|
|
1009
1104
|
this.logger.info("EMBEDDED_PROVIDER", "Using JWT authentication flow");
|
|
1010
1105
|
if (!authOptions.jwtToken) {
|
|
1011
1106
|
this.logger.error("EMBEDDED_PROVIDER", "JWT token missing for JWT authentication");
|
|
@@ -1015,7 +1110,6 @@ var EmbeddedProvider = class {
|
|
|
1015
1110
|
const authResult = await this.jwtAuth.authenticate({
|
|
1016
1111
|
organizationId,
|
|
1017
1112
|
appId: this.config.appId,
|
|
1018
|
-
parentOrganizationId: this.config.organizationId,
|
|
1019
1113
|
jwtToken: authOptions.jwtToken,
|
|
1020
1114
|
customAuthData: authOptions.customAuthData
|
|
1021
1115
|
});
|
|
@@ -1035,7 +1129,7 @@ var EmbeddedProvider = class {
|
|
|
1035
1129
|
createdAt: now,
|
|
1036
1130
|
lastUsed: now,
|
|
1037
1131
|
authenticatorCreatedAt: now,
|
|
1038
|
-
authenticatorExpiresAt:
|
|
1132
|
+
authenticatorExpiresAt: Date.now() + expiresInMs,
|
|
1039
1133
|
lastRenewalAttempt: void 0,
|
|
1040
1134
|
username
|
|
1041
1135
|
};
|
|
@@ -1051,8 +1145,8 @@ var EmbeddedProvider = class {
|
|
|
1051
1145
|
async handleRedirectAuth(organizationId, stamperInfo, authOptions, username) {
|
|
1052
1146
|
this.logger.info("EMBEDDED_PROVIDER", "Using Phantom Connect authentication flow (redirect-based)", {
|
|
1053
1147
|
provider: authOptions?.provider,
|
|
1054
|
-
hasRedirectUrl: !!this.config.authOptions
|
|
1055
|
-
authUrl: this.config.authOptions
|
|
1148
|
+
hasRedirectUrl: !!this.config.authOptions.redirectUrl,
|
|
1149
|
+
authUrl: this.config.authOptions.authUrl
|
|
1056
1150
|
});
|
|
1057
1151
|
const now = Date.now();
|
|
1058
1152
|
const sessionId = generateSessionId();
|
|
@@ -1073,7 +1167,7 @@ var EmbeddedProvider = class {
|
|
|
1073
1167
|
authenticatorCreatedAt: now,
|
|
1074
1168
|
authenticatorExpiresAt: now + AUTHENTICATOR_EXPIRATION_TIME_MS,
|
|
1075
1169
|
lastRenewalAttempt: void 0,
|
|
1076
|
-
username: username || `user-${
|
|
1170
|
+
username: username || `user-${(0, import_utils.randomUUID)()}`
|
|
1077
1171
|
};
|
|
1078
1172
|
this.logger.log("EMBEDDED_PROVIDER", "Saving temporary session before redirect", {
|
|
1079
1173
|
sessionId: tempSession.sessionId,
|
|
@@ -1083,19 +1177,17 @@ var EmbeddedProvider = class {
|
|
|
1083
1177
|
await this.storage.saveSession(tempSession);
|
|
1084
1178
|
this.logger.info("EMBEDDED_PROVIDER", "Starting Phantom Connect redirect", {
|
|
1085
1179
|
organizationId,
|
|
1086
|
-
parentOrganizationId: this.config.organizationId,
|
|
1087
1180
|
appId: this.config.appId,
|
|
1088
1181
|
provider: authOptions?.provider,
|
|
1089
|
-
authUrl: this.config.authOptions
|
|
1182
|
+
authUrl: this.config.authOptions.authUrl
|
|
1090
1183
|
});
|
|
1091
1184
|
const authResult = await this.authProvider.authenticate({
|
|
1092
1185
|
organizationId,
|
|
1093
1186
|
appId: this.config.appId,
|
|
1094
|
-
parentOrganizationId: this.config.organizationId,
|
|
1095
1187
|
provider: authOptions?.provider,
|
|
1096
|
-
redirectUrl: this.config.authOptions
|
|
1188
|
+
redirectUrl: this.config.authOptions.redirectUrl,
|
|
1097
1189
|
customAuthData: authOptions?.customAuthData,
|
|
1098
|
-
authUrl: this.config.authOptions
|
|
1190
|
+
authUrl: this.config.authOptions.authUrl,
|
|
1099
1191
|
sessionId
|
|
1100
1192
|
});
|
|
1101
1193
|
if (authResult && "walletId" in authResult) {
|
|
@@ -1190,8 +1282,8 @@ var EmbeddedProvider = class {
|
|
|
1190
1282
|
newKeyId: newKeyInfo.keyId,
|
|
1191
1283
|
newPublicKey: newKeyInfo.publicKey
|
|
1192
1284
|
});
|
|
1193
|
-
const base64urlPublicKey = (0,
|
|
1194
|
-
const
|
|
1285
|
+
const base64urlPublicKey = (0, import_base64url2.base64urlEncode)(import_bs582.default.decode(newKeyInfo.publicKey));
|
|
1286
|
+
const expiresInMs = AUTHENTICATOR_EXPIRATION_TIME_MS;
|
|
1195
1287
|
let authenticatorResult;
|
|
1196
1288
|
try {
|
|
1197
1289
|
authenticatorResult = await this.client.createAuthenticator({
|
|
@@ -1204,7 +1296,7 @@ var EmbeddedProvider = class {
|
|
|
1204
1296
|
publicKey: base64urlPublicKey,
|
|
1205
1297
|
algorithm: "Ed25519"
|
|
1206
1298
|
// Commented for now until KMS supports fully expiring organizations
|
|
1207
|
-
//
|
|
1299
|
+
// expiresInMs: expiresInMs,
|
|
1208
1300
|
},
|
|
1209
1301
|
replaceExpirable: true
|
|
1210
1302
|
});
|
|
@@ -1224,12 +1316,12 @@ var EmbeddedProvider = class {
|
|
|
1224
1316
|
const now = Date.now();
|
|
1225
1317
|
session.stamperInfo = newKeyInfo;
|
|
1226
1318
|
session.authenticatorCreatedAt = now;
|
|
1227
|
-
session.authenticatorExpiresAt =
|
|
1319
|
+
session.authenticatorExpiresAt = Date.now() + expiresInMs;
|
|
1228
1320
|
session.lastRenewalAttempt = now;
|
|
1229
1321
|
await this.storage.saveSession(session);
|
|
1230
1322
|
this.logger.info("EMBEDDED_PROVIDER", "Authenticator renewal completed successfully", {
|
|
1231
1323
|
newKeyId: newKeyInfo.keyId,
|
|
1232
|
-
expiresAt: new Date(
|
|
1324
|
+
expiresAt: new Date(Date.now() + expiresInMs).toISOString()
|
|
1233
1325
|
});
|
|
1234
1326
|
} catch (error) {
|
|
1235
1327
|
await this.stamper.rollbackRotation();
|
|
@@ -1252,7 +1344,10 @@ var EmbeddedProvider = class {
|
|
|
1252
1344
|
this.client = new import_client.PhantomClient(
|
|
1253
1345
|
{
|
|
1254
1346
|
apiBaseUrl: this.config.apiBaseUrl,
|
|
1255
|
-
organizationId: session.organizationId
|
|
1347
|
+
organizationId: session.organizationId,
|
|
1348
|
+
headers: {
|
|
1349
|
+
...this.platform.analyticsHeaders || {}
|
|
1350
|
+
}
|
|
1256
1351
|
},
|
|
1257
1352
|
this.stamper
|
|
1258
1353
|
);
|