@getpara/core-sdk 2.0.0-alpha.3 → 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 (91) hide show
  1. package/dist/cjs/ParaCore.js +3023 -0
  2. package/dist/cjs/PlatformUtils.js +15 -0
  3. package/dist/cjs/StorageUtils.js +15 -0
  4. package/dist/cjs/constants.js +84 -0
  5. package/dist/cjs/cryptography/utils.js +350 -0
  6. package/dist/cjs/errors.js +51 -0
  7. package/dist/cjs/external/mpcComputationClient.js +62 -0
  8. package/dist/cjs/external/userManagementClient.js +106 -0
  9. package/dist/cjs/index.js +85 -4001
  10. package/dist/cjs/package.json +3 -0
  11. package/dist/cjs/shares/KeyContainer.js +89 -0
  12. package/dist/cjs/shares/recovery.js +127 -0
  13. package/dist/cjs/shares/shareDistribution.js +104 -0
  14. package/dist/cjs/transmission/transmissionUtils.js +93 -0
  15. package/dist/cjs/types/config.js +43 -0
  16. package/dist/cjs/types/coreApi.js +74 -0
  17. package/dist/cjs/types/events.js +41 -0
  18. package/dist/cjs/types/index.js +52 -0
  19. package/dist/cjs/types/methods.js +15 -0
  20. package/dist/cjs/types/onRamps.js +33 -0
  21. package/dist/cjs/types/popup.js +35 -0
  22. package/dist/cjs/types/recovery.js +34 -0
  23. package/dist/cjs/types/theme.js +15 -0
  24. package/dist/cjs/types/wallet.js +31 -0
  25. package/dist/cjs/utils/autobind.js +41 -0
  26. package/dist/cjs/utils/events.js +45 -0
  27. package/dist/cjs/utils/formatting.js +112 -0
  28. package/dist/cjs/utils/index.js +41 -0
  29. package/dist/cjs/utils/json.js +37 -0
  30. package/dist/cjs/utils/listeners.js +71 -0
  31. package/dist/cjs/utils/onRamps.js +92 -0
  32. package/dist/cjs/utils/phone.js +61 -0
  33. package/dist/cjs/utils/polling.js +58 -0
  34. package/dist/cjs/utils/types.js +29 -0
  35. package/dist/cjs/utils/url.js +135 -0
  36. package/dist/cjs/utils/wallet.js +159 -0
  37. package/dist/esm/ParaCore.js +2984 -0
  38. package/dist/esm/PlatformUtils.js +0 -0
  39. package/dist/esm/StorageUtils.js +0 -0
  40. package/dist/esm/chunk-7B52C2XE.js +70 -0
  41. package/dist/esm/constants.js +43 -0
  42. package/dist/esm/cryptography/utils.js +282 -0
  43. package/dist/esm/errors.js +27 -0
  44. package/dist/esm/external/mpcComputationClient.js +30 -0
  45. package/dist/esm/external/userManagementClient.js +71 -0
  46. package/dist/esm/index.js +58 -3965
  47. package/dist/esm/package.json +4 -0
  48. package/dist/esm/shares/KeyContainer.js +57 -0
  49. package/dist/esm/shares/recovery.js +74 -0
  50. package/dist/esm/shares/shareDistribution.js +64 -0
  51. package/dist/esm/transmission/transmissionUtils.js +42 -0
  52. package/dist/esm/types/config.js +20 -0
  53. package/dist/esm/types/coreApi.js +52 -0
  54. package/dist/esm/types/events.js +19 -0
  55. package/dist/esm/types/index.js +22 -0
  56. package/dist/esm/types/methods.js +0 -0
  57. package/dist/esm/types/onRamps.js +11 -0
  58. package/dist/esm/types/popup.js +13 -0
  59. package/dist/esm/types/recovery.js +12 -0
  60. package/dist/esm/types/theme.js +0 -0
  61. package/dist/esm/types/wallet.js +9 -0
  62. package/dist/esm/utils/autobind.js +19 -0
  63. package/dist/esm/utils/events.js +11 -0
  64. package/dist/esm/utils/formatting.js +74 -0
  65. package/dist/esm/utils/index.js +11 -0
  66. package/dist/esm/utils/json.js +15 -0
  67. package/dist/esm/utils/listeners.js +38 -0
  68. package/dist/esm/utils/onRamps.js +66 -0
  69. package/dist/esm/utils/phone.js +28 -0
  70. package/dist/esm/utils/polling.js +18 -0
  71. package/dist/esm/utils/types.js +7 -0
  72. package/dist/esm/utils/url.js +90 -0
  73. package/dist/esm/utils/wallet.js +103 -0
  74. package/dist/types/ParaCore.d.ts +157 -126
  75. package/dist/types/PlatformUtils.d.ts +4 -3
  76. package/dist/types/constants.d.ts +2 -0
  77. package/dist/types/index.d.ts +3 -3
  78. package/dist/types/types/config.d.ts +4 -5
  79. package/dist/types/types/coreApi.d.ts +47 -9
  80. package/dist/types/types/events.d.ts +4 -1
  81. package/dist/types/types/methods.d.ts +9 -4
  82. package/dist/types/types/onRamps.d.ts +3 -3
  83. package/dist/types/types/wallet.d.ts +4 -2
  84. package/dist/types/utils/formatting.d.ts +3 -2
  85. package/dist/types/utils/onRamps.d.ts +12 -5
  86. package/dist/types/utils/wallet.d.ts +8 -7
  87. package/package.json +7 -7
  88. package/dist/cjs/index.js.br +0 -0
  89. package/dist/cjs/index.js.gz +0 -0
  90. package/dist/esm/index.js.br +0 -0
  91. package/dist/esm/index.js.gz +0 -0
