Skip to content

Commit a008c80

Browse files
committed
adding rust napi bindings
1 parent 1513275 commit a008c80

17 files changed

+98
-235
lines changed

Cargo.toml

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
[package]
2+
name = "cas-typescript-sdk-napi"
3+
version = "0.1.0"
4+
edition = "2021"
5+
6+
[lib]
7+
path = "src/lib.rs"
8+
crate-type = ["cdylib"]
9+
10+
[dependencies]
11+
argon2 = "0.5.2"
12+
napi = "2"
13+
napi-derive = "2"
14+
rand = "0.8.5"
15+
16+
[build-dependencies]
17+
napi-build = "1"

build.rs

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
extern crate napi_build;
2+
3+
fn main() {
4+
napi_build::setup();
5+
}

cas_core_lib.dll

-3.22 MB
Binary file not shown.

index.d.ts

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
/* tslint:disable */
2+
/* eslint-disable */
3+
4+
/* auto-generated by NAPI-RS */
5+
6+
export function argon2Hash(password: string): string
7+
export function argon2Verify(hashedPassword: string, passwordToVerify: string): boolean

index.node

305 KB
Binary file not shown.

libcas_core_lib.so

-8.17 MB
Binary file not shown.

package-lock.json

+17-189
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+2-3
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"types": "lib/index.d.ts",
77
"scripts": {
88
"test": "mocha -r ts-node/register ./test/**/*.ts --timeout 20000 --recursive",
9-
"build": "tsc && copyfiles \"./cas_core_lib.dll\" \"lib\" && copyfiles \"./libcas_core_lib.so\" \"lib\"",
9+
"build": "napi build --release && tsc",
1010
"prepare": "npm run build"
1111
},
1212
"repository": {
@@ -25,16 +25,15 @@
2525
"registry": "https://registry.npmjs.org/"
2626
},
2727
"devDependencies": {
28+
"@napi-rs/cli": "^2.17.0",
2829
"@types/chai": "^4.3.5",
2930
"@types/mocha": "^10.0.1",
3031
"@types/node-fetch": "^2.6.3",
3132
"chai": "^4.3.7",
32-
"copyfiles": "^2.4.1",
3333
"mocha": "^10.2.0",
3434
"ts-node": "^10.9.1",
3535
"typescript": "^5.0.3"
3636
},
3737
"dependencies": {
38-
"koffi": "^2.7.1"
3938
}
4039
}
File renamed without changes.
File renamed without changes.

src-ts/index.ts

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { Argon2Wrapper } from "./password-hashers/argon2-wrapper";
2+
3+
export {
4+
Argon2Wrapper
5+
}
+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import {argon2Hash, argon2Verify} from "./../../index";
2+
3+
export class Argon2Wrapper {
4+
public hashPassword(password: string): string {
5+
if (!password){
6+
throw new Error("You must provide a password to hash with Argon2");
7+
}
8+
return argon2Hash(password);
9+
}
10+
11+
public verifyPassword(hashedPassword: string, passwordToVerify: string): boolean {
12+
if (!hashedPassword || !passwordToVerify) {
13+
throw new Error("You must provide a hashed password and a plaintext password to verify with Argon2");
14+
}
15+
return argon2Verify(hashedPassword, passwordToVerify);
16+
}
17+
}

0 commit comments

Comments
 (0)