@passkeyme/auth 2.0.1 → 2.0.2

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.esm.js CHANGED
@@ -449,6 +449,179 @@ class PasskeymeApiClient {
449
449
  }
450
450
  }
451
451
 
452
+ /**
453
+ * Platform SDK Interface for Passkeyme
454
+ *
455
+ * This interface abstracts platform-specific passkey operations,
456
+ * allowing the core SDK to work across web, React Native, and other platforms.
457
+ */
458
+ /**
459
+ * No-op implementation for platforms without passkey support
460
+ */
461
+ class NoOpPasskeySDK {
462
+ async register(_options) {
463
+ return {
464
+ success: false,
465
+ error: "Passkeys not supported on this platform",
466
+ };
467
+ }
468
+ async authenticate(_options) {
469
+ return {
470
+ success: false,
471
+ error: "Passkeys not supported on this platform",
472
+ };
473
+ }
474
+ isSupported() {
475
+ return false;
476
+ }
477
+ canUseDiscoverableCredentials() {
478
+ return false;
479
+ }
480
+ supportsBiometrics() {
481
+ return false;
482
+ }
483
+ }
484
+
485
+ /**
486
+ * Web Platform SDK Implementation
487
+ *
488
+ * Wraps the passkeyme-web-sdk to implement the PasskeySDK interface
489
+ */
490
+ /**
491
+ * Web implementation of PasskeySDK using passkeyme-web-sdk
492
+ *
493
+ * This implementation should be used for web browsers that support WebAuthn.
494
+ * The actual passkeyme-web-sdk dependency should be provided by the consuming package.
495
+ */
496
+ class WebPasskeySDK {
497
+ constructor(webSDK) {
498
+ this.webSDK = webSDK;
499
+ }
500
+ async register(options) {
501
+ try {
502
+ if (!this.webSDK) {
503
+ return {
504
+ success: false,
505
+ error: "Web SDK not available",
506
+ };
507
+ }
508
+ // Extract the challenge from the options
509
+ // The options object contains: { username, displayName, challenge, ...otherChallengeData }
510
+ const { username, displayName, challenge, ...otherData } = options;
511
+ // Pass the challenge data directly to the web SDK
512
+ const challengeData = challenge || otherData;
513
+ // Call the web SDK register method with the challenge
514
+ const result = await this.webSDK.passkeyRegister(challengeData);
515
+ return {
516
+ success: true,
517
+ credentialId: result.credentialId || result.id,
518
+ data: result,
519
+ };
520
+ }
521
+ catch (error) {
522
+ return {
523
+ success: false,
524
+ error: error.message || "Registration failed",
525
+ };
526
+ }
527
+ }
528
+ async authenticate(options) {
529
+ try {
530
+ if (!this.webSDK) {
531
+ return {
532
+ success: false,
533
+ error: "Web SDK not available",
534
+ };
535
+ }
536
+ // Extract the challenge from the options
537
+ // The options object contains: { username, challenge, ...otherChallengeData }
538
+ const { username, challenge, ...otherData } = options;
539
+ // Pass the challenge data directly to the web SDK
540
+ const challengeData = challenge || otherData;
541
+ // Call the web SDK authenticate method with the challenge
542
+ const result = await this.webSDK.passkeyAuthenticate(challengeData);
543
+ return {
544
+ success: true,
545
+ assertion: result,
546
+ data: result,
547
+ };
548
+ }
549
+ catch (error) {
550
+ return {
551
+ success: false,
552
+ error: error.message || "Authentication failed",
553
+ };
554
+ }
555
+ }
556
+ isSupported() {
557
+ // Check if we're in a browser environment with WebAuthn support
558
+ return (typeof window !== "undefined" &&
559
+ typeof navigator !== "undefined" &&
560
+ "credentials" in navigator &&
561
+ typeof navigator.credentials.create === "function");
562
+ }
563
+ async getAvailableAuthenticators() {
564
+ // This is a basic implementation - the web SDK might provide more detailed info
565
+ const authenticators = [];
566
+ if (this.isSupported()) {
567
+ // Basic platform authenticator info
568
+ authenticators.push({
569
+ type: "platform",
570
+ supportsBiometrics: true, // Assume platform authenticators support biometrics
571
+ supportsUserVerification: true,
572
+ });
573
+ // Basic cross-platform authenticator info
574
+ authenticators.push({
575
+ type: "cross-platform",
576
+ supportsBiometrics: false,
577
+ supportsUserVerification: true,
578
+ });
579
+ }
580
+ return authenticators;
581
+ }
582
+ canUseDiscoverableCredentials() {
583
+ // Check if the platform supports discoverable credentials (resident keys)
584
+ return this.isSupported();
585
+ }
586
+ supportsBiometrics() {
587
+ // On web, this depends on the platform authenticator availability
588
+ // This is a simplified check - a more sophisticated implementation
589
+ // would actually test for platform authenticator support
590
+ return (this.isSupported() &&
591
+ typeof window !== "undefined" &&
592
+ /Mac|Win|Linux/.test(navigator.platform));
593
+ }
594
+ async initialize(config) {
595
+ // Initialize the web SDK if it has an init method
596
+ if (this.webSDK && typeof this.webSDK.init === "function") {
597
+ await this.webSDK.init(config);
598
+ }
599
+ }
600
+ async cleanup() {
601
+ // Cleanup if the web SDK has a cleanup method
602
+ if (this.webSDK && typeof this.webSDK.cleanup === "function") {
603
+ await this.webSDK.cleanup();
604
+ }
605
+ }
606
+ }
607
+
608
+ /**
609
+ * Platform SDK exports
610
+ */
611
+ // Conditionally export React Native SDK only in React Native environments
612
+ let ReactNativePasskeySDK = null;
613
+ try {
614
+ // Only try to load React Native SDK if we're actually in a React Native environment
615
+ if (typeof navigator !== "undefined" && navigator.product === "ReactNative") {
616
+ const { ReactNativePasskeySDK: RNPasskeySDK, } = require("./ReactNativePasskeySDK");
617
+ ReactNativePasskeySDK = RNPasskeySDK;
618
+ }
619
+ }
620
+ catch (error) {
621
+ // React Native SDK not available or not in React Native environment
622
+ ReactNativePasskeySDK = null;
623
+ }
624
+
452
625
  /**
453
626
  * Browser storage implementation using localStorage or sessionStorage
454
627
  */
