diff --git a/src/service/registry.ts b/src/service/registry.ts index 562e6f4..bc4bc18 100644 --- a/src/service/registry.ts +++ b/src/service/registry.ts @@ -183,21 +183,7 @@ export class RegistryService { data: Uint8Array; revision: number; }): SignedRegistryEntry { - const list = new Uint8Array([ - recordTypeRegistryEntry, - ...encodeEndian(revision, 8), - data.length, - ...data, - ]); - - const signature = ed25519.sign(list, kp.extractBytes()); - - return { - pk: kp.publicKey, - revision, - data, - signature: new Uint8Array(signature), - }; + return this.signRegistryEntry({ kp, data, revision }); } async getFromDB(pk: Uint8Array): Promise { @@ -281,3 +267,29 @@ export function serializeRegistryEntry(sre: SignedRegistryEntry): Uint8Array { ...sre.signature, ]); } + +export function signRegistryEntry({ + kp, + data, + revision, +}: { + kp: KeyPairEd25519; + data: Uint8Array; + revision: number; +}): SignedRegistryEntry { + const list = new Uint8Array([ + recordTypeRegistryEntry, + ...encodeEndian(revision, 8), + data.length, + ...data, + ]); + + const signature = ed25519.sign(list, kp.extractBytes()); + + return { + pk: kp.publicKey, + revision, + data, + signature: new Uint8Array(signature), + }; +}