Skip to content

Commit

Permalink
feat: init (#1)
Browse files Browse the repository at this point in the history
* feat: init init

* feat: bee-js inspired feats

* test: first unit

* feat: init inclusionProofBottomUp function

* refactor: bmtHash parameters without span

* test: chunk

* test: bmtTree and inclusion proof segments

* feat: chunk bmt functions and inclusion proof

* test: chunk bmt and inclusion proof

* feat: get span value

* feat: export file.ts

* test: file bmt

* feat: init file bmt

* test: span

* feat: export max span value constant

* refactor: calculate only the data subsumed under the chunk

* test: update file test

* fix: calculate chunk address

* feat: bmt on files

* test: unit test on files and chunks

* test: add testfile < 4 kb

* test: integration test on files

* feat: carrier chunk

* test: carrier chunk

* refactor: chunk inclusion proof

* feat: add equalBytes utility function

* refactor: file exportables

* test: inclusion proof chunk

* feat: file inclusion proof

* test: file inclusion proof

* style: remove blank line before if rule

* feat: file inclusion proof with carrier chunk edge-case

* fix: place chunkSegmentIndex inside the bmt level loop

* test: file inclusion proof tests

* refactor: calculate chunk bmt levels

* refactor: maxSegmentCount usage instead hard-coded value

* refactor: bit shifting instead division and floor

* refactor: renaming and jsdoc

* refactor: makeChunkedFile

* refactor: renamings

* refactor: type

* refactor: exportables

* refactor: imports

* refactor: exportables

* ci: code check

* ci: automated code test

* docs: init readme

* fix: condition for carrier chunk segment index calculation

* chore: package name

* fix: last segment index calculation

* docs: add images

* ci: release-please actions

* ci: bee-factory pull from own repo

* ci: add other env variables

* ci: bee debug api url env set

* ci: change localhost to ipv4

* test: raise test timeout limit

* ci: trigger ci

* fix: typeo

* fix: I think it is better than was

* docs: image references

* refactor: error message

* test: add one more inclusion proof test
  • Loading branch information
nugaon committed Mar 25, 2022
1 parent 7a2c958 commit ce95662
Show file tree
Hide file tree
Showing 31 changed files with 18,617 additions and 1 deletion.
33 changes: 33 additions & 0 deletions .babelrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
'use strict'

module.exports = function (api) {
const targets = '>1% or node >=10 and not ie 11 and not dead'
api.cache(true)
api.cacheDirectory = true

return {
presets: [
'@babel/preset-typescript',
[
'@babel/preset-env',
{
corejs: 3,
useBuiltIns: 'entry',
modules: 'commonjs',
bugfixes: true,
targets
}
]
],
plugins: [
'@babel/plugin-proposal-class-properties',
[
'@babel/plugin-transform-runtime',
{
helpers: false,
regenerator: true
}
]
]
}
}
109 changes: 109 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
module.exports = {
extends: ['plugin:@typescript-eslint/recommended', 'prettier', 'plugin:prettier/recommended'],
parserOptions: {
sourceType: 'module',
ecmaVersion: 2018,
project: './tsconfig.test.json'
},
env: {
jest: true,
},
globals: {
browser: true,
page: true,
},
plugins: ['jest', 'unused-imports'],
rules: {
'array-bracket-newline': ['error', 'consistent'],
strict: ['error', 'safe'],
'block-scoped-var': 'error',
complexity: 'warn',
'default-case': 'error',
'dot-notation': 'warn',
eqeqeq: 'error',
'guard-for-in': 'warn',
'linebreak-style': ['warn', 'unix'],
'no-alert': 'error',
'no-case-declarations': 'error',
'no-console': 'error',
'no-constant-condition': 'error',
'no-continue': 'warn',
'no-div-regex': 'error',
'no-empty': 'warn',
'no-empty-pattern': 'error',
'no-implicit-coercion': 'error',
'prefer-arrow-callback': 'warn',
'no-labels': 'error',
'no-loop-func': 'error',
'no-nested-ternary': 'warn',
'no-script-url': 'error',
'no-warning-comments': 'warn',
'quote-props': ['error', 'as-needed'],
'require-yield': 'error',
'max-nested-callbacks': ['error', 4],
'max-depth': ['error', 4],
'space-before-function-paren': [
'error',
{
anonymous: 'never',
named: 'never',
asyncArrow: 'always',
},
],
'padding-line-between-statements': [
'error',
{ blankLine: 'always', prev: '*', next: 'function' },
{ blankLine: 'always', prev: '*', next: 'return' },
],
'no-useless-constructor': 'off',
'no-dupe-class-members': 'off',
'no-unused-expressions': 'off',
curly: ['error', 'multi-line'],
'object-curly-spacing': ['error', 'always'],
'comma-dangle': ['error', 'always-multiline'],
'@typescript-eslint/no-useless-constructor': 'error',
'@typescript-eslint/no-unused-expressions': 'error',
'@typescript-eslint/member-delimiter-style': [
'error',
{
multiline: {
delimiter: 'none',
requireLast: true,
},
singleline: {
delimiter: 'semi',
requireLast: false,
},
},
],
'@typescript-eslint/ban-ts-comment': [
'error',
{
'ts-expect-error': 'allow-with-description',
'ts-ignore': 'allow-with-description',
'ts-nocheck': 'allow-with-description',
'ts-check': 'allow-with-description',
minimumDescriptionLength: 6,
},
],
"require-await": "off",
"@typescript-eslint/promise-function-async": "error",
"@typescript-eslint/require-await": "off",
"@typescript-eslint/no-unused-vars": "off",
"unused-imports/no-unused-imports": "error",
"@typescript-eslint/no-non-null-assertion": "off",
"unused-imports/no-unused-vars": [
"warn",
{ "vars": "all", "varsIgnorePattern": "^_", "args": "after-used", "argsIgnorePattern": "^_" }
]
},
overrides: [
{
files: ['*.spec.ts'],
rules: {
'max-nested-callbacks': ['error', 10], // allow describe/it nesting
},
},
],
}

54 changes: 54 additions & 0 deletions .github/workflows/check.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
name: Check

on:
push:
branches:
- 'master'
pull_request:
branches:
- '**'

jobs:
check:
runs-on: ubuntu-latest

strategy:
matrix:
node-version: [16.x]

steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}

