-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
252 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import type { Claim, SignedClaim } from '../types'; | ||
import type { NodeIdEncoded } from '../../ids/types'; | ||
import * as ids from '../../ids'; | ||
import * as claimsUtils from '../utils'; | ||
import * as tokensUtils from '../../tokens/utils'; | ||
import * as validationErrors from '../../validation/errors'; | ||
import * as utils from '../../utils'; | ||
|
||
/** | ||
* Asserts that a node is apart of a network | ||
*/ | ||
interface ClaimNetworkNode extends Claim { | ||
typ: 'ClaimNetworkNode'; | ||
iss: NodeIdEncoded; | ||
sub: NodeIdEncoded; | ||
} | ||
|
||
function assertClaimNetworkNode( | ||
claimNetworkNode: unknown, | ||
): asserts claimNetworkNode is ClaimNetworkNode { | ||
if (!utils.isObject(claimNetworkNode)) { | ||
throw new validationErrors.ErrorParse('must be POJO'); | ||
} | ||
if (claimNetworkNode['typ'] !== 'ClaimNetworkNode') { | ||
throw new validationErrors.ErrorParse( | ||
'`typ` property must be `ClaimNetworkNode`', | ||
); | ||
} | ||
if ( | ||
claimNetworkNode['iss'] == null || | ||
ids.decodeNodeId(claimNetworkNode['iss']) == null | ||
) { | ||
throw new validationErrors.ErrorParse( | ||
'`iss` property must be an encoded node ID', | ||
); | ||
} | ||
if ( | ||
claimNetworkNode['sub'] == null || | ||
ids.decodeNodeId(claimNetworkNode['sub']) == null | ||
) { | ||
throw new validationErrors.ErrorParse( | ||
'`sub` property must be an encoded node ID', | ||
); | ||
} | ||
} | ||
|
||
function parseClaimNetworkNode( | ||
claimNetworkNodeEncoded: unknown, | ||
): ClaimNetworkNode { | ||
const claimNetworkNode = claimsUtils.parseClaim(claimNetworkNodeEncoded); | ||
assertClaimNetworkNode(claimNetworkNode); | ||
return claimNetworkNode; | ||
} | ||
|
||
function parseSignedClaimNetworkNode( | ||
signedClaimNetworkNodeEncoded: unknown, | ||
): SignedClaim<ClaimNetworkNode> { | ||
const signedClaim = tokensUtils.parseSignedToken( | ||
signedClaimNetworkNodeEncoded, | ||
); | ||
assertClaimNetworkNode(signedClaim.payload); | ||
return signedClaim as SignedClaim<ClaimNetworkNode>; | ||
} | ||
|
||
export { | ||
assertClaimNetworkNode, | ||
parseClaimNetworkNode, | ||
parseSignedClaimNetworkNode, | ||
}; | ||
|
||
export type { ClaimNetworkNode }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export * from './claimLinkIdentity'; | ||
export * from './claimLinkNode'; | ||
export * from './claimNetworkNode'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import type { HandlerTypes } from '@matrixai/rpc'; | ||
import type NodesNetworkSignClaim from '../handlers/NodesNetworkSignClaim'; | ||
import { UnaryCaller } from '@matrixai/rpc'; | ||
|
||
type CallerTypes = HandlerTypes<NodesNetworkSignClaim>; | ||
|
||
const nodesNetworkSignClaim = new UnaryCaller< | ||
CallerTypes['input'], | ||
CallerTypes['output'] | ||
>(); | ||
|
||
export default nodesNetworkSignClaim; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import type { | ||
AgentRPCRequestParams, | ||
AgentRPCResponseResult, | ||
AgentClaimMessage, | ||
} from '../types'; | ||
import type NodeManager from '../../../nodes/NodeManager'; | ||
import type { JSONValue } from '../../../types'; | ||
import { UnaryHandler } from '@matrixai/rpc'; | ||
import * as agentErrors from '../errors'; | ||
import * as agentUtils from '../utils'; | ||
|
||
class NodesNetworkSignClaim extends UnaryHandler< | ||
{ | ||
nodeManager: NodeManager; | ||
}, | ||
AgentRPCRequestParams<AgentClaimMessage>, | ||
AgentRPCResponseResult<AgentClaimMessage> | ||
> { | ||
public handle = async ( | ||
input: AgentRPCRequestParams<AgentClaimMessage>, | ||
_cancel, | ||
meta: Record<string, JSONValue> | undefined, | ||
): Promise<AgentRPCResponseResult<AgentClaimMessage>> => { | ||
const { nodeManager } = this.container; | ||
// Connections should always be validated | ||
const requestingNodeId = agentUtils.nodeIdFromMeta(meta); | ||
if (requestingNodeId == null) { | ||
throw new agentErrors.ErrorAgentNodeIdMissing(); | ||
} | ||
return nodeManager.handleClaimNetworkNode(requestingNodeId, input); | ||
}; | ||
} | ||
|
||
export default NodesNetworkSignClaim; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import type { | ||
AgentRPCRequestParams, | ||
AgentRPCResponseResult, | ||
} from '../types'; | ||
import type NodeConnectionManager from '../../../nodes/NodeConnectionManager'; | ||
import type { Host, Port } from '../../../network/types'; | ||
import type { JSONValue } from '../../../types'; | ||
import { UnaryHandler } from '@matrixai/rpc'; | ||
import * as x509 from '@peculiar/x509'; | ||
import * as agentErrors from '../errors'; | ||
import * as agentUtils from '../utils'; | ||
import { never } from '../../../utils'; | ||
import * as keysUtils from '../../../keys/utils'; | ||
import * as ids from '../../../ids'; | ||
|
||
class NodesNetworkAuthenticate extends UnaryHandler< | ||
{ | ||
nodeConnectionManager: NodeConnectionManager; | ||
}, | ||
AgentRPCRequestParams<{}>, | ||
AgentRPCResponseResult<{}> | ||
> { | ||
public handle = async ( | ||
input: AgentRPCRequestParams<{}>, | ||
_cancel, | ||
meta: Record<string, JSONValue> | undefined, | ||
): Promise<AgentRPCResponseResult<{}>> => { | ||
return {}; | ||
}; | ||
} | ||
|
||
export default NodesNetworkAuthenticate; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters