@explorins/pers-signer 1.0.9 → 1.0.12
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/browser.cjs.js +15 -70
- package/dist/browser.cjs.js.map +1 -1
- package/dist/browser.d.ts +0 -8
- package/dist/browser.esm.js +15 -70
- package/dist/browser.esm.js.map +1 -1
- package/dist/index.cjs.js +15 -70
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.d.ts +0 -8
- package/dist/index.esm.js +15 -70
- package/dist/index.esm.js.map +1 -1
- package/dist/react-native.cjs.js +15 -70
- package/dist/react-native.cjs.js.map +1 -1
- package/dist/react-native.d.ts +0 -8
- package/dist/react-native.esm.js +15 -70
- package/dist/react-native.esm.js.map +1 -1
- package/package.json +2 -2
package/dist/index.cjs.js
CHANGED
|
@@ -527,18 +527,6 @@ class PersService {
|
|
|
527
527
|
if (cached) {
|
|
528
528
|
return cached;
|
|
529
529
|
}
|
|
530
|
-
// Check storage cache (if available)
|
|
531
|
-
const storedTenant = this.getTenantFromStorage(tenantId);
|
|
532
|
-
if (storedTenant) {
|
|
533
|
-
// Restore to memory cache
|
|
534
|
-
this.tenantCache.set(tenantId, storedTenant);
|
|
535
|
-
// Update current project key
|
|
536
|
-
const projectKey = storedTenant.projectApiKey || storedTenant.projectKey || storedTenant.apiKey;
|
|
537
|
-
if (projectKey) {
|
|
538
|
-
this.currentProjectKey = projectKey;
|
|
539
|
-
}
|
|
540
|
-
return storedTenant;
|
|
541
|
-
}
|
|
542
530
|
try {
|
|
543
531
|
const headers = {
|
|
544
532
|
'accept': 'application/json',
|
|
@@ -575,9 +563,8 @@ class PersService {
|
|
|
575
563
|
}
|
|
576
564
|
}
|
|
577
565
|
const tenantData = await response.json();
|
|
578
|
-
// Cache the tenant data
|
|
566
|
+
// Cache the tenant data in memory only
|
|
579
567
|
this.tenantCache.set(tenantId, tenantData);
|
|
580
|
-
this.storeTenantInStorage(tenantId, tenantData);
|
|
581
568
|
// Update current project key (check multiple possible property names)
|
|
582
569
|
this.currentProjectKey = tenantData.projectKey || tenantData.projectApiKey || tenantData.apiKey;
|
|
583
570
|
return tenantData;
|
|
@@ -596,7 +583,7 @@ class PersService {
|
|
|
596
583
|
static async initializeTenant(tenantId, authToken) {
|
|
597
584
|
const tenantData = await this.getTenantById(tenantId, authToken);
|
|
598
585
|
// Update service configuration with tenant's project key
|
|
599
|
-
const projectKey = tenantData.projectApiKey
|
|
586
|
+
const projectKey = tenantData.projectApiKey;
|
|
600
587
|
if (projectKey) {
|
|
601
588
|
this.currentProjectKey = projectKey;
|
|
602
589
|
}
|
|
@@ -616,56 +603,12 @@ class PersService {
|
|
|
616
603
|
console.error('No project key available. Current tenant cache:', Array.from(this.tenantCache.keys()));
|
|
617
604
|
throw new Error('No project key available. Please initialize tenant or configure project key.');
|
|
618
605
|
}
|
|
619
|
-
/**
|
|
620
|
-
* Get cached tenant data (platform-agnostic)
|
|
621
|
-
*/
|
|
622
|
-
static getTenantFromStorage(tenantId) {
|
|
623
|
-
try {
|
|
624
|
-
// Only use localStorage if available (web environment)
|
|
625
|
-
if (typeof localStorage !== 'undefined') {
|
|
626
|
-
const cached = localStorage.getItem(`tenant_${tenantId}`);
|
|
627
|
-
if (cached) {
|
|
628
|
-
const tenantData = JSON.parse(cached);
|
|
629
|
-
return tenantData;
|
|
630
|
-
}
|
|
631
|
-
}
|
|
632
|
-
}
|
|
633
|
-
catch (error) {
|
|
634
|
-
console.warn('Failed to parse cached tenant data:', error);
|
|
635
|
-
}
|
|
636
|
-
return null;
|
|
637
|
-
}
|
|
638
|
-
/**
|
|
639
|
-
* Store tenant data (platform-agnostic)
|
|
640
|
-
*/
|
|
641
|
-
static storeTenantInStorage(tenantId, tenantData) {
|
|
642
|
-
try {
|
|
643
|
-
// Only use localStorage if available (web environment)
|
|
644
|
-
if (typeof localStorage !== 'undefined') {
|
|
645
|
-
localStorage.setItem(`tenant_${tenantId}`, JSON.stringify(tenantData));
|
|
646
|
-
}
|
|
647
|
-
}
|
|
648
|
-
catch (error) {
|
|
649
|
-
// Silent fail for storage issues
|
|
650
|
-
}
|
|
651
|
-
}
|
|
652
606
|
/**
|
|
653
607
|
* Clear tenant cache and reset project key
|
|
654
608
|
*/
|
|
655
609
|
static clearTenantCache() {
|
|
656
610
|
this.tenantCache.clear();
|
|
657
611
|
this.currentProjectKey = null;
|
|
658
|
-
// Clear from cache as well (platform-agnostic)
|
|
659
|
-
const keysToRemove = [];
|
|
660
|
-
if (typeof localStorage !== 'undefined') {
|
|
661
|
-
for (let i = 0; i < localStorage.length; i++) {
|
|
662
|
-
const key = localStorage.key(i);
|
|
663
|
-
if (key?.startsWith('tenant_')) {
|
|
664
|
-
keysToRemove.push(key);
|
|
665
|
-
}
|
|
666
|
-
}
|
|
667
|
-
}
|
|
668
|
-
keysToRemove.forEach(key => localStorage.removeItem(key));
|
|
669
612
|
}
|
|
670
613
|
/**
|
|
671
614
|
* Authenticates a user with the PERS backend using their auth token
|
|
@@ -1470,9 +1413,8 @@ class TransactionSigningService {
|
|
|
1470
1413
|
// Validate transaction status is signable
|
|
1471
1414
|
const isSignable = SIGNABLE_STATUSES.some(status => status === transactionStatus);
|
|
1472
1415
|
if (!isSignable) {
|
|
1473
|
-
// Create
|
|
1416
|
+
// Create status info for UI using TransactionErrorHandler
|
|
1474
1417
|
const statusInfo = TransactionErrorHandler.createStatusInfo(transactionId, transactionStatus);
|
|
1475
|
-
localStorage.setItem('transaction_status', JSON.stringify(statusInfo));
|
|
1476
1418
|
throw { shouldShowStatus: true, statusInfo };
|
|
1477
1419
|
}
|
|
1478
1420
|
// Authenticate with PERS using backend signer token to set up signing account
|
|
@@ -1482,7 +1424,6 @@ class TransactionSigningService {
|
|
|
1482
1424
|
// Update PERS access token with the new one that has signing account linked
|
|
1483
1425
|
const newPersAccessToken = persSignerAuth.accessToken;
|
|
1484
1426
|
if (newPersAccessToken) {
|
|
1485
|
-
localStorage.setItem('pers_access_token', newPersAccessToken);
|
|
1486
1427
|
updatedPersAccessToken = newPersAccessToken;
|
|
1487
1428
|
}
|
|
1488
1429
|
}
|
|
@@ -1507,12 +1448,7 @@ class TransactionSigningService {
|
|
|
1507
1448
|
* Validate and prepare wallet for signing
|
|
1508
1449
|
*/
|
|
1509
1450
|
async prepareWallet(authTokens, ethersProviderUrl) {
|
|
1510
|
-
//
|
|
1511
|
-
const walletRegistrationFailed = localStorage.getItem('wallet_registration_failed') === 'true';
|
|
1512
|
-
if (walletRegistrationFailed) {
|
|
1513
|
-
const errorDetails = localStorage.getItem('wallet_error_details') || 'Unknown wallet error';
|
|
1514
|
-
throw TransactionErrorHandler.createError(exports.TransactionSigningErrorCode.WALLET_NOT_AVAILABLE, `Wallet not available for transaction signing. Registration failed: ${errorDetails}. Please refresh the page and complete wallet setup.`);
|
|
1515
|
-
}
|
|
1451
|
+
// Wallet validation will be handled through API responses - no localStorage needed
|
|
1516
1452
|
let walletData;
|
|
1517
1453
|
try {
|
|
1518
1454
|
walletData = await WalletService.listWallets(authTokens.backendAuthToken);
|
|
@@ -2084,8 +2020,17 @@ class PersSignerSDK {
|
|
|
2084
2020
|
*/
|
|
2085
2021
|
async combinedAuthentication(identifier, persAccessToken) {
|
|
2086
2022
|
try {
|
|
2087
|
-
// Authenticate with DFNS
|
|
2088
|
-
|
|
2023
|
+
// Authenticate with DFNS - try login first, register if user doesn't exist
|
|
2024
|
+
let signerAuthToken;
|
|
2025
|
+
try {
|
|
2026
|
+
signerAuthToken = await this.loginUser(identifier);
|
|
2027
|
+
}
|
|
2028
|
+
catch (loginError) {
|
|
2029
|
+
console.log(`[PersSignerSDK] User not found, registering new user: ${identifier}`);
|
|
2030
|
+
// User doesn't exist - register new user (registerUser already includes login)
|
|
2031
|
+
const registrationResult = await this.registerUser(identifier);
|
|
2032
|
+
signerAuthToken = registrationResult.authToken;
|
|
2033
|
+
}
|
|
2089
2034
|
return {
|
|
2090
2035
|
identifier,
|
|
2091
2036
|
signerAuthToken,
|