@bsv/sdk 1.3.28 → 1.3.29
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/cjs/package.json +1 -1
- package/dist/cjs/src/auth/Peer.js +142 -91
- package/dist/cjs/src/auth/Peer.js.map +1 -1
- package/dist/cjs/src/auth/SessionManager.js +82 -21
- package/dist/cjs/src/auth/SessionManager.js.map +1 -1
- package/dist/cjs/tsconfig.cjs.tsbuildinfo +1 -1
- package/dist/esm/src/auth/Peer.js +138 -88
- package/dist/esm/src/auth/Peer.js.map +1 -1
- package/dist/esm/src/auth/SessionManager.js +88 -22
- package/dist/esm/src/auth/SessionManager.js.map +1 -1
- package/dist/esm/tsconfig.esm.tsbuildinfo +1 -1
- package/dist/types/src/auth/Peer.d.ts +21 -23
- package/dist/types/src/auth/Peer.d.ts.map +1 -1
- package/dist/types/src/auth/SessionManager.d.ts +25 -7
- package/dist/types/src/auth/SessionManager.d.ts.map +1 -1
- package/dist/types/src/auth/types.d.ts +1 -0
- package/dist/types/src/auth/types.d.ts.map +1 -1
- package/dist/types/tsconfig.types.tsbuildinfo +1 -1
- package/dist/umd/bundle.js +1 -1
- package/docs/auth.md +33 -38
- package/package.json +1 -1
- package/src/auth/Peer.ts +186 -130
- package/src/auth/SessionManager.ts +89 -22
- package/src/auth/__tests/Peer.test.ts +66 -0
- package/src/auth/__tests/SessionManager.test.ts +3 -2
- package/src/auth/types.ts +1 -0
package/docs/auth.md
CHANGED
|
@@ -46,6 +46,7 @@ export interface PeerSession {
|
|
|
46
46
|
sessionNonce?: string;
|
|
47
47
|
peerNonce?: string;
|
|
48
48
|
peerIdentityKey?: string;
|
|
49
|
+
lastUpdate: number;
|
|
49
50
|
}
|
|
50
51
|
```
|
|
51
52
|
|
|
@@ -617,6 +618,8 @@ Represents a peer capable of performing mutual authentication.
|
|
|
617
618
|
Manages sessions, handles authentication handshakes, certificate requests and responses,
|
|
618
619
|
and sending and receiving general messages over a transport layer.
|
|
619
620
|
|
|
621
|
+
This version supports multiple concurrent sessions per peer identityKey.
|
|
622
|
+
|
|
620
623
|
```ts
|
|
621
624
|
export class Peer {
|
|
622
625
|
public sessionManager: SessionManager;
|
|
@@ -631,12 +634,11 @@ export class Peer {
|
|
|
631
634
|
stopListeningForCertificatesReceived(callbackID: number): void
|
|
632
635
|
listenForCertificatesRequested(callback: (senderPublicKey: string, requestedCertificates: RequestedCertificateSet) => void): number
|
|
633
636
|
stopListeningForCertificatesRequested(callbackID: number): void
|
|
634
|
-
async processInitialRequest(message: AuthMessage): Promise<void>
|
|
635
637
|
async sendCertificateResponse(verifierIdentityKey: string, certificates: VerifiableCertificate[]): Promise<void>
|
|
636
638
|
}
|
|
637
639
|
```
|
|
638
640
|
|
|
639
|
-
See also: [
|
|
641
|
+
See also: [PeerSession](./auth.md#interface-peersession), [RequestedCertificateSet](./auth.md#interface-requestedcertificateset), [SessionManager](./auth.md#class-sessionmanager), [Transport](./auth.md#interface-transport), [VerifiableCertificate](./auth.md#class-verifiablecertificate), [WalletInterface](./wallet.md#interface-walletinterface)
|
|
640
642
|
|
|
641
643
|
#### Constructor
|
|
642
644
|
|
|
@@ -665,6 +667,10 @@ Argument Details
|
|
|
665
667
|
Retrieves an authenticated session for a given peer identity. If no session exists
|
|
666
668
|
or the session is not authenticated, initiates a handshake to create or authenticate the session.
|
|
667
669
|
|
|
670
|
+
- If `identityKey` is provided, we look up any existing session for that identity key.
|
|
671
|
+
- If none is found or not authenticated, we do a new handshake.
|
|
672
|
+
- If `identityKey` is not provided, but we have a `lastInteractedWithPeer`, we try that key.
|
|
673
|
+
|
|
668
674
|
```ts
|
|
669
675
|
async getAuthenticatedSession(identityKey?: string, maxWaitTime?: number): Promise<PeerSession>
|
|
670
676
|
```
|
|
@@ -677,15 +683,9 @@ Returns
|
|
|
677
683
|
Argument Details
|
|
678
684
|
|
|
679
685
|
+ **identityKey**
|
|
680
|
-
+ The identity public key of the peer.
|
|
681
|
-
to retrieve an existing session associated with this identity.
|
|
686
|
+
+ The identity public key of the peer.
|
|
682
687
|
+ **maxWaitTime**
|
|
683
|
-
+ The maximum time in milliseconds to wait for the handshake
|
|
684
|
-
to complete if a new session is required. Defaults to a pre-defined timeout if not specified.
|
|
685
|
-
|
|
686
|
-
Throws
|
|
687
|
-
|
|
688
|
-
- Throws an error if the transport is not connected or if the handshake fails.
|
|
688
|
+
+ The maximum time in milliseconds to wait for the handshake.
|
|
689
689
|
|
|
690
690
|
#### Method listenForCertificatesReceived
|
|
691
691
|
|
|
@@ -740,20 +740,6 @@ Argument Details
|
|
|
740
740
|
+ **callback**
|
|
741
741
|
+ The function to call when a general message is received.
|
|
742
742
|
|
|
743
|
-
#### Method processInitialRequest
|
|
744
|
-
|
|
745
|
-
Processes an initial request message from a peer.
|
|
746
|
-
|
|
747
|
-
```ts
|
|
748
|
-
async processInitialRequest(message: AuthMessage): Promise<void>
|
|
749
|
-
```
|
|
750
|
-
See also: [AuthMessage](./auth.md#interface-authmessage)
|
|
751
|
-
|
|
752
|
-
Argument Details
|
|
753
|
-
|
|
754
|
-
+ **message**
|
|
755
|
-
+ The incoming initial request message.
|
|
756
|
-
|
|
757
743
|
#### Method requestCertificates
|
|
758
744
|
|
|
759
745
|
Sends a request for certificates to a peer.
|
|
@@ -774,7 +760,7 @@ Argument Details
|
|
|
774
760
|
+ **certificatesToRequest**
|
|
775
761
|
+ Specifies the certifiers and types of certificates required from the peer.
|
|
776
762
|
+ **identityKey**
|
|
777
|
-
+ The identity public key of the peer. If not provided, the current session identity is used.
|
|
763
|
+
+ The identity public key of the peer. If not provided, the current or last session identity is used.
|
|
778
764
|
+ **maxWaitTime**
|
|
779
765
|
+ Maximum time in milliseconds to wait for the peer session to be authenticated.
|
|
780
766
|
|
|
@@ -791,20 +777,16 @@ async sendCertificateResponse(verifierIdentityKey: string, certificates: Verifia
|
|
|
791
777
|
```
|
|
792
778
|
See also: [VerifiableCertificate](./auth.md#class-verifiablecertificate)
|
|
793
779
|
|
|
794
|
-
Returns
|
|
795
|
-
|
|
796
|
-
- A promise that resolves once the certificate response has been sent successfully.
|
|
797
|
-
|
|
798
780
|
Argument Details
|
|
799
781
|
|
|
800
782
|
+ **verifierIdentityKey**
|
|
801
783
|
+ The identity key of the peer requesting the certificates.
|
|
802
784
|
+ **certificates**
|
|
803
|
-
+ The list of certificates to
|
|
785
|
+
+ The list of certificates to include in the response.
|
|
804
786
|
|
|
805
787
|
Throws
|
|
806
788
|
|
|
807
|
-
|
|
789
|
+
Will throw an error if the transport fails to send the message.
|
|
808
790
|
|
|
809
791
|
#### Method stopListeningForCertificatesReceived
|
|
810
792
|
|
|
@@ -858,7 +840,9 @@ Argument Details
|
|
|
858
840
|
+ **message**
|
|
859
841
|
+ The message payload to send.
|
|
860
842
|
+ **identityKey**
|
|
861
|
-
+ The identity public key of the peer. If not provided,
|
|
843
|
+
+ The identity public key of the peer. If not provided, uses lastInteractedWithPeer (if any).
|
|
844
|
+
+ **maxWaitTime**
|
|
845
|
+
+ optional max wait time in ms
|
|
862
846
|
|
|
863
847
|
Throws
|
|
864
848
|
|
|
@@ -869,8 +853,8 @@ Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](
|
|
|
869
853
|
---
|
|
870
854
|
### Class: SessionManager
|
|
871
855
|
|
|
872
|
-
Manages sessions for peers, allowing
|
|
873
|
-
|
|
856
|
+
Manages sessions for peers, allowing multiple concurrent sessions
|
|
857
|
+
per identity key. Primary lookup is always by `sessionNonce`.
|
|
874
858
|
|
|
875
859
|
```ts
|
|
876
860
|
export class SessionManager {
|
|
@@ -887,7 +871,11 @@ See also: [PeerSession](./auth.md#interface-peersession)
|
|
|
887
871
|
|
|
888
872
|
#### Method addSession
|
|
889
873
|
|
|
890
|
-
Adds a session to the manager, associating it with
|
|
874
|
+
Adds a session to the manager, associating it with its sessionNonce,
|
|
875
|
+
and also with its peerIdentityKey (if any).
|
|
876
|
+
|
|
877
|
+
This does NOT overwrite existing sessions for the same peerIdentityKey,
|
|
878
|
+
allowing multiple concurrent sessions for the same peer.
|
|
891
879
|
|
|
892
880
|
```ts
|
|
893
881
|
addSession(session: PeerSession): void
|
|
@@ -901,7 +889,13 @@ Argument Details
|
|
|
901
889
|
|
|
902
890
|
#### Method getSession
|
|
903
891
|
|
|
904
|
-
Retrieves a session based on a given identifier
|
|
892
|
+
Retrieves a session based on a given identifier, which can be:
|
|
893
|
+
- A sessionNonce, or
|
|
894
|
+
- A peerIdentityKey.
|
|
895
|
+
|
|
896
|
+
If it is a `sessionNonce`, returns that exact session.
|
|
897
|
+
If it is a `peerIdentityKey`, returns the "best" (e.g. most recently updated,
|
|
898
|
+
authenticated) session associated with that peer, if any.
|
|
905
899
|
|
|
906
900
|
```ts
|
|
907
901
|
getSession(identifier: string): PeerSession | undefined
|
|
@@ -919,7 +913,7 @@ Argument Details
|
|
|
919
913
|
|
|
920
914
|
#### Method hasSession
|
|
921
915
|
|
|
922
|
-
Checks if a session exists
|
|
916
|
+
Checks if a session exists for a given identifier (either sessionNonce or identityKey).
|
|
923
917
|
|
|
924
918
|
```ts
|
|
925
919
|
hasSession(identifier: string): boolean
|
|
@@ -950,7 +944,8 @@ Argument Details
|
|
|
950
944
|
|
|
951
945
|
#### Method updateSession
|
|
952
946
|
|
|
953
|
-
Updates a session in the manager
|
|
947
|
+
Updates a session in the manager (primarily by re-adding it),
|
|
948
|
+
ensuring we record the latest data (e.g., isAuthenticated, lastUpdate, etc.).
|
|
954
949
|
|
|
955
950
|
```ts
|
|
956
951
|
updateSession(session: PeerSession): void
|