@getpara/core-sdk 2.0.0-alpha.29 → 2.0.0-alpha.30

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.
@@ -122,6 +122,7 @@ const _ParaCore = class _ParaCore {
122
122
  __privateAdd(this, _ParaCore_instances);
123
123
  __privateAdd(this, _authInfo);
124
124
  this.isNativePasskey = false;
125
+ this.isReady = false;
125
126
  __privateAdd(this, _partner);
126
127
  this.accountLinkInProgress = void 0;
127
128
  this.isAwaitingAccountCreation = false;
@@ -771,6 +772,9 @@ const _ParaCore = class _ParaCore {
771
772
  touchSession(regenerate = false) {
772
773
  return __async(this, null, function* () {
773
774
  var _a, _b, _c;
775
+ if (!this.isReady) {
776
+ yield this.ready();
777
+ }
774
778
  const session = yield this.ctx.client.touchSession(regenerate);
775
779
  if (!__privateGet(this, _partner) || ((_a = __privateGet(this, _partner)) == null ? void 0 : _a.id) !== session.partnerId || !(0, import_utils2.supportedWalletTypesEq)(((_b = __privateGet(this, _partner)) == null ? void 0 : _b.supportedWalletTypes) || [], session.supportedWalletTypes) || (((_c = __privateGet(this, _partner)) == null ? void 0 : _c.cosmosPrefix) || "cosmos") !== session.cosmosPrefix) {
776
780
  yield __privateMethod(this, _ParaCore_instances, getPartner_fn).call(this, session.partnerId);
@@ -929,31 +933,27 @@ const _ParaCore = class _ParaCore {
929
933
  * @param externalAddress - External wallet address to set.
930
934
  * @param externalType - Type of external wallet to set.
931
935
  */
932
- setExternalWallet(_0) {
933
- return __async(this, arguments, function* ({
934
- address,
935
- type,
936
- provider,
937
- providerId,
938
- addressBech32,
939
- withFullParaAuth,
940
- isConnectionOnly,
941
- withVerification
942
- }) {
943
- this.externalWallets = {
944
- [address]: {
945
- id: address,
946
- address: addressBech32 != null ? addressBech32 : address,
947
- type,
948
- name: provider,
949
- isExternal: true,
950
- isExternalWithParaAuth: withFullParaAuth,
951
- externalProviderId: providerId,
952
- signer: "",
953
- isExternalConnectionOnly: isConnectionOnly,
954
- isExternalWithVerification: withVerification
955
- }
956
- };
936
+ setExternalWallet(externalWallet) {
937
+ return __async(this, null, function* () {
938
+ this.externalWallets = (Array.isArray(externalWallet) ? externalWallet : [externalWallet]).reduce(
939
+ (acc, { address, type, provider, providerId, addressBech32, withFullParaAuth, isConnectionOnly, withVerification }) => {
940
+ return __spreadProps(__spreadValues({}, acc), {
941
+ [address]: {
942
+ id: address,
943
+ address: addressBech32 != null ? addressBech32 : address,
944
+ type,
945
+ name: provider,
946
+ isExternal: true,
947
+ isExternalWithParaAuth: withFullParaAuth,
948
+ externalProviderId: providerId,
949
+ signer: "",
950
+ isExternalConnectionOnly: isConnectionOnly,
951
+ isExternalWithVerification: withVerification
952
+ }
953
+ });
954
+ },
955
+ {}
956
+ );
957
957
  this.setExternalWallets(this.externalWallets);
958
958
  (0, import_utils2.dispatchEvent)(import_types.ParaEvent.EXTERNAL_WALLET_CHANGE_EVENT, null);
959
959
  });
@@ -1305,13 +1305,22 @@ const _ParaCore = class _ParaCore {
1305
1305
  } = _b, urlOptions = __objRest(_b, [
1306
1306
  "externalWallet"
1307
1307
  ]);
1308
- if (this.externalWalletConnectionOnly || externalWallet.isConnectionOnly) {
1309
- externalWallet.withFullParaAuth = false;
1310
- yield this.setExternalWallet(externalWallet);
1308
+ const externalWallets = Array.isArray(externalWallet) ? externalWallet : [externalWallet];
1309
+ if (this.externalWalletConnectionOnly || externalWallets.every((wallet) => wallet.isConnectionOnly)) {
1310
+ yield this.setExternalWallet(
1311
+ externalWallets.map((wallet) => __spreadProps(__spreadValues({}, wallet), {
1312
+ withFullParaAuth: false
1313
+ }))
1314
+ );
1311
1315
  return Promise.resolve({
1312
1316
  userId: constants.EXTERNAL_WALLET_CONNECTION_ONLY_USER_ID
1313
1317
  });
1314
1318
  }
1319
+ if (Array.isArray(externalWallet)) {
1320
+ throw new Error(
1321
+ "Cannot authenticate multiple external wallets at once. To connect multiple wallets at once, use CONNECTION_ONLY mode."
1322
+ );
1323
+ }
1315
1324
  this.requireApiKey();
1316
1325
  const serverAuthState = yield this.ctx.client.loginExternalWallet({ externalWallet });
1317
1326
  if (!externalWallet.withFullParaAuth && externalWallet.withVerification) {
@@ -2782,6 +2791,9 @@ const _ParaCore = class _ParaCore {
2782
2791
  (0, import_utils2.dispatchEvent)(import_types.ParaEvent.LOGOUT_EVENT, null);
2783
2792
  });
2784
2793
  }
2794
+ get toStringAdditions() {
2795
+ return {};
2796
+ }
2785
2797
  /**
2786
2798
  * Converts to a string, removing sensitive data when logging this class.
2787
2799
  *
@@ -2805,7 +2817,7 @@ const _ParaCore = class _ParaCore {
2805
2817
  }),
2806
2818
  {}
2807
2819
  );
2808
- const obj = {
2820
+ const obj = __spreadProps(__spreadValues({
2809
2821
  partnerId: (_a = __privateGet(this, _partner)) == null ? void 0 : _a.id,
2810
2822
  supportedWalletTypes: (_b = __privateGet(this, _partner)) == null ? void 0 : _b.supportedWalletTypes,
2811
2823
  cosmosPrefix: (_c = __privateGet(this, _partner)) == null ? void 0 : _c.cosmosPrefix,
@@ -2818,6 +2830,8 @@ const _ParaCore = class _ParaCore {
2818
2830
  wallets: redactedWallets,
2819
2831
  externalWallets: redactedExternalWallets,
2820
2832
  loginEncryptionKeyPair: this.loginEncryptionKeyPair ? "[REDACTED]" : void 0,
2833
+ isReady: this.isReady
2834
+ }, this.toStringAdditions), {
2821
2835
  ctx: {
2822
2836
  apiKey: this.ctx.apiKey,
2823
2837
  disableWorkers: this.ctx.disableWorkers,
@@ -2828,9 +2842,14 @@ const _ParaCore = class _ParaCore {
2828
2842
  useDKLS: this.ctx.useDKLS,
2829
2843
  cosmosPrefix: this.ctx.cosmosPrefix
2830
2844
  }
2831
- };
2845
+ });
2832
2846
  return `Para ${JSON.stringify(obj, null, 2)}`;
2833
2847
  }
2848
+ devLog(...s) {
2849
+ if (this.ctx.env === import_types.Environment.DEV || this.ctx.env === import_types.Environment.SANDBOX) {
2850
+ console.log(...s);
2851
+ }
2852
+ }
2834
2853
  getNewCredentialAndUrl() {
2835
2854
  return __async(this, arguments, function* ({
2836
2855
  authMethod = "PASSKEY",
@@ -3248,7 +3267,7 @@ prepareAuthState_fn = function(_0) {
3248
3267
  yield __privateMethod(this, _ParaCore_instances, setAuthInfo_fn).call(this, authInfo);
3249
3268
  yield this.assertIsAuthSet();
3250
3269
  if (!!externalWallet) {
3251
- yield this.setExternalWallet(externalWallet);
3270
+ yield this.setExternalWallet([externalWallet]);
3252
3271
  }
3253
3272
  if (!!userId) {
3254
3273
  yield this.setUserId(userId);
@@ -88,6 +88,7 @@ const _ParaCore = class _ParaCore {
88
88
  __privateAdd(this, _ParaCore_instances);
89
89
  __privateAdd(this, _authInfo);
90
90
  this.isNativePasskey = false;
91
+ this.isReady = false;
91
92
  __privateAdd(this, _partner);
92
93
  this.accountLinkInProgress = void 0;
93
94
  this.isAwaitingAccountCreation = false;
@@ -737,6 +738,9 @@ const _ParaCore = class _ParaCore {
737
738
  touchSession(regenerate = false) {
738
739
  return __async(this, null, function* () {
739
740
  var _a, _b, _c;
741
+ if (!this.isReady) {
742
+ yield this.ready();
743
+ }
740
744
  const session = yield this.ctx.client.touchSession(regenerate);
741
745
  if (!__privateGet(this, _partner) || ((_a = __privateGet(this, _partner)) == null ? void 0 : _a.id) !== session.partnerId || !supportedWalletTypesEq(((_b = __privateGet(this, _partner)) == null ? void 0 : _b.supportedWalletTypes) || [], session.supportedWalletTypes) || (((_c = __privateGet(this, _partner)) == null ? void 0 : _c.cosmosPrefix) || "cosmos") !== session.cosmosPrefix) {
742
746
  yield __privateMethod(this, _ParaCore_instances, getPartner_fn).call(this, session.partnerId);
@@ -895,31 +899,27 @@ const _ParaCore = class _ParaCore {
895
899
  * @param externalAddress - External wallet address to set.
896
900
  * @param externalType - Type of external wallet to set.
897
901
  */
898
- setExternalWallet(_0) {
899
- return __async(this, arguments, function* ({
900
- address,
901
- type,
902
- provider,
903
- providerId,
904
- addressBech32,
905
- withFullParaAuth,
906
- isConnectionOnly,
907
- withVerification
908
- }) {
909
- this.externalWallets = {
910
- [address]: {
911
- id: address,
912
- address: addressBech32 != null ? addressBech32 : address,
913
- type,
914
- name: provider,
915
- isExternal: true,
916
- isExternalWithParaAuth: withFullParaAuth,
917
- externalProviderId: providerId,
918
- signer: "",
919
- isExternalConnectionOnly: isConnectionOnly,
920
- isExternalWithVerification: withVerification
921
- }
922
- };
902
+ setExternalWallet(externalWallet) {
903
+ return __async(this, null, function* () {
904
+ this.externalWallets = (Array.isArray(externalWallet) ? externalWallet : [externalWallet]).reduce(
905
+ (acc, { address, type, provider, providerId, addressBech32, withFullParaAuth, isConnectionOnly, withVerification }) => {
906
+ return __spreadProps(__spreadValues({}, acc), {
907
+ [address]: {
908
+ id: address,
909
+ address: addressBech32 != null ? addressBech32 : address,
910
+ type,
911
+ name: provider,
912
+ isExternal: true,
913
+ isExternalWithParaAuth: withFullParaAuth,
914
+ externalProviderId: providerId,
915
+ signer: "",
916
+ isExternalConnectionOnly: isConnectionOnly,
917
+ isExternalWithVerification: withVerification
918
+ }
919
+ });
920
+ },
921
+ {}
922
+ );
923
923
  this.setExternalWallets(this.externalWallets);
924
924
  dispatchEvent(ParaEvent.EXTERNAL_WALLET_CHANGE_EVENT, null);
925
925
  });
@@ -1271,13 +1271,22 @@ const _ParaCore = class _ParaCore {
1271
1271
  } = _b, urlOptions = __objRest(_b, [
1272
1272
  "externalWallet"
1273
1273
  ]);
1274
- if (this.externalWalletConnectionOnly || externalWallet.isConnectionOnly) {
1275
- externalWallet.withFullParaAuth = false;
1276
- yield this.setExternalWallet(externalWallet);
1274
+ const externalWallets = Array.isArray(externalWallet) ? externalWallet : [externalWallet];
1275
+ if (this.externalWalletConnectionOnly || externalWallets.every((wallet) => wallet.isConnectionOnly)) {
1276
+ yield this.setExternalWallet(
1277
+ externalWallets.map((wallet) => __spreadProps(__spreadValues({}, wallet), {
1278
+ withFullParaAuth: false
1279
+ }))
1280
+ );
1277
1281
  return Promise.resolve({
1278
1282
  userId: constants.EXTERNAL_WALLET_CONNECTION_ONLY_USER_ID
1279
1283
  });
1280
1284
  }
1285
+ if (Array.isArray(externalWallet)) {
1286
+ throw new Error(
1287
+ "Cannot authenticate multiple external wallets at once. To connect multiple wallets at once, use CONNECTION_ONLY mode."
1288
+ );
1289
+ }
1281
1290
  this.requireApiKey();
1282
1291
  const serverAuthState = yield this.ctx.client.loginExternalWallet({ externalWallet });
1283
1292
  if (!externalWallet.withFullParaAuth && externalWallet.withVerification) {
@@ -2748,6 +2757,9 @@ const _ParaCore = class _ParaCore {
2748
2757
  dispatchEvent(ParaEvent.LOGOUT_EVENT, null);
2749
2758
  });
2750
2759
  }
2760
+ get toStringAdditions() {
2761
+ return {};
2762
+ }
2751
2763
  /**
2752
2764
  * Converts to a string, removing sensitive data when logging this class.
2753
2765
  *
@@ -2771,7 +2783,7 @@ const _ParaCore = class _ParaCore {
2771
2783
  }),
2772
2784
  {}
2773
2785
  );
2774
- const obj = {
2786
+ const obj = __spreadProps(__spreadValues({
2775
2787
  partnerId: (_a = __privateGet(this, _partner)) == null ? void 0 : _a.id,
2776
2788
  supportedWalletTypes: (_b = __privateGet(this, _partner)) == null ? void 0 : _b.supportedWalletTypes,
2777
2789
  cosmosPrefix: (_c = __privateGet(this, _partner)) == null ? void 0 : _c.cosmosPrefix,
@@ -2784,6 +2796,8 @@ const _ParaCore = class _ParaCore {
2784
2796
  wallets: redactedWallets,
2785
2797
  externalWallets: redactedExternalWallets,
2786
2798
  loginEncryptionKeyPair: this.loginEncryptionKeyPair ? "[REDACTED]" : void 0,
2799
+ isReady: this.isReady
2800
+ }, this.toStringAdditions), {
2787
2801
  ctx: {
2788
2802
  apiKey: this.ctx.apiKey,
2789
2803
  disableWorkers: this.ctx.disableWorkers,
@@ -2794,9 +2808,14 @@ const _ParaCore = class _ParaCore {
2794
2808
  useDKLS: this.ctx.useDKLS,
2795
2809
  cosmosPrefix: this.ctx.cosmosPrefix
2796
2810
  }
2797
- };
2811
+ });
2798
2812
  return `Para ${JSON.stringify(obj, null, 2)}`;
2799
2813
  }
2814
+ devLog(...s) {
2815
+ if (this.ctx.env === Environment.DEV || this.ctx.env === Environment.SANDBOX) {
2816
+ console.log(...s);
2817
+ }
2818
+ }
2800
2819
  getNewCredentialAndUrl() {
2801
2820
  return __async(this, arguments, function* ({
2802
2821
  authMethod = "PASSKEY",
@@ -3214,7 +3233,7 @@ prepareAuthState_fn = function(_0) {
3214
3233
  yield __privateMethod(this, _ParaCore_instances, setAuthInfo_fn).call(this, authInfo);
3215
3234
  yield this.assertIsAuthSet();
3216
3235
  if (!!externalWallet) {
3217
- yield this.setExternalWallet(externalWallet);
3236
+ yield this.setExternalWallet([externalWallet]);
3218
3237
  }
3219
3238
  if (!!userId) {
3220
3239
  yield this.setUserId(userId);
@@ -8,6 +8,7 @@ export declare abstract class ParaCore implements CoreInterface {
8
8
  ctx: Ctx;
9
9
  protected isNativePasskey: boolean;
10
10
  protected isPartnerOptional?: boolean;
11
+ isReady: boolean;
11
12
  get authInfo(): CoreAuthInfo | undefined;
12
13
  get email(): AuthIdentifier<'email'> | undefined;
13
14
  get phone(): AuthIdentifier<'phone'> | undefined;
@@ -205,6 +206,7 @@ export declare abstract class ParaCore implements CoreInterface {
205
206
  * Init only needs to be called for storage that is async.
206
207
  */
207
208
  init(): Promise<void>;
209
+ protected abstract ready(): Promise<void>;
208
210
  protected setAuth(auth: PrimaryAuth, { extras, userId }?: {
209
211
  extras?: AuthExtras;
210
212
  userId?: string;
@@ -237,7 +239,7 @@ export declare abstract class ParaCore implements CoreInterface {
237
239
  * @param externalAddress - External wallet address to set.
238
240
  * @param externalType - Type of external wallet to set.
239
241
  */
240
- setExternalWallet({ address, type, provider, providerId, addressBech32, withFullParaAuth, isConnectionOnly, withVerification, }: ExternalWalletInfo): Promise<void>;
242
+ setExternalWallet(externalWallet: ExternalWalletInfo[] | ExternalWalletInfo): Promise<void>;
241
243
  /**
242
244
  * Sets the user id associated with the `ParaCore` instance.
243
245
  * @param userId - User id to set.
@@ -653,12 +655,14 @@ export declare abstract class ParaCore implements CoreInterface {
653
655
  logout({ clearPregenWallets }?: {
654
656
  clearPregenWallets?: boolean;
655
657
  }): Promise<void>;
658
+ protected get toStringAdditions(): Record<string, unknown>;
656
659
  /**
657
660
  * Converts to a string, removing sensitive data when logging this class.
658
661
  *
659
662
  * Doesn't work for all types of logging.
660
663
  **/
661
664
  toString(): string;
665
+ protected devLog(...s: string[]): void;
662
666
  protected getNewCredentialAndUrl({ authMethod, isForNewDevice, portalTheme, shorten, }?: NewCredentialUrlParams): Promise<{
663
667
  credentialId: string;
664
668
  url?: string;
@@ -142,7 +142,7 @@ export type CoreMethods = Record<CoreMethodName, {
142
142
  /**
143
143
  * The external wallet information to use for login.
144
144
  */
145
- externalWallet: ExternalWalletInfo;
145
+ externalWallet: ExternalWalletInfo | ExternalWalletInfo[];
146
146
  };
147
147
  response: AuthStateVerifyOrLogin;
148
148
  };
package/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "@getpara/core-sdk",
3
- "version": "2.0.0-alpha.29",
3
+ "version": "2.0.0-alpha.30",
4
4
  "dependencies": {
5
5
  "@celo/utils": "^8.0.2",
6
6
  "@cosmjs/encoding": "^0.32.4",
7
7
  "@ethereumjs/util": "^9.1.0",
8
- "@getpara/user-management-client": "2.0.0-alpha.29",
8
+ "@getpara/user-management-client": "2.0.0-alpha.30",
9
9
  "@noble/hashes": "^1.5.0",
10
10
  "base64url": "^3.0.1",
11
11
  "libphonenumber-js": "^1.11.7",
@@ -27,7 +27,7 @@
27
27
  "dist",
28
28
  "package.json"
29
29
  ],
30
- "gitHead": "7b90cb5a1a83f9bce9d61bd2baf190c47b58b705",
30
+ "gitHead": "8b06219b9c248a3fbdbd05dc7501e8042c369301",
31
31
  "main": "dist/cjs/index.js",
32
32
  "module": "dist/esm/index.js",
33
33
  "scripts": {