UNPKG

@0xcert/merkle

Version:

Implementation of basic functions of binary Merkle tree.

60 lines 2.82 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; Object.defineProperty(exports, "__esModule", { value: true }); const utils_1 = require("@0xcert/utils"); const spec_1 = require("@hayspec/spec"); const __1 = require("../../.."); const spec = new spec_1.Spec(); spec.before((ctx) => __awaiter(void 0, void 0, void 0, function* () { ctx.set('merkle', new __1.Merkle({ hasher: (v) => utils_1.sha(256, v) })); })); spec.test('exposes 0 from empty array', (ctx) => __awaiter(void 0, void 0, void 0, function* () { const values = []; const expose = []; const fullRecipe = yield ctx.get('merkle').notarize(values); const minRecipe = yield ctx.get('merkle').disclose(fullRecipe, expose); ctx.deepEqual(minRecipe, { values: [], nodes: [ { index: 0, hash: 'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855' }, ], }); })); spec.test('exposes 0 from A, B, C, D', (ctx) => __awaiter(void 0, void 0, void 0, function* () { const values = ['A', 'B', 'C', 'D']; const expose = []; const fullRecipe = yield ctx.get('merkle').notarize(values); const minRecipe = yield ctx.get('merkle').disclose(fullRecipe, expose); ctx.deepEqual(minRecipe, { values: [], nodes: [ { index: 0, hash: 'b16c961cbfca86d7b78cd687729bae18f1015c742e7319d91088502a892ba166' }, ], }); })); spec.test('exposes 5 from A, B, C, D', (ctx) => __awaiter(void 0, void 0, void 0, function* () { const values = ['A', 'B', 'C', 'D']; const expose = [0, 2]; const fullRecipe = yield ctx.get('merkle').notarize(values); const minRecipe = yield ctx.get('merkle').disclose(fullRecipe, expose); ctx.deepEqual(minRecipe, { values: [ { index: 0, value: 'A', nonce: '' }, { index: 2, value: 'C', nonce: '' }, ], nodes: [ { index: 3, hash: 'acab60e972cca11cd0571b8d08fe9bfc6521565c601a3785c5f5fb0a406279e6' }, { index: 6, hash: '1bfcb70acfee69c7ef93ea300e3127715dcced515022daf9f149d395610b2cc4' }, ], }); })); exports.default = spec; //# sourceMappingURL=disclose-instance-method.test.js.map