npm.io
0.1.3 • Published 3 years ago

@whi/holochain-serialization

Licence
ISC
Version
0.1.3
Deps
1
Size
203 kB
Vulns
0
Weekly
0
Stars
3
DeprecatedThis package is deprecated

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 @whi/holochain-serialization

Basic Usage

import crypto from 'crypto';
import { encode } from '@msgpack/msgpack';
import { AgentPubKey, DnaHash } from '@whi/holo-hash';
import { hashZomeCall } from '@whi/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