refactor: make deserializeRegistryEntry a method

This commit is contained in:
Derrick Hammer 2023-08-31 02:37:06 -04:00
parent 1221d7de63
commit 05cbd60373
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
1 changed files with 11 additions and 11 deletions

View File

@ -201,11 +201,21 @@ export class RegistryService {
const val = await this.db?.get(stringifyBytes(pk)); const val = await this.db?.get(stringifyBytes(pk));
if (val) { if (val) {
return deserializeRegistryEntry(val); return this.deserializeRegistryEntry(val);
} }
return null; return null;
} }
public deserializeRegistryEntry(event: Uint8Array): SignedRegistryEntry {
const dataLength = event[42];
return {
pk: event.slice(1, 34),
revision: decodeEndian(event.slice(34, 42)),
data: event.slice(43, 43 + dataLength),
signature: event.slice(43 + dataLength),
};
}
} }
function verifyRegistryEntry(sre: SignedRegistryEntry): boolean { function verifyRegistryEntry(sre: SignedRegistryEntry): boolean {
@ -228,13 +238,3 @@ function serializeRegistryEntry(sre: SignedRegistryEntry): Uint8Array {
...sre.signature, ...sre.signature,
]); ]);
} }
function deserializeRegistryEntry(event: Uint8Array): SignedRegistryEntry {
const dataLength = event[42];
return {
pk: event.slice(1, 34),
revision: decodeEndian(event.slice(34, 42)),
data: event.slice(43, 43 + dataLength),
signature: event.slice(43 + dataLength),
};
}