@explorins/pers-sdk-react-native 1.5.31 → 1.5.32
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/hooks/index.d.ts +2 -2
- package/dist/hooks/index.d.ts.map +1 -1
- package/dist/hooks/index.js +1 -1
- package/dist/hooks/useAnalytics.d.ts.map +1 -1
- package/dist/hooks/useAnalytics.js +0 -1
- package/dist/hooks/useAuth.d.ts +0 -1
- package/dist/hooks/useAuth.d.ts.map +1 -1
- package/dist/hooks/useAuth.js +5 -18
- package/dist/hooks/useBusiness.d.ts.map +1 -1
- package/dist/hooks/useBusiness.js +0 -9
- package/dist/hooks/useCampaigns.d.ts.map +1 -1
- package/dist/hooks/useCampaigns.js +0 -10
- package/dist/hooks/useDonations.d.ts.map +1 -1
- package/dist/hooks/useDonations.js +0 -1
- package/dist/hooks/useFiles.d.ts.map +1 -1
- package/dist/hooks/useFiles.js +0 -4
- package/dist/hooks/usePurchases.d.ts.map +1 -1
- package/dist/hooks/usePurchases.js +0 -3
- package/dist/hooks/useRedemptions.d.ts +4 -1
- package/dist/hooks/useRedemptions.d.ts.map +1 -1
- package/dist/hooks/useRedemptions.js +6 -17
- package/dist/hooks/useTenants.d.ts.map +1 -1
- package/dist/hooks/useTenants.js +0 -3
- package/dist/hooks/useTokens.d.ts.map +1 -1
- package/dist/hooks/useTokens.js +0 -6
- package/dist/hooks/useTransactionSigner.d.ts +13 -1
- package/dist/hooks/useTransactionSigner.d.ts.map +1 -1
- package/dist/hooks/useTransactionSigner.js +59 -2
- package/dist/hooks/useTransactions.d.ts +4 -1
- package/dist/hooks/useTransactions.d.ts.map +1 -1
- package/dist/hooks/useTransactions.js +9 -10
- package/dist/hooks/useUserStatus.d.ts.map +1 -1
- package/dist/hooks/useUserStatus.js +0 -3
- package/dist/hooks/useUsers.d.ts.map +1 -1
- package/dist/hooks/useUsers.js +0 -7
- package/dist/hooks/useWeb3.d.ts +26 -42
- package/dist/hooks/useWeb3.d.ts.map +1 -1
- package/dist/hooks/useWeb3.js +27 -53
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +325 -302
- package/dist/index.js.map +1 -1
- package/dist/providers/PersSDKProvider.d.ts +1 -3
- package/dist/providers/PersSDKProvider.d.ts.map +1 -1
- package/dist/providers/PersSDKProvider.js +13 -9
- package/dist/providers/rn-dpop-provider.d.ts +2 -4
- package/dist/providers/rn-dpop-provider.d.ts.map +1 -1
- package/dist/providers/rn-dpop-provider.js +50 -23
- package/dist/storage/rn-secure-storage.d.ts +1 -0
- package/dist/storage/rn-secure-storage.d.ts.map +1 -1
- package/dist/storage/rn-secure-storage.js +9 -12
- package/package.json +2 -2
- package/src/hooks/index.ts +10 -2
- package/src/hooks/useAnalytics.ts +0 -1
- package/src/hooks/useAuth.ts +4 -25
- package/src/hooks/useBusiness.ts +0 -9
- package/src/hooks/useCampaigns.ts +0 -10
- package/src/hooks/useDonations.ts +0 -1
- package/src/hooks/useFiles.ts +0 -4
- package/src/hooks/usePurchases.ts +0 -3
- package/src/hooks/useRedemptions.ts +7 -21
- package/src/hooks/useTenants.ts +0 -3
- package/src/hooks/useTokens.ts +0 -6
- package/src/hooks/useTransactionSigner.ts +74 -4
- package/src/hooks/useTransactions.ts +10 -12
- package/src/hooks/useUserStatus.ts +0 -3
- package/src/hooks/useUsers.ts +0 -7
- package/src/hooks/useWeb3.ts +28 -68
- package/src/index.ts +4 -0
- package/src/providers/PersSDKProvider.tsx +16 -17
- package/src/providers/rn-dpop-provider.ts +85 -45
- package/src/storage/rn-secure-storage.ts +13 -13
package/dist/index.js
CHANGED
|
@@ -32044,6 +32044,119 @@ class PersSDK {
|
|
|
32044
32044
|
}
|
|
32045
32045
|
}
|
|
32046
32046
|
|
|
32047
|
+
/**
|
|
32048
|
+
* AsyncStorage Token Storage for React Native Mobile Platforms
|
|
32049
|
+
*
|
|
32050
|
+
* Bundler-agnostic AsyncStorage implementation for mobile platforms
|
|
32051
|
+
*/
|
|
32052
|
+
/**
|
|
32053
|
+
* Bundler-agnostic AsyncStorage wrapper
|
|
32054
|
+
* Handles different module resolution patterns across bundlers (Metro, Webpack, Rollup, etc.)
|
|
32055
|
+
*/
|
|
32056
|
+
class BundlerAgnosticAsyncStorage {
|
|
32057
|
+
constructor(asyncStorageModule) {
|
|
32058
|
+
// Try different import patterns to handle various bundlers
|
|
32059
|
+
if (asyncStorageModule?.default?.getItem) {
|
|
32060
|
+
// Metro/Webpack pattern: { default: { getItem, setItem, ... } }
|
|
32061
|
+
this.storage = asyncStorageModule.default;
|
|
32062
|
+
}
|
|
32063
|
+
else if (asyncStorageModule?.getItem) {
|
|
32064
|
+
// Direct export pattern: { getItem, setItem, ... }
|
|
32065
|
+
this.storage = asyncStorageModule;
|
|
32066
|
+
}
|
|
32067
|
+
else if (typeof asyncStorageModule === 'function') {
|
|
32068
|
+
// Function export pattern (some bundlers)
|
|
32069
|
+
this.storage = asyncStorageModule();
|
|
32070
|
+
}
|
|
32071
|
+
else {
|
|
32072
|
+
// Log the structure for debugging
|
|
32073
|
+
console.error('[BundlerAgnosticAsyncStorage] Unknown AsyncStorage structure:', asyncStorageModule);
|
|
32074
|
+
throw new Error('AsyncStorage methods not found. Expected structure with getItem/setItem methods. ' +
|
|
32075
|
+
'Make sure @react-native-async-storage/async-storage is properly installed.');
|
|
32076
|
+
}
|
|
32077
|
+
// Validate that we have the required methods
|
|
32078
|
+
const requiredMethods = ['getItem', 'setItem', 'removeItem', 'getAllKeys', 'multiRemove'];
|
|
32079
|
+
const missingMethods = requiredMethods.filter(method => typeof this.storage[method] !== 'function');
|
|
32080
|
+
if (missingMethods.length > 0) {
|
|
32081
|
+
throw new Error(`AsyncStorage missing required methods: ${missingMethods.join(', ')}. ` +
|
|
32082
|
+
'Ensure @react-native-async-storage/async-storage is properly installed and compatible.');
|
|
32083
|
+
}
|
|
32084
|
+
}
|
|
32085
|
+
async getItem(key) {
|
|
32086
|
+
return this.storage.getItem(key);
|
|
32087
|
+
}
|
|
32088
|
+
async setItem(key, value) {
|
|
32089
|
+
return this.storage.setItem(key, value);
|
|
32090
|
+
}
|
|
32091
|
+
async removeItem(key) {
|
|
32092
|
+
return this.storage.removeItem(key);
|
|
32093
|
+
}
|
|
32094
|
+
async getAllKeys() {
|
|
32095
|
+
return this.storage.getAllKeys();
|
|
32096
|
+
}
|
|
32097
|
+
async multiRemove(keys) {
|
|
32098
|
+
return this.storage.multiRemove(keys);
|
|
32099
|
+
}
|
|
32100
|
+
}
|
|
32101
|
+
/**
|
|
32102
|
+
* AsyncStorage implementation for mobile platforms
|
|
32103
|
+
*
|
|
32104
|
+
* This class is only used on mobile platforms (iOS/Android).
|
|
32105
|
+
* Web platforms use LocalStorageTokenStorage from core SDK.
|
|
32106
|
+
*/
|
|
32107
|
+
class AsyncStorageTokenStorage {
|
|
32108
|
+
constructor(keyPrefix = 'pers_tokens_') {
|
|
32109
|
+
this.keyPrefix = keyPrefix;
|
|
32110
|
+
try {
|
|
32111
|
+
// Initialize bundler-agnostic AsyncStorage wrapper
|
|
32112
|
+
this.asyncStorage = new BundlerAgnosticAsyncStorage(AsyncStorage);
|
|
32113
|
+
}
|
|
32114
|
+
catch (error) {
|
|
32115
|
+
console.error('[AsyncStorageTokenStorage] Failed to initialize:', error);
|
|
32116
|
+
throw new Error('Failed to initialize AsyncStorage. Make sure @react-native-async-storage/async-storage is installed and ' +
|
|
32117
|
+
'this code is running on a React Native mobile platform (not web).');
|
|
32118
|
+
}
|
|
32119
|
+
}
|
|
32120
|
+
async set(key, value) {
|
|
32121
|
+
try {
|
|
32122
|
+
await this.asyncStorage.setItem(`${this.keyPrefix}${key}`, value);
|
|
32123
|
+
}
|
|
32124
|
+
catch (error) {
|
|
32125
|
+
console.error(`Failed to store token ${key}:`, error);
|
|
32126
|
+
throw new Error(`Token storage failed: ${error}`);
|
|
32127
|
+
}
|
|
32128
|
+
}
|
|
32129
|
+
async get(key) {
|
|
32130
|
+
try {
|
|
32131
|
+
return await this.asyncStorage.getItem(`${this.keyPrefix}${key}`);
|
|
32132
|
+
}
|
|
32133
|
+
catch (error) {
|
|
32134
|
+
console.error(`Failed to retrieve token ${key}:`, error);
|
|
32135
|
+
return null;
|
|
32136
|
+
}
|
|
32137
|
+
}
|
|
32138
|
+
async remove(key) {
|
|
32139
|
+
try {
|
|
32140
|
+
await this.asyncStorage.removeItem(`${this.keyPrefix}${key}`);
|
|
32141
|
+
}
|
|
32142
|
+
catch (error) {
|
|
32143
|
+
console.error(`Failed to remove token ${key}:`, error);
|
|
32144
|
+
}
|
|
32145
|
+
}
|
|
32146
|
+
async clear() {
|
|
32147
|
+
try {
|
|
32148
|
+
const allKeys = await this.asyncStorage.getAllKeys();
|
|
32149
|
+
const ourKeys = allKeys.filter(key => key.startsWith(this.keyPrefix));
|
|
32150
|
+
if (ourKeys.length > 0) {
|
|
32151
|
+
await this.asyncStorage.multiRemove(ourKeys);
|
|
32152
|
+
}
|
|
32153
|
+
}
|
|
32154
|
+
catch (error) {
|
|
32155
|
+
console.error('Failed to clear token storage:', error);
|
|
32156
|
+
}
|
|
32157
|
+
}
|
|
32158
|
+
}
|
|
32159
|
+
|
|
32047
32160
|
// Conditionally require Keychain to avoid Web bundler errors
|
|
32048
32161
|
let Keychain;
|
|
32049
32162
|
if (reactNative.Platform.OS !== 'web') {
|
|
@@ -32070,6 +32183,7 @@ class ReactNativeSecureStorage {
|
|
|
32070
32183
|
AUTH_STORAGE_KEYS.REFRESH_TOKEN,
|
|
32071
32184
|
AUTH_STORAGE_KEYS.PROVIDER_TOKEN
|
|
32072
32185
|
]);
|
|
32186
|
+
this.fallbackStorage = new AsyncStorageTokenStorage(keyPrefix);
|
|
32073
32187
|
}
|
|
32074
32188
|
async set(key, value) {
|
|
32075
32189
|
const prefixedKey = this.getKeyName(key);
|
|
@@ -32090,12 +32204,12 @@ class ReactNativeSecureStorage {
|
|
|
32090
32204
|
catch (e) {
|
|
32091
32205
|
console.warn(`[ReactNativeSecureStorage] Keychain set failed for ${key}, falling back to AsyncStorage`, e);
|
|
32092
32206
|
// Fallback to AsyncStorage if Keychain fails
|
|
32093
|
-
await
|
|
32207
|
+
await this.fallbackStorage.set(key, stringValue);
|
|
32094
32208
|
}
|
|
32095
32209
|
}
|
|
32096
32210
|
else {
|
|
32097
32211
|
// Store standard config/metadata in AsyncStorage
|
|
32098
|
-
await
|
|
32212
|
+
await this.fallbackStorage.set(key, stringValue);
|
|
32099
32213
|
}
|
|
32100
32214
|
}
|
|
32101
32215
|
async get(key) {
|
|
@@ -32115,7 +32229,7 @@ class ReactNativeSecureStorage {
|
|
|
32115
32229
|
}
|
|
32116
32230
|
// Fallback: Check AsyncStorage if not found in Keychain or Keychain failed
|
|
32117
32231
|
try {
|
|
32118
|
-
const val = await
|
|
32232
|
+
const val = await this.fallbackStorage.get(key);
|
|
32119
32233
|
return val ? this.tryParse(val) : null;
|
|
32120
32234
|
}
|
|
32121
32235
|
catch (e) {
|
|
@@ -32124,7 +32238,7 @@ class ReactNativeSecureStorage {
|
|
|
32124
32238
|
}
|
|
32125
32239
|
else {
|
|
32126
32240
|
try {
|
|
32127
|
-
const val = await
|
|
32241
|
+
const val = await this.fallbackStorage.get(key);
|
|
32128
32242
|
return val ? this.tryParse(val) : null;
|
|
32129
32243
|
}
|
|
32130
32244
|
catch (e) {
|
|
@@ -32145,10 +32259,10 @@ class ReactNativeSecureStorage {
|
|
|
32145
32259
|
console.warn(`[ReactNativeSecureStorage] Failed to reset keychain for ${key}`, e);
|
|
32146
32260
|
}
|
|
32147
32261
|
// Always remove from fallback storage too, just in case
|
|
32148
|
-
await
|
|
32262
|
+
await this.fallbackStorage.remove(key);
|
|
32149
32263
|
}
|
|
32150
32264
|
else {
|
|
32151
|
-
await
|
|
32265
|
+
await this.fallbackStorage.remove(key);
|
|
32152
32266
|
}
|
|
32153
32267
|
}
|
|
32154
32268
|
async clear() {
|
|
@@ -32165,11 +32279,7 @@ class ReactNativeSecureStorage {
|
|
|
32165
32279
|
}
|
|
32166
32280
|
// Clear AsyncStorage keys related to PERS
|
|
32167
32281
|
try {
|
|
32168
|
-
|
|
32169
|
-
const ourKeys = allKeys.filter(k => k.startsWith(this.keyPrefix));
|
|
32170
|
-
if (ourKeys.length > 0) {
|
|
32171
|
-
await AsyncStorage.multiRemove(ourKeys);
|
|
32172
|
-
}
|
|
32282
|
+
await this.fallbackStorage.clear();
|
|
32173
32283
|
}
|
|
32174
32284
|
catch (e) {
|
|
32175
32285
|
console.warn('[ReactNativeSecureStorage] Failed to clear AsyncStorage', e);
|
|
@@ -32238,119 +32348,6 @@ function createReactNativeAuthProvider(projectKey, config = {}) {
|
|
|
32238
32348
|
});
|
|
32239
32349
|
}
|
|
32240
32350
|
|
|
32241
|
-
/**
|
|
32242
|
-
* AsyncStorage Token Storage for React Native Mobile Platforms
|
|
32243
|
-
*
|
|
32244
|
-
* Bundler-agnostic AsyncStorage implementation for mobile platforms
|
|
32245
|
-
*/
|
|
32246
|
-
/**
|
|
32247
|
-
* Bundler-agnostic AsyncStorage wrapper
|
|
32248
|
-
* Handles different module resolution patterns across bundlers (Metro, Webpack, Rollup, etc.)
|
|
32249
|
-
*/
|
|
32250
|
-
class BundlerAgnosticAsyncStorage {
|
|
32251
|
-
constructor(asyncStorageModule) {
|
|
32252
|
-
// Try different import patterns to handle various bundlers
|
|
32253
|
-
if (asyncStorageModule?.default?.getItem) {
|
|
32254
|
-
// Metro/Webpack pattern: { default: { getItem, setItem, ... } }
|
|
32255
|
-
this.storage = asyncStorageModule.default;
|
|
32256
|
-
}
|
|
32257
|
-
else if (asyncStorageModule?.getItem) {
|
|
32258
|
-
// Direct export pattern: { getItem, setItem, ... }
|
|
32259
|
-
this.storage = asyncStorageModule;
|
|
32260
|
-
}
|
|
32261
|
-
else if (typeof asyncStorageModule === 'function') {
|
|
32262
|
-
// Function export pattern (some bundlers)
|
|
32263
|
-
this.storage = asyncStorageModule();
|
|
32264
|
-
}
|
|
32265
|
-
else {
|
|
32266
|
-
// Log the structure for debugging
|
|
32267
|
-
console.error('[BundlerAgnosticAsyncStorage] Unknown AsyncStorage structure:', asyncStorageModule);
|
|
32268
|
-
throw new Error('AsyncStorage methods not found. Expected structure with getItem/setItem methods. ' +
|
|
32269
|
-
'Make sure @react-native-async-storage/async-storage is properly installed.');
|
|
32270
|
-
}
|
|
32271
|
-
// Validate that we have the required methods
|
|
32272
|
-
const requiredMethods = ['getItem', 'setItem', 'removeItem', 'getAllKeys', 'multiRemove'];
|
|
32273
|
-
const missingMethods = requiredMethods.filter(method => typeof this.storage[method] !== 'function');
|
|
32274
|
-
if (missingMethods.length > 0) {
|
|
32275
|
-
throw new Error(`AsyncStorage missing required methods: ${missingMethods.join(', ')}. ` +
|
|
32276
|
-
'Ensure @react-native-async-storage/async-storage is properly installed and compatible.');
|
|
32277
|
-
}
|
|
32278
|
-
}
|
|
32279
|
-
async getItem(key) {
|
|
32280
|
-
return this.storage.getItem(key);
|
|
32281
|
-
}
|
|
32282
|
-
async setItem(key, value) {
|
|
32283
|
-
return this.storage.setItem(key, value);
|
|
32284
|
-
}
|
|
32285
|
-
async removeItem(key) {
|
|
32286
|
-
return this.storage.removeItem(key);
|
|
32287
|
-
}
|
|
32288
|
-
async getAllKeys() {
|
|
32289
|
-
return this.storage.getAllKeys();
|
|
32290
|
-
}
|
|
32291
|
-
async multiRemove(keys) {
|
|
32292
|
-
return this.storage.multiRemove(keys);
|
|
32293
|
-
}
|
|
32294
|
-
}
|
|
32295
|
-
/**
|
|
32296
|
-
* AsyncStorage implementation for mobile platforms
|
|
32297
|
-
*
|
|
32298
|
-
* This class is only used on mobile platforms (iOS/Android).
|
|
32299
|
-
* Web platforms use LocalStorageTokenStorage from core SDK.
|
|
32300
|
-
*/
|
|
32301
|
-
class AsyncStorageTokenStorage {
|
|
32302
|
-
constructor(keyPrefix = 'pers_tokens_') {
|
|
32303
|
-
this.keyPrefix = keyPrefix;
|
|
32304
|
-
try {
|
|
32305
|
-
// Initialize bundler-agnostic AsyncStorage wrapper
|
|
32306
|
-
this.asyncStorage = new BundlerAgnosticAsyncStorage(AsyncStorage);
|
|
32307
|
-
}
|
|
32308
|
-
catch (error) {
|
|
32309
|
-
console.error('[AsyncStorageTokenStorage] Failed to initialize:', error);
|
|
32310
|
-
throw new Error('Failed to initialize AsyncStorage. Make sure @react-native-async-storage/async-storage is installed and ' +
|
|
32311
|
-
'this code is running on a React Native mobile platform (not web).');
|
|
32312
|
-
}
|
|
32313
|
-
}
|
|
32314
|
-
async set(key, value) {
|
|
32315
|
-
try {
|
|
32316
|
-
await this.asyncStorage.setItem(`${this.keyPrefix}${key}`, value);
|
|
32317
|
-
}
|
|
32318
|
-
catch (error) {
|
|
32319
|
-
console.error(`Failed to store token ${key}:`, error);
|
|
32320
|
-
throw new Error(`Token storage failed: ${error}`);
|
|
32321
|
-
}
|
|
32322
|
-
}
|
|
32323
|
-
async get(key) {
|
|
32324
|
-
try {
|
|
32325
|
-
return await this.asyncStorage.getItem(`${this.keyPrefix}${key}`);
|
|
32326
|
-
}
|
|
32327
|
-
catch (error) {
|
|
32328
|
-
console.error(`Failed to retrieve token ${key}:`, error);
|
|
32329
|
-
return null;
|
|
32330
|
-
}
|
|
32331
|
-
}
|
|
32332
|
-
async remove(key) {
|
|
32333
|
-
try {
|
|
32334
|
-
await this.asyncStorage.removeItem(`${this.keyPrefix}${key}`);
|
|
32335
|
-
}
|
|
32336
|
-
catch (error) {
|
|
32337
|
-
console.error(`Failed to remove token ${key}:`, error);
|
|
32338
|
-
}
|
|
32339
|
-
}
|
|
32340
|
-
async clear() {
|
|
32341
|
-
try {
|
|
32342
|
-
const allKeys = await this.asyncStorage.getAllKeys();
|
|
32343
|
-
const ourKeys = allKeys.filter(key => key.startsWith(this.keyPrefix));
|
|
32344
|
-
if (ourKeys.length > 0) {
|
|
32345
|
-
await this.asyncStorage.multiRemove(ourKeys);
|
|
32346
|
-
}
|
|
32347
|
-
}
|
|
32348
|
-
catch (error) {
|
|
32349
|
-
console.error('Failed to clear token storage:', error);
|
|
32350
|
-
}
|
|
32351
|
-
}
|
|
32352
|
-
}
|
|
32353
|
-
|
|
32354
32351
|
// Conditionally require quick-crypto for Native platforms only
|
|
32355
32352
|
let crypto$1;
|
|
32356
32353
|
if (reactNative.Platform.OS !== 'web') {
|
|
@@ -32363,7 +32360,6 @@ if (reactNative.Platform.OS !== 'web') {
|
|
|
32363
32360
|
}
|
|
32364
32361
|
else {
|
|
32365
32362
|
// on Web, we shouldn't be using this provider anyway (Core SDK has WebDPoPProvider)
|
|
32366
|
-
// But to be safe, we can mock or throw
|
|
32367
32363
|
crypto$1 = {
|
|
32368
32364
|
generateKeyPair: () => { throw new Error('ReactNativeDPoPProvider not supported on Web'); }
|
|
32369
32365
|
};
|
|
@@ -32372,26 +32368,39 @@ class ReactNativeDPoPProvider {
|
|
|
32372
32368
|
/**
|
|
32373
32369
|
* Generates a new key pair (ES256 recommended)
|
|
32374
32370
|
*
|
|
32375
|
-
*
|
|
32376
|
-
*
|
|
32377
|
-
* for security at rest (High Security), making the key "Extractable" in memory
|
|
32378
|
-
* but protected by hardware encryption when stored.
|
|
32371
|
+
* Uses WebCrypto API (crypto.subtle) for cross-platform compatibility.
|
|
32372
|
+
* Falls back to Node.js crypto API on iOS if needed.
|
|
32379
32373
|
*/
|
|
32380
32374
|
async generateKeyPair(options) {
|
|
32381
|
-
//
|
|
32375
|
+
// Try WebCrypto API first (works on both iOS and Android)
|
|
32376
|
+
if (crypto$1.subtle) {
|
|
32377
|
+
try {
|
|
32378
|
+
const keyPair = await crypto$1.subtle.generateKey({ name: 'ECDSA', namedCurve: 'P-256' }, true, // extractable - required for JWK export
|
|
32379
|
+
['sign', 'verify']);
|
|
32380
|
+
const publicKeyJwk = await crypto$1.subtle.exportKey('jwk', keyPair.publicKey);
|
|
32381
|
+
const privateKeyJwk = await crypto$1.subtle.exportKey('jwk', keyPair.privateKey);
|
|
32382
|
+
return {
|
|
32383
|
+
publicKey: publicKeyJwk,
|
|
32384
|
+
privateKey: privateKeyJwk
|
|
32385
|
+
};
|
|
32386
|
+
}
|
|
32387
|
+
catch (err) {
|
|
32388
|
+
console.warn('[DPoP] WebCrypto API failed, trying Node.js crypto API', err);
|
|
32389
|
+
}
|
|
32390
|
+
}
|
|
32391
|
+
// Fallback: Node.js crypto API (works on iOS)
|
|
32382
32392
|
return new Promise((resolve, reject) => {
|
|
32383
32393
|
crypto$1.generateKeyPair('ec', { namedCurve: 'P-256' }, (err, publicKey, privateKey) => {
|
|
32384
32394
|
if (err)
|
|
32385
32395
|
return reject(err);
|
|
32386
|
-
|
|
32387
|
-
|
|
32388
|
-
|
|
32389
|
-
|
|
32390
|
-
|
|
32391
|
-
|
|
32392
|
-
|
|
32393
|
-
|
|
32394
|
-
});
|
|
32396
|
+
try {
|
|
32397
|
+
const pJwk = publicKey.export({ format: 'jwk' });
|
|
32398
|
+
const prJwk = privateKey.export({ format: 'jwk' });
|
|
32399
|
+
resolve({ publicKey: pJwk, privateKey: prJwk });
|
|
32400
|
+
}
|
|
32401
|
+
catch (exportErr) {
|
|
32402
|
+
reject(exportErr);
|
|
32403
|
+
}
|
|
32395
32404
|
});
|
|
32396
32405
|
});
|
|
32397
32406
|
}
|
|
@@ -32412,21 +32421,37 @@ class ReactNativeDPoPProvider {
|
|
|
32412
32421
|
const b64Header = this.base64Url(JSON.stringify(header));
|
|
32413
32422
|
const b64Payload = this.base64Url(JSON.stringify(finalPayload));
|
|
32414
32423
|
const signingInput = `${b64Header}.${b64Payload}`;
|
|
32415
|
-
// 4. Sign
|
|
32424
|
+
// 4. Sign - try WebCrypto first, fallback to Node.js crypto
|
|
32425
|
+
if (crypto$1.subtle) {
|
|
32426
|
+
try {
|
|
32427
|
+
const privateKey = await crypto$1.subtle.importKey('jwk', keyPair.privateKey, { name: 'ECDSA', namedCurve: 'P-256' }, false, ['sign']);
|
|
32428
|
+
const signatureBuffer = await crypto$1.subtle.sign({ name: 'ECDSA', hash: 'SHA-256' }, privateKey, buffer.Buffer.from(signingInput));
|
|
32429
|
+
// WebCrypto returns signature in IEEE P1363 format (r || s), which is what we need for JWT
|
|
32430
|
+
return `${signingInput}.${this.base64UrlBuffer(buffer.Buffer.from(signatureBuffer))}`;
|
|
32431
|
+
}
|
|
32432
|
+
catch (err) {
|
|
32433
|
+
console.warn('[DPoP] WebCrypto sign failed, trying Node.js crypto', err);
|
|
32434
|
+
}
|
|
32435
|
+
}
|
|
32436
|
+
// Fallback: Node.js crypto API
|
|
32416
32437
|
const sign = crypto$1.createSign('SHA256');
|
|
32417
32438
|
sign.update(signingInput);
|
|
32418
|
-
// sign.end() is not required/available in quick-crypto as it doesn't strictly follow stream interface
|
|
32419
|
-
// Import private key back from JWK to sign
|
|
32420
|
-
// The keyPair.privateKey is a JsonWebKey object because we exported it earlier.
|
|
32421
|
-
// quick-crypto createPrivateKey expects jwk object if format is jwk
|
|
32422
32439
|
const privateKeyObj = crypto$1.createPrivateKey({ key: keyPair.privateKey, format: 'jwk' });
|
|
32423
32440
|
const signature = sign.sign(privateKeyObj);
|
|
32424
|
-
// signature is a Buffer in quick-crypto
|
|
32425
32441
|
return `${signingInput}.${this.base64UrlBuffer(signature)}`;
|
|
32426
32442
|
}
|
|
32427
32443
|
async hashAccessToken(accessToken) {
|
|
32444
|
+
// Try WebCrypto first
|
|
32445
|
+
if (crypto$1.subtle) {
|
|
32446
|
+
try {
|
|
32447
|
+
const hashBuffer = await crypto$1.subtle.digest('SHA-256', buffer.Buffer.from(accessToken));
|
|
32448
|
+
return this.base64UrlBuffer(buffer.Buffer.from(hashBuffer));
|
|
32449
|
+
}
|
|
32450
|
+
catch (err) {
|
|
32451
|
+
// Fallback to Node.js crypto
|
|
32452
|
+
}
|
|
32453
|
+
}
|
|
32428
32454
|
const hash = crypto$1.createHash('sha256').update(accessToken).digest();
|
|
32429
|
-
// digest returns Buffer in quick-crypto
|
|
32430
32455
|
return this.base64UrlBuffer(hash);
|
|
32431
32456
|
}
|
|
32432
32457
|
// --- Helpers ---
|
|
@@ -32434,7 +32459,6 @@ class ReactNativeDPoPProvider {
|
|
|
32434
32459
|
return this.base64UrlBuffer(buffer.Buffer.from(str));
|
|
32435
32460
|
}
|
|
32436
32461
|
base64UrlBuffer(buf) {
|
|
32437
|
-
// Ensure we have a Buffer
|
|
32438
32462
|
const buffer$1 = buffer.Buffer.isBuffer(buf) ? buf : buffer.Buffer.from(buf);
|
|
32439
32463
|
return buffer$1.toString('base64')
|
|
32440
32464
|
.replace(/=/g, '')
|
|
@@ -32548,7 +32572,6 @@ const PersSDKProvider = ({ children, config }) => {
|
|
|
32548
32572
|
const [isInitialized, setIsInitialized] = react.useState(false);
|
|
32549
32573
|
const [isAuthenticated, setIsAuthenticated] = react.useState(false);
|
|
32550
32574
|
const [user, setUser] = react.useState(null);
|
|
32551
|
-
const [accountAddress, setAccountAddress] = react.useState(null);
|
|
32552
32575
|
const initialize = react.useCallback(async (config) => {
|
|
32553
32576
|
// Prevent multiple initializations
|
|
32554
32577
|
if (isInitialized || initializingRef.current) {
|
|
@@ -32610,9 +32633,8 @@ const PersSDKProvider = ({ children, config }) => {
|
|
|
32610
32633
|
});
|
|
32611
32634
|
}
|
|
32612
32635
|
}, [config, isInitialized, initialize]);
|
|
32613
|
-
const setAuthenticationState = react.useCallback((user,
|
|
32636
|
+
const setAuthenticationState = react.useCallback((user, isAuthenticated) => {
|
|
32614
32637
|
setUser(user);
|
|
32615
|
-
setAccountAddress(accountAddress);
|
|
32616
32638
|
setIsAuthenticated(isAuthenticated);
|
|
32617
32639
|
}, []);
|
|
32618
32640
|
const refreshUserData = react.useCallback(async () => {
|
|
@@ -32628,7 +32650,7 @@ const PersSDKProvider = ({ children, config }) => {
|
|
|
32628
32650
|
throw error;
|
|
32629
32651
|
}
|
|
32630
32652
|
}, [sdk, isAuthenticated, isInitialized]);
|
|
32631
|
-
const contextValue = {
|
|
32653
|
+
const contextValue = react.useMemo(() => ({
|
|
32632
32654
|
// Main SDK instance
|
|
32633
32655
|
sdk,
|
|
32634
32656
|
// Manager shortcuts for convenience
|
|
@@ -32643,20 +32665,26 @@ const PersSDKProvider = ({ children, config }) => {
|
|
|
32643
32665
|
tenants: sdk?.tenants || null,
|
|
32644
32666
|
analytics: sdk?.analytics || null,
|
|
32645
32667
|
donations: sdk?.donations || null,
|
|
32646
|
-
// Legacy support (deprecated but kept for backward compatibility)
|
|
32647
|
-
business: sdk?.businesses || null,
|
|
32648
32668
|
// Platform-specific providers
|
|
32649
32669
|
authProvider,
|
|
32650
32670
|
// State
|
|
32651
32671
|
isInitialized,
|
|
32652
32672
|
isAuthenticated,
|
|
32653
32673
|
user,
|
|
32654
|
-
accountAddress,
|
|
32655
32674
|
// Methods
|
|
32656
32675
|
initialize,
|
|
32657
32676
|
setAuthenticationState,
|
|
32658
32677
|
refreshUserData,
|
|
32659
|
-
}
|
|
32678
|
+
}), [
|
|
32679
|
+
sdk,
|
|
32680
|
+
authProvider,
|
|
32681
|
+
isInitialized,
|
|
32682
|
+
isAuthenticated,
|
|
32683
|
+
user,
|
|
32684
|
+
initialize,
|
|
32685
|
+
setAuthenticationState,
|
|
32686
|
+
refreshUserData
|
|
32687
|
+
]);
|
|
32660
32688
|
return (jsxRuntime.jsx(SDKContext.Provider, { value: contextValue, children: children }));
|
|
32661
32689
|
};
|
|
32662
32690
|
// Custom hook to use the SDK context
|
|
@@ -32706,7 +32734,7 @@ const usePersSDK = () => {
|
|
|
32706
32734
|
* ```
|
|
32707
32735
|
*/
|
|
32708
32736
|
const useAuth = () => {
|
|
32709
|
-
const { sdk, authProvider, isInitialized, isAuthenticated, user,
|
|
32737
|
+
const { sdk, authProvider, isInitialized, isAuthenticated, user, setAuthenticationState, refreshUserData } = usePersSDK();
|
|
32710
32738
|
/**
|
|
32711
32739
|
* Authenticates a user with a JWT token
|
|
32712
32740
|
*
|
|
@@ -32727,18 +32755,13 @@ const useAuth = () => {
|
|
|
32727
32755
|
throw new Error('SDK not initialized. Call initialize() first.');
|
|
32728
32756
|
}
|
|
32729
32757
|
try {
|
|
32730
|
-
console.log(`Logging in as ${userType}...`);
|
|
32731
32758
|
// Set token in auth provider
|
|
32732
32759
|
await authProvider.setAccessToken(jwtToken);
|
|
32733
32760
|
// Perform login using the manager
|
|
32734
32761
|
const result = await sdk.auth.loginWithToken(jwtToken, userType);
|
|
32735
32762
|
const userData = result.user || result.admin;
|
|
32736
32763
|
if (userData) {
|
|
32737
|
-
|
|
32738
|
-
('wallets' in userData && userData.wallets?.[0]?.address) ||
|
|
32739
|
-
null;
|
|
32740
|
-
setAuthenticationState(userData, userAccountAddress, true);
|
|
32741
|
-
console.log('Login successful');
|
|
32764
|
+
setAuthenticationState(userData, true);
|
|
32742
32765
|
return result;
|
|
32743
32766
|
}
|
|
32744
32767
|
else {
|
|
@@ -32767,7 +32790,6 @@ const useAuth = () => {
|
|
|
32767
32790
|
throw new Error('SDK not initialized. Call initialize() first.');
|
|
32768
32791
|
}
|
|
32769
32792
|
try {
|
|
32770
|
-
console.log('Logging in with raw user data...');
|
|
32771
32793
|
// Use the raw data login from the auth manager
|
|
32772
32794
|
const result = await sdk.auth.loginWithRawData(rawUserData);
|
|
32773
32795
|
// Set token from result
|
|
@@ -32776,11 +32798,7 @@ const useAuth = () => {
|
|
|
32776
32798
|
}
|
|
32777
32799
|
const userData = result.user;
|
|
32778
32800
|
if (userData) {
|
|
32779
|
-
|
|
32780
|
-
userData?.wallets?.[0]?.address ||
|
|
32781
|
-
null;
|
|
32782
|
-
setAuthenticationState(userData, userAccountAddress, true);
|
|
32783
|
-
console.log('Raw data login successful');
|
|
32801
|
+
setAuthenticationState(userData, true);
|
|
32784
32802
|
}
|
|
32785
32803
|
else {
|
|
32786
32804
|
throw new Error('No user data returned from raw data login');
|
|
@@ -32805,12 +32823,10 @@ const useAuth = () => {
|
|
|
32805
32823
|
*/
|
|
32806
32824
|
const logout = react.useCallback(async () => {
|
|
32807
32825
|
try {
|
|
32808
|
-
console.log('Logging out...');
|
|
32809
32826
|
if (authProvider) {
|
|
32810
32827
|
await authProvider.clearTokens();
|
|
32811
32828
|
}
|
|
32812
|
-
setAuthenticationState(null,
|
|
32813
|
-
console.log('Logout successful');
|
|
32829
|
+
setAuthenticationState(null, false);
|
|
32814
32830
|
}
|
|
32815
32831
|
catch (error) {
|
|
32816
32832
|
console.error('Logout failed:', error);
|
|
@@ -32891,7 +32907,7 @@ const useAuth = () => {
|
|
|
32891
32907
|
throw new Error('SDK not initialized. Call initialize() first.');
|
|
32892
32908
|
}
|
|
32893
32909
|
await sdk.auth.clearAuth();
|
|
32894
|
-
setAuthenticationState(null,
|
|
32910
|
+
setAuthenticationState(null, false);
|
|
32895
32911
|
}, [sdk, setAuthenticationState]);
|
|
32896
32912
|
/**
|
|
32897
32913
|
* Checks if the current authentication is valid (non-expired)
|
|
@@ -32916,7 +32932,6 @@ const useAuth = () => {
|
|
|
32916
32932
|
isInitialized,
|
|
32917
32933
|
isAuthenticated,
|
|
32918
32934
|
user,
|
|
32919
|
-
accountAddress,
|
|
32920
32935
|
// Methods
|
|
32921
32936
|
login,
|
|
32922
32937
|
loginWithRawData,
|
|
@@ -32982,7 +32997,6 @@ const useTokens = () => {
|
|
|
32982
32997
|
}
|
|
32983
32998
|
try {
|
|
32984
32999
|
const result = await sdk.tokens.getTokens();
|
|
32985
|
-
console.log('Tokens fetched successfully:', result);
|
|
32986
33000
|
return result;
|
|
32987
33001
|
}
|
|
32988
33002
|
catch (error) {
|
|
@@ -33009,7 +33023,6 @@ const useTokens = () => {
|
|
|
33009
33023
|
}
|
|
33010
33024
|
try {
|
|
33011
33025
|
const result = await sdk.tokens.getActiveCreditToken();
|
|
33012
|
-
console.log('Active credit token fetched successfully:', result);
|
|
33013
33026
|
return result;
|
|
33014
33027
|
}
|
|
33015
33028
|
catch (error) {
|
|
@@ -33036,7 +33049,6 @@ const useTokens = () => {
|
|
|
33036
33049
|
}
|
|
33037
33050
|
try {
|
|
33038
33051
|
const result = await sdk.tokens.getRewardTokens();
|
|
33039
|
-
console.log('Reward tokens fetched successfully:', result);
|
|
33040
33052
|
return result;
|
|
33041
33053
|
}
|
|
33042
33054
|
catch (error) {
|
|
@@ -33063,7 +33075,6 @@ const useTokens = () => {
|
|
|
33063
33075
|
}
|
|
33064
33076
|
try {
|
|
33065
33077
|
const result = await sdk.tokens.getTokenTypes();
|
|
33066
|
-
console.log('Token types fetched successfully:', result);
|
|
33067
33078
|
return result;
|
|
33068
33079
|
}
|
|
33069
33080
|
catch (error) {
|
|
@@ -33090,7 +33101,6 @@ const useTokens = () => {
|
|
|
33090
33101
|
}
|
|
33091
33102
|
try {
|
|
33092
33103
|
const result = await sdk.tokens.getStatusTokens();
|
|
33093
|
-
console.log('Status tokens fetched successfully:', result);
|
|
33094
33104
|
return result;
|
|
33095
33105
|
}
|
|
33096
33106
|
catch (error) {
|
|
@@ -33119,7 +33129,6 @@ const useTokens = () => {
|
|
|
33119
33129
|
}
|
|
33120
33130
|
try {
|
|
33121
33131
|
const result = await sdk.tokens.getTokenByContract(contractAddress, contractTokenId);
|
|
33122
|
-
console.log('Token by contract fetched successfully:', result);
|
|
33123
33132
|
return result;
|
|
33124
33133
|
}
|
|
33125
33134
|
catch (error) {
|
|
@@ -33138,6 +33147,45 @@ const useTokens = () => {
|
|
|
33138
33147
|
};
|
|
33139
33148
|
};
|
|
33140
33149
|
|
|
33150
|
+
/**
|
|
33151
|
+
* Transaction statuses that allow signing
|
|
33152
|
+
*/
|
|
33153
|
+
[exports.TransactionStatus.PENDING_SIGNATURE, exports.TransactionStatus.CREATED];
|
|
33154
|
+
|
|
33155
|
+
/**
|
|
33156
|
+
* Error codes for transaction signing operations
|
|
33157
|
+
*/
|
|
33158
|
+
var TransactionSigningErrorCode;
|
|
33159
|
+
(function (TransactionSigningErrorCode) {
|
|
33160
|
+
TransactionSigningErrorCode["INVALID_TOKENS"] = "INVALID_TOKENS";
|
|
33161
|
+
TransactionSigningErrorCode["TRANSACTION_NOT_FOUND"] = "TRANSACTION_NOT_FOUND";
|
|
33162
|
+
TransactionSigningErrorCode["TRANSACTION_NOT_PENDING"] = "TRANSACTION_NOT_PENDING";
|
|
33163
|
+
TransactionSigningErrorCode["WALLET_NOT_AVAILABLE"] = "WALLET_NOT_AVAILABLE";
|
|
33164
|
+
TransactionSigningErrorCode["WEBAUTHN_OPERATION_IN_PROGRESS"] = "WEBAUTHN_OPERATION_IN_PROGRESS";
|
|
33165
|
+
TransactionSigningErrorCode["SIGNING_CANCELLED"] = "SIGNING_CANCELLED";
|
|
33166
|
+
TransactionSigningErrorCode["PERS_AUTH_FAILED"] = "PERS_AUTH_FAILED";
|
|
33167
|
+
TransactionSigningErrorCode["AUTH_FAILED"] = "AUTH_FAILED";
|
|
33168
|
+
TransactionSigningErrorCode["TRANSACTION_NOT_READY"] = "TRANSACTION_NOT_READY";
|
|
33169
|
+
TransactionSigningErrorCode["SUBMISSION_FAILED"] = "SUBMISSION_FAILED";
|
|
33170
|
+
TransactionSigningErrorCode["SERVER_ERROR"] = "SERVER_ERROR";
|
|
33171
|
+
TransactionSigningErrorCode["UNKNOWN_ERROR"] = "UNKNOWN_ERROR";
|
|
33172
|
+
})(TransactionSigningErrorCode || (TransactionSigningErrorCode = {}));
|
|
33173
|
+
|
|
33174
|
+
/**
|
|
33175
|
+
* Signing status types for type-safe status updates
|
|
33176
|
+
* Using const pattern instead of enum for better bundling compatibility
|
|
33177
|
+
*/
|
|
33178
|
+
const SigningStatus = {
|
|
33179
|
+
INITIALIZING: 'initializing',
|
|
33180
|
+
AUTHENTICATING: 'authenticating',
|
|
33181
|
+
PREPARING: 'preparing',
|
|
33182
|
+
SIGNING: 'signing',
|
|
33183
|
+
SUBMITTING: 'submitting',
|
|
33184
|
+
COMPLETED: 'completed',
|
|
33185
|
+
ERROR: 'error',
|
|
33186
|
+
EXPIRED: 'expired'
|
|
33187
|
+
};
|
|
33188
|
+
|
|
33141
33189
|
// Dynamic import the signer SDK to avoid build issues with static dependencies
|
|
33142
33190
|
let createPersSignerSDK = null;
|
|
33143
33191
|
try {
|
|
@@ -33330,6 +33378,8 @@ const DEFAULT_ETHERS_PROVIDER = "https://sepolia.infura.io/v3/2781b4b5242343d5b0
|
|
|
33330
33378
|
const useTransactionSigner = () => {
|
|
33331
33379
|
// const { isInitialized, isAuthenticated, user } = usePersSDK();
|
|
33332
33380
|
const [isSignerInitialized, setIsSignerInitialized] = react.useState(false);
|
|
33381
|
+
const [currentStatus, setCurrentStatus] = react.useState(null);
|
|
33382
|
+
const [statusMessage, setStatusMessage] = react.useState(null);
|
|
33333
33383
|
const signerSDKRef = react.useRef(null);
|
|
33334
33384
|
// Auto-initialize signer SDK when PERS SDK is ready
|
|
33335
33385
|
react.useEffect(() => {
|
|
@@ -33378,6 +33428,7 @@ const useTransactionSigner = () => {
|
|
|
33378
33428
|
*
|
|
33379
33429
|
* @param {string} jwt - JWT token containing transaction ID and user information
|
|
33380
33430
|
* Must include: `transactionId`, `identifierEmail`, `tenantId`
|
|
33431
|
+
* @param {StatusCallback} [onStatusUpdate] - Optional callback for real-time status updates
|
|
33381
33432
|
* @returns {Promise<SubmissionResult>} Complete transaction result
|
|
33382
33433
|
*
|
|
33383
33434
|
* @throws {Error} 'Transaction signer not initialized' - Hook not ready
|
|
@@ -33400,6 +33451,15 @@ const useTransactionSigner = () => {
|
|
|
33400
33451
|
* ```
|
|
33401
33452
|
*
|
|
33402
33453
|
* @example
|
|
33454
|
+
* **With Status Updates:**
|
|
33455
|
+
* ```typescript
|
|
33456
|
+
* const result = await signAndSubmitTransactionWithJWT(jwtToken, (status, message) => {
|
|
33457
|
+
* console.log(`Status: ${status} - ${message}`);
|
|
33458
|
+
* setStatusText(message);
|
|
33459
|
+
* });
|
|
33460
|
+
* ```
|
|
33461
|
+
*
|
|
33462
|
+
* @example
|
|
33403
33463
|
* **With Error Handling:**
|
|
33404
33464
|
* ```typescript
|
|
33405
33465
|
* try {
|
|
@@ -33434,20 +33494,30 @@ const useTransactionSigner = () => {
|
|
|
33434
33494
|
*
|
|
33435
33495
|
* @see {@link SubmissionResult} for detailed result structure
|
|
33436
33496
|
*/
|
|
33437
|
-
const signAndSubmitTransactionWithJWT = react.useCallback(async (jwt) => {
|
|
33497
|
+
const signAndSubmitTransactionWithJWT = react.useCallback(async (jwt, onStatusUpdate) => {
|
|
33438
33498
|
if (!isSignerInitialized || !signerSDKRef.current) {
|
|
33439
33499
|
throw new Error('Transaction signer not initialized');
|
|
33440
33500
|
}
|
|
33441
33501
|
if (!createPersSignerSDK) {
|
|
33442
33502
|
throw new Error('PERS Signer SDK not available. Blockchain signing is not supported.');
|
|
33443
33503
|
}
|
|
33504
|
+
// Create status callback wrapper that updates both hook state and calls user callback
|
|
33505
|
+
const statusCallback = {
|
|
33506
|
+
onStatusUpdate: (status, message, data) => {
|
|
33507
|
+
setCurrentStatus(status);
|
|
33508
|
+
setStatusMessage(message);
|
|
33509
|
+
onStatusUpdate?.(status, message, data);
|
|
33510
|
+
}
|
|
33511
|
+
};
|
|
33444
33512
|
try {
|
|
33445
33513
|
// Use the actual SDK method that handles the complete sign + submit flow
|
|
33446
|
-
const submissionResult = await signerSDKRef.current.signAndSubmitPersTransaction(jwt);
|
|
33514
|
+
const submissionResult = await signerSDKRef.current.signAndSubmitPersTransaction(jwt, statusCallback);
|
|
33447
33515
|
return submissionResult;
|
|
33448
33516
|
}
|
|
33449
33517
|
catch (error) {
|
|
33450
33518
|
console.error('[useTransactionSigner] JWT transaction signing failed:', error);
|
|
33519
|
+
setCurrentStatus(SigningStatus.ERROR);
|
|
33520
|
+
setStatusMessage(error instanceof Error ? error.message : 'Transaction failed');
|
|
33451
33521
|
throw error; // Re-throw to maintain error handling upstream
|
|
33452
33522
|
}
|
|
33453
33523
|
}, [isSignerInitialized]);
|
|
@@ -33459,6 +33529,7 @@ const useTransactionSigner = () => {
|
|
|
33459
33529
|
* from authentication to blockchain submission in a single call.
|
|
33460
33530
|
*
|
|
33461
33531
|
* @param {string} jwt - JWT token with transaction and user data
|
|
33532
|
+
* @param {StatusCallback} [onStatusUpdate] - Optional callback for real-time status updates
|
|
33462
33533
|
* @returns {Promise<SubmissionResult>} Transaction result with hash and status
|
|
33463
33534
|
*/
|
|
33464
33535
|
signAndSubmitTransactionWithJWT,
|
|
@@ -33504,6 +33575,36 @@ const useTransactionSigner = () => {
|
|
|
33504
33575
|
* ```
|
|
33505
33576
|
*/
|
|
33506
33577
|
isSignerAvailable: isSignerInitialized && !!createPersSignerSDK,
|
|
33578
|
+
/**
|
|
33579
|
+
* Current signing status for UI feedback
|
|
33580
|
+
*
|
|
33581
|
+
* Tracks the current state of the signing process. Use this to show
|
|
33582
|
+
* progress indicators or status messages during transaction signing.
|
|
33583
|
+
*
|
|
33584
|
+
* Possible values: 'initializing', 'authenticating', 'preparing',
|
|
33585
|
+
* 'signing', 'submitting', 'completed', 'error', 'expired'
|
|
33586
|
+
*
|
|
33587
|
+
* @example
|
|
33588
|
+
* ```typescript
|
|
33589
|
+
* const { currentStatus, statusMessage } = useTransactionSigner();
|
|
33590
|
+
*
|
|
33591
|
+
* return (
|
|
33592
|
+
* <View>
|
|
33593
|
+
* {currentStatus && (
|
|
33594
|
+
* <Text>Status: {statusMessage}</Text>
|
|
33595
|
+
* )}
|
|
33596
|
+
* </View>
|
|
33597
|
+
* );
|
|
33598
|
+
* ```
|
|
33599
|
+
*/
|
|
33600
|
+
currentStatus,
|
|
33601
|
+
/**
|
|
33602
|
+
* Human-readable status message
|
|
33603
|
+
*
|
|
33604
|
+
* Provides a user-friendly description of the current signing status.
|
|
33605
|
+
* Updates in real-time as the transaction progresses.
|
|
33606
|
+
*/
|
|
33607
|
+
statusMessage,
|
|
33507
33608
|
};
|
|
33508
33609
|
};
|
|
33509
33610
|
|
|
@@ -33545,7 +33646,7 @@ const useTransactionSigner = () => {
|
|
|
33545
33646
|
*/
|
|
33546
33647
|
const useTransactions = () => {
|
|
33547
33648
|
const { sdk, isInitialized, isAuthenticated } = usePersSDK();
|
|
33548
|
-
const { signAndSubmitTransactionWithJWT, isSignerAvailable } = useTransactionSigner();
|
|
33649
|
+
const { signAndSubmitTransactionWithJWT, isSignerAvailable, currentStatus, statusMessage } = useTransactionSigner();
|
|
33549
33650
|
if (!isAuthenticated && isInitialized) {
|
|
33550
33651
|
console.warn('SDK not authenticated. Some transaction operations may fail.');
|
|
33551
33652
|
}
|
|
@@ -33567,29 +33668,29 @@ const useTransactions = () => {
|
|
|
33567
33668
|
* recipient: '0x123...',
|
|
33568
33669
|
* tokenId: 'token-123'
|
|
33569
33670
|
* };
|
|
33570
|
-
* const result = await createTransaction(request)
|
|
33671
|
+
* const result = await createTransaction(request, (status, message) => {
|
|
33672
|
+
* console.log(`Status: ${status} - ${message}`);
|
|
33673
|
+
* });
|
|
33571
33674
|
* console.log('Transaction created:', result);
|
|
33572
33675
|
* ```
|
|
33573
33676
|
*/
|
|
33574
|
-
const createTransaction = react.useCallback(async (request) => {
|
|
33677
|
+
const createTransaction = react.useCallback(async (request, onStatusUpdate) => {
|
|
33575
33678
|
if (!isInitialized || !sdk) {
|
|
33576
33679
|
throw new Error('SDK not initialized. Call initialize() first.');
|
|
33577
33680
|
}
|
|
33578
33681
|
try {
|
|
33579
33682
|
const result = await sdk.transactions.createTransaction(request);
|
|
33580
|
-
console.log('Transaction created successfully:', result);
|
|
33581
33683
|
// Check if transaction requires signing (contains actionable authToken)
|
|
33582
33684
|
// Type assertion needed as TransactionRequestResponseDTO type may not include all dynamic properties
|
|
33583
33685
|
const txToken = result?.actionable?.authToken;
|
|
33584
33686
|
if (txToken) {
|
|
33585
|
-
console.log('[useTransactions] Transaction requires signing, attempting automatic signature...');
|
|
33586
33687
|
try {
|
|
33587
33688
|
if (!isSignerAvailable) {
|
|
33588
33689
|
console.warn('[useTransactions] Transaction signer not available, skipping automatic signing');
|
|
33589
33690
|
return result;
|
|
33590
33691
|
}
|
|
33591
33692
|
// Automatically sign the transaction using the authToken
|
|
33592
|
-
const signingResult = await signAndSubmitTransactionWithJWT(txToken);
|
|
33693
|
+
const signingResult = await signAndSubmitTransactionWithJWT(txToken, onStatusUpdate);
|
|
33593
33694
|
if (signingResult.success) {
|
|
33594
33695
|
console.log('[useTransactions] Transaction signed successfully:', signingResult.transactionHash);
|
|
33595
33696
|
// Return the original result - the transaction is now signed and will be processed
|
|
@@ -33634,7 +33735,6 @@ const useTransactions = () => {
|
|
|
33634
33735
|
}
|
|
33635
33736
|
try {
|
|
33636
33737
|
const result = await sdk.transactions.getTransactionById(transactionId);
|
|
33637
|
-
console.log('Transaction fetched successfully:', result);
|
|
33638
33738
|
return result;
|
|
33639
33739
|
}
|
|
33640
33740
|
catch (error) {
|
|
@@ -33662,7 +33762,6 @@ const useTransactions = () => {
|
|
|
33662
33762
|
}
|
|
33663
33763
|
try {
|
|
33664
33764
|
const result = await sdk.transactions.getUserTransactionHistory(role);
|
|
33665
|
-
console.log('Transaction history fetched successfully:', result);
|
|
33666
33765
|
return result;
|
|
33667
33766
|
}
|
|
33668
33767
|
catch (error) {
|
|
@@ -33689,7 +33788,6 @@ const useTransactions = () => {
|
|
|
33689
33788
|
}
|
|
33690
33789
|
try {
|
|
33691
33790
|
const result = await sdk.transactions.getPaginatedTransactions(params);
|
|
33692
|
-
console.log('Paginated transactions fetched successfully:', result);
|
|
33693
33791
|
return result;
|
|
33694
33792
|
}
|
|
33695
33793
|
catch (error) {
|
|
@@ -33703,7 +33801,6 @@ const useTransactions = () => {
|
|
|
33703
33801
|
}
|
|
33704
33802
|
try {
|
|
33705
33803
|
const result = await sdk.transactions.exportTransactionsCSV();
|
|
33706
|
-
console.log('Transactions CSV exported successfully');
|
|
33707
33804
|
return result;
|
|
33708
33805
|
}
|
|
33709
33806
|
catch (error) {
|
|
@@ -33719,6 +33816,9 @@ const useTransactions = () => {
|
|
|
33719
33816
|
getPaginatedTransactions,
|
|
33720
33817
|
exportTransactionsCSV,
|
|
33721
33818
|
isAvailable: isInitialized && !!sdk?.transactions,
|
|
33819
|
+
// Expose signing status for UI feedback
|
|
33820
|
+
signingStatus: currentStatus,
|
|
33821
|
+
signingStatusMessage: statusMessage,
|
|
33722
33822
|
};
|
|
33723
33823
|
};
|
|
33724
33824
|
|
|
@@ -33777,7 +33877,6 @@ const useBusiness = () => {
|
|
|
33777
33877
|
}
|
|
33778
33878
|
try {
|
|
33779
33879
|
const result = await sdk.businesses.getActiveBusinesses();
|
|
33780
|
-
console.log('Active businesses fetched successfully:', result);
|
|
33781
33880
|
return result;
|
|
33782
33881
|
}
|
|
33783
33882
|
catch (error) {
|
|
@@ -33804,7 +33903,6 @@ const useBusiness = () => {
|
|
|
33804
33903
|
}
|
|
33805
33904
|
try {
|
|
33806
33905
|
const result = await sdk.businesses.getBusinessTypes();
|
|
33807
|
-
console.log('Business types fetched successfully:', result);
|
|
33808
33906
|
return result;
|
|
33809
33907
|
}
|
|
33810
33908
|
catch (error) {
|
|
@@ -33818,7 +33916,6 @@ const useBusiness = () => {
|
|
|
33818
33916
|
}
|
|
33819
33917
|
try {
|
|
33820
33918
|
const result = await sdk.businesses.getBusinessById(businessId);
|
|
33821
|
-
console.log('Business fetched successfully:', result);
|
|
33822
33919
|
return result;
|
|
33823
33920
|
}
|
|
33824
33921
|
catch (error) {
|
|
@@ -33832,7 +33929,6 @@ const useBusiness = () => {
|
|
|
33832
33929
|
}
|
|
33833
33930
|
try {
|
|
33834
33931
|
const result = await sdk.businesses.getBusinesses();
|
|
33835
|
-
console.log('All businesses fetched successfully:', result);
|
|
33836
33932
|
return result;
|
|
33837
33933
|
}
|
|
33838
33934
|
catch (error) {
|
|
@@ -33846,7 +33942,6 @@ const useBusiness = () => {
|
|
|
33846
33942
|
}
|
|
33847
33943
|
try {
|
|
33848
33944
|
const result = await sdk.businesses.getBusinessByAccount(accountAddress);
|
|
33849
|
-
console.log('Business by account fetched successfully:', result);
|
|
33850
33945
|
return result;
|
|
33851
33946
|
}
|
|
33852
33947
|
catch (error) {
|
|
@@ -33860,7 +33955,6 @@ const useBusiness = () => {
|
|
|
33860
33955
|
}
|
|
33861
33956
|
try {
|
|
33862
33957
|
const result = await sdk.businesses.getBusinessesByType(typeId);
|
|
33863
|
-
console.log('Businesses by type fetched successfully:', result);
|
|
33864
33958
|
return result;
|
|
33865
33959
|
}
|
|
33866
33960
|
catch (error) {
|
|
@@ -33889,7 +33983,6 @@ const useBusiness = () => {
|
|
|
33889
33983
|
}
|
|
33890
33984
|
try {
|
|
33891
33985
|
const result = await sdk.businesses.createBusiness(displayName);
|
|
33892
|
-
console.log('Business created successfully:', result);
|
|
33893
33986
|
return result;
|
|
33894
33987
|
}
|
|
33895
33988
|
catch (error) {
|
|
@@ -33903,7 +33996,6 @@ const useBusiness = () => {
|
|
|
33903
33996
|
}
|
|
33904
33997
|
try {
|
|
33905
33998
|
const result = await sdk.businesses.updateBusiness(businessId, businessData);
|
|
33906
|
-
console.log('Business updated successfully:', result);
|
|
33907
33999
|
return result;
|
|
33908
34000
|
}
|
|
33909
34001
|
catch (error) {
|
|
@@ -33917,7 +34009,6 @@ const useBusiness = () => {
|
|
|
33917
34009
|
}
|
|
33918
34010
|
try {
|
|
33919
34011
|
const result = await sdk.businesses.toggleBusinessStatus(businessId, toggleData);
|
|
33920
|
-
console.log('Business status toggled successfully:', result);
|
|
33921
34012
|
return result;
|
|
33922
34013
|
}
|
|
33923
34014
|
catch (error) {
|
|
@@ -33947,7 +34038,6 @@ const useCampaigns = () => {
|
|
|
33947
34038
|
}
|
|
33948
34039
|
try {
|
|
33949
34040
|
const result = await sdk.campaigns.getActiveCampaigns();
|
|
33950
|
-
console.log('Active campaigns fetched successfully:', result);
|
|
33951
34041
|
return result;
|
|
33952
34042
|
}
|
|
33953
34043
|
catch (error) {
|
|
@@ -33961,7 +34051,6 @@ const useCampaigns = () => {
|
|
|
33961
34051
|
}
|
|
33962
34052
|
try {
|
|
33963
34053
|
const result = await sdk.campaigns.getCampaignById(campaignId);
|
|
33964
|
-
console.log('Campaign fetched successfully:', result);
|
|
33965
34054
|
return result;
|
|
33966
34055
|
}
|
|
33967
34056
|
catch (error) {
|
|
@@ -33977,9 +34066,7 @@ const useCampaigns = () => {
|
|
|
33977
34066
|
throw new Error('SDK not authenticated. claimCampaign requires authentication.');
|
|
33978
34067
|
}
|
|
33979
34068
|
try {
|
|
33980
|
-
console.log('Claiming campaign with request:', request);
|
|
33981
34069
|
const result = await sdk.campaigns.claimCampaign(request);
|
|
33982
|
-
console.log('Campaign claimed successfully:', result);
|
|
33983
34070
|
return result;
|
|
33984
34071
|
}
|
|
33985
34072
|
catch (error) {
|
|
@@ -33997,7 +34084,6 @@ const useCampaigns = () => {
|
|
|
33997
34084
|
}
|
|
33998
34085
|
try {
|
|
33999
34086
|
const result = await sdk.campaigns.getUserClaims();
|
|
34000
|
-
console.log('User claims fetched successfully:', result);
|
|
34001
34087
|
return result;
|
|
34002
34088
|
}
|
|
34003
34089
|
catch (error) {
|
|
@@ -34011,7 +34097,6 @@ const useCampaigns = () => {
|
|
|
34011
34097
|
}
|
|
34012
34098
|
try {
|
|
34013
34099
|
const result = await sdk.campaigns.getCampaignTriggers();
|
|
34014
|
-
console.log('Campaign triggers fetched successfully:', result);
|
|
34015
34100
|
return result;
|
|
34016
34101
|
}
|
|
34017
34102
|
catch (error) {
|
|
@@ -34026,7 +34111,6 @@ const useCampaigns = () => {
|
|
|
34026
34111
|
}
|
|
34027
34112
|
try {
|
|
34028
34113
|
const result = await sdk.campaigns.getAllCampaigns(active);
|
|
34029
|
-
console.log('All campaigns fetched successfully:', result);
|
|
34030
34114
|
return result;
|
|
34031
34115
|
}
|
|
34032
34116
|
catch (error) {
|
|
@@ -34040,7 +34124,6 @@ const useCampaigns = () => {
|
|
|
34040
34124
|
}
|
|
34041
34125
|
try {
|
|
34042
34126
|
const result = await sdk.campaigns.getCampaignClaims();
|
|
34043
|
-
console.log('Campaign claims fetched successfully:', result);
|
|
34044
34127
|
return result;
|
|
34045
34128
|
}
|
|
34046
34129
|
catch (error) {
|
|
@@ -34054,7 +34137,6 @@ const useCampaigns = () => {
|
|
|
34054
34137
|
}
|
|
34055
34138
|
try {
|
|
34056
34139
|
const result = await sdk.campaigns.getCampaignClaimsByUserId(userId);
|
|
34057
|
-
console.log('Campaign claims by user ID fetched successfully:', result);
|
|
34058
34140
|
return result;
|
|
34059
34141
|
}
|
|
34060
34142
|
catch (error) {
|
|
@@ -34068,7 +34150,6 @@ const useCampaigns = () => {
|
|
|
34068
34150
|
}
|
|
34069
34151
|
try {
|
|
34070
34152
|
const result = await sdk.campaigns.getCampaignClaimsByBusinessId(businessId);
|
|
34071
|
-
console.log('Campaign claims by business ID fetched successfully:', result);
|
|
34072
34153
|
return result;
|
|
34073
34154
|
}
|
|
34074
34155
|
catch (error) {
|
|
@@ -34092,14 +34173,13 @@ const useCampaigns = () => {
|
|
|
34092
34173
|
|
|
34093
34174
|
const useRedemptions = () => {
|
|
34094
34175
|
const { sdk, isInitialized, isAuthenticated } = usePersSDK();
|
|
34095
|
-
const { signAndSubmitTransactionWithJWT, isSignerAvailable } = useTransactionSigner();
|
|
34176
|
+
const { signAndSubmitTransactionWithJWT, isSignerAvailable, currentStatus, statusMessage } = useTransactionSigner();
|
|
34096
34177
|
const getActiveRedemptions = react.useCallback(async () => {
|
|
34097
34178
|
if (!isInitialized || !sdk) {
|
|
34098
34179
|
throw new Error('SDK not initialized. Call initialize() first.');
|
|
34099
34180
|
}
|
|
34100
34181
|
try {
|
|
34101
34182
|
const result = await sdk.redemptions.getActiveRedemptions();
|
|
34102
|
-
console.log('Active redemptions fetched successfully:', result);
|
|
34103
34183
|
return result;
|
|
34104
34184
|
}
|
|
34105
34185
|
catch (error) {
|
|
@@ -34117,7 +34197,6 @@ const useRedemptions = () => {
|
|
|
34117
34197
|
}
|
|
34118
34198
|
try {
|
|
34119
34199
|
const result = await sdk.redemptions.getUserRedemptions();
|
|
34120
|
-
console.log('User redemptions fetched successfully:', result);
|
|
34121
34200
|
return result;
|
|
34122
34201
|
}
|
|
34123
34202
|
catch (error) {
|
|
@@ -34125,7 +34204,7 @@ const useRedemptions = () => {
|
|
|
34125
34204
|
throw error;
|
|
34126
34205
|
}
|
|
34127
34206
|
}, [sdk, isInitialized, isAuthenticated]);
|
|
34128
|
-
const redeem = react.useCallback(async (redemptionId) => {
|
|
34207
|
+
const redeem = react.useCallback(async (redemptionId, onStatusUpdate) => {
|
|
34129
34208
|
if (!isInitialized || !sdk) {
|
|
34130
34209
|
throw new Error('SDK not initialized. Call initialize() first.');
|
|
34131
34210
|
}
|
|
@@ -34133,18 +34212,12 @@ const useRedemptions = () => {
|
|
|
34133
34212
|
throw new Error('SDK not authenticated. redeem requires authentication.');
|
|
34134
34213
|
}
|
|
34135
34214
|
try {
|
|
34136
|
-
console.log('Redeeming redemption:', redemptionId);
|
|
34137
34215
|
const result = await sdk.redemptions.redeem(redemptionId);
|
|
34138
|
-
// Check if result has signing fields and sign transaction if required and signer is available
|
|
34139
|
-
console.log('Redemption processed successfully:', result);
|
|
34140
34216
|
const txToken = result.senderTransaction?.actionable?.authToken;
|
|
34141
34217
|
if (txToken && isSignerAvailable) {
|
|
34142
|
-
console.log('Transaction requires blockchain signing, processing with WebAuthn signer...');
|
|
34143
34218
|
try {
|
|
34144
|
-
const signingResult = await signAndSubmitTransactionWithJWT(txToken);
|
|
34145
|
-
console.log('Blockchain signing result:', signingResult);
|
|
34219
|
+
const signingResult = await signAndSubmitTransactionWithJWT(txToken, onStatusUpdate);
|
|
34146
34220
|
if (signingResult.success) {
|
|
34147
|
-
console.log('Transaction signed successfully:', signingResult.transactionHash);
|
|
34148
34221
|
// Return enhanced result with signing information
|
|
34149
34222
|
return {
|
|
34150
34223
|
...result,
|
|
@@ -34182,9 +34255,7 @@ const useRedemptions = () => {
|
|
|
34182
34255
|
throw new Error('SDK not initialized. Call initialize() first.');
|
|
34183
34256
|
}
|
|
34184
34257
|
try {
|
|
34185
|
-
console.log('Creating redemption offer with data:', redemptionData);
|
|
34186
34258
|
const result = await sdk.redemptions.createRedemption(redemptionData);
|
|
34187
|
-
console.log('Redemption offer created successfully:', result);
|
|
34188
34259
|
return result;
|
|
34189
34260
|
}
|
|
34190
34261
|
catch (error) {
|
|
@@ -34198,7 +34269,6 @@ const useRedemptions = () => {
|
|
|
34198
34269
|
}
|
|
34199
34270
|
try {
|
|
34200
34271
|
const result = await sdk.redemptions.getAllRedemptions(active);
|
|
34201
|
-
console.log('All redemptions fetched successfully:', result);
|
|
34202
34272
|
return result;
|
|
34203
34273
|
}
|
|
34204
34274
|
catch (error) {
|
|
@@ -34212,7 +34282,6 @@ const useRedemptions = () => {
|
|
|
34212
34282
|
}
|
|
34213
34283
|
try {
|
|
34214
34284
|
const result = await sdk.redemptions.getRedemptionTypes();
|
|
34215
|
-
console.log('Redemption types fetched successfully:', result);
|
|
34216
34285
|
return result;
|
|
34217
34286
|
}
|
|
34218
34287
|
catch (error) {
|
|
@@ -34226,7 +34295,6 @@ const useRedemptions = () => {
|
|
|
34226
34295
|
}
|
|
34227
34296
|
try {
|
|
34228
34297
|
const result = await sdk.redemptions.updateRedemption(redemptionId, redemptionData);
|
|
34229
|
-
console.log('Redemption updated successfully:', result);
|
|
34230
34298
|
return result;
|
|
34231
34299
|
}
|
|
34232
34300
|
catch (error) {
|
|
@@ -34240,7 +34308,6 @@ const useRedemptions = () => {
|
|
|
34240
34308
|
}
|
|
34241
34309
|
try {
|
|
34242
34310
|
const result = await sdk.redemptions.toggleRedemptionStatus(redemptionId);
|
|
34243
|
-
console.log('Redemption status toggled successfully:', result);
|
|
34244
34311
|
return result;
|
|
34245
34312
|
}
|
|
34246
34313
|
catch (error) {
|
|
@@ -34258,6 +34325,9 @@ const useRedemptions = () => {
|
|
|
34258
34325
|
updateRedemption,
|
|
34259
34326
|
toggleRedemptionStatus,
|
|
34260
34327
|
isAvailable: isInitialized && !!sdk?.redemptions,
|
|
34328
|
+
// Expose signing status for UI feedback
|
|
34329
|
+
signingStatus: currentStatus,
|
|
34330
|
+
signingStatusMessage: statusMessage,
|
|
34261
34331
|
};
|
|
34262
34332
|
};
|
|
34263
34333
|
|
|
@@ -34266,56 +34336,53 @@ const useRedemptions = () => {
|
|
|
34266
34336
|
*
|
|
34267
34337
|
* Provides comprehensive Web3 functionality including token balance queries,
|
|
34268
34338
|
* metadata retrieval, collection management, IPFS resolution, and blockchain
|
|
34269
|
-
* explorer integration. Supports multi-chain operations
|
|
34339
|
+
* explorer integration. Supports multi-chain operations.
|
|
34340
|
+
*
|
|
34341
|
+
* Note: Wallet addresses should be obtained from `user.wallets` via `usePersSDK()`.
|
|
34270
34342
|
*
|
|
34271
34343
|
* @returns Web3 hook with methods for blockchain operations
|
|
34272
34344
|
*
|
|
34273
34345
|
* @example
|
|
34274
34346
|
* ```typescript
|
|
34275
34347
|
* function Web3Component() {
|
|
34276
|
-
* const {
|
|
34277
|
-
*
|
|
34278
|
-
*
|
|
34279
|
-
*
|
|
34280
|
-
*
|
|
34281
|
-
* } = useWeb3();
|
|
34348
|
+
* const { user } = usePersSDK();
|
|
34349
|
+
* const { getTokenBalance, getTokenMetadata } = useWeb3();
|
|
34350
|
+
*
|
|
34351
|
+
* // Get wallet address from user
|
|
34352
|
+
* const walletAddress = user?.wallets?.[0]?.address;
|
|
34282
34353
|
*
|
|
34283
34354
|
* const loadTokenData = async () => {
|
|
34284
|
-
*
|
|
34285
|
-
*
|
|
34286
|
-
*
|
|
34287
|
-
*
|
|
34288
|
-
* }
|
|
34355
|
+
* if (!walletAddress) {
|
|
34356
|
+
* console.log('No wallet connected');
|
|
34357
|
+
* return;
|
|
34358
|
+
* }
|
|
34289
34359
|
*
|
|
34290
|
-
*
|
|
34291
|
-
*
|
|
34292
|
-
*
|
|
34293
|
-
*
|
|
34294
|
-
*
|
|
34360
|
+
* const balance = await getTokenBalance({
|
|
34361
|
+
* walletAddress,
|
|
34362
|
+
* contractAddress: '0x123...',
|
|
34363
|
+
* chainId: 1
|
|
34364
|
+
* });
|
|
34295
34365
|
*
|
|
34296
|
-
*
|
|
34297
|
-
* } catch (error) {
|
|
34298
|
-
* console.error('Failed to load token data:', error);
|
|
34299
|
-
* }
|
|
34366
|
+
* console.log('Token balance:', balance);
|
|
34300
34367
|
* };
|
|
34301
34368
|
*
|
|
34302
34369
|
* return (
|
|
34303
|
-
* <
|
|
34304
|
-
* {
|
|
34305
|
-
* <
|
|
34306
|
-
* <
|
|
34307
|
-
* <
|
|
34308
|
-
* </
|
|
34370
|
+
* <View>
|
|
34371
|
+
* {walletAddress ? (
|
|
34372
|
+
* <View>
|
|
34373
|
+
* <Text>Wallet: {walletAddress}</Text>
|
|
34374
|
+
* <Button onPress={loadTokenData} title="Load Tokens" />
|
|
34375
|
+
* </View>
|
|
34309
34376
|
* ) : (
|
|
34310
|
-
* <
|
|
34377
|
+
* <Text>No wallet connected</Text>
|
|
34311
34378
|
* )}
|
|
34312
|
-
* </
|
|
34379
|
+
* </View>
|
|
34313
34380
|
* );
|
|
34314
34381
|
* }
|
|
34315
34382
|
* ```
|
|
34316
34383
|
*/
|
|
34317
34384
|
const useWeb3 = () => {
|
|
34318
|
-
const { sdk, isInitialized, isAuthenticated
|
|
34385
|
+
const { sdk, isInitialized, isAuthenticated } = usePersSDK();
|
|
34319
34386
|
if (!isAuthenticated && isInitialized) {
|
|
34320
34387
|
console.warn('SDK not authenticated. Some web3 operations may fail.');
|
|
34321
34388
|
}
|
|
@@ -34339,13 +34406,11 @@ const useWeb3 = () => {
|
|
|
34339
34406
|
* ```
|
|
34340
34407
|
*/
|
|
34341
34408
|
const getTokenBalance = react.useCallback(async (request) => {
|
|
34342
|
-
console.log('[useWeb3] getTokenBalance called with request:', request);
|
|
34343
34409
|
if (!isInitialized || !sdk) {
|
|
34344
34410
|
throw new Error('SDK not initialized. Call initialize() first.');
|
|
34345
34411
|
}
|
|
34346
34412
|
try {
|
|
34347
34413
|
const result = await sdk.web3.getTokenBalance(request);
|
|
34348
|
-
console.log('Token balance fetched successfully:', result);
|
|
34349
34414
|
return result;
|
|
34350
34415
|
}
|
|
34351
34416
|
catch (error) {
|
|
@@ -34378,7 +34443,6 @@ const useWeb3 = () => {
|
|
|
34378
34443
|
}
|
|
34379
34444
|
try {
|
|
34380
34445
|
const result = await sdk.web3.getTokenMetadata(request);
|
|
34381
|
-
console.log('Token metadata fetched successfully:', result);
|
|
34382
34446
|
return result;
|
|
34383
34447
|
}
|
|
34384
34448
|
catch (error) {
|
|
@@ -34392,7 +34456,6 @@ const useWeb3 = () => {
|
|
|
34392
34456
|
}
|
|
34393
34457
|
try {
|
|
34394
34458
|
const result = await sdk.web3.getTokenCollection(request);
|
|
34395
|
-
console.log('Token collection fetched successfully:', result);
|
|
34396
34459
|
return result;
|
|
34397
34460
|
}
|
|
34398
34461
|
catch (error) {
|
|
@@ -34406,7 +34469,6 @@ const useWeb3 = () => {
|
|
|
34406
34469
|
}
|
|
34407
34470
|
try {
|
|
34408
34471
|
const result = await sdk.web3.resolveIPFSUrl(url, chainId);
|
|
34409
|
-
console.log('IPFS URL resolved successfully:', result);
|
|
34410
34472
|
return result;
|
|
34411
34473
|
}
|
|
34412
34474
|
catch (error) {
|
|
@@ -34420,7 +34482,6 @@ const useWeb3 = () => {
|
|
|
34420
34482
|
}
|
|
34421
34483
|
try {
|
|
34422
34484
|
const result = await sdk.web3.fetchAndProcessMetadata(tokenUri, chainId);
|
|
34423
|
-
console.log('Metadata fetched and processed successfully:', result);
|
|
34424
34485
|
return result;
|
|
34425
34486
|
}
|
|
34426
34487
|
catch (error) {
|
|
@@ -34434,7 +34495,6 @@ const useWeb3 = () => {
|
|
|
34434
34495
|
}
|
|
34435
34496
|
try {
|
|
34436
34497
|
const result = await sdk.web3.getChainDataById(chainId);
|
|
34437
|
-
console.log('Chain data fetched successfully:', result);
|
|
34438
34498
|
return result;
|
|
34439
34499
|
}
|
|
34440
34500
|
catch (error) {
|
|
@@ -34448,7 +34508,6 @@ const useWeb3 = () => {
|
|
|
34448
34508
|
}
|
|
34449
34509
|
try {
|
|
34450
34510
|
const result = await sdk.web3.getExplorerUrl(chainId, address, type);
|
|
34451
|
-
console.log('Explorer URL generated successfully:', result);
|
|
34452
34511
|
return result;
|
|
34453
34512
|
}
|
|
34454
34513
|
catch (error) {
|
|
@@ -34456,19 +34515,6 @@ const useWeb3 = () => {
|
|
|
34456
34515
|
throw error;
|
|
34457
34516
|
}
|
|
34458
34517
|
}, [sdk, isInitialized]);
|
|
34459
|
-
const getWalletInfo = react.useCallback(async () => {
|
|
34460
|
-
if (!isInitialized) {
|
|
34461
|
-
throw new Error('SDK not initialized. Call initialize() first.');
|
|
34462
|
-
}
|
|
34463
|
-
if (!accountAddress) {
|
|
34464
|
-
console.warn('No account address available');
|
|
34465
|
-
return null;
|
|
34466
|
-
}
|
|
34467
|
-
return {
|
|
34468
|
-
address: accountAddress,
|
|
34469
|
-
isConnected: !!accountAddress,
|
|
34470
|
-
};
|
|
34471
|
-
}, [isInitialized, accountAddress]);
|
|
34472
34518
|
return {
|
|
34473
34519
|
getTokenBalance,
|
|
34474
34520
|
getTokenMetadata,
|
|
@@ -34477,8 +34523,6 @@ const useWeb3 = () => {
|
|
|
34477
34523
|
fetchAndProcessMetadata,
|
|
34478
34524
|
getChainDataById,
|
|
34479
34525
|
getExplorerUrl,
|
|
34480
|
-
getWalletInfo,
|
|
34481
|
-
accountAddress: isInitialized ? accountAddress : null,
|
|
34482
34526
|
isAvailable: isInitialized && !!sdk?.web3,
|
|
34483
34527
|
};
|
|
34484
34528
|
};
|
|
@@ -34491,7 +34535,6 @@ const usePurchases = () => {
|
|
|
34491
34535
|
}
|
|
34492
34536
|
try {
|
|
34493
34537
|
const result = await sdk.purchases.createPaymentIntent(amount, currency, receiptEmail, description);
|
|
34494
|
-
console.log('Payment intent created successfully:', result);
|
|
34495
34538
|
return result;
|
|
34496
34539
|
}
|
|
34497
34540
|
catch (error) {
|
|
@@ -34505,7 +34548,6 @@ const usePurchases = () => {
|
|
|
34505
34548
|
}
|
|
34506
34549
|
try {
|
|
34507
34550
|
const result = await sdk.purchases.getActivePurchaseTokens();
|
|
34508
|
-
console.log('Active purchase tokens fetched successfully:', result);
|
|
34509
34551
|
return result;
|
|
34510
34552
|
}
|
|
34511
34553
|
catch (error) {
|
|
@@ -34522,7 +34564,6 @@ const usePurchases = () => {
|
|
|
34522
34564
|
}
|
|
34523
34565
|
try {
|
|
34524
34566
|
const result = await sdk.purchases.getAllUserPurchases();
|
|
34525
|
-
console.log('User purchases fetched successfully:', result);
|
|
34526
34567
|
return result;
|
|
34527
34568
|
}
|
|
34528
34569
|
catch (error) {
|
|
@@ -34559,7 +34600,6 @@ const useTenants = () => {
|
|
|
34559
34600
|
}
|
|
34560
34601
|
try {
|
|
34561
34602
|
const result = await sdk.tenants.getClientConfig();
|
|
34562
|
-
console.log('Client config fetched successfully:', result);
|
|
34563
34603
|
return result;
|
|
34564
34604
|
}
|
|
34565
34605
|
catch (error) {
|
|
@@ -34573,7 +34613,6 @@ const useTenants = () => {
|
|
|
34573
34613
|
}
|
|
34574
34614
|
try {
|
|
34575
34615
|
const result = await sdk.tenants.getLoginToken();
|
|
34576
|
-
console.log('Login token fetched successfully');
|
|
34577
34616
|
return result;
|
|
34578
34617
|
}
|
|
34579
34618
|
catch (error) {
|
|
@@ -34587,7 +34626,6 @@ const useTenants = () => {
|
|
|
34587
34626
|
}
|
|
34588
34627
|
try {
|
|
34589
34628
|
const result = await sdk.tenants.getAdmins();
|
|
34590
|
-
console.log('Admins fetched successfully:', result);
|
|
34591
34629
|
return result;
|
|
34592
34630
|
}
|
|
34593
34631
|
catch (error) {
|
|
@@ -34615,7 +34653,6 @@ const useUsers = () => {
|
|
|
34615
34653
|
}
|
|
34616
34654
|
try {
|
|
34617
34655
|
const result = await sdk.users.getCurrentUser();
|
|
34618
|
-
console.log('Current user fetched successfully:', result);
|
|
34619
34656
|
return result;
|
|
34620
34657
|
}
|
|
34621
34658
|
catch (error) {
|
|
@@ -34632,7 +34669,6 @@ const useUsers = () => {
|
|
|
34632
34669
|
}
|
|
34633
34670
|
try {
|
|
34634
34671
|
const result = await sdk.users.updateCurrentUser(userData);
|
|
34635
|
-
console.log('Current user updated successfully:', result);
|
|
34636
34672
|
return result;
|
|
34637
34673
|
}
|
|
34638
34674
|
catch (error) {
|
|
@@ -34646,7 +34682,6 @@ const useUsers = () => {
|
|
|
34646
34682
|
}
|
|
34647
34683
|
try {
|
|
34648
34684
|
const result = await sdk.users.getUserById(userId);
|
|
34649
|
-
console.log('User fetched successfully:', result);
|
|
34650
34685
|
return result;
|
|
34651
34686
|
}
|
|
34652
34687
|
catch (error) {
|
|
@@ -34660,7 +34695,6 @@ const useUsers = () => {
|
|
|
34660
34695
|
}
|
|
34661
34696
|
try {
|
|
34662
34697
|
const result = await sdk.users.getAllUsersPublic(filter);
|
|
34663
|
-
console.log('Public users fetched successfully:', result);
|
|
34664
34698
|
return result;
|
|
34665
34699
|
}
|
|
34666
34700
|
catch (error) {
|
|
@@ -34675,7 +34709,6 @@ const useUsers = () => {
|
|
|
34675
34709
|
}
|
|
34676
34710
|
try {
|
|
34677
34711
|
const result = await sdk.users.getAllUsers();
|
|
34678
|
-
console.log('All users fetched successfully:', result);
|
|
34679
34712
|
return result;
|
|
34680
34713
|
}
|
|
34681
34714
|
catch (error) {
|
|
@@ -34689,7 +34722,6 @@ const useUsers = () => {
|
|
|
34689
34722
|
}
|
|
34690
34723
|
try {
|
|
34691
34724
|
const result = await sdk.users.updateUser(userId, userData);
|
|
34692
|
-
console.log('User updated successfully:', result);
|
|
34693
34725
|
return result;
|
|
34694
34726
|
}
|
|
34695
34727
|
catch (error) {
|
|
@@ -34703,7 +34735,6 @@ const useUsers = () => {
|
|
|
34703
34735
|
}
|
|
34704
34736
|
try {
|
|
34705
34737
|
const result = await sdk.users.toggleUserStatus(user);
|
|
34706
|
-
console.log('User status toggled successfully:', result);
|
|
34707
34738
|
return result;
|
|
34708
34739
|
}
|
|
34709
34740
|
catch (error) {
|
|
@@ -34731,7 +34762,6 @@ const useUserStatus = () => {
|
|
|
34731
34762
|
}
|
|
34732
34763
|
try {
|
|
34733
34764
|
const result = await sdk.userStatus.getUserStatusTypes();
|
|
34734
|
-
console.log('User status types fetched successfully:', result);
|
|
34735
34765
|
return result;
|
|
34736
34766
|
}
|
|
34737
34767
|
catch (error) {
|
|
@@ -34748,7 +34778,6 @@ const useUserStatus = () => {
|
|
|
34748
34778
|
}
|
|
34749
34779
|
try {
|
|
34750
34780
|
const result = await sdk.userStatus.getEarnedUserStatus();
|
|
34751
|
-
console.log('Earned user status fetched successfully:', result);
|
|
34752
34781
|
return result;
|
|
34753
34782
|
}
|
|
34754
34783
|
catch (error) {
|
|
@@ -34763,7 +34792,6 @@ const useUserStatus = () => {
|
|
|
34763
34792
|
}
|
|
34764
34793
|
try {
|
|
34765
34794
|
const result = await sdk.userStatus.createUserStatusType(userStatusType);
|
|
34766
|
-
console.log('User status type created successfully:', result);
|
|
34767
34795
|
return result;
|
|
34768
34796
|
}
|
|
34769
34797
|
catch (error) {
|
|
@@ -34843,7 +34871,6 @@ const useFiles = () => {
|
|
|
34843
34871
|
}
|
|
34844
34872
|
try {
|
|
34845
34873
|
const result = await sdk.files.getSignedPutUrl(entityId, entityType, fileExtension);
|
|
34846
|
-
console.log('Signed put URL generated successfully:', result);
|
|
34847
34874
|
return result;
|
|
34848
34875
|
}
|
|
34849
34876
|
catch (error) {
|
|
@@ -34873,7 +34900,6 @@ const useFiles = () => {
|
|
|
34873
34900
|
}
|
|
34874
34901
|
try {
|
|
34875
34902
|
const result = await sdk.files.getSignedGetUrl(entityId, entityType, expireSeconds);
|
|
34876
|
-
console.log('Signed get URL generated successfully:', result);
|
|
34877
34903
|
return result;
|
|
34878
34904
|
}
|
|
34879
34905
|
catch (error) {
|
|
@@ -34887,7 +34913,6 @@ const useFiles = () => {
|
|
|
34887
34913
|
}
|
|
34888
34914
|
try {
|
|
34889
34915
|
const result = await sdk.files.getSignedUrl(request);
|
|
34890
|
-
console.log('Signed URL generated successfully:', result);
|
|
34891
34916
|
return result;
|
|
34892
34917
|
}
|
|
34893
34918
|
catch (error) {
|
|
@@ -34901,7 +34926,6 @@ const useFiles = () => {
|
|
|
34901
34926
|
}
|
|
34902
34927
|
try {
|
|
34903
34928
|
const result = await sdk.files.optimizeMedia(url, width, height);
|
|
34904
|
-
console.log('Media optimized successfully:', result);
|
|
34905
34929
|
return result;
|
|
34906
34930
|
}
|
|
34907
34931
|
catch (error) {
|
|
@@ -34976,7 +35000,6 @@ const useAnalytics = () => {
|
|
|
34976
35000
|
}
|
|
34977
35001
|
try {
|
|
34978
35002
|
const result = await sdk.analytics.getTransactionAnalytics(request);
|
|
34979
|
-
console.log('Transaction analytics fetched successfully:', result);
|
|
34980
35003
|
return result;
|
|
34981
35004
|
}
|
|
34982
35005
|
catch (error) {
|
|
@@ -35037,7 +35060,6 @@ const useDonations = () => {
|
|
|
35037
35060
|
}
|
|
35038
35061
|
try {
|
|
35039
35062
|
const result = await sdk.donations.getDonationTypes();
|
|
35040
|
-
console.log('Donation types fetched successfully:', result);
|
|
35041
35063
|
return result;
|
|
35042
35064
|
}
|
|
35043
35065
|
catch (error) {
|
|
@@ -35059,6 +35081,7 @@ exports.PersSDKProvider = PersSDKProvider;
|
|
|
35059
35081
|
exports.ReactNativeDPoPProvider = ReactNativeDPoPProvider;
|
|
35060
35082
|
exports.ReactNativeHttpClient = ReactNativeHttpClient;
|
|
35061
35083
|
exports.ReactNativeSecureStorage = ReactNativeSecureStorage;
|
|
35084
|
+
exports.SigningStatus = SigningStatus;
|
|
35062
35085
|
exports.TRANSACTION_FORMATS = TRANSACTION_FORMATS;
|
|
35063
35086
|
exports.TRANSACTION_FORMAT_DESCRIPTIONS = TRANSACTION_FORMAT_DESCRIPTIONS;
|
|
35064
35087
|
exports.apiPublicKeyTestPrefix = apiPublicKeyTestPrefix;
|