@getpara/core-sdk 1.12.0 → 2.0.0-alpha.5

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 (55) hide show
  1. package/dist/cjs/ParaCore.js +936 -974
  2. package/dist/cjs/constants.js +7 -1
  3. package/dist/cjs/index.js +15 -9
  4. package/dist/cjs/types/coreApi.js +74 -0
  5. package/dist/cjs/types/events.js +1 -0
  6. package/dist/cjs/types/index.js +4 -2
  7. package/dist/cjs/types/{params.js → methods.js} +2 -2
  8. package/dist/cjs/utils/autobind.js +41 -0
  9. package/dist/cjs/utils/formatting.js +0 -12
  10. package/dist/cjs/utils/index.js +10 -0
  11. package/dist/cjs/utils/json.js +37 -0
  12. package/dist/cjs/utils/listeners.js +2 -11
  13. package/dist/cjs/utils/phone.js +61 -0
  14. package/dist/cjs/utils/types.js +29 -0
  15. package/dist/cjs/utils/url.js +34 -2
  16. package/dist/cjs/utils/wallet.js +30 -17
  17. package/dist/esm/ParaCore.js +952 -979
  18. package/dist/esm/constants.js +5 -1
  19. package/dist/esm/index.js +12 -9
  20. package/dist/esm/types/coreApi.js +52 -0
  21. package/dist/esm/types/events.js +1 -0
  22. package/dist/esm/types/index.js +2 -1
  23. package/dist/esm/utils/autobind.js +19 -0
  24. package/dist/esm/utils/formatting.js +0 -10
  25. package/dist/esm/utils/index.js +5 -0
  26. package/dist/esm/utils/json.js +15 -0
  27. package/dist/esm/utils/listeners.js +2 -11
  28. package/dist/esm/utils/phone.js +28 -0
  29. package/dist/esm/utils/types.js +7 -0
  30. package/dist/esm/utils/url.js +15 -2
  31. package/dist/esm/utils/wallet.js +27 -16
  32. package/dist/types/ParaCore.d.ts +100 -391
  33. package/dist/types/PlatformUtils.d.ts +3 -3
  34. package/dist/types/constants.d.ts +2 -0
  35. package/dist/types/external/userManagementClient.d.ts +1 -1
  36. package/dist/types/index.d.ts +5 -3
  37. package/dist/types/types/config.d.ts +4 -24
  38. package/dist/types/types/coreApi.d.ts +475 -0
  39. package/dist/types/types/events.d.ts +4 -1
  40. package/dist/types/types/index.d.ts +2 -1
  41. package/dist/types/types/methods.d.ts +148 -0
  42. package/dist/types/types/onRamps.d.ts +3 -3
  43. package/dist/types/types/wallet.d.ts +4 -4
  44. package/dist/types/utils/autobind.d.ts +1 -0
  45. package/dist/types/utils/formatting.d.ts +2 -4
  46. package/dist/types/utils/index.d.ts +5 -0
  47. package/dist/types/utils/json.d.ts +1 -0
  48. package/dist/types/utils/onRamps.d.ts +3 -3
  49. package/dist/types/utils/phone.d.ts +7 -0
  50. package/dist/types/utils/types.d.ts +2 -0
  51. package/dist/types/utils/url.d.ts +2 -1
  52. package/dist/types/utils/wallet.d.ts +9 -7
  53. package/package.json +4 -3
  54. package/dist/types/types/params.d.ts +0 -73
  55. /package/dist/esm/types/{params.js → methods.js} +0 -0
@@ -1,6 +1,7 @@
1
1
  import "./chunk-7B52C2XE.js";
2
- const PARA_CORE_VERSION = "1.12.0";
2
+ const PARA_CORE_VERSION = "2.0.0-alpha.3";
3
3
  const PREFIX = "@CAPSULE/";
4
+ const LOCAL_STORAGE_AUTH_INFO = `${PREFIX}authInfo`;
4
5
  const LOCAL_STORAGE_EMAIL = `${PREFIX}e-mail`;
5
6
  const LOCAL_STORAGE_PHONE = `${PREFIX}phone`;
6
7
  const LOCAL_STORAGE_COUNTRY_CODE = `${PREFIX}countryCode`;
@@ -16,9 +17,11 @@ const LOCAL_STORAGE_SESSION_COOKIE = `${PREFIX}sessionCookie`;
16
17
  const SESSION_STORAGE_LOGIN_ENCRYPTION_KEY_PAIR = `${PREFIX}loginEncryptionKeyPair`;
17
18
  const POLLING_INTERVAL_MS = 2e3;
18
19
  const SHORT_POLLING_INTERVAL_MS = 1e3;
20
+ const POLLING_TIMEOUT_MS = 3e5;
19
21
  const EXTERNAL_WALLET_CONNECTION_ONLY_USER_ID = "EXTERNAL_WALLET_CONNECTION_ONLY";
20
22
  export {
21
23
  EXTERNAL_WALLET_CONNECTION_ONLY_USER_ID,
24
+ LOCAL_STORAGE_AUTH_INFO,
22
25
  LOCAL_STORAGE_COUNTRY_CODE,
23
26
  LOCAL_STORAGE_CURRENT_WALLET_IDS,
24
27
  LOCAL_STORAGE_ED25519_WALLETS,
@@ -33,6 +36,7 @@ export {
33
36
  LOCAL_STORAGE_WALLETS,
34
37
  PARA_CORE_VERSION,
35
38
  POLLING_INTERVAL_MS,
39
+ POLLING_TIMEOUT_MS,
36
40
  PREFIX,
37
41
  SESSION_STORAGE_LOGIN_ENCRYPTION_KEY_PAIR,
38
42
  SHORT_POLLING_INTERVAL_MS
package/dist/esm/index.js CHANGED
@@ -4,15 +4,15 @@ import {
4
4
  AuthMethod,
5
5
  EmailTheme,
6
6
  Network,
7
- WalletType,
8
- WalletScheme,
9
7
  OnRampAsset,
10
8
  OnRampPurchaseType,
11
9
  OnRampProvider,
12
10
  OnRampPurchaseStatus,
13
- OAuthMethod,
14
11
  NON_ED25519,
15
- PREGEN_IDENTIFIER_TYPES
12
+ PREGEN_IDENTIFIER_TYPES,
13
+ WALLET_TYPES,
14
+ WALLET_SCHEMES,
15
+ OAUTH_METHODS
16
16
  } from "@getpara/user-management-client";
17
17
  import {
18
18
  OnRampMethod,
@@ -20,9 +20,10 @@ import {
20
20
  PregenIdentifierType,
21
21
  RecoveryStatus
22
22
  } from "./types/index.js";
23
+ export * from "./types/coreApi.js";
23
24
  export * from "./types/events.js";
24
25
  export * from "./types/config.js";
25
- import { getPortalDomain, stringToPhoneNumber, entityToWallet } from "./utils/index.js";
26
+ import { getPortalDomain, entityToWallet, constructUrl, shortenUrl } from "./utils/index.js";
26
27
  import { PREFIX } from "./constants.js";
27
28
  import { distributeNewShare } from "./shares/shareDistribution.js";
28
29
  import { KeyContainer } from "./shares/KeyContainer.js";
@@ -50,6 +51,7 @@ export * from "./external/userManagementClient.js";
50
51
  export * from "./errors.js";
51
52
  export * from "./utils/formatting.js";
52
53
  export * from "./utils/polling.js";
54
+ export * from "./utils/phone.js";
53
55
  import { isWalletSupported } from "./utils/wallet.js";
54
56
  import { getNetworkPrefix, getOnRampAssets, getOnRampNetworks, toAssetInfoArray } from "./utils/onRamps.js";
55
57
  import { getPortalBaseURL } from "./utils/url.js";
@@ -62,7 +64,7 @@ export {
62
64
  KeyContainer,
63
65
  NON_ED25519,
64
66
  Network,
65
- OAuthMethod,
67
+ OAUTH_METHODS,
66
68
  OnRampAsset,
67
69
  OnRampMethod,
68
70
  OnRampProvider,
@@ -73,8 +75,9 @@ export {
73
75
  PregenIdentifierType,
74
76
  RecoveryStatus,
75
77
  PREFIX as STORAGE_PREFIX,
76
- WalletScheme,
77
- WalletType,
78
+ WALLET_SCHEMES,
79
+ WALLET_TYPES,
80
+ constructUrl,
78
81
  decryptPrivateKey,
79
82
  decryptPrivateKeyAndDecryptShare,
80
83
  decryptPrivateKeyWithPassword,
@@ -104,7 +107,7 @@ export {
104
107
  mpcComputationClient,
105
108
  paraVersion,
106
109
  publicKeyFromHex,
107
- stringToPhoneNumber,
110
+ shortenUrl,
108
111
  toAssetInfoArray,
109
112
  retrieve as transmissionUtilsRetrieve
110
113
  };
@@ -0,0 +1,52 @@
1
+ import "../chunk-7B52C2XE.js";
2
+ const PARA_CORE_METHODS = [
3
+ "getAuthInfo",
4
+ "signUpOrLogIn",
5
+ "verifyNewAccount",
6
+ "waitForLogin",
7
+ "waitForSignup",
8
+ "waitForWalletCreation",
9
+ "getOAuthUrl",
10
+ "verifyOAuth",
11
+ "getFarcasterConnectUri",
12
+ "verifyFarcaster",
13
+ "verifyTelegram",
14
+ "resendVerificationCode",
15
+ "loginExternalWallet",
16
+ "verifyExternalWallet",
17
+ "setup2fa",
18
+ "enable2fa",
19
+ "verify2fa",
20
+ "logout",
21
+ "clearStorage",
22
+ "isSessionActive",
23
+ "isFullyLoggedIn",
24
+ "refreshSession",
25
+ "keepSessionAlive",
26
+ "exportSession",
27
+ "importSession",
28
+ "getVerificationToken",
29
+ "getWallets",
30
+ "getWalletsByType",
31
+ "fetchWallets",
32
+ "createWallet",
33
+ "createWalletPerType",
34
+ "getPregenWallets",
35
+ "hasPregenWallet",
36
+ "updatePregenWalletIdentifier",
37
+ "createPregenWallet",
38
+ "createPregenWalletPerType",
39
+ "claimPregenWallets",
40
+ "createGuestWallets",
41
+ "distributeNewWalletShare",
42
+ "getUserShare",
43
+ "setUserShare",
44
+ "refreshShare",
45
+ "signMessage",
46
+ "signTransaction",
47
+ "initiateOnRampTransaction",
48
+ "getWalletBalance"
49
+ ];
50
+ export {
51
+ PARA_CORE_METHODS
52
+ };
@@ -11,6 +11,7 @@ var ParaEvent = ((ParaEvent2) => {
11
11
  ParaEvent2["WALLETS_CHANGE_EVENT"] = `${EVENT_PREFIX}WalletsChange`;
12
12
  ParaEvent2["WALLET_CREATED"] = `${EVENT_PREFIX}WalletCreated`;
13
13
  ParaEvent2["PREGEN_WALLET_CLAIMED"] = `${EVENT_PREFIX}PregenWalletClaimed`;
14
+ ParaEvent2["GUEST_WALLETS_CREATED"] = `${EVENT_PREFIX}GuestWalletsCreated`;
14
15
  return ParaEvent2;
15
16
  })(ParaEvent || {});
16
17
  export {
@@ -1,7 +1,8 @@
1
1
  import "../chunk-7B52C2XE.js";
2
2
  export * from "./config.js";
3
+ export * from "./coreApi.js";
3
4
  export * from "./wallet.js";
4
- export * from "./params.js";
5
+ export * from "./methods.js";
5
6
  export * from "./theme.js";
6
7
  export * from "./onRamps.js";
7
8
  export * from "./popup.js";
@@ -0,0 +1,19 @@
1
+ import "../chunk-7B52C2XE.js";
2
+ function autoBind(instance) {
3
+ let proto = instance;
4
+ while (proto && proto !== Object.prototype) {
5
+ for (const key of Object.getOwnPropertyNames(proto)) {
6
+ const value = instance[key];
7
+ if (typeof value === "function" && key !== "constructor") {
8
+ try {
9
+ instance[key] = value.bind(instance);
10
+ } catch (e) {
11
+ }
12
+ }
13
+ }
14
+ proto = Object.getPrototypeOf(proto);
15
+ }
16
+ }
17
+ export {
18
+ autoBind
19
+ };
@@ -3,7 +3,6 @@ import { toBech32 } from "@cosmjs/encoding";
3
3
  import { sha256 } from "@noble/hashes/sha256";
4
4
  import { ripemd160 } from "@noble/hashes/ripemd160";
5
5
  import elliptic from "elliptic";
6
- import parsePhoneNumberFromString from "libphonenumber-js";
7
6
  const secp256k1 = new elliptic.ec("secp256k1");
8
7
  function hexStringToBase64(hexString) {
9
8
  if (hexString.substring(0, 2) === "0x") {
@@ -64,13 +63,6 @@ function truncateAddress(str, addressType, {
64
63
  const margin = targetLength !== void 0 ? (targetLength - minimum) / 2 : 4;
65
64
  return `${str.slice(0, minimum + margin)}...${str.slice(-1 * margin)}`;
66
65
  }
67
- function stringToPhoneNumber(str) {
68
- var _a;
69
- return (_a = parsePhoneNumberFromString(str)) == null ? void 0 : _a.formatInternational().replace(/[^\d+]/g, "");
70
- }
71
- function normalizePhoneNumber(countryCode, number) {
72
- return stringToPhoneNumber(`${countryCode[0] !== "+" ? "+" : ""}${countryCode}${number}`);
73
- }
74
66
  export {
75
67
  decimalToHex,
76
68
  getCosmosAddress,
@@ -78,7 +70,5 @@ export {
78
70
  hexToDecimal,
79
71
  hexToSignature,
80
72
  hexToUint8Array,
81
- normalizePhoneNumber,
82
- stringToPhoneNumber,
83
73
  truncateAddress
84
74
  };
@@ -1,6 +1,11 @@
1
+ export * from "./autobind.js";
1
2
  export * from "./events.js";
2
3
  export * from "./formatting.js";
4
+ export * from "./json.js";
5
+ export * from "./listeners.js";
3
6
  export * from "./onRamps.js";
7
+ export * from "./phone.js";
4
8
  export * from "./polling.js";
9
+ export * from "./types.js";
5
10
  export * from "./url.js";
6
11
  export * from "./wallet.js";
@@ -0,0 +1,15 @@
1
+ import "../chunk-7B52C2XE.js";
2
+ function jsonParse(data, validate) {
3
+ try {
4
+ const res = JSON.parse(data);
5
+ if (validate && !validate(res)) {
6
+ return void 0;
7
+ }
8
+ return res;
9
+ } catch (e) {
10
+ return void 0;
11
+ }
12
+ }
13
+ export {
14
+ jsonParse
15
+ };
@@ -19,21 +19,12 @@ function storageListener(e) {
19
19
  if (e.key === constants.LOCAL_STORAGE_WALLETS || e.key === constants.LOCAL_STORAGE_ED25519_WALLETS) {
20
20
  this.updateWalletsFromStorage();
21
21
  }
22
- if (e.key === constants.LOCAL_STORAGE_EMAIL) {
23
- this.updateEmailFromStorage();
24
- }
25
- if (e.key === constants.LOCAL_STORAGE_COUNTRY_CODE) {
26
- this.updateCountryCodeFromStorage();
27
- }
28
- if (e.key === constants.LOCAL_STORAGE_PHONE) {
29
- this.updatePhoneFromStorage();
22
+ if (e.key === constants.LOCAL_STORAGE_AUTH_INFO) {
23
+ this.updateAuthInfoFromStorage();
30
24
  }
31
25
  if (e.key === constants.LOCAL_STORAGE_USER_ID) {
32
26
  this.updateUserIdFromStorage();
33
27
  }
34
- if (e.key === constants.LOCAL_STORAGE_TELEGRAM_USER_ID) {
35
- this.updateTelegramUserIdFromStorage();
36
- }
37
28
  }
38
29
  function setupListeners() {
39
30
  if (typeof window !== "undefined" && window.addEventListener && window.location) {
@@ -0,0 +1,28 @@
1
+ import "../chunk-7B52C2XE.js";
2
+ import parsePhoneNumberFromString from "libphonenumber-js";
3
+ function formatPhoneNumber(phone, countryCode, { forDisplay = false } = {}) {
4
+ phone = phone.toString();
5
+ countryCode = countryCode == null ? void 0 : countryCode.toString();
6
+ let sanitizedNumber, parsedNumber;
7
+ if (!!countryCode) {
8
+ sanitizedNumber = phone.replace(/\D/g, "");
9
+ if (/^\+\d+$/.test(countryCode)) {
10
+ countryCode = countryCode.slice(1);
11
+ }
12
+ parsedNumber = parsePhoneNumberFromString(sanitizedNumber, { defaultCallingCode: countryCode });
13
+ } else {
14
+ sanitizedNumber = `+${phone.replace(/\D/g, "")}`;
15
+ parsedNumber = parsePhoneNumberFromString(sanitizedNumber);
16
+ }
17
+ if (parsedNumber == null ? void 0 : parsedNumber.isValid()) {
18
+ return forDisplay ? parsedNumber.formatInternational() : parsedNumber.formatInternational().replace(/[^\d+]/g, "");
19
+ }
20
+ return null;
21
+ }
22
+ function displayPhoneNumber(phone, countryCode) {
23
+ return formatPhoneNumber(phone, countryCode, { forDisplay: true });
24
+ }
25
+ export {
26
+ displayPhoneNumber,
27
+ formatPhoneNumber
28
+ };
@@ -0,0 +1,7 @@
1
+ import "../chunk-7B52C2XE.js";
2
+ function isServerAuthState(obj) {
3
+ return "stage" in obj;
4
+ }
5
+ export {
6
+ isServerAuthState
7
+ };
@@ -1,4 +1,7 @@
1
- import "../chunk-7B52C2XE.js";
1
+ import {
2
+ __async
3
+ } from "../chunk-7B52C2XE.js";
4
+ import { upload } from "../transmission/transmissionUtils.js";
2
5
  import { Environment } from "../types/index.js";
3
6
  function getPortalDomain(env, isE2E) {
4
7
  if (isE2E) {
@@ -68,10 +71,20 @@ function constructUrl({
68
71
  });
69
72
  return url.toString();
70
73
  }
74
+ function shortenUrl(ctx, url) {
75
+ return __async(this, null, function* () {
76
+ const compressedUrl = yield upload(url, ctx.client);
77
+ return constructUrl({
78
+ base: getPortalBaseURL(ctx),
79
+ path: `/short/${compressedUrl}`
80
+ });
81
+ });
82
+ }
71
83
  export {
72
84
  constructUrl,
73
85
  getParaConnectBaseUrl,
74
86
  getParaConnectDomain,
75
87
  getPortalBaseURL,
76
- getPortalDomain
88
+ getPortalDomain,
89
+ shortenUrl
77
90
  };
@@ -3,19 +3,18 @@ import {
3
3
  __spreadValues
4
4
  } from "../chunk-7B52C2XE.js";
5
5
  import * as uuid from "uuid";
6
- import { WalletScheme, WalletType } from "@getpara/user-management-client";
7
- import { stringToPhoneNumber } from "./formatting.js";
6
+ import { formatPhoneNumber } from "./phone.js";
8
7
  const WalletSchemeTypeMap = {
9
- [WalletScheme.DKLS]: {
10
- [WalletType.EVM]: true,
11
- [WalletType.COSMOS]: true
8
+ DKLS: {
9
+ EVM: true,
10
+ COSMOS: true
12
11
  },
13
- [WalletScheme.CGGMP]: {
14
- [WalletType.EVM]: true,
15
- [WalletType.COSMOS]: true
12
+ CGGMP: {
13
+ EVM: true,
14
+ COSMOS: true
16
15
  },
17
- [WalletScheme.ED25519]: {
18
- [WalletType.SOLANA]: true
16
+ ED25519: {
17
+ SOLANA: true
19
18
  }
20
19
  };
21
20
  function isPregenIdentifierMatch(a, b, type) {
@@ -26,7 +25,7 @@ function isPregenIdentifierMatch(a, b, type) {
26
25
  case "EMAIL":
27
26
  return a.toLowerCase() === b.toLowerCase();
28
27
  case "PHONE":
29
- return stringToPhoneNumber(a) === stringToPhoneNumber(b);
28
+ return formatPhoneNumber(a) === formatPhoneNumber(b);
30
29
  case "CUSTOM_ID":
31
30
  return a === b;
32
31
  default:
@@ -41,7 +40,7 @@ function isWalletSupported(types, wallet) {
41
40
  }
42
41
  function getSchemes(types) {
43
42
  return Object.keys(WalletSchemeTypeMap).filter((scheme) => {
44
- if (scheme === WalletScheme.CGGMP) {
43
+ if (scheme === "CGGMP") {
45
44
  return false;
46
45
  }
47
46
  return (Array.isArray(types) ? types : Object.keys(types)).some((type) => WalletSchemeTypeMap[scheme][type]);
@@ -57,7 +56,7 @@ function getWalletTypes(schemes) {
57
56
  ];
58
57
  }
59
58
  function getEquivalentTypes(types) {
60
- return getWalletTypes(getSchemes((Array.isArray(types) ? types : [types]).map((t) => WalletType[t])));
59
+ return getWalletTypes(getSchemes(Array.isArray(types) ? types : [types]));
61
60
  }
62
61
  function entityToWallet(w) {
63
62
  return __spreadProps(__spreadValues({}, w), {
@@ -69,13 +68,23 @@ function entityToWallet(w) {
69
68
  function migrateWallet(obj) {
70
69
  if (["USER", "PREGEN"].includes(obj.type)) {
71
70
  obj.isPregen = obj.type === "PREGEN";
72
- obj.type = obj.scheme === WalletScheme.ED25519 ? WalletType.SOLANA : WalletType.EVM;
71
+ obj.type = obj.scheme === "ED25519" ? "SOLANA" : "EVM";
73
72
  }
74
73
  if (!!obj.scheme && !obj.type) {
75
- obj.type = obj.scheme === WalletScheme.ED25519 ? WalletType.SOLANA : WalletType.EVM;
74
+ obj.type = obj.scheme === "ED25519" ? "SOLANA" : "EVM";
76
75
  }
77
76
  return obj;
78
77
  }
78
+ function supportedWalletTypesEq(a, b) {
79
+ return a.length === b.length && a.every(({ type, optional }, index) => b[index].type === type && b[index].optional === optional);
80
+ }
81
+ function mergeCurrentWalletIds(original, additional) {
82
+ return [.../* @__PURE__ */ new Set([...Object.keys(original), ...Object.keys(additional)])].reduce((acc, key) => {
83
+ return __spreadProps(__spreadValues({}, acc), {
84
+ [key]: [.../* @__PURE__ */ new Set([...original[key] || [], ...additional[key] || []])]
85
+ });
86
+ }, {});
87
+ }
79
88
  function newUuid() {
80
89
  return uuid.v4();
81
90
  }
@@ -87,6 +96,8 @@ export {
87
96
  getWalletTypes,
88
97
  isPregenIdentifierMatch,
89
98
  isWalletSupported,
99
+ mergeCurrentWalletIds,
90
100
  migrateWallet,
91
- newUuid
101
+ newUuid,
102
+ supportedWalletTypesEq
92
103
  };