@explorins/pers-signer 1.0.32 → 1.0.34

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/dist/index.d.ts CHANGED
@@ -1,10 +1,10 @@
1
- import * as _explorins_web3_ts_types from '@explorins/web3-ts/types';
2
- import { LegacyTransaction, AnyTransactionData } from '@explorins/web3-ts/types';
3
- export { AnyTransactionData, BaseTransaction, CounterfactualWalletEIP712Data, EIP1559Transaction, EIP2930Transaction, EIP712TransactionData, EIP712TypedData, LegacyTransaction } from '@explorins/web3-ts/types';
1
+ import { CounterfactualWalletTransactionResponse as CounterfactualWalletTransactionResponse$1 } from '@explorins/pers-shared';
4
2
  import * as _explorins_pers_shared_browser from '@explorins/pers-shared/browser';
5
3
  import { CounterfactualWalletTransactionResponse, TransactionStatus, TransactionRequestResponseDTO, TenantPublicDTO, SessionAuthContextResponseDTO, TransactionFormat } from '@explorins/pers-shared/browser';
6
4
  export { CampaignClaimDTO, CampaignDTO, SessionAuthResponseDTO, TRANSACTION_FORMATS, TRANSACTION_FORMAT_DESCRIPTIONS, TransactionFormat, TransactionRequestResponseDTO, TransactionStatus, TransactionSubmissionRequestDTO } from '@explorins/pers-shared/browser';
7
- import { CounterfactualWalletTransactionResponse as CounterfactualWalletTransactionResponse$1 } from '@explorins/pers-shared';
5
+ import * as _explorins_web3_ts_types from '@explorins/web3-ts/types';
6
+ import { LegacyTransaction, AnyTransactionData } from '@explorins/web3-ts/types';
7
+ export { AnyTransactionData, BaseTransaction, CounterfactualWalletEIP712Data, EIP1559Transaction, EIP2930Transaction, EIP712TransactionData, EIP712TypedData, LegacyTransaction } from '@explorins/web3-ts/types';
8
8
  import { AbstractSigner, Provider, TransactionRequest, TypedDataDomain, TypedDataField } from 'ethers';
9
9
 
10
10
  /**
@@ -309,7 +309,7 @@ interface TransactionSigningResult {
309
309
  shouldShowStatus?: boolean;
310
310
  }
311
311
  /**
312
- * Transaction submission result for internal processing
312
+ * Transaction submission result
313
313
  */
