cas-typescript-sdk 1.0.47 → 1.0.49
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.d.ts +141 -0
- package/index.darwin-x64.node +0 -0
- package/index.js +631 -0
- package/index.linux-x64-gnu.node +0 -0
- package/index.linux-x64-musl.node +0 -0
- package/index.win32-x64-msvc.node +0 -0
- package/lib/asymmetric/index.d.ts +3 -0
- package/lib/asymmetric/index.js +5 -0
- package/lib/digital-signature/index.d.ts +6 -0
- package/lib/digital-signature/index.js +11 -0
- package/lib/hashers/index.d.ts +5 -0
- package/lib/hashers/index.js +11 -0
- package/lib/hybrid/index.d.ts +2 -0
- package/lib/hybrid/index.js +5 -0
- package/lib/index.d.ts +10 -0
- package/lib/key_exchange/index.d.ts +3 -0
- package/lib/key_exchange/index.js +5 -0
- package/lib/message/index.d.ts +2 -0
- package/lib/message/index.js +5 -0
- package/lib/password-hashers/index.d.ts +6 -0
- package/lib/password-hashers/index.js +13 -0
- package/lib/signature/index.d.ts +2 -0
- package/lib/signature/index.js +5 -0
- package/lib/sponges/index.d.ts +2 -0
- package/lib/sponges/index.js +5 -0
- package/lib/symmetric/index.d.ts +2 -0
- package/lib/symmetric/index.js +5 -0
- package/package.json +8 -1
- package/.github/workflows/main-pr-linux.yml +0 -28
- package/.github/workflows/main-pr-windows.yml +0 -28
- package/.github/workflows/main-publish.yml +0 -109
- package/Cargo.toml +0 -19
- package/build.rs +0 -5
- package/docs/EXAMPLES.md +0 -138
- package/src/asymmetric/cas_ed25519.rs +0 -35
- package/src/asymmetric/cas_rsa.rs +0 -32
- package/src/digital_signature/sha_256_rsa.rs +0 -40
- package/src/digital_signature/sha_512_rsa.rs +0 -40
- package/src/digital_signature/types.rs +0 -34
- package/src/hashers/blake2.rs +0 -60
- package/src/hashers/sha.rs +0 -68
- package/src/hybrid/hpke.rs +0 -63
- package/src/hybrid/types.rs +0 -15
- package/src/key_exchange/types.rs +0 -17
- package/src/key_exchange/x25519.rs +0 -25
- package/src/lib.rs +0 -47
- package/src/message/hmac.rs +0 -21
- package/src/password_hashers/argon2.rs +0 -37
- package/src/password_hashers/bcrypt.rs +0 -37
- package/src/password_hashers/scrypt.rs +0 -36
- package/src/sponges/ascon_aead.rs +0 -66
- package/src/symmetric/aes.rs +0 -71
- package/src-ts/asymmetric/RSAWrapper.ts +0 -59
- package/src-ts/digital-signature/digital-siganture-sha-512.ts +0 -40
- package/src-ts/digital-signature/digital-signature-base.ts +0 -6
- package/src-ts/digital-signature/digital-signature-factory.ts +0 -25
- package/src-ts/digital-signature/digital-signaturte-sha-256.ts +0 -41
- package/src-ts/hashers/blake2-wrapper.ts +0 -43
- package/src-ts/hashers/hasher-base.ts +0 -6
- package/src-ts/hashers/hasher-factory.ts +0 -19
- package/src-ts/hashers/hasher-type.ts +0 -4
- package/src-ts/hashers/sha-wrapper.ts +0 -60
- package/src-ts/hybrid/hpke.ts +0 -44
- package/src-ts/key_exchange/x25519.ts +0 -23
- package/src-ts/message/hmac.ts +0 -26
- package/src-ts/password-hashers/argon2-wrapper.ts +0 -31
- package/src-ts/password-hashers/bcrypt-wrapper.ts +0 -35
- package/src-ts/password-hashers/password-hasher-base.ts +0 -4
- package/src-ts/password-hashers/password-hasher-factory.ts +0 -25
- package/src-ts/password-hashers/password-hasher-type.ts +0 -5
- package/src-ts/password-hashers/scrypt-wrapper.ts +0 -32
- package/src-ts/signature/ed25519-wrapper.ts +0 -36
- package/src-ts/sponges/ascon-wrapper.ts +0 -72
- package/src-ts/symmetric/aes-wrapper.ts +0 -101
- package/test-ts/asymmetric.test.spec.ts +0 -15
- package/test-ts/digital-signature.test.spec.ts +0 -70
- package/test-ts/hasher.test.spec.ts +0 -139
- package/test-ts/helpers/array.ts +0 -10
- package/test-ts/hmac.test.spec.ts +0 -16
- package/test-ts/hybrid.test.spec.ts +0 -23
- package/test-ts/insecure-channel.test.spec.ts +0 -55
- package/test-ts/key-exchange.test.spec.ts +0 -23
- package/test-ts/password-hasher.test.spec.ts +0 -104
- package/test-ts/sponges.test.spec.ts +0 -28
- package/test-ts/symmetric.test.spec.ts +0 -82
- package/tsconfig.json +0 -22
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Blake2Wrapper = exports.HasherType = exports.HasherFactory = exports.SHAWrapper = void 0;
|
|
4
|
+
const hasher_factory_1 = require("./hasher-factory");
|
|
5
|
+
Object.defineProperty(exports, "HasherFactory", { enumerable: true, get: function () { return hasher_factory_1.HasherFactory; } });
|
|
6
|
+
const hasher_type_1 = require("./hasher-type");
|
|
7
|
+
Object.defineProperty(exports, "HasherType", { enumerable: true, get: function () { return hasher_type_1.HasherType; } });
|
|
8
|
+
const sha_wrapper_1 = require("./sha-wrapper");
|
|
9
|
+
Object.defineProperty(exports, "SHAWrapper", { enumerable: true, get: function () { return sha_wrapper_1.SHAWrapper; } });
|
|
10
|
+
const blake2_wrapper_1 = require("./blake2-wrapper");
|
|
11
|
+
Object.defineProperty(exports, "Blake2Wrapper", { enumerable: true, get: function () { return blake2_wrapper_1.Blake2Wrapper; } });
|
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export * from "./password-hashers/index";
|
|
2
|
+
export * from "./hashers/index";
|
|
3
|
+
export * from "./key_exchange/index";
|
|
4
|
+
export * from "./symmetric/index";
|
|
5
|
+
export * from "./asymmetric/index";
|
|
6
|
+
export * from "./digital-signature";
|
|
7
|
+
export * from "./sponges/index";
|
|
8
|
+
export * from "./message/index";
|
|
9
|
+
export * from "./signature/index";
|
|
10
|
+
export * from "./hybrid/index";
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.X25519Wrapper = void 0;
|
|
4
|
+
const x25519_1 = require("./x25519");
|
|
5
|
+
Object.defineProperty(exports, "X25519Wrapper", { enumerable: true, get: function () { return x25519_1.X25519Wrapper; } });
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { Argon2Wrapper } from "./argon2-wrapper";
|
|
2
|
+
import { BCryptWrapper } from "./bcrypt-wrapper";
|
|
3
|
+
import { ScryptWrapper } from "./scrypt-wrapper";
|
|
4
|
+
import { PasswordHasherType } from "./password-hasher-type";
|
|
5
|
+
import { PasswordHasherFactory } from "./password-hasher-factory";
|
|
6
|
+
export { Argon2Wrapper, BCryptWrapper, PasswordHasherFactory, PasswordHasherType, ScryptWrapper, };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ScryptWrapper = exports.PasswordHasherType = exports.PasswordHasherFactory = exports.BCryptWrapper = exports.Argon2Wrapper = void 0;
|
|
4
|
+
const argon2_wrapper_1 = require("./argon2-wrapper");
|
|
5
|
+
Object.defineProperty(exports, "Argon2Wrapper", { enumerable: true, get: function () { return argon2_wrapper_1.Argon2Wrapper; } });
|
|
6
|
+
const bcrypt_wrapper_1 = require("./bcrypt-wrapper");
|
|
7
|
+
Object.defineProperty(exports, "BCryptWrapper", { enumerable: true, get: function () { return bcrypt_wrapper_1.BCryptWrapper; } });
|
|
8
|
+
const scrypt_wrapper_1 = require("./scrypt-wrapper");
|
|
9
|
+
Object.defineProperty(exports, "ScryptWrapper", { enumerable: true, get: function () { return scrypt_wrapper_1.ScryptWrapper; } });
|
|
10
|
+
const password_hasher_type_1 = require("./password-hasher-type");
|
|
11
|
+
Object.defineProperty(exports, "PasswordHasherType", { enumerable: true, get: function () { return password_hasher_type_1.PasswordHasherType; } });
|
|
12
|
+
const password_hasher_factory_1 = require("./password-hasher-factory");
|
|
13
|
+
Object.defineProperty(exports, "PasswordHasherFactory", { enumerable: true, get: function () { return password_hasher_factory_1.PasswordHasherFactory; } });
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Ed25519Wrapper = void 0;
|
|
4
|
+
const ed25519_wrapper_1 = require("./ed25519-wrapper");
|
|
5
|
+
Object.defineProperty(exports, "Ed25519Wrapper", { enumerable: true, get: function () { return ed25519_wrapper_1.Ed25519Wrapper; } });
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AsconWrapper = void 0;
|
|
4
|
+
const ascon_wrapper_1 = require("./ascon-wrapper");
|
|
5
|
+
Object.defineProperty(exports, "AsconWrapper", { enumerable: true, get: function () { return ascon_wrapper_1.AsconWrapper; } });
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AESWrapper = void 0;
|
|
4
|
+
const aes_wrapper_1 = require("./aes-wrapper");
|
|
5
|
+
Object.defineProperty(exports, "AESWrapper", { enumerable: true, get: function () { return aes_wrapper_1.AESWrapper; } });
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cas-typescript-sdk",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.49",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "lib/index.d.ts",
|
|
@@ -23,6 +23,13 @@
|
|
|
23
23
|
"url": "https://github.com/Cryptographic-API-Services/cas-typescript-sdk/issues"
|
|
24
24
|
},
|
|
25
25
|
"homepage": "https://github.com/Cryptographic-API-Services/cas-typescript-sdk#readme",
|
|
26
|
+
"files": [
|
|
27
|
+
"lib",
|
|
28
|
+
"index.js",
|
|
29
|
+
"index.d.ts",
|
|
30
|
+
"*.node",
|
|
31
|
+
"README.md"
|
|
32
|
+
],
|
|
26
33
|
"publishConfig": {
|
|
27
34
|
"access": "public",
|
|
28
35
|
"registry": "https://registry.npmjs.org/"
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
# This workflow will do a clean installation of node dependencies, cache/restore them, build the source code and run tests across different versions of node
|
|
2
|
-
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-nodejs
|
|
3
|
-
|
|
4
|
-
name: Linux Build / Test
|
|
5
|
-
|
|
6
|
-
on:
|
|
7
|
-
pull_request:
|
|
8
|
-
branches: [ "main" ]
|
|
9
|
-
|
|
10
|
-
jobs:
|
|
11
|
-
build:
|
|
12
|
-
|
|
13
|
-
runs-on: ubuntu-latest
|
|
14
|
-
|
|
15
|
-
strategy:
|
|
16
|
-
matrix:
|
|
17
|
-
node-version: [24.x]
|
|
18
|
-
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/
|
|
19
|
-
|
|
20
|
-
steps:
|
|
21
|
-
- uses: actions/checkout@v3
|
|
22
|
-
- name: Use Node.js ${{ matrix.node-version }}
|
|
23
|
-
uses: actions/setup-node@v3
|
|
24
|
-
with:
|
|
25
|
-
node-version: ${{ matrix.node-version }}
|
|
26
|
-
cache: 'npm'
|
|
27
|
-
- run: npm ci
|
|
28
|
-
- run: npm test
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
# This workflow will do a clean installation of node dependencies, cache/restore them, build the source code and run tests across different versions of node
|
|
2
|
-
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-nodejs
|
|
3
|
-
|
|
4
|
-
name: Windows Build / Test
|
|
5
|
-
|
|
6
|
-
on:
|
|
7
|
-
pull_request:
|
|
8
|
-
branches: [ "main" ]
|
|
9
|
-
|
|
10
|
-
jobs:
|
|
11
|
-
build:
|
|
12
|
-
|
|
13
|
-
runs-on: windows-latest
|
|
14
|
-
|
|
15
|
-
strategy:
|
|
16
|
-
matrix:
|
|
17
|
-
node-version: [24.x]
|
|
18
|
-
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/
|
|
19
|
-
|
|
20
|
-
steps:
|
|
21
|
-
- uses: actions/checkout@v3
|
|
22
|
-
- name: Use Node.js ${{ matrix.node-version }}
|
|
23
|
-
uses: actions/setup-node@v3
|
|
24
|
-
with:
|
|
25
|
-
node-version: ${{ matrix.node-version }}
|
|
26
|
-
cache: 'npm'
|
|
27
|
-
- run: npm ci
|
|
28
|
-
- run: npm test
|
|
@@ -1,109 +0,0 @@
|
|
|
1
|
-
# Cross-platform build and publish workflow
|
|
2
|
-
|
|
3
|
-
name: Build and Publish
|
|
4
|
-
|
|
5
|
-
on:
|
|
6
|
-
push:
|
|
7
|
-
branches: [ "main" ]
|
|
8
|
-
|
|
9
|
-
jobs:
|
|
10
|
-
build-matrix:
|
|
11
|
-
runs-on: ${{ matrix.settings.host }}
|
|
12
|
-
strategy:
|
|
13
|
-
fail-fast: false
|
|
14
|
-
matrix:
|
|
15
|
-
settings:
|
|
16
|
-
# Linux builds (on Ubuntu)
|
|
17
|
-
- host: ubuntu-latest
|
|
18
|
-
target: x86_64-unknown-linux-gnu
|
|
19
|
-
docker: ghcr.io/napi-rs/napi-rs/nodejs-rust:lts-debian-zig
|
|
20
|
-
- host: ubuntu-latest
|
|
21
|
-
target: x86_64-unknown-linux-musl
|
|
22
|
-
docker: ghcr.io/napi-rs/napi-rs/nodejs-rust:lts-alpine-zig
|
|
23
|
-
# Windows builds (on Windows)
|
|
24
|
-
- host: windows-latest
|
|
25
|
-
target: x86_64-pc-windows-msvc
|
|
26
|
-
# macOS builds (on macOS)
|
|
27
|
-
- host: macos-latest
|
|
28
|
-
target: x86_64-apple-darwin
|
|
29
|
-
|
|
30
|
-
name: Build ${{ matrix.settings.target }}
|
|
31
|
-
steps:
|
|
32
|
-
- uses: actions/checkout@v4
|
|
33
|
-
|
|
34
|
-
- name: Setup node
|
|
35
|
-
uses: actions/setup-node@v4
|
|
36
|
-
with:
|
|
37
|
-
node-version: 24
|
|
38
|
-
cache: npm
|
|
39
|
-
|
|
40
|
-
- name: Install dependencies
|
|
41
|
-
run: npm ci
|
|
42
|
-
|
|
43
|
-
- name: Setup Rust
|
|
44
|
-
if: ${{ !matrix.settings.docker }}
|
|
45
|
-
uses: dtolnay/rust-toolchain@stable
|
|
46
|
-
with:
|
|
47
|
-
toolchain: stable
|
|
48
|
-
targets: ${{ matrix.settings.target }}
|
|
49
|
-
components: rustfmt, clippy
|
|
50
|
-
|
|
51
|
-
- name: Build in Docker
|
|
52
|
-
if: ${{ matrix.settings.docker }}
|
|
53
|
-
run: |
|
|
54
|
-
docker run --rm -v "$(pwd)":/build -w /build ${{ matrix.settings.docker }} sh -c "
|
|
55
|
-
rustup toolchain install nightly &&
|
|
56
|
-
rustup default nightly &&
|
|
57
|
-
npm ci &&
|
|
58
|
-
cargo update &&
|
|
59
|
-
npm run build:ts &&
|
|
60
|
-
npx napi build --platform --release --target ${{ matrix.settings.target }}
|
|
61
|
-
"
|
|
62
|
-
|
|
63
|
-
- name: Build native
|
|
64
|
-
if: ${{ !matrix.settings.docker }}
|
|
65
|
-
run: |
|
|
66
|
-
cargo update
|
|
67
|
-
npm run build:ts
|
|
68
|
-
npx napi build --platform --release --target ${{ matrix.settings.target }}
|
|
69
|
-
|
|
70
|
-
- name: Upload artifact
|
|
71
|
-
uses: actions/upload-artifact@v4
|
|
72
|
-
with:
|
|
73
|
-
name: bindings-${{ matrix.settings.target }}
|
|
74
|
-
path: "*.node"
|
|
75
|
-
if-no-files-found: error
|
|
76
|
-
|
|
77
|
-
publish:
|
|
78
|
-
name: Publish
|
|
79
|
-
runs-on: ubuntu-latest
|
|
80
|
-
needs: [build-matrix]
|
|
81
|
-
|
|
82
|
-
steps:
|
|
83
|
-
- uses: actions/checkout@v4
|
|
84
|
-
|
|
85
|
-
- name: Setup node
|
|
86
|
-
uses: actions/setup-node@v4
|
|
87
|
-
with:
|
|
88
|
-
node-version: 24
|
|
89
|
-
registry-url: 'https://registry.npmjs.org'
|
|
90
|
-
cache: npm
|
|
91
|
-
|
|
92
|
-
- name: Install dependencies
|
|
93
|
-
run: npm ci
|
|
94
|
-
|
|
95
|
-
- name: Build TypeScript
|
|
96
|
-
run: npm run build:ts
|
|
97
|
-
|
|
98
|
-
- name: Download all artifacts
|
|
99
|
-
uses: actions/download-artifact@v4
|
|
100
|
-
with:
|
|
101
|
-
merge-multiple: true
|
|
102
|
-
|
|
103
|
-
- name: List binaries
|
|
104
|
-
run: ls -la *.node
|
|
105
|
-
|
|
106
|
-
- name: Publish to npm
|
|
107
|
-
run: npm publish --access public
|
|
108
|
-
env:
|
|
109
|
-
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
|
package/Cargo.toml
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
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
|
-
napi = "3"
|
|
12
|
-
napi-derive = "3"
|
|
13
|
-
csbindgen = "1.9.3"
|
|
14
|
-
cas-lib = { version = "=0.2.65" }
|
|
15
|
-
zeroize = "1.8.1"
|
|
16
|
-
zeroizing-alloc = "0.1.0"
|
|
17
|
-
|
|
18
|
-
[build-dependencies]
|
|
19
|
-
napi-build = "1"
|
package/build.rs
DELETED
package/docs/EXAMPLES.md
DELETED
|
@@ -1,138 +0,0 @@
|
|
|
1
|
-
### Symmetric
|
|
2
|
-
- AES 256
|
|
3
|
-
```typescript
|
|
4
|
-
const aesWrapper: AESWrapper = new AESWrapper();
|
|
5
|
-
const aesKey = aesWrapper.aes128Key();
|
|
6
|
-
const aesNonce = aesWrapper.aesNonce();
|
|
7
|
-
const toEncrypt: string = "This is my array to encrypt";
|
|
8
|
-
const encoder = new TextEncoder();
|
|
9
|
-
const tohashBytes: Array<number> = Array.from(encoder.encode(toEncrypt));
|
|
10
|
-
const ciphertext = aesWrapper.aes128Encrypt(aesKey, aesNonce, tohashBytes);
|
|
11
|
-
const plaintxt = aesWrapper.aes128Decrypt(aesKey, aesNonce, ciphertext);
|
|
12
|
-
```
|
|
13
|
-
|
|
14
|
-
### Asymmetric
|
|
15
|
-
-RSA
|
|
16
|
-
```typescript
|
|
17
|
-
const rsaWrapper: RSAWrapper = new RSAWrapper();
|
|
18
|
-
const keys: RsaKeyPairResult = rsaWrapper.generateKeys(4096);
|
|
19
|
-
const tohashed: string = "This is my array to encrypt";
|
|
20
|
-
const encoder = new TextEncoder();
|
|
21
|
-
const tohashBytes: Array<number> = Array.from(encoder.encode(tohashed));
|
|
22
|
-
const ciphertext = rsaWrapper.encrypt(keys.publicKey, tohashBytes);
|
|
23
|
-
const plaintext = rsaWrapper.decrypt(keys.privateKey, ciphertext);
|
|
24
|
-
```
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
### Digital Signature
|
|
28
|
-
-ED25519 SHA
|
|
29
|
-
```typescript
|
|
30
|
-
const shaDsWrapper = DigitalSignatureFactory.get(DigitalSignatureType.SHA256)
|
|
31
|
-
const toHash: string = "This is my array to encrypt";
|
|
32
|
-
const encoder = new TextEncoder();
|
|
33
|
-
const toHashBytes: Array<number> = Array.from(encoder.encode(toHash));
|
|
34
|
-
const dsResult = shaDsWrapper.createED25519(toHashBytes);
|
|
35
|
-
const verify = shaDsWrapper.verifyED25519(dsResult.publicKey, toHashBytes, dsResult.signature);
|
|
36
|
-
```
|
|
37
|
-
|
|
38
|
-
-RSA SHA
|
|
39
|
-
```typescript
|
|
40
|
-
const shaDsWrapper = DigitalSignatureFactory.get(DigitalSignatureType.SHA512)
|
|
41
|
-
const tohashed: string = "This is my array to encrypt";
|
|
42
|
-
const notOriginal: string = "This is not a fun time";
|
|
43
|
-
const encoder = new TextEncoder();
|
|
44
|
-
const tohashBytes: Array<number> = Array.from(encoder.encode(tohashed));
|
|
45
|
-
const badBytes: Array<number> = Array.from(encoder.encode(notOriginal));
|
|
46
|
-
const dsResult: RSADigitalSignatureResult = shaDsWrapper.createRsa(4096, tohashBytes);
|
|
47
|
-
const verify = shaDsWrapper.verifyRSa(dsResult.publicKey, badBytes, dsResult.signature);
|
|
48
|
-
```
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
### Hashers
|
|
52
|
-
-SHA3 512
|
|
53
|
-
```typescript
|
|
54
|
-
const wrapper = new SHAWrapper();
|
|
55
|
-
const tohashed: string = "This is my array to hash";
|
|
56
|
-
const encoder = new TextEncoder();
|
|
57
|
-
const tohashBytes: Array<number> = Array.from(encoder.encode(tohashed));
|
|
58
|
-
const hashed = wrapper.hash512(tohashBytes);
|
|
59
|
-
```
|
|
60
|
-
|
|
61
|
-
-SHA3 256
|
|
62
|
-
```typescript
|
|
63
|
-
const wrapper = new SHAWrapper();
|
|
64
|
-
const tohashed: string = "This is my array to hash";
|
|
65
|
-
const encoder = new TextEncoder();
|
|
66
|
-
const tohashBytes: Array<number> = Array.from(encoder.encode(tohashed));
|
|
67
|
-
const hashed = wrapper.hash256(tohashBytes);
|
|
68
|
-
```
|
|
69
|
-
|
|
70
|
-
### Hybrid Encryption
|
|
71
|
-
-AES/RSA Encryption
|
|
72
|
-
```typescript
|
|
73
|
-
const hybridWrapper = new HybridEncryptionWrapper();
|
|
74
|
-
let initalizer = new AESRSAHybridInitializer(128, 4096);
|
|
75
|
-
const tohashed: string = "This is my encrypt text for rsa hybrid";
|
|
76
|
-
const encoder = new TextEncoder();
|
|
77
|
-
const toEncrypt: Array<number> = Array.from(encoder.encode(tohashed));
|
|
78
|
-
let result: AesRsaHybridEncryptResult = hybridWrapper.encrypt(toEncrypt, initalizer);
|
|
79
|
-
let plaintext: Array<number> = hybridWrapper.decrypt(initalizer.rsaKeyPair.privateKey, result);
|
|
80
|
-
```
|
|
81
|
-
|
|
82
|
-
### Key Exchange
|
|
83
|
-
-X25519
|
|
84
|
-
```typescript
|
|
85
|
-
const wrapper = new X25519Wrapper();
|
|
86
|
-
const alice = wrapper.generateSecretAndPublicKey();
|
|
87
|
-
const bob = wrapper.generateSecretAndPublicKey();
|
|
88
|
-
|
|
89
|
-
const alice_shared_secret = wrapper.generateSharedSecret(
|
|
90
|
-
alice.secretKey,
|
|
91
|
-
bob.publicKey,
|
|
92
|
-
);
|
|
93
|
-
const bob_shared_secret = wrapper.generateSharedSecret(
|
|
94
|
-
bob.secretKey,
|
|
95
|
-
alice.publicKey,
|
|
96
|
-
);
|
|
97
|
-
|
|
98
|
-
var result = areEqual(alice_shared_secret, bob_shared_secret);
|
|
99
|
-
```
|
|
100
|
-
|
|
101
|
-
### Sponges
|
|
102
|
-
-Ascon 128
|
|
103
|
-
```typescript
|
|
104
|
-
const wrapper: AsconWrapper = new AsconWrapper();
|
|
105
|
-
const key: Array<number> = wrapper.ascon128Key();
|
|
106
|
-
const nonce: Array<number> = wrapper.ascon128Nonce();
|
|
107
|
-
const tohashed: string = "This is my array to encrypt";
|
|
108
|
-
const encoder = new TextEncoder();
|
|
109
|
-
const tohashBytes: Array<number> = Array.from(encoder.encode(tohashed));
|
|
110
|
-
const ciphertext = wrapper.ascon128Encrypt(key, nonce, tohashBytes);
|
|
111
|
-
const plaintext = wrapper.ascon128Decrypt(key, nonce, ciphertext);
|
|
112
|
-
```
|
|
113
|
-
|
|
114
|
-
### Passwords
|
|
115
|
-
- BCrypt
|
|
116
|
-
```typescript
|
|
117
|
-
const hasher: BCryptWrapper = new BCryptWrapper();
|
|
118
|
-
const password: string = "ThisOneBadPassword!@";
|
|
119
|
-
const hashedPassword: string = hasher.hashPassword(password);
|
|
120
|
-
```
|
|
121
|
-
|
|
122
|
-
- SCrypt
|
|
123
|
-
```typescript
|
|
124
|
-
const hasher: ScryptWrapper = PasswordHasherFactory.getHasher(
|
|
125
|
-
PasswordHasherType.Scrypt,
|
|
126
|
-
);
|
|
127
|
-
const password: string = "ScryptRocks";
|
|
128
|
-
const hashed: string = hasher.hashPassword(password);
|
|
129
|
-
```
|
|
130
|
-
|
|
131
|
-
- Argon2
|
|
132
|
-
```typescript
|
|
133
|
-
const hasher: ScryptWrapper = PasswordHasherFactory.getHasher(
|
|
134
|
-
PasswordHasherType.Argon2,
|
|
135
|
-
);
|
|
136
|
-
const password: string = "ScryptRocks";
|
|
137
|
-
const hashed: string = hasher.hashPassword(password);
|
|
138
|
-
```
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
use cas_lib::signatures::cas_ed25519::{Ed25519ByteKeyPair, Ed25519ByteSignature};
|
|
3
|
-
use cas_lib::signatures::ed25519::{get_ed25519_key_pair, ed25519_sign_with_key_pair, ed25519_verify_with_public_key};
|
|
4
|
-
use napi_derive::napi;
|
|
5
|
-
|
|
6
|
-
#[napi(constructor)]
|
|
7
|
-
pub struct CASED25519KeyPairResult {
|
|
8
|
-
pub private_key: Vec<u8>,
|
|
9
|
-
pub public_key: Vec<u8>,
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
impl From<Ed25519ByteKeyPair> for CASED25519KeyPairResult {
|
|
13
|
-
fn from(result: Ed25519ByteKeyPair) -> Self {
|
|
14
|
-
CASED25519KeyPairResult {
|
|
15
|
-
private_key: result.key_pair,
|
|
16
|
-
public_key: result.public_key
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
#[napi]
|
|
22
|
-
pub fn generate_ed25519_keys() -> CASED25519KeyPairResult {
|
|
23
|
-
return get_ed25519_key_pair().into();
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
#[napi]
|
|
27
|
-
pub fn sign_ed25519(private_key: Vec<u8>, message: Vec<u8>) -> Vec<u8> {
|
|
28
|
-
let signature = ed25519_sign_with_key_pair(private_key, message);
|
|
29
|
-
signature.signature // assuming Ed25519ByteSignature has a field named `signature: Vec<u8>`
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
#[napi]
|
|
33
|
-
pub fn verify_ed25519(public_key: Vec<u8>, message: Vec<u8>, signature: Vec<u8>) -> bool {
|
|
34
|
-
return ed25519_verify_with_public_key(public_key, signature, message);
|
|
35
|
-
}
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
use cas_lib::asymmetric::{cas_rsa::CASRSA, types::{CASRSAEncryption, RSAKeyPairResult}};
|
|
2
|
-
use napi_derive::napi;
|
|
3
|
-
|
|
4
|
-
#[napi(constructor)]
|
|
5
|
-
pub struct CASRSAKeyPairResult {
|
|
6
|
-
pub private_key: String,
|
|
7
|
-
pub public_key: String,
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
impl From<RSAKeyPairResult> for CASRSAKeyPairResult {
|
|
11
|
-
fn from(result: RSAKeyPairResult) -> Self {
|
|
12
|
-
CASRSAKeyPairResult {
|
|
13
|
-
private_key: result.private_key,
|
|
14
|
-
public_key: result.public_key,
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
#[napi]
|
|
20
|
-
pub fn generate_rsa_keys(key_size: u32) -> CASRSAKeyPairResult {
|
|
21
|
-
return CASRSA::generate_rsa_keys(key_size as usize).into();
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
#[napi]
|
|
25
|
-
pub fn sign_rsa(private_key: String, hash: Vec<u8>) -> Vec<u8> {
|
|
26
|
-
return CASRSA::sign(private_key, hash);
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
#[napi]
|
|
30
|
-
pub fn verify_rsa(public_key: String, hash: Vec<u8>, signature: Vec<u8>) -> bool {
|
|
31
|
-
return CASRSA::verify(public_key, hash, signature);
|
|
32
|
-
}
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
use cas_lib::digital_signature::{cas_digital_signature_rsa::RSADigitalSignature, sha_256_rsa::SHA256RSADigitalSignature};
|
|
2
|
-
use napi_derive::napi;
|
|
3
|
-
|
|
4
|
-
use super::types::CASRSADigitalSignatureResult;
|
|
5
|
-
|
|
6
|
-
#[napi]
|
|
7
|
-
pub fn sha_256_rsa_digital_signature(
|
|
8
|
-
rsa_key_size: u32,
|
|
9
|
-
data_to_sign: Vec<u8>,
|
|
10
|
-
) -> CASRSADigitalSignatureResult {
|
|
11
|
-
return <SHA256RSADigitalSignature as RSADigitalSignature>::digital_signature_rsa(rsa_key_size, data_to_sign).into();
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
#[napi]
|
|
15
|
-
pub fn sha_256_rsa_verify_digital_signature(
|
|
16
|
-
public_key: String,
|
|
17
|
-
data_to_verify: Vec<u8>,
|
|
18
|
-
signature: Vec<u8>,
|
|
19
|
-
) -> bool {
|
|
20
|
-
return <SHA256RSADigitalSignature as RSADigitalSignature>::verify_rsa(public_key, data_to_verify, signature);
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
#[test]
|
|
24
|
-
fn sha_256_rsa_digital_signature_test() {
|
|
25
|
-
let key_size: u32 = 1024;
|
|
26
|
-
let data_to_sign = b"GetTheseBytes".to_vec();
|
|
27
|
-
let signature_result: CASRSADigitalSignatureResult = <SHA256RSADigitalSignature as RSADigitalSignature>::digital_signature_rsa(key_size, data_to_sign.clone()).into();
|
|
28
|
-
let is_verified: bool = SHA256RSADigitalSignature::verify_rsa(signature_result.public_key, data_to_sign, signature_result.signature);
|
|
29
|
-
assert_eq!(is_verified, true);
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
#[test]
|
|
33
|
-
fn sha_256_rsa_digital_signature_fail_test() {
|
|
34
|
-
let key_size: u32 = 1024;
|
|
35
|
-
let data_to_sign = b"GetTheseBytes".to_vec();
|
|
36
|
-
let signature_result: CASRSADigitalSignatureResult = <SHA256RSADigitalSignature as RSADigitalSignature>::digital_signature_rsa(key_size, data_to_sign.clone()).into();
|
|
37
|
-
let new_data = b"NOtTheOriginalData".to_vec();
|
|
38
|
-
let is_verified: bool = SHA256RSADigitalSignature::verify_rsa(signature_result.public_key, new_data, signature_result.signature);
|
|
39
|
-
assert_eq!(is_verified, false);
|
|
40
|
-
}
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
use cas_lib::digital_signature::{cas_digital_signature_rsa::RSADigitalSignature, sha_512_rsa::SHA512RSADigitalSignature};
|
|
2
|
-
use napi_derive::napi;
|
|
3
|
-
|
|
4
|
-
use super::types::CASRSADigitalSignatureResult;
|
|
5
|
-
|
|
6
|
-
#[napi]
|
|
7
|
-
pub fn sha_512_rsa_digital_signature(
|
|
8
|
-
rsa_key_size: u32,
|
|
9
|
-
data_to_sign: Vec<u8>,
|
|
10
|
-
) -> CASRSADigitalSignatureResult {
|
|
11
|
-
return <SHA512RSADigitalSignature as RSADigitalSignature>::digital_signature_rsa(rsa_key_size, data_to_sign).into();
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
#[napi]
|
|
15
|
-
pub fn sha_512_rsa_verify_digital_signature(
|
|
16
|
-
public_key: String,
|
|
17
|
-
data_to_verify: Vec<u8>,
|
|
18
|
-
signature: Vec<u8>,
|
|
19
|
-
) -> bool {
|
|
20
|
-
return <SHA512RSADigitalSignature as RSADigitalSignature>::verify_rsa(public_key, data_to_verify, signature);
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
#[test]
|
|
24
|
-
fn sha_512_rsa_digital_signature_test() {
|
|
25
|
-
let key_size: u32 = 1024;
|
|
26
|
-
let data_to_sign = b"GetTheseBytes".to_vec();
|
|
27
|
-
let signature_result: CASRSADigitalSignatureResult = SHA512RSADigitalSignature::digital_signature_rsa(key_size, data_to_sign.clone()).into();
|
|
28
|
-
let is_verified: bool = <SHA512RSADigitalSignature as RSADigitalSignature>::verify_rsa(signature_result.public_key, data_to_sign, signature_result.signature);
|
|
29
|
-
assert_eq!(is_verified, true);
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
#[test]
|
|
33
|
-
fn sha_512_rsa_digital_signature_fail_test() {
|
|
34
|
-
let key_size: u32 = 1024;
|
|
35
|
-
let data_to_sign = b"GetTheseBytes".to_vec();
|
|
36
|
-
let signature_result: CASRSADigitalSignatureResult = SHA512RSADigitalSignature::digital_signature_rsa(key_size, data_to_sign.clone()).into();
|
|
37
|
-
let new_data = b"NOtTheOriginalData".to_vec();
|
|
38
|
-
let is_verified: bool = <SHA512RSADigitalSignature as RSADigitalSignature>::verify_rsa(signature_result.public_key, new_data, signature_result.signature);
|
|
39
|
-
assert_eq!(is_verified, false);
|
|
40
|
-
}
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
use cas_lib::digital_signature::cas_digital_signature_rsa::{RSADigitalSignatureResult, SHAED25519DalekDigitalSignatureResult};
|
|
2
|
-
use napi_derive::napi;
|
|
3
|
-
|
|
4
|
-
#[napi(constructor)]
|
|
5
|
-
pub struct CASSHAED25519DalekDigitalSignatureResult {
|
|
6
|
-
pub public_key: Vec<u8>,
|
|
7
|
-
pub signature: Vec<u8>
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
impl From<SHAED25519DalekDigitalSignatureResult> for CASSHAED25519DalekDigitalSignatureResult {
|
|
11
|
-
fn from(value: SHAED25519DalekDigitalSignatureResult) -> Self {
|
|
12
|
-
CASSHAED25519DalekDigitalSignatureResult {
|
|
13
|
-
public_key: value.public_key.to_vec(),
|
|
14
|
-
signature: value.signature.to_vec()
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
#[napi(constructor)]
|
|
20
|
-
pub struct CASRSADigitalSignatureResult {
|
|
21
|
-
pub public_key: String,
|
|
22
|
-
pub private_key: String,
|
|
23
|
-
pub signature: Vec<u8>,
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
impl From<RSADigitalSignatureResult> for CASRSADigitalSignatureResult {
|
|
27
|
-
fn from(value: RSADigitalSignatureResult) -> Self {
|
|
28
|
-
CASRSADigitalSignatureResult {
|
|
29
|
-
public_key: value.public_key,
|
|
30
|
-
private_key: value.private_key,
|
|
31
|
-
signature: value.signature
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
}
|