Skip to content

Commit

Permalink
fix: module name highwayhasher
Browse files Browse the repository at this point in the history
  • Loading branch information
asonnleitner committed Mar 1, 2022
1 parent 13fb46a commit 4abe1c5
Show file tree
Hide file tree
Showing 24 changed files with 76 additions and 174 deletions.
30 changes: 15 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
![highway-wasm](./docs/preview.png)
![highwayhash-wasm](./docs/preview.png)

# highway-wasm
# highwayhash-wasm

[![npm version][npm-version-src]][npm-href]
[![npm downloads][npm-downloads-src]][npm-href]
Expand All @@ -22,17 +22,17 @@

## Install

Add `highway-wasm` dependency to your project:
Add `highwayhash-wasm` dependency to your project:

```shell
# using npm
npm i highway-wasm
npm i highwayhash-wasm

# using yarn
yarn add highway-wasm
yarn add highwayhash-wasm

# using pnpm
pnpm add highway-wasm
pnpm add highwayhash-wasm
```

## Usage
Expand All @@ -41,16 +41,16 @@ Use this method to generate hashes is the length of the data is not known in adv

```javascript
// import the library using esm or cjs syntax
import { useHighway } from 'highway-wasm'
const { useHighway } = require('highway-wasm')
import { useHighwayHash } from 'highwayhash-wasm'
const { useHighwayHash } = require('highwayhash-wasm')

// Some 32 byte key
const key = new Uint8Array(32).fill(8)
// Some data to hash
const data = Uint8Array.from([0])

// Load the wasm module which returns the the Highway object
const highway = await useHighway({
const highway = await useHighwayHash({
// Optional: pass a key and keep it hidden from attackers to ensure
// unpredictability, and attackers can't mount a DoS attack
key: key,
Expand Down Expand Up @@ -133,10 +133,10 @@ const hash = hasher.hash64(key, data).toBigUint64Array()


<!-- badges -->
[npm-version-src]: https://badgen.net/npm/v/highway-wasm
[npm-href]: https://www.npmjs.com/package/highway-wasm
[npm-downloads-src]: https://badgen.net/npm/dm/highway-wasm
[github-actions-ci-src]: https://github.com/asonnleitner/highway-wasm/actions/workflows/ci.yaml/badge.svg
[github-actions-ci-href]: https://github.com/asonnleitner/highway-wasm/actions/workflows/ci.yaml
[npm-version-src]: https://badgen.net/npm/v/highwayhash-wasm
[npm-href]: https://www.npmjs.com/package/highwayhash-wasm
[npm-downloads-src]: https://badgen.net/npm/dm/highwayhash-wasm
[github-actions-ci-src]: https://github.com/asonnleitner/highwayhash-wasm/actions/workflows/ci.yaml/badge.svg
[github-actions-ci-href]: https://github.com/asonnleitner/highwayhash-wasm/actions/workflows/ci.yaml

[license-src]: https://badgen.net/npm/license/highway-wasm
[license-src]: https://badgen.net/npm/license/highwayhash-wasm
2 changes: 1 addition & 1 deletion api-extractor.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"$schema": "https://developer.microsoft.com/json-schemas/api-extractor/v7/api-extractor.schema.json",
"projectFolder": ".",
"mainEntryPointFilePath": "<projectFolder>/js/highway-wasm/src/index.d.ts",
"mainEntryPointFilePath": "<projectFolder>/js/highwayhash-wasm/src/index.d.ts",
"bundledPackages": [],
"compiler": {
"tsconfigFilePath": "<projectFolder>/tsconfig.json"
Expand Down
1 change: 0 additions & 1 deletion dist/highway-wasm.cjs.js

This file was deleted.

97 changes: 0 additions & 97 deletions dist/highway-wasm.d.ts

This file was deleted.

1 change: 0 additions & 1 deletion dist/highway-wasm.esm.js

This file was deleted.

1 change: 0 additions & 1 deletion dist/highway-wasm.global.js

This file was deleted.

Binary file modified docs/preview.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions highway/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
[package]
name = "highway"
name = "highwayhash"
version = "0.1.0"
authors = ["asonnleitner <andreassonnleitner@gmail.com>"]
description = "A wasm game of life implementation"
repository = "https://github.com/asonnleitner/highway-wasm"
repository = "https://github.com/asonnleitner/highwayhash-wasm"
license = "MIT"
edition = "2021"

Expand Down
6 changes: 3 additions & 3 deletions highway/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,12 +108,12 @@ impl Hash {
}

#[wasm_bindgen]
pub struct WasmHighway {
pub struct WasmHighwayHash {
hasher: HighwayHasher,
}

#[wasm_bindgen]
impl WasmHighway {
impl WasmHighwayHash {
fn hasher(key: &[u8]) -> HighwayHasher {
// console_error_panic_hook::set_once();
return HighwayHasher::new(if key.is_empty() {
Expand All @@ -124,7 +124,7 @@ impl WasmHighway {
}

pub fn new(key: &[u8]) -> Self {
WasmHighway {
WasmHighwayHash {
hasher: Self::hasher(key),
}
}
Expand Down
2 changes: 1 addition & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<html lang="en">
<head>
<title>highwayhash-wasm</title>
<script src="js/highway-wasm/dist/index.js"></script>
<script src="js/highwayhash-wasm/dist/index.js"></script>
<!-- <script type="module" src="./packages/highway/src/index.ts"></script>-->
<!-- <script src="./bootstrap.js"></script>-->
</head>
Expand Down
2 changes: 1 addition & 1 deletion jest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const config: InitialOptionsTsJest = {
// transform: {
// '^.+\\.(ts|js)x?$': 'ts-jest'
// },
// transformIgnorePatterns: ['js/highway-wasm/lib/(?!(highway|highway-simd))']
// transformIgnorePatterns: ['js/highwayhash-wasm/lib/(?!(highway|highway-simd))']
}

export default config
17 changes: 0 additions & 17 deletions js/highway-wasm/src/index.d.ts

This file was deleted.

17 changes: 17 additions & 0 deletions js/highwayhash-wasm/src/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { WasmHighwayHash, Hash } from '../lib/highwayhash/highwayhash'

export declare const useSimd: () => boolean

interface HighwayHashOptions {
key?: Uint8Array
simd?: boolean
}
export declare const useHighwayHash: (options?: HighwayHashOptions) => Promise<{
hasher: typeof WasmHighwayHash
new: (key: Uint8Array) => WasmHighwayHash
hash64: (data: Uint8Array) => Hash
hash128: (data: Uint8Array) => Hash
hash256: (data: Uint8Array) => Hash
}>

export {}
18 changes: 10 additions & 8 deletions js/highway-wasm/src/index.ts → js/highwayhash-wasm/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import init, { WasmHighway as Highway } from '../lib/highway/highway.js'
import { default as WASM } from '../lib/highway/highway_bg.wasm'
import init, {
WasmHighwayHash as HighwayHash
} from '../lib/highwayhash/highwayhash'
import { default as WASM } from '../lib/highwayhash/highwayhash_bg.wasm'
import initSimd, {
WasmHighway as HighwaySimd
} from '../lib/highway-simd/highway-simd'
import { default as simdWASM } from '../lib/highway-simd/highway-simd_bg.wasm'
WasmHighwayHash as HighwayHashSimd
} from '../lib/highwayhash-simd/highwayhash-simd'
import { default as simdWASM } from '../lib/highwayhash-simd/highwayhash-simd_bg.wasm'

// https://github.com/GoogleChromeLabs/wasm-feature-detect/blob/master/src/detectors/simd/module.wat
export const useSimd = () =>
Expand All @@ -14,7 +16,7 @@ export const useSimd = () =>
])
)

const useModule = (hasher: typeof Highway) => (key: Uint8Array) => {
const useModule = (hasher: typeof HighwayHash) => (key: Uint8Array) => {
if (key.length && key.length !== 32) throw new Error('Key must be 32 bytes')

return {
Expand Down Expand Up @@ -43,15 +45,15 @@ interface HighwayOptions {
simd?: boolean
}

export const useHighway = async (options?: HighwayOptions) => {
export const useHighwayHash = async (options?: HighwayOptions) => {
const simd =
useSimd() && options && options.simd !== undefined
? Boolean(options.simd)
: true

console.log({ simd })
simd ? await initSimd(simdWASM) : await init(WASM)
return useModule(simd ? HighwaySimd : Highway)(
return useModule(simd ? HighwayHashSimd : HighwayHash)(
options && options.key ? options.key : Uint8Array.from({ length: 32 })
)
}
File renamed without changes.
4 changes: 2 additions & 2 deletions js/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// import the library
import { useHighway } from 'highway-wasm'
import { useHighwayHash } from 'highwayhash-wasm'

// Load the wasm module
const main = async () => {
Expand All @@ -9,7 +9,7 @@ const main = async () => {
const data = Uint8Array.from([0])

// Load the wasm module which returns the the Highway object
const highway = await useHighway({
const highway = await useHighwayHash({
// Optional: pass a key and keep it hidden from attackers to ensure
// unpredictability, and attackers can't mount a DoS attack
key: key,
Expand Down
22 changes: 11 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
{
"name": "highway-wasm",
"name": "highwayhash-wasm",
"version": "1.2.3",
"description": "HighwayHash WASM bindings for browser and node environments",
"author": "Andreas Sonnleitner <asonnleitner@gmail.com>",
"license": "MIT",
"repository": {
"type": "git",
"url": "git://github.com:asonnleitner/highway-wasm.git"
"url": "git://github.com:asonnleitner/highwayhash-wasm.git"
},
"main": "dist/highway-wasm.cjs.js",
"module": "dist/highway-wasm.esm.js",
"unpkg": "dist/highway-wasm.global.js",
"jsdelivr": "dist/highway-wasm.global.js",
"types": "dist/highway-wasm.d.ts",
"main": "dist/highwayhash-wasm.cjs.js",
"module": "dist/highwayhash-wasm.esm.js",
"unpkg": "dist/highwayhash-wasm.global.js",
"jsdelivr": "dist/highwayhash-wasm.global.js",
"types": "dist/highwayhash-wasm.d.ts",
"files": [
"dist"
],
Expand All @@ -25,11 +25,11 @@
"build": "pnpm clean && pnpm optimized-build:wasm && pnpm build:js && pnpm make-types",
"make-types": "api-extractor run --local --verbose",
"build:js": "pnpm build:esm && pnpm build:cjs && pnpm build:global",
"build:esm": "ts-node scripts/build.ts highway-wasm -f esm",
"build:cjs": "ts-node scripts/build.ts highway-wasm -f cjs",
"build:global": "ts-node scripts/build.ts highway-wasm -f global",
"build:esm": "ts-node scripts/build.ts highwayhash-wasm -f esm",
"build:cjs": "ts-node scripts/build.ts highwayhash-wasm -f cjs",
"build:global": "ts-node scripts/build.ts highwayhash-wasm -f global",
"optimized-build:wasm": "scripts/build && scripts/optimize",
"clean": "rm -rf dist/* && rm -rf js/highway-wasm/lib/*",
"clean": "rm -rf dist/* && rm -rf js/highwayhash-wasm/lib/*",
"prepare": "husky install"
},
"lint-staged": {
Expand Down
4 changes: 2 additions & 2 deletions release.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module.exports = {
branches: 'master',
repositoryUrl: 'https://github.com/asonnleitner/highway-wasm',
repositoryUrl: 'https://github.com/asonnleitner/highwayhash-wasm',
plugins: [
'@semantic-release/commit-analyzer',
'@semantic-release/release-notes-generator',
Expand All @@ -16,7 +16,7 @@ module.exports = {
{
assets: [
{
path: 'highway-wasm/dist.tar.gz',
path: 'highwayhash-wasm/dist.tar.gz',
label: 'dist'
}
]
Expand Down
4 changes: 2 additions & 2 deletions scripts/build
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ function build() {
}

function main() {
build "highway" "${ROOT_DIR}/js/highway-wasm/lib/highway"
RUSTFLAGS="-C target-feature=+simd128" build "highway-simd" "${ROOT_DIR}/js/highway-wasm/lib/highway-simd"
build "highwayhash" "${ROOT_DIR}/js/highwayhash-wasm/lib/highwayhash"
RUSTFLAGS="-C target-feature=+simd128" build "highwayhash-simd" "${ROOT_DIR}/js/highwayhash-wasm/lib/highwayhash-simd"
}

main "$@"
Loading

0 comments on commit 4abe1c5

Please sign in to comment.