@phantom/embedded-provider-core 1.0.0-beta.2 → 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 +8 -5
- package/dist/index.d.ts +8 -5
- package/dist/index.js +38 -23
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +38 -23
- package/dist/index.mjs.map +1 -1
- package/package.json +8 -8
package/dist/index.mjs
CHANGED
|
@@ -195,6 +195,10 @@ var EmbeddedSolanaChain = class {
|
|
|
195
195
|
const results = await Promise.all(transactions.map((tx) => this.signTransaction(tx)));
|
|
196
196
|
return results;
|
|
197
197
|
}
|
|
198
|
+
async signAndSendAllTransactions(transactions) {
|
|
199
|
+
const results = await Promise.all(transactions.map((tx) => this.signAndSendTransaction(tx)));
|
|
200
|
+
return { signatures: results.map((result) => result.signature) };
|
|
201
|
+
}
|
|
198
202
|
connect(_options) {
|
|
199
203
|
if (!this.provider.isConnected()) {
|
|
200
204
|
throw new Error("Provider not connected. Call provider connect first.");
|
|
@@ -466,6 +470,9 @@ var EmbeddedProvider = class {
|
|
|
466
470
|
this.eventListeners = /* @__PURE__ */ new Map();
|
|
467
471
|
this.logger = logger;
|
|
468
472
|
this.logger.log("EMBEDDED_PROVIDER", "Initializing EmbeddedProvider", { config });
|
|
473
|
+
if (config.embeddedWalletType === "app-wallet") {
|
|
474
|
+
throw new Error("app-wallet type is not currently supported. Please use 'user-wallet' instead.");
|
|
475
|
+
}
|
|
469
476
|
this.config = config;
|
|
470
477
|
this.platform = platform;
|
|
471
478
|
this.storage = platform.storage;
|
|
@@ -473,7 +480,6 @@ var EmbeddedProvider = class {
|
|
|
473
480
|
this.urlParamsAccessor = platform.urlParamsAccessor;
|
|
474
481
|
this.stamper = platform.stamper;
|
|
475
482
|
this.jwtAuth = new JWTAuth();
|
|
476
|
-
config.solanaProvider;
|
|
477
483
|
this.solana = new EmbeddedSolanaChain(this);
|
|
478
484
|
this.ethereum = new EmbeddedEthereumChain(this);
|
|
479
485
|
this.logger.info("EMBEDDED_PROVIDER", "EmbeddedProvider initialized");
|
|
@@ -740,7 +746,10 @@ var EmbeddedProvider = class {
|
|
|
740
746
|
this.logger.log("EMBEDDED_PROVIDER", "Creating temporary PhantomClient");
|
|
741
747
|
const tempClient = new PhantomClient(
|
|
742
748
|
{
|
|
743
|
-
apiBaseUrl: this.config.apiBaseUrl
|
|
749
|
+
apiBaseUrl: this.config.apiBaseUrl,
|
|
750
|
+
headers: {
|
|
751
|
+
...this.platform.analyticsHeaders || {}
|
|
752
|
+
}
|
|
744
753
|
},
|
|
745
754
|
this.stamper
|
|
746
755
|
);
|
|
@@ -753,7 +762,7 @@ var EmbeddedProvider = class {
|
|
|
753
762
|
platform: platformName
|
|
754
763
|
});
|
|
755
764
|
const base64urlPublicKey = base64urlEncode(bs582.decode(stamperInfo.publicKey));
|
|
756
|
-
const
|
|
765
|
+
const expiresInMs = AUTHENTICATOR_EXPIRATION_TIME_MS;
|
|
757
766
|
const username = `user-${shortPubKey}`;
|
|
758
767
|
const { organizationId } = await tempClient.createOrganization(organizationName, [
|
|
759
768
|
{
|
|
@@ -766,13 +775,13 @@ var EmbeddedProvider = class {
|
|
|
766
775
|
publicKey: base64urlPublicKey,
|
|
767
776
|
algorithm: "Ed25519"
|
|
768
777
|
// Commented for now until KMS supports fully expirable organizations
|
|
769
|
-
//
|
|
778
|
+
// expiresInMs: expiresInMs,
|
|
770
779
|
}
|
|
771
780
|
]
|
|
772
781
|
}
|
|
773
782
|
]);
|
|
774
783
|
this.logger.info("EMBEDDED_PROVIDER", "Organization created", { organizationId });
|
|
775
|
-
return { organizationId, stamperInfo,
|
|
784
|
+
return { organizationId, stamperInfo, expiresInMs, username };
|
|
776
785
|
}
|
|
777
786
|
async connect(authOptions) {
|
|
778
787
|
try {
|
|
@@ -801,8 +810,8 @@ var EmbeddedProvider = class {
|
|
|
801
810
|
}
|
|
802
811
|
this.validateAuthOptions(authOptions);
|
|
803
812
|
this.logger.info("EMBEDDED_PROVIDER", "No existing connection, creating new auth flow");
|
|
804
|
-
const { organizationId, stamperInfo,
|
|
805
|
-
const session = await this.handleAuthFlow(organizationId, stamperInfo, authOptions,
|
|
813
|
+
const { organizationId, stamperInfo, expiresInMs, username } = await this.createOrganizationAndStamper();
|
|
814
|
+
const session = await this.handleAuthFlow(organizationId, stamperInfo, authOptions, expiresInMs, username);
|
|
806
815
|
if (!session) {
|
|
807
816
|
return {
|
|
808
817
|
addresses: [],
|
|
@@ -972,13 +981,13 @@ var EmbeddedProvider = class {
|
|
|
972
981
|
* It handles app-wallet creation directly or routes to JWT/redirect authentication for user-wallets.
|
|
973
982
|
* Returns null for redirect flows since they don't complete synchronously.
|
|
974
983
|
*/
|
|
975
|
-
async handleAuthFlow(organizationId, stamperInfo, authOptions,
|
|
984
|
+
async handleAuthFlow(organizationId, stamperInfo, authOptions, expiresInMs, username) {
|
|
976
985
|
if (this.config.embeddedWalletType === "user-wallet") {
|
|
977
986
|
this.logger.info("EMBEDDED_PROVIDER", "Creating user-wallet, routing authentication", {
|
|
978
987
|
authProvider: authOptions?.provider || "phantom-connect"
|
|
979
988
|
});
|
|
980
989
|
if (authOptions?.provider === "jwt") {
|
|
981
|
-
return await this.handleJWTAuth(organizationId, stamperInfo, authOptions,
|
|
990
|
+
return await this.handleJWTAuth(organizationId, stamperInfo, authOptions, expiresInMs, username);
|
|
982
991
|
} else {
|
|
983
992
|
this.logger.info("EMBEDDED_PROVIDER", "Starting redirect-based authentication flow", {
|
|
984
993
|
organizationId,
|
|
@@ -994,7 +1003,10 @@ var EmbeddedProvider = class {
|
|
|
994
1003
|
const tempClient = new PhantomClient(
|
|
995
1004
|
{
|
|
996
1005
|
apiBaseUrl: this.config.apiBaseUrl,
|
|
997
|
-
organizationId
|
|
1006
|
+
organizationId,
|
|
1007
|
+
headers: {
|
|
1008
|
+
...this.platform.analyticsHeaders || {}
|
|
1009
|
+
}
|
|
998
1010
|
},
|
|
999
1011
|
this.stamper
|
|
1000
1012
|
);
|
|
@@ -1015,7 +1027,7 @@ var EmbeddedProvider = class {
|
|
|
1015
1027
|
createdAt: now,
|
|
1016
1028
|
lastUsed: now,
|
|
1017
1029
|
authenticatorCreatedAt: now,
|
|
1018
|
-
authenticatorExpiresAt:
|
|
1030
|
+
authenticatorExpiresAt: Date.now() + expiresInMs,
|
|
1019
1031
|
lastRenewalAttempt: void 0,
|
|
1020
1032
|
username
|
|
1021
1033
|
};
|
|
@@ -1028,7 +1040,7 @@ var EmbeddedProvider = class {
|
|
|
1028
1040
|
* We use this method to handle JWT-based authentication for user-wallets.
|
|
1029
1041
|
* It authenticates using the provided JWT token and creates a completed session.
|
|
1030
1042
|
*/
|
|
1031
|
-
async handleJWTAuth(organizationId, stamperInfo, authOptions,
|
|
1043
|
+
async handleJWTAuth(organizationId, stamperInfo, authOptions, expiresInMs, username) {
|
|
1032
1044
|
this.logger.info("EMBEDDED_PROVIDER", "Using JWT authentication flow");
|
|
1033
1045
|
if (!authOptions.jwtToken) {
|
|
1034
1046
|
this.logger.error("EMBEDDED_PROVIDER", "JWT token missing for JWT authentication");
|
|
@@ -1058,7 +1070,7 @@ var EmbeddedProvider = class {
|
|
|
1058
1070
|
createdAt: now,
|
|
1059
1071
|
lastUsed: now,
|
|
1060
1072
|
authenticatorCreatedAt: now,
|
|
1061
|
-
authenticatorExpiresAt:
|
|
1073
|
+
authenticatorExpiresAt: Date.now() + expiresInMs,
|
|
1062
1074
|
lastRenewalAttempt: void 0,
|
|
1063
1075
|
username
|
|
1064
1076
|
};
|
|
@@ -1074,8 +1086,8 @@ var EmbeddedProvider = class {
|
|
|
1074
1086
|
async handleRedirectAuth(organizationId, stamperInfo, authOptions, username) {
|
|
1075
1087
|
this.logger.info("EMBEDDED_PROVIDER", "Using Phantom Connect authentication flow (redirect-based)", {
|
|
1076
1088
|
provider: authOptions?.provider,
|
|
1077
|
-
hasRedirectUrl: !!this.config.authOptions
|
|
1078
|
-
authUrl: this.config.authOptions
|
|
1089
|
+
hasRedirectUrl: !!this.config.authOptions.redirectUrl,
|
|
1090
|
+
authUrl: this.config.authOptions.authUrl
|
|
1079
1091
|
});
|
|
1080
1092
|
const now = Date.now();
|
|
1081
1093
|
const sessionId = generateSessionId();
|
|
@@ -1109,16 +1121,16 @@ var EmbeddedProvider = class {
|
|
|
1109
1121
|
parentOrganizationId: this.config.organizationId,
|
|
1110
1122
|
appId: this.config.appId,
|
|
1111
1123
|
provider: authOptions?.provider,
|
|
1112
|
-
authUrl: this.config.authOptions
|
|
1124
|
+
authUrl: this.config.authOptions.authUrl
|
|
1113
1125
|
});
|
|
1114
1126
|
const authResult = await this.authProvider.authenticate({
|
|
1115
1127
|
organizationId,
|
|
1116
1128
|
appId: this.config.appId,
|
|
1117
1129
|
parentOrganizationId: this.config.organizationId,
|
|
1118
1130
|
provider: authOptions?.provider,
|
|
1119
|
-
redirectUrl: this.config.authOptions
|
|
1131
|
+
redirectUrl: this.config.authOptions.redirectUrl,
|
|
1120
1132
|
customAuthData: authOptions?.customAuthData,
|
|
1121
|
-
authUrl: this.config.authOptions
|
|
1133
|
+
authUrl: this.config.authOptions.authUrl,
|
|
1122
1134
|
sessionId
|
|
1123
1135
|
});
|
|
1124
1136
|
if (authResult && "walletId" in authResult) {
|
|
@@ -1214,7 +1226,7 @@ var EmbeddedProvider = class {
|
|
|
1214
1226
|
newPublicKey: newKeyInfo.publicKey
|
|
1215
1227
|
});
|
|
1216
1228
|
const base64urlPublicKey = base64urlEncode(bs582.decode(newKeyInfo.publicKey));
|
|
1217
|
-
const
|
|
1229
|
+
const expiresInMs = AUTHENTICATOR_EXPIRATION_TIME_MS;
|
|
1218
1230
|
let authenticatorResult;
|
|
1219
1231
|
try {
|
|
1220
1232
|
authenticatorResult = await this.client.createAuthenticator({
|
|
@@ -1227,7 +1239,7 @@ var EmbeddedProvider = class {
|
|
|
1227
1239
|
publicKey: base64urlPublicKey,
|
|
1228
1240
|
algorithm: "Ed25519"
|
|
1229
1241
|
// Commented for now until KMS supports fully expiring organizations
|
|
1230
|
-
//
|
|
1242
|
+
// expiresInMs: expiresInMs,
|
|
1231
1243
|
},
|
|
1232
1244
|
replaceExpirable: true
|
|
1233
1245
|
});
|
|
@@ -1247,12 +1259,12 @@ var EmbeddedProvider = class {
|
|
|
1247
1259
|
const now = Date.now();
|
|
1248
1260
|
session.stamperInfo = newKeyInfo;
|
|
1249
1261
|
session.authenticatorCreatedAt = now;
|
|
1250
|
-
session.authenticatorExpiresAt =
|
|
1262
|
+
session.authenticatorExpiresAt = Date.now() + expiresInMs;
|
|
1251
1263
|
session.lastRenewalAttempt = now;
|
|
1252
1264
|
await this.storage.saveSession(session);
|
|
1253
1265
|
this.logger.info("EMBEDDED_PROVIDER", "Authenticator renewal completed successfully", {
|
|
1254
1266
|
newKeyId: newKeyInfo.keyId,
|
|
1255
|
-
expiresAt: new Date(
|
|
1267
|
+
expiresAt: new Date(Date.now() + expiresInMs).toISOString()
|
|
1256
1268
|
});
|
|
1257
1269
|
} catch (error) {
|
|
1258
1270
|
await this.stamper.rollbackRotation();
|
|
@@ -1275,7 +1287,10 @@ var EmbeddedProvider = class {
|
|
|
1275
1287
|
this.client = new PhantomClient(
|
|
1276
1288
|
{
|
|
1277
1289
|
apiBaseUrl: this.config.apiBaseUrl,
|
|
1278
|
-
organizationId: session.organizationId
|
|
1290
|
+
organizationId: session.organizationId,
|
|
1291
|
+
headers: {
|
|
1292
|
+
...this.platform.analyticsHeaders || {}
|
|
1293
|
+
}
|
|
1279
1294
|
},
|
|
1280
1295
|
this.stamper
|
|
1281
1296
|
);
|