@getpara/core-sdk 1.10.0 → 1.11.0

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.
Files changed (36) hide show
  1. package/dist/cjs/ParaCore.js +81 -49
  2. package/dist/cjs/constants.js +1 -1
  3. package/dist/cjs/utils/formatting.js +7 -3
  4. package/dist/cjs/utils/wallet.js +18 -2
  5. package/dist/esm/ParaCore.js +83 -50
  6. package/dist/esm/{chunk-UICEQADR.js → chunk-7B52C2XE.js} +2 -0
  7. package/dist/esm/constants.js +2 -2
  8. package/dist/esm/cryptography/utils.js +1 -1
  9. package/dist/esm/errors.js +1 -1
  10. package/dist/esm/external/mpcComputationClient.js +1 -1
  11. package/dist/esm/external/userManagementClient.js +1 -1
  12. package/dist/esm/index.js +1 -1
  13. package/dist/esm/shares/KeyContainer.js +1 -1
  14. package/dist/esm/shares/recovery.js +1 -1
  15. package/dist/esm/shares/shareDistribution.js +1 -1
  16. package/dist/esm/transmission/transmissionUtils.js +1 -1
  17. package/dist/esm/types/config.js +1 -1
  18. package/dist/esm/types/events.js +1 -1
  19. package/dist/esm/types/index.js +1 -1
  20. package/dist/esm/types/onRamps.js +1 -1
  21. package/dist/esm/types/popup.js +1 -1
  22. package/dist/esm/types/recovery.js +1 -1
  23. package/dist/esm/types/wallet.js +1 -1
  24. package/dist/esm/utils/events.js +1 -1
  25. package/dist/esm/utils/formatting.js +8 -4
  26. package/dist/esm/utils/listeners.js +1 -1
  27. package/dist/esm/utils/onRamps.js +1 -1
  28. package/dist/esm/utils/polling.js +1 -1
  29. package/dist/esm/utils/url.js +1 -1
  30. package/dist/esm/utils/wallet.js +7 -2
  31. package/dist/types/ParaCore.d.ts +6 -3
  32. package/dist/types/index.d.ts +1 -1
  33. package/dist/types/types/params.d.ts +3 -0
  34. package/dist/types/utils/formatting.d.ts +2 -1
  35. package/dist/types/utils/wallet.d.ts +1 -0
  36. package/package.json +3 -3
@@ -61,6 +61,7 @@ var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot
61
61
  var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
62
62
  var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
63
63
  var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