@@ -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,18 @@
1
+ import {
2
+ __async
3
+ } from "../chunk-7B52C2XE.js";
4
+ function waitUntilTrue(condition, timeoutMs, intervalMs) {
5
+ return __async(this, null, function* () {
6
+ const start = Date.now();
7
+ while (Date.now() - start < timeoutMs) {
8
+ if (yield condition()) {
9
+ return true;
10
+ }
11
+ yield new Promise((resolve) => setTimeout(resolve, intervalMs));
12
+ }
13
+ return false;
14
+ });
15
+ }
16
+ export {
17
+ waitUntilTrue
18
+ };
@@ -0,0 +1,7 @@
1
+ import "../chunk-7B52C2XE.js";
2
+ function isServerAuthState(obj) {
3
+ return "stage" in obj;
4
+ }
5
+ export {
6
+ isServerAuthState
7
+ };
@@ -0,0 +1,90 @@
1
+ import {
2
+ __async
3
+ } from "../chunk-7B52C2XE.js";
4
+ import { upload } from "../transmission/transmissionUtils.js";
5
+ import { Environment } from "../types/index.js";
6
+ function getPortalDomain(env, isE2E) {
7
+ if (isE2E) {
8
+ return `localhost`;
9
+ }
10
+ switch (env) {
11
+ case Environment.DEV:
12
+ return "localhost";
13
+ case Environment.SANDBOX:
14
+ return "app.sandbox.usecapsule.com";
15
+ case Environment.BETA:
16
+ return "app.beta.usecapsule.com";
17
+ case Environment.PROD:
18
+ return "app.usecapsule.com";
19
+ default:
20
+ throw new Error(`env: ${env} not supported`);
21
+ }
22
+ }
23
+ function getPortalBaseURL({ env, isE2E }, useLocalIp, isForWasm) {
24
+ if (isE2E) {
25
+ if (isForWasm) {
26
+ return `https://app.sandbox.usecapsule.com`;
27
+ }
28
+ return `http://localhost:3003`;
29
+ }
30
+ const domain = getPortalDomain(env);
31
+ if (env === Environment.DEV) {
32
+ if (useLocalIp) {
33
+ return `http://127.0.0.1:3003`;
34
+ }
35
+ return `http://${domain}:3003`;
36
+ }
37
+ return `https://${domain}`;
38
+ }
39
+ function getParaConnectDomain(env) {
40
+ switch (env) {
41
+ case Environment.DEV:
42
+ return "localhost";
43
+ case Environment.SANDBOX:
44
+ return "connect.sandbox.getpara.com";
45
+ case Environment.BETA:
46
+ return "connect.beta.getpara.com";
47
+ case Environment.PROD:
48
+ return "connect.getpara.com";
49
+ default:
50
+ throw new Error(`env: ${env} not supported`);
51
+ }
52
+ }
53
+ function getParaConnectBaseUrl({ env }, useLocalIp) {
54
+ const domain = getParaConnectDomain(env);
55
+ if (env === Environment.DEV) {
56
+ if (useLocalIp) {
57
+ return `http://127.0.0.1:3008`;
58
+ }
59
+ return `http://${domain}:3008`;
60
+ }
61
+ return `https://${domain}`;
62
+ }
63
+ function constructUrl({
64
+ base,
65
+ path,
66
+ params = {}
67
+ }) {
68
+ const url = new URL(path, base);
69
+ Object.entries(params).forEach(([key, value]) => {
70
+ if (!!value && value !== "undefined" && value !== "null") url.searchParams.set(key, value.toString());
71
+ });
72
+ return url.toString();
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
+ }
83
+ export {
84
+ constructUrl,
85
+ getParaConnectBaseUrl,
86
+ getParaConnectDomain,
87
+ getPortalBaseURL,
88
+ getPortalDomain,
89
+ shortenUrl
90
+ };
@@ -0,0 +1,103 @@
1
+ import {
2
+ __spreadProps,
3
+ __spreadValues
4
+ } from "../chunk-7B52C2XE.js";
5
+ import * as uuid from "uuid";
6
+ import { formatPhoneNumber } from "./phone.js";
7
+ const WalletSchemeTypeMap = {
8
+ DKLS: {
9
+ EVM: true,
10
+ COSMOS: true
11
+ },
12
+ CGGMP: {
13
+ EVM: true,
14
+ COSMOS: true
15
+ },
16
+ ED25519: {
17
+ SOLANA: true
18
+ }
19
+ };
20
+ function isPregenIdentifierMatch(a, b, type) {
21
+ if (!a || !b) {
22
+ return false;
23
+ }
24
+ switch (type) {
25
+ case "EMAIL":
26
+ return a.toLowerCase() === b.toLowerCase();
27
+ case "PHONE":
28
+ return formatPhoneNumber(a) === formatPhoneNumber(b);
29
+ case "CUSTOM_ID":
30
+ return a === b;
31
+ default:
32
+ return a.replace(/^@/g, "").toLowerCase() === b.replace(/^@/g, "").toLowerCase();
33
+ }
34
+ }
35
+ function isWalletSupported(types, wallet) {
36
+ return types.some((walletType) => {
37
+ var _a;
38
+ return !!((_a = WalletSchemeTypeMap[wallet == null ? void 0 : wallet.scheme]) == null ? void 0 : _a[walletType]);
39
+ });
40
+ }
41
+ function getSchemes(types) {
42
+ return Object.keys(WalletSchemeTypeMap).filter((scheme) => {
43
+ if (scheme === "CGGMP") {
44
+ return false;
45
+ }
46
+ return (Array.isArray(types) ? types : Object.keys(types)).some((type) => WalletSchemeTypeMap[scheme][type]);
47
+ });
48
+ }
49
+ function getWalletTypes(schemes) {
50
+ return [
51
+ ...new Set(
52
+ schemes.reduce((acc, scheme) => {
53
+ return [...acc, ...Object.keys(WalletSchemeTypeMap[scheme]).filter((type) => WalletSchemeTypeMap[scheme][type])];
54
+ }, [])
55
+ )
56
+ ];
57
+ }
58
+ function getEquivalentTypes(types) {
59
+ return getWalletTypes(getSchemes(Array.isArray(types) ? types : [types]));
60
+ }
61
+ function entityToWallet(w) {
62
+ return __spreadProps(__spreadValues({}, w), {
63
+ scheme: w.scheme,
64
+ type: w.type,
65
+ pregenIdentifierType: w.pregenIdentifierType
66
+ });
67
+ }
68
+ function migrateWallet(obj) {
69
+ if (["USER", "PREGEN"].includes(obj.type)) {
70
+ obj.isPregen = obj.type === "PREGEN";
71
+ obj.type = obj.scheme === "ED25519" ? "SOLANA" : "EVM";
72
+ }
73
+ if (!!obj.scheme && !obj.type) {
74
+ obj.type = obj.scheme === "ED25519" ? "SOLANA" : "EVM";
75
+ }
76
+ return obj;
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
+ }
88
+ function newUuid() {
89
+ return uuid.v4();
90
+ }
91
+ export {
92
+ WalletSchemeTypeMap,
93
+ entityToWallet,
94
+ getEquivalentTypes,
95
+ getSchemes,
96
+ getWalletTypes,
97
+ isPregenIdentifierMatch,
98
+ isWalletSupported,
99
+ mergeCurrentWalletIds,
100
+ migrateWallet,
101
+ newUuid,
102
+ supportedWalletTypesEq
103
+ };