@getpara/core-sdk 2.0.0-dev.0 → 2.0.0-dev.2

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 (100) hide show
  1. package/dist/cjs/ParaCore.js +3378 -0
  2. package/dist/cjs/PlatformUtils.js +15 -0
  3. package/dist/cjs/StorageUtils.js +15 -0
  4. package/dist/cjs/constants.js +87 -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 +102 -4080
  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/auth.js +33 -0
  16. package/dist/cjs/types/config.js +43 -0
  17. package/dist/cjs/types/coreApi.js +89 -0
  18. package/dist/cjs/types/events.js +41 -0
  19. package/dist/cjs/types/index.js +54 -0
  20. package/dist/cjs/types/methods.js +15 -0
  21. package/dist/cjs/types/onRamps.js +33 -0
  22. package/dist/cjs/types/popup.js +35 -0
  23. package/dist/cjs/types/recovery.js +34 -0
  24. package/dist/cjs/types/theme.js +15 -0
  25. package/dist/cjs/types/wallet.js +31 -0
  26. package/dist/cjs/utils/autobind.js +41 -0
  27. package/dist/cjs/utils/events.js +45 -0
  28. package/dist/cjs/utils/formatting.js +116 -0
  29. package/dist/cjs/utils/index.js +41 -0
  30. package/dist/cjs/utils/json.js +37 -0
  31. package/dist/cjs/utils/listeners.js +71 -0
  32. package/dist/cjs/utils/onRamps.js +92 -0
  33. package/dist/cjs/utils/phone.js +73 -0
  34. package/dist/cjs/utils/polling.js +58 -0
  35. package/dist/cjs/utils/types.js +29 -0
  36. package/dist/cjs/utils/url.js +135 -0
  37. package/dist/cjs/utils/wallet.js +159 -0
  38. package/dist/esm/ParaCore.js +3343 -0
  39. package/dist/esm/PlatformUtils.js +0 -0
  40. package/dist/esm/StorageUtils.js +0 -0
  41. package/dist/esm/chunk-7B52C2XE.js +70 -0
  42. package/dist/esm/constants.js +45 -0
  43. package/dist/esm/cryptography/utils.js +282 -0
  44. package/dist/esm/errors.js +27 -0
  45. package/dist/esm/external/mpcComputationClient.js +30 -0
  46. package/dist/esm/external/userManagementClient.js +71 -0
  47. package/dist/esm/index.js +78 -4049
  48. package/dist/esm/package.json +4 -0
  49. package/dist/esm/shares/KeyContainer.js +57 -0
  50. package/dist/esm/shares/recovery.js +74 -0
  51. package/dist/esm/shares/shareDistribution.js +64 -0
  52. package/dist/esm/transmission/transmissionUtils.js +42 -0
  53. package/dist/esm/types/auth.js +11 -0
  54. package/dist/esm/types/config.js +20 -0
  55. package/dist/esm/types/coreApi.js +66 -0
  56. package/dist/esm/types/events.js +19 -0
  57. package/dist/esm/types/index.js +23 -0
  58. package/dist/esm/types/methods.js +0 -0
  59. package/dist/esm/types/onRamps.js +11 -0
  60. package/dist/esm/types/popup.js +13 -0
  61. package/dist/esm/types/recovery.js +12 -0
  62. package/dist/esm/types/theme.js +0 -0
  63. package/dist/esm/types/wallet.js +9 -0
  64. package/dist/esm/utils/autobind.js +19 -0
  65. package/dist/esm/utils/events.js +11 -0
  66. package/dist/esm/utils/formatting.js +76 -0
  67. package/dist/esm/utils/index.js +11 -0
  68. package/dist/esm/utils/json.js +15 -0
  69. package/dist/esm/utils/listeners.js +38 -0
  70. package/dist/esm/utils/onRamps.js +66 -0
  71. package/dist/esm/utils/phone.js +39 -0
  72. package/dist/esm/utils/polling.js +18 -0
  73. package/dist/esm/utils/types.js +7 -0
  74. package/dist/esm/utils/url.js +90 -0
  75. package/dist/esm/utils/wallet.js +103 -0
  76. package/dist/types/ParaCore.d.ts +140 -367
  77. package/dist/types/PlatformUtils.d.ts +4 -5
  78. package/dist/types/constants.d.ts +17 -13
  79. package/dist/types/index.d.ts +5 -4
  80. package/dist/types/shares/KeyContainer.d.ts +0 -2
  81. package/dist/types/types/auth.d.ts +16 -0
  82. package/dist/types/types/config.d.ts +12 -5
  83. package/dist/types/types/coreApi.d.ts +531 -0
  84. package/dist/types/types/events.d.ts +4 -1
  85. package/dist/types/types/index.d.ts +2 -0
  86. package/dist/types/types/methods.d.ts +145 -42
  87. package/dist/types/types/onRamps.d.ts +3 -3
  88. package/dist/types/types/wallet.d.ts +8 -4
  89. package/dist/types/utils/formatting.d.ts +5 -2
  90. package/dist/types/utils/index.d.ts +1 -0
  91. package/dist/types/utils/onRamps.d.ts +12 -5
  92. package/dist/types/utils/phone.d.ts +6 -2
  93. package/dist/types/utils/types.d.ts +2 -0
  94. package/dist/types/utils/url.d.ts +2 -1
  95. package/dist/types/utils/wallet.d.ts +9 -7
  96. package/package.json +27 -26
  97. package/dist/cjs/index.js.br +0 -0
  98. package/dist/cjs/index.js.gz +0 -0
  99. package/dist/esm/index.js.br +0 -0
  100. package/dist/esm/index.js.gz +0 -0
