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