merkle-verification
Skill15 starsChanged 59 days agoMITView on GitHub
- Category: storage - SDK: @0gfoundation/0g-storage-ts-sdk ^1.2.12 - Activation Triggers: "verify file", "merkle proof", "data integrity", "root hash", "check file" Compute root hashes and verify data integrity for files stored on 0G Storage. Uses Merkle tree proofs to cryptographically verify that downloaded data matches what was originally uploaded.
- Reads credentials
In this repository26 other files it gives its agents.
- AGENTS.mdAGENTS.md
- CLAUDE.mdCLAUDE.md
- agent-accountsSkill
- agent-reputationSkill
- deploy-agentSkill
- interact-agentSkill
- manage-agentSkill
- deploy-contractSkill
- interact-contractSkill
- scaffold-projectSkill
- account-managementSkill
- embeddingsSkill
- fine-tuningSkill
- image-editingSkill
- provider-discoverySkill
- speech-to-textSkill
- streaming-chatSkill
- text-to-imageSkill
- video-generationSkill
- compute-plus-storageSkill
- storage-plus-chainSkill
- 0g-pc-setupSkill
- 0g-pc-switch-modelSkill
- 0g-pc-uninstallSkill
- download-fileSkill
- upload-fileSkill
The file
We split this skill into the rules it gives an agent
2 rules. About 0 are common, 0 are distinctive, and 2 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈0
Distinctive · estimate
This author's own choices. Worth a look.
2
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 22
Create a ZgFile from the file to verify
- Very specific: line 33
Use verified downloads (true flag) for automatic verification
≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Merkle Verification
Metadata
- Category: storage
- SDK:
@0gfoundation/0g-storage-ts-sdk^1.2.12 - Activation Triggers: "verify file", "merkle proof", "data integrity", "root hash", "check file"
Purpose
Compute root hashes and verify data integrity for files stored on 0G Storage. Uses Merkle tree proofs to cryptographically verify that downloaded data matches what was originally uploaded.
Prerequisites
- Node.js >= 18
@0gfoundation/0g-storage-ts-sdkinstalled
Quick Workflow
- Create a
ZgFilefrom the file to verify - Generate the Merkle tree
- Extract the root hash
- Compare against the expected root hash
- Close the file handle
Core Rules
ALWAYS
- Close file handles after computing the Merkle tree
- Use verified downloads (
trueflag) for automatic verification - Store root hashes securely — they are your proof of data identity
NEVER
- Skip verification for production data
- Trust a root hash without verifying the source
Code Examples
Compute Root Hash
import { ZgFile } from '@0gfoundation/0g-storage-ts-sdk';
async function computeRootHash(filePath: string): Promise<string> {
const file = await ZgFile.fromFilePath(filePath);
try {
const [tree, err] = await file.merkleTree();
if (err) throw new Error(`Merkle tree error: ${err}`);
return tree.rootHash();
} finally {
await file.close();
}
}
// Usage
const hash = await computeRootHash('./my-file.pdf');
console.log('Root hash:', hash);Verify File Integrity
import { ZgFile } from '@0gfoundation/0g-storage-ts-sdk';
async function verifyFile(filePath: string, expectedHash: string): Promise<boolean> {
const file = await ZgFile.fromFilePath(filePath);
try {
const [tree, err] = await file.merkleTree();
if (err) return false;
const actualHash = tree.rootHash();
const isValid = actualHash === expectedHash;
console.log(`Expected: ${expectedHash}`);
console.log(`Actual: ${actualHash}`);
console.log(`Valid: ${isValid}`);
return isValid;
} finally {
await file.close();
}
}
// Usage
const isValid = await verifyFile('./downloaded-file.pdf', '0xabc123...');
if (!isValid) {
console.error('File integrity check failed!');
}Verified Download (Automatic Verification)
import { Indexer } from '@0gfoundation/0g-storage-ts-sdk';
async function downloadAndVerify(rootHash: string, outputPath: string): Promise<void> {
const indexer = new Indexer(process.env.STORAGE_INDEXER!);
// The third parameter enables automatic Merkle proof verification
// Throws an error if verification fails
await indexer.download(rootHash, outputPath, true);
console.log('Downloaded and verified successfully');
}Compare Two Files
async function filesMatch(filePath1: string, filePath2: string): Promise<boolean> {
const hash1 = await computeRootHash(filePath1);
const hash2 = await computeRootHash(filePath2);
return hash1 === hash2;
}Anti-Patterns
// BAD: Not closing file handle
const file = await ZgFile.fromFilePath('data.txt');
const [tree] = await file.merkleTree();
const hash = tree.rootHash();
// file.close() never called — memory leak!
// BAD: Unverified download in production
await indexer.download(rootHash, outputPath, false); // No verification!
// BAD: Comparing hashes case-sensitively when format may differ
if (hash1 === hash2) // Could fail if one is checksummedCommon Errors & Fixes
| Error | Cause | Fix |
Merkle tree error | Empty or corrupted file | Verify file has content |
Verification failed | Data was tampered with | Re-download from 0G Storage |
ENOENT | File path doesn't exist | Check file path |
Related Skills
- Upload File — generates root hash during upload
- Download File — can auto-verify during download
References
- Storage Patterns
- Security Patterns
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

