refactor: bug fixes and return early if the entry is the same
This commit is contained in:
parent
9ecea29244
commit
6388669ca8
|
@ -137,27 +137,34 @@ export async function createEntry(
|
||||||
sk = createKeyPair(sk);
|
sk = createKeyPair(sk);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let existing = true;
|
||||||
let entry = await this.getEntry(sk.publicKey);
|
let entry = await this.getEntry(sk.publicKey);
|
||||||
|
|
||||||
if (!entry) {
|
if (!entry) {
|
||||||
|
existing = false;
|
||||||
entry = {
|
entry = {
|
||||||
pk: sk,
|
pk: sk.publicKey,
|
||||||
data: cid.toRegistryEntry(),
|
data: cid.toRegistryEntry(),
|
||||||
revision,
|
revision,
|
||||||
} as unknown as SignedRegistryEntry;
|
} as unknown as SignedRegistryEntry;
|
||||||
} else {
|
}
|
||||||
if (!equalBytes(sk.publicKey, entry.pk)) {
|
|
||||||
throwValidationError(
|
if (!equalBytes(sk.publicKey, entry.pk)) {
|
||||||
"entry.pk", // name of the variable
|
throwValidationError(
|
||||||
Buffer.from(entry.pk).toString("hex"), // actual value
|
"entry.pk", // name of the variable
|
||||||
"result", // valueKind (assuming it's a function parameter)
|
Buffer.from(entry.pk).toString("hex"), // actual value
|
||||||
Buffer.from(sk.publicKey).toString("hex"), // expected description
|
"result", // valueKind (assuming it's a function parameter)
|
||||||
);
|
Buffer.from(sk.publicKey).toString("hex"), // expected description
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (existing) {
|
||||||
|
if (equalBytes(entry.data, cid.toRegistryEntry())) {
|
||||||
|
return entry;
|
||||||
}
|
}
|
||||||
|
|
||||||
entry.revision++;
|
entry.revision++;
|
||||||
}
|
}
|
||||||
|
|
||||||
const signedEntry = signRegistryEntry({
|
const signedEntry = signRegistryEntry({
|
||||||
kp: sk,
|
kp: sk,
|
||||||
data: entry.data,
|
data: entry.data,
|
||||||
|
|
Loading…
Reference in New Issue