## Try getting the node modules from cache, if failed npm ci
- uses: actions/cache@v2
id: cache-npm
with:
path: node_modules
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.OS }}-node-${{ env.cache-name }}-
${{ runner.OS }}-node-
${{ runner.OS }}-
- name: Install npm deps
if: steps.cache-npm.outputs.cache-hit != 'true'
run: npm ci

- name: Commit linting
uses: wagoid/commitlint-github-action@v2

- name: Code linting
run: npm run lint:check
env:
CI: true

- name: Type check
run: npm run check:types

- name: Build nodejs code
run: npm run compile
20 changes: 20 additions & 0 deletions .github/workflows/publish_npmjs.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# After new release is published on github, publish it to npmjs
name: Publish on npmjs

on:
release:
types: [published]

jobs:
publish:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
with:
node-version: 16
registry-url: 'https://registry.npmjs.org'
- run: npm ci
- run: npm publish --access public
env:
NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}
20 changes: 20 additions & 0 deletions .github/workflows/release_github.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# On each new commit to master, create/update a PR with release
# automatically bumps version and creates changelog as per conventional commits
name: Release Github

on:
push:
branches:
- master

jobs:
release-please:
runs-on: ubuntu-latest
steps:
- uses: GoogleCloudPlatform/release-please-action@v2
id: release
with:
token: ${{ secrets.REPO_GHA_PAT }}
release-type: node
package-name: '@fairdatasociety/bmt-js'
bump-minor-pre-major: true
64 changes: 64 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
name: Tests

on:
push:
branches:
- 'master'
pull_request:
branches:
- '**'

env:
WORKERS: 4
BEE_VERSION: '1.4.1'
BLOCKCHAIN_VERSION: '1.2.0'
BEE_ENV_PREFIX: 'swarm-test'
BEE_IMAGE_PREFIX: 'docker.pkg.github.com/ethersphere/bee-factory'
COMMIT_VERSION_TAG: 'false'
BEE_API_URL: 'http://127.0.0.1:1633'
BEE_DEBUG_API_URL: 'http://127.0.0.1:1635'

jobs:
node-tests:
runs-on: ubuntu-latest

strategy:
matrix:
node-version: [14.x, 15.x, 16.x, 17.x]

steps:
- name: Checkout
uses: actions/checkout@v2
with:
fetch-depth: 1

- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}

- name: Auth to Github Package Docker Registry
run: |
echo "${{ secrets.GITHUB_TOKEN }}" | docker login https://docker.pkg.github.com -u ${GITHUB_ACTOR} --password-stdin
# Setup Bee environment
- name: Start Bee Factory environment
run: |
git clone --depth=1 https://github.com/fairDataSociety/bee-factory.git
chmod +x -R ./bee-factory/scripts
./bee-factory/scripts/environment.sh start --detach --workers=$WORKERS
## Try getting the node modules from cache, if failed npm ci
- uses: actions/cache@v2
id: cache-npm
with:
path: node_modules
key: ${{ runner.os }}-node-${{ matrix.node }}-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.OS }}-node-${{ matrix.node }}-${{ env.cache-name }}-
${{ runner.OS }}-node-${{ matrix.node }}-
- name: Install npm deps
if: steps.cache-npm.outputs.cache-hit != 'true'
run: npm ci
- name: Run tests
run: npm run test
18 changes: 18 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Runtime data
pids
*.pid
*.seed

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage
.nyc_output

dist

# Dependency directory
node_modules

.vscode/
13 changes: 13 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"printWidth": 110,
"tabWidth": 2,
"useTabs": false,
"bracketSpacing": true,
"semi": false,
"singleQuote": true,
"quoteProps": "as-needed",
"trailingComma": "all",
"endOfLine": "lf",
"arrowParens": "avoid",
"proseWrap": "always"
}

0 comments on commit ce95662

Please sign in to comment.