@getpara/core-sdk 2.0.0-dev.1 → 2.0.0-dev.3
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 +3378 -0
- package/dist/cjs/PlatformUtils.js +15 -0
- package/dist/cjs/StorageUtils.js +15 -0
- package/dist/cjs/constants.js +87 -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 +100 -5043
- 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/auth.js +33 -0
- package/dist/cjs/types/config.js +43 -0
- package/dist/cjs/types/coreApi.js +89 -0
- package/dist/cjs/types/events.js +41 -0
- package/dist/cjs/types/index.js +54 -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 +116 -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 +73 -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 +3343 -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 +45 -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 +76 -5011
- 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/auth.js +11 -0
- package/dist/esm/types/config.js +20 -0
- package/dist/esm/types/coreApi.js +66 -0
- package/dist/esm/types/events.js +19 -0
- package/dist/esm/types/index.js +23 -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 +76 -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 +39 -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 +115 -449
- package/dist/types/PlatformUtils.d.ts +4 -5
- package/dist/types/constants.d.ts +16 -13
- package/dist/types/index.d.ts +3 -3
- package/dist/types/shares/KeyContainer.d.ts +0 -2
- package/dist/types/types/auth.d.ts +16 -0
- package/dist/types/types/config.d.ts +12 -5
- package/dist/types/types/coreApi.d.ts +152 -58
- package/dist/types/types/events.d.ts +4 -1
- package/dist/types/types/index.d.ts +1 -0
- package/dist/types/types/methods.d.ts +49 -57
- package/dist/types/types/onRamps.d.ts +3 -3
- package/dist/types/types/wallet.d.ts +8 -3
- package/dist/types/utils/formatting.d.ts +5 -2
- package/dist/types/utils/onRamps.d.ts +12 -5
- package/dist/types/utils/phone.d.ts +4 -0
- package/dist/types/utils/wallet.d.ts +8 -7
- package/package.json +27 -26
- 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,15 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __copyProps = (to, from, except, desc) => {
|
|
6
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
7
|
+
for (let key of __getOwnPropNames(from))
|
|
8
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
9
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
10
|
+
}
|
|
11
|
+
return to;
|
|
12
|
+
};
|
|
13
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
14
|
+
var PlatformUtils_exports = {};
|
|
15
|
+
module.exports = __toCommonJS(PlatformUtils_exports);
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __copyProps = (to, from, except, desc) => {
|
|
6
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
7
|
+
for (let key of __getOwnPropNames(from))
|
|
8
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
9
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
10
|
+
}
|
|
11
|
+
return to;
|
|
12
|
+
};
|
|
13
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
14
|
+
var StorageUtils_exports = {};
|
|
15
|
+
module.exports = __toCommonJS(StorageUtils_exports);
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
var constants_exports = {};
|
|
19
|
+
__export(constants_exports, {
|
|
20
|
+
ACCOUNT_LINK_CONFLICT: () => ACCOUNT_LINK_CONFLICT,
|
|
21
|
+
EXTERNAL_WALLET_CONNECTION_ONLY_USER_ID: () => EXTERNAL_WALLET_CONNECTION_ONLY_USER_ID,
|
|
22
|
+
LOCAL_STORAGE_AUTH_INFO: () => LOCAL_STORAGE_AUTH_INFO,
|
|
23
|
+
LOCAL_STORAGE_COUNTRY_CODE: () => LOCAL_STORAGE_COUNTRY_CODE,
|
|
24
|
+
LOCAL_STORAGE_CURRENT_WALLET_IDS: () => LOCAL_STORAGE_CURRENT_WALLET_IDS,
|
|
25
|
+
LOCAL_STORAGE_ED25519_WALLETS: () => LOCAL_STORAGE_ED25519_WALLETS,
|
|
26
|
+
LOCAL_STORAGE_EMAIL: () => LOCAL_STORAGE_EMAIL,
|
|
27
|
+
LOCAL_STORAGE_EXTERNAL_WALLETS: () => LOCAL_STORAGE_EXTERNAL_WALLETS,
|
|
28
|
+
LOCAL_STORAGE_EXTERNAL_WALLET_USER_ID: () => LOCAL_STORAGE_EXTERNAL_WALLET_USER_ID,
|
|
29
|
+
LOCAL_STORAGE_FARCASTER_USERNAME: () => LOCAL_STORAGE_FARCASTER_USERNAME,
|
|
30
|
+
LOCAL_STORAGE_PHONE: () => LOCAL_STORAGE_PHONE,
|
|
31
|
+
LOCAL_STORAGE_SESSION_COOKIE: () => LOCAL_STORAGE_SESSION_COOKIE,
|
|
32
|
+
LOCAL_STORAGE_TELEGRAM_USER_ID: () => LOCAL_STORAGE_TELEGRAM_USER_ID,
|
|
33
|
+
LOCAL_STORAGE_USER_ID: () => LOCAL_STORAGE_USER_ID,
|
|
34
|
+
LOCAL_STORAGE_WALLETS: () => LOCAL_STORAGE_WALLETS,
|
|
35
|
+
PARA_CORE_VERSION: () => PARA_CORE_VERSION,
|
|
36
|
+
POLLING_INTERVAL_MS: () => POLLING_INTERVAL_MS,
|
|
37
|
+
POLLING_TIMEOUT_MS: () => POLLING_TIMEOUT_MS,
|
|
38
|
+
PREFIX: () => PREFIX,
|
|
39
|
+
SESSION_STORAGE_LOGIN_ENCRYPTION_KEY_PAIR: () => SESSION_STORAGE_LOGIN_ENCRYPTION_KEY_PAIR,
|
|
40
|
+
SHORT_POLLING_INTERVAL_MS: () => SHORT_POLLING_INTERVAL_MS
|
|
41
|
+
});
|
|
42
|
+
module.exports = __toCommonJS(constants_exports);
|
|
43
|
+
const PARA_CORE_VERSION = "2.0.0-dev.0";
|
|
44
|
+
const PREFIX = "@CAPSULE/";
|
|
45
|
+
const LOCAL_STORAGE_AUTH_INFO = `${PREFIX}authInfo`;
|
|
46
|
+
const LOCAL_STORAGE_EMAIL = `${PREFIX}e-mail`;
|
|
47
|
+
const LOCAL_STORAGE_PHONE = `${PREFIX}phone`;
|
|
48
|
+
const LOCAL_STORAGE_COUNTRY_CODE = `${PREFIX}countryCode`;
|
|
49
|
+
const LOCAL_STORAGE_FARCASTER_USERNAME = `${PREFIX}farcasterUsername`;
|
|
50
|
+
const LOCAL_STORAGE_TELEGRAM_USER_ID = `${PREFIX}telegramUserId`;
|
|
51
|
+
const LOCAL_STORAGE_EXTERNAL_WALLET_USER_ID = `${PREFIX}externalWalletUserId`;
|
|
52
|
+
const LOCAL_STORAGE_USER_ID = `${PREFIX}userId`;
|
|
53
|
+
const LOCAL_STORAGE_ED25519_WALLETS = `${PREFIX}ed25519Wallets`;
|
|
54
|
+
const LOCAL_STORAGE_WALLETS = `${PREFIX}wallets`;
|
|
55
|
+
const LOCAL_STORAGE_EXTERNAL_WALLETS = `${PREFIX}externalWallets`;
|
|
56
|
+
const LOCAL_STORAGE_CURRENT_WALLET_IDS = `${PREFIX}currentWalletIds`;
|
|
57
|
+
const LOCAL_STORAGE_SESSION_COOKIE = `${PREFIX}sessionCookie`;
|
|
58
|
+
const SESSION_STORAGE_LOGIN_ENCRYPTION_KEY_PAIR = `${PREFIX}loginEncryptionKeyPair`;
|
|
59
|
+
const POLLING_INTERVAL_MS = 2e3;
|
|
60
|
+
const SHORT_POLLING_INTERVAL_MS = 1e3;
|
|
61
|
+
const POLLING_TIMEOUT_MS = 3e5;
|
|
62
|
+
const EXTERNAL_WALLET_CONNECTION_ONLY_USER_ID = "EXTERNAL_WALLET_CONNECTION_ONLY";
|
|
63
|
+
const ACCOUNT_LINK_CONFLICT = "Account already linked";
|
|
64
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
65
|
+
0 && (module.exports = {
|
|
66
|
+
ACCOUNT_LINK_CONFLICT,
|
|
67
|
+
EXTERNAL_WALLET_CONNECTION_ONLY_USER_ID,
|
|
68
|
+
LOCAL_STORAGE_AUTH_INFO,
|
|
69
|
+
LOCAL_STORAGE_COUNTRY_CODE,
|
|
70
|
+
LOCAL_STORAGE_CURRENT_WALLET_IDS,
|
|
71
|
+
LOCAL_STORAGE_ED25519_WALLETS,
|
|
72
|
+
LOCAL_STORAGE_EMAIL,
|
|
73
|
+
LOCAL_STORAGE_EXTERNAL_WALLETS,
|
|
74
|
+
LOCAL_STORAGE_EXTERNAL_WALLET_USER_ID,
|
|
75
|
+
LOCAL_STORAGE_FARCASTER_USERNAME,
|
|
76
|
+
LOCAL_STORAGE_PHONE,
|
|
77
|
+
LOCAL_STORAGE_SESSION_COOKIE,
|
|
78
|
+
LOCAL_STORAGE_TELEGRAM_USER_ID,
|
|
79
|
+
LOCAL_STORAGE_USER_ID,
|
|
80
|
+
LOCAL_STORAGE_WALLETS,
|
|
81
|
+
PARA_CORE_VERSION,
|
|
82
|
+
POLLING_INTERVAL_MS,
|
|
83
|
+
POLLING_TIMEOUT_MS,
|
|
84
|
+
PREFIX,
|
|
85
|
+
SESSION_STORAGE_LOGIN_ENCRYPTION_KEY_PAIR,
|
|
86
|
+
SHORT_POLLING_INTERVAL_MS
|
|
87
|
+
});
|
|
@@ -0,0 +1,350 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
24
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
25
|
+
mod
|
|
26
|
+
));
|
|
27
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
|
+
var __async = (__this, __arguments, generator) => {
|
|
29
|
+
return new Promise((resolve, reject) => {
|
|
30
|
+
var fulfilled = (value) => {
|
|
31
|
+
try {
|
|
32
|
+
step(generator.next(value));
|
|
33
|
+
} catch (e) {
|
|
34
|
+
reject(e);
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
var rejected = (value) => {
|
|
38
|
+
try {
|
|
39
|
+
step(generator.throw(value));
|
|
40
|
+
} catch (e) {
|
|
41
|
+
reject(e);
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
45
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
|
46
|
+
});
|
|
47
|
+
};
|
|
48
|
+
var utils_exports = {};
|
|
49
|
+
__export(utils_exports, {
|
|
50
|
+
decodePrivateKeyPemHex: () => decodePrivateKeyPemHex,
|
|
51
|
+
decryptPrivateKey: () => decryptPrivateKey,
|
|
52
|
+
decryptPrivateKeyAndDecryptShare: () => decryptPrivateKeyAndDecryptShare,
|
|
53
|
+
decryptPrivateKeyWithPassword: () => decryptPrivateKeyWithPassword,
|
|
54
|
+
decryptWithKeyPair: () => decryptWithKeyPair,
|
|
55
|
+
decryptWithPrivateKey: () => decryptWithPrivateKey,
|
|
56
|
+
encodePrivateKeyToPemHex: () => encodePrivateKeyToPemHex,
|
|
57
|
+
encryptPrivateKey: () => encryptPrivateKey,
|
|
58
|
+
encryptPrivateKeyWithPassword: () => encryptPrivateKeyWithPassword,
|
|
59
|
+
encryptWithDerivedPublicKey: () => encryptWithDerivedPublicKey,
|
|
60
|
+
getAsymmetricKeyPair: () => getAsymmetricKeyPair,
|
|
61
|
+
getDerivedPrivateKeyAndDecrypt: () => getDerivedPrivateKeyAndDecrypt,
|
|
62
|
+
getPublicKeyFromSignature: () => getPublicKeyFromSignature,
|
|
63
|
+
getPublicKeyHex: () => getPublicKeyHex,
|
|
64
|
+
getSHA256HashHex: () => getSHA256HashHex,
|
|
65
|
+
hashPasswordWithSalt: () => hashPasswordWithSalt,
|
|
66
|
+
publicKeyFromHex: () => publicKeyFromHex,
|
|
67
|
+
publicKeyHexToPem: () => publicKeyHexToPem,
|
|
68
|
+
symmetricKeyEncryptMessage: () => symmetricKeyEncryptMessage
|
|
69
|
+
});
|
|
70
|
+
module.exports = __toCommonJS(utils_exports);
|
|
71
|
+
var import_base64url = __toESM(require("base64url"));
|
|
72
|
+
var import_node_forge = __toESM(require("node-forge"));
|
|
73
|
+
var import_utils = require("../utils/index.js");
|
|
74
|
+
const rsa = import_node_forge.default.pki.rsa;
|
|
75
|
+
const RSA_ENCRYPTION_SCHEME = "RSA-OAEP";
|
|
76
|
+
const CONSTANT_IV = "794241bc819a125a7b78ea313decc0bc";
|
|
77
|
+
const CONSTANT_IV_AES = new Uint8Array([23, 66, 157, 146, 179, 158, 117, 120, 184, 73, 123, 81]);
|
|
78
|
+
function getSHA256HashHex(str) {
|
|
79
|
+
const md = import_node_forge.default.md.sha256.create();
|
|
80
|
+
md.update(str);
|
|
81
|
+
return md.digest().toHex();
|
|
82
|
+
}
|
|
83
|
+
function getPublicKeyHex(keyPair) {
|
|
84
|
+
const pem = import_node_forge.default.pki.publicKeyToRSAPublicKeyPem(keyPair.publicKey);
|
|
85
|
+
return Buffer.from(pem, "utf-8").toString("hex");
|
|
86
|
+
}
|
|
87
|
+
function publicKeyFromHex(publicKeyHex) {
|
|
88
|
+
const pem = publicKeyHexToPem(publicKeyHex);
|
|
89
|
+
return import_node_forge.default.pki.publicKeyFromPem(pem);
|
|
90
|
+
}
|
|
91
|
+
function publicKeyHexToPem(publicKeyHex) {
|
|
92
|
+
return Buffer.from(publicKeyHex, "hex").toString("utf-8");
|
|
93
|
+
}
|
|
94
|
+
function encodePrivateKeyToPemHex(keyPair) {
|
|
95
|
+
const pem = import_node_forge.default.pki.privateKeyToPem(keyPair.privateKey);
|
|
96
|
+
return Buffer.from(pem, "utf-8").toString("hex");
|
|
97
|
+
}
|
|
98
|
+
function decodePrivateKeyPemHex(privateKeyPemHex) {
|
|
99
|
+
const pem = Buffer.from(privateKeyPemHex, "hex").toString("utf-8");
|
|
100
|
+
return import_node_forge.default.pki.privateKeyFromPem(pem);
|
|
101
|
+
}
|
|
102
|
+
function encryptPrivateKey(keyPair, key) {
|
|
103
|
+
return __async(this, null, function* () {
|
|
104
|
+
const privateKeyPemHex = encodePrivateKeyToPemHex(keyPair);
|
|
105
|
+
const cryptoKey = yield window.crypto.subtle.importKey(
|
|
106
|
+
"raw",
|
|
107
|
+
Buffer.from(key, "base64"),
|
|
108
|
+
{
|
|
109
|
+
name: "AES-GCM",
|
|
110
|
+
length: 256
|
|
111
|
+
},
|
|
112
|
+
true,
|
|
113
|
+
["encrypt", "decrypt"]
|
|
114
|
+
);
|
|
115
|
+
const encodedPlaintext = new TextEncoder().encode(privateKeyPemHex);
|
|
116
|
+
const ciphertext = yield window.crypto.subtle.encrypt(
|
|
117
|
+
{ name: "AES-GCM", iv: CONSTANT_IV_AES },
|
|
118
|
+
cryptoKey,
|
|
119
|
+
encodedPlaintext
|
|
120
|
+
);
|
|
121
|
+
return Buffer.from(ciphertext).toString("base64");
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
function decryptPrivateKey(encryptedPrivateKeyPemHex, key) {
|
|
125
|
+
return __async(this, null, function* () {
|
|
126
|
+
const secretKey = yield crypto.subtle.importKey(
|
|
127
|
+
"raw",
|
|
128
|
+
Buffer.from(key, "base64"),
|
|
129
|
+
{
|
|
130
|
+
name: "AES-GCM",
|
|
131
|
+
length: 256
|
|
132
|
+
},
|
|
133
|
+
true,
|
|
134
|
+
["encrypt", "decrypt"]
|
|
135
|
+
);
|
|
136
|
+
const cleartext = yield crypto.subtle.decrypt(
|
|
137
|
+
{ name: "AES-GCM", iv: CONSTANT_IV_AES },
|
|
138
|
+
secretKey,
|
|
139
|
+
Buffer.from(encryptedPrivateKeyPemHex, "base64")
|
|
140
|
+
);
|
|
141
|
+
const privateKeyPemHex = new TextDecoder().decode(cleartext);
|
|
142
|
+
const privateKey = decodePrivateKeyPemHex(privateKeyPemHex);
|
|
143
|
+
return privateKey;
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
function getAsymmetricKeyPair(ctx, seedValue) {
|
|
147
|
+
return __async(this, null, function* () {
|
|
148
|
+
const prng = import_node_forge.default.random.createInstance();
|
|
149
|
+
if (seedValue) {
|
|
150
|
+
prng.seedFileSync = (_n) => seedValue;
|
|
151
|
+
prng.seedFile = (_n, cb) => {
|
|
152
|
+
cb(null, seedValue);
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
const options = {
|
|
156
|
+
bits: 2048,
|
|
157
|
+
e: 65537,
|
|
158
|
+
prng
|
|
159
|
+
};
|
|
160
|
+
if (!ctx.disableWorkers) {
|
|
161
|
+
options.workLoad = 100;
|
|
162
|
+
options.workers = seedValue ? 1 : -1;
|
|
163
|
+
const workerRes = yield fetch(`${(0, import_utils.getPortalBaseURL)(ctx)}/static/js/prime.worker.min.js`);
|
|
164
|
+
const workerBlob = new Blob([yield workerRes.text()], { type: "application/javascript" });
|
|
165
|
+
options.workerScript = URL.createObjectURL(workerBlob);
|
|
166
|
+
}
|
|
167
|
+
return new Promise(
|
|
168
|
+
(resolve, reject) => rsa.generateKeyPair(options, (err, keypair) => {
|
|
169
|
+
if (err) {
|
|
170
|
+
reject(err);
|
|
171
|
+
}
|
|
172
|
+
resolve(keypair);
|
|
173
|
+
})
|
|
174
|
+
);
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
function getPublicKeyFromSignature(ctx, userHandle) {
|
|
178
|
+
return __async(this, null, function* () {
|
|
179
|
+
const encodedUserHandle = import_base64url.default.encode(userHandle);
|
|
180
|
+
const keyPair = yield getAsymmetricKeyPair(ctx, encodedUserHandle);
|
|
181
|
+
return getPublicKeyHex(keyPair);
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
function symmetricKeyEncryptMessage(message) {
|
|
185
|
+
const key = import_node_forge.default.random.getBytesSync(16);
|
|
186
|
+
const cipher = import_node_forge.default.cipher.createCipher("AES-CBC", key);
|
|
187
|
+
cipher.start({ iv: CONSTANT_IV });
|
|
188
|
+
cipher.update(import_node_forge.default.util.createBuffer(message));
|
|
189
|
+
cipher.finish();
|
|
190
|
+
const encryptedMessageHex = cipher.output.toHex();
|
|
191
|
+
return { key, encryptedMessageHex };
|
|
192
|
+
}
|
|
193
|
+
function decipherEncryptedMessageHex(key, encryptedMessageHex) {
|
|
194
|
+
const decipher = import_node_forge.default.cipher.createDecipher("AES-CBC", key);
|
|
195
|
+
decipher.start({ iv: CONSTANT_IV });
|
|
196
|
+
decipher.update(import_node_forge.default.util.createBuffer(import_node_forge.default.util.hexToBytes(encryptedMessageHex)));
|
|
197
|
+
decipher.finish();
|
|
198
|
+
return decipher.output.toString();
|
|
199
|
+
}
|
|
200
|
+
function decryptWithKeyPair(keyPair, encryptedMessageHex, encryptedKeyHex) {
|
|
201
|
+
const encryptedKey = Buffer.from(encryptedKeyHex, "hex").toString("utf-8");
|
|
202
|
+
const key = keyPair.privateKey.decrypt(encryptedKey, RSA_ENCRYPTION_SCHEME);
|
|
203
|
+
return decipherEncryptedMessageHex(key, encryptedMessageHex);
|
|
204
|
+
}
|
|
205
|
+
function decryptWithPrivateKey(privateKey, encryptedMessageHex, encryptedKeyHex) {
|
|
206
|
+
const encryptedKey = Buffer.from(encryptedKeyHex, "hex").toString("utf-8");
|
|
207
|
+
const key = privateKey.decrypt(encryptedKey, RSA_ENCRYPTION_SCHEME);
|
|
208
|
+
return decipherEncryptedMessageHex(key, encryptedMessageHex);
|
|
209
|
+
}
|
|
210
|
+
function decryptWithDerivedPrivateKey(_0, _1) {
|
|
211
|
+
return __async(this, arguments, function* (ctx, {
|
|
212
|
+
seedValue,
|
|
213
|
+
encryptedMessageHex,
|
|
214
|
+
encryptedKeyHex
|
|
215
|
+
}) {
|
|
216
|
+
const keyPair = yield getAsymmetricKeyPair(ctx, seedValue);
|
|
217
|
+
return decryptWithPrivateKey(keyPair.privateKey, encryptedMessageHex, encryptedKeyHex);
|
|
218
|
+
});
|
|
219
|
+
}
|
|
220
|
+
function getDerivedPrivateKeyAndDecrypt(ctx, seedValue, encryptedShares) {
|
|
221
|
+
return __async(this, null, function* () {
|
|
222
|
+
return Promise.all(
|
|
223
|
+
encryptedShares.map((share) => __async(this, null, function* () {
|
|
224
|
+
return {
|
|
225
|
+
walletId: share.walletId,
|
|
226
|
+
walletScheme: share.walletScheme,
|
|
227
|
+
partnerId: share.partnerId,
|
|
228
|
+
signer: yield decryptWithDerivedPrivateKey(ctx, {
|
|
229
|
+
seedValue,
|
|
230
|
+
encryptedMessageHex: share.encryptedShare,
|
|
231
|
+
encryptedKeyHex: share.encryptedKey
|
|
232
|
+
}),
|
|
233
|
+
protocolId: share.protocolId
|
|
234
|
+
};
|
|
235
|
+
}))
|
|
236
|
+
);
|
|
237
|
+
});
|
|
238
|
+
}
|
|
239
|
+
function decryptPrivateKeyAndDecryptShare(encryptionKey, encryptedShares, encryptedPrivateKey) {
|
|
240
|
+
return __async(this, null, function* () {
|
|
241
|
+
let privateKey;
|
|
242
|
+
try {
|
|
243
|
+
privateKey = yield decryptPrivateKey(encryptedPrivateKey, encryptionKey);
|
|
244
|
+
} catch (e) {
|
|
245
|
+
}
|
|
246
|
+
try {
|
|
247
|
+
privateKey = yield decryptPrivateKeyWithPassword(encryptedPrivateKey, encryptionKey);
|
|
248
|
+
} catch (e) {
|
|
249
|
+
}
|
|
250
|
+
if (!privateKey) {
|
|
251
|
+
throw new Error("Could not decrypt private key");
|
|
252
|
+
}
|
|
253
|
+
return encryptedShares.map((share) => ({
|
|
254
|
+
walletId: share.walletId,
|
|
255
|
+
walletScheme: share.walletScheme,
|
|
256
|
+
partnerId: share.partnerId,
|
|
257
|
+
signer: decryptWithPrivateKey(privateKey, share.encryptedShare, share.encryptedKey),
|
|
258
|
+
protocolId: share.protocolId
|
|
259
|
+
}));
|
|
260
|
+
});
|
|
261
|
+
}
|
|
262
|
+
function encryptWithDerivedPublicKey(publicKeyHex, message) {
|
|
263
|
+
const { key, encryptedMessageHex } = symmetricKeyEncryptMessage(message);
|
|
264
|
+
const publicKeyPem = publicKeyHexToPem(publicKeyHex);
|
|
265
|
+
const publicKey = import_node_forge.default.pki.publicKeyFromPem(publicKeyPem);
|
|
266
|
+
const encryptedKey = publicKey.encrypt(key, RSA_ENCRYPTION_SCHEME);
|
|
267
|
+
const encryptedKeyHex = Buffer.from(encryptedKey, "utf-8").toString("hex");
|
|
268
|
+
return { encryptedMessageHex, encryptedKeyHex };
|
|
269
|
+
}
|
|
270
|
+
function hashPasswordWithSalt(password) {
|
|
271
|
+
const salt = generateSalt();
|
|
272
|
+
const saltedPassword = salt + password;
|
|
273
|
+
const hash = getSHA256HashHex(saltedPassword);
|
|
274
|
+
return { salt, hash };
|
|
275
|
+
}
|
|
276
|
+
function generateSalt(length = 16) {
|
|
277
|
+
return import_node_forge.default.util.bytesToHex(import_node_forge.default.random.getBytesSync(length));
|
|
278
|
+
}
|
|
279
|
+
function deriveCryptoKeyFromPassword(hashedPassword) {
|
|
280
|
+
return __async(this, null, function* () {
|
|
281
|
+
const keyBuffer = Buffer.from(hashedPassword, "hex");
|
|
282
|
+
return yield window.crypto.subtle.importKey(
|
|
283
|
+
"raw",
|
|
284
|
+
keyBuffer,
|
|
285
|
+
{
|
|
286
|
+
name: "AES-GCM",
|
|
287
|
+
length: 256
|
|
288
|
+
},
|
|
289
|
+
true,
|
|
290
|
+
["encrypt", "decrypt"]
|
|
291
|
+
);
|
|
292
|
+
});
|
|
293
|
+
}
|
|
294
|
+
function encryptPrivateKeyWithPassword(keyPair, hashedPassword) {
|
|
295
|
+
return __async(this, null, function* () {
|
|
296
|
+
const cryptoKey = yield deriveCryptoKeyFromPassword(hashedPassword);
|
|
297
|
+
const privateKeyPemHex = encodePrivateKeyToPemHex(keyPair);
|
|
298
|
+
const encodedPlaintext = new TextEncoder().encode(privateKeyPemHex);
|
|
299
|
+
const ciphertext = yield window.crypto.subtle.encrypt(
|
|
300
|
+
{ name: "AES-GCM", iv: CONSTANT_IV_AES },
|
|
301
|
+
cryptoKey,
|
|
302
|
+
encodedPlaintext
|
|
303
|
+
);
|
|
304
|
+
return Buffer.from(ciphertext).toString("base64");
|
|
305
|
+
});
|
|
306
|
+
}
|
|
307
|
+
function decryptPrivateKeyWithPassword(encryptedPrivateKeyPemHex, hashedPassword) {
|
|
308
|
+
return __async(this, null, function* () {
|
|
309
|
+
const secretKey = yield crypto.subtle.importKey(
|
|
310
|
+
"raw",
|
|
311
|
+
Buffer.from(hashedPassword, "hex"),
|
|
312
|
+
{
|
|
313
|
+
name: "AES-GCM",
|
|
314
|
+
length: 256
|
|
315
|
+
},
|
|
316
|
+
true,
|
|
317
|
+
["encrypt", "decrypt"]
|
|
318
|
+
);
|
|
319
|
+
const cleartext = yield crypto.subtle.decrypt(
|
|
320
|
+
{ name: "AES-GCM", iv: CONSTANT_IV_AES },
|
|
321
|
+
secretKey,
|
|
322
|
+
Buffer.from(encryptedPrivateKeyPemHex, "base64")
|
|
323
|
+
);
|
|
324
|
+
const privateKeyPemHex = new TextDecoder().decode(cleartext);
|
|
325
|
+
const privateKey = decodePrivateKeyPemHex(privateKeyPemHex);
|
|
326
|
+
return privateKey;
|
|
327
|
+
});
|
|
328
|
+
}
|
|
329
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
330
|
+
0 && (module.exports = {
|
|
331
|
+
decodePrivateKeyPemHex,
|
|
332
|
+
decryptPrivateKey,
|
|
333
|
+
decryptPrivateKeyAndDecryptShare,
|
|
334
|
+
decryptPrivateKeyWithPassword,
|
|
335
|
+
decryptWithKeyPair,
|
|
336
|
+
decryptWithPrivateKey,
|
|
337
|
+
encodePrivateKeyToPemHex,
|
|
338
|
+
encryptPrivateKey,
|
|
339
|
+
encryptPrivateKeyWithPassword,
|
|
340
|
+
encryptWithDerivedPublicKey,
|
|
341
|
+
getAsymmetricKeyPair,
|
|
342
|
+
getDerivedPrivateKeyAndDecrypt,
|
|
343
|
+
getPublicKeyFromSignature,
|
|
344
|
+
getPublicKeyHex,
|
|
345
|
+
getSHA256HashHex,
|
|
346
|
+
hashPasswordWithSalt,
|
|
347
|
+
publicKeyFromHex,
|
|
348
|
+
publicKeyHexToPem,
|
|
349
|
+
symmetricKeyEncryptMessage
|
|
350
|
+
});
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
var errors_exports = {};
|
|
19
|
+
__export(errors_exports, {
|
|
20
|
+
TransactionReviewDenied: () => TransactionReviewDenied,
|
|
21
|
+
TransactionReviewError: () => TransactionReviewError,
|
|
22
|
+
TransactionReviewTimeout: () => TransactionReviewTimeout
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(errors_exports);
|
|
25
|
+
class TransactionReviewError extends Error {
|
|
26
|
+
constructor(transactionReviewUrl) {
|
|
27
|
+
super("transaction review error");
|
|
28
|
+
this.name = "TransactionReviewError";
|
|
29
|
+
this.transactionReviewUrl = transactionReviewUrl;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
class TransactionReviewDenied extends Error {
|
|
33
|
+
constructor() {
|
|
34
|
+
super("transaction review has been denied by the user");
|
|
35
|
+
this.name = "TransactionReviewDenied";
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
class TransactionReviewTimeout extends Error {
|
|
39
|
+
constructor(transactionReviewUrl, pendingTransactionId) {
|
|
40
|
+
super("transaction review has timed out");
|
|
41
|
+
this.name = "TransactionReviewTimeout";
|
|
42
|
+
this.transactionReviewUrl = transactionReviewUrl;
|
|
43
|
+
this.pendingTransactionId = pendingTransactionId;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
47
|
+
0 && (module.exports = {
|
|
48
|
+
TransactionReviewDenied,
|
|
49
|
+
TransactionReviewError,
|
|
50
|
+
TransactionReviewTimeout
|
|
51
|
+
});
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
24
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
25
|
+
mod
|
|
26
|
+
));
|
|
27
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
|
+
var mpcComputationClient_exports = {};
|
|
29
|
+
__export(mpcComputationClient_exports, {
|
|
30
|
+
initClient: () => initClient
|
|
31
|
+
});
|
|
32
|
+
module.exports = __toCommonJS(mpcComputationClient_exports);
|
|
33
|
+
var import_axios = __toESM(require("axios"));
|
|
34
|
+
function initClient(baseURL, useAdapter) {
|
|
35
|
+
const client = import_axios.default.create({ baseURL });
|
|
36
|
+
if (useAdapter) {
|
|
37
|
+
client.defaults.adapter = function(config) {
|
|
38
|
+
return fetch(config.baseURL + config.url, {
|
|
39
|
+
method: config.method,
|
|
40
|
+
headers: config.headers,
|
|
41
|
+
body: config.data,
|
|
42
|
+
credentials: config.withCredentials ? "include" : void 0
|
|
43
|
+
}).then(
|
|
44
|
+
(response) => response.text().then((text) => ({
|
|
45
|
+
data: text,
|
|
46
|
+
status: response.status,
|
|
47
|
+
statusText: response.statusText,
|
|
48
|
+
headers: response.headers,
|
|
49
|
+
config,
|
|
50
|
+
request: fetch
|
|
51
|
+
}))
|
|
52
|
+
).catch(function(reason) {
|
|
53
|
+
throw reason;
|
|
54
|
+
});
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
return client;
|
|
58
|
+
}
|
|
59
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
60
|
+
0 && (module.exports = {
|
|
61
|
+
initClient
|
|
62
|
+
});
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
24
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
25
|
+
mod
|
|
26
|
+
));
|
|
27
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
|
+
var userManagementClient_exports = {};
|
|
29
|
+
__export(userManagementClient_exports, {
|
|
30
|
+
getBaseMPCNetworkUrl: () => getBaseMPCNetworkUrl,
|
|
31
|
+
getBaseOAuthUrl: () => getBaseOAuthUrl,
|
|
32
|
+
getBaseUrl: () => getBaseUrl,
|
|
33
|
+
initClient: () => initClient
|
|
34
|
+
});
|
|
35
|
+
module.exports = __toCommonJS(userManagementClient_exports);
|
|
36
|
+
var import_user_management_client = __toESM(require("@getpara/user-management-client"));
|
|
37
|
+
var import_types = require("../types/index.js");
|
|
38
|
+
function getBaseOAuthUrl(env) {
|
|
39
|
+
switch (env) {
|
|
40
|
+
case import_types.Environment.DEV:
|
|
41
|
+
return "http://localhost:8080/";
|
|
42
|
+
case import_types.Environment.SANDBOX:
|
|
43
|
+
return "https://api.sandbox.usecapsule.com/";
|
|
44
|
+
case import_types.Environment.BETA:
|
|
45
|
+
return "https://api.beta.usecapsule.com/";
|
|
46
|
+
case import_types.Environment.PROD:
|
|
47
|
+
return "https://api.usecapsule.com/";
|
|
48
|
+
default:
|
|
49
|
+
throw new Error(`unsupported env: ${env}`);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
function getBaseUrl(env) {
|
|
53
|
+
switch (env) {
|
|
54
|
+
case import_types.Environment.DEV:
|
|
55
|
+
return "http://localhost:8080/";
|
|
56
|
+
case import_types.Environment.SANDBOX:
|
|
57
|
+
return "https://api.sandbox.getpara.com/";
|
|
58
|
+
case import_types.Environment.BETA:
|
|
59
|
+
return "https://api.beta.getpara.com/";
|
|
60
|
+
case import_types.Environment.PROD:
|
|
61
|
+
return "https://api.getpara.com/";
|
|
62
|
+
default:
|
|
63
|
+
throw new Error(`unsupported env: ${env}`);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
function getBaseMPCNetworkUrl(env, useWebsocket) {
|
|
67
|
+
const prefix = useWebsocket ? "ws" : "http";
|
|
68
|
+
switch (env) {
|
|
69
|
+
case import_types.Environment.DEV:
|
|
70
|
+
return `${prefix}://localhost:3000`;
|
|
71
|
+
case import_types.Environment.SANDBOX:
|
|
72
|
+
return `${prefix}s://mpc-network.sandbox.getpara.com`;
|
|
73
|
+
case import_types.Environment.BETA:
|
|
74
|
+
return `${prefix}s://mpc-network.beta.getpara.com`;
|
|
75
|
+
case import_types.Environment.PROD:
|
|
76
|
+
return `${prefix}s://mpc-network.prod.getpara.com`;
|
|
77
|
+
default:
|
|
78
|
+
throw new Error(`unsupported env: ${env}`);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
function initClient({
|
|
82
|
+
env,
|
|
83
|
+
version,
|
|
84
|
+
apiKey,
|
|
85
|
+
partnerId,
|
|
86
|
+
useFetchAdapter = false,
|
|
87
|
+
retrieveSessionCookie,
|
|
88
|
+
persistSessionCookie
|
|
89
|
+
}) {
|
|
90
|
+
return new import_user_management_client.default({
|
|
91
|
+
userManagementHost: getBaseUrl(env),
|
|
92
|
+
version: [import_types.Environment.DEV, import_types.Environment.SANDBOX].includes(env) ? "dev" : version,
|
|
93
|
+
apiKey,
|
|
94
|
+
partnerId,
|
|
95
|
+
opts: { useFetchAdapter },
|
|
96
|
+
retrieveSessionCookie,
|
|
97
|
+
persistSessionCookie
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
101
|
+
0 && (module.exports = {
|
|
102
|
+
getBaseMPCNetworkUrl,
|
|
103
|
+
getBaseOAuthUrl,
|
|
104
|
+
getBaseUrl,
|
|
105
|
+
initClient
|
|
106
|
+
});
|