@spartan-hc/holochain-serialization
v0.2.0
Published
A Javascript library for signing Holochain zome call input
Downloads
26
Readme
Holochain Serialization
A (pure) Javascript library for signing Holochain zome call input.
Overview
Features
- Serialize objects using
@msgpack/msgpack
encoder (sorted keys) - Hash using blake2b 256 bit digest
- Special serialization for
ZomeCallUnsigned
- key order must match the Rust struct key order
Install
npm i @spartan-hc/holochain-serialization
Basic Usage
import crypto from 'crypto';
import { encode } from '@msgpack/msgpack';
import { AgentPubKey, DnaHash } from '@spartan-hc/holo-hash';
import { hashZomeCall } from '@spartan-hc/holochain-serialization';
import ed25519 from 'some_ed25519_library'; // Not a real ed25519 library
const key_pair = ed25519.keyPair();
const agent_hash = new AgentPubKey( key_pair.publicKey );
const dna_hash = new DnaHash( crypto.randomBytes(32) );
const zome_call_request = {
"cap_secret": null,
"cell_id": [ dna_hash, agent_hash ],
"zome_name": "zome",
"fn_name": "function",
"payload": encode( null ),
"provenance": agent_hash,
"nonce": crypto.randomBytes( 32 ),
"expires_at": (Date.now() + (5 * 60 * 1_000)) * 1_000,
};
const digest = hashZomeCall( zome_call_request );
zome_call_request.signature = ed25519.sign( digest, key_pair.privateKey );
API Reference
See docs/API.md
Contributing
See CONTRIBUTING.md