@explorins/pers-sdk-react-native 1.5.8 → 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.
@@ -1 +1 @@
1
- {"version":3,"file":"useTransactionSigner.d.ts","sourceRoot":"","sources":["../../src/hooks/useTransactionSigner.ts"],"names":[],"mappings":"AA6EA,UAAU,wBAAwB;IAChC,OAAO,EAAE,OAAO,CAAC;IACjB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAKD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AACH,eAAO,MAAM,oBAAoB;IAgM7B;;OAEG;2BAvE2C,MAAM,KAAG,QAAQ,wBAAwB,CAAC;IA0ExF;;OAEG;gCAjJgD;QACnD,QAAQ,CAAC,EAAE,MAAM,CAAC;QAClB,UAAU,CAAC,EAAE,MAAM,CAAC;QACpB,iBAAiB,CAAC,EAAE,MAAM,CAAC;KAC5B;IAgJC;;OAEG;;IAGH;;OAEG;;CAGN,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,qBAAqB,GAAG,UAAU,CAAC,OAAO,oBAAoB,CAAC,CAAC;AAE5E;;GAEG;AACH,YAAY,EAAE,wBAAwB,EAAE,CAAC"}
1
+ {"version":3,"file":"useTransactionSigner.d.ts","sourceRoot":"","sources":["../../src/hooks/useTransactionSigner.ts"],"names":[],"mappings":"AA6EA,UAAU,wBAAwB;IAChC,OAAO,EAAE,OAAO,CAAC;IACjB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAKD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AACH,eAAO,MAAM,oBAAoB;IAkQ7B;;OAEG;2BAvE2C,MAAM,KAAG,QAAQ,wBAAwB,CAAC;IA0ExF;;OAEG;gCAhLgD;QACnD,QAAQ,CAAC,EAAE,MAAM,CAAC;QAClB,UAAU,CAAC,EAAE,MAAM,CAAC;QACpB,iBAAiB,CAAC,EAAE,MAAM,CAAC;KAC5B;IA+KC;;OAEG;;IAGH;;OAEG;;CAGN,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,qBAAqB,GAAG,UAAU,CAAC,OAAO,oBAAoB,CAAC,CAAC;AAE5E;;GAEG;AACH,YAAY,EAAE,wBAAwB,EAAE,CAAC"}
@@ -87,19 +87,51 @@ export const useTransactionSigner = () => {
87
87
  });
88
88
  if (isInitialized && isAuthenticated && user && !isSignerInitialized && sdk && authProvider) {
89
89
  console.log('[useTransactionSigner] Auto-initializing PERS transaction signer...');
90
- // Get configuration from the PERS SDK
91
- const sdkConfig = sdk.config || {};
92
- console.log('[useTransactionSigner] SDK config:', sdkConfig);
93
- const apiProjectKey = sdkConfig.apiProjectKey || 'demo-project-key';
94
- console.log('[useTransactionSigner] Extracted API project key:', apiProjectKey);
95
- const tenantId = sdkConfig.tenantId || 'vq-demo';
96
- initializeSigner({
97
- tenantId: tenantId,
98
- projectKey: apiProjectKey,
99
- ethersProviderUrl: DEFAULT_ETHERS_PROVIDER
100
- }).catch((error) => {
101
- console.error('[useTransactionSigner] Auto-initialization failed:', error);
102
- });
90
+ // Async auto-initialization function
91
+ const autoInitialize = async () => {
92
+ try {
93
+ // Get configuration from the PERS SDK
94
+ const sdkConfig = sdk.config || {};
95
+ console.log('[useTransactionSigner] SDK config:', sdkConfig);
96
+ // Try to extract tenantId from JWT token if available
97
+ let tenantIdFromJWT;
98
+ if (authProvider.getToken) {
99
+ try {
100
+ const token = await authProvider.getToken();
101
+ if (token) {
102
+ // Decode JWT to get tenant information
103
+ const tokenParts = token.split('.');
104
+ if (tokenParts.length >= 2) {
105
+ const payload = JSON.parse(atob(tokenParts[1]));
106
+ console.log('[useTransactionSigner] JWT payload decoded:', payload);
107
+ // Look for tenant ID in various possible fields
108
+ tenantIdFromJWT = payload.tenantId || payload.tenant_id || payload.tenant;
109
+ if (tenantIdFromJWT) {
110
+ console.log('[useTransactionSigner] Found tenant ID in JWT:', tenantIdFromJWT);
111
+ }
112
+ }
113
+ }
114
+ }
115
+ catch (e) {
116
+ console.warn('[useTransactionSigner] Failed to decode JWT for tenant ID:', e);
117
+ }
118
+ }
119
+ // For React Native, we should get tenantId from JWT, then user/auth context, then config
120
+ const userTenantId = user.tenantId || user.tenant_id;
121
+ const configTenantId = sdkConfig.tenantId || 'vq-demo';
122
+ const tenantId = tenantIdFromJWT || userTenantId || configTenantId;
123
+ console.log('[useTransactionSigner] Extracted tenant ID:', tenantId, 'from JWT:', tenantIdFromJWT, 'user:', userTenantId, 'or config:', configTenantId);
124
+ // Don't use apiProjectKey since we'll get it via tenant initialization
125
+ await initializeSigner({
126
+ tenantId: tenantId,
127
+ ethersProviderUrl: DEFAULT_ETHERS_PROVIDER
128
+ });
129
+ }
130
+ catch (error) {
131
+ console.error('[useTransactionSigner] Auto-initialization failed:', error);
132
+ }
133
+ };
134
+ autoInitialize();
103
135
  }
