This repository has been archived by the owner on Jan 4, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Brian Faust
committed
Sep 23, 2021
0 parents
commit 0c16339
Showing
20 changed files
with
6,399 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
root = true | ||
|
||
[*] | ||
indent_size = 2 | ||
indent_style = space | ||
end_of_line = lf | ||
charset = utf-8 | ||
trim_trailing_whitespace = true | ||
insert_final_newline = true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
* text=auto eol=lf |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
name: Node.js CI | ||
|
||
on: | ||
push: | ||
branches: [main] | ||
pull_request: | ||
branches: [main] | ||
|
||
jobs: | ||
test: | ||
if: "!contains(github.event.head_commit.message, 'ci skip')" | ||
|
||
strategy: | ||
matrix: | ||
os: [ubuntu-latest] | ||
|
||
runs-on: ${{ matrix.os }} | ||
|
||
steps: | ||
- uses: actions/checkout@v2 | ||
|
||
- uses: actions/setup-node@v2 | ||
with: | ||
node-version: 14.x | ||
|
||
- name: Cache ~/.pnpm-store | ||
uses: actions/cache@v2 | ||
env: | ||
cache-name: cache-pnpm-store | ||
with: | ||
path: ~/.pnpm-store | ||
key: ${{ runner.os }}-${{ matrix.node-version }}-build-${{ env.cache-name }}-${{ hashFiles('**/pnpm-lock.yaml') }} | ||
restore-keys: | | ||
${{ runner.os }}-${{ matrix.node-version }}-build-${{ env.cache-name }}- | ||
${{ runner.os }}-${{ matrix.node-version }}-build- | ||
${{ runner.os }}- | ||
- name: Install pnpm | ||
run: npm i -g pnpm | ||
|
||
- name: Install deps | ||
run: pnpm i | ||
|
||
# Runs a set of commands using the runners shell | ||
- name: Build and Test | ||
run: npm run test | ||
|
||
- name: Release | ||
run: pnpx -y semantic-release --branches main | ||
env: | ||
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
NPM_TOKEN: ${{ secrets.NPM_TOKEN }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
node_modules | ||
.DS_Store | ||
dist | ||
*.log |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
**You can help the author become a full-time open-source maintainer by [sponsoring him on GitHub](https://github.com/sponsors/faustbrian).** | ||
|
||
--- | ||
|
||
# @faustbrian/node-nominated-proof-of-stake | ||
|
||
[![npm version](https://badgen.net/npm/v/@faustbrian/node-nominated-proof-of-stake)](https://npm.im/@faustbrian/node-nominated-proof-of-stake) | ||
|
||
## Installation | ||
|
||
``` | ||
pnpm install @faustbrian/node-nominated-proof-of-stake | ||
``` | ||
|
||
## Usage | ||
|
||
```ts | ||
import { IValidator, mine, round, validator } from "@faustbrian/node-nominated-proof-of-stake"; | ||
|
||
const validators: IValidator[] = [ | ||
validator( | ||
"02062f6f6d2aabafd745e6b01f4aa788a012c4ce7131312026bdb6eb4e74a464d2", | ||
[{ stake: 1 }], | ||
), | ||
validator( | ||
"020aac4ec02d47d306b394b79d3351c56c1253cd67fe2c1a38ceba59b896d584d1", | ||
[{ stake: 2 }], | ||
), | ||
validator( | ||
"0212a11582a28f178b906edbf8e8c447ce1ba86041ee731e595ae4d39ef034c2ad", | ||
[{ stake: 3 }], | ||
), | ||
validator( | ||
"0215789ac26155b7a338708f595b97c453e08918d0630c896cbd31d83fe2ad1c33", | ||
[{ stake: 4 }], | ||
), | ||
validator( | ||
"021b0f58eca7f123428a8647ffe0644a9454c510f066d3864c27d8c7ad8f5a8aa4", | ||
[{ stake: 5 }], | ||
), | ||
]; | ||
|
||
const validatorsByRound: round({ | ||
limit: 5, | ||
round: 1, | ||
validators, | ||
}); | ||
|
||
mine({ | ||
height: 1, | ||
slot: 1, | ||
validator: validators[4], | ||
validators: validatorsByRound, | ||
}); // Will return a new SHA256 hash. | ||
|
||
mine({ | ||
height: 2, | ||
slot: 2, | ||
validator: validators[1], | ||
validators: validatorsByRound, | ||
}); // Error because someone else was expected to mine. | ||
``` | ||
|
||
## License | ||
|
||
This is an open-sourced software licensed under the [AGPL-3.0-or-later](LICENSE). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
module.exports = { | ||
testEnvironment: "node", | ||
transform: { | ||
"^.+\\.tsx?$": "@sucrase/jest-plugin", | ||
}, | ||
testPathIgnorePatterns: ["/node_modules/", "/dist/", "/types/"], | ||
testMatch: ["**/*.test.ts"], | ||
moduleFileExtensions: ["ts", "tsx", "js", "jsx", "json", "node"], | ||
setupFilesAfterEnv: ["jest-extended"], | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
{ | ||
"name": "@faustbrian/node-nominated-proof-of-stake", | ||
"version": "1.0.0", | ||
"description": "An implementation of NPoS consensus for node.js", | ||
"homepage": "https://github.com/faustbrian/node-nominated-proof-of-stake", | ||
"bugs": { | ||
"url": "https://github.com/faustbrian/node-nominated-proof-of-stake/issues" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/faustbrian/node-nominated-proof-of-stake.git" | ||
}, | ||
"license": "AGPL-3.0-or-later", | ||
"author": { | ||
"name": "Brian Faust", | ||
"email": "brian@faust.mx", | ||
"url": "https://faust.mx" | ||
}, | ||
"exports": { | ||
"require": "./dist/index.js", | ||
"import": "./dist/index.mjs" | ||
}, | ||
"main": "./dist/index.js", | ||
"module": "./dist/index.mjs", | ||
"types": "./dist/index.d.ts", | ||
"files": [ | ||
"dist" | ||
], | ||
"scripts": { | ||
"build": "tsup source --format cjs,esm --dts-resolve", | ||
"test": "jest", | ||
"lint": "stdlint && deno fmt source", | ||
"prepublishOnly": "pnpm run build" | ||
}, | ||
"dependencies": { | ||
"@faustbrian/node-deterministic-array-shuffle": "^1.0.0", | ||
"@faustbrian/node-sha256": "^1.0.0" | ||
}, | ||
"devDependencies": { | ||
"@faustbrian/stdlint": "^1.0.0", | ||
"@sindresorhus/tsconfig": "^2.0.0", | ||
"@sucrase/jest-plugin": "^2.0.0", | ||
"@types/jest": "^27.0.1", | ||
"jest": "^27.2.0", | ||
"jest-extended": "^0.11.5", | ||
"tsup": "^4.8.4", | ||
"typescript": "^4.4.3" | ||
}, | ||
"engines": { | ||
"node": ">=12" | ||
}, | ||
"publishConfig": { | ||
"access": "public" | ||
} | ||
} |
Oops, something went wrong.