314
314
  interface SubmissionResult {
315
315
  submitResult: TransactionRequestResponseDTO;
@@ -319,9 +319,6 @@ interface SubmissionResult {
319
319
  success: boolean;
320
320
  error?: string;
321
321
  }
322
- /**
323
- * Metadata for transaction parameters - string values only
324
- */
325
322
  /**
326
323
  * Authentication tokens required for transaction signing
327
324
  */
@@ -459,117 +456,307 @@ interface ServiceError {
459
456
  }
460
457
 
461
458
  /**
462
- * Wallet management service
463
- * Updated for v1 API endpoints per migration reference
459
+ * PERS Blockchain Signer SDK
460
+ *
461
+ * A lightweight blockchain transaction signing SDK with WebAuthn authentication.
462
+ * Provides 5 focused methods for complete transaction lifecycle management:
463
+ *
464
+ * 1. loginUser(jwtToken) - Authenticate user with 5-minute caching
465
+ * 2. signTransaction(signingData, jwtToken) - Sign transactions with auto-login
466
+ * 3. submitTransaction(signedTx, jwtToken) - Submit signed transactions to blockchain
467
+ * 4. signPersTransaction(jwtToken) - Legacy one-liner for backward compatibility
468
+ * 5. signAndSubmitPersTransaction(jwtToken) - Complete sign + submit flow
469
+ *
470
+ * @example
471
+ * ```typescript
472
+ * import { createPersSignerSDK } from '@explorins/pers-signer';
473
+ *
474
+ * const sdk = createPersSignerSDK({
475
+ * webAuthnProvider: myWebAuthnProvider,
476
+ * ethersProviderUrl: 'https://ethereum-rpc.com'
477
+ * });
478
+ *
479
+ * // Quick sign and submit
480
+ * const result = await sdk.signAndSubmitPersTransaction(jwtToken);
481
+ * if (result.success) {
482
+ * console.log('Transaction submitted:', result.transactionHash);
483
+ * }
484
+ * ```
464
485
  */
465
- declare class WalletService {
466
- /**
467
- * List all wallets for authenticated user
468
- * @param signerToken - Signer JWT token
469
- * @returns Promise resolving to wallet data
470
- */
471
- static listWallets(signerToken: string): Promise<Wallet[]>;
472
- }
473
486
 
474
487
  /**
475
- * Service for interacting with PERS (Phygital Experience Rewards System) backend API
488
+ * Configuration options for the PERS Signer SDK
476
489
  */
490
+ interface PersSignerConfig {
491
+ ethersProviderUrl?: string;
492
+ apiUrl?: string;
493
+ relyingPartyName?: string;
494
+ globalStatusCallback?: StatusCallback;
495
+ }
477
496
  /**
478
- * Configuration interface for PERS API
497
+ * Extended configuration that includes the WebAuthn provider
479
498
  */
480
- interface PersApiConfig {
481
- baseUrl: string;
482
- projectKey?: string;
499
+ interface ExtendedPersSignerConfig extends PersSignerConfig {
500
+ webAuthnProvider: WebAuthnProvider;
483
501
  }
484
- declare class PersService {
485
- private static config;
486
- private static tenantCache;
487
- private static currentProjectKey;
488
- private static currentTenantId;
489
- private static readonly TENANT_CACHE_TTL;
490
- /**
491
- * Configure the PERS API settings
492
- * @param config - The configuration object
493
- */
494
- static configure(config: Partial<PersApiConfig>): void;
495
- /**
496
- * Get current configuration
497
- */
498
- static getConfig(): PersApiConfig;
502
+ /**
503
+ * PERS Blockchain Signer SDK Class
504
+ *
505
+ * Main SDK class providing blockchain transaction signing capabilities with WebAuthn authentication.
506
+ * Implements a clean 5-method API for complete transaction lifecycle management.
507
+ *
508
+ * Features:
509
+ * - WebAuthn-based secure authentication
510
+ * - 5-minute user session caching
511
+ * - Automatic transaction data fetching
512
+ * - Blockchain transaction signing and submission
513
+ * - Multi-tenant support
514
+ *
515
+ * @class PersSignerSDK
516
+ */
517
+ declare class PersSignerSDK {
518
+ private config;
519
+ private authenticationService;
520
+ private transactionSigningService;
499
521
  /**
500
- * Get tenant information by tenant ID
501
- * @param tenantId - The tenant ID to retrieve
502
- * @param authToken - Optional auth token for authentication
503
- * @returns Promise with tenant public information
522
+ * Initialize the PERS Signer SDK
523
+ *
524
+ * @param {ExtendedPersSignerConfig} config - SDK configuration object
525
+ * @throws {Error} If required configuration is missing
504
526
  */
505
- static getTenantById(tenantId: string, authToken: string): Promise<TenantPublicDTO>;
527
+ constructor(config: ExtendedPersSignerConfig);
506
528
  /**
507
- * Initialize tenant configuration from JWT
508
- * @param tenantId - The tenant ID from JWT payload
509
- * @param authToken - Optional auth token for authentication
510
- * @returns Promise with tenant information
529
+ * Helper method to trigger both global and method-specific status callbacks
530
+ * @private
511
531
  */
512
- static initializeTenant(tenantId: string, authToken: string): Promise<TenantPublicDTO>;
532
+ private triggerStatusUpdate;
513
533
  /**
514
- * Ensure tenant is initialized and current, with automatic revalidation
515
- * @param tenantId - The tenant ID to ensure is initialized
516
- * @param authToken - Optional auth token for authentication
517
- * @returns Promise with tenant information
534
+ * Authenticate user and cache session for 5 minutes
535
+ *
536
+ * Validates JWT token, authenticates with both signer and PERS backends,
537
+ * and caches the authenticated user session to avoid repeated authentication.
538
+ *
539
+ * @param {string} jwtToken - JWT token containing user identifier and tenant info
540
+ * @param {StatusCallback} [statusCallback] - Optional callback for status updates
541
+ * @returns {Promise<AuthenticatedUser>} Authenticated user with access tokens
542
+ * @throws {Error} If JWT is invalid, expired, or authentication fails
543
+ *
544
+ * @example
545
+ * ```typescript
546
+ * try {
547
+ * const user = await sdk.loginUser(jwtToken, {
548
+ * onStatusUpdate: (status, message) => console.log(`${status}: ${message}`)
549
+ * });
550
+ * console.log('Authenticated:', user.identifier);
551
+ * } catch (error) {
552
+ * console.error('Authentication failed:', error.message);
553
+ * }
554
+ * ```
518
555
  */
519
- static ensureTenantInitialized(tenantId: string, authToken: string): Promise<TenantPublicDTO>;
556
+ loginUser(jwtToken: string, statusCallback?: StatusCallback): Promise<AuthenticatedUser>;
520
557
  /**
521
- * Get the current project key (either from tenant or fallback)
522
- * @param tenantId - Optional tenant ID to ensure is initialized
523
- * @returns The project key to use for API calls
558
+ * Sign a PERS transaction (legacy compatibility method)
559
+ *
560
+ * Automatically handles user authentication, transaction data fetching,
561
+ * and transaction signing in a single call. This is the legacy method
562
+ * maintained for backward compatibility.
563
+ *
564
+ * @param {string} jwtToken - JWT token containing transaction ID and user info
565
+ * @param {StatusCallback} [statusCallback] - Optional callback for status updates
566
+ * @returns {Promise<TransactionSigningResult>} Signing result with signature and metadata
567
+ * @throws {Error} If authentication fails, transaction ID missing, or signing fails
568
+ *
569
+ * @example
570
+ * ```typescript
571
+ * try {
572
+ * const result = await sdk.signPersTransaction(jwtToken, {
573
+ * onStatusUpdate: (status, message) => console.log(`${status}: ${message}`)
574
+ * });
575
+ * if (result.success) {
576
+ * console.log('Transaction signed:', result.signature);
577
+ * }
578
+ * } catch (error) {
579
+ * console.error('Signing failed:', error.message);
580
+ * }
581
+ * ```
524
582
  */
525
- private static getProjectKey;
583
+ signPersTransaction(jwtToken: string, statusCallback?: StatusCallback): Promise<TransactionSigningResult>;
526
584
  /**
527
- * Clear tenant cache and reset project key
585
+ * Sign a transaction with provided signing data
586
+ *
587
+ * Low-level method to sign transactions when you already have the signing data.
588
+ * Automatically handles user authentication and applies the blockchain signature.
589
+ *
590
+ * @param {CounterfactualWalletTransactionResponse | LegacyTransaction} signingData - Transaction data to sign
591
+ * @param {string} jwtToken - JWT token containing transaction ID and user info
592
+ * @param {StatusCallback} [statusCallback] - Optional callback for status updates
593
+ * @returns {Promise<TransactionSigningResult>} Signing result with signature and metadata
594
+ * @throws {Error} If authentication fails, transaction ID missing, or signing fails
595
+ *
596
+ * @example
597
+ * ```typescript
598
+ * const signingData = await getTransactionData(transactionId);
599
+ * const result = await sdk.signTransaction(signingData, jwtToken, {
600
+ * onStatusUpdate: (status, message) => console.log(`${status}: ${message}`)
601
+ * });
602
+ * console.log('Signed transaction:', result.signature);
603
+ * ```
528
604
  */
529
- static clearTenantCache(): void;
605
+ signTransaction(signingData: CounterfactualWalletTransactionResponse$1 | LegacyTransaction, jwtToken: string, statusCallback?: StatusCallback): Promise<TransactionSigningResult>;
530
606
  /**
531
- * Authenticates a user with the PERS backend using their auth token
607
+ * Complete transaction flow: sign and submit in one call
532
608
  *
533
- * @param authToken - The authentication token received from backend after login/registration
534
- * @param tenantId - Optional tenant ID for automatic initialization
535
- * @returns A promise that resolves to the authentication response
536
- * @throws If the request fails
609
+ * Convenience method that combines signing and submission into a single operation.
610
+ * This is the recommended method for most use cases as it handles the complete
611
+ * transaction lifecycle automatically.
612
+ *
613
+ * @param {string} jwtToken - JWT token containing transaction ID and user info
614
+ * @param {StatusCallback} [statusCallback] - Optional callback for status updates
615
+ * @returns {Promise<SubmissionResult>} Submission result with transaction hash and status
616
+ * @throws {Error} If authentication, signing, or submission fails
617
+ *
618
+ * @example
619
+ * ```typescript
620
+ * try {
621
+ * const result = await sdk.signAndSubmitPersTransaction(jwtToken, {
622
+ * onStatusUpdate: (status, message) => {
623
+ * console.log(`Status: ${status} - ${message}`);
624
+ * }
625
+ * });
626
+ * if (result.success) {
627
+ * console.log('Transaction completed:', result.transactionHash);
628
+ * if (result.shouldRedirect) {
629
+ * window.location.href = result.redirectUrl;
630
+ * }
631
+ * }
632
+ * } catch (error) {
633
+ * console.error('Transaction failed:', error.message);
634
+ * }
635
+ * ```
537
636
  */
538
- static authenticateUser(authToken: string, tenantId: string): Promise<SessionAuthContextResponseDTO>;
637
+ signAndSubmitPersTransaction(jwtToken: string, statusCallback?: StatusCallback): Promise<SubmissionResult>;
539
638
  /**
540
- * Submits a transaction by calling the backend endpoint
639
+ * Submit a signed transaction to the blockchain
541
640
  *
542
- * @param transactionId - The ID of the transaction to submit
543
- * @param signedTransactionOrSignature - The signed transaction data or EIP-712 signature
544
- * @param persAccessToken - The PERS access token for authentication (Bearer)
545
- * @param submissionType - The transaction format type
546
- * @param tenantId - Optional tenant ID for automatic initialization
547
- * @returns A promise that resolves to the transaction submission response
548
- * @throws If the request fails
641
+ * Takes a signed transaction result and submits it to the blockchain network.
642
+ * Returns detailed submission results including transaction hash and any
643
+ * redirect information for UI flows.
644
+ *
645
+ * @param {TransactionSigningResult} signingResult - Result from a successful transaction signing
646
+ * @param {string} jwtToken - JWT token containing tenant and user info
647
+ * @param {StatusCallback} [statusCallback] - Optional callback for status updates
648
+ * @returns {Promise<SubmissionResult>} Submission result with transaction hash and status
649
+ * @throws {Error} If signing result is invalid, JWT is missing tenantId, or submission fails
650
+ *
651
+ * @example
652
+ * ```typescript
653
+ * const signedTx = await sdk.signPersTransaction(jwtToken);
654
+ * const result = await sdk.submitTransaction(signedTx, jwtToken, {
655
+ * onStatusUpdate: (status, message) => console.log(`${status}: ${message}`)
656
+ * });
657
+ * console.log('Transaction submitted:', result.transactionHash);
658
+ * ```
549
659
  */
550
- static submitTransaction(transactionId: string, signedTransactionOrSignature: string, persAccessToken: string, submissionType: TransactionFormat, tenantId: string): Promise<TransactionRequestResponseDTO>;
660
+ submitTransaction(signingResult: TransactionSigningResult, jwtToken: string, statusCallback?: StatusCallback): Promise<SubmissionResult>;
551
661
  /**
552
- * Fetches a prepared transaction for signing by transactionId
553
- * @param transactionId - The transaction ID to fetch
554
- * @param persAccessToken - The PERS access token for authentication (Bearer)
555
- * @param tenantId - Optional tenant ID for automatic initialization
556
- * @returns The prepared transaction data
557
- * @throws If the request fails
662
+ * Clear user authentication cache
663
+ *
664
+ * Removes all cached user sessions, forcing fresh authentication
665
+ * on the next method call. Useful for logout scenarios or when
666
+ * switching between different user contexts.
667
+ *
668
+ * @example
669
+ * ```typescript
670
+ * // Clear cache on user logout
671
+ * sdk.clearCache();
672
+ * console.log('User cache cleared');
673
+ * ```
558
674
  */
559
- static fetchPreparedTransaction(transactionId: string, persAccessToken: string, tenantId: string): Promise<TransactionRequestResponseDTO>;
675
+ clearCache(): void;
676
+ }
677
+ /**
678
+ * Create a new PERS Signer SDK instance
679
+ *
680
+ * Factory function to create and configure a new SDK instance with the provided
681
+ * configuration. This is the recommended way to initialize the SDK.
682
+ *
683
+ * @param {PersSignerConfig} config - SDK configuration object
684
+ * @returns {PersSignerSDK} Configured SDK instance ready for use
685
+ * @throws {Error} If required configuration is missing or invalid
686
+ *
687
+ * @example
688
+ * ```typescript
689
+ * import { createPersSignerSDK, getWebAuthnProvider } from '@explorins/pers-signer';
690
+ *
691
+ * const webAuthnProvider = await getWebAuthnProvider();
692
+ * const sdk = createPersSignerSDK({
693
+ * webAuthnProvider,
694
+ * ethersProviderUrl: 'https://mainnet.infura.io/v3/YOUR_KEY',
695
+ * tenantId: 'your-tenant-id'
696
+ * });
697
+ * ```
698
+ */
699
+ declare function createPersSignerSDK(config: ExtendedPersSignerConfig): PersSignerSDK;
700
+
701
+ /**
702
+ * Authentication service for user login and registration
703
+ * Uses constructor-based dependency injection for WebAuthn provider
704
+ * Updated for new v1 API endpoints
705
+ */
706
+ declare class AuthenticationService {
707
+ private signerToken;
708
+ private webAuthnProvider;
709
+ constructor(config: ExtendedPersSignerConfig);
560
710
  /**
561
- * Helper method to determine if transaction data is available for signing
562
- * @param transactionResponse - Response from prepare or fetch transaction
563
- * @returns boolean indicating if transaction can be signed
711
+ * Login with PERS token to get signer JWT
712
+ * @param persToken - PERS JWT from PERS authentication
713
+ * @returns Promise resolving to login response or provider challenge data
564
714
  */
565
- static isTransactionReadyForSigning(transactionResponse: TransactionRequestResponseDTO): boolean;
715
+ loginWithPersToken(persToken: string): Promise<JWTLoginResponse | unknown>;
566
716
  /**
567
- * Helper method to get transaction data from response
568
- * @param transactionResponse - Response from prepare or fetch transaction
569
- * @returns The transaction data ready for signing
570
- * @throws If transaction data is not available
717
+ * Verify signer token validity
718
+ * @param token - Signer JWT to verify
719
+ * @returns Promise resolving to verification result
571
720
  */
572
- static getTransactionDataForSigning(transactionResponse: TransactionRequestResponseDTO): _explorins_pers_shared_browser.CounterfactualWalletTransactionResponse | _explorins_web3_ts_types.LegacyTransaction;
721
+ verifyToken(token: string): Promise<VerifyTokenResponse>;
722
+ /**
723
+ * Register user with unified flow
724
+ * @param persToken - PERS JWT token
725
+ * @returns Promise resolving to authenticated user data
726
+ */
727
+ registerUser(persToken: string): Promise<JWTLoginResponse>;
728
+ /**
729
+ * Get current signer token
730
+ * @returns The current signer JWT token
731
+ */
732
+ getSignerToken(): string | null;
733
+ /**
734
+ * Set signer token (for external token management)
735
+ * @param token - Signer JWT token
736
+ */
737
+ setSignerToken(token: string): void;
738
+ /**
739
+ * Combined authentication flow - handles both login and registration
740
+ * @param identifier - User identifier (email/userId)
741
+ * @param persAccessToken - PERS JWT token for authentication
742
+ * @param webAuthnProvider - WebAuthn provider for credential creation
743
+ * @param relyingPartyConfig - Configuration for WebAuthn relying party
744
+ * @returns Promise resolving to authenticated user with signer token
745
+ */
746
+ combinedAuthentication(identifier: string, persAccessToken: string): Promise<AuthenticatedUser>;
747
+ }
748
+
749
+ /**
750
+ * Wallet management service
751
+ * Updated for v1 API endpoints per migration reference
752
+ */
753
+ declare class WalletService {
754
+ /**
755
+ * List all wallets for authenticated user
756
+ * @param signerToken - Signer JWT token
757
+ * @returns Promise resolving to wallet data
758
+ */
759
+ static listWallets(signerToken: string): Promise<Wallet[]>;
573
760
  }
574
761
 
575
762
  /**
@@ -616,6 +803,119 @@ declare class SigningService {
616
803
  signBatch(authToken: string, walletId: string, requests: SigningRequest[]): Promise<CompleteSignatureResponse['data'][]>;
617
804
  }
618
805
 
806
+ /**
807
+ * Service for interacting with PERS (Phygital Experience Rewards System) backend API
808
+ */
809
+ /**
810
+ * Configuration interface for PERS API
811
+ */
812
+ interface PersApiConfig {
813
+ baseUrl: string;
814
+ projectKey?: string;
815
+ }
816
+ declare class PersService {
817
+ private static config;
818
+ private static tenantCache;
819
+ private static currentProjectKey;
820
+ private static currentTenantId;
821
+ private static readonly TENANT_CACHE_TTL;
822
+ /**
823
+ * Configure the PERS API settings
824
+ * @param config - The configuration object
825
+ */
826
+ static configure(config: Partial<PersApiConfig>): void;
827
+ /**
828
+ * Get current configuration
829
+ */
830
+ static getConfig(): PersApiConfig;
831
+ /**
832
+ * Get tenant information by tenant ID
833
+ * @param tenantId - The tenant ID to retrieve
834
+ * @param authToken - Optional auth token for authentication
835
+ * @returns Promise with tenant public information
836
+ */
837
+ static getTenantById(tenantId: string, authToken: string): Promise<TenantPublicDTO>;
838
+ /**
839
+ * Initialize tenant configuration from JWT
840
+ * @param tenantId - The tenant ID from JWT payload
841
+ * @param authToken - Optional auth token for authentication
842
+ * @returns Promise with tenant information
843
+ */
844
+ static initializeTenant(tenantId: string, authToken: string): Promise<TenantPublicDTO>;
845
+ /**
846
+ * Ensure tenant is initialized and current, with automatic revalidation
847
+ * @param tenantId - The tenant ID to ensure is initialized
848
+ * @param authToken - Optional auth token for authentication
849
+ * @returns Promise with tenant information
850
+ */
851
+ static ensureTenantInitialized(tenantId: string, authToken: string): Promise<TenantPublicDTO>;
852
+ /**
853
+ * Get the current project key (either from tenant or fallback)
854
+ * @param tenantId - Optional tenant ID to ensure is initialized
855
+ * @returns The project key to use for API calls
856
+ */
857
+ private static getProjectKey;
858
+ /**
859
+ * Clear tenant cache and reset project key
860
+ */
861
+ static clearTenantCache(): void;
862
+ /**
863
+ * Authenticates a user with the PERS backend using their auth token
864
+ *
865
+ * @param authToken - The authentication token received from backend after login/registration
866
+ * @param tenantId - Optional tenant ID for automatic initialization
867
+ * @returns A promise that resolves to the authentication response
868
+ * @throws If the request fails
869
+ */
870
+ static authenticateUser(authToken: string, tenantId: string): Promise<SessionAuthContextResponseDTO>;
871
+ /**
872
+ * Submits a transaction by calling the backend endpoint
873
+ *
874
+ * @param transactionId - The ID of the transaction to submit
875
+ * @param signedTransactionOrSignature - The signed transaction data or EIP-712 signature
876
+ * @param persAccessToken - The PERS access token for authentication (Bearer)
877
+ * @param submissionType - The transaction format type
878
+ * @param tenantId - Optional tenant ID for automatic initialization
879
+ * @returns A promise that resolves to the transaction submission response
880
+ * @throws If the request fails
881
+ */
882
+ static submitTransaction(transactionId: string, signedTransactionOrSignature: string, persAccessToken: string, submissionType: TransactionFormat, tenantId: string): Promise<TransactionRequestResponseDTO>;
883
+ /**
884
+ * Fetches a prepared transaction for signing by transactionId
885
+ * @param transactionId - The transaction ID to fetch
886
+ * @param persAccessToken - The PERS access token for authentication (Bearer)
887
+ * @param tenantId - Optional tenant ID for automatic initialization
888
+ * @returns The prepared transaction data
889
+ * @throws If the request fails
890
+ */
891
+ static fetchPreparedTransaction(transactionId: string, persAccessToken: string, tenantId: string): Promise<TransactionRequestResponseDTO>;
892
+ /**
893
+ * Helper method to determine if transaction data is available for signing
894
+ * @param transactionResponse - Response from prepare or fetch transaction
895
+ * @returns boolean indicating if transaction can be signed
896
+ */
897
+ static isTransactionReadyForSigning(transactionResponse: TransactionRequestResponseDTO): boolean;
898
+ /**
899
+ * Helper method to get transaction data from response
900
+ * @param transactionResponse - Response from prepare or fetch transaction
901
+ * @returns The transaction data ready for signing
902
+ * @throws If transaction data is not available
903
+ */
904
+ static getTransactionDataForSigning(transactionResponse: TransactionRequestResponseDTO): _explorins_pers_shared_browser.CounterfactualWalletTransactionResponse | _explorins_web3_ts_types.LegacyTransaction;
905
+ }
906
+
907
+ /**
908
+ * Health check service for signer API
909
+ * Handles health check operations for the new v1 API
910
+ */
911
+ declare class HealthService {
912
+ /**
913
+ * Perform health check on the signer API
914
+ * @returns Promise resolving to health check result
915
+ */
916
+ static checkHealth(): Promise<HealthCheckResponse>;
917
+ }
918
+
619
919
  type WalletOptions = {
620
920
  wallet: WalletMetadata;
621
921
  authToken: string;
@@ -885,314 +1185,6 @@ declare function setHttpClient(client: HttpClient): void;
885
1185
  */
886
1186
  declare function getHttpClient(): HttpClient;
887
1187
 
888
- /**
889
- * PERS Blockchain Signer SDK
890
- *
891
- * A lightweight blockchain transaction signing SDK with WebAuthn authentication.
892
- * Provides 5 focused methods for complete transaction lifecycle management:
893
- *
894
- * 1. loginUser(jwtToken) - Authenticate user with 5-minute caching
895
- * 2. signTransaction(signingData, jwtToken) - Sign transactions with auto-login
896
- * 3. submitTransaction(signedTx, jwtToken) - Submit signed transactions to blockchain
897
- * 4. signPersTransaction(jwtToken) - Legacy one-liner for backward compatibility
898
- * 5. signAndSubmitPersTransaction(jwtToken) - Complete sign + submit flow
899
- *
900
- * @example
901
- * ```typescript
902
- * import { createPersSignerSDK } from '@explorins/pers-signer';
903
- *
904
- * const sdk = createPersSignerSDK({
905
- * webAuthnProvider: myWebAuthnProvider,
906
- * ethersProviderUrl: 'https://ethereum-rpc.com'
907
- * });
908
- *
909
- * // Quick sign and submit
910
- * const result = await sdk.signAndSubmitPersTransaction(jwtToken);
911
- * if (result.success) {
912
- * console.log('Transaction submitted:', result.transactionHash);
913
- * }
914
- * ```
915
- */
916
-
917
- /**
918
- * Configuration interface for the PERS Signer SDK
919
- *
920
- * @interface PersSignerConfig
921
- * @property {string} [tenantId] - Optional tenant identifier for multi-tenant applications
922
- * @property {string} [ethersProviderUrl] - Custom Ethereum RPC provider URL
923
- * @property {WebAuthnProvider} webAuthnProvider - WebAuthn provider for secure authentication
924
- * @property {string} [apiUrl] - Custom API base URL (defaults to production)
925
- * @property {string} [relyingPartyName] - WebAuthn relying party name for authentication
926
- * @property {StatusCallback} [globalStatusCallback] - Optional global status callback for all operations
927
- */
928
- interface ExtendedPersSignerConfig {
929
- ethersProviderUrl?: string;
930
- webAuthnProvider: WebAuthnProvider;
931
- apiUrl?: string;
932
- relyingPartyName?: string;
933
- globalStatusCallback?: StatusCallback;
934
- }
935
- interface PersSignerConfig extends Omit<ExtendedPersSignerConfig, 'webAuthnProvider'> {
936
- }
937
- /**
938
- * PERS Blockchain Signer SDK Class
939
- *
940
- * Main SDK class providing blockchain transaction signing capabilities with WebAuthn authentication.
941
- * Implements a clean 5-method API for complete transaction lifecycle management.
942
- *
943
- * Features:
944
- * - WebAuthn-based secure authentication
945
- * - 5-minute user session caching
946
- * - Automatic transaction data fetching
947
- * - Blockchain transaction signing and submission
948
- * - Multi-tenant support
949
- *
950
- * @class PersSignerSDK
951
- */
952
- declare class PersSignerSDK {
953
- private config;
954
- private authenticationService;
955
- private transactionSigningService;
956
- /**
957
- * Initialize the PERS Signer SDK
958
- *
959
- * @param {ExtendedPersSignerConfig} config - SDK configuration object
960
- * @throws {Error} If required configuration is missing
961
- */
962
- constructor(config: ExtendedPersSignerConfig);
963
- /**
964
- * Helper method to trigger both global and method-specific status callbacks
965
- * @private
966
- */
967
- private triggerStatusUpdate;
968
- /**
969
- * Authenticate user and cache session for 5 minutes
970
- *
971
- * Validates JWT token, authenticates with both signer and PERS backends,
972
- * and caches the authenticated user session to avoid repeated authentication.
973
- *
974
- * @param {string} jwtToken - JWT token containing user identifier and tenant info
975
- * @param {StatusCallback} [statusCallback] - Optional callback for status updates
976
- * @returns {Promise<AuthenticatedUser>} Authenticated user with access tokens
977
- * @throws {Error} If JWT is invalid, expired, or authentication fails
978
- *
979
- * @example
980
- * ```typescript
981
- * try {
982
- * const user = await sdk.loginUser(jwtToken, {
983
- * onStatusUpdate: (status, message) => console.log(`${status}: ${message}`)
984
- * });
985
- * console.log('Authenticated:', user.identifier);
986
- * } catch (error) {
987
- * console.error('Authentication failed:', error.message);
988
- * }
989
- * ```
990
- */
991
- loginUser(jwtToken: string, statusCallback?: StatusCallback): Promise<AuthenticatedUser>;
992
- /**
993
- * Sign a PERS transaction (legacy compatibility method)
994
- *
995
- * Automatically handles user authentication, transaction data fetching,
996
- * and transaction signing in a single call. This is the legacy method
997
- * maintained for backward compatibility.
998
- *
999
- * @param {string} jwtToken - JWT token containing transaction ID and user info
1000
- * @param {StatusCallback} [statusCallback] - Optional callback for status updates
1001
- * @returns {Promise<TransactionSigningResult>} Signing result with signature and metadata
1002
- * @throws {Error} If authentication fails, transaction ID missing, or signing fails
1003
- *
1004
- * @example
1005
- * ```typescript
1006
- * try {
1007
- * const result = await sdk.signPersTransaction(jwtToken, {
1008
- * onStatusUpdate: (status, message) => console.log(`${status}: ${message}`)
1009
- * });
1010
- * if (result.success) {
1011
- * console.log('Transaction signed:', result.signature);
1012
- * }
1013
- * } catch (error) {
1014
- * console.error('Signing failed:', error.message);
1015
- * }
1016
- * ```
1017
- */
1018
- signPersTransaction(jwtToken: string, statusCallback?: StatusCallback): Promise<TransactionSigningResult>;
1019
- /**
1020
- * Sign a transaction with provided signing data
1021
- *
1022
- * Low-level method to sign transactions when you already have the signing data.
1023
- * Automatically handles user authentication and applies the blockchain signature.
1024
- *
1025
- * @param {CounterfactualWalletTransactionResponse | LegacyTransaction} signingData - Transaction data to sign
1026
- * @param {string} jwtToken - JWT token containing transaction ID and user info
1027
- * @param {StatusCallback} [statusCallback] - Optional callback for status updates
1028
- * @returns {Promise<TransactionSigningResult>} Signing result with signature and metadata
1029
- * @throws {Error} If authentication fails, transaction ID missing, or signing fails
1030
- *
1031
- * @example
1032
- * ```typescript
1033
- * const signingData = await getTransactionData(transactionId);
1034
- * const result = await sdk.signTransaction(signingData, jwtToken, {
1035
- * onStatusUpdate: (status, message) => console.log(`${status}: ${message}`)
1036
- * });
1037
- * console.log('Signed transaction:', result.signature);
1038
- * ```
1039
- */
1040
- signTransaction(signingData: CounterfactualWalletTransactionResponse$1 | LegacyTransaction, jwtToken: string, statusCallback?: StatusCallback): Promise<TransactionSigningResult>;
1041
- /**
1042
- * Complete transaction flow: sign and submit in one call
1043
- *
1044
- * Convenience method that combines signing and submission into a single operation.
1045
- * This is the recommended method for most use cases as it handles the complete
1046
- * transaction lifecycle automatically.
1047
- *
1048
- * @param {string} jwtToken - JWT token containing transaction ID and user info
1049
- * @param {StatusCallback} [statusCallback] - Optional callback for status updates
1050
- * @returns {Promise<SubmissionResult>} Submission result with transaction hash and status
1051
- * @throws {Error} If authentication, signing, or submission fails
1052
- *
1053
- * @example
1054
- * ```typescript
1055
- * try {
1056
- * const result = await sdk.signAndSubmitPersTransaction(jwtToken, {
1057
- * onStatusUpdate: (status, message) => {
1058
- * console.log(`Status: ${status} - ${message}`);
1059
- * }
1060
- * });
1061
- * if (result.success) {
1062
- * console.log('Transaction completed:', result.transactionHash);
1063
- * if (result.shouldRedirect) {
1064
- * window.location.href = result.redirectUrl;
1065
- * }
1066
- * }
1067
- * } catch (error) {
1068
- * console.error('Transaction failed:', error.message);
1069
- * }
1070
- * ```
1071
- */
1072
- signAndSubmitPersTransaction(jwtToken: string, statusCallback?: StatusCallback): Promise<SubmissionResult>;
1073
- /**
1074
- * Submit a signed transaction to the blockchain
1075
- *
1076
- * Takes a signed transaction result and submits it to the blockchain network.
1077
- * Returns detailed submission results including transaction hash and any
1078
- * redirect information for UI flows.
1079
- *
1080
- * @param {TransactionSigningResult} signingResult - Result from a successful transaction signing
1081
- * @param {string} jwtToken - JWT token containing tenant and user info
1082
- * @param {StatusCallback} [statusCallback] - Optional callback for status updates
1083
- * @returns {Promise<SubmissionResult>} Submission result with transaction hash and status
1084
- * @throws {Error} If signing result is invalid, JWT is missing tenantId, or submission fails
1085
- *
1086
- * @example
1087
- * ```typescript
1088
- * const signedTx = await sdk.signPersTransaction(jwtToken);
1089
- * const result = await sdk.submitTransaction(signedTx, jwtToken, {
1090
- * onStatusUpdate: (status, message) => console.log(`${status}: ${message}`)
1091
- * });
1092
- * console.log('Transaction submitted:', result.transactionHash);
1093
- * ```
1094
- */
1095
- submitTransaction(signingResult: TransactionSigningResult, jwtToken: string, statusCallback?: StatusCallback): Promise<SubmissionResult>;
1096
- /**
1097
- * Clear user authentication cache
1098
- *
1099
- * Removes all cached user sessions, forcing fresh authentication
1100
- * on the next method call. Useful for logout scenarios or when
1101
- * switching between different user contexts.
1102
- *
1103
- * @example
1104
- * ```typescript
1105
- * // Clear cache on user logout
1106
- * sdk.clearCache();
1107
- * console.log('User cache cleared');
1108
- * ```
1109
- */
1110
- clearCache(): void;
1111
- }
1112
- /**
1113
- * Create a new PERS Signer SDK instance
1114
- *
1115
- * Factory function to create and configure a new SDK instance with the provided
1116
- * configuration. This is the recommended way to initialize the SDK.
1117
- *
1118
- * @param {PersSignerConfig} config - SDK configuration object
1119
- * @returns {PersSignerSDK} Configured SDK instance ready for use
1120
- * @throws {Error} If required configuration is missing or invalid
1121
- *
1122
- * @example
1123
- * ```typescript
1124
- * import { createPersSignerSDK, getWebAuthnProvider } from '@explorins/pers-signer';
1125
- *
1126
- * const webAuthnProvider = await getWebAuthnProvider();
1127
- * const sdk = createPersSignerSDK({
1128
- * webAuthnProvider,
1129
- * ethersProviderUrl: 'https://mainnet.infura.io/v3/YOUR_KEY',
1130
- * tenantId: 'your-tenant-id'
1131
- * });
1132
- * ```
1133
- */
1134
- declare function createPersSignerSDK(config: ExtendedPersSignerConfig): PersSignerSDK;
1135
-
1136
- /**
1137
- * Authentication service for user login and registration
1138
- * Uses constructor-based dependency injection for WebAuthn provider
1139
- * Updated for new v1 API endpoints
1140
- */
1141
- declare class AuthenticationService {
1142
- private signerToken;
1143
- private webAuthnProvider;
1144
- constructor(config: ExtendedPersSignerConfig);
1145
- /**
1146
- * Login with PERS token to get signer JWT
1147
- * @param persToken - PERS JWT from PERS authentication
1148
- * @returns Promise resolving to login response or provider challenge data
1149
- */
1150
- loginWithPersToken(persToken: string): Promise<JWTLoginResponse | unknown>;
1151
- /**
1152
- * Verify signer token validity
1153
- * @param token - Signer JWT to verify
1154
- * @returns Promise resolving to verification result
1155
- */
1156
- verifyToken(token: string): Promise<VerifyTokenResponse>;
1157
- /**
1158
- * Register user with unified flow
1159
- * @param persToken - PERS JWT token
1160
- * @returns Promise resolving to authenticated user data
1161
- */
1162
- registerUser(persToken: string): Promise<JWTLoginResponse>;
1163
- /**
1164
- * Get current signer token
1165
- * @returns The current signer JWT token
1166
- */
1167
- getSignerToken(): string | null;
1168
- /**
1169
- * Set signer token (for external token management)
1170
- * @param token - Signer JWT token
1171
- */
1172
- setSignerToken(token: string): void;
1173
- /**
1174
- * Combined authentication flow - handles both login and registration
1175
- * @param identifier - User identifier (email/userId)
1176
- * @param persAccessToken - PERS JWT token for authentication
1177
- * @param webAuthnProvider - WebAuthn provider for credential creation
1178
- * @param relyingPartyConfig - Configuration for WebAuthn relying party
1179
- * @returns Promise resolving to authenticated user with signer token
1180
- */
1181
- combinedAuthentication(identifier: string, persAccessToken: string): Promise<AuthenticatedUser>;
1182
- }
1183
-
1184
- /**
1185
- * Health check service for signer API
1186
- * Handles health check operations for the new v1 API
1187
- */
1188
- declare class HealthService {
1189
- /**
1190
- * Perform health check on the signer API
1191
- * @returns Promise resolving to health check result
1192
- */
1193
- static checkHealth(): Promise<HealthCheckResponse>;
1194
- }
1195
-
1196
1188
  /**
1197
1189
  * Browser-specific WebAuthn provider using native browser APIs
1198
1190
  * Fully agnostic implementation without external SDK dependencies
@@ -1294,4 +1286,4 @@ declare class UserCache {
1294
1286
  }
1295
1287
 
1296
1288
  export { AuthenticationService, FetchHttpClient, HealthService, KeyWallet, PersService, PersSignerSDK, ReactNativeConfigProvider, SIGNABLE_STATUSES, SigningService, SigningStatus, StaticConfigProvider, TransactionErrorHandler, TransactionSigningErrorCode, TransactionSigningService, TransactionSubmissionHandler, TransactionValidator, UserCache, WalletService, WebAuthnCoordinator, WebConfigProvider, createPersSignerSDK, extractJWTFromToken, getBrowserWebAuthnProvider, getConfigProvider, getHttpClient, getJWTPayload, getReactNativeWebAuthnProvider, getServiceConfig, isJWTExpired, setConfigProvider, setHttpClient };
1297
- export type { AuthResponse, AuthenticatedUser, CombinedTransactionStatus, CompleteSignatureResponse, ConfigProvider, HashSigningRequest, HealthCheckResponse, HttpClient, HttpRequestOptions, HttpResponse, JWTExtractionResult, JWTPayload, ListWalletsRequest, ListWalletsResponse, LoginRequest, LoginResponse, PersSignerConfig, RegistrationChallenge, RegistrationResult, RelyingPartyConfig, ServiceError, SignResponse, SignerApiError, SignerApiResponse, SigningAuthTokens, SigningChallenge, SigningRequest, StatusCallback, StatusUpdateData, SubmissionResult, TransactionSigningError, TransactionSigningParams, TransactionSigningResult, TransactionStatusInfo, TypedDataSigningRequest, UserCredentials, VerifyTokenRequest, VerifyTokenResponse, WalletItem, WalletListResponse, WebAuthnConfig, WebAuthnProvider };
1289
+ export type { AuthResponse, AuthenticatedUser, CombinedTransactionStatus, CompleteSignatureResponse, ConfigProvider, ExtendedPersSignerConfig, HashSigningRequest, HealthCheckResponse, HttpClient, HttpRequestOptions, HttpResponse, JWTExtractionResult, JWTPayload, ListWalletsRequest, ListWalletsResponse, LoginRequest, LoginResponse, PersSignerConfig, RegistrationChallenge, RegistrationResult, RelyingPartyConfig, ServiceError, SignResponse, SignerApiError, SignerApiResponse, SigningAuthTokens, SigningChallenge, SigningRequest, StatusCallback, StatusUpdateData, SubmissionResult, TransactionSigningError, TransactionSigningParams, TransactionSigningResult, TransactionStatusInfo, TypedDataSigningRequest, UserCredentials, VerifyTokenRequest, VerifyTokenResponse, WalletItem, WalletListResponse, WebAuthnConfig, WebAuthnProvider };