Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
amydevs committed Aug 6, 2024
1 parent c112166 commit 43c201d
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 6 deletions.
9 changes: 8 additions & 1 deletion src/claims/payloads/claimNetworkAccess.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ interface ClaimNetworkAccess extends Claim {
typ: 'ClaimNetworkAccess';
iss: NodeIdEncoded;
sub: NodeIdEncoded;
signedClaimNetworkNodeEncoded: SignedTokenEncoded;x
signedClaimNetworkNodeEncoded: SignedTokenEncoded;
}

function assertClaimNetworkAccess(
Expand Down Expand Up @@ -44,6 +44,13 @@ function assertClaimNetworkAccess(
'`sub` property must be an encoded node ID',
);
}
if (
claimNetworkAccess['signedClaimNetworkNodeEncoded'] == null
) {
throw new validationErrors.ErrorParse(
'`signedClaimNetworkNodeEncoded` property must be an encoded signed token',
);
}
}

function parseClaimNetworkAccess(
Expand Down
18 changes: 15 additions & 3 deletions src/nodes/NodeManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ import * as claimsErrors from '../claims/errors';
import * as utils from '../utils/utils';
import config from '../config';
import * as networkUtils from '../network/utils';
import { ClaimNetworkAccess, assertClaimNetworkAccess } from '../claims/payloads/claimNetworkAccess';

const abortEphemeralTaskReason = Symbol('abort ephemeral task reason');
const abortSingletonTaskReason = Symbol('abort singleton task reason');
Expand Down Expand Up @@ -1546,14 +1547,14 @@ class NodeManager {
};
}

public async handleVerifyClaimNetworkNode(
public async handleVerifyClaimNetwork(
requestingNodeId: NodeId,
input: AgentRPCRequestParams<AgentClaimMessage>,
tran?: DBTransaction,
): Promise<AgentRPCResponseResult<AgentClaimMessage>> {
if (tran == null) {
return this.db.withTransactionF((tran) =>
this.handleVerifyClaimNetworkNode(requestingNodeId, input, tran),
this.handleVerifyClaimNetwork(requestingNodeId, input, tran),
);
}
const signedClaim = claimsUtils.parseSignedClaim(input.signedTokenEncoded);
Expand All @@ -1566,7 +1567,18 @@ class NodeManager {
) {
throw new claimsErrors.ErrorSinglySignedClaimVerificationFailed();
}
// Need to get the seednode and test public keys against the claim
for await (const [claimId, claim] of this.sigchain.getSignedClaims({})) {
let claimNetworkAccess: ClaimNetworkAccess;
try {
assertClaimNetworkAccess(claim.payload);
claimNetworkAccess = claim.payload;
}
catch(_) {
continue;
}
// Need to get the seednode and test public keys against the claim

}
throw new Error();
}

Expand Down
12 changes: 12 additions & 0 deletions src/nodes/agent/callers/nodesNetworkVerifyClaim.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import type { HandlerTypes } from '@matrixai/rpc';
import type NodesNetworkVerifyClaim from '../handlers/NodesNetworkVerifyClaim';
import { UnaryCaller } from '@matrixai/rpc';

type CallerTypes = HandlerTypes<NodesNetworkVerifyClaim>;

const nodesNetworkVerifyClaim = new UnaryCaller<
CallerTypes['input'],
CallerTypes['output']
>();

export default nodesNetworkVerifyClaim;
4 changes: 2 additions & 2 deletions src/nodes/agent/handlers/NodesNetworkVerifyClaim.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type {
AgentRPCRequestParams,
AgentRPCResponseResult,
} from '../types';
import type NodeConnectionManager from '../../../nodes/NodeConnectionManager';
import type NodeManager from '../../../nodes/NodeManager';
import type { Host, Port } from '../../../network/types';
import type { JSONValue } from '../../../types';
import { UnaryHandler } from '@matrixai/rpc';
Expand All @@ -15,7 +15,7 @@ import * as ids from '../../../ids';

class NodesNetworkAuthenticate extends UnaryHandler<
{
nodeConnectionManager: NodeConnectionManager;
nodeManager: NodeManager;
},
AgentRPCRequestParams<{}>,
AgentRPCResponseResult<{}>
Expand Down

0 comments on commit 43c201d

Please sign in to comment.