@explorins/pers-sdk-react-native 1.5.2 → 1.5.4

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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@explorins/pers-sdk-react-native",
3
- "version": "1.5.2",
3
+ "version": "1.5.4",
4
4
  "description": "React Native SDK for PERS Platform - Tourism Loyalty System with Manager Pattern Architecture",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -35,7 +35,7 @@
35
35
  "@dfns/sdk-react-native": "^0.8.1",
36
36
  "@explorins/pers-sdk": "^1.6.3",
37
37
  "@explorins/pers-shared": "^2.1.40",
38
- "@explorins/pers-signer": "^1.0.6",
38
+ "@explorins/pers-signer": "^1.0.9",
39
39
  "@explorins/web3-ts": "^0.3.75",
40
40
  "@react-native-async-storage/async-storage": "^2.2.0",
41
41
  "buffer": "^6.0.3",
@@ -3,7 +3,7 @@ import { usePersSDK } from '../providers/PersSDKProvider';
3
3
  import type { UserDTO, AdminDTO } from '@explorins/pers-shared';
4
4
 
5
5
  // Dynamic import the signer SDK to avoid build issues with static dependencies
6
- let createPersSignerSDK: ((config: any) => Promise<any>) | null = null;
6
+ let createPersSignerSDK: ((config: PersSignerConfig) => Promise<any>) | null = null;
7
7
  try {
8
8
  const signerModule = require('@explorins/pers-signer/react-native');
9
9
  createPersSignerSDK = signerModule.createPersSignerSDK;
@@ -13,6 +13,15 @@ try {
13
13
  console.warn('[useTransactionSigner] Real blockchain signing will not be available');
14
14
  }
15
15
 
16
+ interface PersSignerConfig {
17
+ tenantId?: string; // Multi-tenant identifier
18
+ ethersProviderUrl?: string; // Custom blockchain provider
19
+ // webAuthnProvider: WebAuthnProvider; // Platform-specific WebAuthn provider
20
+ // Optional overrides for advanced use cases
21
+ apiUrl?: string; // Override default signer API URL (defaults to signer-api.pers.ninja)
22
+ relyingPartyName?: string; // Override default relying party name (defaults to 'PERS Signer')
23
+ }
24
+
16
25
  interface PersSignerSDKInstance {
17
26
  authenticateUser: (userInfo: SignerUserInfo) => Promise<SignerAuthenticatedUser>;
18
27
  signPersTransaction: (user: SignerAuthenticatedUser, jwt: string) => Promise<SigningResult>;
@@ -22,6 +31,7 @@ interface SignerUserInfo {
22
31
  identifier: string;
23
32
  email?: string;
24
33
  id?: string;
34
+ persAccessToken?: string;
25
35
  }
26
36
 
27
37
  interface SignerAuthenticatedUser {
@@ -119,34 +129,44 @@ export const useTransactionSigner = () => {
119
129
 
120
130
  // Auto-initialize signer when user is authenticated and real SDK is available
121
131
  useEffect(() => {
122
- if (isInitialized && isAuthenticated && user && !isSignerInitialized) {
132
+ if (isInitialized && isAuthenticated && user && !isSignerInitialized && sdk) {
123
133
  console.log('[useTransactionSigner] Auto-initializing PERS transaction signer...');
134
+
135
+ // Get configuration from the PERS SDK
136
+ const sdkConfig = (sdk as any).config || {};
137
+ const apiProjectKey = sdkConfig.apiProjectKey || 'demo-project-key';
138
+ const tenantId = sdkConfig.tenantId || 'vq-demo';
139
+
124
140
  initializeSigner({
125
- tenantId: 'auto-tenant', // TODO: Get from SDK config or environment
141
+ tenantId: tenantId,
142
+ projectKey: apiProjectKey,
126
143
  ethersProviderUrl: DEFAULT_ETHERS_PROVIDER
127
144
  }).catch((error) => {
128
145
  console.error('[useTransactionSigner] Auto-initialization failed:', error);
129
146
  });
130
147
  }
131
- }, [isInitialized, isAuthenticated, user, isSignerInitialized, createPersSignerSDK]);
148
+ }, [isInitialized, isAuthenticated, user, isSignerInitialized, sdk]);
132
149
 
133
150
  /**
134
151
  * Initialize the blockchain signer with configuration
135
152
  *
136
153
  * @param config - Signer configuration options
137
154
  * @param config.tenantId - Multi-tenant identifier for the signer
155
+ * @param config.projectKey - PERS project API key for authentication
138
156
  * @param config.ethersProviderUrl - Custom blockchain provider URL
139
157
  *
140
158
  * @example
141
159
  * ```typescript
142
160
  * await initializeSigner({
143
161
  * tenantId: 'my-tenant-id',
162
+ * projectKey: 'your-pers-api-key',
144
163
  * ethersProviderUrl: 'https://sepolia.infura.io/v3/your-key'
145
164
  * });
146
165
  * ```
147
166
  */
148
167
  const initializeSigner = useCallback(async (config?: {
149
- tenantId?: string;
168
+ tenantId?: string;
169
+ projectKey?: string;
150
170
  ethersProviderUrl?: string;
151
171
  }) => {
152
172
  if (!createPersSignerSDK) {
@@ -156,8 +176,10 @@ export const useTransactionSigner = () => {
156
176
  try {
157
177
  console.log('[useTransactionSigner] Initializing PERS transaction signer...');
158
178
 
179
+ // TODO: accept direct project key in signer sdk
159
180
  const signerSDK = await createPersSignerSDK({
160
181
  tenantId: config?.tenantId,
182
+ // projectKey: config?.projectKey,
161
183
  ethersProviderUrl: config?.ethersProviderUrl || DEFAULT_ETHERS_PROVIDER
162
184
  });
163
185
 
@@ -221,9 +243,16 @@ export const useTransactionSigner = () => {
221
243
  id: currentUser.id || jwtUserInfo.userId
222
244
  };
223
245
 
224
- // Authenticate user with blockchain signer
246
+ // Get PERS access token from the main SDK
247
+ const authProvider = (sdk as any).authProvider || (sdk as any)._authProvider;
248
+ const persAccessToken = authProvider ? await authProvider.getToken() : '';
249
+
250
+ // Authenticate user with blockchain signer and pass PERS token
225
251
  console.log('[useTransactionSigner] Authenticating user with signer:', signerUserInfo.identifier);
226
- const signerUser = await signerSDKRef.current.authenticateUser(signerUserInfo);
252
+ const signerUser = await signerSDKRef.current.authenticateUser({
253
+ ...signerUserInfo,
254
+ persAccessToken: persAccessToken
255
+ });
227
256
 
228
257
  // Sign the PERS transaction using JWT
229
258
  console.log('[useTransactionSigner] Signing PERS transaction with JWT containing transaction data');