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

Commit 4b16057

Browse files
Gozalahugomrdiasachingbrain
authored
feat: add types to the library (#92)
Co-authored-by: Hugo Dias <hugomrdias@gmail.com> Co-authored-by: achingbrain <alex@achingbrain.net>
1 parent 338f0b4 commit 4b16057

17 files changed

+302
-90
lines changed

Diff for: .github/ISSUE_TEMPLATE/config.yml

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
blank_issues_enabled: false
2+
contact_links:
3+
- name: Getting Help on IPFS
4+
url: https://ipfs.io/help
5+
about: All information about how and where to get help on IPFS.
6+
- name: IPFS Official Forum
7+
url: https://discuss.ipfs.io
8+
about: Please post general questions, support requests, and discussions here.

Diff for: .github/ISSUE_TEMPLATE/open_an_issue.md

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
---
2+
name: Open an issue
3+
about: Only for actionable issues relevant to this repository.
4+
title: ''
5+
labels: need/triage
6+
assignees: ''
7+
8+
---
9+
<!--
10+
Hello! To ensure this issue is correctly addressed as soon as possible by the IPFS team, please try to make sure:
11+
12+
- This issue is relevant to this repository's topic or codebase.
13+
14+
- A clear description is provided. It should includes as much relevant information as possible and clear scope for the issue to be actionable.
15+
16+
FOR GENERAL DISCUSSION, HELP OR QUESTIONS, please see the options at https://ipfs.io/help or head directly to https://discuss.ipfs.io.
17+
18+
(you can delete this section after reading)
19+
-->

Diff for: .github/config.yml

+68
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
# Configuration for welcome - https://github.com/behaviorbot/welcome
2+
3+
# Configuration for new-issue-welcome - https://github.com/behaviorbot/new-issue-welcome
4+
# Comment to be posted to on first time issues
5+
newIssueWelcomeComment: >
6+
Thank you for submitting your first issue to this repository! A maintainer
7+
will be here shortly to triage and review.
8+
9+
In the meantime, please double-check that you have provided all the
10+
necessary information to make this process easy! Any information that can
11+
help save additional round trips is useful! We currently aim to give
12+
initial feedback within **two business days**. If this does not happen, feel
13+
free to leave a comment.
14+
15+
Please keep an eye on how this issue will be labeled, as labels give an
16+
overview of priorities, assignments and additional actions requested by the
17+
maintainers:
18+
19+
- "Priority" labels will show how urgent this is for the team.
20+
- "Status" labels will show if this is ready to be worked on, blocked, or in progress.
21+
- "Need" labels will indicate if additional input or analysis is required.
22+
23+
Finally, remember to use https://discuss.ipfs.io if you just need general
24+
support.
25+
26+
# Configuration for new-pr-welcome - https://github.com/behaviorbot/new-pr-welcome
27+
# Comment to be posted to on PRs from first time contributors in your repository
28+
newPRWelcomeComment: >
29+
Thank you for submitting this PR!
30+
31+
A maintainer will be here shortly to review it.
32+
33+
We are super grateful, but we are also overloaded! Help us by making sure
34+
that:
35+
36+
* The context for this PR is clear, with relevant discussion, decisions
37+
and stakeholders linked/mentioned.
38+
39+
* Your contribution itself is clear (code comments, self-review for the
40+
rest) and in its best form. Follow the [code contribution
41+
guidelines](https://github.com/ipfs/community/blob/master/CONTRIBUTING.md#code-contribution-guidelines)
42+
if they apply.
43+
44+
Getting other community members to do a review would be great help too on
45+
complex PRs (you can ask in the chats/forums). If you are unsure about
46+
something, just leave us a comment.
47+
48+
Next steps:
49+
50+
* A maintainer will triage and assign priority to this PR, commenting on
51+
any missing things and potentially assigning a reviewer for high
52+
priority items.
53+
54+
* The PR gets reviews, discussed and approvals as needed.
55+
56+
* The PR is merged by maintainers when it has been approved and comments addressed.
57+
58+
We currently aim to provide initial feedback/triaging within **two business
59+
days**. Please keep an eye on any labelling actions, as these will indicate
60+
priorities and status of your contribution.
61+
62+
We are very grateful for your contribution!
63+
64+
65+
# Configuration for first-pr-merge - https://github.com/behaviorbot/first-pr-merge
66+
# Comment to be posted to on pull requests merged by a first time user
67+
# Currently disabled
68+
#firstPRMergeComment: ""

Diff for: .github/workflows/main.yml

+67
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
name: ci
2+
on:
3+
push:
4+
branches:
5+
- master
6+
pull_request:
7+
branches:
8+
- master
9+
10+
jobs:
11+
check:
12+
runs-on: ubuntu-latest
13+
steps:
14+
- uses: actions/checkout@v2
15+
- run: npm install
16+
- run: npx aegir lint
17+
- uses: gozala/typescript-error-reporter-action@v1.0.8
18+
- run: npx aegir build
19+
- run: npx aegir dep-check
20+
- uses: ipfs/aegir/actions/bundle-size@master
21+
name: size
22+
with:
23+
github_token: ${{ secrets.GITHUB_TOKEN }}
24+
test-node:
25+
needs: check
26+
runs-on: ${{ matrix.os }}
27+
strategy:
28+
matrix:
29+
os: [windows-latest, ubuntu-latest, macos-latest]
30+
node: [12, 14]
31+
fail-fast: true
32+
steps:
33+
- uses: actions/checkout@v2
34+
- uses: actions/setup-node@v1
35+
with:
36+
node-version: ${{ matrix.node }}
37+
- run: npm install
38+
- run: npx nyc --reporter=lcov aegir test -t node -- --bail
39+
- uses: codecov/codecov-action@v1
40+
test-chrome:
41+
needs: check
42+
runs-on: ubuntu-latest
43+
steps:
44+
- uses: actions/checkout@v2
45+
- run: npm install
46+
- run: npx aegir test -t browser -t webworker --bail
47+
test-firefox:
48+
needs: check
49+
runs-on: ubuntu-latest
50+
steps:
51+
- uses: actions/checkout@v2
52+
- run: npm install
53+
- run: npx aegir test -t browser -t webworker --bail -- --browsers FirefoxHeadless
54+
test-electron-main:
55+
needs: check
56+
runs-on: ubuntu-latest
57+
steps:
58+
- uses: actions/checkout@v2
59+
- run: npm install
60+
- run: npx xvfb-maybe aegir test -t electron-main --bail
61+
test-electron-renderer:
62+
needs: check
63+
runs-on: ubuntu-latest
64+
steps:
65+
- uses: actions/checkout@v2
66+
- run: npm install
67+
- run: npx xvfb-maybe aegir test -t electron-renderer --bail

Diff for: .travis.yml

-43
This file was deleted.

Diff for: example.js

-20
This file was deleted.

Diff for: package.json

+12-4
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,15 @@
2020
"browser": {
2121
"./src/sha.js": "./src/sha.browser.js"
2222
},
23+
"types": "dist/src/index.d.ts",
2324
"repository": "github:multiformats/js-multihashing-async",
2425
"scripts": {
2526
"test": "aegir test",
2627
"test:browser": "aegir test -t browser",
2728
"test:node": "aegir test -t node",
2829
"lint": "aegir lint",
30+
"check": "aegir ts -p check",
31+
"prepare": "aegir build --no-bundle",
2932
"docs": "aegir docs",
3033
"release": "aegir release --docs",
3134
"release-minor": "aegir release --type minor --docs",
@@ -35,17 +38,22 @@
3538
},
3639
"dependencies": {
3740
"blakejs": "^1.1.0",
38-
"err-code": "^2.0.0",
41+
"err-code": "^3.0.0",
3942
"js-sha3": "^0.8.0",
40-
"multihashes": "^3.0.1",
43+
"multihashes": "^3.1.2",
4144
"murmurhash3js-revisited": "^3.0.0",
42-
"uint8arrays": "^1.0.0"
45+
"uint8arrays": "^2.0.5"
4346
},
4447
"devDependencies": {
45-
"aegir": "^25.0.0",
48+
"@types/err-code": "^2.0.0",
49+
"@types/sinon": "^9.0.10",
50+
"aegir": "^30.3.0",
4651
"benchmark": "^2.1.4",
4752
"sinon": "^9.0.2"
4853
},
54+
"eslintConfig": {
55+
"extends": "ipfs"
56+
},
4957
"engines": {
5058
"node": ">=10.0.0",
5159
"npm": ">=6.0.0"

Diff for: src/blake.js

+10
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
'use strict'
22

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

56
const minB = 0xb201
@@ -21,12 +22,21 @@ const blake2s = {
2122
// the function as async because it must return a Promise to match the API
2223
// for other functions that do perform asynchronous work (see sha.browser.js)
2324
// eslint-disable-next-line
25+
26+
/**
27+
* @param {number} size
28+
* @param {any} hf
29+
* @returns {import('./types').Digest}
30+
*/
2431
const makeB2Hash = (size, hf) => async (data) => {
2532
const ctx = hf.init(size, null)
2633
hf.update(ctx, data)
2734
return hf.digest(ctx)
2835
}
2936

37+
/**
38+
* @param {Record<number, import('./types').Digest>} table
39+
*/
3040
module.exports = (table) => {
3141
for (let i = 0; i < 64; i++) {
3242
table[minB + i] = makeB2Hash(i + 1, blake2b)

Diff for: src/crypto.js

+6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
'use strict'
22

33
const sha3 = require('js-sha3')
4+
// @ts-ignore - no types available
45
const mur = require('murmurhash3js-revisited')
56
const { factory: sha } = require('./sha')
67
const { fromNumberTo32BitBuf } = require('./utils')
@@ -10,6 +11,10 @@ const uint8ArrayFromString = require('uint8arrays/from-string')
1011
// the function as async because it must return a Promise to match the API
1112
// for other functions that do perform asynchronous work (see sha.browser.js)
1213
// eslint-disable-next-line
14+
/**
15+
* @param {string} algorithm
16+
* @returns {import('./types').Digest}
17+
*/
1318
const hash = (algorithm) => async (data) => {
1419
switch (algorithm) {
1520
case 'sha3-224':
@@ -42,6 +47,7 @@ const hash = (algorithm) => async (data) => {
4247
}
4348
}
4449

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

4753
module.exports = {

0 commit comments

Comments
 (0)