@embarkai/ui-kit 0.3.5 → 0.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/iframe/index.html +1 -1
- package/dist/iframe/main.js +220 -5
- package/dist/iframe/main.js.map +1 -1
- package/dist/index.cjs +5173 -2331
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +17 -1
- package/dist/index.d.ts +17 -1
- package/dist/index.js +4738 -1904
- package/dist/index.js.map +1 -1
- package/dist/styles.css +1 -1
- package/package.json +1 -1
package/dist/iframe/index.html
CHANGED
|
@@ -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.
|
|
18
|
+
<title>EmbarkAI Secure Wallet - iframe version 0.4.1</title>
|
|
19
19
|
|
|
20
20
|
<!-- Styles will be injected by build process -->
|
|
21
21
|
<style>
|
package/dist/iframe/main.js
CHANGED
|
@@ -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
|
*/
|
|
@@ -3187,14 +3211,143 @@ var BinanceOnrampAPI = class {
|
|
|
3187
3211
|
}
|
|
3188
3212
|
};
|
|
3189
3213
|
|
|
3214
|
+
// src/iframe/lib/onramp/finchpay.ts
|
|
3215
|
+
var API_DOMAIN2 = "http://localhost:8000/api";
|
|
3216
|
+
var FinchPayRampAPI = class {
|
|
3217
|
+
constructor(sendResponseFn) {
|
|
3218
|
+
this.sendResponseFn = sendResponseFn;
|
|
3219
|
+
}
|
|
3220
|
+
async getCurrencies(accessToken) {
|
|
3221
|
+
try {
|
|
3222
|
+
const response = await fetch(`${API_DOMAIN2}/finchpay/currencies`, {
|
|
3223
|
+
method: "GET",
|
|
3224
|
+
headers: { "Content-Type": "application/json", ...accessToken && { Authorization: `Bearer ${accessToken}` } }
|
|
3225
|
+
});
|
|
3226
|
+
const data = await response.json();
|
|
3227
|
+
if (!data.success) {
|
|
3228
|
+
console.warn("[FINCHPAY] Failed to fetch currencies:", data);
|
|
3229
|
+
throw new Error(`${data.code}: ${data.message}`);
|
|
3230
|
+
}
|
|
3231
|
+
return data;
|
|
3232
|
+
} catch (error) {
|
|
3233
|
+
throw error;
|
|
3234
|
+
}
|
|
3235
|
+
}
|
|
3236
|
+
async getLimits(payload, accessToken) {
|
|
3237
|
+
const response = await fetch(`${API_DOMAIN2}/finchpay/limits`, {
|
|
3238
|
+
method: "POST",
|
|
3239
|
+
headers: { "Content-Type": "application/json", ...accessToken && { Authorization: `Bearer ${accessToken}` } },
|
|
3240
|
+
body: JSON.stringify(payload)
|
|
3241
|
+
});
|
|
3242
|
+
const data = await response.json();
|
|
3243
|
+
if (!data.success) {
|
|
3244
|
+
console.warn("[FINCHPAY] Failed to fetch limits:", data);
|
|
3245
|
+
throw new Error(`${data.code}: ${data.message}`);
|
|
3246
|
+
}
|
|
3247
|
+
return data;
|
|
3248
|
+
}
|
|
3249
|
+
async getLimitsSummary(payload, accessToken) {
|
|
3250
|
+
const response = await fetch(`${API_DOMAIN2}/finchpay/limits/summary`, {
|
|
3251
|
+
method: "POST",
|
|
3252
|
+
headers: { "Content-Type": "application/json", ...accessToken && { Authorization: `Bearer ${accessToken}` } },
|
|
3253
|
+
body: JSON.stringify(payload)
|
|
3254
|
+
});
|
|
3255
|
+
const data = await response.json();
|
|
3256
|
+
if (!data.success) {
|
|
3257
|
+
console.warn("[FINCHPAY] Failed to fetch limits summary:", data);
|
|
3258
|
+
throw new Error(`${data.code}: ${data.message}`);
|
|
3259
|
+
}
|
|
3260
|
+
return data;
|
|
3261
|
+
}
|
|
3262
|
+
async getEstimates(payload, accessToken) {
|
|
3263
|
+
const response = await fetch(`${API_DOMAIN2}/finchpay/estimates`, {
|
|
3264
|
+
method: "POST",
|
|
3265
|
+
headers: { "Content-Type": "application/json", ...accessToken && { Authorization: `Bearer ${accessToken}` } },
|
|
3266
|
+
body: JSON.stringify(payload)
|
|
3267
|
+
});
|
|
3268
|
+
const data = await response.json();
|
|
3269
|
+
if (!data.success) {
|
|
3270
|
+
console.warn("[FINCHPAY] Failed to fetch estimates:", data);
|
|
3271
|
+
throw new Error(`${data.code}: ${data.message}`);
|
|
3272
|
+
}
|
|
3273
|
+
return data;
|
|
3274
|
+
}
|
|
3275
|
+
async getTransactionStatus(transactionId, accessToken) {
|
|
3276
|
+
try {
|
|
3277
|
+
const response = await fetch(`${API_DOMAIN2}/finchpay/transaction/${transactionId}`, {
|
|
3278
|
+
method: "GET",
|
|
3279
|
+
headers: { "Content-Type": "application/json", ...accessToken && { Authorization: `Bearer ${accessToken}` } }
|
|
3280
|
+
});
|
|
3281
|
+
const data = await response.json();
|
|
3282
|
+
if (!data.success) {
|
|
3283
|
+
console.warn("[FINCHPAY] Failed to fetch transaction status:", data);
|
|
3284
|
+
throw new Error(`${data.code}: ${data.message}`);
|
|
3285
|
+
}
|
|
3286
|
+
return data;
|
|
3287
|
+
} catch (error) {
|
|
3288
|
+
throw error;
|
|
3289
|
+
}
|
|
3290
|
+
}
|
|
3291
|
+
async getWidgetUrl(accessToken) {
|
|
3292
|
+
try {
|
|
3293
|
+
const response = await fetch(`${API_DOMAIN2}/finchpay/widget-url`, {
|
|
3294
|
+
method: "GET",
|
|
3295
|
+
headers: { "Content-Type": "application/json", ...accessToken && { Authorization: `Bearer ${accessToken}` } }
|
|
3296
|
+
});
|
|
3297
|
+
const data = await response.json();
|
|
3298
|
+
if (!data.success) {
|
|
3299
|
+
console.warn("[FINCHPAY] Failed to fetch widget URL:", data);
|
|
3300
|
+
throw new Error(`${data.code}: ${data.message}`);
|
|
3301
|
+
}
|
|
3302
|
+
return data;
|
|
3303
|
+
} catch (error) {
|
|
3304
|
+
throw error;
|
|
3305
|
+
}
|
|
3306
|
+
}
|
|
3307
|
+
// IFRAME MESSAGING
|
|
3308
|
+
async handleMessage(message, origin) {
|
|
3309
|
+
const { type, messageId, data } = message;
|
|
3310
|
+
const { accessToken } = message.data;
|
|
3311
|
+
console.log("[FINCHPAY iframe]: Received message", type, message);
|
|
3312
|
+
switch (type) {
|
|
3313
|
+
case "FINCHPAY_GET_CURRENCIES_QUERY":
|
|
3314
|
+
const isLumiaAvalableRes = await this.getCurrencies(accessToken);
|
|
3315
|
+
this.sendResponseFn(messageId, isLumiaAvalableRes, origin);
|
|
3316
|
+
break;
|
|
3317
|
+
case "FINCHPAY_GET_LIMITS_QUERY":
|
|
3318
|
+
const limitsResponse = await this.getLimits(data, accessToken);
|
|
3319
|
+
this.sendResponseFn(messageId, limitsResponse, origin);
|
|
3320
|
+
break;
|
|
3321
|
+
case "FINCHPAY_GET_LIMITS_SUMMARY_QUERY":
|
|
3322
|
+
const limitsSummaryResponse = await this.getLimitsSummary(data, accessToken);
|
|
3323
|
+
this.sendResponseFn(messageId, limitsSummaryResponse, origin);
|
|
3324
|
+
break;
|
|
3325
|
+
case "FINCHPAY_GET_ESTIMATES_QUERY":
|
|
3326
|
+
const paymentMethodsResponse = await this.getEstimates(data, accessToken);
|
|
3327
|
+
this.sendResponseFn(messageId, paymentMethodsResponse, origin);
|
|
3328
|
+
break;
|
|
3329
|
+
case "FINCHPAY_GET_TRANSACTION_STATUS_QUERY":
|
|
3330
|
+
const transactionStatusResponse = await this.getTransactionStatus(data.transactionId, accessToken);
|
|
3331
|
+
this.sendResponseFn(messageId, transactionStatusResponse, origin);
|
|
3332
|
+
break;
|
|
3333
|
+
case "FINCHPAY_GET_WIDGET_URL_QUERY":
|
|
3334
|
+
const widgetUrlResponse = await this.getWidgetUrl(accessToken);
|
|
3335
|
+
this.sendResponseFn(messageId, widgetUrlResponse, origin);
|
|
3336
|
+
break;
|
|
3337
|
+
default:
|
|
3338
|
+
throw new Error(`[FINCHPAY]: Unknown message type: ${type}`);
|
|
3339
|
+
}
|
|
3340
|
+
}
|
|
3341
|
+
};
|
|
3342
|
+
|
|
3190
3343
|
// src/iframe/lib/onramp/rampnow.ts
|
|
3191
|
-
var
|
|
3344
|
+
var API_DOMAIN3 = "https://api.lumiapassport.com/on-ramp";
|
|
3192
3345
|
var RampnowOnrampAPI = class {
|
|
3193
3346
|
constructor(sendResponseFn) {
|
|
3194
3347
|
this.sendResponseFn = sendResponseFn;
|
|
3195
3348
|
}
|
|
3196
3349
|
async getRampnowConfigQuery(accessToken) {
|
|
3197
|
-
const response = await fetch(`${
|
|
3350
|
+
const response = await fetch(`${API_DOMAIN3}/api/rampnow/cfg`, {
|
|
3198
3351
|
method: "GET",
|
|
3199
3352
|
headers: { ...accessToken && { Authorization: `Bearer ${accessToken}` } }
|
|
3200
3353
|
});
|
|
@@ -3202,7 +3355,7 @@ var RampnowOnrampAPI = class {
|
|
|
3202
3355
|
return data;
|
|
3203
3356
|
}
|
|
3204
3357
|
async getRampOrderQuoteQuery(payload, accessToken) {
|
|
3205
|
-
const response = await fetch(`${
|
|
3358
|
+
const response = await fetch(`${API_DOMAIN3}/api/rampnow/quote`, {
|
|
3206
3359
|
method: "POST",
|
|
3207
3360
|
headers: { "Content-Type": "application/json", ...accessToken && { Authorization: `Bearer ${accessToken}` } },
|
|
3208
3361
|
body: JSON.stringify(payload)
|
|
@@ -3662,6 +3815,8 @@ var SecureMessenger = class {
|
|
|
3662
3815
|
"CLEAR_AUTHORIZATIONS",
|
|
3663
3816
|
"CREATE_BACKUP",
|
|
3664
3817
|
"ENCRYPT_BACKUP_DATA",
|
|
3818
|
+
"ENCRYPT_ENVELOPE_DATA",
|
|
3819
|
+
"DECRYPT_AND_RESTORE_ENVELOPE",
|
|
3665
3820
|
"RESTORE_BACKUP",
|
|
3666
3821
|
"RESTORE_FROM_FILE",
|
|
3667
3822
|
"GET_BACKUP_STATUS",
|
|
@@ -3672,7 +3827,7 @@ var SecureMessenger = class {
|
|
|
3672
3827
|
"TRUSTED_APP_REMOVED",
|
|
3673
3828
|
"TOKEN_REFRESHED"
|
|
3674
3829
|
];
|
|
3675
|
-
const validTypeGroups = ["BINANCE_", "RAMPNOW_"];
|
|
3830
|
+
const validTypeGroups = ["BINANCE_", "RAMPNOW_", "FINCHPAY_"];
|
|
3676
3831
|
const isTypeValid = validTypes.includes(message.type);
|
|
3677
3832
|
const isGroupTypeValid = validTypeGroups.some((prefix) => message.type.startsWith(prefix));
|
|
3678
3833
|
if (!message.type || !isTypeValid && !isGroupTypeValid) return false;
|
|
@@ -4439,7 +4594,7 @@ var SigningManager = class extends TokenRefreshApiClient {
|
|
|
4439
4594
|
};
|
|
4440
4595
|
|
|
4441
4596
|
// src/iframe/main.ts
|
|
4442
|
-
var IFRAME_VERSION = "0.
|
|
4597
|
+
var IFRAME_VERSION = "0.4.1";
|
|
4443
4598
|
var IframeWallet = class {
|
|
4444
4599
|
constructor() {
|
|
4445
4600
|
console.log("=".repeat(60));
|
|
@@ -4454,6 +4609,7 @@ var IframeWallet = class {
|
|
|
4454
4609
|
this.trustedApps = new TrustedAppsManager();
|
|
4455
4610
|
this.optedOutApps = new OptedOutAppsManager();
|
|
4456
4611
|
this.backupManager = new BackupManager();
|
|
4612
|
+
this.finchpay = new FinchPayRampAPI(this.messenger.sendResponse.bind(this.messenger));
|
|
4457
4613
|
this.binance = new BinanceOnrampAPI(this.messenger.sendResponse.bind(this.messenger));
|
|
4458
4614
|
this.rampnow = new RampnowOnrampAPI(this.messenger.sendResponse.bind(this.messenger));
|
|
4459
4615
|
}
|
|
@@ -4481,6 +4637,9 @@ var IframeWallet = class {
|
|
|
4481
4637
|
const { type, messageId, projectId } = message;
|
|
4482
4638
|
try {
|
|
4483
4639
|
switch (true) {
|
|
4640
|
+
case type.startsWith("FINCHPAY_"):
|
|
4641
|
+
await this.finchpay.handleMessage(message, origin);
|
|
4642
|
+
break;
|
|
4484
4643
|
case type.startsWith("BINANCE_"):
|
|
4485
4644
|
await this.binance.handleMessage(message, origin);
|
|
4486
4645
|
break;
|
|
@@ -4538,6 +4697,12 @@ var IframeWallet = class {
|
|
|
4538
4697
|
case type === "ENCRYPT_BACKUP_DATA":
|
|
4539
4698
|
await this.handleEncryptBackupData(message, origin);
|
|
4540
4699
|
break;
|
|
4700
|
+
case type === "ENCRYPT_ENVELOPE_DATA":
|
|
4701
|
+
await this.handleEncryptEnvelopeData(message, origin);
|
|
4702
|
+
break;
|
|
4703
|
+
case type === "DECRYPT_AND_RESTORE_ENVELOPE":
|
|
4704
|
+
await this.handleDecryptAndRestoreEnvelope(message, origin);
|
|
4705
|
+
break;
|
|
4541
4706
|
default:
|
|
4542
4707
|
throw new Error(`Unknown message type: ${type}`);
|
|
4543
4708
|
}
|
|
@@ -5092,6 +5257,56 @@ var IframeWallet = class {
|
|
|
5092
5257
|
this.messenger.sendError(messageId, error.message || "Encryption failed", origin);
|
|
5093
5258
|
}
|
|
5094
5259
|
}
|
|
5260
|
+
async handleEncryptEnvelopeData(message, origin) {
|
|
5261
|
+
const { userId, password } = message.data;
|
|
5262
|
+
const { messageId } = message;
|
|
5263
|
+
if (!userId) {
|
|
5264
|
+
this.messenger.sendError(messageId, "userId is required", origin);
|
|
5265
|
+
return;
|
|
5266
|
+
}
|
|
5267
|
+
try {
|
|
5268
|
+
const envelopeJson = await this.backupManager.encryptEnvelopeData(userId, password);
|
|
5269
|
+
this.messenger.sendResponse(
|
|
5270
|
+
messageId,
|
|
5271
|
+
{
|
|
5272
|
+
type: "IFRAME_MSG_ENVELOPE_ENCRYPTED",
|
|
5273
|
+
envelopeJson
|
|
5274
|
+
},
|
|
5275
|
+
origin
|
|
5276
|
+
);
|
|
5277
|
+
} catch (error) {
|
|
5278
|
+
this.messenger.sendError(messageId, error.message || "Envelope encryption failed", origin);
|
|
5279
|
+
}
|
|
5280
|
+
}
|
|
5281
|
+
async handleDecryptAndRestoreEnvelope(message, origin) {
|
|
5282
|
+
const { userId, envelopeJson, password } = message.data;
|
|
5283
|
+
const { messageId } = message;
|
|
5284
|
+
if (!userId || !envelopeJson) {
|
|
5285
|
+
this.messenger.sendError(messageId, "userId and envelopeJson are required", origin);
|
|
5286
|
+
return;
|
|
5287
|
+
}
|
|
5288
|
+
try {
|
|
5289
|
+
await this.backupManager.decryptAndRestoreEnvelope(envelopeJson, password, userId);
|
|
5290
|
+
this.messenger.sendResponse(
|
|
5291
|
+
messageId,
|
|
5292
|
+
{
|
|
5293
|
+
type: "IFRAME_MSG_ENVELOPE_RESTORED",
|
|
5294
|
+
result: { success: true, timestamp: Date.now() }
|
|
5295
|
+
},
|
|
5296
|
+
origin
|
|
5297
|
+
);
|
|
5298
|
+
this.sendWalletReadyStatus(userId, origin);
|
|
5299
|
+
} catch (error) {
|
|
5300
|
+
this.messenger.sendResponse(
|
|
5301
|
+
messageId,
|
|
5302
|
+
{
|
|
5303
|
+
type: "IFRAME_MSG_ENVELOPE_RESTORED",
|
|
5304
|
+
result: { success: false, timestamp: Date.now(), error: error.message }
|
|
5305
|
+
},
|
|
5306
|
+
origin
|
|
5307
|
+
);
|
|
5308
|
+
}
|
|
5309
|
+
}
|
|
5095
5310
|
displayReadyIndicator() {
|
|
5096
5311
|
const app = document.getElementById("app");
|
|
5097
5312
|
if (!app) return;
|