Skip to content

Commit

Permalink
feat: Add new hash functions and some small changes
Browse files Browse the repository at this point in the history
  • Loading branch information
pigri committed Mar 17, 2024
1 parent 6768017 commit 21d9ac0
Show file tree
Hide file tree
Showing 10 changed files with 394 additions and 18 deletions.
19 changes: 19 additions & 0 deletions .github/workflows/publish.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: npm-publish
on:
workflow_dispatch:
jobs:
build:
runs-on: ubuntu-latest
permissions:
contents: read
id-token: write
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: '18.x'
registry-url: 'https://registry.npmjs.org'
- run: npm ci
- run: npm publish --provenance --access public
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
4 changes: 2 additions & 2 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Sync service prod
name: Test and Build

on:
push:
Expand All @@ -25,4 +25,4 @@ jobs:
cache: 'pnpm'
- run: pnpm install
- run: pnpm run build
- run: NODE_ENV=test pnpm test
- run: pnpm test
17 changes: 13 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
# Hash function for Cloudflare Workers
# Hash functions for Cloudflare Workers

[![NPM](https://nodei.co/npm/cf-workers-hash.png?stars&downloads)](https://nodei.co/npm/cf-workers-hash/)

![GitHub CI](https://github.com/pigri/cf-workers-hash/actions/workflows/test.yaml/badge.svg)

![NPM Publish](https://github.com/pigri/cf-workers-hash/actions/workflows/publish.yaml/badge.svg)

### What is this?
This is a simple hash function library for Cloudflare Workers. It supports the following hash functions:
Expand All @@ -7,11 +13,11 @@ This is a simple hash function library for Cloudflare Workers. It supports the f
- SHA-384
- SHA-512
- MD5
- BASE64
- BASE64 / BASE64-DECODE
- XXHASH32
- XXHASH64
- BCRYPT / BCRYPT-COMPARE
- WHIRLPOOL
- WHIRLPOOL / WHIRLPOOL-DECODE
- SHA3-224
- SHA3-256
- SHA3-384
Expand All @@ -20,6 +26,9 @@ This is a simple hash function library for Cloudflare Workers. It supports the f
- KECCAK256
- KECCAK384
- KECCAK512
- MD6
- CRC32
- CRC32C

### How to install?
```
Expand All @@ -31,7 +40,7 @@ npm install cf-workers-hash
Check the `example` directory.

```
import { sha1, sha256, sha384, sha512, base64, md5, xxhash64, xxhash32, bcrypt, bcryptCompare, whirlpool, sha3_512, sha3_224, sha3_256, sha3_384, keccak512, keccak384, keccak256, keccak224 } from 'cf-workers-hash';
import { sha1, sha256, sha384, sha512, base64, base64Decode, md5, xxhash64, xxhash32, bcrypt, bcryptCompare, whirlpool, whirlpoolDecode, sha3_512, sha3_224, sha3_256, sha3_384, keccak512, keccak384, keccak256, keccak224, md6, crc32, crc32c } from 'cf-workers-hash';
await sha1('test');
```

Expand Down
32 changes: 30 additions & 2 deletions example/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,26 @@
import { sha1, sha256, sha384, sha512, base64, md5, xxhash64, xxhash32, bcrypt, whirlpool, sha3_512, sha3_224, sha3_256, sha3_384, keccak512, keccak384, keccak256, keccak224 } from '../../dist';
import {
sha1,
sha256,
sha384,
sha512,
base64,
md5,
xxhash64,
xxhash32,
bcrypt,
whirlpool,
sha3_512,
sha3_224,
sha3_256,
sha3_384,
keccak512,
keccak384,
keccak256,
keccak224,
md6,
crc32,
crc32c
} from '../../dist';

export default {
async fetch(_: Request) {
Expand All @@ -21,6 +43,9 @@ export default {
const hashKeccak384 = await keccak384(testString);
const hashKeccak256 = await keccak256(testString);
const hashKeccak224 = await keccak224(testString);
const hashMd6 = await md6(testString);
const hashCrc32 = await crc32(testString);
const hashCrc32c = await crc32c(testString);

const data = {
testString,
Expand All @@ -41,7 +66,10 @@ export default {
hashKeccak512,
hashKeccak384,
hashKeccak256,
hashKeccak224
hashKeccak224,
hashMd6,
hashCrc32,
hashCrc32c
};

return Response.json(data);
Expand Down
2 changes: 1 addition & 1 deletion example/wrangler.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "cf-worker-hash-example"
main = "src/index.ts"
compatibility_date = "2024-03-04"
compatibility_flags = [ "nodejs_compat", "nodejs_als"]
node_compat = true
workers_dev = true
#logpush = true

Expand Down
11 changes: 9 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "cf-workers-hash",
"version": "1.0.1",
"version": "1.0.2",
"description": "A simple hash function for Cloudflare Workers",
"main": "./dist/index.js",
"module": "./dist/index.mjs",
Expand All @@ -22,10 +22,14 @@
"cloudflare",
"hash",
"crypto",
"cf"
"cf",
"workers",
"cf-workers",
"cloudflare-workers"
],
"devDependencies": {
"@cloudflare/workers-types": "4.20240314.0",
"@swc/core": "1.4.8",
"@types/bcryptjs": "2.4.6",
"@types/jest": "29.5.12",
"@types/node": "20.11.28",
Expand All @@ -52,9 +56,12 @@
},
"homepage": "https://github.com/pigri/cf-workers-hash#readme",
"dependencies": {
"@aws-crypto/crc32": "5.2.0",
"@aws-crypto/crc32c": "5.2.0",
"bcryptjs": "2.4.3",
"js-md5": "0.8.3",
"js-sha3": "0.9.3",
"md6-hash": "1.0.0",
"whirlpool-hash": "1.1.6",
"xxhashjs": "0.2.2"
}
Expand Down
Loading

0 comments on commit 21d9ac0

Please sign in to comment.