@polkadot/trie-hash
Advanced tools
Comparing version 1.8.0-beta.2 to 1.8.0-beta.3
@@ -14,3 +14,3 @@ "use strict"; | ||
// Copyright 2017-2019 @polkadot/trie-hash authors & contributors | ||
// Copyright 2017-2020 @polkadot/trie-hash authors & contributors | ||
// This software may be modified and distributed under the terms | ||
@@ -32,4 +32,3 @@ // of the Apache-2.0 license. See the LICENSE file for details. | ||
const sharedNibbleCount = input.reduce((min, _ref, index) => { | ||
let [key] = _ref; | ||
const sharedNibbleCount = input.reduce((min, [key], index) => { | ||
return index === 0 ? key.length : Math.min(min, (0, _util.sharedPrefixLength)(key, firstKey)); | ||
@@ -49,6 +48,3 @@ }, 0); | ||
for (let index = 0; index < 16; index++) { | ||
sharedNibbleCounts[index] = input.filter((_, index) => index >= begin).filter((_ref2) => { | ||
let [key] = _ref2; | ||
return key[cursor] === index; | ||
}).length; | ||
sharedNibbleCounts[index] = input.filter((_, index) => index >= begin).filter(([key]) => key[cursor] === index).length; | ||
begin += sharedNibbleCounts[index]; | ||
@@ -72,7 +68,3 @@ } | ||
function buildTrie(input) { | ||
let cursor = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0; | ||
let codec = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : _defaults.DEFAULT_CODEC; | ||
let stream = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : _defaults.DEFAULT_STREAM; | ||
function buildTrie(input, cursor = 0, codec = _defaults.DEFAULT_CODEC, stream = _defaults.DEFAULT_STREAM) { | ||
const trie = _buildTrie(input, cursor, codec, stream); | ||
@@ -79,0 +71,0 @@ |
"use strict"; | ||
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard.js"); | ||
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard"); | ||
@@ -5,0 +5,0 @@ Object.defineProperty(exports, "__esModule", { |
"use strict"; | ||
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault.js"); | ||
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); | ||
@@ -11,14 +11,13 @@ var _chainspec = require("@polkadot/chainspec"); | ||
// Copyright 2017-2019 @polkadot/trie-hash authors & contributors | ||
// Copyright 2017-2020 @polkadot/trie-hash authors & contributors | ||
// This software may be modified and distributed under the terms | ||
// of the Apache-2.0 license. See the LICENSE file for details. | ||
describe('genesis roots', () => { | ||
[_chainspec.alexander, _chainspec.driedDanta].forEach((_ref) => { | ||
let { | ||
genesis: { | ||
raw | ||
}, | ||
genesisRoot, | ||
name | ||
} = _ref; | ||
[_chainspec.alexander, _chainspec.driedDanta].forEach(({ | ||
genesis: { | ||
raw | ||
}, | ||
genesisRoot, | ||
name | ||
}) => { | ||
it("has the correct root for ".concat(name), () => { | ||
@@ -25,0 +24,0 @@ expect((0, _util.u8aToHex)((0, _trieRoot.default)(Object.keys(raw).map(key => ({ |
"use strict"; | ||
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault.js"); | ||
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); | ||
@@ -5,0 +5,0 @@ Object.defineProperty(exports, "__esModule", { |
{ | ||
"name": "@polkadot/trie-hash", | ||
"version": "1.8.0-beta.2", | ||
"version": "1.8.0-beta.3", | ||
"description": "Generates trie roots from key-value pairs", | ||
@@ -28,8 +28,8 @@ "main": "index.js", | ||
"dependencies": { | ||
"@babel/runtime": "^7.7.5", | ||
"@polkadot/util": "^1.8.0-beta.2" | ||
"@babel/runtime": "^7.7.7", | ||
"@polkadot/util": "^1.8.0-beta.3" | ||
}, | ||
"devDependencies": { | ||
"@polkadot/chainspec": "^1.8.0-beta.2" | ||
"@polkadot/chainspec": "^1.8.0-beta.3" | ||
} | ||
} |
"use strict"; | ||
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault.js"); | ||
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); | ||
@@ -14,3 +14,3 @@ Object.defineProperty(exports, "__esModule", { | ||
// Copyright 2017-2019 @polkadot/trie-hash authors & contributors | ||
// Copyright 2017-2020 @polkadot/trie-hash authors & contributors | ||
// This software may be modified and distributed under the terms | ||
@@ -37,5 +37,4 @@ // of the Apache-2.0 license. See the LICENSE file for details. | ||
*/ | ||
function trieRoot(input) { | ||
let codec = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : _defaults.DEFAULT_CODEC; | ||
function trieRoot(input, codec = _defaults.DEFAULT_CODEC) { | ||
return codec.hashing((0, _unhashedTrie.default)(input, codec)); | ||
} |
"use strict"; | ||
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault.js"); | ||
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); | ||
@@ -11,12 +11,11 @@ var _util = require("@polkadot/util"); | ||
// Copyright 2017-2019 @polkadot/trie-hash authors & contributors | ||
// Copyright 2017-2020 @polkadot/trie-hash authors & contributors | ||
// This software may be modified and distributed under the terms | ||
// of the Apache-2.0 license. See the LICENSE file for details. | ||
describe('trieRoot', () => { | ||
Object.values(_data.default).forEach((_ref) => { | ||
let { | ||
desc, | ||
input, | ||
root | ||
} = _ref; | ||
Object.values(_data.default).forEach(({ | ||
desc, | ||
input, | ||
root | ||
}) => { | ||
it("hashes ".concat(desc), () => { | ||
@@ -23,0 +22,0 @@ expect((0, _util.u8aToHex)((0, _trieRoot.default)(input))).toEqual((0, _util.u8aToHex)(root)); |
"use strict"; | ||
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault.js"); | ||
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); | ||
@@ -16,3 +16,3 @@ Object.defineProperty(exports, "__esModule", { | ||
// Copyright 2017-2019 @polkadot/trie-hash authors & contributors | ||
// Copyright 2017-2020 @polkadot/trie-hash authors & contributors | ||
// This software may be modified and distributed under the terms | ||
@@ -39,4 +39,3 @@ // of the Apache-2.0 license. See the LICENSE file for details. | ||
*/ | ||
function trieRootOrdered(input) { | ||
let codec = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : _defaults.DEFAULT_CODEC; | ||
function trieRootOrdered(input, codec = _defaults.DEFAULT_CODEC) { | ||
return (0, _trieRoot.default)(input.map((v, index) => ({ | ||
@@ -43,0 +42,0 @@ k: (0, _util.compactToU8a)(index), |
@@ -7,3 +7,3 @@ "use strict"; | ||
// Copyright 2017-2019 @polkadot/trie-hash authors & contributors | ||
// Copyright 2017-2020 @polkadot/trie-hash authors & contributors | ||
// This software may be modified and distributed under the terms | ||
@@ -10,0 +10,0 @@ // of the Apache-2.0 license. See the LICENSE file for details. |
"use strict"; | ||
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault.js"); | ||
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); | ||
@@ -18,7 +18,6 @@ Object.defineProperty(exports, "__esModule", { | ||
// Copyright 2017-2019 @polkadot/trie-hash authors & contributors | ||
// Copyright 2017-2020 @polkadot/trie-hash authors & contributors | ||
// This software may be modified and distributed under the terms | ||
// of the Apache-2.0 license. See the LICENSE file for details. | ||
function unhashedTrie(input) { | ||
let codec = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : _defaults.DEFAULT_CODEC; | ||
function unhashedTrie(input, codec = _defaults.DEFAULT_CODEC) { | ||
const map = {}; | ||
@@ -28,10 +27,7 @@ input.forEach(pair => { | ||
}); | ||
const pairs = Object.keys(map).sort().map(key => map[key]).map((_ref) => { | ||
let { | ||
k, | ||
v | ||
} = _ref; | ||
return [(0, _util.toNibbles)(k), v]; | ||
}); | ||
const pairs = Object.keys(map).sort().map(key => map[key]).map(({ | ||
k, | ||
v | ||
}) => [(0, _util.toNibbles)(k), v]); | ||
return (0, _buildTrie.default)(pairs, 0, codec); | ||
} |
"use strict"; | ||
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault.js"); | ||
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); | ||
@@ -11,12 +11,11 @@ var _util = require("@polkadot/util"); | ||
// Copyright 2017-2019 @polkadot/trie-hash authors & contributors | ||
// Copyright 2017-2020 @polkadot/trie-hash authors & contributors | ||
// This software may be modified and distributed under the terms | ||
// of the Apache-2.0 license. See the LICENSE file for details. | ||
describe('unhashedTrie', () => { | ||
Object.values(_data.default).forEach((_ref) => { | ||
let { | ||
desc, | ||
input, | ||
output | ||
} = _ref; | ||
Object.values(_data.default).forEach(({ | ||
desc, | ||
input, | ||
output | ||
}) => { | ||
it("encodes ".concat(desc), () => { | ||
@@ -23,0 +22,0 @@ expect((0, _util.u8aToHex)((0, _unhashedTrie.default)(input))).toEqual((0, _util.u8aToHex)(output)); |
24024
304
Updated@babel/runtime@^7.7.7
Updated@polkadot/util@^1.8.0-beta.3