@explorins/pers-signer 1.0.16 → 1.0.17

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/browser.d.ts CHANGED
@@ -479,6 +479,207 @@ interface TransactionSigningParams {
479
479
  returnUrl?: string;
480
480
  }
481
481
 
482
+ /**
483
+ * PERS Blockchain Signer SDK
484
+ *
485
+ * A lightweight blockchain transaction signing SDK with WebAuthn authentication.
486
+ * Provides 5 focused methods for complete transaction lifecycle management:
487
+ *
488
+ * 1. loginUser(jwtToken) - Authenticate user with 5-minute caching
489
+ * 2. signTransaction(signingData, jwtToken) - Sign transactions with auto-login
490
+ * 3. submitTransaction(signedTx, jwtToken) - Submit signed transactions to blockchain
491
+ * 4. signPersTransaction(jwtToken) - Legacy one-liner for backward compatibility
492
+ * 5. signAndSubmitPersTransaction(jwtToken) - Complete sign + submit flow
493
+ *
494
+ * @example
495
+ * ```typescript
496
+ * import { createPersSignerSDK } from '@explorins/pers-signer';
497
+ *
498
+ * const sdk = createPersSignerSDK({
499
+ * webAuthnProvider: myWebAuthnProvider,
500
+ * ethersProviderUrl: 'https://ethereum-rpc.com'
501
+ * });
502
+ *
503
+ * // Quick sign and submit
504
+ * const result = await sdk.signAndSubmitPersTransaction(jwtToken);
505
+ * if (result.success) {
506
+ * console.log('Transaction submitted:', result.transactionHash);
507
+ * }
508
+ * ```
509
+ */
510
+
511
+ /**
512
+ * Configuration interface for the PERS Signer SDK
513
+ *
514
+ * @interface PersSignerConfig
515
+ * @property {string} [tenantId] - Optional tenant identifier for multi-tenant applications
516
+ * @property {string} [ethersProviderUrl] - Custom Ethereum RPC provider URL
517
+ * @property {WebAuthnProvider} webAuthnProvider - WebAuthn provider for secure authentication
518
+ * @property {string} [apiUrl] - Custom API base URL (defaults to production)
519
+ * @property {string} [relyingPartyName] - WebAuthn relying party name for authentication
520
+ */
521
+ interface ExtendedPersSignerConfig {
522
+ ethersProviderUrl?: string;
523
+ webAuthnProvider: WebAuthnProvider;
524
+ apiUrl?: string;
525
+ relyingPartyName?: string;
526
+ }
527
+ interface PersSignerConfig extends Omit<ExtendedPersSignerConfig, 'webAuthnProvider'> {
528
+ }
529
+ /**
530
+ * PERS Blockchain Signer SDK Class
531
+ *
532
+ * Main SDK class providing blockchain transaction signing capabilities with WebAuthn authentication.
533
+ * Implements a clean 5-method API for complete transaction lifecycle management.
534
+ *
535
+ * Features:
536
+ * - WebAuthn-based secure authentication
537
+ * - 5-minute user session caching
538
+ * - Automatic transaction data fetching
539
+ * - Blockchain transaction signing and submission
540
+ * - Multi-tenant support
541
+ *
542
+ * @class PersSignerSDK
543
+ */
544
+ declare class PersSignerSDK {
545
+ private config;
546
+ private authenticationService;
547
+ private transactionSigningService;
548
+ /**
549
+ * Initialize the PERS Signer SDK
550
+ *
551
+ * @param {ExtendedPersSignerConfig} config - SDK configuration object
552
+ * @throws {Error} If required configuration is missing
553
+ */
554
+ constructor(config: ExtendedPersSignerConfig);
555
+ /**
556
+ * Authenticate user and cache session for 5 minutes
557
+ *
558
+ * Validates JWT token, authenticates with both signer and PERS backends,
559
+ * and caches the authenticated user session to avoid repeated authentication.
560
+ *
561
+ * @param {string} jwtToken - JWT token containing user identifier and tenant info
562
+ * @returns {Promise<AuthenticatedUser>} Authenticated user with access tokens
563
+ * @throws {Error} If JWT is invalid, expired, or authentication fails
564
+ *
565
+ * @example
566
+ * ```typescript
567
+ * try {
568
+ * const user = await sdk.loginUser(jwtToken);
569
+ * console.log('Authenticated:', user.identifier);
570
+ * } catch (error) {
571
+ * console.error('Authentication failed:', error.message);
572
+ * }
573
+ * ```
574
+ */
575
+ loginUser(jwtToken: string): Promise<AuthenticatedUser>;
576
+ /**
577
+ * Sign a PERS transaction (legacy compatibility method)
578
+ *
579
+ * Automatically handles user authentication, transaction data fetching,
580
+ * and transaction signing in a single call. This is the legacy method
581
+ * maintained for backward compatibility.
582
+ *
583
+ * @param {string} jwtToken - JWT token containing transaction ID and user info
584
+ * @returns {Promise<TransactionSigningResult>} Signing result with signature and metadata
585
+ * @throws {Error} If authentication fails, transaction ID missing, or signing fails
586
+ *
587
+ * @example
588
+ * ```typescript
589
+ * try {
590
+ * const result = await sdk.signPersTransaction(jwtToken);
591
+ * if (result.success) {
592
+ * console.log('Transaction signed:', result.signature);
593
+ * }
594
+ * } catch (error) {
595
+ * console.error('Signing failed:', error.message);
596
+ * }
597
+ * ```
598
+ */
599
+ signPersTransaction(jwtToken: string): Promise<TransactionSigningResult>;
600
+ /**
601
+ * Sign a transaction with provided signing data
602
+ *
603
+ * Low-level method to sign transactions when you already have the signing data.
604
+ * Automatically handles user authentication and applies the blockchain signature.
605
+ *
606
+ * @param {CounterfactualWalletTransactionResponse | LegacyTransaction} signingData - Transaction data to sign
607
+ * @param {string} jwtToken - JWT token containing transaction ID and user info
608
+ * @returns {Promise<TransactionSigningResult>} Signing result with signature and metadata
609
+ * @throws {Error} If authentication fails, transaction ID missing, or signing fails
610
+ *
611
+ * @example
612
+ * ```typescript
613
+ * const signingData = await getTransactionData(transactionId);
614
+ * const result = await sdk.signTransaction(signingData, jwtToken);
615
+ * console.log('Signed transaction:', result.signature);
616
+ * ```
617
+ */
618
+ signTransaction(signingData: CounterfactualWalletTransactionResponse$1 | LegacyTransaction, jwtToken: string): Promise<TransactionSigningResult>;
619
+ /**
620
+ * Complete transaction flow: sign and submit in one call
621
+ *
622
+ * Convenience method that combines signing and submission into a single operation.
623
+ * This is the recommended method for most use cases as it handles the complete
624
+ * transaction lifecycle automatically.
625
+ *
626
+ * @param {string} jwtToken - JWT token containing transaction ID and user info
627
+ * @returns {Promise<SubmissionResult>} Submission result with transaction hash and status
628
+ * @throws {Error} If authentication, signing, or submission fails
629
+ *
630
+ * @example
631
+ * ```typescript
632
+ * try {
633
+ * const result = await sdk.signAndSubmitPersTransaction(jwtToken);
634
+ * if (result.success) {
635
+ * console.log('Transaction completed:', result.transactionHash);
636
+ * if (result.shouldRedirect) {
637
+ * window.location.href = result.redirectUrl;
638
+ * }
639
+ * }
640
+ * } catch (error) {
641
+ * console.error('Transaction failed:', error.message);
642
+ * }
643
+ * ```
644
+ */
645
+ signAndSubmitPersTransaction(jwtToken: string): Promise<SubmissionResult>;
646
+ /**
647
+ * Submit a signed transaction to the blockchain
648
+ *
649
+ * Takes a signed transaction result and submits it to the blockchain network.
650
+ * Returns detailed submission results including transaction hash and any
651
+ * redirect information for UI flows.
652
+ *
653
+ * @param {TransactionSigningResult} signingResult - Result from a successful transaction signing
654
+ * @param {string} jwtToken - JWT token containing tenant and user info
655
+ * @returns {Promise<SubmissionResult>} Submission result with transaction hash and status
656
+ * @throws {Error} If signing result is invalid, JWT is missing tenantId, or submission fails
657
+ *
658
+ * @example
659
+ * ```typescript
660
+ * const signedTx = await sdk.signPersTransaction(jwtToken);
661
+ * const result = await sdk.submitTransaction(signedTx, jwtToken);
662
+ * console.log('Transaction submitted:', result.transactionHash);
663
+ * ```
664
+ */
665
+ submitTransaction(signingResult: TransactionSigningResult, jwtToken: string): Promise<SubmissionResult>;
666
+ /**
667
+ * Clear user authentication cache
668
+ *
669
+ * Removes all cached user sessions, forcing fresh authentication
670
+ * on the next method call. Useful for logout scenarios or when
671
+ * switching between different user contexts.
672
+ *
673
+ * @example
674
+ * ```typescript
675
+ * // Clear cache on user logout
676
+ * sdk.clearCache();
677
+ * console.log('User cache cleared');
678
+ * ```
679
+ */
680
+ clearCache(): void;
681
+ }
682
+
482
683
  /**
483
684
  * Service for orchestrating transaction signing operations
484
685
  * Handles the complete flow from transaction preparation to submission
@@ -486,7 +687,7 @@ interface TransactionSigningParams {
486
687
  */
