Skip to content

Commit 07292a1

Browse files
committed
wip: creating cross network claiming logic.
[ci skip]
1 parent a37ae10 commit 07292a1

File tree

7 files changed

+422
-29
lines changed

7 files changed

+422
-29
lines changed

src/claims/payloads/claimNetworkAccess.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import type { Claim, SignedClaim } from '../types.js';
2-
import type { NodeIdEncoded } from '../../ids/types.js';
2+
import type { NodeId, NodeIdEncoded } from '../../ids/types.js';
33
import type { SignedTokenEncoded } from '../../tokens/types.js';
4+
import type Token from '../../tokens/Token.js';
45
import * as tokensSchema from '../../tokens/schemas/index.js';
56
import * as ids from '../../ids/index.js';
67
import * as claimsUtils from '../utils.js';
@@ -84,10 +85,21 @@ function parseSignedClaimNetworkAccess(
8485
return signedClaim as SignedClaim<ClaimNetworkAccess>;
8586
}
8687

88+
function verifyClaimNetworkAccess(
89+
networkNodeId: NodeId,
90+
targetNodeId: NodeId,
91+
network: string,
92+
token: Token<ClaimNetworkAccess>,
93+
): void {
94+
// TODO: complete
95+
console.log(token);
96+
}
97+
8798
export {
8899
assertClaimNetworkAccess,
89100
parseClaimNetworkAccess,
90101
parseSignedClaimNetworkAccess,
102+
verifyClaimNetworkAccess,
91103
};
92104

93105
export type { ClaimNetworkAccess };

src/claims/payloads/claimNetworkAuthority.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ interface ClaimNetworkAuthority extends Claim {
1818
typ: 'ClaimNetworkAuthority';
1919
iss: NodeIdEncoded;
2020
sub: NodeIdEncoded;
21+
network: string;
2122
}
2223

2324
function assertClaimNetworkAuthority(
@@ -47,6 +48,11 @@ function assertClaimNetworkAuthority(
4748
'`sub` property must be an encoded node ID',
4849
);
4950
}
51+
if (claimNetworkAuthority['network'] == null) {
52+
throw new validationErrors.ErrorParse(
53+
'`network` property must be a network name string',
54+
);
55+
}
5056
}
5157

5258
function parseClaimNetworkAuthority(
@@ -70,8 +76,9 @@ function parseSignedClaimNetworkAuthority(
7076
function verifyClaimNetworkAuthority(
7177
networkNodeId: NodeId,
7278
targetNodeId: NodeId,
79+
network: string,
7380
token: Token<ClaimNetworkAuthority>,
74-
) {
81+
): void {
7582
// Should be signed by the network authority as the issuer
7683
const nodeIdIss = token.payload.iss;
7784
const networkNodeIdEncoded = nodesUtils.encodeNodeId(networkNodeId);
@@ -97,6 +104,11 @@ function verifyClaimNetworkAuthority(
97104
if (!token.verifyWithPublicKey(targetPublicKey)) {
98105
throw Error('TMP IMP Token was not signed by the network authority');
99106
}
107+
// Checking if the network name matches
108+
const networkName = token.payload.network;
109+
if (networkName !== network) {
110+
throw Error('TMP IMP Network name does not match the expected network');
111+
}
100112
}
101113

102114
export {

0 commit comments

Comments
 (0)