@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
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __defProps = Object.defineProperties;
|
|
3
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
4
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
7
|
+
var __typeError = (msg) => {
|
|
8
|
+
throw TypeError(msg);
|
|
9
|
+
};
|
|
10
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
11
|
+
var __spreadValues = (a, b) => {
|
|
12
|
+
for (var prop in b || (b = {}))
|
|
13
|
+
if (__hasOwnProp.call(b, prop))
|
|
14
|
+
__defNormalProp(a, prop, b[prop]);
|
|
15
|
+
if (__getOwnPropSymbols)
|
|
16
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
17
|
+
if (__propIsEnum.call(b, prop))
|
|
18
|
+
__defNormalProp(a, prop, b[prop]);
|
|
19
|
+
}
|
|
20
|
+
return a;
|
|
21
|
+
};
|
|
22
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
23
|
+
var __objRest = (source, exclude) => {
|
|
24
|
+
var target = {};
|
|
25
|
+
for (var prop in source)
|
|
26
|
+
if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
|
|
27
|
+
target[prop] = source[prop];
|
|
28
|
+
if (source != null && __getOwnPropSymbols)
|
|
29
|
+
for (var prop of __getOwnPropSymbols(source)) {
|
|
30
|
+
if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
|
|
31
|
+
target[prop] = source[prop];
|
|
32
|
+
}
|
|
33
|
+
return target;
|
|
34
|
+
};
|
|
35
|
+
var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
|
|
36
|
+
var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
|
|
37
|
+
var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
38
|
+
var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
|
|
39
|
+
var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "access private method"), method);
|
|
40
|
+
var __async = (__this, __arguments, generator) => {
|
|
41
|
+
return new Promise((resolve, reject) => {
|
|
42
|
+
var fulfilled = (value) => {
|
|
43
|
+
try {
|
|
44
|
+
step(generator.next(value));
|
|
45
|
+
} catch (e) {
|
|
46
|
+
reject(e);
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
var rejected = (value) => {
|
|
50
|
+
try {
|
|
51
|
+
step(generator.throw(value));
|
|
52
|
+
} catch (e) {
|
|
53
|
+
reject(e);
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
57
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
|
58
|
+
});
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
export {
|
|
62
|
+
__spreadValues,
|
|
63
|
+
__spreadProps,
|
|
64
|
+
__objRest,
|
|
65
|
+
__privateGet,
|
|
66
|
+
__privateAdd,
|
|
67
|
+
__privateSet,
|
|
68
|
+
__privateMethod,
|
|
69
|
+
__async
|
|
70
|
+
};
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import "./chunk-7B52C2XE.js";
|
|
2
|
+
const PARA_CORE_VERSION = "2.0.0-alpha.3";
|
|
3
|
+
const PREFIX = "@CAPSULE/";
|
|
4
|
+
const LOCAL_STORAGE_AUTH_INFO = `${PREFIX}authInfo`;
|
|
5
|
+
const LOCAL_STORAGE_EMAIL = `${PREFIX}e-mail`;
|
|
6
|
+
const LOCAL_STORAGE_PHONE = `${PREFIX}phone`;
|
|
7
|
+
const LOCAL_STORAGE_COUNTRY_CODE = `${PREFIX}countryCode`;
|
|
8
|
+
const LOCAL_STORAGE_FARCASTER_USERNAME = `${PREFIX}farcasterUsername`;
|
|
9
|
+
const LOCAL_STORAGE_TELEGRAM_USER_ID = `${PREFIX}telegramUserId`;
|
|
10
|
+
const LOCAL_STORAGE_EXTERNAL_WALLET_USER_ID = `${PREFIX}externalWalletUserId`;
|
|
11
|
+
const LOCAL_STORAGE_USER_ID = `${PREFIX}userId`;
|
|
12
|
+
const LOCAL_STORAGE_ED25519_WALLETS = `${PREFIX}ed25519Wallets`;
|
|
13
|
+
const LOCAL_STORAGE_WALLETS = `${PREFIX}wallets`;
|
|
14
|
+
const LOCAL_STORAGE_EXTERNAL_WALLETS = `${PREFIX}externalWallets`;
|
|
15
|
+
const LOCAL_STORAGE_CURRENT_WALLET_IDS = `${PREFIX}currentWalletIds`;
|
|
16
|
+
const LOCAL_STORAGE_SESSION_COOKIE = `${PREFIX}sessionCookie`;
|
|
17
|
+
const SESSION_STORAGE_LOGIN_ENCRYPTION_KEY_PAIR = `${PREFIX}loginEncryptionKeyPair`;
|
|
18
|
+
const POLLING_INTERVAL_MS = 2e3;
|
|
19
|
+
const SHORT_POLLING_INTERVAL_MS = 1e3;
|
|
20
|
+
const POLLING_TIMEOUT_MS = 3e5;
|
|
21
|
+
const EXTERNAL_WALLET_CONNECTION_ONLY_USER_ID = "EXTERNAL_WALLET_CONNECTION_ONLY";
|
|
22
|
+
export {
|
|
23
|
+
EXTERNAL_WALLET_CONNECTION_ONLY_USER_ID,
|
|
24
|
+
LOCAL_STORAGE_AUTH_INFO,
|
|
25
|
+
LOCAL_STORAGE_COUNTRY_CODE,
|
|
26
|
+
LOCAL_STORAGE_CURRENT_WALLET_IDS,
|
|
27
|
+
LOCAL_STORAGE_ED25519_WALLETS,
|
|
28
|
+
LOCAL_STORAGE_EMAIL,
|
|
29
|
+
LOCAL_STORAGE_EXTERNAL_WALLETS,
|
|
30
|
+
LOCAL_STORAGE_EXTERNAL_WALLET_USER_ID,
|
|
31
|
+
LOCAL_STORAGE_FARCASTER_USERNAME,
|
|
32
|
+
LOCAL_STORAGE_PHONE,
|
|
33
|
+
LOCAL_STORAGE_SESSION_COOKIE,
|
|
34
|
+
LOCAL_STORAGE_TELEGRAM_USER_ID,
|
|
35
|
+
LOCAL_STORAGE_USER_ID,
|
|
36
|
+
LOCAL_STORAGE_WALLETS,
|
|
37
|
+
PARA_CORE_VERSION,
|
|
38
|
+
POLLING_INTERVAL_MS,
|
|
39
|
+
POLLING_TIMEOUT_MS,
|
|
40
|
+
PREFIX,
|
|
41
|
+
SESSION_STORAGE_LOGIN_ENCRYPTION_KEY_PAIR,
|
|
42
|
+
SHORT_POLLING_INTERVAL_MS
|
|
43
|
+
};
|
|
@@ -0,0 +1,282 @@
|
|
|
1
|
+
import {
|
|
2
|
+
__async
|
|
3
|
+
} from "../chunk-7B52C2XE.js";
|
|
4
|
+
import base64url from "base64url";
|
|
5
|
+
import forge from "node-forge";
|
|
6
|
+
import { getPortalBaseURL } from "../utils/index.js";
|
|
7
|
+
const rsa = forge.pki.rsa;
|
|
8
|
+
const RSA_ENCRYPTION_SCHEME = "RSA-OAEP";
|
|
9
|
+
const CONSTANT_IV = "794241bc819a125a7b78ea313decc0bc";
|
|
10
|
+
const CONSTANT_IV_AES = new Uint8Array([23, 66, 157, 146, 179, 158, 117, 120, 184, 73, 123, 81]);
|
|
11
|
+
function getSHA256HashHex(str) {
|
|
12
|
+
const md = forge.md.sha256.create();
|
|
13
|
+
md.update(str);
|
|
14
|
+
return md.digest().toHex();
|
|
15
|
+
}
|
|
16
|
+
function getPublicKeyHex(keyPair) {
|
|
17
|
+
const pem = forge.pki.publicKeyToRSAPublicKeyPem(keyPair.publicKey);
|
|
18
|
+
return Buffer.from(pem, "utf-8").toString("hex");
|
|
19
|
+
}
|
|
20
|
+
function publicKeyFromHex(publicKeyHex) {
|
|
21
|
+
const pem = publicKeyHexToPem(publicKeyHex);
|
|
22
|
+
return forge.pki.publicKeyFromPem(pem);
|
|
23
|
+
}
|
|
24
|
+
function publicKeyHexToPem(publicKeyHex) {
|
|
25
|
+
return Buffer.from(publicKeyHex, "hex").toString("utf-8");
|
|
26
|
+
}
|
|
27
|
+
function encodePrivateKeyToPemHex(keyPair) {
|
|
28
|
+
const pem = forge.pki.privateKeyToPem(keyPair.privateKey);
|
|
29
|
+
return Buffer.from(pem, "utf-8").toString("hex");
|
|
30
|
+
}
|
|
31
|
+
function decodePrivateKeyPemHex(privateKeyPemHex) {
|
|
32
|
+
const pem = Buffer.from(privateKeyPemHex, "hex").toString("utf-8");
|
|
33
|
+
return forge.pki.privateKeyFromPem(pem);
|
|
34
|
+
}
|
|
35
|
+
function encryptPrivateKey(keyPair, key) {
|
|
36
|
+
return __async(this, null, function* () {
|
|
37
|
+
const privateKeyPemHex = encodePrivateKeyToPemHex(keyPair);
|
|
38
|
+
const cryptoKey = yield window.crypto.subtle.importKey(
|
|
39
|
+
"raw",
|
|
40
|
+
Buffer.from(key, "base64"),
|
|
41
|
+
{
|
|
42
|
+
name: "AES-GCM",
|
|
43
|
+
length: 256
|
|
44
|
+
},
|
|
45
|
+
true,
|
|
46
|
+
["encrypt", "decrypt"]
|
|
47
|
+
);
|
|
48
|
+
const encodedPlaintext = new TextEncoder().encode(privateKeyPemHex);
|
|
49
|
+
const ciphertext = yield window.crypto.subtle.encrypt(
|
|
50
|
+
{ name: "AES-GCM", iv: CONSTANT_IV_AES },
|
|
51
|
+
cryptoKey,
|
|
52
|
+
encodedPlaintext
|
|
53
|
+
);
|
|
54
|
+
return Buffer.from(ciphertext).toString("base64");
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
function decryptPrivateKey(encryptedPrivateKeyPemHex, key) {
|
|
58
|
+
return __async(this, null, function* () {
|
|
59
|
+
const secretKey = yield crypto.subtle.importKey(
|
|
60
|
+
"raw",
|
|
61
|
+
Buffer.from(key, "base64"),
|
|
62
|
+
{
|
|
63
|
+
name: "AES-GCM",
|
|
64
|
+
length: 256
|
|
65
|
+
},
|
|
66
|
+
true,
|
|
67
|
+
["encrypt", "decrypt"]
|
|
68
|
+
);
|
|
69
|
+
const cleartext = yield crypto.subtle.decrypt(
|
|
70
|
+
{ name: "AES-GCM", iv: CONSTANT_IV_AES },
|
|
71
|
+
secretKey,
|
|
72
|
+
Buffer.from(encryptedPrivateKeyPemHex, "base64")
|
|
73
|
+
);
|
|
74
|
+
const privateKeyPemHex = new TextDecoder().decode(cleartext);
|
|
75
|
+
const privateKey = decodePrivateKeyPemHex(privateKeyPemHex);
|
|
76
|
+
return privateKey;
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
function getAsymmetricKeyPair(ctx, seedValue) {
|
|
80
|
+
return __async(this, null, function* () {
|
|
81
|
+
const prng = forge.random.createInstance();
|
|
82
|
+
if (seedValue) {
|
|
83
|
+
prng.seedFileSync = (_n) => seedValue;
|
|
84
|
+
prng.seedFile = (_n, cb) => {
|
|
85
|
+
cb(null, seedValue);
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
const options = {
|
|
89
|
+
bits: 2048,
|
|
90
|
+
e: 65537,
|
|
91
|
+
prng
|
|
92
|
+
};
|
|
93
|
+
if (!ctx.disableWorkers) {
|
|
94
|
+
options.workLoad = 100;
|
|
95
|
+
options.workers = seedValue ? 1 : -1;
|
|
96
|
+
const workerRes = yield fetch(`${getPortalBaseURL(ctx)}/static/js/prime.worker.min.js`);
|
|
97
|
+
const workerBlob = new Blob([yield workerRes.text()], { type: "application/javascript" });
|
|
98
|
+
options.workerScript = URL.createObjectURL(workerBlob);
|
|
99
|
+
}
|
|
100
|
+
return new Promise(
|
|
101
|
+
(resolve, reject) => rsa.generateKeyPair(options, (err, keypair) => {
|
|
102
|
+
if (err) {
|
|
103
|
+
reject(err);
|
|
104
|
+
}
|
|
105
|
+
resolve(keypair);
|
|
106
|
+
})
|
|
107
|
+
);
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
function getPublicKeyFromSignature(ctx, userHandle) {
|
|
111
|
+
return __async(this, null, function* () {
|
|
112
|
+
const encodedUserHandle = base64url.encode(userHandle);
|
|
113
|
+
const keyPair = yield getAsymmetricKeyPair(ctx, encodedUserHandle);
|
|
114
|
+
return getPublicKeyHex(keyPair);
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
function symmetricKeyEncryptMessage(message) {
|
|
118
|
+
const key = forge.random.getBytesSync(16);
|
|
119
|
+
const cipher = forge.cipher.createCipher("AES-CBC", key);
|
|
120
|
+
cipher.start({ iv: CONSTANT_IV });
|
|
121
|
+
cipher.update(forge.util.createBuffer(message));
|
|
122
|
+
cipher.finish();
|
|
123
|
+
const encryptedMessageHex = cipher.output.toHex();
|
|
124
|
+
return { key, encryptedMessageHex };
|
|
125
|
+
}
|
|
126
|
+
function decipherEncryptedMessageHex(key, encryptedMessageHex) {
|
|
127
|
+
const decipher = forge.cipher.createDecipher("AES-CBC", key);
|
|
128
|
+
decipher.start({ iv: CONSTANT_IV });
|
|
129
|
+
decipher.update(forge.util.createBuffer(forge.util.hexToBytes(encryptedMessageHex)));
|
|
130
|
+
decipher.finish();
|
|
131
|
+
return decipher.output.toString();
|
|
132
|
+
}
|
|
133
|
+
function decryptWithKeyPair(keyPair, encryptedMessageHex, encryptedKeyHex) {
|
|
134
|
+
const encryptedKey = Buffer.from(encryptedKeyHex, "hex").toString("utf-8");
|
|
135
|
+
const key = keyPair.privateKey.decrypt(encryptedKey, RSA_ENCRYPTION_SCHEME);
|
|
136
|
+
return decipherEncryptedMessageHex(key, encryptedMessageHex);
|
|
137
|
+
}
|
|
138
|
+
function decryptWithPrivateKey(privateKey, encryptedMessageHex, encryptedKeyHex) {
|
|
139
|
+
const encryptedKey = Buffer.from(encryptedKeyHex, "hex").toString("utf-8");
|
|
140
|
+
const key = privateKey.decrypt(encryptedKey, RSA_ENCRYPTION_SCHEME);
|
|
141
|
+
return decipherEncryptedMessageHex(key, encryptedMessageHex);
|
|
142
|
+
}
|
|
143
|
+
function decryptWithDerivedPrivateKey(_0, _1) {
|
|
144
|
+
return __async(this, arguments, function* (ctx, {
|
|
145
|
+
seedValue,
|
|
146
|
+
encryptedMessageHex,
|
|
147
|
+
encryptedKeyHex
|
|
148
|
+
}) {
|
|
149
|
+
const keyPair = yield getAsymmetricKeyPair(ctx, seedValue);
|
|
150
|
+
return decryptWithPrivateKey(keyPair.privateKey, encryptedMessageHex, encryptedKeyHex);
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
function getDerivedPrivateKeyAndDecrypt(ctx, seedValue, encryptedShares) {
|
|
154
|
+
return __async(this, null, function* () {
|
|
155
|
+
return Promise.all(
|
|
156
|
+
encryptedShares.map((share) => __async(this, null, function* () {
|
|
157
|
+
return {
|
|
158
|
+
walletId: share.walletId,
|
|
159
|
+
walletScheme: share.walletScheme,
|
|
160
|
+
partnerId: share.partnerId,
|
|
161
|
+
signer: yield decryptWithDerivedPrivateKey(ctx, {
|
|
162
|
+
seedValue,
|
|
163
|
+
encryptedMessageHex: share.encryptedShare,
|
|
164
|
+
encryptedKeyHex: share.encryptedKey
|
|
165
|
+
}),
|
|
166
|
+
protocolId: share.protocolId
|
|
167
|
+
};
|
|
168
|
+
}))
|
|
169
|
+
);
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
function decryptPrivateKeyAndDecryptShare(encryptionKey, encryptedShares, encryptedPrivateKey) {
|
|
173
|
+
return __async(this, null, function* () {
|
|
174
|
+
let privateKey;
|
|
175
|
+
try {
|
|
176
|
+
privateKey = yield decryptPrivateKey(encryptedPrivateKey, encryptionKey);
|
|
177
|
+
} catch (e) {
|
|
178
|
+
}
|
|
179
|
+
try {
|
|
180
|
+
privateKey = yield decryptPrivateKeyWithPassword(encryptedPrivateKey, encryptionKey);
|
|
181
|
+
} catch (e) {
|
|
182
|
+
}
|
|
183
|
+
if (!privateKey) {
|
|
184
|
+
throw new Error("Could not decrypt private key");
|
|
185
|
+
}
|
|
186
|
+
return encryptedShares.map((share) => ({
|
|
187
|
+
walletId: share.walletId,
|
|
188
|
+
walletScheme: share.walletScheme,
|
|
189
|
+
partnerId: share.partnerId,
|
|
190
|
+
signer: decryptWithPrivateKey(privateKey, share.encryptedShare, share.encryptedKey),
|
|
191
|
+
protocolId: share.protocolId
|
|
192
|
+
}));
|
|
193
|
+
});
|
|
194
|
+
}
|
|
195
|
+
function encryptWithDerivedPublicKey(publicKeyHex, message) {
|
|
196
|
+
const { key, encryptedMessageHex } = symmetricKeyEncryptMessage(message);
|
|
197
|
+
const publicKeyPem = publicKeyHexToPem(publicKeyHex);
|
|
198
|
+
const publicKey = forge.pki.publicKeyFromPem(publicKeyPem);
|
|
199
|
+
const encryptedKey = publicKey.encrypt(key, RSA_ENCRYPTION_SCHEME);
|
|
200
|
+
const encryptedKeyHex = Buffer.from(encryptedKey, "utf-8").toString("hex");
|
|
201
|
+
return { encryptedMessageHex, encryptedKeyHex };
|
|
202
|
+
}
|
|
203
|
+
function hashPasswordWithSalt(password) {
|
|
204
|
+
const salt = generateSalt();
|
|
205
|
+
const saltedPassword = salt + password;
|
|
206
|
+
const hash = getSHA256HashHex(saltedPassword);
|
|
207
|
+
return { salt, hash };
|
|
208
|
+
}
|
|
209
|
+
function generateSalt(length = 16) {
|
|
210
|
+
return forge.util.bytesToHex(forge.random.getBytesSync(length));
|
|
211
|
+
}
|
|
212
|
+
function deriveCryptoKeyFromPassword(hashedPassword) {
|
|
213
|
+
return __async(this, null, function* () {
|
|
214
|
+
const keyBuffer = Buffer.from(hashedPassword, "hex");
|
|
215
|
+
return yield window.crypto.subtle.importKey(
|
|
216
|
+
"raw",
|
|
217
|
+
keyBuffer,
|
|
218
|
+
{
|
|
219
|
+
name: "AES-GCM",
|
|
220
|
+
length: 256
|
|
221
|
+
},
|
|
222
|
+
true,
|
|
223
|
+
["encrypt", "decrypt"]
|
|
224
|
+
);
|
|
225
|
+
});
|
|
226
|
+
}
|
|
227
|
+
function encryptPrivateKeyWithPassword(keyPair, hashedPassword) {
|
|
228
|
+
return __async(this, null, function* () {
|
|
229
|
+
const cryptoKey = yield deriveCryptoKeyFromPassword(hashedPassword);
|
|
230
|
+
const privateKeyPemHex = encodePrivateKeyToPemHex(keyPair);
|
|
231
|
+
const encodedPlaintext = new TextEncoder().encode(privateKeyPemHex);
|
|
232
|
+
const ciphertext = yield window.crypto.subtle.encrypt(
|
|
233
|
+
{ name: "AES-GCM", iv: CONSTANT_IV_AES },
|
|
234
|
+
cryptoKey,
|
|
235
|
+
encodedPlaintext
|
|
236
|
+
);
|
|
237
|
+
return Buffer.from(ciphertext).toString("base64");
|
|
238
|
+
});
|
|
239
|
+
}
|
|
240
|
+
function decryptPrivateKeyWithPassword(encryptedPrivateKeyPemHex, hashedPassword) {
|
|
241
|
+
return __async(this, null, function* () {
|
|
242
|
+
const secretKey = yield crypto.subtle.importKey(
|
|
243
|
+
"raw",
|
|
244
|
+
Buffer.from(hashedPassword, "hex"),
|
|
245
|
+
{
|
|
246
|
+
name: "AES-GCM",
|
|
247
|
+
length: 256
|
|
248
|
+
},
|
|
249
|
+
true,
|
|
250
|
+
["encrypt", "decrypt"]
|
|
251
|
+
);
|
|
252
|
+
const cleartext = yield crypto.subtle.decrypt(
|
|
253
|
+
{ name: "AES-GCM", iv: CONSTANT_IV_AES },
|
|
254
|
+
secretKey,
|
|
255
|
+
Buffer.from(encryptedPrivateKeyPemHex, "base64")
|
|
256
|
+
);
|
|
257
|
+
const privateKeyPemHex = new TextDecoder().decode(cleartext);
|
|
258
|
+
const privateKey = decodePrivateKeyPemHex(privateKeyPemHex);
|
|
259
|
+
return privateKey;
|
|
260
|
+
});
|
|
261
|
+
}
|
|
262
|
+
export {
|
|
263
|
+
decodePrivateKeyPemHex,
|
|
264
|
+
decryptPrivateKey,
|
|
265
|
+
decryptPrivateKeyAndDecryptShare,
|
|
266
|
+
decryptPrivateKeyWithPassword,
|
|
267
|
+
decryptWithKeyPair,
|
|
268
|
+
decryptWithPrivateKey,
|
|
269
|
+
encodePrivateKeyToPemHex,
|
|
270
|
+
encryptPrivateKey,
|
|
271
|
+
encryptPrivateKeyWithPassword,
|
|
272
|
+
encryptWithDerivedPublicKey,
|
|
273
|
+
getAsymmetricKeyPair,
|
|
274
|
+
getDerivedPrivateKeyAndDecrypt,
|
|
275
|
+
getPublicKeyFromSignature,
|
|
276
|
+
getPublicKeyHex,
|
|
277
|
+
getSHA256HashHex,
|
|
278
|
+
hashPasswordWithSalt,
|
|
279
|
+
publicKeyFromHex,
|
|
280
|
+
publicKeyHexToPem,
|
|
281
|
+
symmetricKeyEncryptMessage
|
|
282
|
+
};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import "./chunk-7B52C2XE.js";
|
|
2
|
+
class TransactionReviewError extends Error {
|
|
3
|
+
constructor(transactionReviewUrl) {
|
|
4
|
+
super("transaction review error");
|
|
5
|
+
this.name = "TransactionReviewError";
|
|
6
|
+
this.transactionReviewUrl = transactionReviewUrl;
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
class TransactionReviewDenied extends Error {
|
|
10
|
+
constructor() {
|
|
11
|
+
super("transaction review has been denied by the user");
|
|
12
|
+
this.name = "TransactionReviewDenied";
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
class TransactionReviewTimeout extends Error {
|
|
16
|
+
constructor(transactionReviewUrl, pendingTransactionId) {
|
|
17
|
+
super("transaction review has timed out");
|
|
18
|
+
this.name = "TransactionReviewTimeout";
|
|
19
|
+
this.transactionReviewUrl = transactionReviewUrl;
|
|
20
|
+
this.pendingTransactionId = pendingTransactionId;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
export {
|
|
24
|
+
TransactionReviewDenied,
|
|
25
|
+
TransactionReviewError,
|
|
26
|
+
TransactionReviewTimeout
|
|
27
|
+
};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import "../chunk-7B52C2XE.js";
|
|
2
|
+
import axios from "axios";
|
|
3
|
+
function initClient(baseURL, useAdapter) {
|
|
4
|
+
const client = axios.create({ baseURL });
|
|
5
|
+
if (useAdapter) {
|
|
6
|
+
client.defaults.adapter = function(config) {
|
|
7
|
+
return fetch(config.baseURL + config.url, {
|
|
8
|
+
method: config.method,
|
|
9
|
+
headers: config.headers,
|
|
10
|
+
body: config.data,
|
|
11
|
+
credentials: config.withCredentials ? "include" : void 0
|
|
12
|
+
}).then(
|
|
13
|
+
(response) => response.text().then((text) => ({
|
|
14
|
+
data: text,
|
|
15
|
+
status: response.status,
|
|
16
|
+
statusText: response.statusText,
|
|
17
|
+
headers: response.headers,
|
|
18
|
+
config,
|
|
19
|
+
request: fetch
|
|
20
|
+
}))
|
|
21
|
+
).catch(function(reason) {
|
|
22
|
+
throw reason;
|
|
23
|
+
});
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
return client;
|
|
27
|
+
}
|
|
28
|
+
export {
|
|
29
|
+
initClient
|
|
30
|
+
};
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import "../chunk-7B52C2XE.js";
|
|
2
|
+
import Client from "@getpara/user-management-client";
|
|
3
|
+
import { Environment } from "../types/index.js";
|
|
4
|
+
function getBaseOAuthUrl(env) {
|
|
5
|
+
switch (env) {
|
|
6
|
+
case Environment.DEV:
|
|
7
|
+
return "http://localhost:8080/";
|
|
8
|
+
case Environment.SANDBOX:
|
|
9
|
+
return "https://api.sandbox.usecapsule.com/";
|
|
10
|
+
case Environment.BETA:
|
|
11
|
+
return "https://api.beta.usecapsule.com/";
|
|
12
|
+
case Environment.PROD:
|
|
13
|
+
return "https://api.usecapsule.com/";
|
|
14
|
+
default:
|
|
15
|
+
throw new Error(`unsupported env: ${env}`);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
function getBaseUrl(env) {
|
|
19
|
+
switch (env) {
|
|
20
|
+
case Environment.DEV:
|
|
21
|
+
return "http://localhost:8080/";
|
|
22
|
+
case Environment.SANDBOX:
|
|
23
|
+
return "https://api.sandbox.getpara.com/";
|
|
24
|
+
case Environment.BETA:
|
|
25
|
+
return "https://api.beta.getpara.com/";
|
|
26
|
+
case Environment.PROD:
|
|
27
|
+
return "https://api.getpara.com/";
|
|
28
|
+
default:
|
|
29
|
+
throw new Error(`unsupported env: ${env}`);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
function getBaseMPCNetworkUrl(env, useWebsocket) {
|
|
33
|
+
const prefix = useWebsocket ? "ws" : "http";
|
|
34
|
+
switch (env) {
|
|
35
|
+
case Environment.DEV:
|
|
36
|
+
return `${prefix}://localhost:3000`;
|
|
37
|
+
case Environment.SANDBOX:
|
|
38
|
+
return `${prefix}s://mpc-network.sandbox.getpara.com`;
|
|
39
|
+
case Environment.BETA:
|
|
40
|
+
return `${prefix}s://mpc-network.beta.getpara.com`;
|
|
41
|
+
case Environment.PROD:
|
|
42
|
+
return `${prefix}s://mpc-network.prod.getpara.com`;
|
|
43
|
+
default:
|
|
44
|
+
throw new Error(`unsupported env: ${env}`);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
function initClient({
|
|
48
|
+
env,
|
|
49
|
+
version,
|
|
50
|
+
apiKey,
|
|
51
|
+
partnerId,
|
|
52
|
+
useFetchAdapter = false,
|
|
53
|
+
retrieveSessionCookie,
|
|
54
|
+
persistSessionCookie
|
|
55
|
+
}) {
|
|
56
|
+
return new Client({
|
|
57
|
+
userManagementHost: getBaseUrl(env),
|
|
58
|
+
version: [Environment.DEV, Environment.SANDBOX].includes(env) ? "dev" : version,
|
|
59
|
+
apiKey,
|
|
60
|
+
partnerId,
|
|
61
|
+
opts: { useFetchAdapter },
|
|
62
|
+
retrieveSessionCookie,
|
|
63
|
+
persistSessionCookie
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
export {
|
|
67
|
+
getBaseMPCNetworkUrl,
|
|
68
|
+
getBaseOAuthUrl,
|
|
69
|
+
getBaseUrl,
|
|
70
|
+
initClient
|
|
71
|
+
};
|