@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.
- package/dist/cjs/ParaCore.js +3023 -0
- package/dist/cjs/PlatformUtils.js +15 -0
- package/dist/cjs/StorageUtils.js +15 -0
- package/dist/cjs/constants.js +84 -0
- package/dist/cjs/cryptography/utils.js +350 -0
- package/dist/cjs/errors.js +51 -0
- package/dist/cjs/external/mpcComputationClient.js +62 -0
- package/dist/cjs/external/userManagementClient.js +106 -0
- package/dist/cjs/index.js +85 -4001
- package/dist/cjs/package.json +3 -0
- package/dist/cjs/shares/KeyContainer.js +89 -0
- package/dist/cjs/shares/recovery.js +127 -0
- package/dist/cjs/shares/shareDistribution.js +104 -0
- package/dist/cjs/transmission/transmissionUtils.js +93 -0
- package/dist/cjs/types/config.js +43 -0
- package/dist/cjs/types/coreApi.js +74 -0
- package/dist/cjs/types/events.js +41 -0
- package/dist/cjs/types/index.js +52 -0
- package/dist/cjs/types/methods.js +15 -0
- package/dist/cjs/types/onRamps.js +33 -0
- package/dist/cjs/types/popup.js +35 -0
- package/dist/cjs/types/recovery.js +34 -0
- package/dist/cjs/types/theme.js +15 -0
- package/dist/cjs/types/wallet.js +31 -0
- package/dist/cjs/utils/autobind.js +41 -0
- package/dist/cjs/utils/events.js +45 -0
- package/dist/cjs/utils/formatting.js +112 -0
- package/dist/cjs/utils/index.js +41 -0
- package/dist/cjs/utils/json.js +37 -0
- package/dist/cjs/utils/listeners.js +71 -0
- package/dist/cjs/utils/onRamps.js +92 -0
- package/dist/cjs/utils/phone.js +61 -0
- package/dist/cjs/utils/polling.js +58 -0
- package/dist/cjs/utils/types.js +29 -0
- package/dist/cjs/utils/url.js +135 -0
- package/dist/cjs/utils/wallet.js +159 -0
- package/dist/esm/ParaCore.js +2984 -0
- package/dist/esm/PlatformUtils.js +0 -0
- package/dist/esm/StorageUtils.js +0 -0
- package/dist/esm/chunk-7B52C2XE.js +70 -0
- package/dist/esm/constants.js +43 -0
- package/dist/esm/cryptography/utils.js +282 -0
- package/dist/esm/errors.js +27 -0
- package/dist/esm/external/mpcComputationClient.js +30 -0
- package/dist/esm/external/userManagementClient.js +71 -0
- package/dist/esm/index.js +58 -3965
- package/dist/esm/package.json +4 -0
- package/dist/esm/shares/KeyContainer.js +57 -0
- package/dist/esm/shares/recovery.js +74 -0
- package/dist/esm/shares/shareDistribution.js +64 -0
- package/dist/esm/transmission/transmissionUtils.js +42 -0
- package/dist/esm/types/config.js +20 -0
- package/dist/esm/types/coreApi.js +52 -0
- package/dist/esm/types/events.js +19 -0
- package/dist/esm/types/index.js +22 -0
- package/dist/esm/types/methods.js +0 -0
- package/dist/esm/types/onRamps.js +11 -0
- package/dist/esm/types/popup.js +13 -0
- package/dist/esm/types/recovery.js +12 -0
- package/dist/esm/types/theme.js +0 -0
- package/dist/esm/types/wallet.js +9 -0
- package/dist/esm/utils/autobind.js +19 -0
- package/dist/esm/utils/events.js +11 -0
- package/dist/esm/utils/formatting.js +74 -0
- package/dist/esm/utils/index.js +11 -0
- package/dist/esm/utils/json.js +15 -0
- package/dist/esm/utils/listeners.js +38 -0
- package/dist/esm/utils/onRamps.js +66 -0
- package/dist/esm/utils/phone.js +28 -0
- package/dist/esm/utils/polling.js +18 -0
- package/dist/esm/utils/types.js +7 -0
- package/dist/esm/utils/url.js +90 -0
- package/dist/esm/utils/wallet.js +103 -0
- package/dist/types/ParaCore.d.ts +157 -126
- package/dist/types/PlatformUtils.d.ts +4 -3
- package/dist/types/constants.d.ts +2 -0
- package/dist/types/index.d.ts +3 -3
- package/dist/types/types/config.d.ts +4 -5
- package/dist/types/types/coreApi.d.ts +47 -9
- package/dist/types/types/events.d.ts +4 -1
- package/dist/types/types/methods.d.ts +9 -4
- package/dist/types/types/onRamps.d.ts +3 -3
- package/dist/types/types/wallet.d.ts +4 -2
- package/dist/types/utils/formatting.d.ts +3 -2
- package/dist/types/utils/onRamps.d.ts +12 -5
- package/dist/types/utils/wallet.d.ts +8 -7
- package/package.json +7 -7
- package/dist/cjs/index.js.br +0 -0
- package/dist/cjs/index.js.gz +0 -0
- package/dist/esm/index.js.br +0 -0
- 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,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
|
+
};
|