fix: only submit a new registry entry if the data has changed
This commit is contained in:
parent
704e78b421
commit
39b0117e4f
36
src/index.ts
36
src/index.ts
|
@ -6,6 +6,7 @@ import fs from "fs/promises";
|
||||||
import path from "path";
|
import path from "path";
|
||||||
import {
|
import {
|
||||||
concatBytes,
|
concatBytes,
|
||||||
|
equalBytes,
|
||||||
hexToBytes,
|
hexToBytes,
|
||||||
maybeInitDefaultPortals,
|
maybeInitDefaultPortals,
|
||||||
setActivePortalMasterKey,
|
setActivePortalMasterKey,
|
||||||
|
@ -27,6 +28,7 @@ import {
|
||||||
Logger,
|
Logger,
|
||||||
REGISTRY_TYPES,
|
REGISTRY_TYPES,
|
||||||
S5NodeConfig,
|
S5NodeConfig,
|
||||||
|
SignedRegistryEntry,
|
||||||
} from "@lumeweb/libs5";
|
} from "@lumeweb/libs5";
|
||||||
|
|
||||||
import { MemoryLevel } from "memory-level";
|
import { MemoryLevel } from "memory-level";
|
||||||
|
@ -162,6 +164,7 @@ await peerDefer.promise;
|
||||||
const key = hdKey as HDKey;
|
const key = hdKey as HDKey;
|
||||||
|
|
||||||
let revision = 0;
|
let revision = 0;
|
||||||
|
let sre: SignedRegistryEntry;
|
||||||
|
|
||||||
const ret = await node.services.registry.get(
|
const ret = await node.services.registry.get(
|
||||||
new KeyPairEd25519(key.privateKey).publicKey,
|
new KeyPairEd25519(key.privateKey).publicKey,
|
||||||
|
@ -170,20 +173,27 @@ await peerDefer.promise;
|
||||||
if (ret) {
|
if (ret) {
|
||||||
revision = ret.revision + 1;
|
revision = ret.revision + 1;
|
||||||
}
|
}
|
||||||
const sre = node.services.registry.signRegistryEntry({
|
|
||||||
kp: new KeyPairEd25519((hdKey as HDKey).privateKey),
|
|
||||||
data: concatBytes(
|
|
||||||
Uint8Array.from([
|
|
||||||
REGISTRY_TYPES.CID,
|
|
||||||
CID_TYPES.RESOLVER,
|
|
||||||
CID_HASH_TYPES.BLAKE3,
|
|
||||||
]),
|
|
||||||
cidBytes,
|
|
||||||
),
|
|
||||||
revision,
|
|
||||||
});
|
|
||||||
|
|
||||||
await node.services.registry.set(sre);
|
const newEntry = concatBytes(
|
||||||
|
Uint8Array.from([
|
||||||
|
REGISTRY_TYPES.CID,
|
||||||
|
CID_TYPES.RESOLVER,
|
||||||
|
CID_HASH_TYPES.BLAKE3,
|
||||||
|
]),
|
||||||
|
cidBytes,
|
||||||
|
);
|
||||||
|
|
||||||
|
if (!equalBytes(ret?.data ?? new Uint8Array(), newEntry)) {
|
||||||
|
sre = node.services.registry.signRegistryEntry({
|
||||||
|
kp: new KeyPairEd25519((hdKey as HDKey).privateKey),
|
||||||
|
data: newEntry,
|
||||||
|
revision,
|
||||||
|
});
|
||||||
|
|
||||||
|
await node.services.registry.set(sre);
|
||||||
|
} else {
|
||||||
|
sre = ret as SignedRegistryEntry;
|
||||||
|
}
|
||||||
|
|
||||||
console.log(
|
console.log(
|
||||||
util.format(
|
util.format(
|
||||||
|
|
Loading…
Reference in New Issue