Skip to content
This repository has been archived by the owner on Jun 11, 2024. It is now read-only.

Commit

Permalink
Merge pull request #5342 from LiskHQ/5203-create_tree_package
Browse files Browse the repository at this point in the history
Add lisk-tree package - Closes #5203
  • Loading branch information
shuse2 authored May 19, 2020
2 parents ed6497d + ec238be commit 8286eaa
Show file tree
Hide file tree
Showing 20 changed files with 270 additions and 0 deletions.
2 changes: 2 additions & 0 deletions elements/lisk-tree/.eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
dist-node
jest.config.js
7 changes: 7 additions & 0 deletions elements/lisk-tree/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module.exports = {
extends: '../../.eslintrc.js',
parserOptions: {
project: './tsconfig.json',
tsconfigRootDir: __dirname,
},
};
1 change: 1 addition & 0 deletions elements/lisk-tree/.npmignore
1 change: 1 addition & 0 deletions elements/lisk-tree/.npmrc
1 change: 1 addition & 0 deletions elements/lisk-tree/.prettierignore
1 change: 1 addition & 0 deletions elements/lisk-tree/.prettierrc.json
40 changes: 40 additions & 0 deletions elements/lisk-tree/README.md
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions elements/lisk-tree/jest.config.js
60 changes: 60 additions & 0 deletions elements/lisk-tree/package.json
Original file line number Diff line number Diff line change
@@ -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 <[email protected]>, lightcurve GmbH <[email protected]>",
"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"
}
}
1 change: 1 addition & 0 deletions elements/lisk-tree/scripts
16 changes: 16 additions & 0 deletions elements/lisk-tree/src/index.ts
Original file line number Diff line number Diff line change
@@ -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';
42 changes: 42 additions & 0 deletions elements/lisk-tree/src/merkle_tree.ts
Original file line number Diff line number Diff line change
@@ -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<Buffer>): Proof {
// eslint-disable-next-line
return {} as any;
}
}
19 changes: 19 additions & 0 deletions elements/lisk-tree/src/types.ts
Original file line number Diff line number Diff line change
@@ -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[];
}
20 changes: 20 additions & 0 deletions elements/lisk-tree/src/verify_merkle_tree.ts
Original file line number Diff line number Diff line change
@@ -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;
7 changes: 7 additions & 0 deletions elements/lisk-tree/test/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module.exports = {
extends: '../../../.eslintrc.test.js',
parserOptions: {
project: './tsconfig.json',
tsconfigRootDir: __dirname,
},
};
3 changes: 3 additions & 0 deletions elements/lisk-tree/test/_setup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
require('jest-extended');

process.env.NODE_ENV = 'test';
27 changes: 27 additions & 0 deletions elements/lisk-tree/test/markle_tree.spec.ts
Original file line number Diff line number Diff line change
@@ -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');
});
});
1 change: 1 addition & 0 deletions elements/lisk-tree/test/tsconfig.json
19 changes: 19 additions & 0 deletions elements/lisk-tree/test/verify_standard_tree.spec.ts
Original file line number Diff line number Diff line change
@@ -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');
});
});
1 change: 1 addition & 0 deletions elements/lisk-tree/tsconfig.json

0 comments on commit 8286eaa

Please sign in to comment.