Skip to content

Commit f66abff

Browse files
authored
feat(*): upgrade to NAPI-RS 3.0 alpha (#897)
1 parent f27d119 commit f66abff

33 files changed

+731
-794
lines changed

.denolint.json

Lines changed: 0 additions & 21 deletions
This file was deleted.

.taplo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,6 @@ exclude = ["node_modules/**/*.toml"]
33
# https://taplo.tamasfe.dev/configuration/formatter-options.html
44
[formatting]
55
align_entries = true
6+
column_width = 180
67
indent_tables = true
78
reorder_keys = true

Cargo.toml

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,29 @@
11
[workspace]
2-
members = [
3-
"./crates/alloc",
4-
"./packages/argon2",
5-
"./packages/bcrypt",
6-
"./packages/crc32",
7-
"./packages/jieba",
8-
"./packages/jsonwebtoken",
9-
"./packages/xxhash",
10-
]
2+
members = ["./crates/alloc", "./packages/argon2", "./packages/bcrypt", "./packages/crc32", "./packages/jieba", "./packages/jsonwebtoken", "./packages/xxhash"]
113
resolver = "2"
124

5+
[workspace.dependencies]
6+
argon2 = { version = "0.5", features = ["rand"] }
7+
base64 = { version = "0.22" }
8+
bcrypt = "0.15"
9+
blowfish = { version = "0.9", features = ["bcrypt"] }
10+
crc32c = { version = "0.6" }
11+
crc32fast = { version = "1.4", features = ["nightly"] }
12+
getrandom = "0.2"
13+
global_alloc = { path = "./crates/alloc" }
14+
indexmap = { version = "2", features = ["serde"] }
15+
jieba-rs = { version = "0.6", features = ["default-dict", "tfidf", "textrank"] }
16+
jsonwebtoken = { version = "9" }
17+
mimalloc = "0.1"
18+
napi = { version = "3.0.0-alpha.13", default-features = false, features = ["napi3"] }
19+
napi-build = "2"
20+
napi-derive = { version = "3.0.0-alpha.13", default-features = false, features = ["type-def"] }
21+
once_cell = "1"
22+
quickcheck = "1.0"
23+
rand_core = { version = "0.6", features = ["getrandom"] }
24+
serde = "1.0"
25+
serde_json = "1.0"
26+
xxhash-rust = { version = "0.8", features = ["xxh32", "xxh64", "xxh3"] }
1327
[profile.release]
1428
codegen-units = 1
1529
lto = true

crates/alloc/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ version = "0.1.0"
66
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
77

88
[target.'cfg(all(not(target_os = "linux"), not(target_family = "wasm")))'.dependencies]
9-
mimalloc = { version = "0.1" }
9+
mimalloc = { workspace = true }
1010

1111
[target.'cfg(target_os = "linux")'.dependencies]
12-
mimalloc = { version = "0.1", features = ["local_dynamic_tls"] }
12+
mimalloc = { workspace = true, features = ["local_dynamic_tls"] }

package.json

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -24,27 +24,27 @@
2424
"postinstall": "husky install"
2525
},
2626
"devDependencies": {
27-
"@napi-rs/cli": "^3.0.0-alpha.54",
28-
"@napi-rs/wasm-runtime": "^0.2.4",
29-
"@swc-node/core": "^1.13.1",
30-
"@swc-node/register": "^1.10.0",
31-
"@swc/core": "^1.6.7",
27+
"@napi-rs/cli": "^3.0.0-alpha.63",
28+
"@napi-rs/wasm-runtime": "^0.2.5",
29+
"@swc-node/core": "^1.13.3",
30+
"@swc-node/register": "^1.10.9",
31+
"@swc/core": "^1.7.26",
3232
"@taplo/cli": "^0.7.0",
3333
"@tybys/wasm-util": "^0.9.0",
34-
"@types/node": "^20.14.9",
34+
"@types/node": "^22.7.4",
3535
"ava": "^6.1.3",
3636
"benchmark": "^2.1.4",
3737
"codecov": "^3.8.3",
3838
"cross-env": "^7.0.3",
39-
"husky": "^9.0.11",
40-
"lerna": "^8.1.5",
41-
"lint-staged": "^15.2.7",
42-
"npm-run-all2": "^6.2.1",
43-
"oxlint": "^0.9.0",
44-
"prettier": "^3.3.2",
39+
"husky": "^9.1.6",
40+
"lerna": "^8.1.8",
41+
"lint-staged": "^15.2.10",
42+
"npm-run-all2": "^6.2.3",
43+
"oxlint": "^0.9.9",
44+
"prettier": "^3.3.3",
4545
"ts-node": "^10.9.2",
46-
"tslib": "^2.6.3",
47-
"typescript": "^5.5.3"
46+
"tslib": "^2.7.0",
47+
"typescript": "^5.6.2"
4848
},
4949
"lint-staged": {
5050
"*.@(js|ts|tsx)": [

packages/argon2/Cargo.toml

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,11 @@ version = "0.0.0"
77
crate-type = ["cdylib"]
88

99
[dependencies]
10-
argon2 = { version = "0.5", features = ["rand"] }
11-
global_alloc = { path = "../../crates/alloc" }
12-
napi = { version = "2", default-features = false, features = ["napi3"] }
13-
napi-derive = { version = "2", default-features = false, features = [
14-
"type-def",
15-
] }
16-
rand_core = { version = "0.6", features = ["getrandom"] }
10+
argon2 = { workspace = true }
11+
global_alloc = { workspace = true }
12+
napi = { workspace = true, features = ["napi3"] }
13+
napi-derive = { workspace = true, default-features = false, features = ["type-def"] }
14+
rand_core = { workspace = true }
1715

1816
[build-dependencies]
19-
napi-build = "2"
17+
napi-build = { workspace = true }

packages/argon2/index.d.ts

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* auto-generated by NAPI-RS */
22
/* eslint-disable */
3-
export const enum Algorithm {
3+
export declare const enum Algorithm {
44
/**
55
* Optimizes against GPU cracking attacks but vulnerable to side-channels.
66
* Accesses the memory array in a password dependent order, reducing the possibility of time–memory tradeoff (TMTO) attacks.
@@ -19,13 +19,13 @@ export const enum Algorithm {
1919
Argon2id = 2
2020
}
2121

22-
export declare function hash(password: string | Buffer, options?: Options | undefined | null, abortSignal?: AbortSignal | undefined | null): Promise<string>
22+
export declare function hash(password: string | Uint8Array, options?: Options | undefined | null, abortSignal?: AbortSignal | undefined | null): Promise<string>
2323

24-
export declare function hashRaw(password: string | Buffer, options?: Options | undefined | null, abortSignal?: AbortSignal | undefined | null): Promise<Buffer>
24+
export declare function hashRaw(password: string | Uint8Array, options?: Options | undefined | null, abortSignal?: AbortSignal | undefined | null): Promise<Buffer>
2525

26-
export declare function hashRawSync(password: string | Buffer, options?: Options | undefined | null): Buffer
26+
export declare function hashRawSync(password: string | Uint8Array, options?: Options | undefined | null): Buffer
2727

28-
export declare function hashSync(password: string | Buffer, options?: Options | undefined | null): string
28+
export declare function hashSync(password: string | Uint8Array, options?: Options | undefined | null): string
2929

3030
export interface Options {
3131
/**
@@ -60,15 +60,15 @@ export interface Options {
6060
parallelism?: number
6161
algorithm?: Algorithm
6262
version?: Version
63-
secret?: Buffer
64-
salt?: Buffer
63+
secret?: Uint8Array
64+
salt?: Uint8Array
6565
}
6666

67-
export declare function verify(hashed: string | Buffer, password: string | Buffer, options?: Options | undefined | null, abortSignal?: AbortSignal | undefined | null): Promise<boolean>
67+
export declare function verify(hashed: string | Uint8Array, password: string | Uint8Array, options?: Options | undefined | null, abortSignal?: AbortSignal | undefined | null): Promise<boolean>
6868

69-
export declare function verifySync(hashed: string | Buffer, password: string | Buffer, options?: Options | undefined | null): boolean
69+
export declare function verifySync(hashed: string | Uint8Array, password: string | Uint8Array, options?: Options | undefined | null): boolean
7070

71-
export const enum Version {
71+
export declare const enum Version {
7272
/** Version 16 (0x10 in hex) */
7373
V0x10 = 0,
7474
/**
@@ -77,4 +77,3 @@ export const enum Version {
7777
*/
7878
V0x13 = 1
7979
}
80-

packages/argon2/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -336,15 +336,15 @@ if (!nativeBinding || process.env.NAPI_RS_FORCE_WASI) {
336336
nativeBinding = require('./argon2.wasi.cjs')
337337
} catch (err) {
338338
if (process.env.NAPI_RS_FORCE_WASI) {
339-
console.error(err)
339+
loadErrors.push(err)
340340
}
341341
}
342342
if (!nativeBinding) {
343343
try {
344344
nativeBinding = require('@node-rs/argon2-wasm32-wasi')
345345
} catch (err) {
346346
if (process.env.NAPI_RS_FORCE_WASI) {
347-
console.error(err)
347+
loadErrors.push(err)
348348
}
349349
}
350350
}

packages/argon2/src/lib.rs

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ use argon2::{
1313
use rand_core::OsRng;
1414

1515
#[napi]
16+
#[derive(Clone, Copy)]
1617
pub enum Algorithm {
1718
/// Optimizes against GPU cracking attacks but vulnerable to side-channels.
1819
/// Accesses the memory array in a password dependent order, reducing the possibility of time–memory tradeoff (TMTO) attacks.
@@ -40,6 +41,7 @@ impl Algorithm {
4041
}
4142

4243
#[napi]
44+
#[derive(Clone, Copy)]
4345
pub enum Version {
4446
/// Version 16 (0x10 in hex)
4547
V0x10,
@@ -59,7 +61,7 @@ impl Version {
5961
}
6062
}
6163

62-
#[napi(object)]
64+
#[napi(object, object_to_js = false)]
6365
#[derive(Default)]
6466
pub struct Options {
6567
/// The amount of memory to be used by the hash function, in kilobytes. Each thread will have a memory pool of this size. Note that large values for highly concurrent usage will cause starvation and thrashing if your system memory gets full.
@@ -89,8 +91,8 @@ pub struct Options {
8991
pub parallelism: Option<u32>,
9092
pub algorithm: Option<Algorithm>,
9193
pub version: Option<Version>,
92-
pub secret: Option<Buffer>,
93-
pub salt: Option<Buffer>,
94+
pub secret: Option<Uint8Array>,
95+
pub salt: Option<Uint8Array>,
9496
}
9597

9698
impl Options {
@@ -140,7 +142,7 @@ impl Task for HashTask {
140142

141143
#[napi]
142144
pub fn hash(
143-
password: Either<String, Buffer>,
145+
password: Either<String, &[u8]>,
144146
options: Option<Options>,
145147
abort_signal: Option<AbortSignal>,
146148
) -> AsyncTask<HashTask> {
@@ -159,7 +161,7 @@ pub fn hash(
159161
#[napi]
160162
pub fn hash_sync(
161163
env: Env,
162-
password: Either<String, Buffer>,
164+
password: Either<String, &[u8]>,
163165
options: Option<Options>,
164166
) -> Result<String> {
165167
let mut hash_task = HashTask {
@@ -216,7 +218,7 @@ impl Task for RawHashTask {
216218

217219
#[napi]
218220
pub fn hash_raw(
219-
password: Either<String, Buffer>,
221+
password: Either<String, &[u8]>,
220222
options: Option<Options>,
221223
abort_signal: Option<AbortSignal>,
222224
) -> AsyncTask<RawHashTask> {
@@ -235,7 +237,7 @@ pub fn hash_raw(
235237
#[napi]
236238
pub fn hash_raw_sync(
237239
env: Env,
238-
password: Either<String, Buffer>,
240+
password: Either<String, &[u8]>,
239241
options: Option<Options>,
240242
) -> Result<Buffer> {
241243
let mut hash_task = RawHashTask {
@@ -279,8 +281,8 @@ impl Task for VerifyTask {
279281

280282
#[napi]
281283
pub fn verify(
282-
hashed: Either<String, Buffer>,
283-
password: Either<String, Buffer>,
284+
hashed: Either<String, &[u8]>,
285+
password: Either<String, &[u8]>,
284286
options: Option<Options>,
285287
abort_signal: Option<AbortSignal>,
286288
) -> Result<AsyncTask<VerifyTask>> {
@@ -305,8 +307,8 @@ pub fn verify(
305307
#[napi]
306308
pub fn verify_sync(
307309
env: Env,
308-
hashed: Either<String, Buffer>,
309-
password: Either<String, Buffer>,
310+
hashed: Either<String, &[u8]>,
311+
password: Either<String, &[u8]>,
310312
options: Option<Options>,
311313
) -> Result<bool> {
312314
let mut verify_task = VerifyTask {

packages/bcrypt/Cargo.toml

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,16 @@ version = "0.1.0"
88
crate-type = ["cdylib"]
99

1010
[dependencies]
11-
base64 = { version = "0.22" }
12-
bcrypt = "0.15"
13-
blowfish = { version = "0.9", features = ["bcrypt"] }
14-
getrandom = "0.2"
15-
global_alloc = { path = "../../crates/alloc" }
16-
napi = { version = "2", default-features = false, features = ["napi3"] }
17-
napi-derive = { version = "2" }
11+
base64 = { workspace = true }
12+
bcrypt = { workspace = true }
13+
blowfish = { workspace = true }
14+
getrandom = { workspace = true }
15+
global_alloc = { workspace = true }
16+
napi = { workspace = true, default-features = false, features = ["napi3"] }
17+
napi-derive = { workspace = true }
1818

1919
[dev-dependencies]
20-
quickcheck = "1.0"
20+
quickcheck = { workspace = true }
2121

2222
[build-dependencies]
23-
napi-build = "2"
23+
napi-build = { workspace = true }

packages/bcrypt/binding.d.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,10 @@ export declare function genSalt(round: number, version?: '2a' | '2x' | '2y' | '2
66

77
export declare function genSaltSync(round: number, version?: '2a' | '2x' | '2y' | '2b'): string
88

9-
export declare function hash(input: string | Buffer, cost?: number | undefined | null, salt?: string | Buffer | undefined | null, signal?: AbortSignal | undefined | null): Promise<string>
9+
export declare function hash(input: Uint8Array | string, cost?: number | undefined | null, salt?: string | Buffer | undefined | null, signal?: AbortSignal | undefined | null): Promise<string>
1010

1111
export declare function hashSync(input: string | Buffer, cost?: number | undefined | null, salt?: string | Buffer | undefined | null): string
1212

13-
export declare function verify(password: string | Buffer, hash: string | Buffer, signal?: AbortSignal | undefined | null): Promise<boolean>
13+
export declare function verify(password: Uint8Array | string, hash: Uint8Array | string, signal?: AbortSignal | undefined | null): Promise<boolean>
1414

1515
export declare function verifySync(input: string | Buffer, hash: string | Buffer): boolean
16-

packages/bcrypt/binding.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -336,15 +336,15 @@ if (!nativeBinding || process.env.NAPI_RS_FORCE_WASI) {
336336
nativeBinding = require('./bcrypt.wasi.cjs')
337337
} catch (err) {
338338
if (process.env.NAPI_RS_FORCE_WASI) {
339-
console.error(err)
339+
loadErrors.push(err)
340340
}
341341
}
342342
if (!nativeBinding) {
343343
try {
344344
nativeBinding = require('@node-rs/bcrypt-wasm32-wasi')
345345
} catch (err) {
346346
if (process.env.NAPI_RS_FORCE_WASI) {
347-
console.error(err)
347+
loadErrors.push(err)
348348
}
349349
}
350350
}

0 commit comments

Comments
 (0)