@phantom/browser-sdk 1.0.5 → 1.0.6
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.js +102 -36
- package/dist/index.mjs +85 -19
- package/package.json +11 -11
package/dist/index.js
CHANGED
|
@@ -34,8 +34,8 @@ __export(src_exports, {
|
|
|
34
34
|
BrowserSDK: () => BrowserSDK,
|
|
35
35
|
DebugCategory: () => DebugCategory,
|
|
36
36
|
DebugLevel: () => DebugLevel,
|
|
37
|
-
NetworkId: () =>
|
|
38
|
-
PHANTOM_ICON: () =>
|
|
37
|
+
NetworkId: () => import_constants8.NetworkId,
|
|
38
|
+
PHANTOM_ICON: () => import_constants9.PHANTOM_ICON,
|
|
39
39
|
debug: () => debug,
|
|
40
40
|
detectBrowser: () => detectBrowser,
|
|
41
41
|
getBrowserDisplayName: () => getBrowserDisplayName,
|
|
@@ -2764,7 +2764,7 @@ var BrowserAuthProvider = class {
|
|
|
2764
2764
|
// OAuth session management - defaults to allow refresh unless explicitly clearing after logout
|
|
2765
2765
|
clear_previous_session: (phantomOptions.clearPreviousSession ?? false).toString(),
|
|
2766
2766
|
allow_refresh: (phantomOptions.allowRefresh ?? true).toString(),
|
|
2767
|
-
sdk_version: "1.0.
|
|
2767
|
+
sdk_version: "1.0.6",
|
|
2768
2768
|
sdk_type: "browser",
|
|
2769
2769
|
platform: detectBrowser().name,
|
|
2770
2770
|
algorithm: phantomOptions.algorithm || import_constants3.DEFAULT_AUTHENTICATOR_ALGORITHM
|
|
@@ -2965,14 +2965,14 @@ var Auth2AuthProvider = class {
|
|
|
2965
2965
|
const description = this.urlParamsAccessor.getParam("error_description");
|
|
2966
2966
|
throw new Error(`Auth2 callback error: ${description ?? error}`);
|
|
2967
2967
|
}
|
|
2968
|
-
const { idToken, bearerToken, authUserId, expiresInMs } = await (0, import_auth2.exchangeAuthCode)({
|
|
2968
|
+
const { idToken, bearerToken, authUserId, expiresInMs, refreshToken } = await (0, import_auth2.exchangeAuthCode)({
|
|
2969
2969
|
authApiBaseUrl: this.auth2ProviderOptions.authApiBaseUrl,
|
|
2970
2970
|
clientId: this.auth2ProviderOptions.clientId,
|
|
2971
2971
|
redirectUri: this.auth2ProviderOptions.redirectUri,
|
|
2972
2972
|
code,
|
|
2973
2973
|
codeVerifier
|
|
2974
2974
|
});
|
|
2975
|
-
await this.stamper.
|
|
2975
|
+
await this.stamper.setTokens({ idToken, bearerToken, refreshToken, expiresInMs });
|
|
2976
2976
|
await this.storage.saveSession({
|
|
2977
2977
|
...session,
|
|
2978
2978
|
status: "completed",
|
|
@@ -2999,19 +2999,27 @@ var Auth2AuthProvider = class {
|
|
|
2999
2999
|
var import_bs582 = __toESM(require("bs58"));
|
|
3000
3000
|
var import_base64url = require("@phantom/base64url");
|
|
3001
3001
|
var import_sdk_types = require("@phantom/sdk-types");
|
|
3002
|
+
var import_auth22 = require("@phantom/auth2");
|
|
3003
|
+
var import_constants4 = require("@phantom/constants");
|
|
3002
3004
|
var STORE_NAME = "crypto-keys";
|
|
3003
3005
|
var ACTIVE_KEY = "auth2-p256-signing-key";
|
|
3004
3006
|
var Auth2Stamper = class {
|
|
3005
3007
|
/**
|
|
3006
3008
|
* @param dbName - IndexedDB database name (use a unique name per app to
|
|
3007
3009
|
* avoid key collisions with other stampers, e.g. `phantom-auth2-<appId>`).
|
|
3010
|
+
* @param refreshConfig - When provided, the stamper will automatically refresh
|
|
3011
|
+
* the id_token using the refresh_token before it expires.
|
|
3008
3012
|
*/
|
|
3009
|
-
constructor(dbName) {
|
|
3013
|
+
constructor(dbName, refreshConfig) {
|
|
3010
3014
|
this.dbName = dbName;
|
|
3015
|
+
this.refreshConfig = refreshConfig;
|
|
3011
3016
|
this.db = null;
|
|
3012
3017
|
this._keyPair = null;
|
|
3013
3018
|
this._keyInfo = null;
|
|
3014
3019
|
this._idToken = null;
|
|
3020
|
+
this._bearerToken = null;
|
|
3021
|
+
this._refreshToken = null;
|
|
3022
|
+
this._tokenExpiresAt = null;
|
|
3015
3023
|
this.algorithm = import_sdk_types.Algorithm.secp256r1;
|
|
3016
3024
|
this.type = "OIDC";
|
|
3017
3025
|
}
|
|
@@ -3024,6 +3032,15 @@ var Auth2Stamper = class {
|
|
|
3024
3032
|
if (stored.idToken) {
|
|
3025
3033
|
this._idToken = stored.idToken;
|
|
3026
3034
|
}
|
|
3035
|
+
if (stored.bearerToken) {
|
|
3036
|
+
this._bearerToken = stored.bearerToken;
|
|
3037
|
+
}
|
|
3038
|
+
if (stored.refreshToken) {
|
|
3039
|
+
this._refreshToken = stored.refreshToken;
|
|
3040
|
+
}
|
|
3041
|
+
if (stored.tokenExpiresAt) {
|
|
3042
|
+
this._tokenExpiresAt = stored.tokenExpiresAt;
|
|
3043
|
+
}
|
|
3027
3044
|
return this._keyInfo;
|
|
3028
3045
|
}
|
|
3029
3046
|
return this.generateAndStore();
|
|
@@ -3035,19 +3052,61 @@ var Auth2Stamper = class {
|
|
|
3035
3052
|
return this._keyPair;
|
|
3036
3053
|
}
|
|
3037
3054
|
/**
|
|
3038
|
-
*
|
|
3055
|
+
* Returns the current token state (refreshing proactively if near expiry),
|
|
3056
|
+
* or null if no token has been set yet.
|
|
3057
|
+
*/
|
|
3058
|
+
async getTokens() {
|
|
3059
|
+
if (this.refreshConfig && this._refreshToken && this._tokenExpiresAt !== null && Date.now() >= this._tokenExpiresAt - import_constants4.TOKEN_REFRESH_BUFFER_MS) {
|
|
3060
|
+
const refreshed = await (0, import_auth22.refreshToken)({
|
|
3061
|
+
authApiBaseUrl: this.refreshConfig.authApiBaseUrl,
|
|
3062
|
+
clientId: this.refreshConfig.clientId,
|
|
3063
|
+
redirectUri: this.refreshConfig.redirectUri,
|
|
3064
|
+
refreshToken: this._refreshToken
|
|
3065
|
+
});
|
|
3066
|
+
await this.setTokens(refreshed);
|
|
3067
|
+
}
|
|
3068
|
+
if (!this._idToken || !this._bearerToken) {
|
|
3069
|
+
return null;
|
|
3070
|
+
}
|
|
3071
|
+
return {
|
|
3072
|
+
idToken: this._idToken,
|
|
3073
|
+
bearerToken: this._bearerToken,
|
|
3074
|
+
refreshToken: this._refreshToken ?? void 0
|
|
3075
|
+
};
|
|
3076
|
+
}
|
|
3077
|
+
/**
|
|
3078
|
+
* Arms the stamper with the OIDC token data for subsequent KMS stamp() calls.
|
|
3079
|
+
*
|
|
3080
|
+
* Persists the tokens to IndexedDB alongside the key pair so that
|
|
3081
|
+
* auto-connect can restore them on the next page load without a new login.
|
|
3039
3082
|
*
|
|
3040
|
-
*
|
|
3041
|
-
*
|
|
3083
|
+
* @param refreshToken - When provided alongside a `refreshConfig`, enables
|
|
3084
|
+
* silent token refresh before the token expires.
|
|
3085
|
+
* @param expiresInMs - Token lifetime in milliseconds (from `expires_in * 1000`).
|
|
3086
|
+
* Used to compute the absolute expiry time for proactive refresh.
|
|
3042
3087
|
*/
|
|
3043
|
-
async
|
|
3088
|
+
async setTokens({
|
|
3089
|
+
idToken,
|
|
3090
|
+
bearerToken,
|
|
3091
|
+
refreshToken,
|
|
3092
|
+
expiresInMs
|
|
3093
|
+
}) {
|
|
3044
3094
|
if (!this.db) {
|
|
3045
3095
|
await this.openDB();
|
|
3046
3096
|
}
|
|
3047
3097
|
this._idToken = idToken;
|
|
3098
|
+
this._bearerToken = bearerToken;
|
|
3099
|
+
this._refreshToken = refreshToken ?? null;
|
|
3100
|
+
this._tokenExpiresAt = expiresInMs != null ? Date.now() + expiresInMs : null;
|
|
3048
3101
|
const existing = await this.loadRecord();
|
|
3049
3102
|
if (existing) {
|
|
3050
|
-
await this.storeRecord({
|
|
3103
|
+
await this.storeRecord({
|
|
3104
|
+
...existing,
|
|
3105
|
+
idToken,
|
|
3106
|
+
bearerToken,
|
|
3107
|
+
refreshToken,
|
|
3108
|
+
tokenExpiresAt: this._tokenExpiresAt ?? void 0
|
|
3109
|
+
});
|
|
3051
3110
|
}
|
|
3052
3111
|
}
|
|
3053
3112
|
async stamp(params) {
|
|
@@ -3080,6 +3139,9 @@ var Auth2Stamper = class {
|
|
|
3080
3139
|
this._keyPair = null;
|
|
3081
3140
|
this._keyInfo = null;
|
|
3082
3141
|
this._idToken = null;
|
|
3142
|
+
this._bearerToken = null;
|
|
3143
|
+
this._refreshToken = null;
|
|
3144
|
+
this._tokenExpiresAt = null;
|
|
3083
3145
|
}
|
|
3084
3146
|
// Auth2 doesn't use key rotation; provide minimal no-op implementations.
|
|
3085
3147
|
async rotateKeyPair() {
|
|
@@ -3276,28 +3338,32 @@ var BrowserPhantomAppProvider = class {
|
|
|
3276
3338
|
|
|
3277
3339
|
// src/providers/embedded/adapters/logger.ts
|
|
3278
3340
|
var BrowserLogger = class {
|
|
3279
|
-
info(
|
|
3280
|
-
debug.info(
|
|
3341
|
+
info(message, ...args) {
|
|
3342
|
+
debug.info(message, args.length > 0 ? String(args[0]) : "", args[1]);
|
|
3281
3343
|
}
|
|
3282
|
-
warn(
|
|
3283
|
-
debug.warn(
|
|
3344
|
+
warn(message, ...args) {
|
|
3345
|
+
debug.warn(message, args.length > 0 ? String(args[0]) : "", args[1]);
|
|
3284
3346
|
}
|
|
3285
|
-
error(
|
|
3286
|
-
debug.error(
|
|
3347
|
+
error(message, ...args) {
|
|
3348
|
+
debug.error(message, args.length > 0 ? String(args[0]) : "", args[1]);
|
|
3287
3349
|
}
|
|
3288
|
-
|
|
3289
|
-
debug.log(
|
|
3350
|
+
debug(message, ...args) {
|
|
3351
|
+
debug.log(message, args.length > 0 ? String(args[0]) : "", args[1]);
|
|
3290
3352
|
}
|
|
3291
3353
|
};
|
|
3292
3354
|
|
|
3293
3355
|
// src/providers/embedded/index.ts
|
|
3294
|
-
var
|
|
3356
|
+
var import_constants5 = require("@phantom/constants");
|
|
3295
3357
|
var EmbeddedProvider = class extends import_embedded_provider_core.EmbeddedProvider {
|
|
3296
3358
|
constructor(config) {
|
|
3297
3359
|
debug.log(DebugCategory.EMBEDDED_PROVIDER, "Initializing Browser EmbeddedProvider", { config });
|
|
3298
3360
|
const urlParamsAccessor = new BrowserURLParamsAccessor();
|
|
3299
3361
|
const storage = new BrowserStorage();
|
|
3300
|
-
const stamper = config.unstable__auth2Options ? new Auth2Stamper(`phantom-auth2-${config.appId}
|
|
3362
|
+
const stamper = config.unstable__auth2Options ? new Auth2Stamper(`phantom-auth2-${config.appId}`, {
|
|
3363
|
+
authApiBaseUrl: config.unstable__auth2Options.authApiBaseUrl,
|
|
3364
|
+
clientId: config.unstable__auth2Options.clientId,
|
|
3365
|
+
redirectUri: config.authOptions?.redirectUrl ?? ""
|
|
3366
|
+
}) : new import_indexed_db_stamper.IndexedDbStamper({
|
|
3301
3367
|
dbName: `phantom-embedded-sdk-${config.appId}`,
|
|
3302
3368
|
storeName: "crypto-keys",
|
|
3303
3369
|
keyName: "signing-key"
|
|
@@ -3328,13 +3394,13 @@ var EmbeddedProvider = class extends import_embedded_provider_core.EmbeddedProvi
|
|
|
3328
3394
|
name: platformName,
|
|
3329
3395
|
// Use detected browser name and version for identification
|
|
3330
3396
|
analyticsHeaders: {
|
|
3331
|
-
[
|
|
3332
|
-
[
|
|
3333
|
-
[
|
|
3334
|
-
[
|
|
3335
|
-
[
|
|
3336
|
-
[
|
|
3337
|
-
[
|
|
3397
|
+
[import_constants5.ANALYTICS_HEADERS.SDK_TYPE]: "browser",
|
|
3398
|
+
[import_constants5.ANALYTICS_HEADERS.PLATFORM]: "ext-sdk",
|
|
3399
|
+
[import_constants5.ANALYTICS_HEADERS.PLATFORM_VERSION]: version,
|
|
3400
|
+
[import_constants5.ANALYTICS_HEADERS.CLIENT]: browserName,
|
|
3401
|
+
[import_constants5.ANALYTICS_HEADERS.APP_ID]: config.appId,
|
|
3402
|
+
[import_constants5.ANALYTICS_HEADERS.WALLET_TYPE]: config.embeddedWalletType,
|
|
3403
|
+
[import_constants5.ANALYTICS_HEADERS.SDK_VERSION]: "1.0.6"
|
|
3338
3404
|
// Replaced at build time
|
|
3339
3405
|
}
|
|
3340
3406
|
};
|
|
@@ -3351,7 +3417,7 @@ var EmbeddedProvider = class extends import_embedded_provider_core.EmbeddedProvi
|
|
|
3351
3417
|
|
|
3352
3418
|
// src/ProviderManager.ts
|
|
3353
3419
|
var import_embedded_provider_core2 = require("@phantom/embedded-provider-core");
|
|
3354
|
-
var
|
|
3420
|
+
var import_constants6 = require("@phantom/constants");
|
|
3355
3421
|
|
|
3356
3422
|
// src/utils/auth-callback.ts
|
|
3357
3423
|
function isAuthFailureCallback(searchParams) {
|
|
@@ -3742,8 +3808,8 @@ var ProviderManager = class {
|
|
|
3742
3808
|
if (!this.config.appId) {
|
|
3743
3809
|
throw new Error("appId is required for embedded provider");
|
|
3744
3810
|
}
|
|
3745
|
-
const apiBaseUrl = this.config.apiBaseUrl ||
|
|
3746
|
-
const authUrl = this.config.authOptions?.authUrl ||
|
|
3811
|
+
const apiBaseUrl = this.config.apiBaseUrl || import_constants6.DEFAULT_WALLET_API_URL;
|
|
3812
|
+
const authUrl = this.config.authOptions?.authUrl || import_constants6.DEFAULT_AUTH_URL;
|
|
3747
3813
|
provider = new EmbeddedProvider({
|
|
3748
3814
|
apiBaseUrl,
|
|
3749
3815
|
appId: this.config.appId,
|
|
@@ -3753,7 +3819,7 @@ var ProviderManager = class {
|
|
|
3753
3819
|
redirectUrl: this.config.authOptions?.redirectUrl || this.getValidatedCurrentUrl()
|
|
3754
3820
|
},
|
|
3755
3821
|
unstable__auth2Options: this.config.unstable__auth2Options,
|
|
3756
|
-
embeddedWalletType: embeddedWalletType ||
|
|
3822
|
+
embeddedWalletType: embeddedWalletType || import_constants6.DEFAULT_EMBEDDED_WALLET_TYPE,
|
|
3757
3823
|
addressTypes: this.config.addressTypes || [import_client.AddressType.solana]
|
|
3758
3824
|
});
|
|
3759
3825
|
} else {
|
|
@@ -3789,7 +3855,7 @@ var ProviderManager = class {
|
|
|
3789
3855
|
|
|
3790
3856
|
// src/BrowserSDK.ts
|
|
3791
3857
|
var import_embedded_provider_core3 = require("@phantom/embedded-provider-core");
|
|
3792
|
-
var
|
|
3858
|
+
var import_constants7 = require("@phantom/constants");
|
|
3793
3859
|
var BROWSER_SDK_PROVIDER_TYPES = [
|
|
3794
3860
|
...import_embedded_provider_core3.EMBEDDED_PROVIDER_AUTH_TYPES,
|
|
3795
3861
|
"injected",
|
|
@@ -3825,7 +3891,7 @@ var BrowserSDK = class {
|
|
|
3825
3891
|
});
|
|
3826
3892
|
throw new Error("appId is required when using embedded providers (google, apple, phantom, etc.)");
|
|
3827
3893
|
}
|
|
3828
|
-
const embeddedWalletType = config.embeddedWalletType ||
|
|
3894
|
+
const embeddedWalletType = config.embeddedWalletType || import_constants7.DEFAULT_EMBEDDED_WALLET_TYPE;
|
|
3829
3895
|
if (!["app-wallet", "user-wallet"].includes(embeddedWalletType)) {
|
|
3830
3896
|
debug.error(DebugCategory.BROWSER_SDK, "Invalid embeddedWalletType", {
|
|
3831
3897
|
embeddedWalletType: config.embeddedWalletType
|
|
@@ -4100,6 +4166,6 @@ var BrowserSDK = class {
|
|
|
4100
4166
|
};
|
|
4101
4167
|
|
|
4102
4168
|
// src/index.ts
|
|
4103
|
-
var import_constants7 = require("@phantom/constants");
|
|
4104
|
-
var import_client5 = require("@phantom/client");
|
|
4105
4169
|
var import_constants8 = require("@phantom/constants");
|
|
4170
|
+
var import_client5 = require("@phantom/client");
|
|
4171
|
+
var import_constants9 = require("@phantom/constants");
|
package/dist/index.mjs
CHANGED
|
@@ -2714,7 +2714,7 @@ var BrowserAuthProvider = class {
|
|
|
2714
2714
|
// OAuth session management - defaults to allow refresh unless explicitly clearing after logout
|
|
2715
2715
|
clear_previous_session: (phantomOptions.clearPreviousSession ?? false).toString(),
|
|
2716
2716
|
allow_refresh: (phantomOptions.allowRefresh ?? true).toString(),
|
|
2717
|
-
sdk_version: "1.0.
|
|
2717
|
+
sdk_version: "1.0.6",
|
|
2718
2718
|
sdk_type: "browser",
|
|
2719
2719
|
platform: detectBrowser().name,
|
|
2720
2720
|
algorithm: phantomOptions.algorithm || DEFAULT_AUTHENTICATOR_ALGORITHM
|
|
@@ -2920,14 +2920,14 @@ var Auth2AuthProvider = class {
|
|
|
2920
2920
|
const description = this.urlParamsAccessor.getParam("error_description");
|
|
2921
2921
|
throw new Error(`Auth2 callback error: ${description ?? error}`);
|
|
2922
2922
|
}
|
|
2923
|
-
const { idToken, bearerToken, authUserId, expiresInMs } = await exchangeAuthCode({
|
|
2923
|
+
const { idToken, bearerToken, authUserId, expiresInMs, refreshToken } = await exchangeAuthCode({
|
|
2924
2924
|
authApiBaseUrl: this.auth2ProviderOptions.authApiBaseUrl,
|
|
2925
2925
|
clientId: this.auth2ProviderOptions.clientId,
|
|
2926
2926
|
redirectUri: this.auth2ProviderOptions.redirectUri,
|
|
2927
2927
|
code,
|
|
2928
2928
|
codeVerifier
|
|
2929
2929
|
});
|
|
2930
|
-
await this.stamper.
|
|
2930
|
+
await this.stamper.setTokens({ idToken, bearerToken, refreshToken, expiresInMs });
|
|
2931
2931
|
await this.storage.saveSession({
|
|
2932
2932
|
...session,
|
|
2933
2933
|
status: "completed",
|
|
@@ -2954,19 +2954,27 @@ var Auth2AuthProvider = class {
|
|
|
2954
2954
|
import bs582 from "bs58";
|
|
2955
2955
|
import { base64urlEncode } from "@phantom/base64url";
|
|
2956
2956
|
import { Algorithm } from "@phantom/sdk-types";
|
|
2957
|
+
import { refreshToken as refreshTokenRequest } from "@phantom/auth2";
|
|
2958
|
+
import { TOKEN_REFRESH_BUFFER_MS } from "@phantom/constants";
|
|
2957
2959
|
var STORE_NAME = "crypto-keys";
|
|
2958
2960
|
var ACTIVE_KEY = "auth2-p256-signing-key";
|
|
2959
2961
|
var Auth2Stamper = class {
|
|
2960
2962
|
/**
|
|
2961
2963
|
* @param dbName - IndexedDB database name (use a unique name per app to
|
|
2962
2964
|
* avoid key collisions with other stampers, e.g. `phantom-auth2-<appId>`).
|
|
2965
|
+
* @param refreshConfig - When provided, the stamper will automatically refresh
|
|
2966
|
+
* the id_token using the refresh_token before it expires.
|
|
2963
2967
|
*/
|
|
2964
|
-
constructor(dbName) {
|
|
2968
|
+
constructor(dbName, refreshConfig) {
|
|
2965
2969
|
this.dbName = dbName;
|
|
2970
|
+
this.refreshConfig = refreshConfig;
|
|
2966
2971
|
this.db = null;
|
|
2967
2972
|
this._keyPair = null;
|
|
2968
2973
|
this._keyInfo = null;
|
|
2969
2974
|
this._idToken = null;
|
|
2975
|
+
this._bearerToken = null;
|
|
2976
|
+
this._refreshToken = null;
|
|
2977
|
+
this._tokenExpiresAt = null;
|
|
2970
2978
|
this.algorithm = Algorithm.secp256r1;
|
|
2971
2979
|
this.type = "OIDC";
|
|
2972
2980
|
}
|
|
@@ -2979,6 +2987,15 @@ var Auth2Stamper = class {
|
|
|
2979
2987
|
if (stored.idToken) {
|
|
2980
2988
|
this._idToken = stored.idToken;
|
|
2981
2989
|
}
|
|
2990
|
+
if (stored.bearerToken) {
|
|
2991
|
+
this._bearerToken = stored.bearerToken;
|
|
2992
|
+
}
|
|
2993
|
+
if (stored.refreshToken) {
|
|
2994
|
+
this._refreshToken = stored.refreshToken;
|
|
2995
|
+
}
|
|
2996
|
+
if (stored.tokenExpiresAt) {
|
|
2997
|
+
this._tokenExpiresAt = stored.tokenExpiresAt;
|
|
2998
|
+
}
|
|
2982
2999
|
return this._keyInfo;
|
|
2983
3000
|
}
|
|
2984
3001
|
return this.generateAndStore();
|
|
@@ -2990,19 +3007,61 @@ var Auth2Stamper = class {
|
|
|
2990
3007
|
return this._keyPair;
|
|
2991
3008
|
}
|
|
2992
3009
|
/**
|
|
2993
|
-
*
|
|
3010
|
+
* Returns the current token state (refreshing proactively if near expiry),
|
|
3011
|
+
* or null if no token has been set yet.
|
|
3012
|
+
*/
|
|
3013
|
+
async getTokens() {
|
|
3014
|
+
if (this.refreshConfig && this._refreshToken && this._tokenExpiresAt !== null && Date.now() >= this._tokenExpiresAt - TOKEN_REFRESH_BUFFER_MS) {
|
|
3015
|
+
const refreshed = await refreshTokenRequest({
|
|
3016
|
+
authApiBaseUrl: this.refreshConfig.authApiBaseUrl,
|
|
3017
|
+
clientId: this.refreshConfig.clientId,
|
|
3018
|
+
redirectUri: this.refreshConfig.redirectUri,
|
|
3019
|
+
refreshToken: this._refreshToken
|
|
3020
|
+
});
|
|
3021
|
+
await this.setTokens(refreshed);
|
|
3022
|
+
}
|
|
3023
|
+
if (!this._idToken || !this._bearerToken) {
|
|
3024
|
+
return null;
|
|
3025
|
+
}
|
|
3026
|
+
return {
|
|
3027
|
+
idToken: this._idToken,
|
|
3028
|
+
bearerToken: this._bearerToken,
|
|
3029
|
+
refreshToken: this._refreshToken ?? void 0
|
|
3030
|
+
};
|
|
3031
|
+
}
|
|
3032
|
+
/**
|
|
3033
|
+
* Arms the stamper with the OIDC token data for subsequent KMS stamp() calls.
|
|
2994
3034
|
*
|
|
2995
|
-
* Persists the
|
|
2996
|
-
* auto-connect can restore
|
|
3035
|
+
* Persists the tokens to IndexedDB alongside the key pair so that
|
|
3036
|
+
* auto-connect can restore them on the next page load without a new login.
|
|
3037
|
+
*
|
|
3038
|
+
* @param refreshToken - When provided alongside a `refreshConfig`, enables
|
|
3039
|
+
* silent token refresh before the token expires.
|
|
3040
|
+
* @param expiresInMs - Token lifetime in milliseconds (from `expires_in * 1000`).
|
|
3041
|
+
* Used to compute the absolute expiry time for proactive refresh.
|
|
2997
3042
|
*/
|
|
2998
|
-
async
|
|
3043
|
+
async setTokens({
|
|
3044
|
+
idToken,
|
|
3045
|
+
bearerToken,
|
|
3046
|
+
refreshToken,
|
|
3047
|
+
expiresInMs
|
|
3048
|
+
}) {
|
|
2999
3049
|
if (!this.db) {
|
|
3000
3050
|
await this.openDB();
|
|
3001
3051
|
}
|
|
3002
3052
|
this._idToken = idToken;
|
|
3053
|
+
this._bearerToken = bearerToken;
|
|
3054
|
+
this._refreshToken = refreshToken ?? null;
|
|
3055
|
+
this._tokenExpiresAt = expiresInMs != null ? Date.now() + expiresInMs : null;
|
|
3003
3056
|
const existing = await this.loadRecord();
|
|
3004
3057
|
if (existing) {
|
|
3005
|
-
await this.storeRecord({
|
|
3058
|
+
await this.storeRecord({
|
|
3059
|
+
...existing,
|
|
3060
|
+
idToken,
|
|
3061
|
+
bearerToken,
|
|
3062
|
+
refreshToken,
|
|
3063
|
+
tokenExpiresAt: this._tokenExpiresAt ?? void 0
|
|
3064
|
+
});
|
|
3006
3065
|
}
|
|
3007
3066
|
}
|
|
3008
3067
|
async stamp(params) {
|
|
@@ -3035,6 +3094,9 @@ var Auth2Stamper = class {
|
|
|
3035
3094
|
this._keyPair = null;
|
|
3036
3095
|
this._keyInfo = null;
|
|
3037
3096
|
this._idToken = null;
|
|
3097
|
+
this._bearerToken = null;
|
|
3098
|
+
this._refreshToken = null;
|
|
3099
|
+
this._tokenExpiresAt = null;
|
|
3038
3100
|
}
|
|
3039
3101
|
// Auth2 doesn't use key rotation; provide minimal no-op implementations.
|
|
3040
3102
|
async rotateKeyPair() {
|
|
@@ -3231,17 +3293,17 @@ var BrowserPhantomAppProvider = class {
|
|
|
3231
3293
|
|
|
3232
3294
|
// src/providers/embedded/adapters/logger.ts
|
|
3233
3295
|
var BrowserLogger = class {
|
|
3234
|
-
info(
|
|
3235
|
-
debug.info(
|
|
3296
|
+
info(message, ...args) {
|
|
3297
|
+
debug.info(message, args.length > 0 ? String(args[0]) : "", args[1]);
|
|
3236
3298
|
}
|
|
3237
|
-
warn(
|
|
3238
|
-
debug.warn(
|
|
3299
|
+
warn(message, ...args) {
|
|
3300
|
+
debug.warn(message, args.length > 0 ? String(args[0]) : "", args[1]);
|
|
3239
3301
|
}
|
|
3240
|
-
error(
|
|
3241
|
-
debug.error(
|
|
3302
|
+
error(message, ...args) {
|
|
3303
|
+
debug.error(message, args.length > 0 ? String(args[0]) : "", args[1]);
|
|
3242
3304
|
}
|
|
3243
|
-
|
|
3244
|
-
debug.log(
|
|
3305
|
+
debug(message, ...args) {
|
|
3306
|
+
debug.log(message, args.length > 0 ? String(args[0]) : "", args[1]);
|
|
3245
3307
|
}
|
|
3246
3308
|
};
|
|
3247
3309
|
|
|
@@ -3252,7 +3314,11 @@ var EmbeddedProvider = class extends CoreEmbeddedProvider {
|
|
|
3252
3314
|
debug.log(DebugCategory.EMBEDDED_PROVIDER, "Initializing Browser EmbeddedProvider", { config });
|
|
3253
3315
|
const urlParamsAccessor = new BrowserURLParamsAccessor();
|
|
3254
3316
|
const storage = new BrowserStorage();
|
|
3255
|
-
const stamper = config.unstable__auth2Options ? new Auth2Stamper(`phantom-auth2-${config.appId}
|
|
3317
|
+
const stamper = config.unstable__auth2Options ? new Auth2Stamper(`phantom-auth2-${config.appId}`, {
|
|
3318
|
+
authApiBaseUrl: config.unstable__auth2Options.authApiBaseUrl,
|
|
3319
|
+
clientId: config.unstable__auth2Options.clientId,
|
|
3320
|
+
redirectUri: config.authOptions?.redirectUrl ?? ""
|
|
3321
|
+
}) : new IndexedDbStamper({
|
|
3256
3322
|
dbName: `phantom-embedded-sdk-${config.appId}`,
|
|
3257
3323
|
storeName: "crypto-keys",
|
|
3258
3324
|
keyName: "signing-key"
|
|
@@ -3289,7 +3355,7 @@ var EmbeddedProvider = class extends CoreEmbeddedProvider {
|
|
|
3289
3355
|
[ANALYTICS_HEADERS.CLIENT]: browserName,
|
|
3290
3356
|
[ANALYTICS_HEADERS.APP_ID]: config.appId,
|
|
3291
3357
|
[ANALYTICS_HEADERS.WALLET_TYPE]: config.embeddedWalletType,
|
|
3292
|
-
[ANALYTICS_HEADERS.SDK_VERSION]: "1.0.
|
|
3358
|
+
[ANALYTICS_HEADERS.SDK_VERSION]: "1.0.6"
|
|
3293
3359
|
// Replaced at build time
|
|
3294
3360
|
}
|
|
3295
3361
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@phantom/browser-sdk",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.6",
|
|
4
4
|
"description": "Browser SDK for Phantom Wallet",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -33,16 +33,16 @@
|
|
|
33
33
|
"prettier": "prettier --write \"src/**/*.{ts,tsx}\""
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"@phantom/auth2": "^1.0.
|
|
37
|
-
"@phantom/base64url": "^1.0.
|
|
38
|
-
"@phantom/browser-injected-sdk": "^1.0.
|
|
39
|
-
"@phantom/chain-interfaces": "^1.0.
|
|
40
|
-
"@phantom/client": "^1.0.
|
|
41
|
-
"@phantom/constants": "^1.0.
|
|
42
|
-
"@phantom/embedded-provider-core": "^1.0.
|
|
43
|
-
"@phantom/indexed-db-stamper": "^1.0.
|
|
44
|
-
"@phantom/parsers": "^1.0.
|
|
45
|
-
"@phantom/sdk-types": "^1.0.
|
|
36
|
+
"@phantom/auth2": "^1.0.2",
|
|
37
|
+
"@phantom/base64url": "^1.0.6",
|
|
38
|
+
"@phantom/browser-injected-sdk": "^1.0.6",
|
|
39
|
+
"@phantom/chain-interfaces": "^1.0.6",
|
|
40
|
+
"@phantom/client": "^1.0.6",
|
|
41
|
+
"@phantom/constants": "^1.0.6",
|
|
42
|
+
"@phantom/embedded-provider-core": "^1.0.6",
|
|
43
|
+
"@phantom/indexed-db-stamper": "^1.0.6",
|
|
44
|
+
"@phantom/parsers": "^1.0.6",
|
|
45
|
+
"@phantom/sdk-types": "^1.0.6",
|
|
46
46
|
"axios": "^1.10.0",
|
|
47
47
|
"bs58": "^6.0.0",
|
|
48
48
|
"buffer": "^6.0.3",
|