@getpara/core-sdk 2.0.0-alpha.7 → 2.0.0-alpha.70
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 +1516 -382
- package/dist/cjs/constants.js +13 -1
- package/dist/cjs/index.js +35 -3
- package/dist/cjs/shares/KeyContainer.js +3 -3
- package/dist/cjs/shares/enclave.js +266 -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/{onRamps.js → auth.js} +12 -12
- package/dist/cjs/types/coreApi.js +23 -3
- package/dist/cjs/types/events.js +2 -0
- package/dist/cjs/types/index.js +2 -21
- package/dist/cjs/types/popup.js +1 -0
- package/dist/cjs/utils/config.js +108 -0
- package/dist/cjs/utils/formatting.js +4 -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/recovery.js → utils/window.js} +17 -13
- package/dist/esm/ParaCore.js +1525 -388
- package/dist/esm/constants.js +9 -1
- package/dist/esm/index.js +36 -5
- package/dist/esm/shares/KeyContainer.js +3 -3
- package/dist/esm/shares/enclave.js +226 -0
- package/dist/esm/shares/shareDistribution.js +16 -1
- package/dist/esm/transmission/transmissionUtils.js +4 -3
- package/dist/esm/types/auth.js +11 -0
- package/dist/esm/types/coreApi.js +21 -2
- package/dist/esm/types/events.js +2 -0
- package/dist/esm/types/index.js +1 -16
- package/dist/esm/types/popup.js +1 -0
- package/dist/esm/utils/config.js +86 -0
- package/dist/esm/utils/formatting.js +2 -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 +142 -57
- package/dist/types/PlatformUtils.d.ts +2 -3
- package/dist/types/constants.d.ts +18 -14
- package/dist/types/index.d.ts +6 -4
- package/dist/types/shares/KeyContainer.d.ts +0 -2
- package/dist/types/shares/enclave.d.ts +81 -0
- package/dist/types/shares/shareDistribution.d.ts +4 -2
- package/dist/types/types/assets.d.ts +14 -0
- package/dist/types/types/auth.d.ts +16 -0
- package/dist/types/types/config.d.ts +11 -2
- package/dist/types/types/coreApi.d.ts +133 -37
- package/dist/types/types/events.d.ts +7 -2
- package/dist/types/types/index.d.ts +1 -4
- package/dist/types/types/methods.d.ts +94 -15
- package/dist/types/types/popup.d.ts +2 -1
- package/dist/types/types/wallet.d.ts +11 -4
- package/dist/types/utils/config.d.ts +7 -0
- package/dist/types/utils/formatting.d.ts +2 -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 +23 -23
- 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
|
@@ -17,12 +17,15 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
17
17
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
18
|
var constants_exports = {};
|
|
19
19
|
__export(constants_exports, {
|
|
20
|
+
ACCOUNT_LINK_CONFLICT: () => ACCOUNT_LINK_CONFLICT,
|
|
20
21
|
EXTERNAL_WALLET_CONNECTION_ONLY_USER_ID: () => EXTERNAL_WALLET_CONNECTION_ONLY_USER_ID,
|
|
21
22
|
LOCAL_STORAGE_AUTH_INFO: () => LOCAL_STORAGE_AUTH_INFO,
|
|
22
23
|
LOCAL_STORAGE_COUNTRY_CODE: () => LOCAL_STORAGE_COUNTRY_CODE,
|
|
23
24
|
LOCAL_STORAGE_CURRENT_WALLET_IDS: () => LOCAL_STORAGE_CURRENT_WALLET_IDS,
|
|
24
25
|
LOCAL_STORAGE_ED25519_WALLETS: () => LOCAL_STORAGE_ED25519_WALLETS,
|
|
25
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,
|
|
26
29
|
LOCAL_STORAGE_EXTERNAL_WALLETS: () => LOCAL_STORAGE_EXTERNAL_WALLETS,
|
|
27
30
|
LOCAL_STORAGE_EXTERNAL_WALLET_USER_ID: () => LOCAL_STORAGE_EXTERNAL_WALLET_USER_ID,
|
|
28
31
|
LOCAL_STORAGE_FARCASTER_USERNAME: () => LOCAL_STORAGE_FARCASTER_USERNAME,
|
|
@@ -32,6 +35,7 @@ __export(constants_exports, {
|
|
|
32
35
|
LOCAL_STORAGE_USER_ID: () => LOCAL_STORAGE_USER_ID,
|
|
33
36
|
LOCAL_STORAGE_WALLETS: () => LOCAL_STORAGE_WALLETS,
|
|
34
37
|
PARA_CORE_VERSION: () => PARA_CORE_VERSION,
|
|
38
|
+
PARA_PREFIX: () => PARA_PREFIX,
|
|
35
39
|
POLLING_INTERVAL_MS: () => POLLING_INTERVAL_MS,
|
|
36
40
|
POLLING_TIMEOUT_MS: () => POLLING_TIMEOUT_MS,
|
|
37
41
|
PREFIX: () => PREFIX,
|
|
@@ -39,8 +43,9 @@ __export(constants_exports, {
|
|
|
39
43
|
SHORT_POLLING_INTERVAL_MS: () => SHORT_POLLING_INTERVAL_MS
|
|
40
44
|
});
|
|
41
45
|
module.exports = __toCommonJS(constants_exports);
|
|
42
|
-
const PARA_CORE_VERSION = "2.0.0-alpha.
|
|
46
|
+
const PARA_CORE_VERSION = "2.0.0-alpha.70";
|
|
43
47
|
const PREFIX = "@CAPSULE/";
|
|
48
|
+
const PARA_PREFIX = "@PARA/";
|
|
44
49
|
const LOCAL_STORAGE_AUTH_INFO = `${PREFIX}authInfo`;
|
|
45
50
|
const LOCAL_STORAGE_EMAIL = `${PREFIX}e-mail`;
|
|
46
51
|
const LOCAL_STORAGE_PHONE = `${PREFIX}phone`;
|
|
@@ -54,19 +59,25 @@ const LOCAL_STORAGE_WALLETS = `${PREFIX}wallets`;
|
|
|
54
59
|
const LOCAL_STORAGE_EXTERNAL_WALLETS = `${PREFIX}externalWallets`;
|
|
55
60
|
const LOCAL_STORAGE_CURRENT_WALLET_IDS = `${PREFIX}currentWalletIds`;
|
|
56
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`;
|
|
57
64
|
const SESSION_STORAGE_LOGIN_ENCRYPTION_KEY_PAIR = `${PREFIX}loginEncryptionKeyPair`;
|
|
58
65
|
const POLLING_INTERVAL_MS = 2e3;
|
|
59
66
|
const SHORT_POLLING_INTERVAL_MS = 1e3;
|
|
60
67
|
const POLLING_TIMEOUT_MS = 3e5;
|
|
61
68
|
const EXTERNAL_WALLET_CONNECTION_ONLY_USER_ID = "EXTERNAL_WALLET_CONNECTION_ONLY";
|
|
69
|
+
const ACCOUNT_LINK_CONFLICT = "Account already linked";
|
|
62
70
|
// Annotate the CommonJS export names for ESM import in node:
|
|
63
71
|
0 && (module.exports = {
|
|
72
|
+
ACCOUNT_LINK_CONFLICT,
|
|
64
73
|
EXTERNAL_WALLET_CONNECTION_ONLY_USER_ID,
|
|
65
74
|
LOCAL_STORAGE_AUTH_INFO,
|
|
66
75
|
LOCAL_STORAGE_COUNTRY_CODE,
|
|
67
76
|
LOCAL_STORAGE_CURRENT_WALLET_IDS,
|
|
68
77
|
LOCAL_STORAGE_ED25519_WALLETS,
|
|
69
78
|
LOCAL_STORAGE_EMAIL,
|
|
79
|
+
LOCAL_STORAGE_ENCLAVE_JWT,
|
|
80
|
+
LOCAL_STORAGE_ENCLAVE_REFRESH_JWT,
|
|
70
81
|
LOCAL_STORAGE_EXTERNAL_WALLETS,
|
|
71
82
|
LOCAL_STORAGE_EXTERNAL_WALLET_USER_ID,
|
|
72
83
|
LOCAL_STORAGE_FARCASTER_USERNAME,
|
|
@@ -76,6 +87,7 @@ const EXTERNAL_WALLET_CONNECTION_ONLY_USER_ID = "EXTERNAL_WALLET_CONNECTION_ONLY
|
|
|
76
87
|
LOCAL_STORAGE_USER_ID,
|
|
77
88
|
LOCAL_STORAGE_WALLETS,
|
|
78
89
|
PARA_CORE_VERSION,
|
|
90
|
+
PARA_PREFIX,
|
|
79
91
|
POLLING_INTERVAL_MS,
|
|
80
92
|
POLLING_TIMEOUT_MS,
|
|
81
93
|
PREFIX,
|
package/dist/cjs/index.js
CHANGED
|
@@ -28,23 +28,34 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
28
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
29
|
var src_exports = {};
|
|
30
30
|
__export(src_exports, {
|
|
31
|
+
AccountLinkError: () => import_types.AccountLinkError,
|
|
31
32
|
AuthMethod: () => import_user_management_client.AuthMethod,
|
|
33
|
+
AuthMethodStatus: () => import_user_management_client.AuthMethodStatus,
|
|
34
|
+
COSMOS_WALLETS: () => import_user_management_client.COSMOS_WALLETS,
|
|
35
|
+
EVM_WALLETS: () => import_user_management_client.EVM_WALLETS,
|
|
36
|
+
EXTERNAL_WALLET_TYPES: () => import_user_management_client.EXTERNAL_WALLET_TYPES,
|
|
32
37
|
EmailTheme: () => import_user_management_client.EmailTheme,
|
|
33
38
|
KeyContainer: () => import_KeyContainer.KeyContainer,
|
|
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,
|
|
34
42
|
NON_ED25519: () => import_user_management_client.NON_ED25519,
|
|
35
43
|
Network: () => import_user_management_client.Network,
|
|
36
44
|
OAUTH_METHODS: () => import_user_management_client.OAUTH_METHODS,
|
|
37
45
|
OAuthMethod: () => import_user_management_client.OAuthMethod,
|
|
38
46
|
OnRampAsset: () => import_user_management_client.OnRampAsset,
|
|
39
|
-
OnRampMethod: () =>
|
|
47
|
+
OnRampMethod: () => import_user_management_client.OnRampMethod,
|
|
40
48
|
OnRampProvider: () => import_user_management_client.OnRampProvider,
|
|
41
49
|
OnRampPurchaseStatus: () => import_user_management_client.OnRampPurchaseStatus,
|
|
42
50
|
OnRampPurchaseType: () => import_user_management_client.OnRampPurchaseType,
|
|
51
|
+
PARA_STORAGE_PREFIX: () => import_constants.PARA_PREFIX,
|
|
43
52
|
PREGEN_IDENTIFIER_TYPES: () => import_user_management_client.PREGEN_IDENTIFIER_TYPES,
|
|
44
53
|
PopupType: () => import_types.PopupType,
|
|
45
54
|
PregenIdentifierType: () => import_types.PregenIdentifierType,
|
|
46
|
-
RecoveryStatus: () =>
|
|
55
|
+
RecoveryStatus: () => import_user_management_client.RecoveryStatus,
|
|
56
|
+
SOLANA_WALLETS: () => import_user_management_client.SOLANA_WALLETS,
|
|
47
57
|
STORAGE_PREFIX: () => import_constants.PREFIX,
|
|
58
|
+
ThemeMode: () => import_user_management_client.ThemeMode,
|
|
48
59
|
WALLET_SCHEMES: () => import_user_management_client.WALLET_SCHEMES,
|
|
49
60
|
WALLET_TYPES: () => import_user_management_client.WALLET_TYPES,
|
|
50
61
|
WalletScheme: () => import_user_management_client.WalletScheme,
|
|
@@ -56,12 +67,15 @@ __export(src_exports, {
|
|
|
56
67
|
decryptWithKeyPair: () => import_utils2.decryptWithKeyPair,
|
|
57
68
|
decryptWithPrivateKey: () => import_utils2.decryptWithPrivateKey,
|
|
58
69
|
default: () => src_default,
|
|
70
|
+
dispatchEvent: () => import_utils.dispatchEvent,
|
|
59
71
|
distributeNewShare: () => import_shareDistribution.distributeNewShare,
|
|
60
72
|
encodePrivateKeyToPemHex: () => import_utils2.encodePrivateKeyToPemHex,
|
|
61
73
|
encryptPrivateKey: () => import_utils2.encryptPrivateKey,
|
|
62
74
|
encryptPrivateKeyWithPassword: () => import_utils2.encryptPrivateKeyWithPassword,
|
|
63
75
|
encryptWithDerivedPublicKey: () => import_utils2.encryptWithDerivedPublicKey,
|
|
64
76
|
entityToWallet: () => import_utils.entityToWallet,
|
|
77
|
+
formatAssetQuantity: () => import_user_management_client.formatAssetQuantity,
|
|
78
|
+
formatCurrency: () => import_user_management_client.formatCurrency,
|
|
65
79
|
getAsymmetricKeyPair: () => import_utils2.getAsymmetricKeyPair,
|
|
66
80
|
getBaseUrl: () => import_userManagementClient.getBaseUrl,
|
|
67
81
|
getDerivedPrivateKeyAndDecrypt: () => import_utils2.getDerivedPrivateKeyAndDecrypt,
|
|
@@ -75,6 +89,7 @@ __export(src_exports, {
|
|
|
75
89
|
getSHA256HashHex: () => import_utils2.getSHA256HashHex,
|
|
76
90
|
hashPasswordWithSalt: () => import_utils2.hashPasswordWithSalt,
|
|
77
91
|
initClient: () => import_userManagementClient.initClient,
|
|
92
|
+
isPortal: () => import_utils.isPortal,
|
|
78
93
|
isWalletSupported: () => import_wallet.isWalletSupported,
|
|
79
94
|
mpcComputationClient: () => mpcComputationClient,
|
|
80
95
|
paraVersion: () => paraVersion,
|
|
@@ -102,6 +117,7 @@ __reExport(src_exports, require("./errors.js"), module.exports);
|
|
|
102
117
|
__reExport(src_exports, require("./utils/formatting.js"), module.exports);
|
|
103
118
|
__reExport(src_exports, require("./utils/polling.js"), module.exports);
|
|
104
119
|
__reExport(src_exports, require("./utils/phone.js"), module.exports);
|
|
120
|
+
__reExport(src_exports, require("./utils/config.js"), module.exports);
|
|
105
121
|
var import_wallet = require("./utils/wallet.js");
|
|
106
122
|
var import_onRamps = require("./utils/onRamps.js");
|
|
107
123
|
var import_url = require("./utils/url.js");
|
|
@@ -110,9 +126,17 @@ const paraVersion = import_ParaCore.ParaCore.version;
|
|
|
110
126
|
var src_default = import_ParaCore.ParaCore;
|
|
111
127
|
// Annotate the CommonJS export names for ESM import in node:
|
|
112
128
|
0 && (module.exports = {
|
|
129
|
+
AccountLinkError,
|
|
113
130
|
AuthMethod,
|
|
131
|
+
AuthMethodStatus,
|
|
132
|
+
COSMOS_WALLETS,
|
|
133
|
+
EVM_WALLETS,
|
|
134
|
+
EXTERNAL_WALLET_TYPES,
|
|
114
135
|
EmailTheme,
|
|
115
136
|
KeyContainer,
|
|
137
|
+
LINKED_ACCOUNT_TYPES,
|
|
138
|
+
LOCAL_STORAGE_CURRENT_WALLET_IDS,
|
|
139
|
+
LOCAL_STORAGE_WALLETS,
|
|
116
140
|
NON_ED25519,
|
|
117
141
|
Network,
|
|
118
142
|
OAUTH_METHODS,
|
|
@@ -122,11 +146,14 @@ var src_default = import_ParaCore.ParaCore;
|
|
|
122
146
|
OnRampProvider,
|
|
123
147
|
OnRampPurchaseStatus,
|
|
124
148
|
OnRampPurchaseType,
|
|
149
|
+
PARA_STORAGE_PREFIX,
|
|
125
150
|
PREGEN_IDENTIFIER_TYPES,
|
|
126
151
|
PopupType,
|
|
127
152
|
PregenIdentifierType,
|
|
128
153
|
RecoveryStatus,
|
|
154
|
+
SOLANA_WALLETS,
|
|
129
155
|
STORAGE_PREFIX,
|
|
156
|
+
ThemeMode,
|
|
130
157
|
WALLET_SCHEMES,
|
|
131
158
|
WALLET_TYPES,
|
|
132
159
|
WalletScheme,
|
|
@@ -137,12 +164,15 @@ var src_default = import_ParaCore.ParaCore;
|
|
|
137
164
|
decryptPrivateKeyWithPassword,
|
|
138
165
|
decryptWithKeyPair,
|
|
139
166
|
decryptWithPrivateKey,
|
|
167
|
+
dispatchEvent,
|
|
140
168
|
distributeNewShare,
|
|
141
169
|
encodePrivateKeyToPemHex,
|
|
142
170
|
encryptPrivateKey,
|
|
143
171
|
encryptPrivateKeyWithPassword,
|
|
144
172
|
encryptWithDerivedPublicKey,
|
|
145
173
|
entityToWallet,
|
|
174
|
+
formatAssetQuantity,
|
|
175
|
+
formatCurrency,
|
|
146
176
|
getAsymmetricKeyPair,
|
|
147
177
|
getBaseUrl,
|
|
148
178
|
getDerivedPrivateKeyAndDecrypt,
|
|
@@ -156,6 +186,7 @@ var src_default = import_ParaCore.ParaCore;
|
|
|
156
186
|
getSHA256HashHex,
|
|
157
187
|
hashPasswordWithSalt,
|
|
158
188
|
initClient,
|
|
189
|
+
isPortal,
|
|
159
190
|
isWalletSupported,
|
|
160
191
|
mpcComputationClient,
|
|
161
192
|
paraVersion,
|
|
@@ -170,5 +201,6 @@ var src_default = import_ParaCore.ParaCore;
|
|
|
170
201
|
...require("./errors.js"),
|
|
171
202
|
...require("./utils/formatting.js"),
|
|
172
203
|
...require("./utils/polling.js"),
|
|
173
|
-
...require("./utils/phone.js")
|
|
204
|
+
...require("./utils/phone.js"),
|
|
205
|
+
...require("./utils/config.js")
|
|
174
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,266 @@
|
|
|
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
|
+
retrieveSharesWithRetry(query) {
|
|
251
|
+
return __async(this, null, function* () {
|
|
252
|
+
return yield this.withJwtRefreshRetry(() => __async(this, null, function* () {
|
|
253
|
+
return this.retrieveShares(query);
|
|
254
|
+
}));
|
|
255
|
+
});
|
|
256
|
+
}
|
|
257
|
+
persistSharesWithRetry(shares) {
|
|
258
|
+
return __async(this, null, function* () {
|
|
259
|
+
return yield this.persistShares(shares);
|
|
260
|
+
});
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
264
|
+
0 && (module.exports = {
|
|
265
|
+
EnclaveClient
|
|
266
|
+
});
|
|
@@ -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);
|
|
@@ -15,19 +15,19 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
15
15
|
return to;
|
|
16
16
|
};
|
|
17
17
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
-
var
|
|
19
|
-
__export(
|
|
20
|
-
|
|
18
|
+
var auth_exports = {};
|
|
19
|
+
__export(auth_exports, {
|
|
20
|
+
AccountLinkError: () => AccountLinkError
|
|
21
21
|
});
|
|
22
|
-
module.exports = __toCommonJS(
|
|
23
|
-
var
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
return
|
|
29
|
-
})(
|
|
22
|
+
module.exports = __toCommonJS(auth_exports);
|
|
23
|
+
var AccountLinkError = /* @__PURE__ */ ((AccountLinkError2) => {
|
|
24
|
+
AccountLinkError2["NotAuthenticated"] = "No user is currently authenticated";
|
|
25
|
+
AccountLinkError2["Conflict"] = "Account already linked";
|
|
26
|
+
AccountLinkError2["Canceled"] = "Account linking was canceled";
|
|
27
|
+
AccountLinkError2["Unknown"] = "An unknown error occurred";
|
|
28
|
+
return AccountLinkError2;
|
|
29
|
+
})(AccountLinkError || {});
|
|
30
30
|
// Annotate the CommonJS export names for ESM import in node:
|
|
31
31
|
0 && (module.exports = {
|
|
32
|
-
|
|
32
|
+
AccountLinkError
|
|
33
33
|
});
|
|
@@ -17,7 +17,8 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
17
17
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
18
|
var coreApi_exports = {};
|
|
19
19
|
__export(coreApi_exports, {
|
|
20
|
-
PARA_CORE_METHODS: () => PARA_CORE_METHODS
|
|
20
|
+
PARA_CORE_METHODS: () => PARA_CORE_METHODS,
|
|
21
|
+
PARA_INTERNAL_METHODS: () => PARA_INTERNAL_METHODS
|
|
21
22
|
});
|
|
22
23
|
module.exports = __toCommonJS(coreApi_exports);
|
|
23
24
|
const PARA_CORE_METHODS = [
|
|
@@ -66,9 +67,28 @@ const PARA_CORE_METHODS = [
|
|
|
66
67
|
"signMessage",
|
|
67
68
|
"signTransaction",
|
|
68
69
|
"initiateOnRampTransaction",
|
|
69
|
-
"getWalletBalance"
|
|
70
|
+
"getWalletBalance",
|
|
71
|
+
"issueJwt",
|
|
72
|
+
"getLinkedAccounts",
|
|
73
|
+
"accountLinkInProgress",
|
|
74
|
+
"addCredential",
|
|
75
|
+
"exportPrivateKey"
|
|
76
|
+
];
|
|
77
|
+
const PARA_INTERNAL_METHODS = [
|
|
78
|
+
"linkAccount",
|
|
79
|
+
"unlinkAccount",
|
|
80
|
+
"verifyEmailOrPhoneLink",
|
|
81
|
+
"verifyOAuthLink",
|
|
82
|
+
"verifyFarcasterLink",
|
|
83
|
+
"verifyTelegramLink",
|
|
84
|
+
"verifyExternalWalletLink",
|
|
85
|
+
"accountLinkInProgress",
|
|
86
|
+
"prepareLogin",
|
|
87
|
+
"sendLoginCode",
|
|
88
|
+
"supportedUserAuthMethods"
|
|
70
89
|
];
|
|
71
90
|
// Annotate the CommonJS export names for ESM import in node:
|
|
72
91
|
0 && (module.exports = {
|
|
73
|
-
PARA_CORE_METHODS
|
|
92
|
+
PARA_CORE_METHODS,
|
|
93
|
+
PARA_INTERNAL_METHODS
|
|
74
94
|
});
|
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:
|