refactor: make instance methods deserializeRegistryEntry, verifyRegistryEntry, serializeRegistryEntry wrappers of the functional ones
This commit is contained in:
parent
cb4f23ed7e
commit
66612e9afc
|
@ -234,6 +234,24 @@ export class RegistryService {
|
||||||
}
|
}
|
||||||
|
|
||||||
public deserializeRegistryEntry(event: Uint8Array): SignedRegistryEntry {
|
public deserializeRegistryEntry(event: Uint8Array): SignedRegistryEntry {
|
||||||
|
return deserializeRegistryEntry(event);
|
||||||
|
}
|
||||||
|
|
||||||
|
public verifyRegistryEntry(sre: SignedRegistryEntry): boolean {
|
||||||
|
return verifyRegistryEntry(sre);
|
||||||
|
}
|
||||||
|
public serializeRegistryEntry(sre: SignedRegistryEntry): Uint8Array {
|
||||||
|
return serializeRegistryEntry(sre);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function pTimeout(ms: number) {
|
||||||
|
return new Promise((resolve) => setTimeout(resolve, ms));
|
||||||
|
}
|
||||||
|
|
||||||
|
export function deserializeRegistryEntry(
|
||||||
|
event: Uint8Array,
|
||||||
|
): SignedRegistryEntry {
|
||||||
const dataLength = event[42];
|
const dataLength = event[42];
|
||||||
return {
|
return {
|
||||||
pk: event.slice(1, 34),
|
pk: event.slice(1, 34),
|
||||||
|
@ -241,9 +259,9 @@ export class RegistryService {
|
||||||
data: event.slice(43, 43 + dataLength),
|
data: event.slice(43, 43 + dataLength),
|
||||||
signature: event.slice(43 + dataLength),
|
signature: event.slice(43 + dataLength),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
public verifyRegistryEntry(sre: SignedRegistryEntry): boolean {
|
export function verifyRegistryEntry(sre: SignedRegistryEntry): boolean {
|
||||||
const list: Uint8Array = Uint8Array.from([
|
const list: Uint8Array = Uint8Array.from([
|
||||||
recordTypeRegistryEntry,
|
recordTypeRegistryEntry,
|
||||||
...encodeEndian(sre.revision, 8),
|
...encodeEndian(sre.revision, 8),
|
||||||
|
@ -252,8 +270,8 @@ export class RegistryService {
|
||||||
]);
|
]);
|
||||||
|
|
||||||
return ed25519.verify(sre.signature, list, sre.pk.slice(1));
|
return ed25519.verify(sre.signature, list, sre.pk.slice(1));
|
||||||
}
|
}
|
||||||
public serializeRegistryEntry(sre: SignedRegistryEntry): Uint8Array {
|
export function serializeRegistryEntry(sre: SignedRegistryEntry): Uint8Array {
|
||||||
return Uint8Array.from([
|
return Uint8Array.from([
|
||||||
recordTypeRegistryEntry,
|
recordTypeRegistryEntry,
|
||||||
...sre.pk,
|
...sre.pk,
|
||||||
|
@ -262,9 +280,4 @@ export class RegistryService {
|
||||||
...sre.data,
|
...sre.data,
|
||||||
...sre.signature,
|
...sre.signature,
|
||||||
]);
|
]);
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async function pTimeout(ms: number) {
|
|
||||||
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue