# pbft-typescript

> *Work in progress, do not use in production.*

Latest version **0.0.48** (published 2018-08-05) · MIT license · 0 weekly downloads

## Install

```sh
npm install pbft-typescript
pnpm add pbft-typescript
yarn add pbft-typescript
bun add pbft-typescript
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.48 |
| Published | 2018-08-05 |
| First published | 2018-07-04 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 14 |
| Unpacked size | 614.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 6 |
| Author | Gil Amran |
| Maintainers | gadcl, gilamran |

## Links

- npm: https://www.npmjs.com/package/pbft-typescript
- Repository: https://github.com/orbs-network/PBFT-Typescript
- Homepage: https://github.com/orbs-network/PBFT-Typescript#readme
- Issues: https://github.com/orbs-network/PBFT-Typescript/issues
- npm.io page: https://npm.io/package/pbft-typescript

## Dependencies (14)

- [chai](https://npm.io/package/chai.md) ^4.1.2
- [mocha](https://npm.io/package/mocha.md) ^5.1.1
- [sinon](https://npm.io/package/sinon.md) ^5.0.6
- [crypto](https://npm.io/package/crypto.md) ^1.0.1
- [tslint](https://npm.io/package/tslint.md) ^5.10.0
- [ts-node](https://npm.io/package/ts-node.md) ^6.0.3
- [sinon-chai](https://npm.io/package/sinon-chai.md) ^3.0.0
- [typescript](https://npm.io/package/typescript.md) ^2.9.1
- [@types/chai](https://npm.io/package/@types/chai.md) ^4.1.3
- [@types/node](https://npm.io/package/@types/node.md) ^10.0.4
- [@types/mocha](https://npm.io/package/@types/mocha.md) ^5.2.0
- [@types/sinon](https://npm.io/package/@types/sinon.md) ^4.3.1
- [@types/sinon-chai](https://npm.io/package/@types/sinon-chai.md) ^2.7.29
- [json-stable-stringify](https://npm.io/package/json-stable-stringify.md) ^1.0.1

## Recent versions

- 0.0.48 (latest) — 2018-08-05
- 0.0.47 — 2018-08-05
- 0.0.46 — 2018-08-01
- 0.0.45 — 2018-08-01
- 0.0.44 — 2018-08-01
- 0.0.43 — 2018-07-26
- 0.0.42 — 2018-07-26
- 0.0.41 — 2018-07-25
- 0.0.40 — 2018-07-22
- 0.0.38 — 2018-07-21
- 0.0.37 — 2018-07-20
- 0.0.36 — 2018-07-20
- 0.0.35 — 2018-07-20
- 0.0.34 — 2018-07-20
- 0.0.33 — 2018-07-20
- … 31 more at https://npm.io/package/pbft-typescript/versions

## README

# PBFT-Typescript

*Work in progress, do not use in production.*

This library is a PBFT implementation of the PBFT algorithm (Practical Byzantine Fault Tolerance).

## To do

- [x] Remove node types from the tests
- [x] PBFT onLeaderChange should count itself
- [x] Generate new block via a blocks provider?
- [x] on new-view the new leader is not counting itself (not logging the PP before sending the new-view)
- [x] implement new-view
- [x] we should have a timer for each view. new-view shouldn't restart a timer if it's already started.
- [x] suggest block in new-view (inside PP)
- [x] Convert getBlock of "BlocksProvider" to async.
- [x] the onElected will trigger new-view more than once
- [x] new-view shouldn't restart a timer if it's already started.
- [x] Unsubscribe gossip on dispose of PBFT
- [x] Separate the PBFT to a 1-Height-PBFT and a full PBFT.
- [x] add isMember, and call it from pbft
- [x] missing protection against byzantine attacks with wrong term/senderId etc.
- [x] make sure on onReceiveNewView the PP.view === view
- [x] protect against wrong view in PBFTTerm
- [x] protect against bad leader messages
- [x] publish on npm
- [x] the PP validation should be extracted and used on new view PP
- [x] onReceiveNewView should match the PP.view with the view
- [x] onReceiveNewView should validate the given PP
- [x] use BlockStorage interface
- [x] publish the public types on the root of the library (import { Config } from 'pbft-typescript')
- [x] intellisense is not working for pbft-typescript imports
- [x] BlockStorage interface async compatible.
- [x] BlockStorage interface remove 'appendBlockToChain'.
- [x] add the git repo to the npm site
- [x] Rename OnNewBlock to OnCommitted(Block)
- [x] BlcokStorage.getTopMostBlock() => convert to BlcokStorage.getLastBlockHash()
- [x] BlocksProvider.getBlock() change to requestNewBlock(blockHeight: number)
- [x] BlockStorage: remove getBlockHashOnHeight(), getBlockChainHeight().
- [x] Convert "registerOnCommitted" to async.
- [x] Default implementations of: PBFTStorage.
- [x] Add "restart" to PBFT api
- [x] term should be taken from the height of the latest block (Use the BlockStorage)
- [x] Implement "registerOnCommitted" to async.
- [x] Implement "restart" to PBFT api
- [x] KeyManager passed in config
- [x] NetworkCommunication interface: { `getMembersPKs(height, seed)`, `sendToMembers([pk])`, `subscribeToMessages(cb)`, `unsubscribeFromMessages`}
- [x] Remove senderId from Gossip -> Use PK instead
- [x] Network rename NetworkCommunication
- [x] Block interface {header}
- [x] getNetworkMembersPKs(seed: string): string[]; // ordered
- [x] getHeight should by async
- [x] BlockUtils.calculateBlockHash(blockHeader) - bytes vs string?
- [x] Remove BlockStorage, instead cache the last committed block
- [x] BlockUtils - requestNewBlock and validate => use lastBlockHeader
- [x] KeyManager implementation.
- [x] Make BlockUtils external
- [x] remove blockProvider & blockValidator
- [x] PBFT.start should work with height
- [x] TDD trigger once
- [x] Cache future messages and consume on each new term
- [x] CommitBlock - commit the matching preprepared block in the pbftstorage - not the temp in state (this.CB)
  
## None Blockers

- [x] call the clear pbftStorage after commit.
- [x] set the committee members pks in the PBFTTerm constructor
- [x] clear the pbftStorage
- [x] suggest block in new-view (inside PP), with proofs from other nodes.
  - [x] choose the "best" block (Out of view-change proofs) to offer on new-view
  - [x] on new-view verify that the leader offered the "best" block
  - [x] PrePrepare Compare given blockHash with the hash of the given block
  - [x] Storage - store payloads
  - [x] GetLatestPreparedProof from storage
  - [x] Add proof validator that can validate the prepred proof
    - [x] Test for matching view/leader
    - [x] Make sure the preprepare hold a block
    - [x] count null as a valid proof
    - [x] Verify the payloads
    - [x] Test that the pk is in the committee!
    - [x] Make sure that the prepares are not from the leader
    - [x] Prepared proof is valid only if it has 2f+1
  - [x] send the proof on view change
  - [x] validate the proof on view change
  - [x] on generate new-view add the view-change proof.
  - [x] extract ViewChange tests from onReceiveViewChange to a reusable function
  - [x] onReceiveNewView verify the proof
    - [x] not undefined
    - [x] isArray
    - [x] 2f+1 proofs
    - [x] validate using isViewChangePayloadValid
    - [x] all proofs senders a unique
    - [x] all VC terms match the given term
    - [x] all VC views match the given view
- [ ] validate all signed messages
- [ ] Check state still holds after async await functions (ex: when returning from requestNewBlock - view has changed)
- [ ] Think about view-change counting, when to count myself.
- [ ] add isACommitteeMember to PBFTTerm
- [ ] Change logging methodology - warning - added metadata
- [ ] Have a better (Readable) tests solution to await nextTick
- [ ] documentation
- [ ] monitoring/debug
- [ ] Optimizations: IData - Signature only on hash(header).

## V1 stuff

- [ ] PBFT-BC onCommitted - adds header.pbftData.pbftProof
- [ ] implement `verifyBlock`

---
_Source: https://npm.io/package/pbft-typescript · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
