Skip to content

Commit c4e7663

Browse files
committed
feat: add types, update deps, semantic-release, dependabot
1 parent 8ce0689 commit c4e7663

File tree

9 files changed

+341
-96
lines changed

9 files changed

+341
-96
lines changed

.github/dependabot.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
version: 2
2+
updates:
3+
- package-ecosystem: 'github-actions'
4+
directory: '/'
5+
schedule:
6+
interval: 'daily'
7+
commit-message:
8+
prefix: 'chore'
9+
include: 'scope'
10+
- package-ecosystem: 'npm'
11+
directory: '/'
12+
schedule:
13+
interval: 'daily'
14+
commit-message:
15+
prefix: 'chore'
16+
include: 'scope'

.github/workflows/mikeals-workflow.yml

Lines changed: 0 additions & 50 deletions
This file was deleted.
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
name: Test & Maybe Release
2+
on: [push, pull_request]
3+
jobs:
4+
test:
5+
strategy:
6+
fail-fast: false
7+
matrix:
8+
node: [14.x, 16.x]
9+
os: [macos-latest, ubuntu-latest]
10+
runs-on: ${{ matrix.os }}
11+
steps:
12+
- name: Checkout Repository
13+
uses: actions/checkout@v2.3.4
14+
- name: Use Node.js ${{ matrix.node }}
15+
uses: actions/setup-node@v2.1.5
16+
with:
17+
node-version: ${{ matrix.node }}
18+
- name: Install Dependencies
19+
run: |
20+
npm install --no-progress --no-package-lock
21+
- name: Run tests
22+
run: |
23+
npm test
24+
test-windows:
25+
strategy:
26+
fail-fast: false
27+
matrix:
28+
node: [14.x, 16.x]
29+
os: [windows-latest]
30+
runs-on: ${{ matrix.os }}
31+
steps:
32+
- name: Checkout Repository
33+
uses: actions/checkout@v2.3.4
34+
- name: Use Node.js ${{ matrix.node }}
35+
uses: actions/setup-node@v2.1.5
36+
with:
37+
node-version: ${{ matrix.node }}
38+
- name: Install Dependencies
39+
run: |
40+
npm install --no-progress --no-package-lock
41+
- name: Run tests
42+
run: |
43+
npm run test:node
44+
release:
45+
name: Release
46+
needs: [test, test-windows]
47+
runs-on: ubuntu-latest
48+
if: github.event_name == 'push' && github.ref == 'refs/heads/master'
49+
steps:
50+
- name: Checkout
51+
uses: actions/checkout@v2.3.4
52+
with:
53+
fetch-depth: 0
54+
- name: Setup Node.js
55+
uses: actions/setup-node@v2.1.5
56+
with:
57+
node-version: 14
58+
- name: Install dependencies
59+
run: |
60+
npm install --no-progress --no-package-lock --no-save
61+
- name: Build
62+
run: |
63+
npm run build
64+
- name: Install plugins
65+
run: |
66+
npm install \
67+
@semantic-release/commit-analyzer \
68+
conventional-changelog-conventionalcommits \
69+
@semantic-release/release-notes-generator \
70+
@semantic-release/npm \
71+
@semantic-release/github \
72+
@semantic-release/git \
73+
@semantic-release/changelog \
74+
--no-progress --no-package-lock --no-save
75+
- name: Release
76+
env:
77+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
78+
NPM_TOKEN: ${{ secrets.NPM_AUTH_TOKEN }}
79+
run: npx semantic-release
80+

.npmignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
11
.github
2-
dist/test

index.js

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,23 @@
11
'use strict'
2+
3+
import { from } from 'multiformats/hashes/hasher'
24
import sha3 from 'js-sha3'
3-
const encoder = fn => b => new Uint8Array(fn.array(b))
45

