@embarkai/ui-kit 0.3.5 → 0.4.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.
@@ -15,7 +15,7 @@
15
15
  <meta http-equiv="X-Content-Type-Options" content="nosniff" />
16
16
  <meta http-equiv="Referrer-Policy" content="strict-origin-when-cross-origin" />
17
17
 
18
- <title>EmbarkAI Secure Wallet - iframe version 0.3.5</title>
18
+ <title>EmbarkAI Secure Wallet - iframe version 0.4.0</title>
19
19
 
20
20
  <!-- Styles will be injected by build process -->
21
21
  <style>
@@ -2361,6 +2361,30 @@ var BackupManager = class {
2361
2361
  console.log("[iframe][BackupManager] \u2705 Backup data encrypted");
2362
2362
  return encrypted;
2363
2363
  }
2364
+ /**
2365
+ * Encrypt current keyshare as EnvelopeEncryptedShare (server/guardian format).
2366
+ * Returns JSON string of the envelope.
2367
+ */
2368
+ async encryptEnvelopeData(userId, password) {
2369
+ const data = this.getCurrentKeyshareBackupData(userId);
2370
+ if (!data) {
2371
+ throw new Error("No keyshare found for backup");
2372
+ }
2373
+ const { envelopeEncryptKeyshareWithPassword: envelopeEncryptKeyshareWithPassword2 } = await Promise.resolve().then(() => (init_crypto_utils(), crypto_utils_exports));
2374
+ const envelope = await envelopeEncryptKeyshareWithPassword2(data, password);
2375
+ return JSON.stringify(envelope);
2376
+ }
2377
+ /**
2378
+ * Decrypt an EnvelopeEncryptedShare and restore keyshare to localStorage.
2379
+ */
2380
+ async decryptAndRestoreEnvelope(envelopeJson, password, userId) {
2381
+ const { envelopeDecryptKeyshareWithPassword: envelopeDecryptKeyshareWithPassword2 } = await Promise.resolve().then(() => (init_crypto_utils(), crypto_utils_exports));
2382
+ const envelope = JSON.parse(envelopeJson);
2383
+ const backupData = await envelopeDecryptKeyshareWithPassword2(envelope, password);
2384
+ localStorage.setItem(`tss.${userId}.keyshare`, backupData.keyshare);
2385
+ localStorage.setItem(`tss.${userId}.sessionId`, backupData.sessionId);
2386
+ localStorage.setItem(`tss.${userId}.ownerAddress`, backupData.ownerAddress);
2387
+ }
2364
2388
  /**
2365
2389
  * Restore keyshare from local file backup
2366
2390
  */
@@ -3662,6 +3686,8 @@ var SecureMessenger = class {
3662
3686
  "CLEAR_AUTHORIZATIONS",
3663
3687
  "CREATE_BACKUP",
3664
3688
  "ENCRYPT_BACKUP_DATA",
3689
+ "ENCRYPT_ENVELOPE_DATA",
3690
+ "DECRYPT_AND_RESTORE_ENVELOPE",
3665
3691
  "RESTORE_BACKUP",
3666
3692
  "RESTORE_FROM_FILE",
3667
3693
  "GET_BACKUP_STATUS",
@@ -4439,7 +4465,7 @@ var SigningManager = class extends TokenRefreshApiClient {
4439
4465
  };
4440
4466
 
4441
4467
  // src/iframe/main.ts
4442
- var IFRAME_VERSION = "0.3.5";
4468
+ var IFRAME_VERSION = "0.4.0";
4443
4469
  var IframeWallet = class {
4444
4470
  constructor() {
4445
4471
  console.log("=".repeat(60));
@@ -4538,6 +4564,12 @@ var IframeWallet = class {
4538
4564
  case type === "ENCRYPT_BACKUP_DATA":
4539
4565
  await this.handleEncryptBackupData(message, origin);
4540
4566
  break;
4567
+ case type === "ENCRYPT_ENVELOPE_DATA":
4568
+ await this.handleEncryptEnvelopeData(message, origin);
4569
+ break;
4570
+ case type === "DECRYPT_AND_RESTORE_ENVELOPE":
4571
+ await this.handleDecryptAndRestoreEnvelope(message, origin);
4572
+ break;
4541
4573
  default:
4542
4574
  throw new Error(`Unknown message type: ${type}`);
4543
4575
  }
@@ -5092,6 +5124,44 @@ var IframeWallet = class {
5092
5124
  this.messenger.sendError(messageId, error.message || "Encryption failed", origin);
5093
5125
  }
5094
5126
  }
5127
+ async handleEncryptEnvelopeData(message, origin) {
5128
+ const { userId, password } = message.data;
5129
+ const { messageId } = message;
5130
+ if (!userId) {
5131
+ this.messenger.sendError(messageId, "userId is required", origin);
5132
+ return;
5133
+ }
5134
+ try {
5135
+ const envelopeJson = await this.backupManager.encryptEnvelopeData(userId, password);
5136
+ this.messenger.sendResponse(messageId, {
5137
+ type: "IFRAME_MSG_ENVELOPE_ENCRYPTED",
5138
+ envelopeJson
5139
+ }, origin);
5140
+ } catch (error) {
5141
+ this.messenger.sendError(messageId, error.message || "Envelope encryption failed", origin);
5142
+ }
5143
+ }
5144
+ async handleDecryptAndRestoreEnvelope(message, origin) {
5145
+ const { userId, envelopeJson, password } = message.data;
5146
+ const { messageId } = message;
5147
+ if (!userId || !envelopeJson) {
5148
+ this.messenger.sendError(messageId, "userId and envelopeJson are required", origin);
5149
+ return;
5150
+ }
5151
+ try {
5152
+ await this.backupManager.decryptAndRestoreEnvelope(envelopeJson, password, userId);
5153
+ this.messenger.sendResponse(messageId, {
5154
+ type: "IFRAME_MSG_ENVELOPE_RESTORED",
5155
+ result: { success: true, timestamp: Date.now() }
5156
+ }, origin);
5157
+ this.sendWalletReadyStatus(userId, origin);
5158
+ } catch (error) {
5159
+ this.messenger.sendResponse(messageId, {
5160
+ type: "IFRAME_MSG_ENVELOPE_RESTORED",
5161
+ result: { success: false, timestamp: Date.now(), error: error.message }
5162
+ }, origin);
5163
+ }
5164
+ }
5095
5165
  displayReadyIndicator() {
5096
5166
  const app = document.getElementById("app");
5097
5167
  if (!app) return;