@alviere/core 0.17.1 → 0.18.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/index.mjs CHANGED
@@ -149,10 +149,10 @@ class Cryptor {
149
149
  *
150
150
  */
151
151
  constructor(logger) {
152
+ this.nonce = new Uint8Array(12);
152
153
  this.logger = logger;
153
154
  this.rsa_key = getRSA_PUB_KEY();
154
155
  this.key = this.generate_key();
155
- this.nonce = this.generate_nonce();
156
156
  this.logger?.debug("🔐 Cryptor initialized");
157
157
  }
158
158
  /**
@@ -161,27 +161,21 @@ class Cryptor {
161
161
  * @returns
162
162
  */
163
163
  async encrypt(data) {
164
+ this.nonce = this.generate_nonce();
164
165
  const encoded = new TextEncoder().encode(JSON.stringify(data));
165
166
  const alg = { name: "AES-GCM", iv: this.nonce };
166
167
  const crypto_key = await this.import_key();
167
168
  const cipher = await crypto.subtle.encrypt(alg, crypto_key, encoded);
168
- const cipherStr = this.bufferToStr(cipher);
169
- const cipherB64 = btoa(cipherStr);
170
- const keyStr = this.bufferToStr(this.key);
171
- const keyB64 = btoa(keyStr);
172
- const nonceStr = this.bufferToStr(this.nonce);
173
- const nonceB64 = btoa(nonceStr);
169
+ const cipherB64 = btoa(this.bufferToStr(new Uint8Array(cipher)));
170
+ const keyB64 = btoa(this.bufferToStr(this.key));
171
+ const nonceB64 = btoa(this.bufferToStr(this.nonce));
174
172
  this.logger?.debug(`🔐 RSA_KEY: ${this.rsa_key.substring(0, 50)}...`);
175
173
  const publicKey = pki.publicKeyFromPem(this.rsa_key);
176
- const keyNonceCipher = publicKey.encrypt(keyB64 + "::" + nonceB64);
177
- const keyNonceB64 = btoa(keyNonceCipher);
174
+ const keyNonceB64 = btoa(publicKey.encrypt(keyB64 + "::" + nonceB64));
178
175
  const encrypted_request = {
179
176
  p: cipherB64,
180
- // base64(AES-GCM(<sdk_envelope>))
181
177
  k: keyNonceB64,
182
- // base64(RSA(base64(SDK_KEY)::base64(<sdk_nonce>)))
183
178
  i: getCERTIFICATE_ID()
184
- // certificate id - configurable via environment variable
185
179
  };
186
180
  this.logger?.debug(
187
181
  `🔐 ENCRYPTED_REQUEST: p=${encrypted_request.p.substring(0, 20)}..., i=${encrypted_request.i}`
@@ -227,25 +221,12 @@ class Cryptor {
227
221
  "decrypt"
228
222
  ]);
229
223
  }
230
- /**
231
- *
232
- * @param data
233
- * @returns
234
- */
235
- async rsa_encrypt(data) {
236
- this.logger?.debug(`🔐 RSA_ENCRYPT: Data to encrypt: ${data.substring(0, 50)}...`);
237
- this.logger?.debug(`🔐 RSA_KEY: ${this.rsa_key.substring(0, 50)}...`);
238
- const publicKey = pki.publicKeyFromPem(this.rsa_key);
239
- return btoa(publicKey.encrypt(data));
240
- }
241
224
  /**
242
225
  *
243
226
  * @param buf
244
227
  */
245
228
  bufferToStr(buf) {
246
- const cb = Array.from(new Uint8Array(buf));
247
- const cs = cb.map((byte) => String.fromCharCode(byte)).join("");
248
- return cs;
229
+ return Array.from(buf).map((byte) => String.fromCharCode(byte)).join("");
249
230
  }
250
231
  }
251
232
  class Validator {
@@ -1426,6 +1407,153 @@ class LegalTextsGateway extends AlcoreBase {
1426
1407
  return throwIfApiError(decrypted);
1427
1408
  }
1428
1409
  }
