@getpara/core-sdk 2.0.0-alpha.6 → 2.0.0-alpha.61

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.
Files changed (75) hide show
  1. package/dist/cjs/ParaCore.js +1038 -248
  2. package/dist/cjs/constants.js +13 -1
  3. package/dist/cjs/index.js +31 -3
  4. package/dist/cjs/shares/enclave.js +266 -0
  5. package/dist/cjs/shares/shareDistribution.js +16 -1
  6. package/dist/cjs/types/{theme.js → assets.js} +2 -2
  7. package/dist/cjs/types/{onRamps.js → auth.js} +12 -12
  8. package/dist/cjs/types/coreApi.js +20 -3
  9. package/dist/cjs/types/events.js +2 -0
  10. package/dist/cjs/types/index.js +2 -21
  11. package/dist/cjs/utils/config.js +108 -0
  12. package/dist/cjs/utils/formatting.js +46 -0
  13. package/dist/cjs/utils/index.js +2 -0
  14. package/dist/cjs/utils/onRamps.js +2 -3
  15. package/dist/cjs/utils/wallet.js +3 -0
  16. package/dist/esm/ParaCore.js +1045 -254
  17. package/dist/esm/{chunk-7B52C2XE.js → chunk-W5CT3TVS.js} +2 -0
  18. package/dist/esm/constants.js +10 -2
  19. package/dist/esm/cryptography/utils.js +1 -1
  20. package/dist/esm/errors.js +1 -1
  21. package/dist/esm/external/mpcComputationClient.js +1 -1
  22. package/dist/esm/external/userManagementClient.js +1 -1
  23. package/dist/esm/index.js +31 -6
  24. package/dist/esm/shares/KeyContainer.js +1 -1
  25. package/dist/esm/shares/enclave.js +226 -0
  26. package/dist/esm/shares/recovery.js +1 -1
  27. package/dist/esm/shares/shareDistribution.js +17 -2
  28. package/dist/esm/transmission/transmissionUtils.js +1 -1
  29. package/dist/esm/types/auth.js +11 -0
  30. package/dist/esm/types/config.js +1 -1
  31. package/dist/esm/types/coreApi.js +19 -3
  32. package/dist/esm/types/events.js +3 -1
  33. package/dist/esm/types/index.js +1 -16
  34. package/dist/esm/types/popup.js +1 -1
  35. package/dist/esm/types/wallet.js +1 -1
  36. package/dist/esm/utils/autobind.js +1 -1
  37. package/dist/esm/utils/config.js +86 -0
  38. package/dist/esm/utils/events.js +1 -1
  39. package/dist/esm/utils/formatting.js +44 -1
  40. package/dist/esm/utils/index.js +1 -0
  41. package/dist/esm/utils/json.js +1 -1
  42. package/dist/esm/utils/listeners.js +1 -1
  43. package/dist/esm/utils/onRamps.js +3 -4
  44. package/dist/esm/utils/phone.js +1 -1
  45. package/dist/esm/utils/polling.js +1 -1
  46. package/dist/esm/utils/types.js +1 -1
  47. package/dist/esm/utils/url.js +1 -1
  48. package/dist/esm/utils/wallet.js +4 -1
  49. package/dist/types/ParaCore.d.ts +115 -52
  50. package/dist/types/PlatformUtils.d.ts +2 -3
  51. package/dist/types/constants.d.ts +18 -14
  52. package/dist/types/index.d.ts +6 -4
  53. package/dist/types/shares/KeyContainer.d.ts +0 -2
  54. package/dist/types/shares/enclave.d.ts +81 -0
  55. package/dist/types/shares/shareDistribution.d.ts +4 -2
  56. package/dist/types/types/assets.d.ts +14 -0
  57. package/dist/types/types/auth.d.ts +16 -0
  58. package/dist/types/types/config.d.ts +11 -2
  59. package/dist/types/types/coreApi.d.ts +101 -36
  60. package/dist/types/types/events.d.ts +7 -2
  61. package/dist/types/types/index.d.ts +1 -4
  62. package/dist/types/types/methods.d.ts +85 -13
  63. package/dist/types/types/wallet.d.ts +7 -4
  64. package/dist/types/utils/config.d.ts +7 -0
  65. package/dist/types/utils/formatting.d.ts +12 -1
  66. package/dist/types/utils/index.d.ts +1 -0
  67. package/dist/types/utils/onRamps.d.ts +9 -10
  68. package/package.json +23 -23
  69. package/dist/cjs/types/recovery.js +0 -34
  70. package/dist/esm/types/onRamps.js +0 -11
  71. package/dist/esm/types/recovery.js +0 -12
  72. package/dist/types/types/onRamps.d.ts +0 -10
  73. package/dist/types/types/recovery.d.ts +0 -7
  74. package/dist/types/types/theme.d.ts +0 -12
  75. /package/dist/esm/types/{theme.js → assets.js} +0 -0