64
+ var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "access private method"), method);
64
65
  var __async = (__this, __arguments, generator) => {
65
66
  return new Promise((resolve, reject) => {
66
67
  var fulfilled = (value) => {
@@ -100,7 +101,7 @@ var import_utils2 = require("./utils/index.js");
100
101
  var import_errors = require("./errors.js");
101
102
  var constants = __toESM(require("./constants.js"));
102
103
  var import_listeners = require("./utils/listeners.js");
103
- var _supportedWalletTypes, _supportedWalletTypesOpt;
104
+ var _supportedWalletTypes, _supportedWalletTypesOpt, _ParaCore_instances, createPregenWallet_fn;
104
105
  if (typeof global !== "undefined") {
105
106
  global.Buffer = global.Buffer || import_buffer.Buffer;
106
107
  } else if (typeof window !== "undefined") {
@@ -120,6 +121,7 @@ const _ParaCore = class _ParaCore {
120
121
  * @returns - A new ParaCore instance.
121
122
  */
122
123
  constructor(env, apiKey, opts) {
124
+ __privateAdd(this, _ParaCore_instances);
123
125
  this.isAwaitingAccountCreation = false;
124
126
  this.isAwaitingLogin = false;
125
127
  this.isAwaitingFarcaster = false;
@@ -526,7 +528,7 @@ const _ParaCore = class _ParaCore {
526
528
  var _a, _b;
527
529
  if (this.externalWallets[walletId]) {
528
530
  const wallet2 = this.externalWallets[walletId];
529
- return options.truncate ? (0, import_utils2.truncateAddress)(wallet2.address, wallet2.type, { prefix: this.cosmosPrefix }) : wallet2.address;
531
+ return options.truncate ? (0, import_utils2.truncateAddress)(wallet2.address, wallet2.type, { prefix: this.cosmosPrefix, targetLength: options.targetLength }) : wallet2.address;
530
532
  }
531
533
  const wallet = this.findWallet(walletId, options.addressType);
532
534
  if (!wallet) {
@@ -544,7 +546,7 @@ const _ParaCore = class _ParaCore {
544
546
  str = wallet.address;
545
547
  break;
546
548
  }
547
- return options.truncate ? (0, import_utils2.truncateAddress)(str, wallet.type, { prefix }) : str;
549
+ return options.truncate ? (0, import_utils2.truncateAddress)(str, wallet.type, { prefix, targetLength: options.targetLength }) : str;
548
550
  }
549
551
  /**
550
552
  * Returns a unique hash for a wallet suitable for use as an identicon seed.
@@ -1530,10 +1532,16 @@ const _ParaCore = class _ParaCore {
1530
1532
  if (this.isUsingExternalWallet()) {
1531
1533
  return true;
1532
1534
  }
1535
+ if (this.isGuestMode) {
1536
+ return true;
1537
+ }
1533
1538
  const isSessionActive = yield this.isSessionActive();
1534
1539
  return isSessionActive && (this.isNoWalletConfig || this.currentWalletIdsArray.length > 0 && this.currentWalletIdsArray.reduce((acc, [id]) => acc && !!this.wallets[id], true));
1535
1540
  });
1536
1541
  }
1542
+ get isGuestMode() {
1543
+ return !this.userId && this.currentWalletIdsArray.length > 0 && this.currentWalletIdsArray.every(([id]) => !!this.wallets[id] && this.wallets[id].pregenIdentifierType === "GUEST_ID");
1544
+ }
1537
1545
  supportedAuthMethods(auth) {
1538
1546
  return __async(this, null, function* () {
1539
1547
  const { supportedAuthMethods } = yield this.ctx.client.getSupportedAuthMethods(auth);
@@ -2238,51 +2246,7 @@ const _ParaCore = class _ParaCore {
2238
2246
  **/
2239
2247
  createPregenWallet(opts) {
2240
2248
  return __async(this, null, function* () {
2241
- var _a, _b;
2242
- const {
2243
- type: _type = (_a = this.supportedWalletTypes.find(({ optional }) => !optional)) == null ? void 0 : _a.type,
2244
- pregenIdentifier,
2245
- pregenIdentifierType = "EMAIL"
2246
- } = opts;
2247
- this.requireApiKey();
2248
- const walletType = yield this.assertIsValidWalletType(
2249
- _type != null ? _type : (_b = this.supportedWalletTypes.find(({ optional }) => !optional)) == null ? void 0 : _b.type
2250
- );
2251
- let keygenRes;
2252
- switch (walletType) {
2253
- case import_user_management_client.WalletType.SOLANA:
2254
- keygenRes = yield this.platformUtils.ed25519PreKeygen(
2255
- this.ctx,
2256
- pregenIdentifier,
2257
- pregenIdentifierType,
2258
- this.retrieveSessionCookie()
2259
- );
2260
- break;
2261
- default:
2262
- keygenRes = yield this.platformUtils.preKeygen(
2263
- this.ctx,
2264
- void 0,
2265
- pregenIdentifier,
2266
- pregenIdentifierType,
2267
- walletType,
2268
- null,
2269
- this.retrieveSessionCookie()
2270
- );
2271
- break;
2272
- }
2273
- const { signer, walletId } = keygenRes;
2274
- this.wallets[walletId] = {
2275
- id: walletId,
2276
- signer,
2277
- scheme: walletType === import_user_management_client.WalletType.SOLANA ? import_user_management_client.WalletScheme.ED25519 : import_user_management_client.WalletScheme.DKLS,
2278
- type: walletType,
2279
- isPregen: true,
2280
- pregenIdentifier,
2281
- pregenIdentifierType
2282
- };
2283
- yield this.waitForPregenWalletAddress(walletId);
2284
- yield this.populatePregenWalletAddresses();
2285
- return this.wallets[walletId];
2249
+ return yield __privateMethod(this, _ParaCore_instances, createPregenWallet_fn).call(this, opts);
2286
2250
  });
2287
2251
  }
2288
2252
  /**
@@ -2303,7 +2267,7 @@ const _ParaCore = class _ParaCore {
2303
2267
  }) {
2304
2268
  const wallets = [];
2305
2269
  for (const type of yield this.getTypesToCreate(types)) {
2306
- const wallet = yield this.createPregenWallet({ type, pregenIdentifier, pregenIdentifierType });
2270
+ const wallet = yield __privateMethod(this, _ParaCore_instances, createPregenWallet_fn).call(this, { type, pregenIdentifier, pregenIdentifierType });
2307
2271
  wallets.push(wallet);
2308
2272
  }
2309
2273
  return wallets;
@@ -2452,6 +2416,24 @@ const _ParaCore = class _ParaCore {
2452
2416
  return res.wallets.filter((w) => this.isWalletSupported((0, import_utils2.entityToWallet)(w)));
2453
2417
  });
2454
2418
  }
2419
+ createGuestWallets() {
2420
+ return __async(this, arguments, function* ({ types } = {}) {
2421
+ const wallets = [];
2422
+ const currentWalletIds = {};
2423
+ const guestId = (0, import_utils2.newUuid)();
2424
+ for (const type of yield this.getTypesToCreate(
2425
+ types != null ? types : this.supportedWalletTypes.filter(({ optional }) => !optional).map(({ type: type2 }) => type2)
2426
+ )) {
2427
+ const wallet = yield __privateMethod(this, _ParaCore_instances, createPregenWallet_fn).call(this, { type, pregenIdentifier: guestId, pregenIdentifierType: "GUEST_ID" });
2428
+ wallets.push(wallet);
2429
+ (0, import_utils2.getEquivalentTypes)(type).filter((t) => __privateGet(this, _supportedWalletTypes).some(({ type: type2, optional }) => t === type2 && !optional)).forEach((eqType) => {
2430
+ currentWalletIds[eqType] = [wallet.id];
2431
+ });
2432
+ }
2433
+ yield this.setCurrentWalletIds(currentWalletIds);
2434
+ return wallets;
2435
+ });
2436
+ }
2455
2437
  encodeWalletBase64(wallet) {
2456
2438
  const walletJson = JSON.stringify(wallet);
2457
2439
  const base64Wallet = Buffer.from(walletJson).toString("base64");
@@ -2969,6 +2951,56 @@ const _ParaCore = class _ParaCore {
2969
2951
  };
2970
2952
  _supportedWalletTypes = new WeakMap();
2971
2953
  _supportedWalletTypesOpt = new WeakMap();
2954
+ _ParaCore_instances = new WeakSet();
2955
+ createPregenWallet_fn = function(opts) {
2956
+ return __async(this, null, function* () {
2957
+ var _a, _b;
2958
+ const {
2959
+ type: _type = (_a = this.supportedWalletTypes.find(({ optional }) => !optional)) == null ? void 0 : _a.type,
2960
+ pregenIdentifier,
2961
+ pregenIdentifierType = "EMAIL"
2962
+ } = opts;
2963
+ this.requireApiKey();
2964
+ const walletType = yield this.assertIsValidWalletType(
2965
+ _type != null ? _type : (_b = this.supportedWalletTypes.find(({ optional }) => !optional)) == null ? void 0 : _b.type
2966
+ );
2967
+ let keygenRes;
2968
+ switch (walletType) {
2969
+ case import_user_management_client.WalletType.SOLANA:
2970
+ keygenRes = yield this.platformUtils.ed25519PreKeygen(
2971
+ this.ctx,
2972
+ pregenIdentifier,
2973
+ pregenIdentifierType,
2974
+ this.retrieveSessionCookie()
2975
+ );
2976
+ break;
2977
+ default:
2978
+ keygenRes = yield this.platformUtils.preKeygen(
2979
+ this.ctx,
2980
+ void 0,
2981
+ pregenIdentifier,
2982
+ pregenIdentifierType,
2983
+ walletType,
2984
+ null,
2985
+ this.retrieveSessionCookie()
2986
+ );
2987
+ break;
2988
+ }
2989
+ const { signer, walletId } = keygenRes;
2990
+ this.wallets[walletId] = {
2991
+ id: walletId,
2992
+ signer,
2993
+ scheme: walletType === import_user_management_client.WalletType.SOLANA ? import_user_management_client.WalletScheme.ED25519 : import_user_management_client.WalletScheme.DKLS,
2994
+ type: walletType,
2995
+ isPregen: true,
2996
+ pregenIdentifier,
2997
+ pregenIdentifierType
2998
+ };
2999
+ yield this.waitForPregenWalletAddress(walletId);
3000
+ yield this.populatePregenWalletAddresses();
3001
+ return this.wallets[walletId];
3002
+ });
3003
+ };
2972
3004
  _ParaCore.version = constants.PARA_CORE_VERSION;
2973
3005
  let ParaCore = _ParaCore;
2974
3006
  // Annotate the CommonJS export names for ESM import in node:
@@ -36,7 +36,7 @@ __export(constants_exports, {
36
36
  SHORT_POLLING_INTERVAL_MS: () => SHORT_POLLING_INTERVAL_MS
37
37
  });
38
38
  module.exports = __toCommonJS(constants_exports);
39
- const PARA_CORE_VERSION = '1.10.0';
39
+ const PARA_CORE_VERSION = '1.11.0';
40
40
  const PREFIX = "@CAPSULE/";
41
41
  const LOCAL_STORAGE_EMAIL = `${PREFIX}e-mail`;
42
42
  const LOCAL_STORAGE_PHONE = `${PREFIX}phone`;
@@ -95,9 +95,13 @@ function getCosmosAddress(publicKey, prefix) {
95
95
  const compressedPublicKey = compressPubkey(uncompressedPublicKey);
96
96
  return (0, import_encoding.toBech32)(prefix, rawSecp256k1PubkeyToRawAddress(compressedPublicKey));
97
97
  }
98
- function truncateAddress(str, addressType, { prefix = addressType === "COSMOS" ? "cosmos" : void 0 } = {}) {
99
- const headLength = (addressType === "COSMOS" ? prefix.length : addressType === "SOLANA" ? 0 : 2) + 4;
100
- return `${str.slice(0, headLength)}...${str.slice(-4)}`;
98
+ function truncateAddress(str, addressType, {
99
+ prefix = addressType === "COSMOS" ? "cosmos" : void 0,
100
+ targetLength
101
+ } = {}) {
102
+ const minimum = addressType === "COSMOS" ? prefix.length : addressType === "EVM" ? 2 : 0;
103
+ const margin = targetLength !== void 0 ? (targetLength - minimum) / 2 : 4;
104
+ return `${str.slice(0, minimum + margin)}...${str.slice(-1 * margin)}`;
101
105
  }
102
106
  function stringToPhoneNumber(str) {
103
107
  var _a;
@@ -1,9 +1,11 @@
1
+ var __create = Object.create;
1
2
  var __defProp = Object.defineProperty;
2
3
  var __defProps = Object.defineProperties;
3
4
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
5
  var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
5
6
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
7
  var __getOwnPropSymbols = Object.getOwnPropertySymbols;
8
+ var __getProtoOf = Object.getPrototypeOf;
7
9
  var __hasOwnProp = Object.prototype.hasOwnProperty;
8
10
  var __propIsEnum = Object.prototype.propertyIsEnumerable;
9
11
  var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
@@ -31,6 +33,14 @@ var __copyProps = (to, from, except, desc) => {
31
33
  }
32
34
  return to;
33
35
  };
36
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
37
+ // If the importer is in node compatibility mode or this is not an ESM
38
+ // file that has been converted to a CommonJS file using a Babel-
39
+ // compatible transform (i.e. "__esModule" has not been set), then set
40
+ // "default" to the CommonJS "module.exports" for node compatibility.
41
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
42
+ mod
43
+ ));
34
44
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
35
45
  var wallet_exports = {};
36
46
  __export(wallet_exports, {
@@ -41,9 +51,11 @@ __export(wallet_exports, {
41
51
  getWalletTypes: () => getWalletTypes,
42
52
  isPregenIdentifierMatch: () => isPregenIdentifierMatch,
43
53
  isWalletSupported: () => isWalletSupported,
44
- migrateWallet: () => migrateWallet
54
+ migrateWallet: () => migrateWallet,
55
+ newUuid: () => newUuid
45
56
  });
46
57
  module.exports = __toCommonJS(wallet_exports);
58
+ var uuid = __toESM(require("uuid"));
47
59
  var import_user_management_client = require("@getpara/user-management-client");
48
60
  var import_formatting = require("./formatting.js");
49
61
  const WalletSchemeTypeMap = {
@@ -117,6 +129,9 @@ function migrateWallet(obj) {
117
129
  }
118
130
  return obj;
119
131
  }
132
+ function newUuid() {
133
+ return uuid.v4();
134
+ }
120
135
  // Annotate the CommonJS export names for ESM import in node:
121
136
  0 && (module.exports = {
122
137
  WalletSchemeTypeMap,
@@ -126,5 +141,6 @@ function migrateWallet(obj) {
126
141
  getWalletTypes,
127
142
  isPregenIdentifierMatch,
128
143
  isWalletSupported,
129
- migrateWallet
144
+ migrateWallet,
145
+ newUuid
130
146
  });
@@ -3,11 +3,12 @@ import {
3
3
  __objRest,
4
4
  __privateAdd,
5
5
  __privateGet,
6
+ __privateMethod,
6
7
  __privateSet,
7
8
  __spreadProps,
8
9
  __spreadValues
9
- } from "./chunk-UICEQADR.js";
10
- var _supportedWalletTypes, _supportedWalletTypesOpt;
10
+ } from "./chunk-7B52C2XE.js";
11
+ var _supportedWalletTypes, _supportedWalletTypesOpt, _ParaCore_instances, createPregenWallet_fn;
11
12
  import { Buffer as NodeBuffer } from "buffer";
12
13
  if (typeof global !== "undefined") {
13
14
  global.Buffer = global.Buffer || NodeBuffer;
@@ -54,6 +55,7 @@ import {
54
55
  isPregenIdentifierMatch,
55
56
  isWalletSupported,
56
57
  migrateWallet,
58
+ newUuid,
57
59
  normalizePhoneNumber,
58
60
  truncateAddress,
59
61
  WalletSchemeTypeMap
@@ -70,6 +72,7 @@ const _ParaCore = class _ParaCore {
70
72
  * @returns - A new ParaCore instance.
71
73
  */
72
74
  constructor(env, apiKey, opts) {
75
+ __privateAdd(this, _ParaCore_instances);
73
76
  this.isAwaitingAccountCreation = false;
74
77
  this.isAwaitingLogin = false;
75
78
  this.isAwaitingFarcaster = false;
@@ -476,7 +479,7 @@ const _ParaCore = class _ParaCore {
476
479
  var _a, _b;
477
480
  if (this.externalWallets[walletId]) {
478
481
  const wallet2 = this.externalWallets[walletId];
479
- return options.truncate ? truncateAddress(wallet2.address, wallet2.type, { prefix: this.cosmosPrefix }) : wallet2.address;
482
+ return options.truncate ? truncateAddress(wallet2.address, wallet2.type, { prefix: this.cosmosPrefix, targetLength: options.targetLength }) : wallet2.address;
480
483
  }
481
484
  const wallet = this.findWallet(walletId, options.addressType);
482
485
  if (!wallet) {
@@ -494,7 +497,7 @@ const _ParaCore = class _ParaCore {
494
497
  str = wallet.address;
495
498
  break;
496
499
  }
497
- return options.truncate ? truncateAddress(str, wallet.type, { prefix }) : str;
500
+ return options.truncate ? truncateAddress(str, wallet.type, { prefix, targetLength: options.targetLength }) : str;
498
501
  }
499
502
  /**
500
503
  * Returns a unique hash for a wallet suitable for use as an identicon seed.
@@ -1480,10 +1483,16 @@ const _ParaCore = class _ParaCore {
1480
1483
  if (this.isUsingExternalWallet()) {
1481
1484
  return true;
1482
1485
  }
1486
+ if (this.isGuestMode) {
1487
+ return true;
1488
+ }
1483
1489
  const isSessionActive = yield this.isSessionActive();
1484
1490
  return isSessionActive && (this.isNoWalletConfig || this.currentWalletIdsArray.length > 0 && this.currentWalletIdsArray.reduce((acc, [id]) => acc && !!this.wallets[id], true));
1485
1491
  });
1486
1492
  }
1493
+ get isGuestMode() {
1494
+ return !this.userId && this.currentWalletIdsArray.length > 0 && this.currentWalletIdsArray.every(([id]) => !!this.wallets[id] && this.wallets[id].pregenIdentifierType === "GUEST_ID");
1495
+ }
1487
1496
  supportedAuthMethods(auth) {
1488
1497
  return __async(this, null, function* () {
1489
1498
  const { supportedAuthMethods } = yield this.ctx.client.getSupportedAuthMethods(auth);
@@ -2188,51 +2197,7 @@ const _ParaCore = class _ParaCore {
2188
2197
  **/
2189
2198
  createPregenWallet(opts) {
2190
2199
  return __async(this, null, function* () {
2191
- var _a, _b;
2192
- const {
2193
- type: _type = (_a = this.supportedWalletTypes.find(({ optional }) => !optional)) == null ? void 0 : _a.type,
2194
- pregenIdentifier,
2195
- pregenIdentifierType = "EMAIL"
2196
- } = opts;
2197
- this.requireApiKey();
2198
- const walletType = yield this.assertIsValidWalletType(
2199
- _type != null ? _type : (_b = this.supportedWalletTypes.find(({ optional }) => !optional)) == null ? void 0 : _b.type
2200
- );
2201
- let keygenRes;
2202
- switch (walletType) {
2203
- case WalletType.SOLANA:
2204
- keygenRes = yield this.platformUtils.ed25519PreKeygen(
2205
- this.ctx,
2206
- pregenIdentifier,
2207
- pregenIdentifierType,
2208
- this.retrieveSessionCookie()
2209
- );
2210
- break;
2211
- default:
2212
- keygenRes = yield this.platformUtils.preKeygen(
2213
- this.ctx,
2214
- void 0,
2215
- pregenIdentifier,
2216
- pregenIdentifierType,
2217
- walletType,
2218
- null,
2219
- this.retrieveSessionCookie()
2220
- );
2221
- break;
2222
- }
2223
- const { signer, walletId } = keygenRes;
2224
- this.wallets[walletId] = {
2225
- id: walletId,
2226
- signer,
2227
- scheme: walletType === WalletType.SOLANA ? WalletScheme.ED25519 : WalletScheme.DKLS,
2228
- type: walletType,
2229
- isPregen: true,
2230
- pregenIdentifier,
2231
- pregenIdentifierType
2232
- };
2233
- yield this.waitForPregenWalletAddress(walletId);
2234
- yield this.populatePregenWalletAddresses();
2235
- return this.wallets[walletId];
2200
+ return yield __privateMethod(this, _ParaCore_instances, createPregenWallet_fn).call(this, opts);
2236
2201
  });
2237
2202
  }
2238
2203
  /**
@@ -2253,7 +2218,7 @@ const _ParaCore = class _ParaCore {
2253
2218
  }) {
2254
2219
  const wallets = [];
2255
2220
  for (const type of yield this.getTypesToCreate(types)) {
2256
- const wallet = yield this.createPregenWallet({ type, pregenIdentifier, pregenIdentifierType });
2221
+ const wallet = yield __privateMethod(this, _ParaCore_instances, createPregenWallet_fn).call(this, { type, pregenIdentifier, pregenIdentifierType });
2257
2222
  wallets.push(wallet);
2258
2223
  }
2259
2224
  return wallets;
@@ -2402,6 +2367,24 @@ const _ParaCore = class _ParaCore {
2402
2367
  return res.wallets.filter((w) => this.isWalletSupported(entityToWallet(w)));
2403
2368
  });
2404
2369
  }
2370
+ createGuestWallets() {
2371
+ return __async(this, arguments, function* ({ types } = {}) {
2372
+ const wallets = [];
2373
+ const currentWalletIds = {};
2374
+ const guestId = newUuid();
2375
+ for (const type of yield this.getTypesToCreate(
2376
+ types != null ? types : this.supportedWalletTypes.filter(({ optional }) => !optional).map(({ type: type2 }) => type2)
2377
+ )) {
2378
+ const wallet = yield __privateMethod(this, _ParaCore_instances, createPregenWallet_fn).call(this, { type, pregenIdentifier: guestId, pregenIdentifierType: "GUEST_ID" });
2379
+ wallets.push(wallet);
2380
+ getEquivalentTypes(type).filter((t) => __privateGet(this, _supportedWalletTypes).some(({ type: type2, optional }) => t === type2 && !optional)).forEach((eqType) => {
2381
+ currentWalletIds[eqType] = [wallet.id];
2382
+ });
2383
+ }
2384
+ yield this.setCurrentWalletIds(currentWalletIds);
2385
+ return wallets;
2386
+ });
2387
+ }
2405
2388
  encodeWalletBase64(wallet) {
2406
2389
  const walletJson = JSON.stringify(wallet);
2407
2390
  const base64Wallet = Buffer.from(walletJson).toString("base64");
@@ -2919,6 +2902,56 @@ const _ParaCore = class _ParaCore {
2919
2902
  };
2920
2903
  _supportedWalletTypes = new WeakMap();
2921
2904
  _supportedWalletTypesOpt = new WeakMap();
2905
+ _ParaCore_instances = new WeakSet();
2906
+ createPregenWallet_fn = function(opts) {
2907
+ return __async(this, null, function* () {
2908
+ var _a, _b;
2909
+ const {
2910
+ type: _type = (_a = this.supportedWalletTypes.find(({ optional }) => !optional)) == null ? void 0 : _a.type,
2911
+ pregenIdentifier,
2912
+ pregenIdentifierType = "EMAIL"
2913
+ } = opts;
2914
+ this.requireApiKey();
2915
+ const walletType = yield this.assertIsValidWalletType(
2916
+ _type != null ? _type : (_b = this.supportedWalletTypes.find(({ optional }) => !optional)) == null ? void 0 : _b.type
2917
+ );
2918
+ let keygenRes;
2919
+ switch (walletType) {
2920
+ case WalletType.SOLANA:
2921
+ keygenRes = yield this.platformUtils.ed25519PreKeygen(
2922
+ this.ctx,
2923
+ pregenIdentifier,
2924
+ pregenIdentifierType,
2925
+ this.retrieveSessionCookie()
2926
+ );
2927
+ break;
2928
+ default:
2929
+ keygenRes = yield this.platformUtils.preKeygen(
2930
+ this.ctx,
2931
+ void 0,
2932
+ pregenIdentifier,
2933
+ pregenIdentifierType,
2934
+ walletType,
2935
+ null,
2936
+ this.retrieveSessionCookie()
2937
+ );
2938
+ break;
2939
+ }
2940
+ const { signer, walletId } = keygenRes;
2941
+ this.wallets[walletId] = {
2942
+ id: walletId,
2943
+ signer,
2944
+ scheme: walletType === WalletType.SOLANA ? WalletScheme.ED25519 : WalletScheme.DKLS,
2945
+ type: walletType,
2946
+ isPregen: true,
2947
+ pregenIdentifier,
2948
+ pregenIdentifierType
2949
+ };
2950
+ yield this.waitForPregenWalletAddress(walletId);
2951
+ yield this.populatePregenWalletAddresses();
2952
+ return this.wallets[walletId];
2953
+ });
2954
+ };
2922
2955
  _ParaCore.version = constants.PARA_CORE_VERSION;
2923
2956
  let ParaCore = _ParaCore;
2924
2957
  export {
@@ -36,6 +36,7 @@ var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot
36
36
  var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
37
37
  var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
38
38
  var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
39
+ var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "access private method"), method);
39
40
  var __async = (__this, __arguments, generator) => {
40
41
  return new Promise((resolve, reject) => {
41
42
  var fulfilled = (value) => {
@@ -64,5 +65,6 @@ export {
64
65
  __privateGet,
65
66
  __privateAdd,
66
67
  __privateSet,
68
+ __privateMethod,
67
69
  __async
68
70
  };
@@ -1,5 +1,5 @@
1
- import "./chunk-UICEQADR.js";
2
- const PARA_CORE_VERSION = '1.10.0';
1
+ import "./chunk-7B52C2XE.js";
2
+ const PARA_CORE_VERSION = '1.11.0';
3
3
  const PREFIX = "@CAPSULE/";
4
4
  const LOCAL_STORAGE_EMAIL = `${PREFIX}e-mail`;
5
5
  const LOCAL_STORAGE_PHONE = `${PREFIX}phone`;
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  __async
3
- } from "../chunk-UICEQADR.js";
3
+ } from "../chunk-7B52C2XE.js";
4
4
  import base64url from "base64url";
5
5
  import forge from "node-forge";
6
6
  import { getPortalBaseURL } from "../utils/index.js";
@@ -1,4 +1,4 @@
1
- import "./chunk-UICEQADR.js";
1
+ import "./chunk-7B52C2XE.js";
2
2
  class TransactionReviewError extends Error {
3
3
  constructor(transactionReviewUrl) {
4
4
  super("transaction review error");
@@ -1,4 +1,4 @@
1
- import "../chunk-UICEQADR.js";
1
+ import "../chunk-7B52C2XE.js";
2
2
  import axios from "axios";
3
3
  function initClient(baseURL, useAdapter) {
4
4
  const client = axios.create({ baseURL });
@@ -1,4 +1,4 @@
1
- import "../chunk-UICEQADR.js";
1
+ import "../chunk-7B52C2XE.js";
2
2
  import Client from "@getpara/user-management-client";
3
3
  import { Environment } from "../types/index.js";
4
4
  function getBaseOAuthUrl(env) {
package/dist/esm/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import "./chunk-UICEQADR.js";
1
+ import "./chunk-7B52C2XE.js";
2
2
  import { ParaCore } from "./ParaCore.js";
3
3
  import {
4
4
  AuthMethod,
@@ -1,4 +1,4 @@
1
- import "../chunk-UICEQADR.js";
1
+ import "../chunk-7B52C2XE.js";
2
2
  import { Encrypt as ECIESEncrypt, Decrypt as ECIESDecrypt } from "@celo/utils/lib/ecies.js";
3
3
  import * as eutil from "@ethereumjs/util";
4
4
  import * as forge from "node-forge";
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  __async,
3
3
  __spreadValues
4
- } from "../chunk-UICEQADR.js";
4
+ } from "../chunk-7B52C2XE.js";
5
5
  import { EncryptorType, KeyShareType } from "@getpara/user-management-client";
6
6
  import { KeyContainer } from "./KeyContainer.js";
7
7
  function sendRecoveryForShare(_0) {
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  __async
3
- } from "../chunk-UICEQADR.js";
3
+ } from "../chunk-7B52C2XE.js";
4
4
  import { EncryptorType, KeyShareType } from "@getpara/user-management-client";
5
5
  import { encryptWithDerivedPublicKey } from "../cryptography/utils.js";
6
6
  import { sendRecoveryForShare } from "./recovery.js";
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  __async
3
- } from "../chunk-UICEQADR.js";
3
+ } from "../chunk-7B52C2XE.js";
4
4
  import { Encrypt as ECIESEncrypt, Decrypt as ECIESDecrypt } from "@celo/utils/lib/ecies.js";
5
5
  import { Buffer } from "buffer";
6
6
  import * as eutil from "@ethereumjs/util";
@@ -1,4 +1,4 @@
1
- import "../chunk-UICEQADR.js";
1
+ import "../chunk-7B52C2XE.js";
2
2
  var Environment = /* @__PURE__ */ ((Environment2) => {
3
3
  Environment2["DEV"] = "DEV";
4
4
  Environment2["SANDBOX"] = "SANDBOX";
@@ -1,4 +1,4 @@
1
- import "../chunk-UICEQADR.js";
1
+ import "../chunk-7B52C2XE.js";
2
2
  const EVENT_PREFIX = "para";
3
3
  var ParaEvent = ((ParaEvent2) => {
4
4
  ParaEvent2["LOGIN_EVENT"] = `${EVENT_PREFIX}Login`;
@@ -1,4 +1,4 @@
1
- import "../chunk-UICEQADR.js";
1
+ import "../chunk-7B52C2XE.js";
2
2
  export * from "./config.js";
3
3
  export * from "./wallet.js";
4
4
  export * from "./params.js";
@@ -1,4 +1,4 @@
1
- import "../chunk-UICEQADR.js";
1
+ import "../chunk-7B52C2XE.js";
2
2
  var OnRampMethod = /* @__PURE__ */ ((OnRampMethod2) => {
3
3
  OnRampMethod2["ACH"] = "ACH";
4
4
  OnRampMethod2["DEBIT"] = "Debit";
@@ -1,4 +1,4 @@
1
- import "../chunk-UICEQADR.js";
1
+ import "../chunk-7B52C2XE.js";
2
2
  var PopupType = /* @__PURE__ */ ((PopupType2) => {
3
3
  PopupType2["SIGN_TRANSACTION_REVIEW"] = "SIGN_TRANSACTION_REVIEW";
4
4
  PopupType2["SIGN_MESSAGE_REVIEW"] = "SIGN_MESSAGE_REVIEW";
@@ -1,4 +1,4 @@
1
- import "../chunk-UICEQADR.js";
1
+ import "../chunk-7B52C2XE.js";
2
2
  var RecoveryStatus = /* @__PURE__ */ ((RecoveryStatus2) => {
3
3
  RecoveryStatus2["INITIATED"] = "INITIATED";
4
4
  RecoveryStatus2["READY"] = "READY";
@@ -1,4 +1,4 @@
1
- import "../chunk-UICEQADR.js";
1
+ import "../chunk-7B52C2XE.js";
2
2
  var PregenIdentifierType = /* @__PURE__ */ ((PregenIdentifierType2) => {
3
3
  PregenIdentifierType2["EMAIL"] = "EMAIL";
4
4
  PregenIdentifierType2["PHONE"] = "PHONE";
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  __spreadValues
3
- } from "../chunk-UICEQADR.js";
3
+ } from "../chunk-7B52C2XE.js";
4
4
  function dispatchEvent(type, data, error) {
5
5
  typeof window !== "undefined" && !!window.dispatchEvent && window.dispatchEvent(
6
6
  new CustomEvent(type, { detail: __spreadValues({ data }, error && { error: new Error(error) }) })
@@ -1,4 +1,4 @@
1
- import "../chunk-UICEQADR.js";
1
+ import "../chunk-7B52C2XE.js";
2
2
  import { toBech32 } from "@cosmjs/encoding";
3
3
  import { sha256 } from "@noble/hashes/sha256";
4
4
  import { ripemd160 } from "@noble/hashes/ripemd160";
@@ -56,9 +56,13 @@ function getCosmosAddress(publicKey, prefix) {
56
56
  const compressedPublicKey = compressPubkey(uncompressedPublicKey);
57
57
  return toBech32(prefix, rawSecp256k1PubkeyToRawAddress(compressedPublicKey));
58
58
  }
59
- function truncateAddress(str, addressType, { prefix = addressType === "COSMOS" ? "cosmos" : void 0 } = {}) {
60
- const headLength = (addressType === "COSMOS" ? prefix.length : addressType === "SOLANA" ? 0 : 2) + 4;
61
- return `${str.slice(0, headLength)}...${str.slice(-4)}`;
59
+ function truncateAddress(str, addressType, {
60
+ prefix = addressType === "COSMOS" ? "cosmos" : void 0,
61
+ targetLength
62
+ } = {}) {
63
+ const minimum = addressType === "COSMOS" ? prefix.length : addressType === "EVM" ? 2 : 0;
64
+ const margin = targetLength !== void 0 ? (targetLength - minimum) / 2 : 4;
65
+ return `${str.slice(0, minimum + margin)}...${str.slice(-1 * margin)}`;
62
66
  }
63
67
  function stringToPhoneNumber(str) {
64
68
  var _a;
@@ -1,4 +1,4 @@
1
- import "../chunk-UICEQADR.js";
1
+ import "../chunk-7B52C2XE.js";
2
2
  import * as constants from "../constants.js";
3
3
  function storageListener(e) {
4
4
  if (!e.url.includes(window.location.origin)) {
@@ -1,4 +1,4 @@
1
- import "../chunk-UICEQADR.js";
1
+ import "../chunk-7B52C2XE.js";
2
2
  import { Network } from "@getpara/user-management-client";
3
3
  function toAssetInfoArray(data) {
4
4
  const result = [];
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  __async
3
- } from "../chunk-UICEQADR.js";
3
+ } from "../chunk-7B52C2XE.js";
4
4
  function waitUntilTrue(condition, timeoutMs, intervalMs) {
5
5
  return __async(this, null, function* () {
6
6
  const start = Date.now();
@@ -1,4 +1,4 @@
1
- import "../chunk-UICEQADR.js";
1
+ import "../chunk-7B52C2XE.js";
2
2
  import { Environment } from "../types/index.js";
3
3
  function getPortalDomain(env, isE2E) {
4
4
  if (isE2E) {
@@ -1,7 +1,8 @@
1
1
  import {
2
2
  __spreadProps,
3
3
  __spreadValues
4
- } from "../chunk-UICEQADR.js";
4
+ } from "../chunk-7B52C2XE.js";
5
+ import * as uuid from "uuid";
5
6
  import { WalletScheme, WalletType } from "@getpara/user-management-client";
6
7
  import { stringToPhoneNumber } from "./formatting.js";
7
8
  const WalletSchemeTypeMap = {
@@ -75,6 +76,9 @@ function migrateWallet(obj) {
75
76
  }
76
77
  return obj;
77
78
  }
79
+ function newUuid() {
80
+ return uuid.v4();
81
+ }
78
82
  export {
79
83
  WalletSchemeTypeMap,
80
84
  entityToWallet,
@@ -83,5 +87,6 @@ export {
83
87
  getWalletTypes,
84
88
  isPregenIdentifierMatch,
85
89
  isWalletSupported,
86
- migrateWallet
90
+ migrateWallet,
91
+ newUuid
87
92
  };
@@ -1,6 +1,6 @@
1
1
  import Client, { AuthMethod, BackupKitEmailProps, CurrentWalletIds, EmailTheme, WalletEntity, WalletType, WalletParams, OAuthMethod, OnRampPurchaseCreateParams, OnRampPurchase, TPregenIdentifierType, PregenIds, BiometricLocationHint, TelegramAuthResponse, VerifyTelegramRes, Auth, ExternalWalletLoginRes, AccountMetadata } from '@getpara/user-management-client';
2
2
  import type { pki as pkiType } from 'node-forge';
3
- import { Ctx, Environment, Theme, FullSignatureRes, ExternalWalletInfo, GetWebAuthUrlForLoginParams, AccountSetupResponse, LoginResponse, WalletFilters, WalletTypeProp, Wallet, SupportedWalletTypes, PortalUrlOptions, ConstructorOpts, RecoveryStatus, GetWalletBalanceParams } from './types/index.js';
3
+ import { Ctx, Environment, Theme, FullSignatureRes, ExternalWalletInfo, GetWebAuthUrlForLoginParams, AccountSetupResponse, LoginResponse, WalletFilters, WalletTypeProp, Wallet, SupportedWalletTypes, PortalUrlOptions, ConstructorOpts, RecoveryStatus, GetWalletBalanceParams, CreateGuestWalletsParams } from './types/index.js';
4
4
  import { PlatformUtils } from './PlatformUtils.js';
5
5
  import { CountryCallingCode } from 'libphonenumber-js';
6
6
  export declare abstract class ParaCore {
@@ -151,6 +151,7 @@ export declare abstract class ParaCore {
151
151
  truncate?: boolean;
152
152
  addressType?: WalletTypeProp | undefined;
153
153
  cosmosPrefix?: string;
154
+ targetLength?: number;
154
155
  } | undefined): string;
155
156
  /**
156
157
  * Returns a unique hash for a wallet suitable for use as an identicon seed.
@@ -527,6 +528,7 @@ export declare abstract class ParaCore {
527
528
  * @returns `true` if active, `false` otherwise
528
529
  **/
529
530
  isFullyLoggedIn(): Promise<boolean>;
531
+ get isGuestMode(): boolean;
530
532
  protected supportedAuthMethods(auth: Auth): Promise<Set<AuthMethod>>;
531
533
  /**
532
534
  * Get hints associated with the users stored biometrics.
@@ -774,7 +776,7 @@ export declare abstract class ParaCore {
774
776
  createPregenWallet(opts: {
775
777
  type: WalletType;
776
778
  pregenIdentifier: string;
777
- pregenIdentifierType: TPregenIdentifierType;
779
+ pregenIdentifierType: Exclude<TPregenIdentifierType, 'GUEST_ID'>;
778
780
  }): Promise<Wallet>;
779
781
  /**
780
782
  * Creates new pregenerated wallets for each desired type.
@@ -788,7 +790,7 @@ export declare abstract class ParaCore {
788
790
  **/
789
791
  createPregenWalletPerType({ types, pregenIdentifier, pregenIdentifierType, }: {
790
792
  pregenIdentifier: string;
791
- pregenIdentifierType: TPregenIdentifierType;
793
+ pregenIdentifierType: Exclude<TPregenIdentifierType, 'GUEST_ID'>;
792
794
  types?: WalletType[];
793
795
  }): Promise<Wallet[]>;
794
796
  /**
@@ -837,6 +839,7 @@ export declare abstract class ParaCore {
837
839
  pregenIdentifier?: string;
838
840
  pregenIdentifierType?: TPregenIdentifierType;
839
841
  }): Promise<WalletEntity[]>;
842
+ createGuestWallets({ types }?: CreateGuestWalletsParams): Promise<Wallet[]>;
840
843
  private encodeWalletBase64;
841
844
  /**
842
845
  * Encodes the current wallets encoded in Base 64.
@@ -1,6 +1,6 @@
1
1
  import { ParaCore } from './ParaCore.js';
2
2
  export { AuthMethod, type CurrentWalletIds, EmailTheme, type PartnerEntity, type WalletEntity, Network, WalletType, WalletScheme, OnRampAsset, OnRampPurchaseType, OnRampProvider, OnRampPurchaseStatus, type OnRampConfig, type OnRampAllowedAssets, type OnRampPurchase, OAuthMethod, type TPregenIdentifierType, type PregenIds, NON_ED25519, PREGEN_IDENTIFIER_TYPES, } from '@getpara/user-management-client';
3
- export { OnRampMethod, PopupType, PregenIdentifierType, RecoveryStatus, type ProviderAssetInfo, type SignatureRes, type FullSignatureRes, type SuccessfulSignatureRes, type DeniedSignatureRes, type DeniedSignatureResWithUrl, type OnRampAssetInfo, type Theme, type Wallet, type GetWalletBalanceParams, } from './types/index.js';
3
+ export { OnRampMethod, PopupType, PregenIdentifierType, RecoveryStatus, type ProviderAssetInfo, type SignatureRes, type FullSignatureRes, type SuccessfulSignatureRes, type DeniedSignatureRes, type DeniedSignatureResWithUrl, type OnRampAssetInfo, type Theme, type Wallet, type GetWalletBalanceParams, type CreateGuestWalletsParams, } from './types/index.js';
4
4
  export * from './types/events.js';
5
5
  export * from './types/config.js';
6
6
  export { getPortalDomain, stringToPhoneNumber, entityToWallet } from './utils/index.js';
@@ -68,3 +68,6 @@ export type GetWalletBalanceParams = {
68
68
  walletId: string;
69
69
  rpcUrl?: string;
70
70
  };
71
+ export type CreateGuestWalletsParams = {
72
+ types?: WalletType[];
73
+ };
@@ -11,8 +11,9 @@ export declare function hexToUint8Array(hex: string): Uint8Array;
11
11
  export declare function hexToDecimal(hex: string): string;
12
12
  export declare function decimalToHex(decimal: string): Hex;
13
13
  export declare function getCosmosAddress(publicKey: string, prefix: string): string;
14
- export declare function truncateAddress(str: string, addressType: WalletTypeProp, { prefix }?: {
14
+ export declare function truncateAddress(str: string, addressType: WalletTypeProp, { prefix, targetLength, }?: {
15
15
  prefix?: string;
16
+ targetLength?: number;
16
17
  }): string;
17
18
  export declare function stringToPhoneNumber(str: string): string;
18
19
  export declare function normalizePhoneNumber(countryCode: string, number: string): string | undefined;
@@ -8,3 +8,4 @@ export declare function getWalletTypes(schemes: WalletScheme[]): WalletType[];
8
8
  export declare function getEquivalentTypes(types: WalletTypeProp[] | WalletTypeProp): WalletType[];
9
9
  export declare function entityToWallet(w: WalletEntity): Omit<Wallet, 'signer'>;
10
10
  export declare function migrateWallet(obj: Record<string, unknown>): Wallet;
11
+ export declare function newUuid(): string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@getpara/core-sdk",
3
- "version": "1.10.0",
3
+ "version": "1.11.0",
4
4
  "main": "dist/cjs/index.js",
5
5
  "module": "dist/esm/index.js",
6
6
  "types": "dist/types/index.d.ts",
@@ -10,7 +10,7 @@
10
10
  "@celo/utils": "^8.0.2",
11
11
  "@cosmjs/encoding": "^0.32.4",
12
12
  "@ethereumjs/util": "^9.1.0",
13
- "@getpara/user-management-client": "1.10.0",
13
+ "@getpara/user-management-client": "1.11.0",
14
14
  "@noble/hashes": "^1.5.0",
15
15
  "base64url": "^3.0.1",
16
16
  "libphonenumber-js": "1.11.2",
@@ -40,5 +40,5 @@
40
40
  "require": "./dist/cjs/index.js"
41
41
  }
42
42
  },
43
- "gitHead": "617cf0aa1307a96ec5e91d39e306e8a0b3b86b82"
43
+ "gitHead": "91b68e4ead22e2104307c934f2a582245b176619"
44
44
  }