@embarkai/ui-kit 0.4.0 → 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.
@@ -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.4.0</title>
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>
@@ -3211,14 +3211,143 @@ var BinanceOnrampAPI = class {
3211
3211
  }
3212
3212
  };
3213
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
+
3214
3343
  // src/iframe/lib/onramp/rampnow.ts
3215
- var API_DOMAIN2 = "https://api.lumiapassport.com/on-ramp";
3344
+ var API_DOMAIN3 = "https://api.lumiapassport.com/on-ramp";
3216
3345
  var RampnowOnrampAPI = class {
3217
3346
  constructor(sendResponseFn) {
3218
3347
  this.sendResponseFn = sendResponseFn;
3219
3348
  }
3220
3349
  async getRampnowConfigQuery(accessToken) {
3221
- const response = await fetch(`${API_DOMAIN2}/api/rampnow/cfg`, {
3350
+ const response = await fetch(`${API_DOMAIN3}/api/rampnow/cfg`, {
3222
3351
  method: "GET",
3223
3352
  headers: { ...accessToken && { Authorization: `Bearer ${accessToken}` } }
3224
3353
  });
@@ -3226,7 +3355,7 @@ var RampnowOnrampAPI = class {
3226
3355
  return data;
3227
3356
  }
3228
3357
  async getRampOrderQuoteQuery(payload, accessToken) {
3229
- const response = await fetch(`${API_DOMAIN2}/api/rampnow/quote`, {
3358
+ const response = await fetch(`${API_DOMAIN3}/api/rampnow/quote`, {
3230
3359
  method: "POST",
3231
3360
  headers: { "Content-Type": "application/json", ...accessToken && { Authorization: `Bearer ${accessToken}` } },
3232
3361
  body: JSON.stringify(payload)
@@ -3698,7 +3827,7 @@ var SecureMessenger = class {
3698
3827
  "TRUSTED_APP_REMOVED",
3699
3828
  "TOKEN_REFRESHED"
3700
3829
  ];
3701
- const validTypeGroups = ["BINANCE_", "RAMPNOW_"];
3830
+ const validTypeGroups = ["BINANCE_", "RAMPNOW_", "FINCHPAY_"];
3702
3831
  const isTypeValid = validTypes.includes(message.type);
3703
3832
  const isGroupTypeValid = validTypeGroups.some((prefix) => message.type.startsWith(prefix));
3704
3833
  if (!message.type || !isTypeValid && !isGroupTypeValid) return false;
@@ -4465,7 +4594,7 @@ var SigningManager = class extends TokenRefreshApiClient {
4465
4594
  };
4466
4595
 
4467
4596
  // src/iframe/main.ts
4468
- var IFRAME_VERSION = "0.4.0";
4597
+ var IFRAME_VERSION = "0.4.1";
4469
4598
  var IframeWallet = class {
4470
4599
  constructor() {
4471
4600
  console.log("=".repeat(60));
@@ -4480,6 +4609,7 @@ var IframeWallet = class {
4480
4609
  this.trustedApps = new TrustedAppsManager();
4481
4610
  this.optedOutApps = new OptedOutAppsManager();
4482
4611
  this.backupManager = new BackupManager();
4612
+ this.finchpay = new FinchPayRampAPI(this.messenger.sendResponse.bind(this.messenger));
4483
4613
  this.binance = new BinanceOnrampAPI(this.messenger.sendResponse.bind(this.messenger));
4484
4614
  this.rampnow = new RampnowOnrampAPI(this.messenger.sendResponse.bind(this.messenger));
4485
4615
  }
@@ -4507,6 +4637,9 @@ var IframeWallet = class {
4507
4637
  const { type, messageId, projectId } = message;
4508
4638
  try {
4509
4639
  switch (true) {
4640
+ case type.startsWith("FINCHPAY_"):
4641
+ await this.finchpay.handleMessage(message, origin);
4642
+ break;
4510
4643
  case type.startsWith("BINANCE_"):
4511
4644
  await this.binance.handleMessage(message, origin);
4512
4645
  break;
@@ -5133,10 +5266,14 @@ var IframeWallet = class {
5133
5266
  }
5134
5267
  try {
5135
5268
  const envelopeJson = await this.backupManager.encryptEnvelopeData(userId, password);
5136
- this.messenger.sendResponse(messageId, {
5137
- type: "IFRAME_MSG_ENVELOPE_ENCRYPTED",
5138
- envelopeJson
5139
- }, origin);
5269
+ this.messenger.sendResponse(
5270
+ messageId,
5271
+ {
5272
+ type: "IFRAME_MSG_ENVELOPE_ENCRYPTED",
5273
+ envelopeJson
5274
+ },
5275
+ origin
5276
+ );
5140
5277
  } catch (error) {
5141
5278
  this.messenger.sendError(messageId, error.message || "Envelope encryption failed", origin);
5142
5279
  }
@@ -5150,16 +5287,24 @@ var IframeWallet = class {
5150
5287
  }
5151
5288
  try {
5152
5289
  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);
5290
+ this.messenger.sendResponse(
5291
+ messageId,
5292
+ {
5293
+ type: "IFRAME_MSG_ENVELOPE_RESTORED",
5294
+ result: { success: true, timestamp: Date.now() }
5295
+ },
5296
+ origin
5297
+ );
5157
5298
  this.sendWalletReadyStatus(userId, origin);
5158
5299
  } 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);
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
+ );
5163
5308
  }
5164
5309
  }
5165
5310
  displayReadyIndicator() {