5-
export default [
6-
{ code: 0x14, name: 'sha3-512', encode: encoder(sha3.sha3_512) },
7-
{ code: 0x15, name: 'sha3-384', encode: encoder(sha3.sha3_384) },
8-
{ code: 0x16, name: 'sha3-256', encode: encoder(sha3.sha3_256) },
9-
{ code: 0x17, name: 'sha3-224', encode: encoder(sha3.sha3_224) },
10-
{ code: 0x18, name: 'shake-128', encode: encoder(sha3.shake128) },
11-
{ code: 0x19, name: 'shake-256', encode: encoder(sha3.shake256) },
12-
{ code: 0x1a, name: 'keccak-224', encode: encoder(sha3.keccak224) },
13-
{ code: 0x1b, name: 'keccak-256', encode: encoder(sha3.keccak256) },
14-
{ code: 0x1c, name: 'keccak-384', encode: encoder(sha3.keccak384) },
15-
{ code: 0x1d, name: 'keccak-512', encode: encoder(sha3.keccak512) }
16-
]
6+
/**
7+
* @param {sha3.Hash} fn
8+
* @returns {(inp:Uint8Array)=>Uint8Array}
9+
*/
10+
function encoder (fn) {
11+
return (/** @type {Uint8Array} */ b) => new Uint8Array(fn.array(b))
12+
}
13+
14+
export const sha3512 = from({ code: 0x14, name: 'sha3-512', encode: encoder(sha3.sha3_512) })
15+
export const sha3384 = from({ code: 0x15, name: 'sha3-384', encode: encoder(sha3.sha3_384) })
16+
export const sha3256 = from({ code: 0x16, name: 'sha3-256', encode: encoder(sha3.sha3_256) })
17+
export const sha3224 = from({ code: 0x17, name: 'sha3-224', encode: encoder(sha3.sha3_224) })
18+
export const shake128 = from({ code: 0x18, name: 'shake-128', encode: (b) => new Uint8Array(sha3.shake128.array(b, 256)) })
19+
export const shake256 = from({ code: 0x19, name: 'shake-256', encode: (b) => new Uint8Array(sha3.shake256.array(b, 512)) })
20+
export const keccak224 = from({ code: 0x1a, name: 'keccak-224', encode: encoder(sha3.keccak224) })
21+
export const keccak256 = from({ code: 0x1b, name: 'keccak-256', encode: encoder(sha3.keccak256) })
22+
export const keccak384 = from({ code: 0x1c, name: 'keccak-384', encode: encoder(sha3.keccak384) })
23+
export const keccak512 = from({ code: 0x1d, name: 'keccak-512', encode: encoder(sha3.keccak512) })

package.json

Lines changed: 124 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,47 @@
11
{
22
"name": "@multiformats/sha3",
33
"version": "0.0.0-dev",
4+
"description": "Multiformats hash functions for SHA3",
5+
"main": "index.js",
46
"type": "module",
57
"scripts": {
6-
"build": "npm_config_yes=true npx ipjs@latest build --tests",
7-
"publish": "npm_config_yes=true npx ipjs@latest publish",
8+
"build": "npm run build:js && npm run build:types",
9+
"build:js": "ipjs build --tests --main && npm run build:copy",
10+
"build:copy": "cp -a tsconfig.json *.js dist/",
11+
"build:types": "npm run build:copy && cd dist && tsc --build",
12+
"publish": "ipjs publish",
813
"lint": "standard",
9-
"test:cjs": "npm run build && mocha dist/cjs/node-test/test-*.js",
10-
"test:node": "hundreds mocha test/test-*.js",
11-
"test:browser": "polendina --cleanup dist/cjs/browser-test/test-*.js",
12-
"test": "npm run lint && npm run test:node && npm run test:cjs && npm run test:browser",
13-
"coverage": "c8 --reporter=html mocha test/test-*.js && npx st -d coverage -p 8080"
14+
"test:cjs": "npm run build && mocha dist/cjs/node-test/test-*.js && npm run test:cjs:browser",
15+
"test:node": "c8 --check-coverage --branches 100 --functions 100 --lines 100 mocha test/test-*.js",
16+
"test:cjs:browser": "polendina --cleanup dist/cjs/browser-test/test-*.js",
17+
"test": "npm run lint && npm run test:node && npm run test:cjs",
18+
"coverage": "c8 --reporter=html mocha test/test-*.js && npm_config_yes=true npx st -d coverage -p 8080"
1419
},
1520
"exports": {
1621
"import": "./index.js"
1722
},
18-
"keywords": [],
23+
"keywords": [
24+
"IPFS",
25+
"IPLD",
26+
"multiformats",
27+
"hash",
28+
"multihash",
29+
"blake2"
30+
],
1931
"author": "Mikeal Rogers <mikeal.rogers@gmail.com> (https://www.mikealrogers.com/)",
2032
"license": "(Apache-2.0 AND MIT)",
2133
"dependencies": {
22-
"js-sha3": "^0.8.0"
34+
"js-sha3": "^0.8.0",
35+
"multiformats": "^9.4.1"
2336
},
2437
"devDependencies": {
25-
"hundreds": "0.0.8",
26-
"mocha": "^8.1.1",
27-
"multiformats": "3.0.3",
38+
"c8": "^7.7.3",
39+
"chai": "^4.3.4",
40+
"ipjs": "^5.0.2",
41+
"mocha": "^9.0.2",
2842
"polendina": "^1.1.0",
29-
"standard": "^14.3.4"
43+
"standard": "^16.0.3",
44+
"typescript": "^4.3.5"
3045
},
3146
"repository": {
3247
"type": "git",
@@ -36,5 +51,100 @@
3651
"url": "https://github.com/mikeal/js-sha3/issues"
3752
},
3853
"homepage": "https://github.com/mikeal/js-sha3#readme",
39-
"description": "Multiformats hash functions for SHA3"
54+
"typesVersions": {
55+
"*": {
56+
"*": [
57+
"types/*"
58+
],
59+
"types/*": [
60+
"types/*"
61+
]
62+
}
63+
},
64+
"release": {
65+
"branches": [
66+
"master"
67+
],
68+
"plugins": [
69+
[
70+
"@semantic-release/commit-analyzer",
71+
{
72+
"preset": "conventionalcommits",
73+
"releaseRules": [
74+
{
75+
"breaking": true,
76+
"release": "major"
77+
},
78+
{
79+
"revert": true,
80+
"release": "patch"
81+
},
82+
{
83+
"type": "feat",
84+
"release": "minor"
85+
},
86+
{
87+
"type": "fix",
88+
"release": "patch"
89+
},
90+
{
91+
"type": "chore",
92+
"release": "patch"
93+
},
94+
{
95+
"type": "docs",
96+
"release": "patch"
97+
},
98+
{
99+
"type": "test",
100+
"release": "patch"
101+
},
102+
{
103+
"scope": "no-release",
104+
"release": false
105+
}
106+
]
107+
}
108+
],
109+
[
110+
"@semantic-release/release-notes-generator",
111+
{
112+
"preset": "conventionalcommits",
113+
"presetConfig": {
114+
"types": [
115+
{
116+
"type": "feat",
117+
"section": "Features"
118+
},
119+
{
120+
"type": "fix",
121+
"section": "Bug Fixes"
122+
},
123+
{
124+
"type": "chore",
125+
"section": "Trivial Changes"
126+
},
127+
{
128+
"type": "docs",
129+
"section": "Trivial Changes"
130+
},
131+
{
132+
"type": "test",
133+
"section": "Tests"
134+
}
135+
]
136+
}
137+
}
138+
],
139+
"@semantic-release/changelog",
140+
[
141+
"@semantic-release/npm",
142+
{
143+
"pkgRoot": "dist"
144+
}
145+
],
146+
"@semantic-release/github",
147+
"@semantic-release/git"
148+
]
149+
}
40150
}

test/table.csv.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
export default `
2+
sha3-512, multihash, 0x14, permanent,
3+
sha3-384, multihash, 0x15, permanent,
4+
sha3-256, multihash, 0x16, permanent,
5+
sha3-224, multihash, 0x17, permanent,
6+
shake-128, multihash, 0x18, draft,
7+
shake-256, multihash, 0x19, draft,
8+
keccak-224, multihash, 0x1a, draft, keccak has variable output length. The number specifies the core length
9+
keccak-256, multihash, 0x1b, draft,
10+
keccak-384, multihash, 0x1c, draft,
11+
keccak-512, multihash, 0x1d, draft,
12+
`

0 commit comments

Comments
 (0)