refactor: extract signRegistryEntry as a utility function and make the instance method a wrapper
This commit is contained in:
parent
085c97354e
commit
3c789459ec
|
@ -183,21 +183,7 @@ export class RegistryService {
|
||||||
data: Uint8Array;
|
data: Uint8Array;
|
||||||
revision: number;
|
revision: number;
|
||||||
}): SignedRegistryEntry {
|
}): SignedRegistryEntry {
|
||||||
const list = new Uint8Array([
|
return this.signRegistryEntry({ kp, data, revision });
|
||||||
recordTypeRegistryEntry,
|
|
||||||
...encodeEndian(revision, 8),
|
|
||||||
data.length,
|
|
||||||
...data,
|
|
||||||
]);
|
|
||||||
|
|
||||||
const signature = ed25519.sign(list, kp.extractBytes());
|
|
||||||
|
|
||||||
return {
|
|
||||||
pk: kp.publicKey,
|
|
||||||
revision,
|
|
||||||
data,
|
|
||||||
signature: new Uint8Array(signature),
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async getFromDB(pk: Uint8Array): Promise<SignedRegistryEntry | null> {
|
async getFromDB(pk: Uint8Array): Promise<SignedRegistryEntry | null> {
|
||||||
|
@ -281,3 +267,29 @@ export function serializeRegistryEntry(sre: SignedRegistryEntry): Uint8Array {
|
||||||
...sre.signature,
|
...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),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue