Skip to content

Commit

Permalink
feat!: add types, update deps, semantic-release, dependabot
Browse files Browse the repository at this point in the history
  • Loading branch information
rvagg committed Jul 16, 2021
1 parent e147f9b commit d794400
Show file tree
Hide file tree
Showing 9 changed files with 341 additions and 96 deletions.
16 changes: 16 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
version: 2
updates:
- package-ecosystem: 'github-actions'
directory: '/'
schedule:
interval: 'daily'
commit-message:
prefix: 'chore'
include: 'scope'
- package-ecosystem: 'npm'
directory: '/'
schedule:
interval: 'daily'
commit-message:
prefix: 'chore'
include: 'scope'
50 changes: 0 additions & 50 deletions .github/workflows/mikeals-workflow.yml

This file was deleted.

80 changes: 80 additions & 0 deletions .github/workflows/test-and-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
name: Test & Maybe Release
on: [push, pull_request]
jobs:
test:
strategy:
fail-fast: false
matrix:
node: [14.x, 16.x]
os: [macos-latest, ubuntu-latest]
runs-on: ${{ matrix.os }}
steps:
- name: Checkout Repository
uses: actions/checkout@v2.3.4
- name: Use Node.js ${{ matrix.node }}
uses: actions/setup-node@v2.1.5
with:
node-version: ${{ matrix.node }}
- name: Install Dependencies
run: |
npm install --no-progress --no-package-lock
- name: Run tests
run: |
npm test
test-windows:
strategy:
fail-fast: false
matrix:
node: [14.x, 16.x]
os: [windows-latest]
runs-on: ${{ matrix.os }}
steps:
- name: Checkout Repository
uses: actions/checkout@v2.3.4
- name: Use Node.js ${{ matrix.node }}
uses: actions/setup-node@v2.1.5
with:
node-version: ${{ matrix.node }}
- name: Install Dependencies
run: |
npm install --no-progress --no-package-lock
- name: Run tests
run: |
npm run test:node
release:
name: Release
needs: [test, test-windows]
runs-on: ubuntu-latest
if: github.event_name == 'push' && github.ref == 'refs/heads/master'
steps:
- name: Checkout
uses: actions/checkout@v2.3.4
with:
fetch-depth: 0
- name: Setup Node.js
uses: actions/setup-node@v2.1.5
with:
node-version: 14
- name: Install dependencies
run: |
npm install --no-progress --no-package-lock --no-save
- name: Build
run: |
npm run build
- name: Install plugins
run: |
npm install \
@semantic-release/commit-analyzer \
conventional-changelog-conventionalcommits \
@semantic-release/release-notes-generator \
@semantic-release/npm \
@semantic-release/github \
@semantic-release/git \
@semantic-release/changelog \
--no-progress --no-package-lock --no-save
- name: Release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_AUTH_TOKEN }}
run: npx semantic-release

1 change: 0 additions & 1 deletion .npmignore
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
.github
dist/test
33 changes: 20 additions & 13 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,23 @@
'use strict'

import { from } from 'multiformats/hashes/hasher'
import sha3 from 'js-sha3'
const encoder = fn => b => new Uint8Array(fn.array(b))

export default [
{ code: 0x14, name: 'sha3-512', encode: encoder(sha3.sha3_512) },
{ code: 0x15, name: 'sha3-384', encode: encoder(sha3.sha3_384) },
{ code: 0x16, name: 'sha3-256', encode: encoder(sha3.sha3_256) },
{ code: 0x17, name: 'sha3-224', encode: encoder(sha3.sha3_224) },
{ code: 0x18, name: 'shake-128', encode: encoder(sha3.shake128) },
{ code: 0x19, name: 'shake-256', encode: encoder(sha3.shake256) },
{ code: 0x1a, name: 'keccak-224', encode: encoder(sha3.keccak224) },
{ code: 0x1b, name: 'keccak-256', encode: encoder(sha3.keccak256) },
{ code: 0x1c, name: 'keccak-384', encode: encoder(sha3.keccak384) },
{ code: 0x1d, name: 'keccak-512', encode: encoder(sha3.keccak512) }
]
/**
* @param {sha3.Hash} fn
* @returns {(inp:Uint8Array)=>Uint8Array}
*/
function encoder (fn) {
return (/** @type {Uint8Array} */ b) => new Uint8Array(fn.array(b))
}

export const sha3512 = from({ code: 0x14, name: 'sha3-512', encode: encoder(sha3.sha3_512) })
export const sha3384 = from({ code: 0x15, name: 'sha3-384', encode: encoder(sha3.sha3_384) })
export const sha3256 = from({ code: 0x16, name: 'sha3-256', encode: encoder(sha3.sha3_256) })
export const sha3224 = from({ code: 0x17, name: 'sha3-224', encode: encoder(sha3.sha3_224) })
export const shake128 = from({ code: 0x18, name: 'shake-128', encode: (b) => new Uint8Array(sha3.shake128.array(b, 256)) })
export const shake256 = from({ code: 0x19, name: 'shake-256', encode: (b) => new Uint8Array(sha3.shake256.array(b, 512)) })
export const keccak224 = from({ code: 0x1a, name: 'keccak-224', encode: encoder(sha3.keccak224) })
export const keccak256 = from({ code: 0x1b, name: 'keccak-256', encode: encoder(sha3.keccak256) })
export const keccak384 = from({ code: 0x1c, name: 'keccak-384', encode: encoder(sha3.keccak384) })
export const keccak512 = from({ code: 0x1d, name: 'keccak-512', encode: encoder(sha3.keccak512) })
138 changes: 124 additions & 14 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,32 +1,47 @@
{
"name": "@multiformats/sha3",
"version": "0.0.0-dev",
"description": "Multiformats hash functions for SHA3",
"main": "index.js",
"type": "module",
"scripts": {
"build": "npm_config_yes=true npx ipjs@latest build --tests",
"publish": "npm_config_yes=true npx ipjs@latest publish",
"build": "npm run build:js && npm run build:types",
"build:js": "ipjs build --tests --main && npm run build:copy",
"build:copy": "cp -a tsconfig.json *.js dist/",
"build:types": "npm run build:copy && cd dist && tsc --build",
"publish": "ipjs publish",
"lint": "standard",
"test:cjs": "npm run build && mocha dist/cjs/node-test/test-*.js",
"test:node": "hundreds mocha test/test-*.js",
"test:browser": "polendina --cleanup dist/cjs/browser-test/test-*.js",
"test": "npm run lint && npm run test:node && npm run test:cjs && npm run test:browser",
"coverage": "c8 --reporter=html mocha test/test-*.js && npx st -d coverage -p 8080"
"test:cjs": "npm run build && mocha dist/cjs/node-test/test-*.js && npm run test:cjs:browser",
"test:node": "c8 --check-coverage --branches 100 --functions 100 --lines 100 mocha test/test-*.js",
"test:cjs:browser": "polendina --cleanup dist/cjs/browser-test/test-*.js",
"test": "npm run lint && npm run test:node && npm run test:cjs",
"coverage": "c8 --reporter=html mocha test/test-*.js && npm_config_yes=true npx st -d coverage -p 8080"
},
"exports": {
"import": "./index.js"
},
"keywords": [],
"keywords": [
"IPFS",
"IPLD",
"multiformats",
"hash",
"multihash",
"blake2"
],
"author": "Mikeal Rogers <mikeal.rogers@gmail.com> (https://www.mikealrogers.com/)",
"license": "(Apache-2.0 AND MIT)",
"dependencies": {
"js-sha3": "^0.8.0"
"js-sha3": "^0.8.0",
"multiformats": "^9.4.1"
},
"devDependencies": {
"hundreds": "0.0.8",
"mocha": "^8.1.1",
"multiformats": "3.0.3",
"c8": "^7.7.3",
"chai": "^4.3.4",
"ipjs": "^5.0.2",
"mocha": "^9.0.2",
"polendina": "^1.1.0",
"standard": "^14.3.4"
"standard": "^16.0.3",
"typescript": "^4.3.5"
},
"repository": {
"type": "git",
Expand All @@ -36,5 +51,100 @@
"url": "https://github.com/mikeal/js-sha3/issues"
},
"homepage": "https://github.com/mikeal/js-sha3#readme",
"description": "Multiformats hash functions for SHA3"
"typesVersions": {
"*": {
"*": [
"types/*"
],
"types/*": [
"types/*"
]
}
},
"release": {
"branches": [
"master"
],
"plugins": [
[
"@semantic-release/commit-analyzer",
{
"preset": "conventionalcommits",
"releaseRules": [
{
"breaking": true,
"release": "major"
},
{
"revert": true,
"release": "patch"
},
{
"type": "feat",
"release": "minor"
},
{
"type": "fix",
"release": "patch"
},
{
"type": "chore",
"release": "patch"
},
{
"type": "docs",
"release": "patch"
},
{
"type": "test",
"release": "patch"
},
{
"scope": "no-release",
"release": false
}
]
}
],
[
"@semantic-release/release-notes-generator",
{
"preset": "conventionalcommits",
"presetConfig": {
"types": [
{
"type": "feat",
"section": "Features"
},
{
"type": "fix",
"section": "Bug Fixes"
},
{
"type": "chore",
"section": "Trivial Changes"
},
{
"type": "docs",
"section": "Trivial Changes"
},
{
"type": "test",
"section": "Tests"
}
]
}
}
],
"@semantic-release/changelog",
[
"@semantic-release/npm",
{
"pkgRoot": "dist"
}
],
"@semantic-release/github",
"@semantic-release/git"
]
}
}
12 changes: 12 additions & 0 deletions test/table.csv.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
export default `
sha3-512, multihash, 0x14, permanent,
sha3-384, multihash, 0x15, permanent,
sha3-256, multihash, 0x16, permanent,
sha3-224, multihash, 0x17, permanent,
shake-128, multihash, 0x18, draft,
shake-256, multihash, 0x19, draft,
keccak-224, multihash, 0x1a, draft, keccak has variable output length. The number specifies the core length
keccak-256, multihash, 0x1b, draft,
keccak-384, multihash, 0x1c, draft,
keccak-512, multihash, 0x1d, draft,
`
Loading

0 comments on commit d794400

Please sign in to comment.