@explorins/pers-sdk-react-native 1.5.7 → 1.5.10
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/package.json
CHANGED
|
@@ -129,23 +129,68 @@ export const useTransactionSigner = () => {
|
|
|
129
129
|
|
|
130
130
|
// Auto-initialize signer when user is authenticated and real SDK is available
|
|
131
131
|
useEffect(() => {
|
|
132
|
+
console.log('[useTransactionSigner] useEffect triggered:', {
|
|
133
|
+
isInitialized,
|
|
134
|
+
isAuthenticated,
|
|
135
|
+
hasUser: !!user,
|
|
136
|
+
isSignerInitialized,
|
|
137
|
+
hasSDK: !!sdk,
|
|
138
|
+
hasAuthProvider: !!authProvider,
|
|
139
|
+
hasCreatePersSignerSDK: !!createPersSignerSDK
|
|
140
|
+
});
|
|
141
|
+
|
|
132
142
|
if (isInitialized && isAuthenticated && user && !isSignerInitialized && sdk && authProvider) {
|
|
133
143
|
console.log('[useTransactionSigner] Auto-initializing PERS transaction signer...');
|
|
134
144
|
|
|
135
|
-
//
|
|
136
|
-
const
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
145
|
+
// Async auto-initialization function
|
|
146
|
+
const autoInitialize = async () => {
|
|
147
|
+
try {
|
|
148
|
+
// Get configuration from the PERS SDK
|
|
149
|
+
const sdkConfig = (sdk as any).config || {};
|
|
150
|
+
console.log('[useTransactionSigner] SDK config:', sdkConfig);
|
|
151
|
+
|
|
152
|
+
// Try to extract tenantId from JWT token if available
|
|
153
|
+
let tenantIdFromJWT: string | undefined;
|
|
154
|
+
if (authProvider.getToken) {
|
|
155
|
+
try {
|
|
156
|
+
const token = await authProvider.getToken();
|
|
157
|
+
if (token) {
|
|
158
|
+
// Decode JWT to get tenant information
|
|
159
|
+
const tokenParts = token.split('.');
|
|
160
|
+
if (tokenParts.length >= 2) {
|
|
161
|
+
const payload = JSON.parse(atob(tokenParts[1]));
|
|
162
|
+
console.log('[useTransactionSigner] JWT payload decoded:', payload);
|
|
163
|
+
|
|
164
|
+
// Look for tenant ID in various possible fields
|
|
165
|
+
tenantIdFromJWT = payload.tenantId || payload.tenant_id || payload.tenant;
|
|
166
|
+
if (tenantIdFromJWT) {
|
|
167
|
+
console.log('[useTransactionSigner] Found tenant ID in JWT:', tenantIdFromJWT);
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
} catch (e) {
|
|
172
|
+
console.warn('[useTransactionSigner] Failed to decode JWT for tenant ID:', e);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
// For React Native, we should get tenantId from JWT, then user/auth context, then config
|
|
177
|
+
const userTenantId = (user as any).tenantId || (user as any).tenant_id;
|
|
178
|
+
const configTenantId = sdkConfig.tenantId || 'vq-demo';
|
|
179
|
+
const tenantId = tenantIdFromJWT || userTenantId || configTenantId;
|
|
180
|
+
|
|
181
|
+
console.log('[useTransactionSigner] Extracted tenant ID:', tenantId, 'from JWT:', tenantIdFromJWT, 'user:', userTenantId, 'or config:', configTenantId);
|
|
182
|
+
|
|
183
|
+
// Don't use apiProjectKey since we'll get it via tenant initialization
|
|
184
|
+
await initializeSigner({
|
|
185
|
+
tenantId: tenantId,
|
|
186
|
+
ethersProviderUrl: DEFAULT_ETHERS_PROVIDER
|
|
187
|
+
});
|
|
188
|
+
} catch (error) {
|
|
189
|
+
console.error('[useTransactionSigner] Auto-initialization failed:', error);
|
|
190
|
+
}
|
|
191
|
+
};
|
|
141
192
|
|
|
142
|
-
|
|
143
|
-
tenantId: tenantId,
|
|
144
|
-
projectKey: apiProjectKey,
|
|
145
|
-
ethersProviderUrl: DEFAULT_ETHERS_PROVIDER
|
|
146
|
-
}).catch((error) => {
|
|
147
|
-
console.error('[useTransactionSigner] Auto-initialization failed:', error);
|
|
148
|
-
});
|
|
193
|
+
autoInitialize();
|
|
149
194
|
}
|
|
150
195
|
}, [isInitialized, isAuthenticated, user, isSignerInitialized, sdk, authProvider]);
|
|
151
196
|
|
|
@@ -178,7 +223,7 @@ export const useTransactionSigner = () => {
|
|
|
178
223
|
try {
|
|
179
224
|
console.log('[useTransactionSigner] Initializing PERS transaction signer...');
|
|
180
225
|
|
|
181
|
-
// Configure the PERS service
|
|
226
|
+
// Configure the PERS service before creating SDK
|
|
182
227
|
if (config?.projectKey) {
|
|
183
228
|
console.log('[useTransactionSigner] Configuring PERS service with project key:', config.projectKey);
|
|
184
229
|
try {
|
|
@@ -196,6 +241,37 @@ export const useTransactionSigner = () => {
|
|
|
196
241
|
} catch (configError) {
|
|
197
242
|
console.error('[useTransactionSigner] Failed to configure PERS service:', configError);
|
|
198
243
|
}
|
|
244
|
+
} else if (config?.tenantId) {
|
|
245
|
+
console.log('[useTransactionSigner] No project key provided, will initialize tenant environment with tenantId:', config.tenantId);
|
|
246
|
+
try {
|
|
247
|
+
// Import and initialize tenant environment to get project key
|
|
248
|
+
const { PersService } = await import('@explorins/pers-signer/react-native');
|
|
249
|
+
console.log('[useTransactionSigner] Initializing tenant environment for tenantId:', config.tenantId);
|
|
250
|
+
|
|
251
|
+
// We need to set the auth token first for tenant initialization
|
|
252
|
+
if (authProvider) {
|
|
253
|
+
try {
|
|
254
|
+
const token = await authProvider.getToken();
|
|
255
|
+
if (token) {
|
|
256
|
+
console.log('[useTransactionSigner] Setting auth token for tenant initialization');
|
|
257
|
+
(PersService as any).configure({
|
|
258
|
+
token: token
|
|
259
|
+
});
|
|
260
|
+
}
|
|
261
|
+
} catch (tokenError) {
|
|
262
|
+
console.warn('[useTransactionSigner] Could not get auth token for tenant initialization:', tokenError);
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
await (PersService as any).initTenantEnvironment(config.tenantId);
|
|
267
|
+
console.log('[useTransactionSigner] Tenant environment initialized successfully');
|
|
268
|
+
|
|
269
|
+
// Verify configuration
|
|
270
|
+
const persConfig = (PersService as any).getConfig();
|
|
271
|
+
console.log('[useTransactionSigner] PERS service config after tenant initialization:', persConfig);
|
|
272
|
+
} catch (configError) {
|
|
273
|
+
console.error('[useTransactionSigner] Failed to initialize tenant environment:', configError);
|
|
274
|
+
}
|
|
199
275
|
}
|
|
200
276
|
|
|
201
277
|
const signerSDK = await createPersSignerSDK({
|
|
@@ -211,7 +287,7 @@ export const useTransactionSigner = () => {
|
|
|
211
287
|
console.error('[useTransactionSigner] Failed to initialize transaction signer:', error);
|
|
212
288
|
throw new Error(`Signer initialization failed: ${error}`);
|
|
213
289
|
}
|
|
214
|
-
}, []);
|
|
290
|
+
}, [authProvider]);
|
|
215
291
|
|
|
216
292
|
/**
|
|
217
293
|
* Sign a blockchain transaction using WebAuthn authentication
|