Skip to content
This repository was archived by the owner on Aug 27, 2021. It is now read-only.

Commit dc36fc7

Browse files
committed
feat: initial chain constructor
1 parent 8a2e7b4 commit dc36fc7

File tree

7 files changed

+179
-343
lines changed

7 files changed

+179
-343
lines changed

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,6 @@ dist
99
compiled
1010
.awcache
1111
prototree
12-
.#*
12+
.#*
13+
test-level-db/
14+
test-ipfs-repo/

chain.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { ObjectStore } from '@aperturerobotics/objstore'
2+
import { chain } from './pb/chain/chain_config'
3+
import * as lcrypto from 'libp2p-crypto'
4+
5+
export class Chain {
6+
// db is the object store.
7+
private db: ObjectStore;
8+
private conf: chain.IConfig
9+
10+
constructor(objStore: ObjectStore, chainID: string, validatorPriv: any) {
11+
}
12+
}

key.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import * as lcrypto from 'libp2p-crypto'
2+
3+
// generateKeyPair generates a key pair.
4+
export async function generateKeyPair(keyType: string, keyBits: number): Promise<any> {
5+
return new Promise<any>((resolve, reject) => {
6+
lcrypto.keys.generateKeyPair(keyType, keyBits, (err: any, key: any) => {
7+
if (err) {
8+
reject(err)
9+
} else {
10+
resolve(key)
11+
}
12+
})
13+
})
14+
}

package.json

