git ssb

0+

wanderer🌟 / js-dfinity-radix-tree



Commit 0a2d802a01a22250ddbe078ebe6580c59d300dfd

updated readme

Signed-off-by: wanderer <mjbecze@gmail.com>
wanderer committed on 10/3/2017, 6:24:11 AM
Parent: c3ceee3d4a1abc0272ae876b02e06c9fb67ee82a

Files changed

README.mdchanged
datastore.jsadded
README.mdView
@@ -1,13 +1,10 @@
1-[![NPM Package](https://img.shields.io/npm/v/merkle-radix-tree.svg?style=flat-square)](https://www.npmjs.org/package/merkle-radix-tree)
2-[![Build Status](https://img.shields.io/travis/primea/js-primea-radix-tree.svg?branch=master&style=flat-square)](https://travis-ci.org/primea/js-primea-radix-tree)
3-[![Coverage Status](https://img.shields.io/coveralls/primea/js-primea-radix-tree.svg?style=flat-square)](https://coveralls.io/primea/js-primea-radix-tree)
1 +[![NPM Package](https://img.shields.io/npm/v/dfinit-radix-tree.svg?style=flat-square)](https://www.npmjs.org/package/dfinity-radix-tree)
2 +[![Build Status](https://img.shields.io/travis/primea/js-dfinity-radix-tree.svg?branch=master&style=flat-square)](https://travis-ci.org/primea/js-dfinity-radix-tree)
3 +[![Coverage Status](https://img.shields.io/coveralls/primea/js-dfinity-radix-tree.svg?style=flat-square)](https://coveralls.io/primea/js-dfinity-radix-tree)
44
55 [![js-standard-style](https://cdn.rawgit.com/feross/standard/master/badge.svg)](https://github.com/feross/standard)
66
7-# install
8-`npm install js-dfinity-radix-tree`
9-
107 # SYNOPSIS
118 This implements a binary merkle radix tree. The point of using a binary radix
129 tree is that it generates smaller proof size then trees with larger radixes.
1310 This tree is well suited for storing large dictonaries of fairly random keys.
@@ -16,9 +13,9 @@
1613 top of [ipld-graph-builder](https://github.com/ipld/js-ipld-graph-builder)
1714 and the resulting state and proofs are generated using it.
1815
1916 # INSTALL
20-`npm install js-dfinity-radix-tree`
17 +`npm install dfinity-radix-tree`
2118
2219 # USAGE
2320
2421 ```javascript
datastore.jsView
@@ -1,0 +1,40 @@
1 +const Buffer = require('safe-buffer').Buffer
2 +const crypto = require('node-webcrypto-shim')
3 +const DAG = require('ipld-graph-builder/datastore.js')
4 +const treeNode = require('./treeNode.js')
5 +const HASH_LEN = 20
6 +
7 +module.exports = class TreeDAG extends DAG {
8 + async put (val) {
9 + const encoded = treeNode.encode(val)
10 + let key = await crypto.subtle.digest({
11 + name: 'SHA-256'
12 + }, encoded)
13 +
14 + key = Buffer.from(key.slice(0, HASH_LEN))
15 +
16 + return new Promise((resolve, reject) => {
17 + this._dag.put(key, encoded.toString('hex'), () => {
18 + resolve(key)
19 + })
20 + })
21 + }
22 +
23 + get (link) {
24 + return new Promise((resolve, reject) => {
25 + this._dag.get(link, (err, val) => {
26 + if (err) {
27 + reject(err)
28 + } else {
29 + val = Buffer.from(val, 'hex')
30 + const decoded = treeNode.decode(val)
31 + resolve(decoded)
32 + }
33 + })
34 + })
35 + }
36 +
37 + isValidLink (link) {
38 + return Buffer.isBuffer(link) && link.length === HASH_LEN
39 + }
40 +}

Built with git-ssb-web