browserify / browserify/crypto-browserify

Add support for SHA3

Open
#211 0 comments 2 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
681
Forks
209
PR merge metrics
No merged PRs in 30d

Description

SHA3 is becoming more popular and supported by NodeJS, support for it should be added here as well. The popular package "jsSHA" supports this in a relatively easy to wrap way:

```js
class browserSHA3_256 {
#obj;

constructor(hmacKey = undefined) {
if (hmacKey === undefined) {
this.#obj = new jssha("SHA3-256", "ARRAYBUFFER");
} else {
if (!(hmacKey instanceof Uint8Array)) {
throw(new Error('only support Uint8Array for HMAC Key'));
}

this.#obj = new jssha("SHA3-256", "ARRAYBUFFER", {
hmacKey: {
format: "UINT8ARRAY",
value: hmacKey
}
});
}
}

update(data, options = undefined) {
if (options !== undefined) {
throw(new Error('options for "update" not supported'));
}

if (!(data instanceof ArrayBuffer)) {
data = bufferToArrayBuffer(Buffer.from(data));
}

this.#obj.update(data);

return(this);
}

digest(encoding = undefined) {
let retval;
switch (encoding) {
case 'hex':
retval = this.#obj.getHash("HEX");
break;
case undefined:
retval = Buffer.from(this.#obj.getHash("ARRAYBUFFER"));
break;
default:
throw(new Error(`unsupported encoding "${encoding}"`));
}

return(retval);
}
}
```

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.