NIL Zonefile
A Rust library for parsing and creating NIL zonefiles. This library supports both WebAssembly and native Rust environments.
Installation
Add this to your Cargo.toml
:
[]
= "0.1.0"
For WebAssembly support, enable the wasm
feature:
[]
= { = "0.1.0", = ["wasm"] }
Usage
Rust
use ZoneFile;
JavaScript/TypeScript (via WebAssembly)
=
import { ZoneFile } from 'nil-zonefile';
const zonefile = ZoneFile.fromString(jsonString);
const output = zonefile.toString();
Rust CBOR Support
use ZoneFile;
JavaScript CBOR Support
import { parse_zonefile_cbor, create_zonefile_cbor } from 'nil-zonefile';
// Read from CBOR
const cborBytes = new Uint8Array(/* your CBOR data */);
const result = parse_zonefile_cbor(cborBytes);
// Write to CBOR
const output = create_zonefile_cbor(cborBytes);
Generate Zonefile
import { generateZonefile } from 'nil-zonefile';
const zonefile = {
zonefile: {
owner: "SP3D03X5BHMNSAAW71NN7BQRMV4DW2G4JB3MZAGJ8",
general: "Example Name",
twitter: "@example",
url: "example.locker",
nostr: "",
lightning: "",
btc: "bc1...",
subdomains: {}
},
version: "1.0.0",
status: "current"
};
// Generate uncompressed CBOR
const bytes = generateZonefile(zonefile);
// Generate compressed CBOR using zstd compression
const compressedBytes = generateZonefile(zonefile, true);
Building on macOS
When building this project on macOS (especially for WebAssembly), you need LLVM installed and configured correctly. Two options are available:
Option 1: Using the Setup Script
Run the provided setup script:
This script will:
- Check if you're on macOS
- Install LLVM via Homebrew if needed
- Set up the required environment variables
Option 2: Manual Setup
-
Install LLVM if you haven't already:
-
Set up the required environment variables:
To make these changes permanent, add the above lines to your
~/.zshrc
or~/.bash_profile
.
License
MIT License - Copyright (c) 2025 New Internet Labs Limited