diff --git a/elements/lisk-tree/.eslintignore b/elements/lisk-tree/.eslintignore new file mode 100644 index 00000000000..18f63c615af --- /dev/null +++ b/elements/lisk-tree/.eslintignore @@ -0,0 +1,2 @@ +dist-node +jest.config.js diff --git a/elements/lisk-tree/.eslintrc.js b/elements/lisk-tree/.eslintrc.js new file mode 100644 index 00000000000..8b7fd410b8d --- /dev/null +++ b/elements/lisk-tree/.eslintrc.js @@ -0,0 +1,7 @@ +module.exports = { + extends: '../../.eslintrc.js', + parserOptions: { + project: './tsconfig.json', + tsconfigRootDir: __dirname, + }, +}; diff --git a/elements/lisk-tree/.npmignore b/elements/lisk-tree/.npmignore new file mode 120000 index 00000000000..8a0be70f3ed --- /dev/null +++ b/elements/lisk-tree/.npmignore @@ -0,0 +1 @@ +../../templates/.npmignore.tmpl \ No newline at end of file diff --git a/elements/lisk-tree/.npmrc b/elements/lisk-tree/.npmrc new file mode 120000 index 00000000000..5cc817c4313 --- /dev/null +++ b/elements/lisk-tree/.npmrc @@ -0,0 +1 @@ +../../templates/.npmrc.tmpl \ No newline at end of file diff --git a/elements/lisk-tree/.prettierignore b/elements/lisk-tree/.prettierignore new file mode 120000 index 00000000000..044e4a3df69 --- /dev/null +++ b/elements/lisk-tree/.prettierignore @@ -0,0 +1 @@ +../../templates/.prettierignore.tmpl \ No newline at end of file diff --git a/elements/lisk-tree/.prettierrc.json b/elements/lisk-tree/.prettierrc.json new file mode 120000 index 00000000000..00ecd510aaf --- /dev/null +++ b/elements/lisk-tree/.prettierrc.json @@ -0,0 +1 @@ +../../templates/.prettierrc.json.tmpl \ No newline at end of file diff --git a/elements/lisk-tree/README.md b/elements/lisk-tree/README.md new file mode 100644 index 00000000000..1482515a552 --- /dev/null +++ b/elements/lisk-tree/README.md @@ -0,0 +1,40 @@ +# @liskhq/lisk-tree + +@liskhq/lisk-tree is containing Merkle tree implementations for use with Lisk-related software + +## Installation + +```sh +$ npm install --save @liskhq/lisk-tree +``` + +## License + +Copyright 2016-2019 Lisk Foundation + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + +http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + +--- + +Copyright © 2016-2019 Lisk Foundation + +Copyright © 2015 Crypti + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +[lisk core github]: https://github.com/LiskHQ/lisk +[lisk documentation site]: https://lisk.io/documentation/lisk-elements diff --git a/elements/lisk-tree/jest.config.js b/elements/lisk-tree/jest.config.js new file mode 120000 index 00000000000..475ff02b18a --- /dev/null +++ b/elements/lisk-tree/jest.config.js @@ -0,0 +1 @@ +../../templates/jest.config.js.tmpl \ No newline at end of file diff --git a/elements/lisk-tree/package.json b/elements/lisk-tree/package.json new file mode 100644 index 00000000000..76d6901e4e5 --- /dev/null +++ b/elements/lisk-tree/package.json @@ -0,0 +1,60 @@ +{ + "name": "@liskhq/lisk-tree", + "version": "0.1.0", + "description": "Library containing Markle tree implementations for use with Lisk-related software", + "author": "Lisk Foundation , lightcurve GmbH ", + "license": "Apache-2.0", + "keywords": [ + "lisk", + "blockchain" + ], + "homepage": "https://github.com/LiskHQ/lisk-sdk/tree/master/elements/lisk-tree#readme", + "repository": { + "type": "git", + "url": "git+https://github.com/LiskHQ/lisk-sdk.git" + }, + "bugs": { + "url": "https://github.com/LiskHQ/lisk-sdk/issues" + }, + "engines": { + "node": ">=12.13.0 <=12", + "npm": ">=6.12.0" + }, + "main": "dist-node/index.js", + "scripts": { + "clean": "./scripts/clean.sh", + "format": "prettier --write '**/*'", + "lint": "eslint --ext .js,.ts .", + "lint:fix": "eslint --fix --ext .js,.ts .", + "test": "jest", + "test:watch": "npm test -- --watch", + "prebuild": "rm -r dist-node/* || mkdir dist-node || true", + "build": "tsc", + "build:check": "node -e \"require('./dist-node')\"", + "prepublishOnly": "npm run lint && npm test && npm run build && npm run build:check" + }, + "dependencies": { + "@liskhq/lisk-cryptography": "2.5.0-alpha.0" + }, + "devDependencies": { + "@types/node": "12.12.11", + "@types/jest": "25.1.3", + "@types/jest-when": "2.7.0", + "@typescript-eslint/eslint-plugin": "2.28.0", + "@typescript-eslint/parser": "2.28.0", + "eslint": "6.8.0", + "eslint-config-lisk-base": "1.2.2", + "eslint-config-prettier": "6.10.0", + "eslint-plugin-import": "2.20.1", + "eslint-plugin-jest": "23.8.2", + "jest": "25.1.0", + "jest-extended": "0.11.5", + "jest-when": "2.7.0", + "prettier": "1.19.1", + "source-map-support": "0.5.16", + "ts-jest": "25.2.1", + "ts-node": "8.6.2", + "tsconfig-paths": "3.9.0", + "typescript": "3.8.3" + } +} diff --git a/elements/lisk-tree/scripts b/elements/lisk-tree/scripts new file mode 120000 index 00000000000..f81ccd0a763 --- /dev/null +++ b/elements/lisk-tree/scripts @@ -0,0 +1 @@ +../../templates/scripts.tmpl \ No newline at end of file diff --git a/elements/lisk-tree/src/index.ts b/elements/lisk-tree/src/index.ts new file mode 100644 index 00000000000..00b35a769a0 --- /dev/null +++ b/elements/lisk-tree/src/index.ts @@ -0,0 +1,16 @@ +/* + * Copyright © 2020 Lisk Foundation + * + * See the LICENSE file at the top-level directory of this distribution + * for licensing information. + * + * Unless otherwise agreed in a custom licensing agreement with the Lisk Foundation, + * no part of this software, including this file, may be copied, modified, + * propagated, or distributed except according to the terms contained in the + * LICENSE file. + * + * Removal or modification of this copyright notice is prohibited. + */ + +export * from './merkle_tree'; +export * from './verify_merkle_tree'; diff --git a/elements/lisk-tree/src/merkle_tree.ts b/elements/lisk-tree/src/merkle_tree.ts new file mode 100644 index 00000000000..68e105f0010 --- /dev/null +++ b/elements/lisk-tree/src/merkle_tree.ts @@ -0,0 +1,42 @@ +/* + * Copyright © 2020 Lisk Foundation + * + * See the LICENSE file at the top-level directory of this distribution + * for licensing information. + * + * Unless otherwise agreed in a custom licensing agreement with the Lisk Foundation, + * no part of this software, including this file, may be copied, modified, + * propagated, or distributed except according to the terms contained in the + * LICENSE file. + * + * Removal or modification of this copyright notice is prohibited. + */ + +import { Proof } from './types'; + +export class MerkleTree { + // eslint-disable-next-line + private _root: Buffer; + // eslint-disable-next-line + public constructor(_initValues: Buffer[]) { + this._root = Buffer.alloc(0); + } + + public get root(): Buffer { + if (this._root.length === 0) { + throw new Error('Merkle root has not been calculated'); + } + return this._root; + } + + // eslint-disable-next-line + public append(_value: Buffer): { key: Buffer; value: Buffer }[] { + return []; + } + + // eslint-disable-next-line + public generateProof(_queryData: ReadonlyArray): Proof { + // eslint-disable-next-line + return {} as any; + } +} diff --git a/elements/lisk-tree/src/types.ts b/elements/lisk-tree/src/types.ts new file mode 100644 index 00000000000..2ef0404cac3 --- /dev/null +++ b/elements/lisk-tree/src/types.ts @@ -0,0 +1,19 @@ +/* + * Copyright © 2020 Lisk Foundation + * + * See the LICENSE file at the top-level directory of this distribution + * for licensing information. + * + * Unless otherwise agreed in a custom licensing agreement with the Lisk Foundation, + * no part of this software, including this file, may be copied, modified, + * propagated, or distributed except according to the terms contained in the + * LICENSE file. + * + * Removal or modification of this copyright notice is prohibited. + */ + +export interface Proof { + readonly dataLength: number; + readonly idxs: number[]; + path: Buffer[]; +} diff --git a/elements/lisk-tree/src/verify_merkle_tree.ts b/elements/lisk-tree/src/verify_merkle_tree.ts new file mode 100644 index 00000000000..7fcc7c96b74 --- /dev/null +++ b/elements/lisk-tree/src/verify_merkle_tree.ts @@ -0,0 +1,20 @@ +/* + * Copyright © 2020 Lisk Foundation + * + * See the LICENSE file at the top-level directory of this distribution + * for licensing information. + * + * Unless otherwise agreed in a custom licensing agreement with the Lisk Foundation, + * no part of this software, including this file, may be copied, modified, + * propagated, or distributed except according to the terms contained in the + * LICENSE file. + * + * Removal or modification of this copyright notice is prohibited. + */ + +import { Proof } from './types'; + +export const verifyProofOfInclusion = ( + _proof: Proof, + _merkleRoot: Buffer, +): boolean => true; diff --git a/elements/lisk-tree/test/.eslintrc.js b/elements/lisk-tree/test/.eslintrc.js new file mode 100644 index 00000000000..a98dfb6d823 --- /dev/null +++ b/elements/lisk-tree/test/.eslintrc.js @@ -0,0 +1,7 @@ +module.exports = { + extends: '../../../.eslintrc.test.js', + parserOptions: { + project: './tsconfig.json', + tsconfigRootDir: __dirname, + }, +}; diff --git a/elements/lisk-tree/test/_setup.js b/elements/lisk-tree/test/_setup.js new file mode 100644 index 00000000000..e2a8f3c32b8 --- /dev/null +++ b/elements/lisk-tree/test/_setup.js @@ -0,0 +1,3 @@ +require('jest-extended'); + +process.env.NODE_ENV = 'test'; diff --git a/elements/lisk-tree/test/markle_tree.spec.ts b/elements/lisk-tree/test/markle_tree.spec.ts new file mode 100644 index 00000000000..250da67c0f2 --- /dev/null +++ b/elements/lisk-tree/test/markle_tree.spec.ts @@ -0,0 +1,27 @@ +/* + * Copyright © 2020 Lisk Foundation + * + * See the LICENSE file at the top-level directory of this distribution + * for licensing information. + * + * Unless otherwise agreed in a custom licensing agreement with the Lisk Foundation, + * no part of this software, including this file, may be copied, modified, + * propagated, or distributed except according to the terms contained in the + * LICENSE file. + * + * Removal or modification of this copyright notice is prohibited. + */ + +describe('MerkleTree', () => { + describe('constructor', () => { + it.todo('should have correct root value'); + }); + + describe('append', () => { + it.todo('should append and update root'); + }); + + describe('generateProof', () => { + it.todo('should generate proof that is verifiable'); + }); +}); diff --git a/elements/lisk-tree/test/tsconfig.json b/elements/lisk-tree/test/tsconfig.json new file mode 120000 index 00000000000..c73c54e77b4 --- /dev/null +++ b/elements/lisk-tree/test/tsconfig.json @@ -0,0 +1 @@ +../../../templates/test/tsconfig.json.tmpl \ No newline at end of file diff --git a/elements/lisk-tree/test/verify_standard_tree.spec.ts b/elements/lisk-tree/test/verify_standard_tree.spec.ts new file mode 100644 index 00000000000..8c907409802 --- /dev/null +++ b/elements/lisk-tree/test/verify_standard_tree.spec.ts @@ -0,0 +1,19 @@ +/* + * Copyright © 2020 Lisk Foundation + * + * See the LICENSE file at the top-level directory of this distribution + * for licensing information. + * + * Unless otherwise agreed in a custom licensing agreement with the Lisk Foundation, + * no part of this software, including this file, may be copied, modified, + * propagated, or distributed except according to the terms contained in the + * LICENSE file. + * + * Removal or modification of this copyright notice is prohibited. + */ + +describe('verifyMerkleTree', () => { + describe('verify', () => { + it.todo('should verify if given proof is correct'); + }); +}); diff --git a/elements/lisk-tree/tsconfig.json b/elements/lisk-tree/tsconfig.json new file mode 120000 index 00000000000..900bb05c680 --- /dev/null +++ b/elements/lisk-tree/tsconfig.json @@ -0,0 +1 @@ +../../templates/tsconfig.json.tmpl \ No newline at end of file