@phantom/react-native-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 +99 -33
- package/dist/index.mjs +85 -19
- package/package.json +11 -11
package/dist/index.js
CHANGED
|
@@ -31,7 +31,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
31
31
|
var src_exports = {};
|
|
32
32
|
__export(src_exports, {
|
|
33
33
|
AddressType: () => import_client.AddressType,
|
|
34
|
-
NetworkId: () =>
|
|
34
|
+
NetworkId: () => import_constants5.NetworkId,
|
|
35
35
|
PhantomProvider: () => PhantomProvider,
|
|
36
36
|
darkTheme: () => import_wallet_sdk_ui6.darkTheme,
|
|
37
37
|
lightTheme: () => import_wallet_sdk_ui6.lightTheme,
|
|
@@ -48,7 +48,7 @@ module.exports = __toCommonJS(src_exports);
|
|
|
48
48
|
// src/PhantomProvider.tsx
|
|
49
49
|
var import_react8 = require("react");
|
|
50
50
|
var import_embedded_provider_core = require("@phantom/embedded-provider-core");
|
|
51
|
-
var
|
|
51
|
+
var import_constants4 = require("@phantom/constants");
|
|
52
52
|
var import_wallet_sdk_ui5 = require("@phantom/wallet-sdk-ui");
|
|
53
53
|
|
|
54
54
|
// src/ModalProvider.tsx
|
|
@@ -557,7 +557,7 @@ var ExpoAuthProvider = class {
|
|
|
557
557
|
// OAuth session management - defaults to allow refresh unless explicitly clearing after logout
|
|
558
558
|
clear_previous_session: (phantomOptions.clearPreviousSession ?? false).toString(),
|
|
559
559
|
allow_refresh: (phantomOptions.allowRefresh ?? true).toString(),
|
|
560
|
-
sdk_version: "1.0.
|
|
560
|
+
sdk_version: "1.0.6",
|
|
561
561
|
sdk_type: "react-native",
|
|
562
562
|
platform: import_react_native5.Platform.OS
|
|
563
563
|
});
|
|
@@ -692,14 +692,14 @@ var ExpoAuth2AuthProvider = class {
|
|
|
692
692
|
if (!code) {
|
|
693
693
|
throw new Error("Auth2 callback missing authorization code");
|
|
694
694
|
}
|
|
695
|
-
const { idToken, bearerToken, authUserId, expiresInMs } = await (0, import_auth2.exchangeAuthCode)({
|
|
695
|
+
const { idToken, bearerToken, authUserId, expiresInMs, refreshToken } = await (0, import_auth2.exchangeAuthCode)({
|
|
696
696
|
authApiBaseUrl: this.auth2ProviderOptions.authApiBaseUrl,
|
|
697
697
|
clientId: this.auth2ProviderOptions.clientId,
|
|
698
698
|
redirectUri: this.auth2ProviderOptions.redirectUri,
|
|
699
699
|
code,
|
|
700
700
|
codeVerifier
|
|
701
701
|
});
|
|
702
|
-
await this.stamper.
|
|
702
|
+
await this.stamper.setTokens({ idToken, bearerToken, refreshToken, expiresInMs });
|
|
703
703
|
const { organizationId, walletId } = await this.kms.discoverOrganizationAndWalletId(bearerToken, authUserId);
|
|
704
704
|
return {
|
|
705
705
|
walletId,
|
|
@@ -720,16 +720,24 @@ var import_bs58 = __toESM(require("bs58"));
|
|
|
720
720
|
var import_buffer = require("buffer");
|
|
721
721
|
var import_base64url = require("@phantom/base64url");
|
|
722
722
|
var import_sdk_types = require("@phantom/sdk-types");
|
|
723
|
+
var import_auth22 = require("@phantom/auth2");
|
|
724
|
+
var import_constants2 = require("@phantom/constants");
|
|
723
725
|
var ExpoAuth2Stamper = class {
|
|
724
726
|
/**
|
|
725
727
|
* @param storageKey - expo-secure-store key used to persist the P-256 private key.
|
|
726
728
|
* Use a unique key per app, e.g. `phantom-auth2-<appId>`.
|
|
729
|
+
* @param refreshConfig - When provided, the stamper will automatically refresh
|
|
730
|
+
* the id_token using the refresh_token before it expires.
|
|
727
731
|
*/
|
|
728
|
-
constructor(storageKey) {
|
|
732
|
+
constructor(storageKey, refreshConfig) {
|
|
729
733
|
this.storageKey = storageKey;
|
|
734
|
+
this.refreshConfig = refreshConfig;
|
|
730
735
|
this._keyPair = null;
|
|
731
736
|
this._keyInfo = null;
|
|
732
737
|
this._idToken = null;
|
|
738
|
+
this._bearerToken = null;
|
|
739
|
+
this._refreshToken = null;
|
|
740
|
+
this._tokenExpiresAt = null;
|
|
733
741
|
this.algorithm = import_sdk_types.Algorithm.secp256r1;
|
|
734
742
|
this.type = "OIDC";
|
|
735
743
|
}
|
|
@@ -744,6 +752,15 @@ var ExpoAuth2Stamper = class {
|
|
|
744
752
|
if (stored.idToken) {
|
|
745
753
|
this._idToken = stored.idToken;
|
|
746
754
|
}
|
|
755
|
+
if (stored.bearerToken) {
|
|
756
|
+
this._bearerToken = stored.bearerToken;
|
|
757
|
+
}
|
|
758
|
+
if (stored.refreshToken) {
|
|
759
|
+
this._refreshToken = stored.refreshToken;
|
|
760
|
+
}
|
|
761
|
+
if (stored.tokenExpiresAt) {
|
|
762
|
+
this._tokenExpiresAt = stored.tokenExpiresAt;
|
|
763
|
+
}
|
|
747
764
|
return this._keyInfo;
|
|
748
765
|
}
|
|
749
766
|
return this.generateAndStore();
|
|
@@ -755,16 +772,58 @@ var ExpoAuth2Stamper = class {
|
|
|
755
772
|
return this._keyPair;
|
|
756
773
|
}
|
|
757
774
|
/**
|
|
758
|
-
*
|
|
775
|
+
* Returns the current token state (refreshing proactively if near expiry),
|
|
776
|
+
* or null if no token has been set yet.
|
|
777
|
+
*/
|
|
778
|
+
async getTokens() {
|
|
779
|
+
if (this.refreshConfig && this._refreshToken && this._tokenExpiresAt !== null && Date.now() >= this._tokenExpiresAt - import_constants2.TOKEN_REFRESH_BUFFER_MS) {
|
|
780
|
+
const refreshed = await (0, import_auth22.refreshToken)({
|
|
781
|
+
authApiBaseUrl: this.refreshConfig.authApiBaseUrl,
|
|
782
|
+
clientId: this.refreshConfig.clientId,
|
|
783
|
+
redirectUri: this.refreshConfig.redirectUri,
|
|
784
|
+
refreshToken: this._refreshToken
|
|
785
|
+
});
|
|
786
|
+
await this.setTokens(refreshed);
|
|
787
|
+
}
|
|
788
|
+
if (!this._idToken || !this._bearerToken) {
|
|
789
|
+
return null;
|
|
790
|
+
}
|
|
791
|
+
return {
|
|
792
|
+
idToken: this._idToken,
|
|
793
|
+
bearerToken: this._bearerToken,
|
|
794
|
+
refreshToken: this._refreshToken ?? void 0
|
|
795
|
+
};
|
|
796
|
+
}
|
|
797
|
+
/**
|
|
798
|
+
* Arms the stamper with the OIDC token data for subsequent KMS stamp() calls.
|
|
759
799
|
*
|
|
760
|
-
* Persists the
|
|
761
|
-
* auto-connect can restore
|
|
800
|
+
* Persists the tokens to SecureStore alongside the key pair so that
|
|
801
|
+
* auto-connect can restore them on the next app launch without a new login.
|
|
802
|
+
*
|
|
803
|
+
* @param refreshToken - When provided alongside a `refreshConfig`, enables
|
|
804
|
+
* silent token refresh before the token expires.
|
|
805
|
+
* @param expiresInMs - Token lifetime in milliseconds (from `expires_in * 1000`).
|
|
806
|
+
* Used to compute the absolute expiry time for proactive refresh.
|
|
762
807
|
*/
|
|
763
|
-
async
|
|
808
|
+
async setTokens({
|
|
809
|
+
idToken,
|
|
810
|
+
bearerToken,
|
|
811
|
+
refreshToken,
|
|
812
|
+
expiresInMs
|
|
813
|
+
}) {
|
|
764
814
|
this._idToken = idToken;
|
|
815
|
+
this._bearerToken = bearerToken;
|
|
816
|
+
this._refreshToken = refreshToken ?? null;
|
|
817
|
+
this._tokenExpiresAt = expiresInMs != null ? Date.now() + expiresInMs : null;
|
|
765
818
|
const existing = await this.loadRecord();
|
|
766
819
|
if (existing) {
|
|
767
|
-
await this.storeRecord({
|
|
820
|
+
await this.storeRecord({
|
|
821
|
+
...existing,
|
|
822
|
+
idToken,
|
|
823
|
+
bearerToken,
|
|
824
|
+
refreshToken,
|
|
825
|
+
tokenExpiresAt: this._tokenExpiresAt ?? void 0
|
|
826
|
+
});
|
|
768
827
|
}
|
|
769
828
|
}
|
|
770
829
|
async stamp(params) {
|
|
@@ -797,6 +856,9 @@ var ExpoAuth2Stamper = class {
|
|
|
797
856
|
this._keyPair = null;
|
|
798
857
|
this._keyInfo = null;
|
|
799
858
|
this._idToken = null;
|
|
859
|
+
this._bearerToken = null;
|
|
860
|
+
this._refreshToken = null;
|
|
861
|
+
this._tokenExpiresAt = null;
|
|
800
862
|
}
|
|
801
863
|
// Auth2 doesn't use key rotation; minimal no-op implementations.
|
|
802
864
|
async rotateKeyPair() {
|
|
@@ -940,7 +1002,7 @@ var ExpoURLParamsAccessor = class {
|
|
|
940
1002
|
// src/providers/embedded/stamper.ts
|
|
941
1003
|
var SecureStore3 = __toESM(require("expo-secure-store"));
|
|
942
1004
|
var import_api_key_stamper = require("@phantom/api-key-stamper");
|
|
943
|
-
var
|
|
1005
|
+
var import_constants3 = require("@phantom/constants");
|
|
944
1006
|
var import_crypto = require("@phantom/crypto");
|
|
945
1007
|
var import_base64url2 = require("@phantom/base64url");
|
|
946
1008
|
var ReactNativeStamper = class {
|
|
@@ -948,7 +1010,7 @@ var ReactNativeStamper = class {
|
|
|
948
1010
|
constructor(config = {}) {
|
|
949
1011
|
this.activeKeyRecord = null;
|
|
950
1012
|
this.pendingKeyRecord = null;
|
|
951
|
-
this.algorithm =
|
|
1013
|
+
this.algorithm = import_constants3.DEFAULT_AUTHENTICATOR_ALGORITHM;
|
|
952
1014
|
this.type = "PKI";
|
|
953
1015
|
this.keyPrefix = config.keyPrefix || "phantom-rn-stamper";
|
|
954
1016
|
this.appId = config.appId || "default";
|
|
@@ -1116,24 +1178,24 @@ var ExpoLogger = class {
|
|
|
1116
1178
|
constructor(enabled = false) {
|
|
1117
1179
|
this.enabled = enabled;
|
|
1118
1180
|
}
|
|
1119
|
-
info(
|
|
1181
|
+
info(message, ...args) {
|
|
1120
1182
|
if (this.enabled) {
|
|
1121
|
-
console.info(`[
|
|
1183
|
+
console.info(`[PHANTOM] ${message}`, ...args);
|
|
1122
1184
|
}
|
|
1123
1185
|
}
|
|
1124
|
-
warn(
|
|
1186
|
+
warn(message, ...args) {
|
|
1125
1187
|
if (this.enabled) {
|
|
1126
|
-
console.warn(`[
|
|
1188
|
+
console.warn(`[PHANTOM] ${message}`, ...args);
|
|
1127
1189
|
}
|
|
1128
1190
|
}
|
|
1129
|
-
error(
|
|
1191
|
+
error(message, ...args) {
|
|
1130
1192
|
if (this.enabled) {
|
|
1131
|
-
console.error(`[
|
|
1193
|
+
console.error(`[PHANTOM] ${message}`, ...args);
|
|
1132
1194
|
}
|
|
1133
1195
|
}
|
|
1134
|
-
|
|
1196
|
+
debug(message, ...args) {
|
|
1135
1197
|
if (this.enabled) {
|
|
1136
|
-
console.log(`[
|
|
1198
|
+
console.log(`[PHANTOM] ${message}`, ...args);
|
|
1137
1199
|
}
|
|
1138
1200
|
}
|
|
1139
1201
|
};
|
|
@@ -1166,12 +1228,12 @@ function PhantomProvider({ children, config, debugConfig, theme, appIcon, appNam
|
|
|
1166
1228
|
const redirectUrl = config.authOptions?.redirectUrl || `${config.scheme}://phantom-auth-callback`;
|
|
1167
1229
|
return {
|
|
1168
1230
|
...config,
|
|
1169
|
-
apiBaseUrl: config.apiBaseUrl ||
|
|
1170
|
-
embeddedWalletType: config.embeddedWalletType ||
|
|
1231
|
+
apiBaseUrl: config.apiBaseUrl || import_constants4.DEFAULT_WALLET_API_URL,
|
|
1232
|
+
embeddedWalletType: config.embeddedWalletType || import_constants4.DEFAULT_EMBEDDED_WALLET_TYPE,
|
|
1171
1233
|
authOptions: {
|
|
1172
1234
|
...config.authOptions || {},
|
|
1173
1235
|
redirectUrl,
|
|
1174
|
-
authUrl: config.authOptions?.authUrl ||
|
|
1236
|
+
authUrl: config.authOptions?.authUrl || import_constants4.DEFAULT_AUTH_URL
|
|
1175
1237
|
}
|
|
1176
1238
|
};
|
|
1177
1239
|
}, [config]);
|
|
@@ -1179,7 +1241,11 @@ function PhantomProvider({ children, config, debugConfig, theme, appIcon, appNam
|
|
|
1179
1241
|
const storage = new ExpoSecureStorage();
|
|
1180
1242
|
const urlParamsAccessor = new ExpoURLParamsAccessor();
|
|
1181
1243
|
const logger = new ExpoLogger(debugConfig?.enabled || false);
|
|
1182
|
-
const stamper = config.unstable__auth2Options ? new ExpoAuth2Stamper(`phantom-auth2-${memoizedConfig.appId}
|
|
1244
|
+
const stamper = config.unstable__auth2Options && config.authOptions?.redirectUrl ? new ExpoAuth2Stamper(`phantom-auth2-${memoizedConfig.appId}`, {
|
|
1245
|
+
authApiBaseUrl: config.unstable__auth2Options.authApiBaseUrl,
|
|
1246
|
+
clientId: config.unstable__auth2Options.clientId,
|
|
1247
|
+
redirectUri: config.authOptions.redirectUrl
|
|
1248
|
+
}) : new ReactNativeStamper({
|
|
1183
1249
|
keyPrefix: `phantom-rn-${memoizedConfig.appId}`,
|
|
1184
1250
|
appId: memoizedConfig.appId
|
|
1185
1251
|
});
|
|
@@ -1205,13 +1271,13 @@ function PhantomProvider({ children, config, debugConfig, theme, appIcon, appNam
|
|
|
1205
1271
|
phantomAppProvider: new ReactNativePhantomAppProvider(),
|
|
1206
1272
|
name: platformName,
|
|
1207
1273
|
analyticsHeaders: {
|
|
1208
|
-
[
|
|
1209
|
-
[
|
|
1210
|
-
[
|
|
1211
|
-
[
|
|
1212
|
-
[
|
|
1213
|
-
[
|
|
1214
|
-
[
|
|
1274
|
+
[import_constants4.ANALYTICS_HEADERS.SDK_TYPE]: "react-native",
|
|
1275
|
+
[import_constants4.ANALYTICS_HEADERS.PLATFORM]: "ext-sdk",
|
|
1276
|
+
[import_constants4.ANALYTICS_HEADERS.PLATFORM_VERSION]: `${import_react_native7.Platform.Version}`,
|
|
1277
|
+
[import_constants4.ANALYTICS_HEADERS.CLIENT]: import_react_native7.Platform.OS,
|
|
1278
|
+
[import_constants4.ANALYTICS_HEADERS.APP_ID]: config.appId,
|
|
1279
|
+
[import_constants4.ANALYTICS_HEADERS.WALLET_TYPE]: config.embeddedWalletType,
|
|
1280
|
+
[import_constants4.ANALYTICS_HEADERS.SDK_VERSION]: "1.0.6"
|
|
1215
1281
|
// Replaced at build time
|
|
1216
1282
|
}
|
|
1217
1283
|
};
|
|
@@ -1325,7 +1391,7 @@ function useEthereum() {
|
|
|
1325
1391
|
|
|
1326
1392
|
// src/index.ts
|
|
1327
1393
|
var import_client = require("@phantom/client");
|
|
1328
|
-
var
|
|
1394
|
+
var import_constants5 = require("@phantom/constants");
|
|
1329
1395
|
var import_wallet_sdk_ui6 = require("@phantom/wallet-sdk-ui");
|
|
1330
1396
|
// Annotate the CommonJS export names for ESM import in node:
|
|
1331
1397
|
0 && (module.exports = {
|
package/dist/index.mjs
CHANGED
|
@@ -515,7 +515,7 @@ var ExpoAuthProvider = class {
|
|
|
515
515
|
// OAuth session management - defaults to allow refresh unless explicitly clearing after logout
|
|
516
516
|
clear_previous_session: (phantomOptions.clearPreviousSession ?? false).toString(),
|
|
517
517
|
allow_refresh: (phantomOptions.allowRefresh ?? true).toString(),
|
|
518
|
-
sdk_version: "1.0.
|
|
518
|
+
sdk_version: "1.0.6",
|
|
519
519
|
sdk_type: "react-native",
|
|
520
520
|
platform: Platform.OS
|
|
521
521
|
});
|
|
@@ -655,14 +655,14 @@ var ExpoAuth2AuthProvider = class {
|
|
|
655
655
|
if (!code) {
|
|
656
656
|
throw new Error("Auth2 callback missing authorization code");
|
|
657
657
|
}
|
|
658
|
-
const { idToken, bearerToken, authUserId, expiresInMs } = await exchangeAuthCode({
|
|
658
|
+
const { idToken, bearerToken, authUserId, expiresInMs, refreshToken } = await exchangeAuthCode({
|
|
659
659
|
authApiBaseUrl: this.auth2ProviderOptions.authApiBaseUrl,
|
|
660
660
|
clientId: this.auth2ProviderOptions.clientId,
|
|
661
661
|
redirectUri: this.auth2ProviderOptions.redirectUri,
|
|
662
662
|
code,
|
|
663
663
|
codeVerifier
|
|
664
664
|
});
|
|
665
|
-
await this.stamper.
|
|
665
|
+
await this.stamper.setTokens({ idToken, bearerToken, refreshToken, expiresInMs });
|
|
666
666
|
const { organizationId, walletId } = await this.kms.discoverOrganizationAndWalletId(bearerToken, authUserId);
|
|
667
667
|
return {
|
|
668
668
|
walletId,
|
|
@@ -683,16 +683,24 @@ import bs58 from "bs58";
|
|
|
683
683
|
import { Buffer } from "buffer";
|
|
684
684
|
import { base64urlEncode } from "@phantom/base64url";
|
|
685
685
|
import { Algorithm } from "@phantom/sdk-types";
|
|
686
|
+
import { refreshToken as refreshTokenRequest } from "@phantom/auth2";
|
|
687
|
+
import { TOKEN_REFRESH_BUFFER_MS } from "@phantom/constants";
|
|
686
688
|
var ExpoAuth2Stamper = class {
|
|
687
689
|
/**
|
|
688
690
|
* @param storageKey - expo-secure-store key used to persist the P-256 private key.
|
|
689
691
|
* Use a unique key per app, e.g. `phantom-auth2-<appId>`.
|
|
692
|
+
* @param refreshConfig - When provided, the stamper will automatically refresh
|
|
693
|
+
* the id_token using the refresh_token before it expires.
|
|
690
694
|
*/
|
|
691
|
-
constructor(storageKey) {
|
|
695
|
+
constructor(storageKey, refreshConfig) {
|
|
692
696
|
this.storageKey = storageKey;
|
|
697
|
+
this.refreshConfig = refreshConfig;
|
|
693
698
|
this._keyPair = null;
|
|
694
699
|
this._keyInfo = null;
|
|
695
700
|
this._idToken = null;
|
|
701
|
+
this._bearerToken = null;
|
|
702
|
+
this._refreshToken = null;
|
|
703
|
+
this._tokenExpiresAt = null;
|
|
696
704
|
this.algorithm = Algorithm.secp256r1;
|
|
697
705
|
this.type = "OIDC";
|
|
698
706
|
}
|
|
@@ -707,6 +715,15 @@ var ExpoAuth2Stamper = class {
|
|
|
707
715
|
if (stored.idToken) {
|
|
708
716
|
this._idToken = stored.idToken;
|
|
709
717
|
}
|
|
718
|
+
if (stored.bearerToken) {
|
|
719
|
+
this._bearerToken = stored.bearerToken;
|
|
720
|
+
}
|
|
721
|
+
if (stored.refreshToken) {
|
|
722
|
+
this._refreshToken = stored.refreshToken;
|
|
723
|
+
}
|
|
724
|
+
if (stored.tokenExpiresAt) {
|
|
725
|
+
this._tokenExpiresAt = stored.tokenExpiresAt;
|
|
726
|
+
}
|
|
710
727
|
return this._keyInfo;
|
|
711
728
|
}
|
|
712
729
|
return this.generateAndStore();
|
|
@@ -718,16 +735,58 @@ var ExpoAuth2Stamper = class {
|
|
|
718
735
|
return this._keyPair;
|
|
719
736
|
}
|
|
720
737
|
/**
|
|
721
|
-
*
|
|
738
|
+
* Returns the current token state (refreshing proactively if near expiry),
|
|
739
|
+
* or null if no token has been set yet.
|
|
740
|
+
*/
|
|
741
|
+
async getTokens() {
|
|
742
|
+
if (this.refreshConfig && this._refreshToken && this._tokenExpiresAt !== null && Date.now() >= this._tokenExpiresAt - TOKEN_REFRESH_BUFFER_MS) {
|
|
743
|
+
const refreshed = await refreshTokenRequest({
|
|
744
|
+
authApiBaseUrl: this.refreshConfig.authApiBaseUrl,
|
|
745
|
+
clientId: this.refreshConfig.clientId,
|
|
746
|
+
redirectUri: this.refreshConfig.redirectUri,
|
|
747
|
+
refreshToken: this._refreshToken
|
|
748
|
+
});
|
|
749
|
+
await this.setTokens(refreshed);
|
|
750
|
+
}
|
|
751
|
+
if (!this._idToken || !this._bearerToken) {
|
|
752
|
+
return null;
|
|
753
|
+
}
|
|
754
|
+
return {
|
|
755
|
+
idToken: this._idToken,
|
|
756
|
+
bearerToken: this._bearerToken,
|
|
757
|
+
refreshToken: this._refreshToken ?? void 0
|
|
758
|
+
};
|
|
759
|
+
}
|
|
760
|
+
/**
|
|
761
|
+
* Arms the stamper with the OIDC token data for subsequent KMS stamp() calls.
|
|
762
|
+
*
|
|
763
|
+
* Persists the tokens to SecureStore alongside the key pair so that
|
|
764
|
+
* auto-connect can restore them on the next app launch without a new login.
|
|
722
765
|
*
|
|
723
|
-
*
|
|
724
|
-
*
|
|
766
|
+
* @param refreshToken - When provided alongside a `refreshConfig`, enables
|
|
767
|
+
* silent token refresh before the token expires.
|
|
768
|
+
* @param expiresInMs - Token lifetime in milliseconds (from `expires_in * 1000`).
|
|
769
|
+
* Used to compute the absolute expiry time for proactive refresh.
|
|
725
770
|
*/
|
|
726
|
-
async
|
|
771
|
+
async setTokens({
|
|
772
|
+
idToken,
|
|
773
|
+
bearerToken,
|
|
774
|
+
refreshToken,
|
|
775
|
+
expiresInMs
|
|
776
|
+
}) {
|
|
727
777
|
this._idToken = idToken;
|
|
778
|
+
this._bearerToken = bearerToken;
|
|
779
|
+
this._refreshToken = refreshToken ?? null;
|
|
780
|
+
this._tokenExpiresAt = expiresInMs != null ? Date.now() + expiresInMs : null;
|
|
728
781
|
const existing = await this.loadRecord();
|
|
729
782
|
if (existing) {
|
|
730
|
-
await this.storeRecord({
|
|
783
|
+
await this.storeRecord({
|
|
784
|
+
...existing,
|
|
785
|
+
idToken,
|
|
786
|
+
bearerToken,
|
|
787
|
+
refreshToken,
|
|
788
|
+
tokenExpiresAt: this._tokenExpiresAt ?? void 0
|
|
789
|
+
});
|
|
731
790
|
}
|
|
732
791
|
}
|
|
733
792
|
async stamp(params) {
|
|
@@ -760,6 +819,9 @@ var ExpoAuth2Stamper = class {
|
|
|
760
819
|
this._keyPair = null;
|
|
761
820
|
this._keyInfo = null;
|
|
762
821
|
this._idToken = null;
|
|
822
|
+
this._bearerToken = null;
|
|
823
|
+
this._refreshToken = null;
|
|
824
|
+
this._tokenExpiresAt = null;
|
|
763
825
|
}
|
|
764
826
|
// Auth2 doesn't use key rotation; minimal no-op implementations.
|
|
765
827
|
async rotateKeyPair() {
|
|
@@ -1079,24 +1141,24 @@ var ExpoLogger = class {
|
|
|
1079
1141
|
constructor(enabled = false) {
|
|
1080
1142
|
this.enabled = enabled;
|
|
1081
1143
|
}
|
|
1082
|
-
info(
|
|
1144
|
+
info(message, ...args) {
|
|
1083
1145
|
if (this.enabled) {
|
|
1084
|
-
console.info(`[
|
|
1146
|
+
console.info(`[PHANTOM] ${message}`, ...args);
|
|
1085
1147
|
}
|
|
1086
1148
|
}
|
|
1087
|
-
warn(
|
|
1149
|
+
warn(message, ...args) {
|
|
1088
1150
|
if (this.enabled) {
|
|
1089
|
-
console.warn(`[
|
|
1151
|
+
console.warn(`[PHANTOM] ${message}`, ...args);
|
|
1090
1152
|
}
|
|
1091
1153
|
}
|
|
1092
|
-
error(
|
|
1154
|
+
error(message, ...args) {
|
|
1093
1155
|
if (this.enabled) {
|
|
1094
|
-
console.error(`[
|
|
1156
|
+
console.error(`[PHANTOM] ${message}`, ...args);
|
|
1095
1157
|
}
|
|
1096
1158
|
}
|
|
1097
|
-
|
|
1159
|
+
debug(message, ...args) {
|
|
1098
1160
|
if (this.enabled) {
|
|
1099
|
-
console.log(`[
|
|
1161
|
+
console.log(`[PHANTOM] ${message}`, ...args);
|
|
1100
1162
|
}
|
|
1101
1163
|
}
|
|
1102
1164
|
};
|
|
@@ -1142,7 +1204,11 @@ function PhantomProvider({ children, config, debugConfig, theme, appIcon, appNam
|
|
|
1142
1204
|
const storage = new ExpoSecureStorage();
|
|
1143
1205
|
const urlParamsAccessor = new ExpoURLParamsAccessor();
|
|
1144
1206
|
const logger = new ExpoLogger(debugConfig?.enabled || false);
|
|
1145
|
-
const stamper = config.unstable__auth2Options ? new ExpoAuth2Stamper(`phantom-auth2-${memoizedConfig.appId}
|
|
1207
|
+
const stamper = config.unstable__auth2Options && config.authOptions?.redirectUrl ? new ExpoAuth2Stamper(`phantom-auth2-${memoizedConfig.appId}`, {
|
|
1208
|
+
authApiBaseUrl: config.unstable__auth2Options.authApiBaseUrl,
|
|
1209
|
+
clientId: config.unstable__auth2Options.clientId,
|
|
1210
|
+
redirectUri: config.authOptions.redirectUrl
|
|
1211
|
+
}) : new ReactNativeStamper({
|
|
1146
1212
|
keyPrefix: `phantom-rn-${memoizedConfig.appId}`,
|
|
1147
1213
|
appId: memoizedConfig.appId
|
|
1148
1214
|
});
|
|
@@ -1174,7 +1240,7 @@ function PhantomProvider({ children, config, debugConfig, theme, appIcon, appNam
|
|
|
1174
1240
|
[ANALYTICS_HEADERS.CLIENT]: Platform2.OS,
|
|
1175
1241
|
[ANALYTICS_HEADERS.APP_ID]: config.appId,
|
|
1176
1242
|
[ANALYTICS_HEADERS.WALLET_TYPE]: config.embeddedWalletType,
|
|
1177
|
-
[ANALYTICS_HEADERS.SDK_VERSION]: "1.0.
|
|
1243
|
+
[ANALYTICS_HEADERS.SDK_VERSION]: "1.0.6"
|
|
1178
1244
|
// Replaced at build time
|
|
1179
1245
|
}
|
|
1180
1246
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@phantom/react-native-sdk",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.6",
|
|
4
4
|
"description": "Phantom Wallet SDK for React Native and Expo applications",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -45,16 +45,16 @@
|
|
|
45
45
|
"directory": "packages/react-native-sdk"
|
|
46
46
|
},
|
|
47
47
|
"dependencies": {
|
|
48
|
-
"@phantom/api-key-stamper": "^1.0.
|
|
49
|
-
"@phantom/auth2": "^1.0.
|
|
50
|
-
"@phantom/base64url": "^1.0.
|
|
51
|
-
"@phantom/chain-interfaces": "^1.0.
|
|
52
|
-
"@phantom/client": "^1.0.
|
|
53
|
-
"@phantom/constants": "^1.0.
|
|
54
|
-
"@phantom/crypto": "^1.0.
|
|
55
|
-
"@phantom/embedded-provider-core": "^1.0.
|
|
56
|
-
"@phantom/sdk-types": "^1.0.
|
|
57
|
-
"@phantom/wallet-sdk-ui": "^1.0.
|
|
48
|
+
"@phantom/api-key-stamper": "^1.0.6",
|
|
49
|
+
"@phantom/auth2": "^1.0.2",
|
|
50
|
+
"@phantom/base64url": "^1.0.6",
|
|
51
|
+
"@phantom/chain-interfaces": "^1.0.6",
|
|
52
|
+
"@phantom/client": "^1.0.6",
|
|
53
|
+
"@phantom/constants": "^1.0.6",
|
|
54
|
+
"@phantom/crypto": "^1.0.6",
|
|
55
|
+
"@phantom/embedded-provider-core": "^1.0.6",
|
|
56
|
+
"@phantom/sdk-types": "^1.0.6",
|
|
57
|
+
"@phantom/wallet-sdk-ui": "^1.0.6",
|
|
58
58
|
"@types/bs58": "^5.0.0",
|
|
59
59
|
"bs58": "^6.0.0",
|
|
60
60
|
"buffer": "^6.0.3"
|