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

feat: add types to the library #92

Merged
merged 8 commits into from
Feb 2, 2021
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .github/ISSUE_TEMPLATE/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
blank_issues_enabled: false
contact_links:
- name: Getting Help on IPFS
url: https://ipfs.io/help
about: All information about how and where to get help on IPFS.
- name: IPFS Official Forum
url: https://discuss.ipfs.io
about: Please post general questions, support requests, and discussions here.
19 changes: 19 additions & 0 deletions .github/ISSUE_TEMPLATE/open_an_issue.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
---
name: Open an issue
about: Only for actionable issues relevant to this repository.
title: ''
labels: need/triage
assignees: ''

---
<!--
Hello! To ensure this issue is correctly addressed as soon as possible by the IPFS team, please try to make sure:
- This issue is relevant to this repository's topic or codebase.
- A clear description is provided. It should includes as much relevant information as possible and clear scope for the issue to be actionable.
FOR GENERAL DISCUSSION, HELP OR QUESTIONS, please see the options at https://ipfs.io/help or head directly to https://discuss.ipfs.io.
(you can delete this section after reading)
-->
68 changes: 68 additions & 0 deletions .github/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
# Configuration for welcome - https://github.com/behaviorbot/welcome

# Configuration for new-issue-welcome - https://github.com/behaviorbot/new-issue-welcome
# Comment to be posted to on first time issues
newIssueWelcomeComment: >
Thank you for submitting your first issue to this repository! A maintainer
will be here shortly to triage and review.

In the meantime, please double-check that you have provided all the
necessary information to make this process easy! Any information that can
help save additional round trips is useful! We currently aim to give
initial feedback within **two business days**. If this does not happen, feel
free to leave a comment.

Please keep an eye on how this issue will be labeled, as labels give an
overview of priorities, assignments and additional actions requested by the
maintainers:

- "Priority" labels will show how urgent this is for the team.
- "Status" labels will show if this is ready to be worked on, blocked, or in progress.
- "Need" labels will indicate if additional input or analysis is required.

Finally, remember to use https://discuss.ipfs.io if you just need general
support.

# Configuration for new-pr-welcome - https://github.com/behaviorbot/new-pr-welcome
# Comment to be posted to on PRs from first time contributors in your repository
newPRWelcomeComment: >
Thank you for submitting this PR!

A maintainer will be here shortly to review it.

We are super grateful, but we are also overloaded! Help us by making sure
that:

* The context for this PR is clear, with relevant discussion, decisions
and stakeholders linked/mentioned.

* Your contribution itself is clear (code comments, self-review for the
rest) and in its best form. Follow the [code contribution
guidelines](https://github.com/ipfs/community/blob/master/CONTRIBUTING.md#code-contribution-guidelines)
if they apply.

Getting other community members to do a review would be great help too on
complex PRs (you can ask in the chats/forums). If you are unsure about
something, just leave us a comment.

Next steps:

* A maintainer will triage and assign priority to this PR, commenting on
any missing things and potentially assigning a reviewer for high
priority items.

* The PR gets reviews, discussed and approvals as needed.

* The PR is merged by maintainers when it has been approved and comments addressed.

We currently aim to provide initial feedback/triaging within **two business
days**. Please keep an eye on any labelling actions, as these will indicate
priorities and status of your contribution.

We are very grateful for your contribution!


# Configuration for first-pr-merge - https://github.com/behaviorbot/first-pr-merge
# Comment to be posted to on pull requests merged by a first time user
# Currently disabled
#firstPRMergeComment: ""
67 changes: 67 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
name: ci
on:
push:
branches:
- master
pull_request:
branches:
- master

jobs:
check:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- run: npm install
- run: npx aegir lint
- uses: gozala/typescript-error-reporter-action@v1.0.8
- run: npx aegir build
- run: npx aegir dep-check
- uses: ipfs/aegir/actions/bundle-size@master
name: size
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
test-node:
needs: check
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [windows-latest, ubuntu-latest, macos-latest]
node: [12, 14]
fail-fast: true
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node }}
- run: npm install
- run: npx nyc --reporter=lcov aegir test -t node -- --bail
- uses: codecov/codecov-action@v1
test-chrome:
needs: check
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- run: npm install
- run: npx aegir test -t browser -t webworker --bail
test-firefox:
needs: check
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- run: npm install
- run: npx aegir test -t browser -t webworker --bail -- --browsers FirefoxHeadless
test-electron-main:
needs: check
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- run: npm install
- run: npx xvfb-maybe aegir test -t electron-main --bail
test-electron-renderer:
needs: check
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- run: npm install
- run: npx xvfb-maybe aegir test -t electron-renderer --bail
43 changes: 0 additions & 43 deletions .travis.yml

