0.1.3 • Published 1 year ago

@whi/holochain-serialization v0.1.3

Weekly downloads
-
License
ISC
Repository
github
Last release
1 year ago

npm.io

Holochain Serialization

A (pure) Javascript library for signing Holochain zome call input.

npm.io npm.io npm.io

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

0.1.3

1 year ago

0.1.2

1 year ago

0.1.1

1 year ago

0.1.0

1 year ago