@getpara/core-sdk 1.2.0 → 1.3.1
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/.!4351!index.js.br +0 -0
- package/dist/cjs/.!4353!index.js.gz +0 -0
- package/dist/cjs/index.js +2 -97
- package/dist/cjs/index.js.br +0 -0
- package/dist/cjs/index.js.gz +0 -0
- package/dist/esm/.!4345!index.js.br +0 -0
- package/dist/esm/.!4347!index.js.gz +0 -0
- package/dist/esm/index.js +2 -23
- package/dist/esm/index.js.br +0 -0
- package/dist/esm/index.js.gz +0 -0
- package/package.json +7 -7
- package/dist/cjs/ParaCore.js +0 -2620
- package/dist/cjs/PlatformUtils.js +0 -2
- package/dist/cjs/StorageUtils.js +0 -2
- package/dist/cjs/constants.js +0 -20
- package/dist/cjs/cryptography/utils.js +0 -251
- package/dist/cjs/errors.js +0 -27
- package/dist/cjs/external/mpcComputationClient.js +0 -33
- package/dist/cjs/external/userManagementClient.js +0 -66
- package/dist/cjs/package.json +0 -1
- package/dist/cjs/shares/KeyContainer.js +0 -84
- package/dist/cjs/shares/recovery.js +0 -62
- package/dist/cjs/shares/shareDistribution.js +0 -67
- package/dist/cjs/transmission/transmissionUtils.js +0 -73
- package/dist/cjs/types/config.js +0 -22
- package/dist/cjs/types/events.js +0 -17
- package/dist/cjs/types/index.js +0 -30
- package/dist/cjs/types/onRamps.js +0 -10
- package/dist/cjs/types/params.js +0 -2
- package/dist/cjs/types/popup.js +0 -12
- package/dist/cjs/types/recovery.js +0 -12
- package/dist/cjs/types/theme.js +0 -2
- package/dist/cjs/types/wallet.js +0 -9
- package/dist/cjs/utils/events.js +0 -9
- package/dist/cjs/utils/formatting.js +0 -81
- package/dist/cjs/utils/index.js +0 -22
- package/dist/cjs/utils/onRamps.js +0 -36
- package/dist/cjs/utils/polling.js +0 -25
- package/dist/cjs/utils/url.js +0 -74
- package/dist/cjs/utils/wallet.js +0 -74
- package/dist/esm/ParaCore.js +0 -2590
- package/dist/esm/PlatformUtils.js +0 -1
- package/dist/esm/StorageUtils.js +0 -1
- package/dist/esm/constants.js +0 -17
- package/dist/esm/cryptography/utils.js +0 -226
- package/dist/esm/errors.js +0 -21
- package/dist/esm/external/mpcComputationClient.js +0 -26
- package/dist/esm/external/userManagementClient.js +0 -56
- package/dist/esm/package.json +0 -1
- package/dist/esm/shares/KeyContainer.js +0 -57
- package/dist/esm/shares/recovery.js +0 -58
- package/dist/esm/shares/shareDistribution.js +0 -63
- package/dist/esm/transmission/transmissionUtils.js +0 -45
- package/dist/esm/types/config.js +0 -19
- package/dist/esm/types/events.js +0 -14
- package/dist/esm/types/index.js +0 -9
- package/dist/esm/types/onRamps.js +0 -7
- package/dist/esm/types/params.js +0 -1
- package/dist/esm/types/popup.js +0 -9
- package/dist/esm/types/recovery.js +0 -9
- package/dist/esm/types/theme.js +0 -1
- package/dist/esm/types/wallet.js +0 -6
- package/dist/esm/utils/events.js +0 -5
- package/dist/esm/utils/formatting.js +0 -66
- package/dist/esm/utils/index.js +0 -6
- package/dist/esm/utils/onRamps.js +0 -30
- package/dist/esm/utils/polling.js +0 -21
- package/dist/esm/utils/url.js +0 -66
- package/dist/esm/utils/wallet.js +0 -64
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/dist/esm/StorageUtils.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/dist/esm/constants.js
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
export const PARA_CORE_VERSION = '1.2.0';
|
|
2
|
-
export const PREFIX = '@CAPSULE/';
|
|
3
|
-
export const LOCAL_STORAGE_EMAIL = `${PREFIX}e-mail`;
|
|
4
|
-
export const LOCAL_STORAGE_PHONE = `${PREFIX}phone`;
|
|
5
|
-
export const LOCAL_STORAGE_COUNTRY_CODE = `${PREFIX}countryCode`;
|
|
6
|
-
export const LOCAL_STORAGE_FARCASTER_USERNAME = `${PREFIX}farcasterUsername`;
|
|
7
|
-
export const LOCAL_STORAGE_TELEGRAM_USER_ID = `${PREFIX}telegramUserId`;
|
|
8
|
-
export const LOCAL_STORAGE_USER_ID = `${PREFIX}userId`;
|
|
9
|
-
export const LOCAL_STORAGE_ED25519_WALLETS = `${PREFIX}ed25519Wallets`;
|
|
10
|
-
export const LOCAL_STORAGE_WALLETS = `${PREFIX}wallets`;
|
|
11
|
-
export const LOCAL_STORAGE_EXTERNAL_WALLETS = `${PREFIX}externalWallets`;
|
|
12
|
-
export const LOCAL_STORAGE_CURRENT_WALLET_IDS = `${PREFIX}currentWalletIds`;
|
|
13
|
-
export const LOCAL_STORAGE_CURRENT_EXTERNAL_WALLET_ADDRESSES = `${PREFIX}currentExternalWalletAddresses`;
|
|
14
|
-
export const LOCAL_STORAGE_SESSION_COOKIE = `${PREFIX}sessionCookie`;
|
|
15
|
-
export const SESSION_STORAGE_LOGIN_ENCRYPTION_KEY_PAIR = `${PREFIX}loginEncryptionKeyPair`;
|
|
16
|
-
export const POLLING_INTERVAL_MS = 2000;
|
|
17
|
-
export const SHORT_POLLING_INTERVAL_MS = 1000;
|
|
@@ -1,226 +0,0 @@
|
|
|
1
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
|
-
import base64url from 'base64url';
|
|
11
|
-
import forge from 'node-forge';
|
|
12
|
-
import { getPortalBaseURL } from '../utils/index.js';
|
|
13
|
-
const rsa = forge.pki.rsa;
|
|
14
|
-
const RSA_ENCRYPTION_SCHEME = 'RSA-OAEP';
|
|
15
|
-
// ivs can be constant only because every key is only ever used to encrypt one message
|
|
16
|
-
const CONSTANT_IV = '794241bc819a125a7b78ea313decc0bc';
|
|
17
|
-
const CONSTANT_IV_AES = new Uint8Array([23, 66, 157, 146, 179, 158, 117, 120, 184, 73, 123, 81]);
|
|
18
|
-
export function getSHA256HashHex(str) {
|
|
19
|
-
const md = forge.md.sha256.create();
|
|
20
|
-
md.update(str);
|
|
21
|
-
return md.digest().toHex();
|
|
22
|
-
}
|
|
23
|
-
export function getPublicKeyHex(keyPair) {
|
|
24
|
-
const pem = forge.pki.publicKeyToRSAPublicKeyPem(keyPair.publicKey);
|
|
25
|
-
return Buffer.from(pem, 'utf-8').toString('hex');
|
|
26
|
-
}
|
|
27
|
-
export function publicKeyFromHex(publicKeyHex) {
|
|
28
|
-
const pem = publicKeyHexToPem(publicKeyHex);
|
|
29
|
-
return forge.pki.publicKeyFromPem(pem);
|
|
30
|
-
}
|
|
31
|
-
export function publicKeyHexToPem(publicKeyHex) {
|
|
32
|
-
return Buffer.from(publicKeyHex, 'hex').toString('utf-8');
|
|
33
|
-
}
|
|
34
|
-
export function encodePrivateKeyToPemHex(keyPair) {
|
|
35
|
-
const pem = forge.pki.privateKeyToPem(keyPair.privateKey);
|
|
36
|
-
return Buffer.from(pem, 'utf-8').toString('hex');
|
|
37
|
-
}
|
|
38
|
-
export function decodePrivateKeyPemHex(privateKeyPemHex) {
|
|
39
|
-
const pem = Buffer.from(privateKeyPemHex, 'hex').toString('utf-8');
|
|
40
|
-
return forge.pki.privateKeyFromPem(pem);
|
|
41
|
-
}
|
|
42
|
-
export function encryptPrivateKey(keyPair, key) {
|
|
43
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
44
|
-
const privateKeyPemHex = encodePrivateKeyToPemHex(keyPair);
|
|
45
|
-
const cryptoKey = yield window.crypto.subtle.importKey('raw', Buffer.from(key, 'base64'), {
|
|
46
|
-
name: 'AES-GCM',
|
|
47
|
-
length: 256,
|
|
48
|
-
}, true, ['encrypt', 'decrypt']);
|
|
49
|
-
const encodedPlaintext = new TextEncoder().encode(privateKeyPemHex);
|
|
50
|
-
const ciphertext = yield window.crypto.subtle.encrypt({ name: 'AES-GCM', iv: CONSTANT_IV_AES }, cryptoKey, encodedPlaintext);
|
|
51
|
-
return Buffer.from(ciphertext).toString('base64');
|
|
52
|
-
});
|
|
53
|
-
}
|
|
54
|
-
export function decryptPrivateKey(encryptedPrivateKeyPemHex, key) {
|
|
55
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
56
|
-
const secretKey = yield crypto.subtle.importKey('raw', Buffer.from(key, 'base64'), {
|
|
57
|
-
name: 'AES-GCM',
|
|
58
|
-
length: 256,
|
|
59
|
-
}, true, ['encrypt', 'decrypt']);
|
|
60
|
-
const cleartext = yield crypto.subtle.decrypt({ name: 'AES-GCM', iv: CONSTANT_IV_AES }, secretKey, Buffer.from(encryptedPrivateKeyPemHex, 'base64'));
|
|
61
|
-
const privateKeyPemHex = new TextDecoder().decode(cleartext);
|
|
62
|
-
const privateKey = decodePrivateKeyPemHex(privateKeyPemHex);
|
|
63
|
-
return privateKey;
|
|
64
|
-
});
|
|
65
|
-
}
|
|
66
|
-
export function getAsymmetricKeyPair(ctx, seedValue) {
|
|
67
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
68
|
-
const prng = forge.random.createInstance();
|
|
69
|
-
if (seedValue) {
|
|
70
|
-
prng.seedFileSync = (_n) => seedValue;
|
|
71
|
-
prng.seedFile = (_n, cb) => {
|
|
72
|
-
cb(null, seedValue);
|
|
73
|
-
};
|
|
74
|
-
}
|
|
75
|
-
const options = {
|
|
76
|
-
bits: 2048,
|
|
77
|
-
e: 65537,
|
|
78
|
-
prng,
|
|
79
|
-
};
|
|
80
|
-
if (!ctx.disableWorkers) {
|
|
81
|
-
options.workLoad = 100;
|
|
82
|
-
// only using 1 web worker as more makes the call non-deterministic
|
|
83
|
-
// -1 uses optimal amount of web workers
|
|
84
|
-
options.workers = seedValue ? 1 : -1;
|
|
85
|
-
const workerRes = yield fetch(`${getPortalBaseURL(ctx)}/static/js/prime.worker.min.js`);
|
|
86
|
-
const workerBlob = new Blob([yield workerRes.text()], { type: 'application/javascript' });
|
|
87
|
-
options.workerScript = URL.createObjectURL(workerBlob);
|
|
88
|
-
}
|
|
89
|
-
return new Promise((resolve, reject) => rsa.generateKeyPair(options, (err, keypair) => {
|
|
90
|
-
if (err) {
|
|
91
|
-
reject(err);
|
|
92
|
-
}
|
|
93
|
-
resolve(keypair);
|
|
94
|
-
}));
|
|
95
|
-
});
|
|
96
|
-
}
|
|
97
|
-
export function getPublicKeyFromSignature(ctx, userHandle) {
|
|
98
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
99
|
-
const encodedUserHandle = base64url.encode(userHandle);
|
|
100
|
-
const keyPair = yield getAsymmetricKeyPair(ctx, encodedUserHandle);
|
|
101
|
-
return getPublicKeyHex(keyPair);
|
|
102
|
-
});
|
|
103
|
-
}
|
|
104
|
-
// only use for one time key encryptions as iv is constant
|
|
105
|
-
export function symmetricKeyEncryptMessage(message) {
|
|
106
|
-
const key = forge.random.getBytesSync(16);
|
|
107
|
-
const cipher = forge.cipher.createCipher('AES-CBC', key);
|
|
108
|
-
// iv can be constant only because every key is only ever used to encrypt one message
|
|
109
|
-
cipher.start({ iv: CONSTANT_IV });
|
|
110
|
-
cipher.update(forge.util.createBuffer(message));
|
|
111
|
-
cipher.finish();
|
|
112
|
-
const encryptedMessageHex = cipher.output.toHex();
|
|
113
|
-
return { key, encryptedMessageHex };
|
|
114
|
-
}
|
|
115
|
-
function decipherEncryptedMessageHex(key, encryptedMessageHex) {
|
|
116
|
-
const decipher = forge.cipher.createDecipher('AES-CBC', key);
|
|
117
|
-
// iv can be constant only because every key is only ever used to encrypt one message
|
|
118
|
-
decipher.start({ iv: CONSTANT_IV });
|
|
119
|
-
decipher.update(forge.util.createBuffer(forge.util.hexToBytes(encryptedMessageHex)));
|
|
120
|
-
decipher.finish();
|
|
121
|
-
return decipher.output.toString();
|
|
122
|
-
}
|
|
123
|
-
// Deprecated in favor of decryptWithPrivateKey
|
|
124
|
-
export function decryptWithKeyPair(keyPair, encryptedMessageHex, encryptedKeyHex) {
|
|
125
|
-
const encryptedKey = Buffer.from(encryptedKeyHex, 'hex').toString('utf-8');
|
|
126
|
-
const key = keyPair.privateKey.decrypt(encryptedKey, RSA_ENCRYPTION_SCHEME);
|
|
127
|
-
return decipherEncryptedMessageHex(key, encryptedMessageHex);
|
|
128
|
-
}
|
|
129
|
-
export function decryptWithPrivateKey(privateKey, encryptedMessageHex, encryptedKeyHex) {
|
|
130
|
-
const encryptedKey = Buffer.from(encryptedKeyHex, 'hex').toString('utf-8');
|
|
131
|
-
const key = privateKey.decrypt(encryptedKey, RSA_ENCRYPTION_SCHEME);
|
|
132
|
-
return decipherEncryptedMessageHex(key, encryptedMessageHex);
|
|
133
|
-
}
|
|
134
|
-
function decryptWithDerivedPrivateKey(ctx, { seedValue, encryptedMessageHex, encryptedKeyHex, }) {
|
|
135
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
136
|
-
const keyPair = yield getAsymmetricKeyPair(ctx, seedValue);
|
|
137
|
-
return decryptWithPrivateKey(keyPair.privateKey, encryptedMessageHex, encryptedKeyHex);
|
|
138
|
-
});
|
|
139
|
-
}
|
|
140
|
-
export function getDerivedPrivateKeyAndDecrypt(ctx, seedValue, encryptedShares) {
|
|
141
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
142
|
-
return Promise.all(encryptedShares.map((share) => __awaiter(this, void 0, void 0, function* () {
|
|
143
|
-
return ({
|
|
144
|
-
walletId: share.walletId,
|
|
145
|
-
walletScheme: share.walletScheme,
|
|
146
|
-
partnerId: share.partnerId,
|
|
147
|
-
signer: yield decryptWithDerivedPrivateKey(ctx, {
|
|
148
|
-
seedValue,
|
|
149
|
-
encryptedMessageHex: share.encryptedShare,
|
|
150
|
-
encryptedKeyHex: share.encryptedKey,
|
|
151
|
-
}),
|
|
152
|
-
protocolId: share.protocolId,
|
|
153
|
-
});
|
|
154
|
-
})));
|
|
155
|
-
});
|
|
156
|
-
}
|
|
157
|
-
export function decryptPrivateKeyAndDecryptShare(encryptionKey, encryptedShares, encryptedPrivateKey) {
|
|
158
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
159
|
-
let privateKey;
|
|
160
|
-
try {
|
|
161
|
-
privateKey = yield decryptPrivateKey(encryptedPrivateKey, encryptionKey);
|
|
162
|
-
}
|
|
163
|
-
catch (e) { }
|
|
164
|
-
try {
|
|
165
|
-
privateKey = yield decryptPrivateKeyWithPassword(encryptedPrivateKey, encryptionKey);
|
|
166
|
-
}
|
|
167
|
-
catch (e) { }
|
|
168
|
-
if (!privateKey) {
|
|
169
|
-
throw new Error('Could not decrypt private key');
|
|
170
|
-
}
|
|
171
|
-
return encryptedShares.map(share => ({
|
|
172
|
-
walletId: share.walletId,
|
|
173
|
-
walletScheme: share.walletScheme,
|
|
174
|
-
partnerId: share.partnerId,
|
|
175
|
-
signer: decryptWithPrivateKey(privateKey, share.encryptedShare, share.encryptedKey),
|
|
176
|
-
protocolId: share.protocolId,
|
|
177
|
-
}));
|
|
178
|
-
});
|
|
179
|
-
}
|
|
180
|
-
export function encryptWithDerivedPublicKey(publicKeyHex, message) {
|
|
181
|
-
const { key, encryptedMessageHex } = symmetricKeyEncryptMessage(message);
|
|
182
|
-
const publicKeyPem = publicKeyHexToPem(publicKeyHex);
|
|
183
|
-
const publicKey = forge.pki.publicKeyFromPem(publicKeyPem);
|
|
184
|
-
const encryptedKey = publicKey.encrypt(key, RSA_ENCRYPTION_SCHEME);
|
|
185
|
-
const encryptedKeyHex = Buffer.from(encryptedKey, 'utf-8').toString('hex');
|
|
186
|
-
return { encryptedMessageHex, encryptedKeyHex };
|
|
187
|
-
}
|
|
188
|
-
export function hashPasswordWithSalt(password) {
|
|
189
|
-
const salt = generateSalt();
|
|
190
|
-
const saltedPassword = salt + password;
|
|
191
|
-
const hash = getSHA256HashHex(saltedPassword);
|
|
192
|
-
return { salt, hash };
|
|
193
|
-
}
|
|
194
|
-
function generateSalt(length = 16) {
|
|
195
|
-
return forge.util.bytesToHex(forge.random.getBytesSync(length));
|
|
196
|
-
}
|
|
197
|
-
function deriveCryptoKeyFromPassword(hashedPassword) {
|
|
198
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
199
|
-
const keyBuffer = Buffer.from(hashedPassword, 'hex');
|
|
200
|
-
return yield window.crypto.subtle.importKey('raw', keyBuffer, {
|
|
201
|
-
name: 'AES-GCM',
|
|
202
|
-
length: 256,
|
|
203
|
-
}, true, ['encrypt', 'decrypt']);
|
|
204
|
-
});
|
|
205
|
-
}
|
|
206
|
-
export function encryptPrivateKeyWithPassword(keyPair, hashedPassword) {
|
|
207
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
208
|
-
const cryptoKey = yield deriveCryptoKeyFromPassword(hashedPassword);
|
|
209
|
-
const privateKeyPemHex = encodePrivateKeyToPemHex(keyPair);
|
|
210
|
-
const encodedPlaintext = new TextEncoder().encode(privateKeyPemHex);
|
|
211
|
-
const ciphertext = yield window.crypto.subtle.encrypt({ name: 'AES-GCM', iv: CONSTANT_IV_AES }, cryptoKey, encodedPlaintext);
|
|
212
|
-
return Buffer.from(ciphertext).toString('base64');
|
|
213
|
-
});
|
|
214
|
-
}
|
|
215
|
-
export function decryptPrivateKeyWithPassword(encryptedPrivateKeyPemHex, hashedPassword) {
|
|
216
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
217
|
-
const secretKey = yield crypto.subtle.importKey('raw', Buffer.from(hashedPassword, 'hex'), {
|
|
218
|
-
name: 'AES-GCM',
|
|
219
|
-
length: 256,
|
|
220
|
-
}, true, ['encrypt', 'decrypt']);
|
|
221
|
-
const cleartext = yield crypto.subtle.decrypt({ name: 'AES-GCM', iv: CONSTANT_IV_AES }, secretKey, Buffer.from(encryptedPrivateKeyPemHex, 'base64'));
|
|
222
|
-
const privateKeyPemHex = new TextDecoder().decode(cleartext);
|
|
223
|
-
const privateKey = decodePrivateKeyPemHex(privateKeyPemHex);
|
|
224
|
-
return privateKey;
|
|
225
|
-
});
|
|
226
|
-
}
|
package/dist/esm/errors.js
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
export class TransactionReviewError extends Error {
|
|
2
|
-
constructor(transactionReviewUrl) {
|
|
3
|
-
super('transaction review error');
|
|
4
|
-
this.name = 'TransactionReviewError';
|
|
5
|
-
this.transactionReviewUrl = transactionReviewUrl;
|
|
6
|
-
}
|
|
7
|
-
}
|
|
8
|
-
export class TransactionReviewDenied extends Error {
|
|
9
|
-
constructor() {
|
|
10
|
-
super('transaction review has been denied by the user');
|
|
11
|
-
this.name = 'TransactionReviewDenied';
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
export class TransactionReviewTimeout extends Error {
|
|
15
|
-
constructor(transactionReviewUrl, pendingTransactionId) {
|
|
16
|
-
super('transaction review has timed out');
|
|
17
|
-
this.name = 'TransactionReviewTimeout';
|
|
18
|
-
this.transactionReviewUrl = transactionReviewUrl;
|
|
19
|
-
this.pendingTransactionId = pendingTransactionId;
|
|
20
|
-
}
|
|
21
|
-
}
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import axios from 'axios';
|
|
2
|
-
export function initClient(baseURL, useAdapter) {
|
|
3
|
-
const client = axios.create({ baseURL });
|
|
4
|
-
if (useAdapter) {
|
|
5
|
-
client.defaults.adapter = function (config) {
|
|
6
|
-
return fetch(config.baseURL + config.url, {
|
|
7
|
-
method: config.method,
|
|
8
|
-
headers: config.headers,
|
|
9
|
-
body: config.data,
|
|
10
|
-
credentials: config.withCredentials ? 'include' : undefined,
|
|
11
|
-
})
|
|
12
|
-
.then(response => response.text().then(text => ({
|
|
13
|
-
data: text,
|
|
14
|
-
status: response.status,
|
|
15
|
-
statusText: response.statusText,
|
|
16
|
-
headers: response.headers,
|
|
17
|
-
config: config,
|
|
18
|
-
request: fetch,
|
|
19
|
-
})))
|
|
20
|
-
.catch(function (reason) {
|
|
21
|
-
throw reason;
|
|
22
|
-
});
|
|
23
|
-
};
|
|
24
|
-
}
|
|
25
|
-
return client;
|
|
26
|
-
}
|
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
import Client from '@getpara/user-management-client';
|
|
2
|
-
import { Environment } from '../types/index.js';
|
|
3
|
-
export function getBaseOAuthUrl(env) {
|
|
4
|
-
switch (env) {
|
|
5
|
-
case Environment.DEV:
|
|
6
|
-
return 'http://localhost:8080/';
|
|
7
|
-
case Environment.SANDBOX:
|
|
8
|
-
return 'https://api.sandbox.usecapsule.com/';
|
|
9
|
-
case Environment.BETA:
|
|
10
|
-
return 'https://api.beta.usecapsule.com/';
|
|
11
|
-
case Environment.PROD:
|
|
12
|
-
return 'https://api.usecapsule.com/';
|
|
13
|
-
default:
|
|
14
|
-
throw new Error(`unsupported env: ${env}`);
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
export function getBaseUrl(env) {
|
|
18
|
-
switch (env) {
|
|
19
|
-
case Environment.DEV:
|
|
20
|
-
return 'http://localhost:8080/';
|
|
21
|
-
case Environment.SANDBOX:
|
|
22
|
-
return 'https://api.sandbox.getpara.com/';
|
|
23
|
-
case Environment.BETA:
|
|
24
|
-
return 'https://api.beta.getpara.com/';
|
|
25
|
-
case Environment.PROD:
|
|
26
|
-
return 'https://api.getpara.com/';
|
|
27
|
-
default:
|
|
28
|
-
throw new Error(`unsupported env: ${env}`);
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
export function getBaseMPCNetworkUrl(env, useWebsocket) {
|
|
32
|
-
const prefix = useWebsocket ? 'ws' : 'http';
|
|
33
|
-
switch (env) {
|
|
34
|
-
case Environment.DEV:
|
|
35
|
-
return `${prefix}://localhost:3000`;
|
|
36
|
-
case Environment.SANDBOX:
|
|
37
|
-
return `${prefix}s://mpc-network.sandbox.getpara.com`;
|
|
38
|
-
case Environment.BETA:
|
|
39
|
-
return `${prefix}s://mpc-network.beta.getpara.com`;
|
|
40
|
-
case Environment.PROD:
|
|
41
|
-
return `${prefix}s://mpc-network.prod.getpara.com`;
|
|
42
|
-
default:
|
|
43
|
-
throw new Error(`unsupported env: ${env}`);
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
export function initClient({ env, version, apiKey, partnerId, useFetchAdapter = false, retrieveSessionCookie, persistSessionCookie, }) {
|
|
47
|
-
return new Client({
|
|
48
|
-
userManagementHost: getBaseUrl(env),
|
|
49
|
-
version: [Environment.DEV, Environment.SANDBOX].includes(env) ? 'dev' : version,
|
|
50
|
-
apiKey: apiKey,
|
|
51
|
-
partnerId,
|
|
52
|
-
opts: { useFetchAdapter },
|
|
53
|
-
retrieveSessionCookie,
|
|
54
|
-
persistSessionCookie,
|
|
55
|
-
});
|
|
56
|
-
}
|
package/dist/esm/package.json
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"type":"module","sideEffects":false}
|
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
import { Encrypt as ECIESEncrypt, Decrypt as ECIESDecrypt } from '@celo/utils/lib/ecies.js';
|
|
2
|
-
import * as eutil from 'ethereumjs-util';
|
|
3
|
-
import * as forge from 'node-forge';
|
|
4
|
-
export class KeyContainer {
|
|
5
|
-
constructor(walletId, keyshare, address) {
|
|
6
|
-
this.walletId = walletId;
|
|
7
|
-
this.keyshare = keyshare;
|
|
8
|
-
this.address = address;
|
|
9
|
-
this.backupDecryptionKey = Buffer.from(forge.random.getBytesSync(32), 'binary').toString('hex');
|
|
10
|
-
}
|
|
11
|
-
static buildFrom(serializedContainer) {
|
|
12
|
-
try {
|
|
13
|
-
const parsedObject = JSON.parse(serializedContainer);
|
|
14
|
-
return Object.assign(new KeyContainer('', '', ''), parsedObject);
|
|
15
|
-
}
|
|
16
|
-
catch (e) {
|
|
17
|
-
const container = new KeyContainer('', '', '');
|
|
18
|
-
container.backupDecryptionKey = serializedContainer.split('|')[0];
|
|
19
|
-
return container;
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
getPublicEncryptionKey() {
|
|
23
|
-
return Buffer.from(eutil.privateToPublic(Buffer.from(this.backupDecryptionKey, 'hex')));
|
|
24
|
-
}
|
|
25
|
-
getPublicEncryptionKeyHex() {
|
|
26
|
-
return this.getPublicEncryptionKey().toString('hex');
|
|
27
|
-
}
|
|
28
|
-
encryptForSelf(backup) {
|
|
29
|
-
try {
|
|
30
|
-
const pubkey = this.getPublicEncryptionKey();
|
|
31
|
-
const data = ECIESEncrypt(pubkey, Buffer.from(backup, 'ucs2')).toString('base64');
|
|
32
|
-
return data;
|
|
33
|
-
}
|
|
34
|
-
catch (error) {
|
|
35
|
-
throw Error('Error encrypting backup');
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
static encryptWithPublicKey(publicKey, backup) {
|
|
39
|
-
try {
|
|
40
|
-
const data = ECIESEncrypt(publicKey, Buffer.from(backup, 'ucs2')).toString('base64');
|
|
41
|
-
return data;
|
|
42
|
-
}
|
|
43
|
-
catch (error) {
|
|
44
|
-
throw Error('Error encrypting backup');
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
decrypt(encryptedBackup) {
|
|
48
|
-
try {
|
|
49
|
-
const buf = Buffer.from(encryptedBackup, 'base64');
|
|
50
|
-
const data = ECIESDecrypt(Buffer.from(this.backupDecryptionKey, 'hex'), buf);
|
|
51
|
-
return Buffer.from(data.buffer).toString('ucs2');
|
|
52
|
-
}
|
|
53
|
-
catch (error) {
|
|
54
|
-
throw Error('Error decrypting backup');
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
}
|
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
|
-
import { EncryptorType, KeyShareType } from '@getpara/user-management-client';
|
|
11
|
-
import { KeyContainer } from './KeyContainer.js';
|
|
12
|
-
export function sendRecoveryForShare({ ctx, userId, walletId, otherEncryptedShares = [], userSigner, ignoreRedistributingBackupEncryptedShare = false, emailProps = {}, forceRefresh = false, }) {
|
|
13
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
14
|
-
if (ignoreRedistributingBackupEncryptedShare) {
|
|
15
|
-
yield ctx.client.uploadUserKeyShares(userId, otherEncryptedShares.map(share => (Object.assign({ walletId }, share))));
|
|
16
|
-
return '';
|
|
17
|
-
}
|
|
18
|
-
let userBackupKeyShareOptsArr;
|
|
19
|
-
let recoveryPrivateKeyContainer;
|
|
20
|
-
const { recoveryPublicKeys } = yield ctx.client.getRecoveryPublicKeys(userId);
|
|
21
|
-
if (forceRefresh || !(recoveryPublicKeys === null || recoveryPublicKeys === void 0 ? void 0 : recoveryPublicKeys.length)) {
|
|
22
|
-
recoveryPrivateKeyContainer = new KeyContainer(walletId, '', '');
|
|
23
|
-
const { recoveryPublicKeys } = yield ctx.client.persistRecoveryPublicKeys(userId, [
|
|
24
|
-
recoveryPrivateKeyContainer.getPublicEncryptionKeyHex(),
|
|
25
|
-
]);
|
|
26
|
-
const encryptedUserBackup = recoveryPrivateKeyContainer.encryptForSelf(userSigner);
|
|
27
|
-
userBackupKeyShareOptsArr = [
|
|
28
|
-
{
|
|
29
|
-
walletId,
|
|
30
|
-
encryptedShare: encryptedUserBackup,
|
|
31
|
-
type: KeyShareType.USER,
|
|
32
|
-
encryptor: EncryptorType.RECOVERY,
|
|
33
|
-
recoveryPublicKeyId: recoveryPublicKeys[0].id,
|
|
34
|
-
},
|
|
35
|
-
];
|
|
36
|
-
}
|
|
37
|
-
else {
|
|
38
|
-
userBackupKeyShareOptsArr = recoveryPublicKeys.map(recoveryPublicKey => {
|
|
39
|
-
const { id: recoveryPublicKeyId, publicKey } = recoveryPublicKey;
|
|
40
|
-
const encryptedUserBackup = KeyContainer.encryptWithPublicKey(Buffer.from(publicKey, 'hex'), userSigner);
|
|
41
|
-
return {
|
|
42
|
-
walletId,
|
|
43
|
-
encryptedShare: encryptedUserBackup,
|
|
44
|
-
type: KeyShareType.USER,
|
|
45
|
-
encryptor: EncryptorType.RECOVERY,
|
|
46
|
-
recoveryPublicKeyId,
|
|
47
|
-
};
|
|
48
|
-
});
|
|
49
|
-
}
|
|
50
|
-
yield ctx.client.uploadUserKeyShares(userId, [
|
|
51
|
-
...otherEncryptedShares.map(share => (Object.assign({ walletId }, share))),
|
|
52
|
-
...(ignoreRedistributingBackupEncryptedShare ? [] : userBackupKeyShareOptsArr),
|
|
53
|
-
]);
|
|
54
|
-
yield ctx.client.distributeParaShare(Object.assign({ userId,
|
|
55
|
-
walletId, useDKLS: ctx.useDKLS }, emailProps));
|
|
56
|
-
return recoveryPrivateKeyContainer ? JSON.stringify(recoveryPrivateKeyContainer) : '';
|
|
57
|
-
});
|
|
58
|
-
}
|
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
|
-
import { EncryptorType, KeyShareType } from '@getpara/user-management-client';
|
|
11
|
-
import { encryptWithDerivedPublicKey } from '../cryptography/utils.js';
|
|
12
|
-
import { sendRecoveryForShare } from './recovery.js';
|
|
13
|
-
// function to call on new user share to perform all necessary distribution
|
|
14
|
-
export function distributeNewShare({ ctx, userId, walletId, userShare, ignoreRedistributingBackupEncryptedShare = false, emailProps = {}, partnerId, protocolId, }) {
|
|
15
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
16
|
-
const publicKeysRes = yield ctx.client.getSessionPublicKeys(userId);
|
|
17
|
-
const biometricEncryptedShares = publicKeysRes.data.keys
|
|
18
|
-
.map(key => {
|
|
19
|
-
if (!key.publicKey) {
|
|
20
|
-
return;
|
|
21
|
-
}
|
|
22
|
-
const { encryptedMessageHex, encryptedKeyHex } = encryptWithDerivedPublicKey(key.sigDerivedPublicKey, userShare);
|
|
23
|
-
return {
|
|
24
|
-
encryptedShare: encryptedMessageHex,
|
|
25
|
-
encryptedKey: encryptedKeyHex,
|
|
26
|
-
type: KeyShareType.USER,
|
|
27
|
-
encryptor: EncryptorType.BIOMETRICS,
|
|
28
|
-
biometricPublicKey: key.sigDerivedPublicKey,
|
|
29
|
-
partnerId,
|
|
30
|
-
protocolId,
|
|
31
|
-
};
|
|
32
|
-
})
|
|
33
|
-
.filter(Boolean);
|
|
34
|
-
const passwords = yield ctx.client.getPasswords({ userId });
|
|
35
|
-
const passwordEncryptedShares = passwords
|
|
36
|
-
.map(password => {
|
|
37
|
-
if (password.status === 'PENDING') {
|
|
38
|
-
return;
|
|
39
|
-
}
|
|
40
|
-
const { encryptedMessageHex, encryptedKeyHex } = encryptWithDerivedPublicKey(password.sigDerivedPublicKey, userShare);
|
|
41
|
-
return {
|
|
42
|
-
encryptedShare: encryptedMessageHex,
|
|
43
|
-
encryptedKey: encryptedKeyHex,
|
|
44
|
-
type: KeyShareType.USER,
|
|
45
|
-
encryptor: EncryptorType.PASSWORD,
|
|
46
|
-
passwordId: password.id,
|
|
47
|
-
partnerId,
|
|
48
|
-
protocolId,
|
|
49
|
-
};
|
|
50
|
-
})
|
|
51
|
-
.filter(Boolean);
|
|
52
|
-
const allEncryptedShares = [...biometricEncryptedShares, ...passwordEncryptedShares];
|
|
53
|
-
return yield sendRecoveryForShare({
|
|
54
|
-
ctx,
|
|
55
|
-
userId,
|
|
56
|
-
walletId,
|
|
57
|
-
otherEncryptedShares: allEncryptedShares,
|
|
58
|
-
userSigner: userShare,
|
|
59
|
-
ignoreRedistributingBackupEncryptedShare,
|
|
60
|
-
emailProps,
|
|
61
|
-
});
|
|
62
|
-
});
|
|
63
|
-
}
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
|
-
import { randomBytes } from 'crypto';
|
|
11
|
-
import { Encrypt as ECIESEncrypt, Decrypt as ECIESDecrypt } from '@celo/utils/lib/ecies.js';
|
|
12
|
-
import { Buffer } from 'buffer';
|
|
13
|
-
import * as eutil from 'ethereumjs-util';
|
|
14
|
-
export function upload(message, userManagementClient) {
|
|
15
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
16
|
-
let secret;
|
|
17
|
-
let publicKeyUint8Array;
|
|
18
|
-
while (true) {
|
|
19
|
-
try {
|
|
20
|
-
secret = randomBytes(32).toString('hex');
|
|
21
|
-
// privateToPublic throws error when private key is larger than group order
|
|
22
|
-
// so we want to keep trying until we get a valid private key
|
|
23
|
-
publicKeyUint8Array = eutil.privateToPublic(Buffer.from(secret, 'hex'));
|
|
24
|
-
break;
|
|
25
|
-
}
|
|
26
|
-
catch (e) {
|
|
27
|
-
continue;
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
const pubkey = Buffer.from(publicKeyUint8Array);
|
|
31
|
-
const data = ECIESEncrypt(pubkey, Buffer.from(message, 'ucs2')).toString('base64');
|
|
32
|
-
const { data: { id }, } = yield userManagementClient.tempTrasmissionInit(data);
|
|
33
|
-
return encodeURIComponent(id + '|' + secret);
|
|
34
|
-
});
|
|
35
|
-
}
|
|
36
|
-
export function retrieve(uriEncodedMessage, userManagementClient) {
|
|
37
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
38
|
-
const [id, secret] = decodeURIComponent(uriEncodedMessage).split('|');
|
|
39
|
-
const response = yield userManagementClient.tempTrasmission(id);
|
|
40
|
-
const data = response.data.message;
|
|
41
|
-
const buf = Buffer.from(data, 'base64');
|
|
42
|
-
const res = Buffer.from(ECIESDecrypt(Buffer.from(secret, 'hex'), buf).buffer).toString('ucs2');
|
|
43
|
-
return res;
|
|
44
|
-
});
|
|
45
|
-
}
|
package/dist/esm/types/config.js
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { WalletType, } from '@getpara/user-management-client';
|
|
2
|
-
export var Environment;
|
|
3
|
-
(function (Environment) {
|
|
4
|
-
// Internal Environments
|
|
5
|
-
Environment["DEV"] = "DEV";
|
|
6
|
-
Environment["SANDBOX"] = "SANDBOX";
|
|
7
|
-
Environment["BETA"] = "BETA";
|
|
8
|
-
Environment["PROD"] = "PROD";
|
|
9
|
-
// Customer-Facing Environments
|
|
10
|
-
// NOTE: these resolve to the corresponding internal environments for convenience
|
|
11
|
-
Environment["DEVELOPMENT"] = "BETA";
|
|
12
|
-
Environment["PRODUCTION"] = "PROD";
|
|
13
|
-
})(Environment || (Environment = {}));
|
|
14
|
-
export var EnabledFlow;
|
|
15
|
-
(function (EnabledFlow) {
|
|
16
|
-
EnabledFlow["BUY"] = "BUY";
|
|
17
|
-
EnabledFlow["RECEIVE"] = "RECEIVE";
|
|
18
|
-
EnabledFlow["WITHDRAW"] = "WITHDRAW";
|
|
19
|
-
})(EnabledFlow || (EnabledFlow = {}));
|
package/dist/esm/types/events.js
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
const EVENT_PREFIX = 'para';
|
|
2
|
-
export var ParaEvent;
|
|
3
|
-
(function (ParaEvent) {
|
|
4
|
-
ParaEvent["LOGIN_EVENT"] = "paraLogin";
|
|
5
|
-
ParaEvent["ACCOUNT_CREATION_EVENT"] = "paraAccountCreation";
|
|
6
|
-
ParaEvent["ACCOUNT_SETUP_EVENT"] = "paraAccountSetup";
|
|
7
|
-
ParaEvent["LOGOUT_EVENT"] = "paraLogout";
|
|
8
|
-
ParaEvent["SIGN_MESSAGE_EVENT"] = "paraSignMessage";
|
|
9
|
-
ParaEvent["SIGN_TRANSACTION_EVENT"] = "paraSignTransaction";
|
|
10
|
-
ParaEvent["EXTERNAL_WALLET_CHANGE_EVENT"] = "paraExternalWalletChange";
|
|
11
|
-
ParaEvent["WALLETS_CHANGE_EVENT"] = "paraWalletsChange";
|
|
12
|
-
ParaEvent["WALLET_CREATED"] = "paraWalletCreated";
|
|
13
|
-
ParaEvent["PREGEN_WALLET_CLAIMED"] = "paraPregenWalletClaimed";
|
|
14
|
-
})(ParaEvent || (ParaEvent = {}));
|
package/dist/esm/types/index.js
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
export * from './config.js';
|
|
2
|
-
export * from './wallet.js';
|
|
3
|
-
export * from './params.js';
|
|
4
|
-
export * from './theme.js';
|
|
5
|
-
export * from './onRamps.js';
|
|
6
|
-
export * from './popup.js';
|
|
7
|
-
export * from './recovery.js';
|
|
8
|
-
export * from './events.js';
|
|
9
|
-
export { Network, OnRampAsset, OnRampProvider, OnRampPurchaseStatus, } from '@getpara/user-management-client';
|
package/dist/esm/types/params.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/dist/esm/types/popup.js
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
export var PopupType;
|
|
2
|
-
(function (PopupType) {
|
|
3
|
-
PopupType["SIGN_TRANSACTION_REVIEW"] = "SIGN_TRANSACTION_REVIEW";
|
|
4
|
-
PopupType["SIGN_MESSAGE_REVIEW"] = "SIGN_MESSAGE_REVIEW";
|
|
5
|
-
PopupType["LOGIN_PASSKEY"] = "LOGIN_PASSKEY";
|
|
6
|
-
PopupType["CREATE_PASSKEY"] = "CREATE_PASSKEY";
|
|
7
|
-
PopupType["OAUTH"] = "OAUTH";
|
|
8
|
-
PopupType["ON_RAMP_TRANSACTION"] = "ON_RAMP_TRANSACTION";
|
|
9
|
-
})(PopupType || (PopupType = {}));
|