Skip to content

Latest commit

 

History

History
293 lines (171 loc) · 9.77 KB

index.md

File metadata and controls

293 lines (171 loc) · 9.77 KB

SecureTrie

secure.js:13-16

You can create a secure Trie where the keys are automatically hashed using SHA3 by using require('merkle-patricia-tree/secure'). It has the same methods and constuctor as Trie

Trie

baseTrie.js:26-57

Use require('merkel-patricia-tree') for the base interface. In Vapory applications stick with the Secure Trie Overlay require('merkel-patricia-tree/secure'). The API for the raw and the secure interface are about the same

Parameters

  • db [Object] An instance of levelup or a compatible API. If the db is null or left undefined, then the trie will be stored in memory via memdown
  • root [Buffer or String] A hexStringorBuffer` for the root of a previously stored trie

Properties

  • root Buffer The current root of the trie
  • isCheckpoint Boolean determines if you are saving to a checkpoint or directly to the db
  • EMPTY_TRIE_ROOT Buffer the Root for an empty trie

batch

baseTrie.js:710-722

The given hash of operations (key additions or deletions) are executed on the DB

Parameters

  • ops Array
  • cb Function

Examples

var ops = [
   { type: 'del', key: 'father' }
 , { type: 'put', key: 'name', value: 'Yuri Irsenovich Kim' }
 , { type: 'put', key: 'dob', value: '16 February 1941' }
 , { type: 'put', key: 'spouse', value: 'Kim Young-sook' }
 , { type: 'put', key: 'occupation', value: 'Clown' }
]
trie.batch(ops)

checkRoot

baseTrie.js:730-735

Checks if a given root exists

Parameters

  • root Buffer
  • cb Function

createReadStream

baseTrie.js:685-687

The data event is given an Object hat has two properties; the key and the value. Both should be Buffers.

Returns stream.Readable Returns a stream of the contents of the trie

del

baseTrie.js:121-139

deletes a value given a key

Parameters

  • key Buffer or String
  • cb Function the callback Function

delRaw

baseTrie.js:211-218

Removes a raw value in the underlying db

Parameters

  • key Buffer or String
  • cb Function A callback Function, which is given the argument err - for errors that may have occured

get

baseTrie.js:65-78

Gets a value given a key

Parameters

  • key Buffer or String the key to search for
  • callback Function A callback Function which is given the arguments err - for errors that may have occured and value - the found value in a Buffer or if no value was found null

getRaw

baseTrie.js:147-163

Retrieves a raw value in the underlying db

Parameters

  • key Buffer
  • cb Function A callback Function, which is given the arguments err - for errors that may have occured and value - the found value in a Buffer or if no value was found null.

put

baseTrie.js:87-113

Stores a given value at the given key

Parameters

  • key Buffer or String
  • Value Buffer or String
  • callback Function A callback Function which is given the argument err - for errors that may have occured

putRaw

baseTrie.js:202-202

Writes a value directly to the underlining db

Parameters

  • key Buffer or String The key as a Buffer or String
  • value Buffer The value to be stored
  • callback Function A callback Function, which is given the argument err - for errors that may have occured

checkpoint

checkpoint-interface.js:37-44

Creates a checkpoint that can later be reverted to or committed. After this is called, no changes to the trie will be permanently saved until commit is called

commit

checkpoint-interface.js:51-67

commits a checkpoint to disk

revert

checkpoint-interface.js:74-89

Reverts the trie to the state it was at when checkpoint was first called.

Parameters

  • cb Function the callback

findPath

baseTrie.js:252-300

Trys to find a path to the node for the given key. It returns a stack of nodes to the closet node.

Parameters

  • Function cb - the callback function. Its is given the following arguments- err - any errors encontered
    • node - the last node found
    • keyRemainder - the remaining key nibbles not accounted for
    • stack - an array of nodes that forms the path to node we are searching for
  • targetKey
  • cb

Merkle Proof

Static functions for creating/verifying a merkle proof.

prove

proof.js:12-29

Returns a merkle proof for a given key

Parameters

  • trie Trie
  • key String
  • cb Function A callback Function (arguments {Error} err, {Array.} proof)

verifyProof

proof.js:39-95

Verifies a merkle proof for a given key

Parameters

  • rootHash Buffer
  • key String
  • proof Array<TrieNode>
  • cb Function A callback Function (arguments {Error} err, {String} val)

Internal Util Functions

These are not exposed.

addHexPrefix

trieNode.js:164-179

Parameters

  • dataArr Array
  • key
  • terminator

Returns Buffer returns buffer of encoded data hexPrefix

asyncFirstSeries

util.js:62-78

Take a collection of async fns, call the cb on the first to return a truthy value. If all run without a truthy result, return undefined

Parameters

  • array
  • iterator
  • cb

callTogether

util.js:36-56

Take two or more functions and returns a function that will execute all of the given functions

Parameters

  • cb Function the callback

doKeysMatch

util.js:27-30

Compare two 'nibble array' keys

Parameters

  • keyA
  • keyB

matchingNibbleLength

util.js:16-22

Returns the number of in order matching nibbles of two give nibble arrayes

Parameters

  • nib1 Array
  • nib2 Array

_saveStack

baseTrie.js:502-529

saves a stack

Parameters

  • key Array the key. Should follow the stack
  • stack Array a stack of nodes to the value given by the key
  • opStack Array a stack of levelup operations to commit at the end of this funciton
  • cb Function

_updateNode

baseTrie.js:358-423

Updates a node

Parameters

  • key Buffer
  • value Buffer or String
  • keyRemainder Array
  • stack Array -
  • cb Function the callback