@getpara/core-sdk 2.0.0-fc.2 → 2.0.0
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 +1111 -316
- package/dist/cjs/constants.js +10 -1
- package/dist/cjs/index.js +23 -3
- package/dist/cjs/shares/KeyContainer.js +3 -3
- package/dist/cjs/shares/enclave.js +287 -0
- package/dist/cjs/shares/shareDistribution.js +16 -1
- package/dist/cjs/transmission/transmissionUtils.js +4 -3
- package/dist/cjs/types/{theme.js → assets.js} +2 -2
- package/dist/cjs/types/coreApi.js +7 -2
- package/dist/cjs/types/events.js +2 -0
- package/dist/cjs/types/index.js +0 -21
- package/dist/cjs/types/popup.js +1 -0
- package/dist/cjs/utils/config.js +108 -0
- package/dist/cjs/utils/index.js +5 -1
- package/dist/cjs/utils/onRamps.js +2 -3
- package/dist/cjs/utils/wallet.js +18 -0
- package/dist/cjs/{types/onRamps.js → utils/window.js} +17 -12
- package/dist/esm/ParaCore.js +1115 -320
- package/dist/esm/constants.js +7 -1
- package/dist/esm/index.js +24 -5
- package/dist/esm/shares/KeyContainer.js +3 -3
- package/dist/esm/shares/enclave.js +247 -0
- package/dist/esm/shares/shareDistribution.js +16 -1
- package/dist/esm/transmission/transmissionUtils.js +4 -3
- package/dist/esm/types/coreApi.js +7 -2
- package/dist/esm/types/events.js +2 -0
- package/dist/esm/types/index.js +0 -16
- package/dist/esm/types/popup.js +1 -0
- package/dist/esm/utils/config.js +86 -0
- package/dist/esm/utils/index.js +2 -0
- package/dist/esm/utils/onRamps.js +2 -3
- package/dist/esm/utils/wallet.js +17 -0
- package/dist/esm/utils/window.js +16 -0
- package/dist/types/ParaCore.d.ts +90 -19
- package/dist/types/PlatformUtils.d.ts +2 -1
- package/dist/types/constants.d.ts +3 -0
- package/dist/types/index.d.ts +6 -4
- package/dist/types/shares/enclave.d.ts +83 -0
- package/dist/types/shares/shareDistribution.d.ts +4 -2
- package/dist/types/types/assets.d.ts +14 -0
- package/dist/types/types/config.d.ts +3 -2
- package/dist/types/types/coreApi.d.ts +47 -7
- package/dist/types/types/events.d.ts +7 -2
- package/dist/types/types/index.d.ts +0 -4
- package/dist/types/types/methods.d.ts +56 -12
- package/dist/types/types/popup.d.ts +2 -1
- package/dist/types/types/wallet.d.ts +8 -4
- package/dist/types/utils/config.d.ts +7 -0
- package/dist/types/utils/index.d.ts +2 -0
- package/dist/types/utils/onRamps.d.ts +9 -10
- package/dist/types/utils/wallet.d.ts +1 -0
- package/dist/types/utils/window.d.ts +2 -0
- package/package.json +3 -3
- package/dist/cjs/types/recovery.js +0 -34
- package/dist/esm/types/onRamps.js +0 -11
- package/dist/esm/types/recovery.js +0 -12
- package/dist/types/types/onRamps.d.ts +0 -10
- package/dist/types/types/recovery.d.ts +0 -7
- package/dist/types/types/theme.d.ts +0 -12
- /package/dist/esm/types/{theme.js → assets.js} +0 -0
package/dist/cjs/constants.js
CHANGED
|
@@ -24,6 +24,8 @@ __export(constants_exports, {
|
|
|
24
24
|
LOCAL_STORAGE_CURRENT_WALLET_IDS: () => LOCAL_STORAGE_CURRENT_WALLET_IDS,
|
|
25
25
|
LOCAL_STORAGE_ED25519_WALLETS: () => LOCAL_STORAGE_ED25519_WALLETS,
|
|
26
26
|
LOCAL_STORAGE_EMAIL: () => LOCAL_STORAGE_EMAIL,
|
|
27
|
+
LOCAL_STORAGE_ENCLAVE_JWT: () => LOCAL_STORAGE_ENCLAVE_JWT,
|
|
28
|
+
LOCAL_STORAGE_ENCLAVE_REFRESH_JWT: () => LOCAL_STORAGE_ENCLAVE_REFRESH_JWT,
|
|
27
29
|
LOCAL_STORAGE_EXTERNAL_WALLETS: () => LOCAL_STORAGE_EXTERNAL_WALLETS,
|
|
28
30
|
LOCAL_STORAGE_EXTERNAL_WALLET_USER_ID: () => LOCAL_STORAGE_EXTERNAL_WALLET_USER_ID,
|
|
29
31
|
LOCAL_STORAGE_FARCASTER_USERNAME: () => LOCAL_STORAGE_FARCASTER_USERNAME,
|
|
@@ -33,6 +35,7 @@ __export(constants_exports, {
|
|
|
33
35
|
LOCAL_STORAGE_USER_ID: () => LOCAL_STORAGE_USER_ID,
|
|
34
36
|
LOCAL_STORAGE_WALLETS: () => LOCAL_STORAGE_WALLETS,
|
|
35
37
|
PARA_CORE_VERSION: () => PARA_CORE_VERSION,
|
|
38
|
+
PARA_PREFIX: () => PARA_PREFIX,
|
|
36
39
|
POLLING_INTERVAL_MS: () => POLLING_INTERVAL_MS,
|
|
37
40
|
POLLING_TIMEOUT_MS: () => POLLING_TIMEOUT_MS,
|
|
38
41
|
PREFIX: () => PREFIX,
|
|
@@ -40,8 +43,9 @@ __export(constants_exports, {
|
|
|
40
43
|
SHORT_POLLING_INTERVAL_MS: () => SHORT_POLLING_INTERVAL_MS
|
|
41
44
|
});
|
|
42
45
|
module.exports = __toCommonJS(constants_exports);
|
|
43
|
-
const PARA_CORE_VERSION = "2.0.0
|
|
46
|
+
const PARA_CORE_VERSION = "2.0.0";
|
|
44
47
|
const PREFIX = "@CAPSULE/";
|
|
48
|
+
const PARA_PREFIX = "@PARA/";
|
|
45
49
|
const LOCAL_STORAGE_AUTH_INFO = `${PREFIX}authInfo`;
|
|
46
50
|
const LOCAL_STORAGE_EMAIL = `${PREFIX}e-mail`;
|
|
47
51
|
const LOCAL_STORAGE_PHONE = `${PREFIX}phone`;
|
|
@@ -55,6 +59,8 @@ const LOCAL_STORAGE_WALLETS = `${PREFIX}wallets`;
|
|
|
55
59
|
const LOCAL_STORAGE_EXTERNAL_WALLETS = `${PREFIX}externalWallets`;
|
|
56
60
|
const LOCAL_STORAGE_CURRENT_WALLET_IDS = `${PREFIX}currentWalletIds`;
|
|
57
61
|
const LOCAL_STORAGE_SESSION_COOKIE = `${PREFIX}sessionCookie`;
|
|
62
|
+
const LOCAL_STORAGE_ENCLAVE_JWT = `${PREFIX}enclaveJwt`;
|
|
63
|
+
const LOCAL_STORAGE_ENCLAVE_REFRESH_JWT = `${PREFIX}enclaveRefreshJwt`;
|
|
58
64
|
const SESSION_STORAGE_LOGIN_ENCRYPTION_KEY_PAIR = `${PREFIX}loginEncryptionKeyPair`;
|
|
59
65
|
const POLLING_INTERVAL_MS = 2e3;
|
|
60
66
|
const SHORT_POLLING_INTERVAL_MS = 1e3;
|
|
@@ -70,6 +76,8 @@ const ACCOUNT_LINK_CONFLICT = "Account already linked";
|
|
|
70
76
|
LOCAL_STORAGE_CURRENT_WALLET_IDS,
|
|
71
77
|
LOCAL_STORAGE_ED25519_WALLETS,
|
|
72
78
|
LOCAL_STORAGE_EMAIL,
|
|
79
|
+
LOCAL_STORAGE_ENCLAVE_JWT,
|
|
80
|
+
LOCAL_STORAGE_ENCLAVE_REFRESH_JWT,
|
|
73
81
|
LOCAL_STORAGE_EXTERNAL_WALLETS,
|
|
74
82
|
LOCAL_STORAGE_EXTERNAL_WALLET_USER_ID,
|
|
75
83
|
LOCAL_STORAGE_FARCASTER_USERNAME,
|
|
@@ -79,6 +87,7 @@ const ACCOUNT_LINK_CONFLICT = "Account already linked";
|
|
|
79
87
|
LOCAL_STORAGE_USER_ID,
|
|
80
88
|
LOCAL_STORAGE_WALLETS,
|
|
81
89
|
PARA_CORE_VERSION,
|
|
90
|
+
PARA_PREFIX,
|
|
82
91
|
POLLING_INTERVAL_MS,
|
|
83
92
|
POLLING_TIMEOUT_MS,
|
|
84
93
|
PREFIX,
|
package/dist/cjs/index.js
CHANGED
|
@@ -30,27 +30,32 @@ var src_exports = {};
|
|
|
30
30
|
__export(src_exports, {
|
|
31
31
|
AccountLinkError: () => import_types.AccountLinkError,
|
|
32
32
|
AuthMethod: () => import_user_management_client.AuthMethod,
|
|
33
|
+
AuthMethodStatus: () => import_user_management_client.AuthMethodStatus,
|
|
33
34
|
COSMOS_WALLETS: () => import_user_management_client.COSMOS_WALLETS,
|
|
34
35
|
EVM_WALLETS: () => import_user_management_client.EVM_WALLETS,
|
|
35
36
|
EXTERNAL_WALLET_TYPES: () => import_user_management_client.EXTERNAL_WALLET_TYPES,
|
|
36
37
|
EmailTheme: () => import_user_management_client.EmailTheme,
|
|
37
38
|
KeyContainer: () => import_KeyContainer.KeyContainer,
|
|
38
39
|
LINKED_ACCOUNT_TYPES: () => import_user_management_client.LINKED_ACCOUNT_TYPES,
|
|
40
|
+
LOCAL_STORAGE_CURRENT_WALLET_IDS: () => import_constants.LOCAL_STORAGE_CURRENT_WALLET_IDS,
|
|
41
|
+
LOCAL_STORAGE_WALLETS: () => import_constants.LOCAL_STORAGE_WALLETS,
|
|
39
42
|
NON_ED25519: () => import_user_management_client.NON_ED25519,
|
|
40
43
|
Network: () => import_user_management_client.Network,
|
|
41
44
|
OAUTH_METHODS: () => import_user_management_client.OAUTH_METHODS,
|
|
42
45
|
OAuthMethod: () => import_user_management_client.OAuthMethod,
|
|
43
46
|
OnRampAsset: () => import_user_management_client.OnRampAsset,
|
|
44
|
-
OnRampMethod: () =>
|
|
47
|
+
OnRampMethod: () => import_user_management_client.OnRampMethod,
|
|
45
48
|
OnRampProvider: () => import_user_management_client.OnRampProvider,
|
|
46
49
|
OnRampPurchaseStatus: () => import_user_management_client.OnRampPurchaseStatus,
|
|
47
50
|
OnRampPurchaseType: () => import_user_management_client.OnRampPurchaseType,
|
|
51
|
+
PARA_STORAGE_PREFIX: () => import_constants.PARA_PREFIX,
|
|
48
52
|
PREGEN_IDENTIFIER_TYPES: () => import_user_management_client.PREGEN_IDENTIFIER_TYPES,
|
|
49
53
|
PopupType: () => import_types.PopupType,
|
|
50
54
|
PregenIdentifierType: () => import_types.PregenIdentifierType,
|
|
51
|
-
RecoveryStatus: () =>
|
|
55
|
+
RecoveryStatus: () => import_user_management_client.RecoveryStatus,
|
|
52
56
|
SOLANA_WALLETS: () => import_user_management_client.SOLANA_WALLETS,
|
|
53
57
|
STORAGE_PREFIX: () => import_constants.PREFIX,
|
|
58
|
+
ThemeMode: () => import_user_management_client.ThemeMode,
|
|
54
59
|
WALLET_SCHEMES: () => import_user_management_client.WALLET_SCHEMES,
|
|
55
60
|
WALLET_TYPES: () => import_user_management_client.WALLET_TYPES,
|
|
56
61
|
WalletScheme: () => import_user_management_client.WalletScheme,
|
|
@@ -62,12 +67,15 @@ __export(src_exports, {
|
|
|
62
67
|
decryptWithKeyPair: () => import_utils2.decryptWithKeyPair,
|
|
63
68
|
decryptWithPrivateKey: () => import_utils2.decryptWithPrivateKey,
|
|
64
69
|
default: () => src_default,
|
|
70
|
+
dispatchEvent: () => import_utils.dispatchEvent,
|
|
65
71
|
distributeNewShare: () => import_shareDistribution.distributeNewShare,
|
|
66
72
|
encodePrivateKeyToPemHex: () => import_utils2.encodePrivateKeyToPemHex,
|
|
67
73
|
encryptPrivateKey: () => import_utils2.encryptPrivateKey,
|
|
68
74
|
encryptPrivateKeyWithPassword: () => import_utils2.encryptPrivateKeyWithPassword,
|
|
69
75
|
encryptWithDerivedPublicKey: () => import_utils2.encryptWithDerivedPublicKey,
|
|
70
76
|
entityToWallet: () => import_utils.entityToWallet,
|
|
77
|
+
formatAssetQuantity: () => import_user_management_client.formatAssetQuantity,
|
|
78
|
+
formatCurrency: () => import_user_management_client.formatCurrency,
|
|
71
79
|
getAsymmetricKeyPair: () => import_utils2.getAsymmetricKeyPair,
|
|
72
80
|
getBaseUrl: () => import_userManagementClient.getBaseUrl,
|
|
73
81
|
getDerivedPrivateKeyAndDecrypt: () => import_utils2.getDerivedPrivateKeyAndDecrypt,
|
|
@@ -81,6 +89,7 @@ __export(src_exports, {
|
|
|
81
89
|
getSHA256HashHex: () => import_utils2.getSHA256HashHex,
|
|
82
90
|
hashPasswordWithSalt: () => import_utils2.hashPasswordWithSalt,
|
|
83
91
|
initClient: () => import_userManagementClient.initClient,
|
|
92
|
+
isPortal: () => import_utils.isPortal,
|
|
84
93
|
isWalletSupported: () => import_wallet.isWalletSupported,
|
|
85
94
|
mpcComputationClient: () => mpcComputationClient,
|
|
86
95
|
paraVersion: () => paraVersion,
|
|
@@ -108,6 +117,7 @@ __reExport(src_exports, require("./errors.js"), module.exports);
|
|
|
108
117
|
__reExport(src_exports, require("./utils/formatting.js"), module.exports);
|
|
109
118
|
__reExport(src_exports, require("./utils/polling.js"), module.exports);
|
|
110
119
|
__reExport(src_exports, require("./utils/phone.js"), module.exports);
|
|
120
|
+
__reExport(src_exports, require("./utils/config.js"), module.exports);
|
|
111
121
|
var import_wallet = require("./utils/wallet.js");
|
|
112
122
|
var import_onRamps = require("./utils/onRamps.js");
|
|
113
123
|
var import_url = require("./utils/url.js");
|
|
@@ -118,12 +128,15 @@ var src_default = import_ParaCore.ParaCore;
|
|
|
118
128
|
0 && (module.exports = {
|
|
119
129
|
AccountLinkError,
|
|
120
130
|
AuthMethod,
|
|
131
|
+
AuthMethodStatus,
|
|
121
132
|
COSMOS_WALLETS,
|
|
122
133
|
EVM_WALLETS,
|
|
123
134
|
EXTERNAL_WALLET_TYPES,
|
|
124
135
|
EmailTheme,
|
|
125
136
|
KeyContainer,
|
|
126
137
|
LINKED_ACCOUNT_TYPES,
|
|
138
|
+
LOCAL_STORAGE_CURRENT_WALLET_IDS,
|
|
139
|
+
LOCAL_STORAGE_WALLETS,
|
|
127
140
|
NON_ED25519,
|
|
128
141
|
Network,
|
|
129
142
|
OAUTH_METHODS,
|
|
@@ -133,12 +146,14 @@ var src_default = import_ParaCore.ParaCore;
|
|
|
133
146
|
OnRampProvider,
|
|
134
147
|
OnRampPurchaseStatus,
|
|
135
148
|
OnRampPurchaseType,
|
|
149
|
+
PARA_STORAGE_PREFIX,
|
|
136
150
|
PREGEN_IDENTIFIER_TYPES,
|
|
137
151
|
PopupType,
|
|
138
152
|
PregenIdentifierType,
|
|
139
153
|
RecoveryStatus,
|
|
140
154
|
SOLANA_WALLETS,
|
|
141
155
|
STORAGE_PREFIX,
|
|
156
|
+
ThemeMode,
|
|
142
157
|
WALLET_SCHEMES,
|
|
143
158
|
WALLET_TYPES,
|
|
144
159
|
WalletScheme,
|
|
@@ -149,12 +164,15 @@ var src_default = import_ParaCore.ParaCore;
|
|
|
149
164
|
decryptPrivateKeyWithPassword,
|
|
150
165
|
decryptWithKeyPair,
|
|
151
166
|
decryptWithPrivateKey,
|
|
167
|
+
dispatchEvent,
|
|
152
168
|
distributeNewShare,
|
|
153
169
|
encodePrivateKeyToPemHex,
|
|
154
170
|
encryptPrivateKey,
|
|
155
171
|
encryptPrivateKeyWithPassword,
|
|
156
172
|
encryptWithDerivedPublicKey,
|
|
157
173
|
entityToWallet,
|
|
174
|
+
formatAssetQuantity,
|
|
175
|
+
formatCurrency,
|
|
158
176
|
getAsymmetricKeyPair,
|
|
159
177
|
getBaseUrl,
|
|
160
178
|
getDerivedPrivateKeyAndDecrypt,
|
|
@@ -168,6 +186,7 @@ var src_default = import_ParaCore.ParaCore;
|
|
|
168
186
|
getSHA256HashHex,
|
|
169
187
|
hashPasswordWithSalt,
|
|
170
188
|
initClient,
|
|
189
|
+
isPortal,
|
|
171
190
|
isWalletSupported,
|
|
172
191
|
mpcComputationClient,
|
|
173
192
|
paraVersion,
|
|
@@ -182,5 +201,6 @@ var src_default = import_ParaCore.ParaCore;
|
|
|
182
201
|
...require("./errors.js"),
|
|
183
202
|
...require("./utils/formatting.js"),
|
|
184
203
|
...require("./utils/polling.js"),
|
|
185
|
-
...require("./utils/phone.js")
|
|
204
|
+
...require("./utils/phone.js"),
|
|
205
|
+
...require("./utils/config.js")
|
|
186
206
|
});
|
|
@@ -61,7 +61,7 @@ class KeyContainer {
|
|
|
61
61
|
const pubkey = this.getPublicEncryptionKey();
|
|
62
62
|
const data = (0, import_ecies.Encrypt)(pubkey, Buffer.from(backup, "ucs2")).toString("base64");
|
|
63
63
|
return data;
|
|
64
|
-
} catch (
|
|
64
|
+
} catch (e) {
|
|
65
65
|
throw Error("Error encrypting backup");
|
|
66
66
|
}
|
|
67
67
|
}
|
|
@@ -69,7 +69,7 @@ class KeyContainer {
|
|
|
69
69
|
try {
|
|
70
70
|
const data = (0, import_ecies.Encrypt)(publicKey, Buffer.from(backup, "ucs2")).toString("base64");
|
|
71
71
|
return data;
|
|
72
|
-
} catch (
|
|
72
|
+
} catch (e) {
|
|
73
73
|
throw Error("Error encrypting backup");
|
|
74
74
|
}
|
|
75
75
|
}
|
|
@@ -78,7 +78,7 @@ class KeyContainer {
|
|
|
78
78
|
const buf = Buffer.from(encryptedBackup, "base64");
|
|
79
79
|
const data = (0, import_ecies.Decrypt)(Buffer.from(this.backupDecryptionKey, "hex"), buf);
|
|
80
80
|
return Buffer.from(data.buffer).toString("ucs2");
|
|
81
|
-
} catch (
|
|
81
|
+
} catch (e) {
|
|
82
82
|
throw Error("Error decrypting backup");
|
|
83
83
|
}
|
|
84
84
|
}
|
|
@@ -0,0 +1,287 @@
|
|
|
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 __async = (__this, __arguments, generator) => {
|
|
19
|
+
return new Promise((resolve, reject) => {
|
|
20
|
+
var fulfilled = (value) => {
|
|
21
|
+
try {
|
|
22
|
+
step(generator.next(value));
|
|
23
|
+
} catch (e) {
|
|
24
|
+
reject(e);
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
var rejected = (value) => {
|
|
28
|
+
try {
|
|
29
|
+
step(generator.throw(value));
|
|
30
|
+
} catch (e) {
|
|
31
|
+
reject(e);
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
35
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
|
36
|
+
});
|
|
37
|
+
};
|
|
38
|
+
var enclave_exports = {};
|
|
39
|
+
__export(enclave_exports, {
|
|
40
|
+
EnclaveClient: () => EnclaveClient
|
|
41
|
+
});
|
|
42
|
+
module.exports = __toCommonJS(enclave_exports);
|
|
43
|
+
class EnclaveClient {
|
|
44
|
+
constructor({
|
|
45
|
+
userManagementClient,
|
|
46
|
+
retrieveJwt,
|
|
47
|
+
persistJwt,
|
|
48
|
+
retrieveRefreshJwt,
|
|
49
|
+
persistRefreshJwt
|
|
50
|
+
}) {
|
|
51
|
+
this.enclavePublicKey = null;
|
|
52
|
+
this.frontendKeyPair = null;
|
|
53
|
+
this.userManagementClient = userManagementClient;
|
|
54
|
+
this.retrieveJwt = retrieveJwt;
|
|
55
|
+
this.persistJwt = persistJwt;
|
|
56
|
+
this.retrieveRefreshJwt = retrieveRefreshJwt;
|
|
57
|
+
this.persistRefreshJwt = persistRefreshJwt;
|
|
58
|
+
}
|
|
59
|
+
refreshJwt() {
|
|
60
|
+
return __async(this, null, function* () {
|
|
61
|
+
const frontendKeyPair = yield this.generateFrontendKeyPair();
|
|
62
|
+
const responsePublicKeyPEM = yield this.exportPublicKeyToPEM(frontendKeyPair.publicKey);
|
|
63
|
+
const payload = {
|
|
64
|
+
refreshJwt: this.retrieveRefreshJwt(),
|
|
65
|
+
responsePublicKey: responsePublicKeyPEM
|
|
66
|
+
};
|
|
67
|
+
const encryptedPayload = yield this.encryptForEnclave(JSON.stringify(payload));
|
|
68
|
+
const response = yield this.userManagementClient.refreshEnclaveJwt(JSON.stringify(encryptedPayload));
|
|
69
|
+
const decryptedResponse = yield this.decryptForFrontend(JSON.parse(response.payload));
|
|
70
|
+
this.persistJwt(decryptedResponse.jwt);
|
|
71
|
+
this.persistRefreshJwt(decryptedResponse.refreshJwt);
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
withJwtRefreshRetry(fn) {
|
|
75
|
+
return __async(this, null, function* () {
|
|
76
|
+
try {
|
|
77
|
+
return yield fn();
|
|
78
|
+
} catch (e) {
|
|
79
|
+
yield this.refreshJwt();
|
|
80
|
+
return yield fn();
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
issueEnclaveJwt() {
|
|
85
|
+
return __async(this, null, function* () {
|
|
86
|
+
const frontendKeyPair = yield this.generateFrontendKeyPair();
|
|
87
|
+
const responsePublicKeyPEM = yield this.exportPublicKeyToPEM(frontendKeyPair.publicKey);
|
|
88
|
+
const payload = {
|
|
89
|
+
responsePublicKey: responsePublicKeyPEM
|
|
90
|
+
};
|
|
91
|
+
const encryptedPayload = yield this.encryptForEnclave(JSON.stringify(payload));
|
|
92
|
+
const response = yield this.userManagementClient.issueEnclaveJwt(JSON.stringify(encryptedPayload));
|
|
93
|
+
const decryptedResponse = yield this.decryptForFrontend(JSON.parse(response));
|
|
94
|
+
this.persistJwt(decryptedResponse.jwt);
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Generate a P-256 keypair for the frontend to receive encrypted responses
|
|
99
|
+
*/
|
|
100
|
+
generateFrontendKeyPair() {
|
|
101
|
+
return __async(this, null, function* () {
|
|
102
|
+
if (this.frontendKeyPair) {
|
|
103
|
+
return this.frontendKeyPair;
|
|
104
|
+
}
|
|
105
|
+
this.frontendKeyPair = yield crypto.subtle.generateKey({ name: "ECDH", namedCurve: "P-256" }, true, ["deriveBits"]);
|
|
106
|
+
return this.frontendKeyPair;
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Get the enclave's public key from the user-management service
|
|
111
|
+
*/
|
|
112
|
+
getEnclavePublicKey() {
|
|
113
|
+
return __async(this, null, function* () {
|
|
114
|
+
if (this.enclavePublicKey) {
|
|
115
|
+
return this.enclavePublicKey;
|
|
116
|
+
}
|
|
117
|
+
const response = yield this.userManagementClient.getEnclavePublicKey();
|
|
118
|
+
this.enclavePublicKey = response.publicKey;
|
|
119
|
+
return this.enclavePublicKey;
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Import a PEM-formatted public key for use with Web Crypto API
|
|
124
|
+
*/
|
|
125
|
+
importPublicKeyFromPEM(pemString) {
|
|
126
|
+
return __async(this, null, function* () {
|
|
127
|
+
const pemContents = pemString.replace("-----BEGIN PUBLIC KEY-----", "").replace("-----END PUBLIC KEY-----", "").replace(/\s/g, "");
|
|
128
|
+
const keyData = Uint8Array.from(atob(pemContents), (c) => c.charCodeAt(0));
|
|
129
|
+
return yield crypto.subtle.importKey("spki", keyData, { name: "ECDH", namedCurve: "P-256" }, false, []);
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Export a public key to PEM format
|
|
134
|
+
*/
|
|
135
|
+
exportPublicKeyToPEM(publicKey) {
|
|
136
|
+
return __async(this, null, function* () {
|
|
137
|
+
const exported = yield crypto.subtle.exportKey("spki", publicKey);
|
|
138
|
+
const exportedAsBase64 = btoa(String.fromCharCode(...new Uint8Array(exported)));
|
|
139
|
+
return `-----BEGIN PUBLIC KEY-----
|
|
140
|
+
${exportedAsBase64}
|
|
141
|
+
-----END PUBLIC KEY-----`;
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Encrypt data using P-256 ECIES for the enclave
|
|
146
|
+
*/
|
|
147
|
+
encryptForEnclave(plaintext) {
|
|
148
|
+
return __async(this, null, function* () {
|
|
149
|
+
const enclavePublicKeyPEM = yield this.getEnclavePublicKey();
|
|
150
|
+
const enclavePublicKey = yield this.importPublicKeyFromPEM(enclavePublicKeyPEM);
|
|
151
|
+
const ephemeralKeyPair = yield crypto.subtle.generateKey({ name: "ECDH", namedCurve: "P-256" }, true, ["deriveBits"]);
|
|
152
|
+
const sharedSecretBits = yield crypto.subtle.deriveBits(
|
|
153
|
+
{ name: "ECDH", public: enclavePublicKey },
|
|
154
|
+
ephemeralKeyPair.privateKey,
|
|
155
|
+
256
|
|
156
|
+
// 32 bytes = 256 bits
|
|
157
|
+
);
|
|
158
|
+
const encryptionKeyBuffer = yield crypto.subtle.digest("SHA-256", sharedSecretBits);
|
|
159
|
+
const encryptionKey = yield crypto.subtle.importKey("raw", encryptionKeyBuffer, { name: "AES-GCM" }, false, ["encrypt"]);
|
|
160
|
+
const iv = crypto.getRandomValues(new Uint8Array(12));
|
|
161
|
+
const encrypted = yield crypto.subtle.encrypt(
|
|
162
|
+
{ name: "AES-GCM", iv },
|
|
163
|
+
encryptionKey,
|
|
164
|
+
new TextEncoder().encode(plaintext)
|
|
165
|
+
);
|
|
166
|
+
const encryptedArray = new Uint8Array(encrypted);
|
|
167
|
+
const combined = new Uint8Array(iv.length + encryptedArray.length);
|
|
168
|
+
combined.set(iv);
|
|
169
|
+
combined.set(encryptedArray, iv.length);
|
|
170
|
+
const ephemeralPublicKeyBuffer = yield crypto.subtle.exportKey("spki", ephemeralKeyPair.publicKey);
|
|
171
|
+
return {
|
|
172
|
+
encryptedData: btoa(String.fromCharCode(...combined)),
|
|
173
|
+
keyId: "",
|
|
174
|
+
// Will be set by the enclave
|
|
175
|
+
algorithm: "ECIES-P256-AES256-SHA256",
|
|
176
|
+
ephemeral: btoa(String.fromCharCode(...new Uint8Array(ephemeralPublicKeyBuffer)))
|
|
177
|
+
};
|
|
178
|
+
});
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* Decrypt response encrypted for the frontend
|
|
182
|
+
*/
|
|
183
|
+
decryptForFrontend(encryptedPayload) {
|
|
184
|
+
return __async(this, null, function* () {
|
|
185
|
+
if (!this.frontendKeyPair) {
|
|
186
|
+
throw new Error("Frontend keypair not available");
|
|
187
|
+
}
|
|
188
|
+
const encryptedData = Uint8Array.from(atob(encryptedPayload.encryptedData), (c) => c.charCodeAt(0));
|
|
189
|
+
const ephemeralPublicKeyData = Uint8Array.from(atob(encryptedPayload.ephemeral), (c) => c.charCodeAt(0));
|
|
190
|
+
const ephemeralPublicKey = yield crypto.subtle.importKey(
|
|
191
|
+
"spki",
|
|
192
|
+
ephemeralPublicKeyData,
|
|
193
|
+
{ name: "ECDH", namedCurve: "P-256" },
|
|
194
|
+
false,
|
|
195
|
+
[]
|
|
196
|
+
);
|
|
197
|
+
const sharedSecretBits = yield crypto.subtle.deriveBits(
|
|
198
|
+
{ name: "ECDH", public: ephemeralPublicKey },
|
|
199
|
+
this.frontendKeyPair.privateKey,
|
|
200
|
+
256
|
|
201
|
+
);
|
|
202
|
+
const encryptionKeyBuffer = yield crypto.subtle.digest("SHA-256", sharedSecretBits);
|
|
203
|
+
const encryptionKey = yield crypto.subtle.importKey("raw", encryptionKeyBuffer, { name: "AES-GCM" }, false, ["decrypt"]);
|
|
204
|
+
const iv = encryptedData.slice(0, 12);
|
|
205
|
+
const ciphertext = encryptedData.slice(12);
|
|
206
|
+
const decrypted = yield crypto.subtle.decrypt({ name: "AES-GCM", iv }, encryptionKey, ciphertext);
|
|
207
|
+
return JSON.parse(new TextDecoder().decode(decrypted));
|
|
208
|
+
});
|
|
209
|
+
}
|
|
210
|
+
/**
|
|
211
|
+
* Persist key shares to the enclave
|
|
212
|
+
* @param shares Array of share data to persist
|
|
213
|
+
*/
|
|
214
|
+
persistShares(shares) {
|
|
215
|
+
return __async(this, null, function* () {
|
|
216
|
+
const payload = {
|
|
217
|
+
shares,
|
|
218
|
+
jwt: this.retrieveJwt()
|
|
219
|
+
};
|
|
220
|
+
const encryptedPayload = yield this.encryptForEnclave(JSON.stringify(payload));
|
|
221
|
+
const encryptedPayloadStr = JSON.stringify(encryptedPayload);
|
|
222
|
+
return yield this.userManagementClient.persistEnclaveShares({ encryptedPayload: encryptedPayloadStr });
|
|
223
|
+
});
|
|
224
|
+
}
|
|
225
|
+
/**
|
|
226
|
+
* Retrieve key shares from the enclave
|
|
227
|
+
* @param query Query parameters for finding shares (single query or array of queries)
|
|
228
|
+
*/
|
|
229
|
+
retrieveShares(query) {
|
|
230
|
+
return __async(this, null, function* () {
|
|
231
|
+
yield this.issueEnclaveJwt();
|
|
232
|
+
const frontendKeyPair = yield this.generateFrontendKeyPair();
|
|
233
|
+
const responsePublicKeyPEM = yield this.exportPublicKeyToPEM(frontendKeyPair.publicKey);
|
|
234
|
+
const fullQuery = query.map((q) => ({
|
|
235
|
+
userId: q.userId
|
|
236
|
+
}));
|
|
237
|
+
const payload = {
|
|
238
|
+
query: fullQuery,
|
|
239
|
+
responsePublicKey: responsePublicKeyPEM,
|
|
240
|
+
jwt: this.retrieveJwt()
|
|
241
|
+
};
|
|
242
|
+
const encryptedPayload = yield this.encryptForEnclave(JSON.stringify(payload));
|
|
243
|
+
const encryptedPayloadStr = JSON.stringify(encryptedPayload);
|
|
244
|
+
const response = yield this.userManagementClient.retrieveEnclaveShares(encryptedPayloadStr);
|
|
245
|
+
const encryptedResponse = JSON.parse(response.payload);
|
|
246
|
+
const decryptedData = yield this.decryptForFrontend(encryptedResponse);
|
|
247
|
+
return decryptedData.shares;
|
|
248
|
+
});
|
|
249
|
+
}
|
|
250
|
+
deleteShares() {
|
|
251
|
+
return __async(this, null, function* () {
|
|
252
|
+
yield this.issueEnclaveJwt();
|
|
253
|
+
const frontendKeyPair = yield this.generateFrontendKeyPair();
|
|
254
|
+
const responsePublicKeyPEM = yield this.exportPublicKeyToPEM(frontendKeyPair.publicKey);
|
|
255
|
+
const payload = {
|
|
256
|
+
responsePublicKey: responsePublicKeyPEM,
|
|
257
|
+
jwt: this.retrieveJwt()
|
|
258
|
+
};
|
|
259
|
+
const encryptedPayload = yield this.encryptForEnclave(JSON.stringify(payload));
|
|
260
|
+
const encryptedPayloadStr = JSON.stringify(encryptedPayload);
|
|
261
|
+
yield this.userManagementClient.deleteEnclaveShares(encryptedPayloadStr);
|
|
262
|
+
});
|
|
263
|
+
}
|
|
264
|
+
retrieveSharesWithRetry(query) {
|
|
265
|
+
return __async(this, null, function* () {
|
|
266
|
+
return yield this.withJwtRefreshRetry(() => __async(this, null, function* () {
|
|
267
|
+
return this.retrieveShares(query);
|
|
268
|
+
}));
|
|
269
|
+
});
|
|
270
|
+
}
|
|
271
|
+
persistSharesWithRetry(shares) {
|
|
272
|
+
return __async(this, null, function* () {
|
|
273
|
+
return yield this.persistShares(shares);
|
|
274
|
+
});
|
|
275
|
+
}
|
|
276
|
+
deleteSharesWithRetry() {
|
|
277
|
+
return __async(this, null, function* () {
|
|
278
|
+
return yield this.withJwtRefreshRetry(() => __async(this, null, function* () {
|
|
279
|
+
return this.deleteShares();
|
|
280
|
+
}));
|
|
281
|
+
});
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
285
|
+
0 && (module.exports = {
|
|
286
|
+
EnclaveClient
|
|
287
|
+
});
|
|
@@ -52,8 +52,23 @@ function distributeNewShare(_0) {
|
|
|
52
52
|
ignoreRedistributingBackupEncryptedShare = false,
|
|
53
53
|
emailProps = {},
|
|
54
54
|
partnerId,
|
|
55
|
-
protocolId
|
|
55
|
+
protocolId,
|
|
56
|
+
isEnclaveUser,
|
|
57
|
+
walletScheme
|
|
56
58
|
}) {
|
|
59
|
+
if (isEnclaveUser) {
|
|
60
|
+
yield ctx.enclaveClient.persistSharesWithRetry([
|
|
61
|
+
{
|
|
62
|
+
userId,
|
|
63
|
+
walletId,
|
|
64
|
+
walletScheme,
|
|
65
|
+
signer: userShare,
|
|
66
|
+
partnerId,
|
|
67
|
+
protocolId
|
|
68
|
+
}
|
|
69
|
+
]);
|
|
70
|
+
return "";
|
|
71
|
+
}
|
|
57
72
|
const publicKeysRes = yield ctx.client.getSessionPublicKeys(userId);
|
|
58
73
|
const biometricEncryptedShares = publicKeysRes.data.keys.map((key) => {
|
|
59
74
|
if (!key.publicKey) {
|
|
@@ -54,15 +54,16 @@ module.exports = __toCommonJS(transmissionUtils_exports);
|
|
|
54
54
|
var import_ecies = require("@celo/utils/lib/ecies.js");
|
|
55
55
|
var import_buffer = require("buffer");
|
|
56
56
|
var eutil = __toESM(require("@ethereumjs/util"));
|
|
57
|
-
var import_crypto = require("crypto");
|
|
58
57
|
function upload(message, userManagementClient) {
|
|
59
58
|
return __async(this, null, function* () {
|
|
60
59
|
let secret;
|
|
61
60
|
let publicKeyUint8Array;
|
|
62
61
|
while (true) {
|
|
63
62
|
try {
|
|
64
|
-
|
|
65
|
-
|
|
63
|
+
const privateKeyUint8Array = new Uint8Array(32);
|
|
64
|
+
crypto.getRandomValues(privateKeyUint8Array);
|
|
65
|
+
secret = import_buffer.Buffer.from(privateKeyUint8Array).toString("hex");
|
|
66
|
+
publicKeyUint8Array = eutil.privateToPublic(privateKeyUint8Array);
|
|
66
67
|
break;
|
|
67
68
|
} catch (e) {
|
|
68
69
|
continue;
|
|
@@ -11,5 +11,5 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
11
11
|
return to;
|
|
12
12
|
};
|
|
13
13
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
14
|
-
var
|
|
15
|
-
module.exports = __toCommonJS(
|
|
14
|
+
var assets_exports = {};
|
|
15
|
+
module.exports = __toCommonJS(assets_exports);
|
|
@@ -70,7 +70,9 @@ const PARA_CORE_METHODS = [
|
|
|
70
70
|
"getWalletBalance",
|
|
71
71
|
"issueJwt",
|
|
72
72
|
"getLinkedAccounts",
|
|
73
|
-
"accountLinkInProgress"
|
|
73
|
+
"accountLinkInProgress",
|
|
74
|
+
"addCredential",
|
|
75
|
+
"exportPrivateKey"
|
|
74
76
|
];
|
|
75
77
|
const PARA_INTERNAL_METHODS = [
|
|
76
78
|
"linkAccount",
|
|
@@ -80,7 +82,10 @@ const PARA_INTERNAL_METHODS = [
|
|
|
80
82
|
"verifyFarcasterLink",
|
|
81
83
|
"verifyTelegramLink",
|
|
82
84
|
"verifyExternalWalletLink",
|
|
83
|
-
"accountLinkInProgress"
|
|
85
|
+
"accountLinkInProgress",
|
|
86
|
+
"prepareLogin",
|
|
87
|
+
"sendLoginCode",
|
|
88
|
+
"supportedUserAuthMethods"
|
|
84
89
|
];
|
|
85
90
|
// Annotate the CommonJS export names for ESM import in node:
|
|
86
91
|
0 && (module.exports = {
|
package/dist/cjs/types/events.js
CHANGED
|
@@ -33,6 +33,8 @@ var ParaEvent = ((ParaEvent2) => {
|
|
|
33
33
|
ParaEvent2["WALLET_CREATED"] = `${EVENT_PREFIX}WalletCreated`;
|
|
34
34
|
ParaEvent2["PREGEN_WALLET_CLAIMED"] = `${EVENT_PREFIX}PregenWalletClaimed`;
|
|
35
35
|
ParaEvent2["GUEST_WALLETS_CREATED"] = `${EVENT_PREFIX}GuestWalletsCreated`;
|
|
36
|
+
ParaEvent2["ASSET_TRANSFERRED"] = `${EVENT_PREFIX}AssetTransferred`;
|
|
37
|
+
ParaEvent2["ONRAMP_TRANSACTION_COMPLETE"] = `${EVENT_PREFIX}OnRampTransactionComplete`;
|
|
36
38
|
return ParaEvent2;
|
|
37
39
|
})(ParaEvent || {});
|
|
38
40
|
// Annotate the CommonJS export names for ESM import in node:
|
package/dist/cjs/types/index.js
CHANGED
|
@@ -2,10 +2,6 @@ var __defProp = Object.defineProperty;
|
|
|
2
2
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
3
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
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
5
|
var __copyProps = (to, from, except, desc) => {
|
|
10
6
|
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
7
|
for (let key of __getOwnPropNames(from))
|
|
@@ -17,38 +13,21 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
17
13
|
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
18
14
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
15
|
var types_exports = {};
|
|
20
|
-
__export(types_exports, {
|
|
21
|
-
Network: () => import_user_management_client.Network,
|
|
22
|
-
OnRampAsset: () => import_user_management_client.OnRampAsset,
|
|
23
|
-
OnRampProvider: () => import_user_management_client.OnRampProvider,
|
|
24
|
-
OnRampPurchaseStatus: () => import_user_management_client.OnRampPurchaseStatus
|
|
25
|
-
});
|
|
26
16
|
module.exports = __toCommonJS(types_exports);
|
|
27
17
|
__reExport(types_exports, require("./auth.js"), module.exports);
|
|
28
18
|
__reExport(types_exports, require("./config.js"), module.exports);
|
|
29
19
|
__reExport(types_exports, require("./coreApi.js"), module.exports);
|
|
30
20
|
__reExport(types_exports, require("./wallet.js"), module.exports);
|
|
31
21
|
__reExport(types_exports, require("./methods.js"), module.exports);
|
|
32
|
-
__reExport(types_exports, require("./theme.js"), module.exports);
|
|
33
|
-
__reExport(types_exports, require("./onRamps.js"), module.exports);
|
|
34
22
|
__reExport(types_exports, require("./popup.js"), module.exports);
|
|
35
|
-
__reExport(types_exports, require("./recovery.js"), module.exports);
|
|
36
23
|
__reExport(types_exports, require("./events.js"), module.exports);
|
|
37
|
-
var import_user_management_client = require("@getpara/user-management-client");
|
|
38
24
|
// Annotate the CommonJS export names for ESM import in node:
|
|
39
25
|
0 && (module.exports = {
|
|
40
|
-
Network,
|
|
41
|
-
OnRampAsset,
|
|
42
|
-
OnRampProvider,
|
|
43
|
-
OnRampPurchaseStatus,
|
|
44
26
|
...require("./auth.js"),
|
|
45
27
|
...require("./config.js"),
|
|
46
28
|
...require("./coreApi.js"),
|
|
47
29
|
...require("./wallet.js"),
|
|
48
30
|
...require("./methods.js"),
|
|
49
|
-
...require("./theme.js"),
|
|
50
|
-
...require("./onRamps.js"),
|
|
51
31
|
...require("./popup.js"),
|
|
52
|
-
...require("./recovery.js"),
|
|
53
32
|
...require("./events.js")
|
|
54
33
|
});
|
package/dist/cjs/types/popup.js
CHANGED
|
@@ -27,6 +27,7 @@ var PopupType = /* @__PURE__ */ ((PopupType2) => {
|
|
|
27
27
|
PopupType2["CREATE_PASSKEY"] = "CREATE_PASSKEY";
|
|
28
28
|
PopupType2["OAUTH"] = "OAUTH";
|
|
29
29
|
PopupType2["ON_RAMP_TRANSACTION"] = "ON_RAMP_TRANSACTION";
|
|
30
|
+
PopupType2["EXPORT_PRIVATE_KEY"] = "EXPORT_PRIVATE_KEY";
|
|
30
31
|
return PopupType2;
|
|
31
32
|
})(PopupType || {});
|
|
32
33
|
// Annotate the CommonJS export names for ESM import in node:
|