@@ -1545,6 +1545,15 @@ class NodeManager<Manifest extends AgentClientManifestNodeManager> {
15451545 } ) ;
15461546 }
15471547
1548+ /**
1549+ * Creates a claim on the sigchain granting this node authority over a network to create `ClaimNetworkAccess` claims.
1550+ *
1551+ * @param networkNodeId - The public key NodeId for the root authority for the network
1552+ * @param network - The network URL.
1553+ * @param isPrivate - Indicates if the network is private or not.
1554+ * @param signingHook - A callback used to sign the claim with the network's private key.
1555+ * @param tran
1556+ */
15481557 public async createClaimNetworkAuthority (
15491558 networkNodeId : NodeId ,
15501559 network : string ,
@@ -1618,7 +1627,7 @@ class NodeManager<Manifest extends AgentClientManifestNodeManager> {
16181627 }
16191628
16201629 /**
1621- * This takes a ClaimNetworkAuthority and tracks it in the database under the network name.
1630+ * This takes a ` ClaimNetworkAuthority` and tracks it in the database under the network name.
16221631 */
16231632 protected async setClaimNetworkAuthority (
16241633 claimNetworkAuthority : Token < ClaimNetworkAuthority > ,
@@ -1638,6 +1647,9 @@ class NodeManager<Manifest extends AgentClientManifestNodeManager> {
16381647 ) ;
16391648 }
16401649
1650+ /**
1651+ * This returns the `ClaimNetworkAuthority` for the given network.
1652+ */
16411653 protected async getClaimNetworkAuthority (
16421654 network : string ,
16431655 tran ?: DBTransaction ,
@@ -1664,7 +1676,7 @@ class NodeManager<Manifest extends AgentClientManifestNodeManager> {
16641676 }
16651677
16661678 /**
1667- * This takes a ClaimNetworkAccess and tracks it in the database under the network name.
1679+ * This takes a ` ClaimNetworkAccess` and tracks it in the database under the network name.
16681680 */
16691681 protected async setClaimNetworkAccess (
16701682 claimNetworkAccess : Token < ClaimNetworkAccess > ,
@@ -1684,6 +1696,9 @@ class NodeManager<Manifest extends AgentClientManifestNodeManager> {
16841696 ) ;
16851697 }
16861698
1699+ /**
1700+ * This returns the `ClaimNetworkAccess` for the given network.
1701+ */
16871702 protected async getClaimNetworkAccess (
16881703 network : string ,
16891704 tran ?: DBTransaction ,
@@ -1709,8 +1724,16 @@ class NodeManager<Manifest extends AgentClientManifestNodeManager> {
17091724 return token as Token < ClaimNetworkAccess > ;
17101725 }
17111726
1727+ /**
1728+ * This switches out the active `ClaimNetworkAuthority` and `ClaimNetworkAccess` for the desired network.
1729+ * If no claims exist for the network or no network is provided, then it switches to using no network.
1730+ * In doing so this also updates the `NodeConnectionManager`'s authentication callbacks to use the selected
1731+ * network for authentication.
1732+ * @param network - The Network URL for the desired network to switch to.
1733+ * @param tran
1734+ */
17121735 public async switchNetwork (
1713- network : string ,
1736+ network ? : string ,
17141737 tran ?: DBTransaction ,
17151738 ) : Promise < void > {
17161739 if ( tran == null ) {
@@ -1719,6 +1742,19 @@ class NodeManager<Manifest extends AgentClientManifestNodeManager> {
17191742 ) ;
17201743 }
17211744
1745+ if ( network == null ) {
1746+ this . claimNetworkAuthority = undefined ;
1747+ this . claimNetworkAccess = undefined ;
1748+ // Use the basic no network behavior
1749+ this . nodeConnectionManager . setAuthenticateNetworkForwardCallback (
1750+ nodesUtils . nodesAuthenticateConnectionForwardDefault ,
1751+ ) ;
1752+ this . nodeConnectionManager . setAuthenticateNetworkReverseCallback (
1753+ nodesUtils . nodesAuthenticateConnectionReverseDeny ,
1754+ ) ;
1755+ return ;
1756+ }
1757+
17221758 this . claimNetworkAuthority = await this . getClaimNetworkAuthority (
17231759 network ,
17241760 tran ,
@@ -1737,7 +1773,7 @@ class NodeManager<Manifest extends AgentClientManifestNodeManager> {
17371773 ) ,
17381774 ) ;
17391775 } else {
1740- // Use the basic public behavior
1776+ // Use the basic no network behavior
17411777 this . nodeConnectionManager . setAuthenticateNetworkForwardCallback (
17421778 nodesUtils . nodesAuthenticateConnectionForwardDefault ,
17431779 ) ;
@@ -1747,12 +1783,25 @@ class NodeManager<Manifest extends AgentClientManifestNodeManager> {
17471783 }
17481784 }
17491785
1786+ /**
1787+ * Quick hand utility for checking if the active `ClaimNetworkAuthority` is a private network
1788+ */
17501789 public isClaimNetworkAuthorityPrivate ( ) : boolean | undefined {
17511790 // Return undefined if we're not acting as a network authority
17521791 if ( this . claimNetworkAuthority == null ) return ;
17531792 return this . claimNetworkAuthority . payload . isPrivate ;
17541793 }
17551794
1795+ /**
1796+ * This creates a cross-signed `ClaimNetworkAccess` on the sigchain. The resulting `ClaimNetworkAccess` is used to
1797+ * authenticate connections between nodes within the network.
1798+ *
1799+ * @param targetNodeId - This is a node with an active `ClaimNetworkAuthority` for the network you wish to join.
1800+ * This usually is a seed node for that network.
1801+ * @param network - The URL of the network you wish to join.
1802+ * @param tran
1803+ * @param ctx
1804+ */
17561805 public async claimNetwork (
17571806 targetNodeId : NodeId ,
17581807 network : string ,
@@ -1891,6 +1940,13 @@ class NodeManager<Manifest extends AgentClientManifestNodeManager> {
18911940 return [ claimId , token ] ;
18921941 }
18931942
1943+ /**
1944+ * This provides the handler side of the ClaimNetwork logic.
1945+ * @param requestingNodeId - The nodeId of the node making the request. This should be taken from the connections
1946+ * certificate to confirm that `ClaimNetworkAccess` is being created for the node requesting it.
1947+ * @param input - The input stream for the RPC handler.
1948+ * @param tran
1949+ */
18941950 public async * handleClaimNetwork (
18951951 requestingNodeId : NodeId ,
18961952 input : AsyncIterableIterator < AgentRPCRequestParams < AgentClaimMessage > > ,
@@ -2012,6 +2068,11 @@ class NodeManager<Manifest extends AgentClientManifestNodeManager> {
20122068 } ) ;
20132069 }
20142070
2071+ /**
2072+ * Gets the `ClaimNetworkAuthority` from the target node. It also verifies its valid and for the expected network.
2073+ * @param network
2074+ * @param targetNodeId
2075+ */
20152076 public async remoteClaimNetworkAuthorityGet (
20162077 network : string ,
20172078 targetNodeId : NodeId ,
@@ -2042,6 +2103,9 @@ class NodeManager<Manifest extends AgentClientManifestNodeManager> {
20422103 ) ;
20432104 }
20442105
2106+ /**
2107+ * The handler side logic for `remoteClaimNetworkAuthorityGet`.
2108+ */
20452109 public async handleClaimNetworkAuthorityGet ( ) : Promise < SignedTokenEncoded > {
20462110 if ( this . claimNetworkAuthority == null ) {
20472111 throw new nodesErrors . ErrorNodeManagerClaimNetworkAuthorityMissing ( ) ;
0 commit comments