Lines changed: 105 additions & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -1,105 +1,110 @@
11
{
2-
"name": "@aperturerobotics/inca",
3-
"private": true,
4-
"version": "0.0.0",
5-
"description": "Inca node implementation in Javascript.",
6-
"main": "index.ts",
7-
"author": "Christian Stewart <christian@paral.in>",
8-
"repository": {
9-
"type": "git",
10-
"url": "git@github.com:aperturerobotics/objectsig-js.git"
11-
},
12-
"engines": {
13-
"node": ">=6.0.0"
14-
},
15-
"scripts": {
16-
"lint": "tslint -t codeFrame 'src/**/*.ts' 'test/**/*.ts'",
17-
"prebuild": "rimraf dist",
18-
"test": "jest",
19-
"test:watch": "jest --watch",
20-
"test:prod": "npm run lint && npm run test -- --coverage --no-cache",
21-
"deploy-docs": "ts-node tools/gh-pages-publish",
22-
"report-coverage": "cat ./coverage/lcov.info | coveralls",
23-
"commit": "git-cz",
24-
"precommit": "lint-staged"
25-
},
26-
"lint-staged": {
27-
"{src,test}/**/*.ts": [
28-
"prettier --write --no-semi --single-quote",
29-
"git add"
30-
]
31-
},
32-
"config": {
33-
"commitizen": {
34-
"path": "node_modules/cz-conventional-changelog"
2+
"name": "@aperturerobotics/inca",
3+
"private": true,
4+
"version": "0.0.0",
5+
"description": "Inca node implementation in Javascript.",
6+
"main": "index.ts",
7+
"author": "Christian Stewart <christian@paral.in>",
8+
"repository": {
9+
"type": "git",
10+
"url": "git@github.com:aperturerobotics/objectsig-js.git"
3511
},
36-
"validate-commit-msg": {
37-
"types": "conventional-commit-types",
38-
"helpMessage": "Use \"npm run commit\" instead, we use conventional-changelog format :) (https://github.com/commitizen/cz-cli)"
39-
}
40-
},
41-
"jest": {
42-
"transform": {
43-
".(ts|tsx)": "<rootDir>/node_modules/ts-jest/preprocessor.js"
12+
"engines": {
13+
"node": ">=6.0.0"
14+
},
15+
"scripts": {
16+
"lint": "tslint -t codeFrame 'src/**/*.ts' 'test/**/*.ts'",
17+
"prebuild": "rimraf dist",
18+
"test": "jest",
19+
"test:watch": "jest --watch",
20+
"test:prod": "npm run lint && npm run test -- --coverage --no-cache",
21+
"deploy-docs": "ts-node tools/gh-pages-publish",
22+
"report-coverage": "cat ./coverage/lcov.info | coveralls",
23+
"commit": "git-cz",
24+
"precommit": "lint-staged"
25+
},
26+
"lint-staged": {
27+
"{src,test}/**/*.ts": [
28+
"prettier --write --no-semi --single-quote",
29+
"git add"
30+
]
4431
},
45-
"testRegex": "(/__tests__/.*|\\.(test|spec))\\.(ts|tsx|js)$",
46-
"moduleFileExtensions": [
47-
"ts",
48-
"tsx",
49-
"js"
50-
],
51-
"coveragePathIgnorePatterns": [
52-
"/node_modules/",
53-
"/test/",
54-
"/src/pb/"
55-
],
56-
"coverageThreshold": {
57-
"global": {
58-
"branches": 90,
59-
"functions": 95,
60-
"lines": 95,
61-
"statements": 95
62-
}
32+
"config": {
33+
"commitizen": {
34+
"path": "node_modules/cz-conventional-changelog"
35+
},
36+
"validate-commit-msg": {
37+
"types": "conventional-commit-types",
38+
"helpMessage": "Use \"npm run commit\" instead, we use conventional-changelog format :) (https://github.com/commitizen/cz-cli)"
39+
}
6340
},
64-
"collectCoverage": true,
65-
"mapCoverage": true
66-
},
67-
"devDependencies": {
68-
"@types/es6-promise": "^3.3.0",
69-
"@types/jest": "^21.1.0",
70-
"@types/node": "^8.0.0",
71-
"@types/ipfs": "https://github.com/zabirauf/ipfs-types/archive/aef66519bd24036b706844e96378dcfecab54185/ipfs-types.tar.gz",
72-
"colors": "^1.1.2",
73-
"commitizen": "^2.9.6",
74-
"coveralls": "^3.0.0",
75-
"cross-env": "^5.0.1",
76-
"cz-conventional-changelog": "^2.0.0",
77-
"husky": "^0.14.0",
78-
"jest": "^22.0.0",
79-
"lint-staged": "^6.0.0",
80-
"lodash.camelcase": "^4.3.0",
81-
"prettier": "^1.4.4",
82-
"prompt": "^1.0.0",
83-
"replace-in-file": "^3.0.0-beta.2",
84-
"rimraf": "^2.6.1",
85-
"ts-jest": "^22.0.0",
86-
"ts-node": "^4.0.1",
87-
"tslint": "^5.4.3",
88-
"tslint-config-prettier": "^1.1.0",
89-
"tslint-config-standard": "^7.0.0",
90-
"typedoc": "^0.9.0",
91-
"typescript": "^2.3.4",
92-
"validate-commit-msg": "^2.12.2"
93-
},
94-
"dependencies": {
95-
"@aperturerobotics/pbobject": "^0.2.0",
96-
"buffer": "^5.0.8",
97-
"elliptic": "^6.4.0",
98-
"libp2p-crypto": "^0.11.0",
99-
"multihashes": "^0.4.13",
100-
"multihashing": "^0.3.2",
101-
"node-webcrypto-ossl": "^1.0.33",
102-
"protobufjs": "^6.8.0",
103-
"typedarray-to-buffer": "^3.1.0"
104-
}
41+
"jest": {
42+
"transform": {
43+
".(ts|tsx)": "../../node_modules/ts-jest/preprocessor.js"
44+
},
45+
"testRegex": "(/__tests__/.*|\\.(test|spec))\\.(ts|tsx|js)$",
46+
"moduleFileExtensions": [
47+
"ts",
48+
"tsx",
49+
"js"
50+
],
51+
"coveragePathIgnorePatterns": [
52+
"/node_modules/",
53+
"/test/",
54+
"/src/pb/",
55+
"/packages/objstore/",
56+
"/packages/pbobject/",
57+
"/packages/objectenc/",
58+
"/packages/objectsig"
59+
],
60+
"coverageThreshold": {
61+
"global": {
62+
"branches": 90,
63+
"functions": 95,
64+
"lines": 95,
65+
"statements": 95
66+
}
67+
},
68+
"collectCoverage": true,
69+
"mapCoverage": true
70+
},
71+
"devDependencies": {
72+
"@types/es6-promise": "^3.3.0",
73+
"@types/ipfs": "https://github.com/zabirauf/ipfs-types/archive/aef66519bd24036b706844e96378dcfecab54185/ipfs-types.tar.gz",
74+
"@types/jest": "^21.1.0",
75+
"@types/node": "^8.0.0",
76+
"colors": "^1.1.2",
77+
"commitizen": "^2.9.6",
78+
"coveralls": "^3.0.0",
79+
"cross-env": "^5.0.1",
80+
"cz-conventional-changelog": "^2.0.0",
81+
"husky": "^0.14.0",
82+
"lint-staged": "^6.0.0",
83+
"lodash.camelcase": "^4.3.0",
84+
"prettier": "^1.4.4",
85+
"prompt": "^1.0.0",
86+
"replace-in-file": "^3.0.0-beta.2",
87+
"rimraf": "^2.6.1",
88+
"ts-jest": "^22.0.0",
89+
"ts-node": "^4.0.1",
90+
"tslint": "^5.4.3",
91+
"tslint-config-prettier": "^1.1.0",
92+
"tslint-config-standard": "^7.0.0",
93+
"typedoc": "^0.9.0",
94+
"typescript": "^2.3.4",
95+
"validate-commit-msg": "^2.12.2"
96+
},
97+
"dependencies": {
98+
"@aperturerobotics/pbobject": "^0.2.0",
99+
"buffer": "^5.0.8",
100+
"elliptic": "^6.4.0",
101+
"ipfs": "^0.27.7",
102+
"libp2p-crypto": "^0.11.0",
103+
"multihashes": "^0.4.13",
104+
"multihashing": "^0.3.2",
105+
"node-webcrypto-ossl": "^1.0.33",
106+
"protobufjs": "^6.8.0",
107+
"randombytes": "^2.0.6",
108+
"typedarray-to-buffer": "^3.1.0"
109+
}
105110
}

pb/chain/index.ts

Lines changed: 0 additions & 5 deletions
This file was deleted.

test/chain.test.ts

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import { Chain } from '../chain'
2+
import { ObjectStore, LevelBlobDb, RemoteStore, LocalDB } from '@aperturerobotics/objstore'
3+
import { generateKeyPair } from '../key'
4+
5+
import * as lcrypto from 'libp2p-crypto'
6+
import IPFS from 'ipfs'
7+
import randombytes from 'randombytes'
8+
9+
async function buildIPFS(): Promise<IPFS> {
10+
let ipfs = new IPFS({
11+
repo: './test-ipfs-repo'
12+
})
13+
return new Promise<IPFS>((resolve, reject) => {
14+
ipfs.on('ready', () => {
15+
resolve(ipfs)
16+
})
17+
})
18+
}
19+
20+
describe('Chain', () => {
21+
let key = randombytes(32)
22+
let nonce = randombytes(24)
23+
let ipfs: IPFS
24+
let levelBlob: LevelBlobDb
25+
let remoteStore: RemoteStore
26+
let localStore: LocalDB
27+
let objStore: ObjectStore
28+
29+
beforeAll(async () => {
30+
ipfs = await buildIPFS()
31+
levelBlob = new LevelBlobDb('./test-level-db')
32+
remoteStore = new RemoteStore(ipfs)
33+
localStore = new LocalDB(levelBlob)
34+
objStore = new ObjectStore(localStore, remoteStore)
35+
})
36+
37+
afterAll(async () => {
38+
await levelBlob.close()
39+
ipfs.stop()
40+
})
41+
42+
it('should construct correctly', async () => {
43+
let chain = new Chain(objStore, 'test-chain', await generateKeyPair('ed25519', 256))
44+
})
45+
})

0 commit comments

Comments
 (0)