104
136
  }, [isInitialized, isAuthenticated, user, isSignerInitialized, sdk, authProvider]);
105
137
  /**
@@ -125,7 +157,7 @@ export const useTransactionSigner = () => {
125
157
  }
126
158
  try {
127
159
  console.log('[useTransactionSigner] Initializing PERS transaction signer...');
128
- // Configure the PERS service with the project key before creating SDK
160
+ // Configure the PERS service before creating SDK
129
161
  if (config?.projectKey) {
130
162
  console.log('[useTransactionSigner] Configuring PERS service with project key:', config.projectKey);
131
163
  try {
@@ -144,6 +176,37 @@ export const useTransactionSigner = () => {
144
176
  console.error('[useTransactionSigner] Failed to configure PERS service:', configError);
145
177
  }
146
178
  }
179
+ else if (config?.tenantId) {
180
+ console.log('[useTransactionSigner] No project key provided, will initialize tenant environment with tenantId:', config.tenantId);
181
+ try {
182
+ // Import and initialize tenant environment to get project key
183
+ const { PersService } = await import('@explorins/pers-signer/react-native');
184
+ console.log('[useTransactionSigner] Initializing tenant environment for tenantId:', config.tenantId);
185
+ // We need to set the auth token first for tenant initialization
186
+ if (authProvider) {
187
+ try {
188
+ const token = await authProvider.getToken();
189
+ if (token) {
190
+ console.log('[useTransactionSigner] Setting auth token for tenant initialization');
191
+ PersService.configure({
192
+ token: token
193
+ });
194
+ }
195
+ }
196
+ catch (tokenError) {
197
+ console.warn('[useTransactionSigner] Could not get auth token for tenant initialization:', tokenError);
198
+ }
199
+ }
200
+ await PersService.initTenantEnvironment(config.tenantId);
201
+ console.log('[useTransactionSigner] Tenant environment initialized successfully');
202
+ // Verify configuration
203
+ const persConfig = PersService.getConfig();
204
+ console.log('[useTransactionSigner] PERS service config after tenant initialization:', persConfig);
205
+ }
206
+ catch (configError) {
207
+ console.error('[useTransactionSigner] Failed to initialize tenant environment:', configError);
208
+ }
209
+ }
147
210
  const signerSDK = await createPersSignerSDK({
148
211
  tenantId: config?.tenantId,
149
212
  ethersProviderUrl: config?.ethersProviderUrl || DEFAULT_ETHERS_PROVIDER
@@ -156,7 +219,7 @@ export const useTransactionSigner = () => {
156
219
  console.error('[useTransactionSigner] Failed to initialize transaction signer:', error);
157
220
  throw new Error(`Signer initialization failed: ${error}`);
158
221
  }
159
- }, []);
222
+ }, [authProvider]);
160
223
  /**
161
224
  * Sign a blockchain transaction using WebAuthn authentication
162
225
  *
package/dist/index.js CHANGED
@@ -30329,19 +30329,51 @@ const useTransactionSigner = () => {
30329
30329
  });
30330
30330
  if (isInitialized && isAuthenticated && user && !isSignerInitialized && sdk && authProvider) {
30331
30331
  console.log('[useTransactionSigner] Auto-initializing PERS transaction signer...');
30332
- // Get configuration from the PERS SDK
30333
- const sdkConfig = sdk.config || {};
30334
- console.log('[useTransactionSigner] SDK config:', sdkConfig);
30335
- const apiProjectKey = sdkConfig.apiProjectKey || 'demo-project-key';
30336
- console.log('[useTransactionSigner] Extracted API project key:', apiProjectKey);
30337
- const tenantId = sdkConfig.tenantId || 'vq-demo';
30338
- initializeSigner({
30339
- tenantId: tenantId,
30340
- projectKey: apiProjectKey,
30341
- ethersProviderUrl: DEFAULT_ETHERS_PROVIDER
30342
- }).catch((error) => {
30343
- console.error('[useTransactionSigner] Auto-initialization failed:', error);
30344
- });
30332
+ // Async auto-initialization function
30333
+ const autoInitialize = async () => {
30334
+ try {
30335
+ // Get configuration from the PERS SDK
30336
+ const sdkConfig = sdk.config || {};
30337
+ console.log('[useTransactionSigner] SDK config:', sdkConfig);
30338
+ // Try to extract tenantId from JWT token if available
30339
+ let tenantIdFromJWT;
30340
+ if (authProvider.getToken) {
30341
+ try {
30342
+ const token = await authProvider.getToken();
30343
+ if (token) {
30344
+ // Decode JWT to get tenant information
30345
+ const tokenParts = token.split('.');
30346
+ if (tokenParts.length >= 2) {
30347
+ const payload = JSON.parse(atob(tokenParts[1]));
30348
+ console.log('[useTransactionSigner] JWT payload decoded:', payload);
30349
+ // Look for tenant ID in various possible fields
30350
+ tenantIdFromJWT = payload.tenantId || payload.tenant_id || payload.tenant;
30351
+ if (tenantIdFromJWT) {
30352
+ console.log('[useTransactionSigner] Found tenant ID in JWT:', tenantIdFromJWT);
30353
+ }
30354
+ }
30355
+ }
30356
+ }
30357
+ catch (e) {
30358
+ console.warn('[useTransactionSigner] Failed to decode JWT for tenant ID:', e);
30359
+ }
30360
+ }
30361
+ // For React Native, we should get tenantId from JWT, then user/auth context, then config
30362
+ const userTenantId = user.tenantId || user.tenant_id;
30363
+ const configTenantId = sdkConfig.tenantId || 'vq-demo';
30364
+ const tenantId = tenantIdFromJWT || userTenantId || configTenantId;
30365
+ console.log('[useTransactionSigner] Extracted tenant ID:', tenantId, 'from JWT:', tenantIdFromJWT, 'user:', userTenantId, 'or config:', configTenantId);
30366
+ // Don't use apiProjectKey since we'll get it via tenant initialization
30367
+ await initializeSigner({
30368
+ tenantId: tenantId,
30369
+ ethersProviderUrl: DEFAULT_ETHERS_PROVIDER
30370
+ });
30371
+ }
30372
+ catch (error) {
30373
+ console.error('[useTransactionSigner] Auto-initialization failed:', error);
30374
+ }
30375
+ };
30376
+ autoInitialize();
30345
30377
  }
30346
30378
  }, [isInitialized, isAuthenticated, user, isSignerInitialized, sdk, authProvider]);
30347
30379
  /**
@@ -30367,7 +30399,7 @@ const useTransactionSigner = () => {
30367
30399
  }
30368
30400
  try {
30369
30401
  console.log('[useTransactionSigner] Initializing PERS transaction signer...');
30370
- // Configure the PERS service with the project key before creating SDK
30402
+ // Configure the PERS service before creating SDK
30371
30403
  if (config?.projectKey) {
30372
30404
  console.log('[useTransactionSigner] Configuring PERS service with project key:', config.projectKey);
30373
30405
  try {
@@ -30386,6 +30418,37 @@ const useTransactionSigner = () => {
30386
30418
  console.error('[useTransactionSigner] Failed to configure PERS service:', configError);
30387
30419
  }
30388
30420
  }
30421
+ else if (config?.tenantId) {
30422
+ console.log('[useTransactionSigner] No project key provided, will initialize tenant environment with tenantId:', config.tenantId);
30423
+ try {
30424
+ // Import and initialize tenant environment to get project key
30425
+ const { PersService } = await Promise.resolve().then(function () { return require('./react-native.esm-BtyCg4n1.js'); });
30426
+ console.log('[useTransactionSigner] Initializing tenant environment for tenantId:', config.tenantId);
30427
+ // We need to set the auth token first for tenant initialization
30428
+ if (authProvider) {
30429
+ try {
30430
+ const token = await authProvider.getToken();
30431
+ if (token) {
30432
+ console.log('[useTransactionSigner] Setting auth token for tenant initialization');
30433
+ PersService.configure({
30434
+ token: token
30435
+ });
30436
+ }
30437
+ }
30438
+ catch (tokenError) {
30439
+ console.warn('[useTransactionSigner] Could not get auth token for tenant initialization:', tokenError);
30440
+ }
30441
+ }
30442
+ await PersService.initTenantEnvironment(config.tenantId);
30443
+ console.log('[useTransactionSigner] Tenant environment initialized successfully');
30444
+ // Verify configuration
30445
+ const persConfig = PersService.getConfig();
30446
+ console.log('[useTransactionSigner] PERS service config after tenant initialization:', persConfig);
30447
+ }
30448
+ catch (configError) {
30449
+ console.error('[useTransactionSigner] Failed to initialize tenant environment:', configError);
30450
+ }
30451
+ }
30389
30452
  const signerSDK = await createPersSignerSDK({
30390
30453
  tenantId: config?.tenantId,
30391
30454
  ethersProviderUrl: config?.ethersProviderUrl || DEFAULT_ETHERS_PROVIDER
@@ -30398,7 +30461,7 @@ const useTransactionSigner = () => {
30398
30461
  console.error('[useTransactionSigner] Failed to initialize transaction signer:', error);
30399
30462
  throw new Error(`Signer initialization failed: ${error}`);
30400
30463
  }
30401
- }, []);
30464
+ }, [authProvider]);
30402
30465
  /**
30403
30466
  * Sign a blockchain transaction using WebAuthn authentication
30404
30467
  *