@@ -0,0 +1,66 @@
1
+ import "../chunk-7B52C2XE.js";
2
+ import { Network } from "@getpara/user-management-client";
3
+ function toAssetInfoArray(data) {
4
+ const result = [];
5
+ Object.keys(data).forEach((walletType) => {
6
+ const networks = data[walletType];
7
+ Object.keys(networks).forEach((network) => {
8
+ const assets = networks[network];
9
+ Object.keys(assets).forEach((asset) => {
10
+ const providerInfo = assets[asset];
11
+ result.push([walletType, network, asset, providerInfo]);
12
+ });
13
+ });
14
+ });
15
+ return result;
16
+ }
17
+ function getOnRampNetworks(data, {
18
+ walletType,
19
+ allowed,
20
+ assets,
21
+ providers,
22
+ action
23
+ } = {}) {
24
+ return [
25
+ ...new Set(
26
+ toAssetInfoArray(data).filter(
27
+ ([type, network, asset, providerInfo]) => (!walletType || type === walletType) && (!allowed || allowed.includes(network)) && (!assets || assets.includes(asset)) && (!providers || providers.some((provider) => {
28
+ var _a;
29
+ return ((_a = providerInfo[provider]) == null ? void 0 : _a[1]) && (!action || providerInfo[provider][1][action]);
30
+ }))
31
+ ).map(([_, network]) => network)
32
+ )
33
+ ];
34
+ }
35
+ function getOnRampAssets(data, {
36
+ walletType,
37
+ network,
38
+ allowed,
39
+ providers,
40
+ action
41
+ } = {}) {
42
+ return [
43
+ ...new Set(
44
+ toAssetInfoArray(data).filter(
45
+ ([t, n, a, p]) => (!walletType || t === walletType) && (!network || n === network) && (!Array.isArray(allowed) || allowed.includes(a)) && (!providers || providers.some((provider) => {
46
+ var _a;
47
+ return ((_a = p[provider]) == null ? void 0 : _a[1]) && (!action || p[provider][1][action]);
48
+ }))
49
+ ).map(([, , asset]) => asset)
50
+ )
51
+ ];
52
+ }
53
+ const NETWORK_PREFIXES = {
54
+ [Network.COSMOS]: "cosmos",
55
+ [Network.NOBLE]: "noble"
56
+ };
57
+ function getNetworkPrefix(network) {
58
+ return NETWORK_PREFIXES[network];
59
+ }
60
+ export {
61
+ NETWORK_PREFIXES,
62
+ getNetworkPrefix,
63
+ getOnRampAssets,
64
+ getOnRampNetworks,
65
+ toAssetInfoArray
66
+ };
@@ -0,0 +1,39 @@
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
+ function splitPhoneNumber(phone) {
26
+ const parsedNumber = parsePhoneNumberFromString(phone);
27
+ if (parsedNumber == null ? void 0 : parsedNumber.isValid()) {
28
+ return {
29
+ phone: parsedNumber.nationalNumber.replace(/\D/g, ""),
30
+ countryCode: `+${parsedNumber.countryCallingCode}`
31
+ };
32
+ }
33
+ throw new Error("Invalid phone number");
34
+ }
35
+ export {
36
+ displayPhoneNumber,
37
+ formatPhoneNumber,
38
+ splitPhoneNumber
39
+ };
@@ -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
+ };