@spacesprotocol/libveritas
v0.0.0-dev.20260401231450
Published
JavaScript/WASM bindings for [libveritas](https://github.com/spacesprotocol/libveritas) — stateless verification for Bitcoin handles using the [Spaces protocol](https://spacesprotocol.org).
Readme
@spacesprotocol/libveritas
JavaScript/WASM bindings for libveritas — stateless verification for Bitcoin handles using the Spaces protocol.
Installation
npm install @spacesprotocol/libveritasUsage
Verifying a message
import { Veritas, QueryContext, Message } from "@spacesprotocol/libveritas";
// Load trust anchors
const veritas = new Veritas(anchors);
console.log(`Anchors: ${veritas.oldestAnchor()} .. ${veritas.newestAnchor()}`);
// Build query context (empty = verify all handles)
const ctx = new QueryContext();
ctx.addRequest("alice@bitcoin");
// Verify a message (binary data from relay)
const msg = new Message(messageBytes);
const result = veritas.verifyMessage(ctx, msg);
// Inspect verified zones
for (const zone of result.zones()) {
console.log(`${zone.handle()} -> ${zone.sovereignty()}`);
// Store zone for later comparison
const bytes = zone.toBytes();
}
// Compare zones
const better = newerZone.isBetterThan(olderZone);
// Get certificates
for (const cert of result.certificates()) {
console.log(cert);
}Building a message
import { MessageBuilder, RecordSet, OffchainData } from "@spacesprotocol/libveritas";
// Construct offchain data
let rs = new RecordSet(1, { nostr: "npub1...", ipv4: "127.0.0.1" });
let sig = wallet.signSchnorr(rs.id());
let offchainBytes = OffchainData.from(rs, sig);
// Build a message with certificates and offchain data
let builder = new MessageBuilder([
{ name: "@bitcoin", cert: rootCertBytes },
{ name: "alice@bitcoin", offchainData: offchainBytes, cert: leafCertBytes },
]);
// Get the chain proof request to send to a provider
let request = builder.chainProofRequest();
// ... send request to provider, get chain proof back ...
let msg = builder.build(chainProofBytes);
// Serialize for transport
let bytes = msg.toBytes();Updating offchain data
// Update offchain data on a verified message (no cert changes)
let msg = result.message();
let rs = new RecordSet(2, { nostr: "npub1new..." });
let sig = wallet.signSchnorr(rs.id());
let offchainBytes = OffchainData.from(rs, sig);
msg.update([
{ name: "alice@bitcoin", offchainData: offchainBytes },
]);
let updatedBytes = msg.toBytes();Building from source
cargo install wasm-pack
wasm-pack build bindings/wasm --target web