Skip to content

Latest commit

 

History

History
106 lines (79 loc) · 2.09 KB

File metadata and controls

106 lines (79 loc) · 2.09 KB

back to README.md

API Reference

serialize( input, key_order )

Serialize any input using msgpack encoding

  • input - (required) any input that can be msgpack'ed
  • key_order - (optional) a list of ordered keys
    • default to use msgpack sort keys

Returns Uint8Array

Example

const bytes = serialize( "Hello world" );

serializeKeyOrder( input, key_order )

Serialize any input using msgpack encoding with sort keys enabled

  • input - (required) any input that can be msgpack'ed
  • key_order - (required) a list of ordered keys

Returns Uint8Array

Example

const bytes = serializeKeyOrder({
    "3": null,
    "two": null,
    "one": null,
    "4": null,
}, [ "one", "two", "3", "4" ] );

hash( input )

Hash any input using serialize.

Returns Uint8Array(32)

Example

const digest = hash( "Hello world" );

serializeZomeCall( zome_call_unsigned )

Serialize unsigned zome call input with keys sorted according to the Rust equivalent

Returns Uint8Array

Example

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 bytes = serializeZomeCall( zome_call_request );

hashZomeCall( zome_call_unsigned )

Hash input using serializeZomeCall.

Returns Uint8Array(32)

Example

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 );

Module exports

{
    serialize,
    serializeKeyOrder,
    hash,
    serializeZomeCall,
    hashZomeCall,
    blake2b,
}