@@ -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.6";
46
+ const PARA_CORE_VERSION = "2.0.0-alpha.61";
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,24 +28,36 @@ 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,
34
40
  NON_ED25519: () => import_user_management_client.NON_ED25519,
35
41
  Network: () => import_user_management_client.Network,
36
42
  OAUTH_METHODS: () => import_user_management_client.OAUTH_METHODS,
43
+ OAuthMethod: () => import_user_management_client.OAuthMethod,
37
44
  OnRampAsset: () => import_user_management_client.OnRampAsset,
38
- OnRampMethod: () => import_types.OnRampMethod,
45
+ OnRampMethod: () => import_user_management_client.OnRampMethod,
39
46
  OnRampProvider: () => import_user_management_client.OnRampProvider,
40
47
  OnRampPurchaseStatus: () => import_user_management_client.OnRampPurchaseStatus,
41
48
  OnRampPurchaseType: () => import_user_management_client.OnRampPurchaseType,
49
+ PARA_STORAGE_PREFIX: () => import_constants.PARA_PREFIX,
42
50
  PREGEN_IDENTIFIER_TYPES: () => import_user_management_client.PREGEN_IDENTIFIER_TYPES,
43
51
  PopupType: () => import_types.PopupType,
44
52
  PregenIdentifierType: () => import_types.PregenIdentifierType,
45
- RecoveryStatus: () => import_types.RecoveryStatus,
53
+ RecoveryStatus: () => import_user_management_client.RecoveryStatus,
54
+ SOLANA_WALLETS: () => import_user_management_client.SOLANA_WALLETS,
46
55
  STORAGE_PREFIX: () => import_constants.PREFIX,
56
+ ThemeMode: () => import_user_management_client.ThemeMode,
47
57
  WALLET_SCHEMES: () => import_user_management_client.WALLET_SCHEMES,
48
58
  WALLET_TYPES: () => import_user_management_client.WALLET_TYPES,
59
+ WalletScheme: () => import_user_management_client.WalletScheme,
60
+ WalletType: () => import_user_management_client.WalletType,
49
61
  constructUrl: () => import_utils.constructUrl,
50
62
  decryptPrivateKey: () => import_utils2.decryptPrivateKey,
51
63
  decryptPrivateKeyAndDecryptShare: () => import_utils2.decryptPrivateKeyAndDecryptShare,
