Require current node possession proof
This commit is contained in:
parent
66eeaaf958
commit
64062fadac
10 changed files with 417 additions and 10 deletions
|
|
@ -11,6 +11,7 @@ const SHA256_PATTERN = /^[a-f0-9]{64}$/;
|
|||
const MAX_CLAIM_LIFETIME_MS = 24 * 60 * 60 * 1000;
|
||||
const MAX_CLOCK_SKEW_MS = 5 * 60 * 1000;
|
||||
const registeredEndpoints = new WeakSet<object>();
|
||||
const verifiedClaims = new WeakSet<object>();
|
||||
|
||||
export interface NodeRegistrationEndpoint {
|
||||
algorithm: 'Ed25519';
|
||||
|
|
@ -57,6 +58,13 @@ export interface VerifiedNodeRegistration extends NodeRegistrationClaimPayload {
|
|||
verifiedAt: number;
|
||||
}
|
||||
|
||||
export function assertVerifiedNodeRegistration(
|
||||
claim: VerifiedNodeRegistration,
|
||||
): VerifiedNodeRegistration {
|
||||
if (!verifiedClaims.has(claim)) invalidClaim();
|
||||
return claim;
|
||||
}
|
||||
|
||||
export interface NodeRegistrationLookup {
|
||||
domainId: string;
|
||||
nodeType: DomainNodeType;
|
||||
|
|
@ -270,9 +278,11 @@ export function verifyNodeRegistrationClaim(
|
|||
} catch {
|
||||
invalidClaim();
|
||||
}
|
||||
return Object.freeze({
|
||||
const verified = Object.freeze({
|
||||
...payload,
|
||||
signature: input.signature,
|
||||
verifiedAt: now,
|
||||
});
|
||||
verifiedClaims.add(verified);
|
||||
return verified;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue