0.1.0 • Published 2 years ago
@whi/holochain-prototyping v0.1.0
Holohain Prototyping (for Node.js)
A Javascript library for quickly prototyping Holochain integrity models
Overview
Install
npm i @whi/holochain-prototypingUsage
Import
import {
    Cell, DNA,
    AppEntryType,
} from '@whi/holochain-prototyping';Basic
Example
import { AgentPubKey } from '@whi/holo-hash';
class PostEntry extends AppEntryType {
    static struct               = {
        "published_at": Number,
        "author": AgentPubKey,
        "message": String,
    };
}
const dna                       = new DNA([
    {
        "EntryTypes": [
            PostEntry,
        ],
        "LinkTypes": [
            "Post",
        ],
        "validation": (op) => {
	    // ...validation code
	},
    },
]);
const agent = new AgentPubKey( crypto.randomBytes(32) );
const cell = new Cell( agent, dna );
cell.run( 0, () => {
    const {
        agent_info,
        hash_entry,
        create_entry,
        create_link,
    } = HDK;
    const agent = agent_info().agent_initial_pubkey;
    const post = new EntryTypes.PostEntry({
        "published_at": Date.now(),
        "author": agent,
        "message": "Hello world",
    });
    const address = hash_entry( post );   // EntryHash
    const post_id = create_entry( post ); // ActionHash
    create_link( agent, post_id, LinkTypes.Post, tag );
});Contributing
See CONTRIBUTING.md
0.1.0
2 years ago