1410
+ const BUSINESS_TYPES = [
1411
+ "SOLE_PROPRIETORSHIP",
1412
+ "LLC",
1413
+ "LLP",
1414
+ "CORPORATION_C",
1415
+ "CORPORATION_S",
1416
+ "GENERAL_PARTNERSHIP",
1417
+ "GOVERNMENT_ENTITY",
1418
+ "NON_PROFIT_CORPORATION"
1419
+ ];
1420
+ const COUNTRIES = ["USA", "CAN", "MEX", "GBR"];
1421
+ const PROFESSIONS = [
1422
+ "ACCOUNTANT",
1423
+ "ACTOR",
1424
+ "ADMINISTRATIVE_ASSISTANT",
1425
+ "ANALYST",
1426
+ "ARCHITECT",
1427
+ "ARTIST",
1428
+ "CARPENTER",
1429
+ "CASHIER",
1430
+ "CHILDCARE",
1431
+ "COOK",
1432
+ "CLEANER",
1433
+ "COACH",
1434
+ "CONSTRUCTION_WORKER",
1435
+ "CONSULTANT",
1436
+ "CONTENT_CREATOR",
1437
+ "COUNSELOR",
1438
+ "CUSTOMER_SERVICE",
1439
+ "DATA_ENTRY",
1440
+ "DESIGNER",
1441
+ "DENTIST",
1442
+ "DEVELOPER",
1443
+ "DIETITIAN",
1444
+ "DOCTOR",
1445
+ "DRIVER",
1446
+ "EDITOR",
1447
+ "ELECTRICIAN",
1448
+ "ENGINEER",
1449
+ "ESTHETICIAN",
1450
+ "EXECUTIVE",
1451
+ "EXECUTIVE_ASSISTANT",
1452
+ "FARMER",
1453
+ "FINANCIAL_ADVISOR",
1454
+ "FIREFIGHTER",
1455
+ "GRAPHIC_DESIGNER",
1456
+ "HAIRDRESSER",
1457
+ "HUMAN_RESOURCES",
1458
+ "IT_SUPPORT",
1459
+ "JANITOR",
1460
+ "JUDGE",
1461
+ "LAWYER",
1462
+ "LIBRARIAN",
1463
+ "MAINTENANCE_WORKER",
1464
+ "MANAGER",
1465
+ "MEDICAL_ASSISTANT",
1466
+ "MECHANIC",
1467
+ "MILITARY",
1468
+ "MUSICIAN",
1469
+ "NURSE",
1470
+ "PARALEGAL",
1471
+ "PARAMEDIC",
1472
+ "PHARMACIST",
1473
+ "PHOTOGRAPHER",
1474
+ "PHYSICAL_THERAPIST",
1475
+ "PHYSICIAN",
1476
+ "PILOT",
1477
+ "PLUMBER",
1478
+ "POLICE_OFFICER",
1479
+ "POLITICIAN",
1480
+ "PROFESSOR",
1481
+ "PROJECT_MANAGER",
1482
+ "PSYCHOLOGIST",
1483
+ "REAL_ESTATE_AGENT",
1484
+ "RECEPTIONIST",
1485
+ "RESEARCHER",
1486
+ "RETAIL_ASSOCIATE",
1487
+ "SALES_REPRESENTATIVE",
1488
+ "SCIENTIST",
1489
+ "SECURITY_GUARD",
1490
+ "SOCIAL_WORKER",
1491
+ "TEACHER",
1492
+ "TECHNICIAN",
1493
+ "TRANSLATOR",
1494
+ "VETERINARIAN",
1495
+ "WAREHOUSE_WORKER",
1496
+ "WELDER",
1497
+ "WRITER"
1498
+ ];
1499
+ const US_STATES = [
1500
+ "AL",
1501
+ "AK",
1502
+ "AZ",
1503
+ "AR",
1504
+ "CA",
1505
+ "CO",
1506
+ "CT",
1507
+ "DE",
1508
+ "FL",
1509
+ "GA",
1510
+ "HI",
1511
+ "ID",
1512
+ "IL",
1513
+ "IN",
1514
+ "IA",
1515
+ "KS",
1516
+ "KY",
1517
+ "LA",
1518
+ "ME",
1519
+ "MD",
1520
+ "MA",
1521
+ "MI",
1522
+ "MN",
1523
+ "MS",
1524
+ "MO",
1525
+ "MT",
1526
+ "NE",
1527
+ "NV",
1528
+ "NH",
1529
+ "NJ",
1530
+ "NM",
1531
+ "NY",
1532
+ "NC",
1533
+ "ND",
1534
+ "OH",
1535
+ "OK",
1536
+ "OR",
1537
+ "PA",
1538
+ "RI",
1539
+ "SC",
1540
+ "SD",
1541
+ "TN",
1542
+ "TX",
1543
+ "UT",
1544
+ "VT",
1545
+ "VA",
1546
+ "WA",
1547
+ "WV",
1548
+ "WI",
1549
+ "WY",
1550
+ "DC",
1551
+ "AS",
1552
+ "GU",
1553
+ "MP",
1554
+ "PR",
1555
+ "VI"
1556
+ ];
1429
1557
  function NewAddCardRequest(params) {
1430
1558
  const { external_id, name, pan, expiry, code, zip } = params;
1431
1559
  const expiryParts = expiry.split("/");
@@ -2515,9 +2643,11 @@ export {
2515
2643
  AlcoreErrorMessages,
2516
2644
  AlviereCore,
2517
2645
  AuthGateway,
2646
+ BUSINESS_TYPES,
2518
2647
  BankInfoGateway,
2519
2648
  BaseFieldPlugin,
2520
2649
  CERTIFICATE_ID,
2650
+ COUNTRIES,
2521
2651
  CardNumberPlugin,
2522
2652
  CriticalErrorCodes,
2523
2653
  Cryptor,
@@ -2546,11 +2676,13 @@ export {
2546
2676
  NewSendFundsRequest,
2547
2677
  NewTransferFundsRequest,
2548
2678
  NewWithdrawFundsRequest,
2679
+ PROFESSIONS,
2549
2680
  PaymentInstrumentsApiService,
2550
2681
  PaymentInstrumentsGateway,
2551
2682
  PaymentProcessor,
2552
2683
  PaymentsGateway,
2553
2684
  RSA_PUB_KEY,
2685
+ US_STATES,
2554
2686
  Validator,
2555
2687
  WalletsApiService,
2556
2688
  WalletsGateway,