refactor: make deserializeRegistryEntry a method
This commit is contained in:
parent
1221d7de63
commit
05cbd60373
|
@ -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),
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in New Issue