@explorins/pers-signer 1.0.5

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.
@@ -0,0 +1,1208 @@
1
+ import * as _explorins_web3_ts_types from '@explorins/web3-ts/types';
2
+ import { AnyTransactionData } from '@explorins/web3-ts/types';
3
+ export { AnyTransactionData } from '@explorins/web3-ts/types';
4
+ import * as _explorins_pers_shared_browser from '@explorins/pers-shared/browser';
5
+ import { TenantPublicDTO, SessionAuthContextResponseDTO, TransactionRequestResponseDTO, TransactionFormat, CampaignDTO, CampaignClaimDTO, TransactionStatus } from '@explorins/pers-shared/browser';
6
+ export { TransactionFormat, TransactionRequestResponseDTO, TransactionStatus } from '@explorins/pers-shared/browser';
7
+ import { AbstractSigner, Provider, TransactionRequest, TypedDataDomain, TypedDataField } from 'ethers';
8
+
9
+ /**
10
+ * Wallet management service
11
+ * Handles wallet listing and management operations
12
+ */
13
+ declare class WalletService {
14
+ /**
15
+ * List all wallets for authenticated user
16
+ * @param authToken - Authentication token
17
+ * @returns Promise resolving to wallet list
18
+ */
19
+ static listWallets(authToken: string): Promise<any>;
20
+ /**
21
+ * Get wallet by ID (when backend supports it)
22
+ * @param authToken - Authentication token
23
+ * @param walletId - Wallet identifier
24
+ * @returns Promise resolving to wallet details
25
+ */
26
+ static getWallet(authToken: string, walletId: string): Promise<any>;
27
+ /**
28
+ * Create new wallet (when backend supports it)
29
+ * @param authToken - Authentication token
30
+ * @param walletConfig - Wallet configuration
31
+ * @returns Promise resolving to wallet creation result
32
+ */
33
+ static createWallet(authToken: string, walletConfig: any): Promise<any>;
34
+ }
35
+
36
+ /**
37
+ * Service for interacting with PERS (Phygital Experience Rewards System) backend API
38
+ */
39
+ /**
40
+ * Configuration interface for PERS API
41
+ */
42
+ interface PersApiConfig {
43
+ baseUrl: string;
44
+ projectKey?: string;
45
+ }
46
+ declare class PersService {
47
+ private static config;
48
+ private static tenantCache;
49
+ private static currentProjectKey;
50
+ private static useStaging;
51
+ /**
52
+ * Configure the PERS API settings
53
+ * @param config - The configuration object
54
+ */
55
+ static configure(config: Partial<PersApiConfig>): void;
56
+ /**
57
+ * Enable staging mode when project key is not available
58
+ * @param enableStaging Whether to use staging environment
59
+ */
60
+ static setStagingMode(enableStaging: boolean): void;
61
+ /**
62
+ * Get current configuration
63
+ */
64
+ static getConfig(): PersApiConfig;
65
+ /**
66
+ * Get tenant information by tenant ID
67
+ * @param tenantId - The tenant ID to retrieve
68
+ * @param authToken - Optional auth token for authentication
69
+ * @returns Promise with tenant public information
70
+ */
71
+ static getTenantById(tenantId: string, authToken?: string): Promise<TenantPublicDTO>;
72
+ /**
73
+ * Initialize tenant configuration from JWT
74
+ * @param tenantId - The tenant ID from JWT payload
75
+ * @param authToken - Optional auth token for authentication
76
+ * @returns Promise with tenant information
77
+ */
78
+ static initializeTenant(tenantId: string, authToken?: string): Promise<TenantPublicDTO>;
79
+ /**
80
+ * Get the current project key (either from tenant or fallback)
81
+ * @returns The project key to use for API calls
82
+ */
83
+ private static getProjectKey;
84
+ /**
85
+ * Get cached tenant data (platform-agnostic)
86
+ */
87
+ private static getTenantFromStorage;
88
+ /**
89
+ * Store tenant data (platform-agnostic)
90
+ */
91
+ private static storeTenantInStorage;
92
+ /**
93
+ * Clear tenant cache and reset project key
94
+ */
95
+ static clearTenantCache(): void;
96
+ /**
97
+ * Authenticates a user with the PERS backend using their auth token
98
+ *
99
+ * @param authToken - The authentication token received from DFNS after login/registration
100
+ * @returns A promise that resolves to the authentication response
101
+ * @throws If the request fails
102
+ */
103
+ static authenticateUser(authToken: string): Promise<SessionAuthContextResponseDTO>;
104
+ /**
105
+ * Prepares a transaction by calling the backend endpoint
106
+ *
107
+ * @param form - The transaction details
108
+ * @param persAccessToken - The PERS access token for authentication (Bearer)
109
+ * @returns A promise that resolves to the transaction preparation response
110
+ * @throws If the request fails
111
+ */
112
+ static prepareTransaction(form: any, persAccessToken: string): Promise<TransactionRequestResponseDTO>;
113
+ /**
114
+ * Submits a transaction by calling the backend endpoint
115
+ *
116
+ * @param transactionId - The ID of the transaction to submit
117
+ * @param signedTransactionOrSignature - The signed transaction data or EIP-712 signature
118
+ * @param persAccessToken - The PERS access token for authentication (Bearer)
119
+ * @param submissionType - The transaction format type
120
+ * @returns A promise that resolves to the transaction submission response
121
+ * @throws If the request fails
122
+ */
123
+ static submitTransaction(transactionId: string, signedTransactionOrSignature: string, persAccessToken: string, submissionType: TransactionFormat): Promise<any>;
124
+ /**
125
+ * Fetches a prepared transaction for signing by transactionId
126
+ * @param transactionId - The transaction ID to fetch
127
+ * @param persAccessToken - The PERS access token for authentication (Bearer)
128
+ * @returns The prepared transaction data
129
+ * @throws If the request fails
130
+ */
131
+ static fetchPreparedTransaction(transactionId: string, persAccessToken: string): Promise<TransactionRequestResponseDTO>;
132
+ /**
133
+ * Claims a reward from the PERS blockchain system
134
+ * @param rewardId - The ID of the reward to claim
135
+ * @param pointsCost - The points cost for the reward
136
+ * @param persAccessToken - The PERS access token for authentication (Bearer)
137
+ * @returns The reward claim response including reward image URL
138
+ * @throws If the request fails
139
+ */
140
+ static claimReward(rewardId: string, pointsCost: number, persAccessToken: string): Promise<any>;
141
+ /**
142
+ * Get all active campaigns
143
+ * @returns Promise with list of active campaigns
144
+ */
145
+ static getActiveCampaigns(): Promise<CampaignDTO[]>;
146
+ /**
147
+ * Claims a campaign for a user
148
+ * @param campaignId - The ID of the campaign to claim
149
+ * @param persAccessToken - The PERS access token for authentication (Bearer)
150
+ * @returns Promise with the campaign claim response
151
+ * @throws If the request fails
152
+ */
153
+ static claimCampaign(campaignId: string, persAccessToken: string): Promise<CampaignClaimDTO>;
154
+ /**
155
+ * Gets all campaign claims for the authenticated user
156
+ * @param persAccessToken - The PERS access token for authentication (Bearer)
157
+ * @returns Promise with list of user's campaign claims
158
+ * @throws If the request fails
159
+ */
160
+ static getUserCampaignClaims(persAccessToken: string): Promise<CampaignClaimDTO[]>;
161
+ /**
162
+ * Gets all available rewards for redemption
163
+ * @returns Promise with list of available rewards that can be exchanged for points
164
+ * @throws If the request fails
165
+ */
166
+ static getAvailableRedemptions(): Promise<any[]>;
167
+ /**
168
+ * Helper method to determine if transaction data is available for signing
169
+ * @param transactionResponse - Response from prepare or fetch transaction
170
+ * @returns boolean indicating if transaction can be signed
171
+ */
172
+ static isTransactionReadyForSigning(transactionResponse: TransactionRequestResponseDTO): boolean;
173
+ /**
174
+ * Helper method to get transaction data from response
175
+ * @param transactionResponse - Response from prepare or fetch transaction
176
+ * @returns The transaction data ready for signing
177
+ * @throws If transaction data is not available
178
+ */
179
+ static getTransactionDataForSigning(transactionResponse: TransactionRequestResponseDTO): _explorins_pers_shared_browser.CounterfactualWalletTransactionResponse | _explorins_web3_ts_types.LegacyTransaction;
180
+ }
181
+
182
+ /**
183
+ * Types for WebAuthn provider abstraction
184
+ */
185
+ interface WebAuthnProvider {
186
+ create(challenge: any): Promise<any>;
187
+ sign(challenge: any): Promise<any>;
188
+ }
189
+ interface WebAuthnConfig {
190
+ relyingParty: {
191
+ id: string;
192
+ name: string;
193
+ origin?: string;
194
+ };
195
+ }
196
+
197
+ /**
198
+ * Key service response types and interfaces
199
+ */
200
+ /**
201
+ * Signature response from key signing operations
202
+ */
203
+ interface SignResponse {
204
+ id: string;
205
+ keyId: string;
206
+ requester: {
207
+ userId: string;
208
+ appId: string;
209
+ };
210
+ requestBody: {
211
+ hash: string;
212
+ kind: "Hash";
213
+ };
214
+ status: "Signed";
215
+ signature: {
216
+ r: string;
217
+ s: string;
218
+ recid: number;
219
+ };
220
+ network: "KeyECDSA";
221
+ dateRequested: string;
222
+ dateSigned: string;
223
+ walletId: string;
224
+ }
225
+ /**
226
+ * Authentication response from login/register operations
227
+ */
228
+ interface AuthResponse {
229
+ token: string;
230
+ message?: string;
231
+ status?: number;
232
+ }
233
+ /**
234
+ * Registration challenge response
235
+ */
236
+ interface RegistrationChallenge {
237
+ temporaryAuthenticationToken: string;
238
+ challenge: any;
239
+ status?: number;
240
+ message?: string;
241
+ }
242
+ /**
243
+ * Registration completion response
244
+ */
245
+ interface RegistrationResult {
246
+ token: string;
247
+ walletId?: string;
248
+ status?: number;
249
+ message?: string;
250
+ }
251
+ /**
252
+ * Wallet listing response
253
+ */
254
+ interface WalletListResponse$1 {
255
+ wallets: WalletItem$1[];
256
+ status?: number;
257
+ message?: string;
258
+ }
259
+ /**
260
+ * Individual wallet item
261
+ */
262
+ interface WalletItem$1 {
263
+ id: string;
264
+ address: string;
265
+ network: string;
266
+ status: string;
267
+ signingKey?: unknown;
268
+ dateCreated?: string;
269
+ custodial?: boolean;
270
+ tags?: string[];
271
+ boundToEvmNetwork?: boolean;
272
+ [key: string]: unknown;
273
+ }
274
+ /**
275
+ * Hash signing request
276
+ */
277
+ interface HashSigningRequest {
278
+ kind: "Hash";
279
+ hash: string;
280
+ }
281
+ /**
282
+ * EIP-712 typed data signing request
283
+ */
284
+ interface TypedDataSigningRequest {
285
+ blockchainKind: "Evm";
286
+ kind: "Eip712";
287
+ types: Record<string, any[]>;
288
+ domain: any;
289
+ message: Record<string, any>;
290
+ }
291
+ /**
292
+ * Generic signing request
293
+ */
294
+ type SigningRequest = HashSigningRequest | TypedDataSigningRequest;
295
+ /**
296
+ * Signing challenge response
297
+ */
298
+ interface SigningChallenge {
299
+ requestBody: any;
300
+ challenge: {
301
+ challengeIdentifier: string;
302
+ [key: string]: any;
303
+ };
304
+ status?: number;
305
+ message?: string;
306
+ }
307
+ /**
308
+ * User credentials for authentication
309
+ */
310
+ interface UserCredentials {
311
+ username: string;
312
+ appId?: string;
313
+ }
314
+ /**
315
+ * Relying party configuration for WebAuthn
316
+ */
317
+ interface RelyingPartyConfig {
318
+ id: string;
319
+ name: string;
320
+ origin?: string;
321
+ }
322
+
323
+ /**
324
+ * Signing service for cryptographic operations
325
+ * Handles hash signing and typed data signing with WebAuthn
326
+ * Uses constructor-based dependency injection for WebAuthn provider
327
+ */
328
+ declare class SigningService {
329
+ private webAuthnProvider;
330
+ constructor(webAuthnProvider: WebAuthnProvider);
331
+ /**
332
+ * Sign a hash using the specified wallet
333
+ * @param authToken - Authentication token
334
+ * @param walletId - Wallet identifier
335
+ * @param hash - Hash to sign
336
+ * @returns Promise resolving to signature response
337
+ */
338
+ signHash(authToken: string, walletId: string, hash: string): Promise<SignResponse>;
339
+ /**
340
+ * Sign EIP-712 typed data using the specified wallet
341
+ * @param authToken - Authentication token
342
+ * @param walletId - Wallet identifier
343
+ * @param domain - EIP-712 domain
344
+ * @param types - EIP-712 types definition
345
+ * @param value - Data to sign
346
+ * @returns Promise resolving to signature response
347
+ */
348
+ signTypedData(authToken: string, walletId: string, domain: any, types: Record<string, any[]>, value: Record<string, any>): Promise<SignResponse>;
349
+ /**
350
+ * Generic signing method that handles the complete signing flow
351
+ * @param authToken - Authentication token
352
+ * @param walletId - Wallet identifier
353
+ * @param request - Signing request object
354
+ * @returns Promise resolving to signature response
355
+ */
356
+ private signRequest;
357
+ /**
358
+ * Sign multiple requests in batch (when backend supports it)
359
+ * @param authToken - Authentication token
360
+ * @param walletId - Wallet identifier
361
+ * @param requests - Array of signing requests
362
+ * @returns Promise resolving to array of signature responses
363
+ */
364
+ signBatch(authToken: string, walletId: string, requests: SigningRequest[]): Promise<SignResponse[]>;
365
+ }
366
+
367
+ /**
368
+ * Shared type definitions for the blockchain signer shared library
369
+ */
370
+
371
+ /**
372
+ * Represents a wallet configuration with its metadata
373
+ */
374
+ interface WalletConfig {
375
+ id: string;
376
+ name: string;
377
+ address?: string;
378
+ credentialId?: string;
379
+ publicKey?: string;
380
+ createdAt?: Date;
381
+ }
382
+ /**
383
+ * Authentication token structure
384
+ */
385
+ interface AuthToken {
386
+ token: string;
387
+ expiresAt: Date;
388
+ refreshToken?: string;
389
+ }
390
+ /**
391
+ * User authentication state
392
+ */
393
+ interface AuthState {
394
+ isAuthenticated: boolean;
395
+ token?: AuthToken;
396
+ user?: UserProfile;
397
+ wallets?: WalletConfig[];
398
+ }
399
+ /**
400
+ * User profile information
401
+ */
402
+ interface UserProfile {
403
+ id: string;
404
+ username: string;
405
+ email?: string;
406
+ createdAt: Date;
407
+ lastLoginAt?: Date;
408
+ }
409
+ /**
410
+ * Prepared transaction from PERS service
411
+ */
412
+ interface PreparedTransaction {
413
+ id: string;
414
+ transactionData: AnyTransactionData;
415
+ metadata?: Record<string, any>;
416
+ createdAt: Date;
417
+ expiresAt?: Date;
418
+ }
419
+ /**
420
+ * Transaction signing result
421
+ */
422
+ interface SigningResult$1 {
423
+ signature: string;
424
+ transactionHash?: string;
425
+ rawTransaction?: string;
426
+ }
427
+ /**
428
+ * Environment variable types for shared services
429
+ */
430
+ interface SharedLibEnvironment {
431
+ }
432
+ /**
433
+ * Service configuration options
434
+ */
435
+ interface ServiceConfig$1 {
436
+ apiUrl: string;
437
+ environment: 'development' | 'staging' | 'production';
438
+ timeout?: number;
439
+ retryAttempts?: number;
440
+ }
441
+ /**
442
+ * Error types for service operations
443
+ */
444
+ interface ServiceError {
445
+ code: string;
446
+ message: string;
447
+ details?: any;
448
+ timestamp: Date;
449
+ }
450
+ /**
451
+ * API response wrapper
452
+ */
453
+ interface ApiResponse<T = any> {
454
+ success: boolean;
455
+ data?: T;
456
+ error?: ServiceError;
457
+ metadata?: Record<string, any>;
458
+ }
459
+
460
+ interface GetWalletResponse {
461
+ id: string;
462
+ signingKey: {
463
+ publicKey: string;
464
+ };
465
+ }
466
+
467
+ type WalletOptions = {
468
+ wallet: WalletMetadata;
469
+ authToken: string;
470
+ signingService: SigningService;
471
+ };
472
+ type WalletMetadata = GetWalletResponse & {
473
+ boundToEvmNetwork: boolean;
474
+ };
475
+ declare class KeyWallet extends AbstractSigner {
476
+ private options;
477
+ private address?;
478
+ private authToken;
479
+ private metadata;
480
+ private signingService;
481
+ constructor(options: WalletOptions, provider?: Provider | null);
482
+ connect(provider: Provider | null): KeyWallet;
483
+ getAddress(): Promise<string>;
484
+ private signHash;
485
+ signTransaction(tx: TransactionRequest): Promise<string>;
486
+ signMessage(message: string | Uint8Array): Promise<string>;
487
+ signTypedData(domain: TypedDataDomain, types: Record<string, TypedDataField[]>, value: Record<string, any>): Promise<string>;
488
+ /**
489
+ * Signs a PERS transaction based on its format
490
+ * Handles different transaction types: Legacy, EIP-2930, EIP-1559, and EIP-712
491
+ * @param transactionData - The transaction data from PERS API
492
+ * @returns The signature string
493
+ */
494
+ signPersTransaction(transactionData: AnyTransactionData): Promise<string>;
495
+ }
496
+
497
+ /**
498
+ * Combined transaction status type that includes both PERS and additional statuses
499
+ */
500
+ type CombinedTransactionStatus = TransactionStatus;
501
+ /**
502
+ * Transaction statuses that allow signing
503
+ */
504
+ declare const SIGNABLE_STATUSES: readonly [TransactionStatus.PENDING_SIGNATURE, TransactionStatus.CREATED];
505
+ /**
506
+ * Transaction status information for UI display
507
+ */
508
+ interface TransactionStatusInfo {
509
+ transactionId: string;
510
+ transactionStatus: CombinedTransactionStatus;
511
+ message: string;
512
+ }
513
+ /**
514
+ * Transaction signing result
515
+ */
516
+ interface TransactionSigningResult {
517
+ success: boolean;
518
+ transactionId: string;
519
+ transactionHash?: string;
520
+ signature?: string;
521
+ error?: string;
522
+ statusInfo?: TransactionStatusInfo;
523
+ shouldRedirect?: boolean;
524
+ redirectUrl?: string;
525
+ shouldShowStatus?: boolean;
526
+ }
527
+ /**
528
+ * Transaction result for localStorage storage
529
+ */
530
+ interface StoredTransactionResult {
531
+ transactionId: string;
532
+ transactionHash: string;
533
+ }
534
+ /**
535
+ * Transaction submission result for internal processing
536
+ */
537
+ interface SubmissionResult {
538
+ submitResult: TransactionRequestResponseDTO;
539
+ shouldRedirect: boolean;
540
+ redirectUrl?: string;
541
+ }
542
+ /**
543
+ * Metadata for transaction parameters - string values only
544
+ */
545
+ interface TransactionMetadata {
546
+ [key: string]: string;
547
+ }
548
+ /**
549
+ * Authentication tokens required for transaction signing
550
+ */
551
+ interface SigningAuthTokens {
552
+ backendAuthToken: string;
553
+ persAccessToken: string;
554
+ }
555
+ /**
556
+ * Transaction signing parameters
557
+ */
558
+ interface TransactionSigningParams {
559
+ transactionId: string;
560
+ authTokens: SigningAuthTokens;
561
+ ethersProviderUrl: string;
562
+ returnUrl?: string;
563
+ metadata?: TransactionMetadata;
564
+ walletRegistrationFailed?: boolean;
565
+ walletErrorDetails?: string;
566
+ }
567
+
568
+ /**
569
+ * Service for orchestrating transaction signing operations
570
+ * Handles the complete flow from transaction preparation to submission
571
+ * Uses constructor-based dependency injection for WebAuthn provider
572
+ */
573
+ declare class TransactionSigningService {
574
+ private webAuthnProvider;
575
+ constructor(webAuthnProvider: WebAuthnProvider);
576
+ /**
577
+ * Prepare transaction for signing - fetch and validate
578
+ */
579
+ private prepareTransaction;
580
+ /**
581
+ * Validate and prepare wallet for signing
582
+ */
583
+ private prepareWallet;
584
+ /**
585
+ * Execute the transaction signing with WebAuthn coordination
586
+ */
587
+ private executeTransactionSigning;
588
+ /**
589
+ * Main transaction signing orchestration method
590
+ * Handles the complete flow from preparation to submission
591
+ * @param params - Transaction signing parameters
592
+ * @returns Promise resolving to transaction signing result
593
+ * @throws TransactionSigningError for validation and operation failures
594
+ */
595
+ signTransaction(params: TransactionSigningParams): Promise<TransactionSigningResult>;
596
+ }
597
+
598
+ /**
599
+ * Error codes for transaction signing operations
600
+ */
601
+ declare enum TransactionSigningErrorCode {
602
+ INVALID_TOKENS = "INVALID_TOKENS",
603
+ TRANSACTION_NOT_FOUND = "TRANSACTION_NOT_FOUND",
604
+ TRANSACTION_NOT_PENDING = "TRANSACTION_NOT_PENDING",
605
+ WALLET_NOT_AVAILABLE = "WALLET_NOT_AVAILABLE",
606
+ WEBAUTHN_OPERATION_IN_PROGRESS = "WEBAUTHN_OPERATION_IN_PROGRESS",
607
+ SIGNING_CANCELLED = "SIGNING_CANCELLED",
608
+ PERS_AUTH_FAILED = "PERS_AUTH_FAILED",
609
+ AUTH_FAILED = "AUTH_FAILED",
610
+ TRANSACTION_NOT_READY = "TRANSACTION_NOT_READY",
611
+ SUBMISSION_FAILED = "SUBMISSION_FAILED",
612
+ SERVER_ERROR = "SERVER_ERROR",
613
+ UNKNOWN_ERROR = "UNKNOWN_ERROR"
614
+ }
615
+ /**
616
+ * Structured error for transaction signing operations
617
+ */
618
+ interface TransactionSigningError extends Error {
619
+ code: TransactionSigningErrorCode;
620
+ transactionId?: string;
621
+ originalError?: unknown;
622
+ }
623
+
624
+ /**
625
+ * Handles all error-related operations for transaction signing
626
+ */
627
+ declare class TransactionErrorHandler {
628
+ /**
629
+ * Get user-friendly status messages for transaction statuses
630
+ * @param status - The transaction status
631
+ * @returns Human-readable message explaining the status
632
+ */
633
+ static getStatusMessage(status: CombinedTransactionStatus): string;
634
+ /**
635
+ * Safely convert string status to TransactionStatus enum
636
+ * @param statusString - The status string to convert
637
+ * @returns A valid TransactionStatus enum value
638
+ */
639
+ static parseTransactionStatus(statusString: string): CombinedTransactionStatus;
640
+ /**
641
+ * Create a structured transaction signing error
642
+ * @param code - Error code
643
+ * @param message - Error message
644
+ * @param transactionId - Optional transaction ID
645
+ * @param originalError - Original error that caused this
646
+ * @returns Structured error object
647
+ */
648
+ static createError(code: TransactionSigningErrorCode, message: string, transactionId?: string, originalError?: unknown): TransactionSigningError;
649
+ /**
650
+ * Create transaction status info object for UI display
651
+ * @param transactionId - The transaction ID
652
+ * @param status - The transaction status
653
+ * @param customMessage - Optional custom message, otherwise uses default status message
654
+ * @returns TransactionStatusInfo object
655
+ */
656
+ static createStatusInfo(transactionId: string, status: CombinedTransactionStatus, customMessage?: string): TransactionStatusInfo;
657
+ /**
658
+ * Handle TRANSACTION_NOT_PENDING error from PERS API
659
+ * Consolidates the duplicate error handling logic
660
+ * @param error - The error object from PERS API
661
+ * @param transactionId - The transaction ID
662
+ * @returns Never (always throws)
663
+ * @throws Object with shouldShowStatus and statusInfo
664
+ */
665
+ static handleTransactionNotPendingError(error: {
666
+ status?: number;
667
+ error?: {
668
+ code?: string;
669
+ message?: string;
670
+ developerMessage?: string;
671
+ };
672
+ code?: string;
673
+ message?: string;
674
+ developerMessage?: string;
675
+ }, transactionId: string): never;
676
+ /**
677
+ * Process PERS API errors and handle TRANSACTION_NOT_PENDING cases
678
+ * @param err - The caught error from PERS API
679
+ * @param transactionId - The transaction ID
680
+ * @throws Either the original error or a structured status error
681
+ */
682
+ static processPersApiError(err: unknown, transactionId: string): never;
683
+ }
684
+
685
+ /**
686
+ * Handles all validation operations for transaction signing
687
+ */
688
+ declare class TransactionValidator {
689
+ /**
690
+ * Validate transaction signing parameters
691
+ * @param params - Transaction signing parameters to validate
692
+ * @throws TransactionSigningError if validation fails
693
+ */
694
+ static validateSigningParams(params: TransactionSigningParams): void;
695
+ /**
696
+ * Validate authentication tokens passed as parameters
697
+ * @param authTokens - The authentication tokens to validate
698
+ * @returns true if valid, throws error if invalid
699
+ */
700
+ static validateAuthTokens(authTokens: SigningAuthTokens): boolean;
701
+ }
702
+
703
+ /**
704
+ * Handles transaction submission, success flows, and redirect logic
705
+ */
706
+ declare class TransactionSubmissionHandler {
707
+ /**
708
+ * Create redirect URL with transaction parameters
709
+ * @param returnUrl - Base return URL
710
+ * @param transactionHash - Transaction hash to include
711
+ * @param metadata - Optional metadata to include as parameters
712
+ * @returns Promise resolving to the complete redirect URL
713
+ */
714
+ static createRedirectUrl(returnUrl: string, transactionHash: string, metadata?: TransactionMetadata): Promise<string>;
715
+ /**
716
+ * Submit transaction and handle success flow
717
+ * @param preparedTransaction - The prepared transaction
718
+ * @param signature - The transaction signature
719
+ * @param signingData - The signing data used
720
+ * @param authTokens - Authentication tokens
721
+ * @param transactionId - Transaction ID for tracking
722
+ * @param returnUrl - Optional return URL for redirect
723
+ * @param metadata - Optional metadata for redirect parameters
724
+ * @returns Promise resolving to submission result
725
+ */
726
+ static handleTransactionSubmission(preparedTransaction: TransactionRequestResponseDTO, signature: string, signingData: AnyTransactionData, authTokens: SigningAuthTokens, returnUrl?: string, metadata?: TransactionMetadata): Promise<SubmissionResult>;
727
+ }
728
+
729
+ /**
730
+ * Utility class for coordinating WebAuthn operations to prevent conflicts
731
+ * Manages global state flags to ensure only one WebAuthn operation runs at a time
732
+ */
733
+ declare class WebAuthnCoordinator {
734
+ /**
735
+ * Clear the landing authentication flag
736
+ * Used when starting a new transaction signing flow
737
+ */
738
+ static clearLandingAuthentication(): void;
739
+ /**
740
+ * Check if a WebAuthn operation is currently in progress
741
+ * @returns True if an operation is in progress, false otherwise
742
+ */
743
+ static checkConcurrentOperations(): boolean;
744
+ /**
745
+ * Set the WebAuthn operation in progress flag
746
+ * @param inProgress - Whether an operation is in progress
747
+ */
748
+ static setOperationInProgress(inProgress: boolean): void;
749
+ }
750
+
751
+ /**
752
+ * Platform-agnostic configuration provider
753
+ * Abstracts environment variable access for cross-platform compatibility
754
+ */
755
+ interface ServiceConfig {
756
+ apiUrl: string;
757
+ appId?: string;
758
+ relyingParty: {
759
+ id: string;
760
+ name: string;
761
+ origin?: string;
762
+ };
763
+ }
764
+ interface ConfigProvider {
765
+ getServiceConfig(): ServiceConfig;
766
+ }
767
+ /**
768
+ * Web platform configuration provider
769
+ * Uses provided configuration instead of environment variables
770
+ */
771
+ declare class WebConfigProvider implements ConfigProvider {
772
+ private config;
773
+ constructor(config: ServiceConfig);
774
+ getServiceConfig(): ServiceConfig;
775
+ }
776
+ /**
777
+ * React Native configuration provider
778
+ * Uses process.env or custom config for React Native environments
779
+ */
780
+ declare class ReactNativeConfigProvider implements ConfigProvider {
781
+ private config;
782
+ constructor(config: ServiceConfig);
783
+ getServiceConfig(): ServiceConfig;
784
+ }
785
+ /**
786
+ * Static configuration provider for testing or custom setups
787
+ */
788
+ declare class StaticConfigProvider implements ConfigProvider {
789
+ private config;
790
+ constructor(config: ServiceConfig);
791
+ getServiceConfig(): ServiceConfig;
792
+ }
793
+ /**
794
+ * Set the global configuration provider
795
+ */
796
+ declare function setConfigProvider(provider: ConfigProvider): void;
797
+ /**
798
+ * Get the current configuration provider
799
+ * Requires explicit initialization with setConfigProvider
800
+ */
801
+ declare function getConfigProvider(): ConfigProvider;
802
+ /**
803
+ * Get the service configuration
804
+ */
805
+ declare function getServiceConfig(): ServiceConfig;
806
+
807
+ /**
808
+ * Platform-agnostic HTTP client abstraction
809
+ * Provides a consistent interface for HTTP requests across platforms
810
+ */
811
+ interface HttpResponse<T = any> {
812
+ data: T;
813
+ status: number;
814
+ statusText: string;
815
+ headers: Record<string, string>;
816
+ }
817
+ interface HttpRequestOptions {
818
+ method: 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH';
819
+ headers?: Record<string, string>;
820
+ body?: any;
821
+ timeout?: number;
822
+ }
823
+ interface HttpClient {
824
+ request<T = any>(url: string, options: HttpRequestOptions): Promise<HttpResponse<T>>;
825
+ get<T = any>(url: string, headers?: Record<string, string>): Promise<HttpResponse<T>>;
826
+ post<T = any>(url: string, data?: any, headers?: Record<string, string>): Promise<HttpResponse<T>>;
827
+ put<T = any>(url: string, data?: any, headers?: Record<string, string>): Promise<HttpResponse<T>>;
828
+ delete<T = any>(url: string, headers?: Record<string, string>): Promise<HttpResponse<T>>;
829
+ }
830
+ /**
831
+ * Fetch-based HTTP client for web environments
832
+ */
833
+ declare class FetchHttpClient implements HttpClient {
834
+ private defaultHeaders;
835
+ request<T = any>(url: string, options: HttpRequestOptions): Promise<HttpResponse<T>>;
836
+ get<T = any>(url: string, headers?: Record<string, string>): Promise<HttpResponse<T>>;
837
+ post<T = any>(url: string, data?: any, headers?: Record<string, string>): Promise<HttpResponse<T>>;
838
+ put<T = any>(url: string, data?: any, headers?: Record<string, string>): Promise<HttpResponse<T>>;
839
+ delete<T = any>(url: string, headers?: Record<string, string>): Promise<HttpResponse<T>>;
840
+ }
841
+ /**
842
+ * Set the global HTTP client
843
+ */
844
+ declare function setHttpClient(client: HttpClient): void;
845
+ /**
846
+ * Get the current HTTP client
847
+ */
848
+ declare function getHttpClient(): HttpClient;
849
+
850
+ /**
851
+ * PERS Blockchain Signer SDK - Simple Orchestrator
852
+ *
853
+ * Lightweight SDK that orchestrates existing services.
854
+ * Uses environment configuration and existing infrastructure.
855
+ */
856
+
857
+ interface JWTPayload {
858
+ email?: string;
859
+ userId?: string;
860
+ tenantId?: string;
861
+ exp?: number;
862
+ [key: string]: any;
863
+ }
864
+ interface PersAuthResult {
865
+ user: {
866
+ email?: string;
867
+ id?: string;
868
+ };
869
+ accessToken: string;
870
+ }
871
+ /**
872
+ * User information for authentication
873
+ */
874
+ interface SignerUserInfo {
875
+ identifier: string;
876
+ email?: string;
877
+ id?: string;
878
+ }
879
+ /**
880
+ * Authenticated user with all required tokens
881
+ */
882
+ interface SignerAuthenticatedUser {
883
+ identifier: string;
884
+ signerAuthToken: string;
885
+ persAccessToken: string;
886
+ }
887
+ interface AuthenticationResult {
888
+ user: SignerAuthenticatedUser;
889
+ isExpired: boolean;
890
+ }
891
+ interface JWTExtractionResult {
892
+ payload: JWTPayload | null;
893
+ isExpired: boolean;
894
+ }
895
+ interface PersSignerConfig {
896
+ tenantId?: string;
897
+ ethersProviderUrl?: string;
898
+ webAuthnProvider: WebAuthnProvider;
899
+ apiUrl?: string;
900
+ relyingPartyName?: string;
901
+ }
902
+ interface SigningResult {
903
+ success: boolean;
904
+ transactionHash?: string;
905
+ error?: string;
906
+ }
907
+ /**
908
+ * Main PERS Signer SDK class
909
+ *
910
+ * Simple orchestrator that uses existing services and environment configuration.
911
+ * No complex initialization needed - services are already configured.
912
+ */
913
+ declare class PersSignerSDK {
914
+ private config;
915
+ private authService;
916
+ private signingService;
917
+ private transactionSigningService;
918
+ private webAuthnProvider;
919
+ constructor(config: PersSignerConfig);
920
+ /**
921
+ * Re-export TransactionSigningService with WebAuthn provider already injected
922
+ * This provides the same interface as the original service but with automatic provider injection
923
+ */
924
+ get TransactionSigningService(): TransactionSigningService;
925
+ /**
926
+ * Complete user onboarding flow - same as web project
927
+ * Uses existing AuthenticationService and PersService
928
+ */
929
+ authenticateUser(userInfo: SignerUserInfo): Promise<SignerAuthenticatedUser>;
930
+ /**
931
+ * Complete PERS transaction signing flow - exactly like web project
932
+ * Uses existing TransactionSigningService with injected WebAuthn provider
933
+ */
934
+ signPersTransaction(user: SignerAuthenticatedUser, transactionId: string): Promise<SigningResult>;
935
+ /**
936
+ * Register new user - uses existing AuthenticationService
937
+ */
938
+ registerUser(identifier: string): Promise<{
939
+ authToken: string;
940
+ }>;
941
+ /**
942
+ * Login existing user - uses existing AuthenticationService
943
+ */
944
+ loginUser(identifier: string): Promise<string>;
945
+ /**
946
+ * Add wallet to PERS user - uses existing PersService
947
+ */
948
+ addWalletToPersUser(signerAuthToken: string): Promise<string>;
949
+ /**
950
+ * Retrieve transaction data from PERS - uses existing PersService
951
+ */
952
+ retrieveTransactionData(transactionId: string, persAccessToken: string): Promise<TransactionRequestResponseDTO>;
953
+ /**
954
+ * Sign transaction data - uses existing SigningService
955
+ * Follows same patterns as KeyWallet.signPersTransaction
956
+ */
957
+ signTransactionData(signerAuthToken: string, signingData: AnyTransactionData): Promise<string>;
958
+ /**
959
+ * Submit signed transaction to PERS - uses existing PersService
960
+ */
961
+ submitTransaction(transactionId: string, signature: string, persAccessToken: string, transactionFormat?: TransactionFormat): Promise<{
962
+ transactionHash?: string;
963
+ success: boolean;
964
+ }>;
965
+ /**
966
+ * Check if user exists - uses existing AuthenticationService
967
+ */
968
+ checkUserExists(identifier: string): Promise<boolean>;
969
+ /**
970
+ * Get user wallets - uses existing WalletService
971
+ */
972
+ getUserWallets(signerAuthToken: string): Promise<any>;
973
+ /**
974
+ * Get transaction status - uses existing PersService
975
+ */
976
+ getTransactionStatus(transactionId: string, persAccessToken: string): Promise<{
977
+ status: string;
978
+ transactionHash?: string;
979
+ }>;
980
+ /**
981
+ * Initialize tenant - uses existing PersService
982
+ */
983
+ initializeTenant(tenantId: string): Promise<void>;
984
+ /**
985
+ * Extract and validate JWT token from URL search parameters
986
+ * Uses a simpler approach compatible with browser environments
987
+ */
988
+ extractJWTFromURL(searchParams: URLSearchParams): JWTExtractionResult;
989
+ /**
990
+ * Initialize tenant from JWT payload using existing PersService
991
+ */
992
+ initializeTenantFromJWT(payload: JWTPayload): Promise<string>;
993
+ /**
994
+ * Authenticate user with PERS API using existing PersService pattern
995
+ */
996
+ /**
997
+ * Authenticate user with PERS API using existing PersService
998
+ */
999
+ authenticatePersUser(jwtToken: string, projectKey: string): Promise<PersAuthResult>;
1000
+ /**
1001
+ * Combined PERS + DFNS authentication flow
1002
+ */
1003
+ combinedAuthentication(identifier: string, persAccessToken: string): Promise<SignerAuthenticatedUser>;
1004
+ /**
1005
+ * Complete JWT-based authentication flow (legacy PERS flow)
1006
+ */
1007
+ authenticateWithJWT(searchParams: URLSearchParams): Promise<AuthenticationResult | null>;
1008
+ }
1009
+
1010
+ /**
1011
+ * Wallet list response from WalletService
1012
+ */
1013
+ interface WalletListResponse {
1014
+ items: WalletItem[];
1015
+ }
1016
+ /**
1017
+ * Individual wallet item from wallet list - compatible with KeyWallet constructor
1018
+ */
1019
+ interface WalletItem {
1020
+ id: string;
1021
+ address: string;
1022
+ network: string;
1023
+ status: string;
1024
+ signingKey?: unknown;
1025
+ dateCreated?: string;
1026
+ custodial?: boolean;
1027
+ tags?: string[];
1028
+ boundToEvmNetwork?: boolean;
1029
+ [key: string]: unknown;
1030
+ }
1031
+
1032
+ /**
1033
+ * Utility functions for handling URL search parameters in a consistent way across applications
1034
+ */
1035
+ /**
1036
+ * Creates a URL search string that preserves all current parameters
1037
+ * @param paramsToExclude Array of parameter names to exclude from the result
1038
+ * @param paramsToAdd Object with additional parameters to add or override
1039
+ * @param baseParams Optional URLSearchParams object to use instead of window.location.search
1040
+ * @returns A search string with '?' prefix if there are parameters, or empty string if no parameters
1041
+ */
1042
+ declare function createSearchString(paramsToExclude?: string[], paramsToAdd?: Record<string, string>, baseParams?: URLSearchParams | string): string;
1043
+ /**
1044
+ * Creates a URL path with search parameters
1045
+ * @param basePath The base path without search parameters
1046
+ * @param paramsToExclude Array of parameter names to exclude from the result
1047
+ * @param paramsToAdd Object with additional parameters to add or override
1048
+ * @param baseParams Optional URLSearchParams object to use instead of window.location.search
1049
+ * @returns A full path with search parameters
1050
+ */
1051
+ declare function createUrlWithSearchParams(basePath: string, paramsToExclude?: string[], paramsToAdd?: Record<string, string>, baseParams?: URLSearchParams | string): string;
1052
+ /**
1053
+ * Combines the current search parameters with new ones
1054
+ * @param searchParams The current URLSearchParams object
1055
+ * @param additionalParams Object with parameters to add or update
1056
+ * @returns A new URLSearchParams object
1057
+ */
1058
+ declare function mergeSearchParams(searchParams: URLSearchParams, additionalParams?: Record<string, string>): URLSearchParams;
1059
+ /**
1060
+ * Gets a specific search parameter value
1061
+ * @param key The parameter name to get
1062
+ * @param search Optional search string to parse (defaults to window.location.search)
1063
+ * @returns The parameter value or null if not found
1064
+ */
1065
+ declare function getSearchParam(key: string, search?: string): string | null;
1066
+ /**
1067
+ * Gets all search parameters as a URLSearchParams object
1068
+ * @param search Optional search string to parse (defaults to window.location.search)
1069
+ * @returns A URLSearchParams object
1070
+ */
1071
+ declare function getAllSearchParams(search?: string): URLSearchParams;
1072
+ /**
1073
+ * Removes a specific search parameter
1074
+ * @param key The parameter name to remove
1075
+ * @param search Optional search string to parse (defaults to window.location.search)
1076
+ * @returns A new search string without the specified parameter
1077
+ */
1078
+ declare function removeSearchParam(key: string, search?: string): string;
1079
+ /**
1080
+ * Updates or adds a specific search parameter
1081
+ * @param key The parameter name to update
1082
+ * @param value The new value for the parameter
1083
+ * @param search Optional search string to parse (defaults to window.location.search)
1084
+ * @returns A new search string with the updated parameter
1085
+ */
1086
+ declare function updateSearchParam(key: string, value: string, search?: string): string;
1087
+
1088
+ /**
1089
+ * Utility for debugging search parameter handling
1090
+ */
1091
+ /**
1092
+ * Logs the current search parameters with a custom message
1093
+ * This is useful for debugging search parameter preservation across navigation
1094
+ *
1095
+ * @param message - A descriptive message to identify where the logging happens
1096
+ * @param additionalData - Optional additional data to log
1097
+ */
1098
+ declare function logSearchParams(message: string, additionalData?: any): void;
1099
+ /**
1100
+ * Creates a search parameter tracking hook that can be used in React components
1101
+ * Logs search parameter changes when the component mounts/updates
1102
+ *
1103
+ * @param componentName - The name of the component (for logging)
1104
+ */
1105
+ declare function createSearchParamLogger(componentName: string): () => void;
1106
+
1107
+ /**
1108
+ * Generates a RFC4122 version 4 compliant UUID
1109
+ * @returns A randomly generated UUID
1110
+ */
1111
+ declare function generateUUID(): string;
1112
+ /**
1113
+ * Create a semi-anonymous username for users
1114
+ * @returns A username in the format "user_[random string]"
1115
+ */
1116
+ declare function generateAnonymousUsername(): string;
1117
+ /**
1118
+ * Create a guest username for the application with a random prefix
1119
+ * @returns A guest email in the format "randomstring_guest@explorins.com"
1120
+ */
1121
+ declare function generateGuestUsername(): string;
1122
+
1123
+ /**
1124
+ * Utility functions for tenant-specific operations
1125
+ */
1126
+ /**
1127
+ * Represents a tenant configuration
1128
+ */
1129
+ interface TenantConfig {
1130
+ id: string;
1131
+ name: string;
1132
+ analytics?: {
1133
+ enabled: boolean;
1134
+ trackingId?: string;
1135
+ };
1136
+ }
1137
+ /**
1138
+ * Initialize tenant-specific analytics
1139
+ * @param tenantId The tenant ID
1140
+ * @param getTenantConfig Function to retrieve tenant configuration
1141
+ */
1142
+ declare const initTenantAnalytics: (tenantId: string, getTenantConfig: (id: string) => TenantConfig | null) => void;
1143
+
1144
+ /**
1145
+ * Authentication service for user login and registration
1146
+ * Uses constructor-based dependency injection for WebAuthn provider
1147
+ */
1148
+ declare class AuthenticationService {
1149
+ private webAuthnProvider;
1150
+ constructor(webAuthnProvider: WebAuthnProvider);
1151
+ /**
1152
+ * Authenticate user with username
1153
+ * @param username - User identifier
1154
+ * @returns Promise resolving to authentication token
1155
+ */
1156
+ login(username: string): Promise<string>;
1157
+ /**
1158
+ * Register new user with WebAuthn credential
1159
+ * @param username - User identifier
1160
+ * @returns Promise resolving to registration result
1161
+ */
1162
+ register(username: string): Promise<RegistrationResult>;
1163
+ /**
1164
+ * Validate authentication token (when backend supports it)
1165
+ * @param authToken - Token to validate
1166
+ * @returns Promise resolving to validation result
1167
+ */
1168
+ validateToken(authToken: string): Promise<boolean>;
1169
+ /**
1170
+ * Get user information (when backend supports it)
1171
+ * @param authToken - Authentication token
1172
+ * @returns Promise resolving to user info or null
1173
+ */
1174
+ getUser(authToken: string): Promise<{
1175
+ username: string;
1176
+ } | null>;
1177
+ }
1178
+
1179
+ /**
1180
+ * Browser-specific WebAuthn provider using DFNS browser SDK
1181
+ */
1182
+
1183
+ /**
1184
+ * Get WebAuthn provider for browser environments
1185
+ */
1186
+ declare function getBrowserWebAuthnProvider(): Promise<WebAuthnProvider>;
1187
+
1188
+ /**
1189
+ * Browser-specific entry point for the PERS Signer SDK
1190
+ * Includes only browser-compatible dependencies
1191
+ */
1192
+
1193
+ /**
1194
+ * Create a new AuthenticationService instance with browser WebAuthn provider
1195
+ */
1196
+ declare function createAuthenticationService(): Promise<AuthenticationService>;
1197
+ /**
1198
+ * Create a new SigningService instance with browser WebAuthn provider
1199
+ */
1200
+ declare function createSigningService(): Promise<SigningService>;
1201
+ /**
1202
+ * Create a new PersSignerSDK instance with browser WebAuthn provider
1203
+ * @param config - SDK configuration (ethersProviderUrl is required)
1204
+ */
1205
+ declare function createPersSignerSDK(config: Omit<PersSignerConfig, 'webAuthnProvider'>): Promise<PersSignerSDK>;
1206
+
1207
+ export { AuthenticationService, FetchHttpClient, KeyWallet, PersService, PersSignerSDK, ReactNativeConfigProvider, SIGNABLE_STATUSES, SigningService, StaticConfigProvider, TransactionErrorHandler, TransactionSigningErrorCode, TransactionSigningService, TransactionSubmissionHandler, TransactionValidator, WalletService, WebAuthnCoordinator, WebConfigProvider, createAuthenticationService, createPersSignerSDK, createSearchParamLogger, createSearchString, createSigningService, createUrlWithSearchParams, generateAnonymousUsername, generateGuestUsername, generateUUID, getAllSearchParams, getBrowserWebAuthnProvider, getConfigProvider, getHttpClient, getSearchParam, getServiceConfig, getBrowserWebAuthnProvider as getWebAuthnProvider, initTenantAnalytics, logSearchParams, mergeSearchParams, removeSearchParam, setConfigProvider, setHttpClient, updateSearchParam };
1208
+ export type { ApiResponse, AuthResponse, AuthState, AuthToken, AuthenticationResult, CombinedTransactionStatus, ConfigProvider, HashSigningRequest, HttpClient, HttpRequestOptions, HttpResponse, JWTExtractionResult, JWTPayload, WalletItem$1 as KeyWalletItem, WalletListResponse$1 as KeyWalletListResponse, PersAuthResult, PersSignerConfig, PreparedTransaction, RegistrationChallenge, RegistrationResult, RelyingPartyConfig, ServiceConfig$1 as ServiceConfig, ServiceError, SharedLibEnvironment, SignResponse, SignerAuthenticatedUser, SignerUserInfo, SigningAuthTokens, SigningChallenge, SigningRequest, SigningResult$1 as SigningResult, StoredTransactionResult, SubmissionResult, TenantConfig, TransactionMetadata, TransactionSigningError, TransactionSigningParams, TransactionSigningResult, TransactionStatusInfo, TypedDataSigningRequest, UserCredentials, UserProfile, WalletConfig, WalletItem, WalletListResponse, WebAuthnConfig, WebAuthnProvider };