@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.
@@ -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;IAsL7B;;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"}
@@ -76,21 +76,62 @@ export const useTransactionSigner = () => {
76
76
  const signerSDKRef = useRef(null);
77
77
  // Auto-initialize signer when user is authenticated and real SDK is available
78
78
  useEffect(() => {
79
+ console.log('[useTransactionSigner] useEffect triggered:', {
80
+ isInitialized,
81
+ isAuthenticated,
82
+ hasUser: !!user,
83
+ isSignerInitialized,
84
+ hasSDK: !!sdk,
85
+ hasAuthProvider: !!authProvider,
86
+ hasCreatePersSignerSDK: !!createPersSignerSDK
87
+ });
79
88
  if (isInitialized && isAuthenticated && user && !isSignerInitialized && sdk && authProvider) {
80
89
  console.log('[useTransactionSigner] Auto-initializing PERS transaction signer...');
81
- // Get configuration from the PERS SDK
82
- const sdkConfig = sdk.config || {};
83
- console.log('[useTransactionSigner] SDK config:', sdkConfig);
84
- const apiProjectKey = sdkConfig.apiProjectKey || 'demo-project-key';
85
- console.log('[useTransactionSigner] Extracted API project key:', apiProjectKey);
86
- const tenantId = sdkConfig.tenantId || 'vq-demo';
87
- initializeSigner({
88
- tenantId: tenantId,
89
- projectKey: apiProjectKey,
90
- ethersProviderUrl: DEFAULT_ETHERS_PROVIDER
91
- }).catch((error) => {
92
- console.error('[useTransactionSigner] Auto-initialization failed:', error);
93
- });
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();
94
135
  }
95
136
  }, [isInitialized, isAuthenticated, user, isSignerInitialized, sdk, authProvider]);
96
137
  /**
@@ -116,7 +157,7 @@ export const useTransactionSigner = () => {
116
157
  }
117
158
  try {
118
159
  console.log('[useTransactionSigner] Initializing PERS transaction signer...');
119
- // Configure the PERS service with the project key before creating SDK
160
+ // Configure the PERS service before creating SDK
120
161
  if (config?.projectKey) {
121
162
  console.log('[useTransactionSigner] Configuring PERS service with project key:', config.projectKey);
122
163
  try {
@@ -135,6 +176,37 @@ export const useTransactionSigner = () => {
135
176
  console.error('[useTransactionSigner] Failed to configure PERS service:', configError);
136
177
  }
137
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
+ }
138
210
  const signerSDK = await createPersSignerSDK({
139
211
  tenantId: config?.tenantId,
140
212
  ethersProviderUrl: config?.ethersProviderUrl || DEFAULT_ETHERS_PROVIDER
@@ -147,7 +219,7 @@ export const useTransactionSigner = () => {
147
219
  console.error('[useTransactionSigner] Failed to initialize transaction signer:', error);
148
220
  throw new Error(`Signer initialization failed: ${error}`);
149
221
  }
150
- }, []);
222
+ }, [authProvider]);
151
223
  /**
152
224
  * Sign a blockchain transaction using WebAuthn authentication
153
225
  *
package/dist/index.js CHANGED
@@ -30318,21 +30318,62 @@ const useTransactionSigner = () => {
30318
30318
  const signerSDKRef = react.useRef(null);
30319
30319
  // Auto-initialize signer when user is authenticated and real SDK is available
30320
30320
  react.useEffect(() => {
30321
+ console.log('[useTransactionSigner] useEffect triggered:', {
30322
+ isInitialized,
30323
+ isAuthenticated,
30324
+ hasUser: !!user,
30325
+ isSignerInitialized,
30326
+ hasSDK: !!sdk,
30327
+ hasAuthProvider: !!authProvider,
30328
+ hasCreatePersSignerSDK: !!createPersSignerSDK
30329
+ });
30321
30330
  if (isInitialized && isAuthenticated && user && !isSignerInitialized && sdk && authProvider) {
30322
30331
  console.log('[useTransactionSigner] Auto-initializing PERS transaction signer...');
30323
- // Get configuration from the PERS SDK
30324
- const sdkConfig = sdk.config || {};
30325
- console.log('[useTransactionSigner] SDK config:', sdkConfig);
30326
- const apiProjectKey = sdkConfig.apiProjectKey || 'demo-project-key';
30327
- console.log('[useTransactionSigner] Extracted API project key:', apiProjectKey);
30328
- const tenantId = sdkConfig.tenantId || 'vq-demo';
30329
- initializeSigner({
30330
- tenantId: tenantId,
30331
- projectKey: apiProjectKey,
30332
- ethersProviderUrl: DEFAULT_ETHERS_PROVIDER
30333
- }).catch((error) => {
30334
- console.error('[useTransactionSigner] Auto-initialization failed:', error);
30335
- });
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();
30336
30377
  }
30337
30378
  }, [isInitialized, isAuthenticated, user, isSignerInitialized, sdk, authProvider]);
30338
30379
  /**
@@ -30358,7 +30399,7 @@ const useTransactionSigner = () => {
30358
30399
  }
30359
30400
  try {
30360
30401
  console.log('[useTransactionSigner] Initializing PERS transaction signer...');
30361
- // Configure the PERS service with the project key before creating SDK
30402
+ // Configure the PERS service before creating SDK
30362
30403
  if (config?.projectKey) {
30363
30404
  console.log('[useTransactionSigner] Configuring PERS service with project key:', config.projectKey);
30364
30405
  try {
@@ -30377,6 +30418,37 @@ const useTransactionSigner = () => {
30377
30418
  console.error('[useTransactionSigner] Failed to configure PERS service:', configError);
30378
30419
  }
30379
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
+ }
30380
30452
  const signerSDK = await createPersSignerSDK({
30381
30453
  tenantId: config?.tenantId,
30382
30454
  ethersProviderUrl: config?.ethersProviderUrl || DEFAULT_ETHERS_PROVIDER
@@ -30389,7 +30461,7 @@ const useTransactionSigner = () => {
30389
30461
  console.error('[useTransactionSigner] Failed to initialize transaction signer:', error);
30390
30462
  throw new Error(`Signer initialization failed: ${error}`);
30391
30463
  }
30392
- }, []);
30464
+ }, [authProvider]);
30393
30465
  /**
30394
30466
  * Sign a blockchain transaction using WebAuthn authentication
30395
30467
  *