Skip to content

Commit 671b89c

Browse files
committed
feat(argon2): vendor hash-wasm v4.12.0 as @bitgo/argon2
Vendor the argon2 subset of hash-wasm as a new @bitgo/argon2 module, following the same pattern as @bitgo/sjcl. The pre-built UMD bundle (~29KB) contains argon2 and blake2b WASM binaries embedded as base64 with zero runtime dependencies. Exports: argon2id, argon2i, argon2d, argon2Verify with full TypeScript type definitions. Includes verify-vendor.sh script for reproducible re-vendoring from npm. WCN-29 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> TICKET: WCN-29
1 parent b28bbf2 commit 671b89c

File tree

10 files changed

+480
-0
lines changed

10 files changed

+480
-0
lines changed

modules/argon2/.mocharc.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
require: 'tsx'
2+
timeout: '60000'
3+
reporter: 'min'
4+
reporter-option:
5+
- 'cdn=true'
6+
- 'json=false'
7+
exit: true
8+
spec: ['test/**/*.ts']

modules/argon2/CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Change Log
2+
3+
All notable changes to this project will be documented in this file.
4+
5+
## 1.0.0
6+
7+
- Initial release. Vendored argon2 from hash-wasm v4.12.0 (MIT license).
8+
- Provides argon2id, argon2i, argon2d, and argon2Verify functions.
9+
- WASM binaries (~6.6KB argon2 + ~7.4KB blake2b) embedded as base64 in the JS bundle.

modules/argon2/LICENSE

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
MIT License
2+
3+
Copyright (c) 2020 Dani Biro
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.
22+
23+
Vendored from hash-wasm v4.12.0 (https://github.com/Daninet/hash-wasm)

modules/argon2/argon2.umd.min.js

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

modules/argon2/index.d.ts

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/**
2+
* @bitgo/argon2 - Vendored from hash-wasm v4.12.0
3+
* https://github.com/Daninet/hash-wasm
4+
* MIT License - Copyright (c) 2020 Dani Biro
5+
*/
6+
7+
export type ITypedArray = Uint8Array | Uint16Array | Uint32Array;
8+
export type IDataType = string | Buffer | ITypedArray;
9+
10+
export interface IArgon2Options {
11+
/** Password (or message) to be hashed */
12+
password: IDataType;
13+
/** Salt (usually containing random bytes) */
14+
salt: IDataType;
15+
/** Secret for keyed hashing */
16+
secret?: IDataType;
17+
/** Number of iterations to perform */
18+
iterations: number;
19+
/** Degree of parallelism */
20+
parallelism: number;
21+
/** Amount of memory to be used in kibibytes (1024 bytes) */
22+
memorySize: number;
23+
/** Output size in bytes */
24+
hashLength: number;
25+
/** Desired output type. Defaults to 'hex' */
26+
outputType?: 'hex' | 'binary' | 'encoded';
27+
}
28+
29+
interface IArgon2OptionsBinary {
30+
outputType: 'binary';
31+
}
32+
33+
type Argon2ReturnType<T> = T extends IArgon2OptionsBinary ? Uint8Array : string;
34+
35+
/** Calculates hash using the argon2i password-hashing function */
36+
export function argon2i<T extends IArgon2Options>(options: T): Promise<Argon2ReturnType<T>>;
37+
38+
/** Calculates hash using the argon2id password-hashing function */
39+
export function argon2id<T extends IArgon2Options>(options: T): Promise<Argon2ReturnType<T>>;
40+
41+
/** Calculates hash using the argon2d password-hashing function */
42+
export function argon2d<T extends IArgon2Options>(options: T): Promise<Argon2ReturnType<T>>;
43+
44+
export interface Argon2VerifyOptions {
45+
/** Password to be verified */
46+
password: IDataType;
47+
/** Secret used on hash creation */
48+
secret?: IDataType;
49+
/** A previously generated argon2 hash in the 'encoded' output format */
50+
hash: string;
51+
}
52+
53+
/** Verifies password using the argon2 password-hashing function */
54+
export function argon2Verify(options: Argon2VerifyOptions): Promise<boolean>;

modules/argon2/package.json

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"name": "@bitgo/argon2",
3+
"version": "1.0.0",
4+
"description": "Vendored argon2 (hash-wasm v4.12.0) for BitGo SDK",
5+
"main": "argon2.umd.min.js",
6+
"types": "index.d.ts",
7+
"files": [
8+
"argon2.umd.min.js",
9+
"index.d.ts",
10+
"LICENSE"
11+
],
12+
"author": "BitGo SDK Team <sdkteam@bitgo.com>",
13+
"license": "MIT",
14+
"repository": {
15+
"type": "git",
16+
"url": "https://github.com/BitGo/BitGoJS.git",
17+
"directory": "modules/argon2"
18+
},
19+
"publishConfig": {
20+
"access": "public"
21+
}
22+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
#!/usr/bin/env bash
2+
# Verify (or re-vendor) argon2.umd.min.js from hash-wasm on npm.
3+
#
4+
# Usage:
5+
# ./scripts/verify-vendor.sh # verify current file matches upstream
6+
# ./scripts/verify-vendor.sh 4.13.0 # re-vendor from a specific version
7+
#
8+
set -euo pipefail
9+
10+
VERSION="${1:-4.12.0}"
11+
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
12+
MODULE_DIR="$(dirname "$SCRIPT_DIR")"
13+
TARGET="$MODULE_DIR/argon2.umd.min.js"
14+
15+
TMPDIR="$(mktemp -d)"
16+
trap 'rm -rf "$TMPDIR"' EXIT
17+
18+
echo "Downloading hash-wasm@${VERSION} from npm..."
19+
curl -sL "https://registry.npmjs.org/hash-wasm/-/hash-wasm-${VERSION}.tgz" | tar xz -C "$TMPDIR"
20+
21+
UPSTREAM="$TMPDIR/package/dist/argon2.umd.min.js"
22+
if [ ! -f "$UPSTREAM" ]; then
23+
echo "ERROR: argon2.umd.min.js not found in hash-wasm@${VERSION}" >&2
24+
exit 1
25+
fi
26+
27+
UPSTREAM_SHA=$(shasum -a 256 "$UPSTREAM" | awk '{print $1}')
28+
echo "Upstream SHA256: $UPSTREAM_SHA"
29+
30+
if [ -f "$TARGET" ]; then
31+
LOCAL_SHA=$(shasum -a 256 "$TARGET" | awk '{print $1}')
32+
echo "Local SHA256: $LOCAL_SHA"
33+
34+
if [ "$UPSTREAM_SHA" = "$LOCAL_SHA" ]; then
35+
echo "MATCH: vendored file is identical to hash-wasm@${VERSION}"
36+
exit 0
37+
else
38+
echo "MISMATCH: vendored file differs from hash-wasm@${VERSION}"
39+
if [ -z "${1:-}" ]; then
40+
exit 1
41+
fi
42+
fi
43+
fi
44+
45+
if [ -n "${1:-}" ]; then
46+
echo "Copying hash-wasm@${VERSION} argon2.umd.min.js into $MODULE_DIR..."
47+
cp "$UPSTREAM" "$TARGET"
48+
echo "Done. Update the version in package.json description and CHANGELOG.md."
49+
fi

0 commit comments

Comments
 (0)