@0xcert/merkle
Version:
Implementation of basic functions of binary Merkle tree.
52 lines • 2.96 kB
JavaScript
;
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('recreate 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);
const imprint = yield ctx.get('merkle').imprint(minRecipe);
ctx.is(imprint, fullRecipe.nodes[0].hash);
}));
spec.test('recreate from A, B, C, D with exposed indexes 1, 2', (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);
const imprint = yield ctx.get('merkle').imprint(minRecipe);
ctx.is(imprint, fullRecipe.nodes[0].hash);
}));
spec.test('recreate from from A, B, C, D, E, F, G, H with exposed indexes 7', (ctx) => __awaiter(void 0, void 0, void 0, function* () {
const values = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H'];
const expose = [7];
const fullRecipe = yield ctx.get('merkle').notarize(values);
const minRecipe = yield ctx.get('merkle').disclose(fullRecipe, expose);
const imprint = yield ctx.get('merkle').imprint(minRecipe);
ctx.is(imprint, fullRecipe.nodes[0].hash);
}));
spec.test('recreate from from A, B, C, D, E, F, G, H with exposed indexes 3, 5, 6', (ctx) => __awaiter(void 0, void 0, void 0, function* () {
const values = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H'];
const expose = [3, 5, 6];
const fullRecipe = yield ctx.get('merkle').notarize(values);
const minRecipe = yield ctx.get('merkle').disclose(fullRecipe, expose);
const imprint = yield ctx.get('merkle').imprint(minRecipe);
ctx.is(imprint, fullRecipe.nodes[0].hash);
}));
exports.default = spec;
//# sourceMappingURL=imprint-instance-method.test.js.map