487
688
  declare class TransactionSigningService {
488
689
  private webAuthnProvider;
489
- constructor(config: PersSignerConfig);
690
+ constructor(config: ExtendedPersSignerConfig);
490
691
  /**
491
692
  * Prepare transaction for signing - fetch and validate
492
693
  */
@@ -749,206 +950,6 @@ declare function setHttpClient(client: HttpClient): void;
749
950
  */
750
951
  declare function getHttpClient(): HttpClient;
751
952
 
752
- /**
753
- * PERS Blockchain Signer SDK
754
- *
755
- * A lightweight blockchain transaction signing SDK with WebAuthn authentication.
756
- * Provides 5 focused methods for complete transaction lifecycle management:
757
- *
758
- * 1. loginUser(jwtToken) - Authenticate user with 5-minute caching
759
- * 2. signTransaction(signingData, jwtToken) - Sign transactions with auto-login
760
- * 3. submitTransaction(signedTx, jwtToken) - Submit signed transactions to blockchain
761
- * 4. signPersTransaction(jwtToken) - Legacy one-liner for backward compatibility
762
- * 5. signAndSubmitPersTransaction(jwtToken) - Complete sign + submit flow
763
- *
764
- * @example
765
- * ```typescript
766
- * import { createPersSignerSDK } from '@explorins/pers-signer';
767
- *
768
- * const sdk = createPersSignerSDK({
769
- * webAuthnProvider: myWebAuthnProvider,
770
- * ethersProviderUrl: 'https://ethereum-rpc.com'
771
- * });
772
- *
773
- * // Quick sign and submit
774
- * const result = await sdk.signAndSubmitPersTransaction(jwtToken);
775
- * if (result.success) {
776
- * console.log('Transaction submitted:', result.transactionHash);
777
- * }
778
- * ```
779
- */
780
-
781
- /**
782
- * Configuration interface for the PERS Signer SDK
783
- *
784
- * @interface PersSignerConfig
785
- * @property {string} [tenantId] - Optional tenant identifier for multi-tenant applications
786
- * @property {string} [ethersProviderUrl] - Custom Ethereum RPC provider URL
787
- * @property {WebAuthnProvider} webAuthnProvider - WebAuthn provider for secure authentication
788
- * @property {string} [apiUrl] - Custom API base URL (defaults to production)
789
- * @property {string} [relyingPartyName] - WebAuthn relying party name for authentication
790
- */
791
- interface PersSignerConfig {
792
- tenantId?: string;
793
- ethersProviderUrl?: string;
794
- webAuthnProvider: WebAuthnProvider;
795
- apiUrl?: string;
796
- relyingPartyName?: string;
797
- }
798
- /**
799
- * PERS Blockchain Signer SDK Class
800
- *
801
- * Main SDK class providing blockchain transaction signing capabilities with WebAuthn authentication.
802
- * Implements a clean 5-method API for complete transaction lifecycle management.
803
- *
804
- * Features:
805
- * - WebAuthn-based secure authentication
806
- * - 5-minute user session caching
807
- * - Automatic transaction data fetching
808
- * - Blockchain transaction signing and submission
809
- * - Multi-tenant support
810
- *
811
- * @class PersSignerSDK
812
- */
813
- declare class PersSignerSDK {
814
- private config;
815
- private authenticationService;
816
- private transactionSigningService;
817
- /**
818
- * Initialize the PERS Signer SDK
819
- *
820
- * @param {PersSignerConfig} config - SDK configuration object
821
- * @throws {Error} If required configuration is missing
822
- */
823
- constructor(config: PersSignerConfig);
824
- /**
825
- * Authenticate user and cache session for 5 minutes
826
- *
827
- * Validates JWT token, authenticates with both signer and PERS backends,
828
- * and caches the authenticated user session to avoid repeated authentication.
829
- *
830
- * @param {string} jwtToken - JWT token containing user identifier and tenant info
831
- * @returns {Promise<AuthenticatedUser>} Authenticated user with access tokens
832
- * @throws {Error} If JWT is invalid, expired, or authentication fails
833
- *
834
- * @example
835
- * ```typescript
836
- * try {
837
- * const user = await sdk.loginUser(jwtToken);
838
- * console.log('Authenticated:', user.identifier);
839
- * } catch (error) {
840
- * console.error('Authentication failed:', error.message);
841
- * }
842
- * ```
843
- */
844
- loginUser(jwtToken: string): Promise<AuthenticatedUser>;
845
- /**
846
- * Sign a PERS transaction (legacy compatibility method)
847
- *
848
- * Automatically handles user authentication, transaction data fetching,
849
- * and transaction signing in a single call. This is the legacy method
850
- * maintained for backward compatibility.
851
- *
852
- * @param {string} jwtToken - JWT token containing transaction ID and user info
853
- * @returns {Promise<TransactionSigningResult>} Signing result with signature and metadata
854
- * @throws {Error} If authentication fails, transaction ID missing, or signing fails
855
- *
856
- * @example
857
- * ```typescript
858
- * try {
859
- * const result = await sdk.signPersTransaction(jwtToken);
860
- * if (result.success) {
861
- * console.log('Transaction signed:', result.signature);
862
- * }
863
- * } catch (error) {
864
- * console.error('Signing failed:', error.message);
865
- * }
866
- * ```
867
- */
868
- signPersTransaction(jwtToken: string): Promise<TransactionSigningResult>;
869
- /**
870
- * Sign a transaction with provided signing data
871
- *
872
- * Low-level method to sign transactions when you already have the signing data.
873
- * Automatically handles user authentication and applies the blockchain signature.
874
- *
875
- * @param {CounterfactualWalletTransactionResponse | LegacyTransaction} signingData - Transaction data to sign
876
- * @param {string} jwtToken - JWT token containing transaction ID and user info
877
- * @returns {Promise<TransactionSigningResult>} Signing result with signature and metadata
878
- * @throws {Error} If authentication fails, transaction ID missing, or signing fails
879
- *
880
- * @example
881
- * ```typescript
882
- * const signingData = await getTransactionData(transactionId);
883
- * const result = await sdk.signTransaction(signingData, jwtToken);
884
- * console.log('Signed transaction:', result.signature);
885
- * ```
886
- */
887
- signTransaction(signingData: CounterfactualWalletTransactionResponse$1 | LegacyTransaction, jwtToken: string): Promise<TransactionSigningResult>;
888
- /**
889
- * Complete transaction flow: sign and submit in one call
890
- *
891
- * Convenience method that combines signing and submission into a single operation.
892
- * This is the recommended method for most use cases as it handles the complete
893
- * transaction lifecycle automatically.
894
- *
895
- * @param {string} jwtToken - JWT token containing transaction ID and user info
896
- * @returns {Promise<SubmissionResult>} Submission result with transaction hash and status
897
- * @throws {Error} If authentication, signing, or submission fails
898
- *
899
- * @example
900
- * ```typescript
901
- * try {
902
- * const result = await sdk.signAndSubmitPersTransaction(jwtToken);
903
- * if (result.success) {
904
- * console.log('Transaction completed:', result.transactionHash);
905
- * if (result.shouldRedirect) {
906
- * window.location.href = result.redirectUrl;
907
- * }
908
- * }
909
- * } catch (error) {
910
- * console.error('Transaction failed:', error.message);
911
- * }
912
- * ```
913
- */
914
- signAndSubmitPersTransaction(jwtToken: string): Promise<SubmissionResult>;
915
- /**
916
- * Submit a signed transaction to the blockchain
917
- *
918
- * Takes a signed transaction result and submits it to the blockchain network.
919
- * Returns detailed submission results including transaction hash and any
920
- * redirect information for UI flows.
921
- *
922
- * @param {TransactionSigningResult} signingResult - Result from a successful transaction signing
923
- * @param {string} jwtToken - JWT token containing tenant and user info
924
- * @returns {Promise<SubmissionResult>} Submission result with transaction hash and status
925
- * @throws {Error} If signing result is invalid, JWT is missing tenantId, or submission fails
926
- *
927
- * @example
928
- * ```typescript
929
- * const signedTx = await sdk.signPersTransaction(jwtToken);
930
- * const result = await sdk.submitTransaction(signedTx, jwtToken);
931
- * console.log('Transaction submitted:', result.transactionHash);
932
- * ```
933
- */
934
- submitTransaction(signingResult: TransactionSigningResult, jwtToken: string): Promise<SubmissionResult>;
935
- /**
936
- * Clear user authentication cache
937
- *
938
- * Removes all cached user sessions, forcing fresh authentication
939
- * on the next method call. Useful for logout scenarios or when
940
- * switching between different user contexts.
941
- *
942
- * @example
943
- * ```typescript
944
- * // Clear cache on user logout
945
- * sdk.clearCache();
946
- * console.log('User cache cleared');
947
- * ```
948
- */
949
- clearCache(): void;
950
- }
951
-
952
953
  /**
953
954
  * Wallet list response from WalletService
954
955
  */
@@ -988,7 +989,7 @@ declare class AuthenticationService {
988
989
  private signerToken;
989
990
  private config;
990
991
  private webAuthnProvider;
991
- constructor(config: PersSignerConfig);
992
+ constructor(config: ExtendedPersSignerConfig);
992
993
  /**
993
994
  * Login with PERS token to get signer JWT
994
995
  * @param persToken - PERS JWT from PERS authentication
@@ -1054,7 +1055,7 @@ declare function getBrowserWebAuthnProvider(): Promise<WebAuthnProvider>;
1054
1055
  * Create a new PersSignerSDK instance with browser WebAuthn provider
1055
1056
  * @param config - SDK configuration (ethersProviderUrl is required)
1056
1057
  */
1057
- declare function createPersSignerSDK(config: Omit<PersSignerConfig, 'webAuthnProvider'>): Promise<PersSignerSDK>;
1058
+ declare function createPersSignerSDK(config: PersSignerConfig): Promise<PersSignerSDK>;
1058
1059
 
1059
1060
  export { AuthenticationService, FetchHttpClient, KeyWallet, PersService, PersSignerSDK, ReactNativeConfigProvider, SIGNABLE_STATUSES, SigningService, StaticConfigProvider, TransactionErrorHandler, TransactionSigningErrorCode, TransactionSigningService, TransactionSubmissionHandler, TransactionValidator, WalletService, WebAuthnCoordinator, WebConfigProvider, createPersSignerSDK, getBrowserWebAuthnProvider, getConfigProvider, getHttpClient, getServiceConfig, getBrowserWebAuthnProvider as getWebAuthnProvider, setConfigProvider, setHttpClient };
1060
1061
  export type { AuthResponse, AuthenticatedUser, CombinedTransactionStatus, ConfigProvider, HashSigningRequest, HttpClient, HttpRequestOptions, HttpResponse, PersSignerConfig, PlatformConfig, RegistrationChallenge, RegistrationResult, RelyingPartyConfig, ServiceConfig, ServiceError, SignResponse, SigningAuthTokens, SigningChallenge, SigningRequest, SubmissionResult, TransactionSigningError, TransactionSigningParams, TransactionSigningResult, TransactionStatusInfo, TypedDataSigningRequest, UserCredentials, WalletItem, WalletListResponse, WebAuthnConfig, WebAuthnProvider };
@@ -1737,7 +1737,7 @@ class PersSignerSDK {
1737
1737
  /**
1738
1738
  * Initialize the PERS Signer SDK
1739
1739
  *
1740
- * @param {PersSignerConfig} config - SDK configuration object
1740
+ * @param {ExtendedPersSignerConfig} config - SDK configuration object
1741
1741
  * @throws {Error} If required configuration is missing
1742
1742
  */
1743
1743
  constructor(config) {
@@ -1782,7 +1782,7 @@ class PersSignerSDK {
1782
1782
  throw new Error('Invalid or expired JWT token');
1783
1783
  }
1784
1784
  const identifier = payload.identifierEmail || payload.email || payload.userId;
1785
- const tenantId = payload.tenantId || this.config.tenantId || '';
1785
+ const tenantId = payload.tenantId || '';
1786
1786
  if (!identifier) {
1787
1787
  throw new Error('JWT token missing user identifier (identifierEmail, email, or userId)');
1788
1788
  }