This file was deleted.

20 changes: 0 additions & 20 deletions example.js

This file was deleted.

15 changes: 11 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,15 @@
"browser": {
"./src/sha.js": "./src/sha.browser.js"
},
"types": "dist/src/index.d.ts",
"repository": "github:multiformats/js-multihashing-async",
"scripts": {
"test": "aegir test",
"test:browser": "aegir test -t browser",
"test:node": "aegir test -t node",
"lint": "aegir lint",
"check": "aegir ts -p check",
"prepare": "aegir build --no-bundle",
"docs": "aegir docs",
"release": "aegir release --docs",
"release-minor": "aegir release --type minor --docs",
Expand All @@ -35,17 +38,21 @@
},
"dependencies": {
"blakejs": "^1.1.0",
"err-code": "^2.0.0",
"err-code": "^2.0.3",
"js-sha3": "^0.8.0",
"multihashes": "^3.0.1",
"multihashes": "multiformats/js-multihash#fix/temp-types",
"murmurhash3js-revisited": "^3.0.0",
"uint8arrays": "^1.0.0"
"uint8arrays": "^2.0.5"
},
"devDependencies": {
"aegir": "^25.0.0",
"@types/err-code": "^2.0.0",
"aegir": "ipfs/aegir#feat/docs2.0",
"benchmark": "^2.1.4",
"sinon": "^9.0.2"
},
"eslintConfig": {
"extends": "ipfs"
},
"engines": {
"node": ">=10.0.0",
"npm": ">=6.0.0"
Expand Down
10 changes: 10 additions & 0 deletions src/blake.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
'use strict'

// @ts-ignore - no types available
const blake = require('blakejs')

const minB = 0xb201
Expand All @@ -21,12 +22,21 @@ const blake2s = {
// the function as async because it must return a Promise to match the API
// for other functions that do perform asynchronous work (see sha.browser.js)
// eslint-disable-next-line

/**
* @param {number} size
* @param {any} hf
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: perhaps useful to type hf?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes but im going to defer that to another PR

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#96

* @returns {import('./types').Digest}
*/
const makeB2Hash = (size, hf) => async (data) => {
const ctx = hf.init(size, null)
hf.update(ctx, data)
return hf.digest(ctx)
}

/**
* @param {Record<number, import('./types').Digest>} table
*/
module.exports = (table) => {
for (let i = 0; i < 64; i++) {
table[minB + i] = makeB2Hash(i + 1, blake2b)
Expand Down
6 changes: 6 additions & 0 deletions src/crypto.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use strict'

const sha3 = require('js-sha3')
// @ts-ignore - no types available
const mur = require('murmurhash3js-revisited')
const { factory: sha } = require('./sha')
const { fromNumberTo32BitBuf } = require('./utils')
Expand All @@ -10,6 +11,10 @@ const uint8ArrayFromString = require('uint8arrays/from-string')
// the function as async because it must return a Promise to match the API
// for other functions that do perform asynchronous work (see sha.browser.js)
// eslint-disable-next-line
/**
* @param {string} algorithm
* @returns {import('./types').Digest}
*/
const hash = (algorithm) => async (data) => {
switch (algorithm) {
case 'sha3-224':
Expand Down Expand Up @@ -42,6 +47,7 @@ const hash = (algorithm) => async (data) => {
}
}

/** @type {import('./types').Digest} */
const identity = data => data

module.exports = {
Expand Down
Loading