@0xcert/merkle
Advanced tools
Comparing version 0.0.0-alpha3 to 0.0.0-alpha4
@@ -5,4 +5,4 @@ { | ||
{ | ||
"version": "0.0.0-alpha3", | ||
"tag": "@0xcert/merkle_v0.0.0-alpha3", | ||
"version": "0.0.0-alpha4", | ||
"tag": "@0xcert/merkle_v0.0.0-alpha4", | ||
"date": "Thu, 22 Nov 2018 00:51:03 GMT", | ||
@@ -9,0 +9,0 @@ "comments": {} |
@@ -5,3 +5,3 @@ # Change Log - @0xcert/merkle | ||
## 0.0.0-alpha3 | ||
## 0.0.0-alpha4 | ||
Thu, 22 Nov 2018 00:51:03 GMT | ||
@@ -8,0 +8,0 @@ |
@@ -14,8 +14,8 @@ export declare type MerkleHasher = ((v: any) => string) | ((v: any) => Promise<string>); | ||
} | ||
export interface MerkleConfig { | ||
export interface MerkleOptions { | ||
hasher?: MerkleHasher; | ||
} | ||
export declare class Merkle { | ||
protected config: MerkleConfig; | ||
constructor(config?: MerkleConfig); | ||
protected $options: MerkleOptions; | ||
constructor(options?: MerkleOptions); | ||
notarize(data: (string | number | boolean)[]): Promise<{ | ||
@@ -22,0 +22,0 @@ values: { |
@@ -12,4 +12,4 @@ "use strict"; | ||
class Merkle { | ||
constructor(config) { | ||
this.config = Object.assign({ hasher: (v) => v }, config); | ||
constructor(options) { | ||
this.$options = Object.assign({ hasher: (v) => v }, options); | ||
} | ||
@@ -19,9 +19,9 @@ notarize(data) { | ||
const values = [...data]; | ||
const nodes = [yield this.config.hasher('')]; | ||
const nodes = [yield this.$options.hasher('')]; | ||
for (let i = values.length - 1; i >= 0; i--) { | ||
const right = nodes[0]; | ||
const value = values[i]; | ||
nodes.unshift(yield this.config.hasher(value)); | ||
nodes.unshift(yield this.$options.hasher(value)); | ||
const left = nodes[0]; | ||
nodes.unshift(yield this.config.hasher(`${left}${right}`)); | ||
nodes.unshift(yield this.$options.hasher(`${left}${right}`)); | ||
} | ||
@@ -58,3 +58,3 @@ return { | ||
index: v.index * 2 + 1, | ||
hash: yield this.config.hasher(v.value), | ||
hash: yield this.$options.hasher(v.value), | ||
value: v.value | ||
@@ -72,3 +72,3 @@ }); | ||
index: i - 2, | ||
hash: yield this.config.hasher(`${left.hash}${right.hash}`), | ||
hash: yield this.$options.hasher(`${left.hash}${right.hash}`), | ||
}); | ||
@@ -75,0 +75,0 @@ } |
{ | ||
"files": { | ||
"packages/0xcert-merkle/CHANGELOG.json": "c834037b3ac868766044b38984d26819079773ce", | ||
"packages/0xcert-merkle/CHANGELOG.md": "0a9e01de51537048f3bf3f0d916dd2bc66e1c5d4", | ||
"packages/0xcert-merkle/CHANGELOG.json": "0aef3b60e80a605ed10b44843e427be9a6f6158b", | ||
"packages/0xcert-merkle/CHANGELOG.md": "c93b732554220c4f9689704ec8908e9e8ddcfbd9", | ||
"packages/0xcert-merkle/README.md": "f6e5733c5260faa8370cd755dae8f5af2f38a3fc", | ||
"packages/0xcert-merkle/nodemon.json": "82b893373db9861f1df4b55d8ea68a5d37b118de", | ||
"packages/0xcert-merkle/package.json": "894089b25d613c3d9f45b9eced934c85cb51fdda", | ||
"packages/0xcert-merkle/src/core/merkle.ts": "9a3f42523d73242de94a6bd4bce7c2247914e7a8", | ||
"packages/0xcert-merkle/package.json": "ae4eb3bbd2448c8f8c0572869a7164e55f79caa7", | ||
"packages/0xcert-merkle/src/core/merkle.ts": "4bf83b0caf30059846519987ff62587c37f34162", | ||
"packages/0xcert-merkle/src/index.ts": "d6e89de6faec0b508d09239bf458d7a8a26e4775", | ||
@@ -15,5 +15,5 @@ "packages/0xcert-merkle/src/tests/core/merkle/disclose-instance-method.test.ts": "5f930e26e52b08f0cdf6d750c4288cd59d15d865", | ||
"packages/0xcert-merkle/tsconfig.json": "4aeac3c20e45b7e477e82012eb7788f7dbb11bf3", | ||
"common/config/rush/npm-shrinkwrap.json": "9dea1ec1c34d5bcf4df825f8250513472c8f14f2" | ||
"common/config/rush/npm-shrinkwrap.json": "85e9a2392b6dc8ee32e79467374e9a32d2631090" | ||
}, | ||
"arguments": "npx hayspec test " | ||
"arguments": "npm run clean && npx tsc " | ||
} |
{ | ||
"name": "@0xcert/merkle", | ||
"version": "0.0.0-alpha3", | ||
"version": "0.0.0-alpha4", | ||
"description": "Merkle tree management tool.", | ||
@@ -22,3 +22,3 @@ "main": "./dist/index.js", | ||
"devDependencies": { | ||
"@0xcert/utils": "0.0.0-alpha3", | ||
"@0xcert/utils": "0.0.0-alpha4", | ||
"@hayspec/cli": "^0.7.6", | ||
@@ -25,0 +25,0 @@ "@hayspec/spec": "^0.7.6", |
@@ -33,3 +33,3 @@ /** | ||
*/ | ||
export interface MerkleConfig { | ||
export interface MerkleOptions { | ||
hasher?: MerkleHasher; | ||
@@ -42,3 +42,3 @@ } | ||
export class Merkle { | ||
protected config: MerkleConfig; | ||
protected $options: MerkleOptions; | ||
@@ -48,6 +48,6 @@ /** | ||
*/ | ||
public constructor(config?: MerkleConfig) { | ||
this.config = { | ||
public constructor(options?: MerkleOptions) { | ||
this.$options = { | ||
hasher: (v) => v, | ||
...config, | ||
...options, | ||
}; | ||
@@ -62,3 +62,3 @@ } | ||
const values = [...data]; | ||
const nodes = [await this.config.hasher('')]; | ||
const nodes = [await this.$options.hasher('')]; | ||
@@ -69,7 +69,7 @@ for (let i = values.length - 1; i >= 0; i--) { | ||
nodes.unshift( | ||
await this.config.hasher(value) | ||
await this.$options.hasher(value) | ||
); | ||
const left = nodes[0]; | ||
nodes.unshift( | ||
await this.config.hasher(`${left}${right}`) | ||
await this.$options.hasher(`${left}${right}`) | ||
); | ||
@@ -122,3 +122,3 @@ } | ||
index: v.index * 2 + 1, | ||
hash: await this.config.hasher(v.value), | ||
hash: await this.$options.hasher(v.value), | ||
value: v.value | ||
@@ -138,3 +138,3 @@ })) | ||
index: i - 2, | ||
hash: await this.config.hasher(`${left.hash}${right.hash}`), | ||
hash: await this.$options.hasher(`${left.hash}${right.hash}`), | ||
}); | ||
@@ -141,0 +141,0 @@ } |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
39768