-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improved performance, JSDocs, README and added Prettifier
- Loading branch information
1 parent
2d030b3
commit 5498091
Showing
14 changed files
with
431 additions
and
331 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
name: Publish | ||
on: | ||
push: | ||
branches: | ||
- main | ||
|
||
jobs: | ||
publish: | ||
runs-on: ubuntu-latest | ||
|
||
permissions: | ||
contents: read | ||
id-token: write | ||
|
||
steps: | ||
- uses: actions/checkout@v4 | ||
|
||
- name: Publish package | ||
run: npx jsr publish |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"tabWidth": 2, | ||
"useTabs": true, | ||
"printWidth": 160 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,41 @@ | ||
import dts from 'bun-plugin-dts'; | ||
import Logger from '@rabbit-company/logger'; | ||
import fs from 'fs/promises'; | ||
import dts from "bun-plugin-dts"; | ||
import Logger from "@rabbit-company/logger"; | ||
import fs from "fs/promises"; | ||
|
||
await fs.rm('./module', {recursive: true, force: true}); | ||
await fs.rm('./dist', {recursive: true, force: true}); | ||
await fs.rm("./module", { recursive: true, force: true }); | ||
await fs.rm("./dist", { recursive: true, force: true }); | ||
|
||
Logger.info('Start bulding module...'); | ||
Logger.info("Start bulding module..."); | ||
let moduleBuild = await Bun.build({ | ||
entrypoints: ['./src/blake2b.ts'], | ||
outdir: './module', | ||
target: 'browser', | ||
format: 'esm', | ||
plugins: [ | ||
dts({output: {noBanner: true}}) | ||
], | ||
entrypoints: ["./src/blake2b.ts"], | ||
outdir: "./module", | ||
target: "browser", | ||
format: "esm", | ||
plugins: [dts({ output: { noBanner: true } })], | ||
}); | ||
|
||
if(moduleBuild.success){ | ||
Logger.info('Bulding module complete'); | ||
}else{ | ||
Logger.error('Bulding module failed'); | ||
if (moduleBuild.success) { | ||
Logger.info("Bulding module complete"); | ||
} else { | ||
Logger.error("Bulding module failed"); | ||
} | ||
|
||
fs.cp('./src/index.html', './dist/index.html', {recursive: true, force: true}); | ||
fs.cp("./src/index.html", "./dist/index.html", { recursive: true, force: true }); | ||
|
||
Logger.info('Start bundling dist...'); | ||
Logger.info("Start bundling dist..."); | ||
let distBuild = await Bun.build({ | ||
entrypoints: ['./src/index.ts'], | ||
outdir: './dist', | ||
target: 'browser', | ||
format: 'esm', | ||
entrypoints: ["./src/index.ts"], | ||
outdir: "./dist", | ||
target: "browser", | ||
format: "esm", | ||
minify: true, | ||
sourcemap: 'none', // Bun still generates incorrect sourcemaps | ||
plugins: [], | ||
sourcemap: "none", | ||
plugins: [], | ||
}); | ||
|
||
if(distBuild.success){ | ||
Logger.info('Bundling dist complete'); | ||
}else{ | ||
Logger.error('Bundling dist failed'); | ||
if (distBuild.success) { | ||
Logger.info("Bundling dist complete"); | ||
} else { | ||
Logger.error("Bundling dist failed"); | ||
Logger.error(distBuild.logs); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"name": "@rabbit-company/blake2b", | ||
"version": "2.1.0", | ||
"exports": "./src/blake2b.ts" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,52 @@ | ||
export interface CTX { | ||
b: Uint8Array; | ||
h: Uint32Array; | ||
t: number; | ||
c: number; | ||
outlen: number; | ||
} | ||
export default class Blake2b { | ||
v: Uint32Array; | ||
m: Uint32Array; | ||
BLAKE2B_IV32: Uint32Array; | ||
SIGMA8: number[]; | ||
parameterBlock: Uint8Array; | ||
SIGMA82: Uint8Array; | ||
ADD64AA(v: Uint32Array, a: number, b: number): void; | ||
ADD64AC(v: Uint32Array, a: number, b0: number, b1: number): void; | ||
B2B_GET32(arr: Uint8Array, i: number): number; | ||
B2B_G(a: number, b: number, c: number, d: number, ix: number, iy: number): void; | ||
blake2bCompress(ctx: CTX, last: boolean): void; | ||
blake2bInit(outlen: number, key: Uint8Array | undefined, salt: Uint8Array, personal: Uint8Array): CTX; | ||
blake2bUpdate(ctx: CTX, input: Uint8Array): void; | ||
blake2bFinal(ctx: CTX): Uint8Array; | ||
blake2bStart(input: string | Uint8Array, key: Uint8Array | undefined, outlen: number, salt: string | Uint8Array, personal: string | Uint8Array): Uint8Array; | ||
normalizeInput(input: string | Uint8Array): Uint8Array; | ||
toHex(bytes: Uint8Array): string; | ||
/** | ||
* The `Blake2b` namespace provides functionality for generating Blake2b-512 cryptographic hashes. | ||
* It includes methods for creating hashes with optional HMAC mode, specifying output length, | ||
* and applying salt and personalization values. | ||
*/ | ||
declare namespace Blake2b { | ||
/** | ||
* Calculates the Blake2b hash of the given message using the specified parameters. | ||
* Computes the Blake2b hash of the provided message using the given parameters. | ||
* | ||
* @param {string | Uint8Array} message - The input message to be hashed. | ||
* @param {string | Uint8Array | undefined} secret - The secret key for HMAC mode (optional). | ||
* @param {number} [length=64] - The desired length of the hash output in bytes (default is 64). | ||
* @param {string | Uint8Array} [salt=new Uint8Array(16)] - The salt value for the hash function (default is a new Uint8Array(16)). | ||
* @param {string | Uint8Array} [personal=new Uint8Array(16)] - The personalization string for the hash function (default is a new Uint8Array(16)). | ||
* @param {string | Uint8Array} message - The input data to be hashed. This can be a string or a Uint8Array. | ||
* @param {string | Uint8Array | undefined} [secret] - An optional secret key for HMAC mode. This can be a string or a Uint8Array. | ||
* If not provided, a standard Blake2b hash will be computed. If provided, it should be between 1 and 64 bytes in length. | ||
* @param {number} [length=64] - The desired length of the hash output in bytes. The value should be between 1 and 64. Defaults to 64 bytes. | ||
* @param {string | Uint8Array} [salt=new Uint8Array(16)] - An optional salt value for the hash function. This can be a string or a Uint8Array. | ||
* The salt must be exactly 16 bytes long. Defaults to a zeroed 16-byte Uint8Array. | ||
* @param {string | Uint8Array} [personal=new Uint8Array(16)] - An optional personalization string for the hash function. This can be a string or a Uint8Array. | ||
* The personalization string must be exactly 16 bytes long. Defaults to a zeroed 16-byte Uint8Array. | ||
* @returns {string} - The hexadecimal representation of the Blake2b hash output. | ||
*/ | ||
static hash(message: string | Uint8Array | undefined, secret: string | Uint8Array | undefined, length?: number, salt?: string | Uint8Array, personal?: string | Uint8Array): string; | ||
* | ||
* @throws {Error} If the provided output length (`length`) is not within the range of 1 to 64 bytes. | ||
* @throws {Error} If the provided secret key exceeds 64 bytes in length. | ||
* @throws {Error} If the provided salt is not exactly 16 bytes long. | ||
* @throws {Error} If the provided personalization string is not exactly 16 bytes long. | ||
* | ||
* @example | ||
* // Simple usage with a message | ||
* const hashValue = hash('Hello, world!'); | ||
* console.log(hashValue); // Outputs the Blake2b hash as a hex string | ||
* | ||
* @example | ||
* // Using a secret key for HMAC mode | ||
* const hashWithKey = hash('Hello, world!', 'my-secret-key'); | ||
* console.log(hashWithKey); // Outputs the Blake2b HMAC as a hex string | ||
* | ||
* @example | ||
* // Custom output length | ||
* const shortHash = hash('Hello, world!', '', 32); | ||
* console.log(shortHash); // Outputs a 32-byte Blake2b hash as a hex string | ||
* | ||
* @example | ||
* // Using salt and personalization | ||
* const saltedHash = hash('Hello, world!', '', 64, 'my-salt', 'my-personal'); | ||
* console.log(saltedHash); // Outputs a Blake2b hash with salt and personalization as a hex string | ||
*/ | ||
function hash(message?: string | Uint8Array, secret?: string | Uint8Array | undefined, length?: number, salt?: string | Uint8Array, personal?: string | Uint8Array): string; | ||
} | ||
|
||
export { | ||
Blake2b as default, | ||
}; | ||
|
||
export {}; |
Oops, something went wrong.