@@ -625,179 +798,6 @@ TokenStorage.REFRESH_TOKEN_KEY = "passkeyme_refresh_token";
625
798
  TokenStorage.EXPIRES_AT_KEY = "passkeyme_expires_at";
626
799
  TokenStorage.TOKEN_TYPE_KEY = "passkeyme_token_type";
627
800
 
628
- /**
629
- * Platform SDK Interface for Passkeyme
630
- *
631
- * This interface abstracts platform-specific passkey operations,
632
- * allowing the core SDK to work across web, React Native, and other platforms.
633
- */
634
- /**
635
- * No-op implementation for platforms without passkey support
636
- */
637
- class NoOpPasskeySDK {
638
- async register(_options) {
639
- return {
640
- success: false,
641
- error: "Passkeys not supported on this platform",
642
- };
643
- }
644
- async authenticate(_options) {
645
- return {
646
- success: false,
647
- error: "Passkeys not supported on this platform",
648
- };
649
- }
650
- isSupported() {
651
- return false;
652
- }
653
- canUseDiscoverableCredentials() {
654
- return false;
655
- }
656
- supportsBiometrics() {
657
- return false;
658
- }
659
- }
660
-
661
- /**
662
- * Web Platform SDK Implementation
663
- *
664
- * Wraps the passkeyme-web-sdk to implement the PasskeySDK interface
665
- */
666
- /**
667
- * Web implementation of PasskeySDK using passkeyme-web-sdk
668
- *
669
- * This implementation should be used for web browsers that support WebAuthn.
670
- * The actual passkeyme-web-sdk dependency should be provided by the consuming package.
671
- */
672
- class WebPasskeySDK {
673
- constructor(webSDK) {
674
- this.webSDK = webSDK;
675
- }
676
- async register(options) {
677
- try {
678
- if (!this.webSDK) {
679
- return {
680
- success: false,
681
- error: "Web SDK not available",
682
- };
683
- }
684
- // Extract the challenge from the options
685
- // The options object contains: { username, displayName, challenge, ...otherChallengeData }
686
- const { username, displayName, challenge, ...otherData } = options;
687
- // Pass the challenge data directly to the web SDK
688
- const challengeData = challenge || otherData;
689
- // Call the web SDK register method with the challenge
690
- const result = await this.webSDK.passkeyRegister(challengeData);
691
- return {
692
- success: true,
693
- credentialId: result.credentialId || result.id,
694
- data: result,
695
- };
696
- }
697
- catch (error) {
698
- return {
699
- success: false,
700
- error: error.message || "Registration failed",
701
- };
702
- }
703
- }
704
- async authenticate(options) {
705
- try {
706
- if (!this.webSDK) {
707
- return {
708
- success: false,
709
- error: "Web SDK not available",
710
- };
711
- }
712
- // Extract the challenge from the options
713
- // The options object contains: { username, challenge, ...otherChallengeData }
714
- const { username, challenge, ...otherData } = options;
715
- // Pass the challenge data directly to the web SDK
716
- const challengeData = challenge || otherData;
717
- // Call the web SDK authenticate method with the challenge
718
- const result = await this.webSDK.passkeyAuthenticate(challengeData);
719
- return {
720
- success: true,
721
- assertion: result,
722
- data: result,
723
- };
724
- }
725
- catch (error) {
726
- return {
727
- success: false,
728
- error: error.message || "Authentication failed",
729
- };
730
- }
731
- }
732
- isSupported() {
733
- // Check if we're in a browser environment with WebAuthn support
734
- return (typeof window !== "undefined" &&
735
- typeof navigator !== "undefined" &&
736
- "credentials" in navigator &&
737
- typeof navigator.credentials.create === "function");
738
- }
739
- async getAvailableAuthenticators() {
740
- // This is a basic implementation - the web SDK might provide more detailed info
741
- const authenticators = [];
742
- if (this.isSupported()) {
743
- // Basic platform authenticator info
744
- authenticators.push({
745
- type: "platform",
746
- supportsBiometrics: true, // Assume platform authenticators support biometrics
747
- supportsUserVerification: true,
748
- });
749
- // Basic cross-platform authenticator info
750
- authenticators.push({
751
- type: "cross-platform",
752
- supportsBiometrics: false,
753
- supportsUserVerification: true,
754
- });
755
- }
756
- return authenticators;
757
- }
758
- canUseDiscoverableCredentials() {
759
- // Check if the platform supports discoverable credentials (resident keys)
760
- return this.isSupported();
761
- }
762
- supportsBiometrics() {
763
- // On web, this depends on the platform authenticator availability
764
- // This is a simplified check - a more sophisticated implementation
765
- // would actually test for platform authenticator support
766
- return (this.isSupported() &&
767
- typeof window !== "undefined" &&
768
- /Mac|Win|Linux/.test(navigator.platform));
769
- }
770
- async initialize(config) {
771
- // Initialize the web SDK if it has an init method
772
- if (this.webSDK && typeof this.webSDK.init === "function") {
773
- await this.webSDK.init(config);
774
- }
775
- }
776
- async cleanup() {
777
- // Cleanup if the web SDK has a cleanup method
778
- if (this.webSDK && typeof this.webSDK.cleanup === "function") {
779
- await this.webSDK.cleanup();
780
- }
781
- }
782
- }
783
-
784
- /**
785
- * Platform SDK exports
786
- */
787
- // Conditionally export React Native SDK only in React Native environments
788
- let ReactNativePasskeySDK = null;
789
- try {
790
- // Only try to load React Native SDK if we're actually in a React Native environment
791
- if (typeof navigator !== "undefined" && navigator.product === "ReactNative") {
792
- const { ReactNativePasskeySDK: RNPasskeySDK, } = require("./ReactNativePasskeySDK");
793
- ReactNativePasskeySDK = RNPasskeySDK;
794
- }
795
- }
796
- catch (error) {
797
- // React Native SDK not available or not in React Native environment
798
- ReactNativePasskeySDK = null;
799
- }
800
-
801
801
  /**
802
802
  * Main Passkeyme Authentication SDK class
803
803
  */
@@ -818,7 +818,7 @@ class PasskeymeAuth {
818
818
  ? `${window.location.origin}/auth/callback`
819
819
  : "http://localhost:3000/auth/callback";
820
820
  // Support both baseUrl and apiUrl for flexibility
821
- const serverUrl = config.apiUrl || config.baseUrl || "https://auth.passkeyme.com";
821
+ const serverUrl = config.baseUrl || "https://auth.passkeyme.com";
822
822
  this.config = {
823
823
  appId: config.appId,
824
824
  baseUrl: serverUrl,