@@ -53,6 +65,7 @@ __export(src_exports, {
53
65
  decryptWithKeyPair: () => import_utils2.decryptWithKeyPair,
54
66
  decryptWithPrivateKey: () => import_utils2.decryptWithPrivateKey,
55
67
  default: () => src_default,
68
+ dispatchEvent: () => import_utils.dispatchEvent,
56
69
  distributeNewShare: () => import_shareDistribution.distributeNewShare,
57
70
  encodePrivateKeyToPemHex: () => import_utils2.encodePrivateKeyToPemHex,
58
71
  encryptPrivateKey: () => import_utils2.encryptPrivateKey,
@@ -99,6 +112,7 @@ __reExport(src_exports, require("./errors.js"), module.exports);
99
112
  __reExport(src_exports, require("./utils/formatting.js"), module.exports);
100
113
  __reExport(src_exports, require("./utils/polling.js"), module.exports);
101
114
  __reExport(src_exports, require("./utils/phone.js"), module.exports);
115
+ __reExport(src_exports, require("./utils/config.js"), module.exports);
102
116
  var import_wallet = require("./utils/wallet.js");
103
117
  var import_onRamps = require("./utils/onRamps.js");
104
118
  var import_url = require("./utils/url.js");
@@ -107,30 +121,43 @@ const paraVersion = import_ParaCore.ParaCore.version;
107
121
  var src_default = import_ParaCore.ParaCore;
108
122
  // Annotate the CommonJS export names for ESM import in node:
109
123
  0 && (module.exports = {
124
+ AccountLinkError,
110
125
  AuthMethod,
126
+ AuthMethodStatus,
127
+ COSMOS_WALLETS,
128
+ EVM_WALLETS,
129
+ EXTERNAL_WALLET_TYPES,
111
130
  EmailTheme,
112
131
  KeyContainer,
132
+ LINKED_ACCOUNT_TYPES,
113
133
  NON_ED25519,
114
134
  Network,
115
135
  OAUTH_METHODS,
136
+ OAuthMethod,
116
137
  OnRampAsset,
117
138
  OnRampMethod,
118
139
  OnRampProvider,
119
140
  OnRampPurchaseStatus,
120
141
  OnRampPurchaseType,
142
+ PARA_STORAGE_PREFIX,
121
143
  PREGEN_IDENTIFIER_TYPES,
122
144
  PopupType,
123
145
  PregenIdentifierType,
124
146
  RecoveryStatus,
147
+ SOLANA_WALLETS,
125
148
  STORAGE_PREFIX,
149
+ ThemeMode,
126
150
  WALLET_SCHEMES,
127
151
  WALLET_TYPES,
152
+ WalletScheme,
153
+ WalletType,
128
154
  constructUrl,
129
155
  decryptPrivateKey,
130
156
  decryptPrivateKeyAndDecryptShare,
131
157
  decryptPrivateKeyWithPassword,
132
158
  decryptWithKeyPair,
133
159
  decryptWithPrivateKey,
160
+ dispatchEvent,
134
161
  distributeNewShare,
135
162
  encodePrivateKeyToPemHex,
136
163
  encryptPrivateKey,
@@ -164,5 +191,6 @@ var src_default = import_ParaCore.ParaCore;
164
191
  ...require("./errors.js"),
165
192
  ...require("./utils/formatting.js"),
166
193
  ...require("./utils/polling.js"),
167
- ...require("./utils/phone.js")
194
+ ...require("./utils/phone.js"),
195
+ ...require("./utils/config.js")
168
196
  });
@@ -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 (error) {
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(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) {
@@ -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 theme_exports = {};
15
- module.exports = __toCommonJS(theme_exports);
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 onRamps_exports = {};
19
- __export(onRamps_exports, {
20
- OnRampMethod: () => OnRampMethod
18
+ var auth_exports = {};
19
+ __export(auth_exports, {
20
+ AccountLinkError: () => AccountLinkError
21
21
  });
22
- module.exports = __toCommonJS(onRamps_exports);
23
- var OnRampMethod = /* @__PURE__ */ ((OnRampMethod2) => {
24
- OnRampMethod2["ACH"] = "ACH";
25
- OnRampMethod2["DEBIT"] = "Debit";
26
- OnRampMethod2["CREDIT"] = "Credit";
27
- OnRampMethod2["APPLE_PAY"] = "Apple Pay";
28
- return OnRampMethod2;
29
- })(OnRampMethod || {});
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
- OnRampMethod
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,25 @@ const PARA_CORE_METHODS = [
66
67
  "signMessage",
67
68
  "signTransaction",
68
69
  "initiateOnRampTransaction",
69
- "getWalletBalance"
70
+ "getWalletBalance",
71
+ "issueJwt",
72
+ "getLinkedAccounts",
73
+ "accountLinkInProgress"
74
+ ];
75
+ const PARA_INTERNAL_METHODS = [
76
+ "linkAccount",
77
+ "unlinkAccount",
78
+ "verifyEmailOrPhoneLink",
79
+ "verifyOAuthLink",
80
+ "verifyFarcasterLink",
81
+ "verifyTelegramLink",
82
+ "verifyExternalWalletLink",
83
+ "accountLinkInProgress",
84
+ "prepareLogin",
85
+ "sendLoginCode"
70
86
  ];
71
87
  // Annotate the CommonJS export names for ESM import in node:
72
88
  0 && (module.exports = {
73
- PARA_CORE_METHODS
89
+ PARA_CORE_METHODS,
90
+ PARA_INTERNAL_METHODS
74
91
  });
@@ -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:
@@ -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,36 +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);
17
+ __reExport(types_exports, require("./auth.js"), module.exports);
27
18
  __reExport(types_exports, require("./config.js"), module.exports);
28
19
  __reExport(types_exports, require("./coreApi.js"), module.exports);
29
20
  __reExport(types_exports, require("./wallet.js"), module.exports);
30
21
  __reExport(types_exports, require("./methods.js"), module.exports);
31
- __reExport(types_exports, require("./theme.js"), module.exports);
32
- __reExport(types_exports, require("./onRamps.js"), module.exports);
33
22
  __reExport(types_exports, require("./popup.js"), module.exports);
34
- __reExport(types_exports, require("./recovery.js"), module.exports);
35
23
  __reExport(types_exports, require("./events.js"), module.exports);
36
- var import_user_management_client = require("@getpara/user-management-client");
37
24
  // Annotate the CommonJS export names for ESM import in node:
38
25
  0 && (module.exports = {
39
- Network,
40
- OnRampAsset,
41
- OnRampProvider,
42
- OnRampPurchaseStatus,
26
+ ...require("./auth.js"),
43
27
  ...require("./config.js"),
44
28
  ...require("./coreApi.js"),
45
29
  ...require("./wallet.js"),
46
30
  ...require("./methods.js"),
47
- ...require("./theme.js"),
48
- ...require("./onRamps.js"),
49
31
  ...require("./popup.js"),
50
- ...require("./recovery.js"),
51
32
  ...require("./events.js")
52
33
  });