cas-typescript-sdk 1.0.15 → 1.0.17
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/.github/workflows/main-pr-linux.yml +28 -0
- package/.github/workflows/main-pr-windows.yml +28 -0
- package/.github/workflows/main-publish.yml +32 -0
- package/Cargo.toml +8 -1
- package/README.md +5 -1
- package/build.rs +5 -5
- package/docs/EXAMPLES.md +39 -0
- package/index.d.ts +21 -0
- package/index.node +0 -0
- package/lib/digital-signature/digital-siganture-sha-512.d.ts +8 -0
- package/lib/digital-signature/digital-siganture-sha-512.js +46 -0
- package/lib/digital-signature/digital-signature-base.d.ts +7 -0
- package/lib/digital-signature/digital-signature-base.js +2 -0
- package/lib/digital-signature/digital-signature-factory.d.ts +8 -0
- package/lib/digital-signature/digital-signature-factory.js +22 -0
- package/lib/digital-signature/digital-signaturte-sha-256.d.ts +8 -0
- package/lib/digital-signature/digital-signaturte-sha-256.js +46 -0
- package/lib/digital-signature/index.d.ts +5 -0
- package/lib/digital-signature/index.js +11 -0
- package/lib/index.d.ts +2 -1
- package/lib/index.js +6 -1
- package/package.json +41 -41
- package/src/asymmetric/cas_asymmetric_encryption.rs +15 -15
- package/src/asymmetric/cas_rsa.rs +88 -80
- package/src/digital_signature/cas_digital_signature_rsa.rs +27 -0
- package/src/digital_signature/sha_256_ed25519.rs +69 -0
- package/src/digital_signature/sha_256_rsa.rs +96 -0
- package/src/digital_signature/sha_512_ed25519.rs +75 -0
- package/src/digital_signature/sha_512_rsa.rs +93 -0
- package/src/hashers/blake2.rs +37 -39
- package/src/hashers/cas_hasher.rs +8 -8
- package/src/hashers/sha.rs +102 -103
- package/src/key_exchange/cas_key_exchange.rs +6 -6
- package/src/key_exchange/x25519.rs +57 -57
- package/src/lib.rs +35 -27
- package/src/password_hashers/argon2.rs +65 -64
- package/src/password_hashers/bcrypt.rs +50 -51
- package/src/password_hashers/cas_password_hasher.rs +4 -4
- package/src/password_hashers/scrypt.rs +61 -56
- package/src/symmetric/aes.rs +155 -151
- package/src/symmetric/cas_symmetric_encryption.rs +14 -14
- package/src-ts/asymmetric/RSAWrapper.ts +53 -53
- package/src-ts/asymmetric/index.ts +3 -3
- package/src-ts/digital-signature/digital-siganture-sha-512.ts +48 -0
- package/src-ts/digital-signature/digital-signature-base.ts +8 -0
- package/src-ts/digital-signature/digital-signature-factory.ts +19 -0
- package/src-ts/digital-signature/digital-signaturte-sha-256.ts +48 -0
- package/src-ts/digital-signature/index.ts +11 -0
- package/src-ts/hashers/hasher-base.ts +5 -5
- package/src-ts/hashers/hasher-factory.ts +11 -11
- package/src-ts/hashers/hasher-type.ts +2 -2
- package/src-ts/hashers/index.ts +5 -5
- package/src-ts/hashers/sha-wrapper.ts +37 -37
- package/src-ts/helpers/nonce-generator.ts +8 -8
- package/src-ts/hybrid/hybrid-encryption-wrapper.ts +64 -64
- package/src-ts/hybrid/index.ts +9 -9
- package/src-ts/hybrid/types/aes-rsa-hybird-encrypt-result.ts +12 -12
- package/src-ts/hybrid/types/aes-rsa-hybrid-initializer.ts +23 -23
- package/src-ts/index.ts +44 -34
- package/src-ts/key_exchange/index.ts +3 -3
- package/src-ts/key_exchange/x25519.ts +10 -10
- package/src-ts/password-hashers/argon2-wrapper.ts +18 -18
- package/src-ts/password-hashers/bcrypt-wrapper.ts +23 -23
- package/src-ts/password-hashers/index.ts +14 -14
- package/src-ts/password-hashers/password-hasher-base.ts +3 -3
- package/src-ts/password-hashers/password-hasher-factory.ts +20 -20
- package/src-ts/password-hashers/password-hasher-type.ts +4 -4
- package/src-ts/password-hashers/scrypt-wrapper.ts +19 -19
- package/src-ts/symmetric/aes-wrapper.ts +50 -50
- package/src-ts/symmetric/index.ts +3 -3
- package/test-ts/asymmetric.test.spec.ts +27 -27
- package/test-ts/digital-signature.test.spec.ts +93 -0
- package/test-ts/hasher.test.spec.ts +70 -70
- package/test-ts/helpers/array.ts +9 -9
- package/test-ts/hybrid.test.spec.ts +33 -33
- package/test-ts/insecure-channel.test.spec.ts +50 -50
- package/test-ts/key-exchange-test.spec.ts +23 -23
- package/test-ts/password-hasher-test.spec.ts +102 -102
- package/test-ts/symmetric.test.spec.ts +31 -31
- package/tsconfig.json +21 -21
- package/build-node.sh +0 -2
- package/src-ts/global.d.ts +0 -2
|
@@ -0,0 +1,28 @@
|
|
|
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: [20.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
|
|
@@ -0,0 +1,28 @@
|
|
|
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: [20.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
|
|
@@ -0,0 +1,32 @@
|
|
|
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: Node.js CI
|
|
5
|
+
|
|
6
|
+
on:
|
|
7
|
+
push:
|
|
8
|
+
branches: [ "main" ]
|
|
9
|
+
|
|
10
|
+
jobs:
|
|
11
|
+
build:
|
|
12
|
+
|
|
13
|
+
runs-on: ubuntu-latest
|
|
14
|
+
|
|
15
|
+
strategy:
|
|
16
|
+
matrix:
|
|
17
|
+
node-version: [20.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
|
+
registry-url: 'https://registry.npmjs.org'
|
|
27
|
+
cache: 'npm'
|
|
28
|
+
- run: npm ci
|
|
29
|
+
- run: npm test
|
|
30
|
+
- run: npm publish
|
|
31
|
+
env:
|
|
32
|
+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
|
package/Cargo.toml
CHANGED
|
@@ -19,7 +19,14 @@ rand_chacha = "0.3.1"
|
|
|
19
19
|
rsa = "0.9.6"
|
|
20
20
|
scrypt = "0.11.0"
|
|
21
21
|
sha3 = "0.10.8"
|
|
22
|
-
x25519-dalek = {version = "2.0.0", features = ["static_secrets"]
|
|
22
|
+
x25519-dalek = {version = "2.0.0", features = ["static_secrets"]}
|
|
23
|
+
rand_07 = { package = "rand", version = "0.7.0" }
|
|
24
|
+
|
|
25
|
+
[profile.dev.package.num-bigint-dig]
|
|
26
|
+
opt-level = 3
|
|
27
|
+
|
|
28
|
+
[dependencies.ed25519-dalek]
|
|
29
|
+
version = "1"
|
|
23
30
|
|
|
24
31
|
[build-dependencies]
|
|
25
32
|
napi-build = "1"
|
package/README.md
CHANGED
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
# cas-typescript-sdk
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
[](https://discord.gg/7bXXCQj45q)
|
|
4
|
+
|
|
5
|
+
Ever wanted all of your most useful cryptographic operations in one module and not have to surf documentation for various packages?
|
|
4
6
|
CAS is here to provide a unified development experience as an abstract layer to the RustCrypto and Dalek-Cryptography suite of algorithms.
|
|
5
7
|
The official NPM page can be found [here](https://www.npmjs.com/package/cas-typescript-sdk).
|
|
6
8
|
|
|
9
|
+
## [Examples](./docs/EXAMPLES.md)
|
|
10
|
+
|
|
7
11
|
## Consuming Library Documentation
|
|
8
12
|
**Note: All work is experimental and we understand some benchmarks might not be the most optimal.**
|
|
9
13
|
|
package/build.rs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
extern crate napi_build;
|
|
2
|
-
|
|
3
|
-
fn main() {
|
|
4
|
-
|
|
5
|
-
}
|
|
1
|
+
extern crate napi_build;
|
|
2
|
+
|
|
3
|
+
fn main() {
|
|
4
|
+
napi_build::setup();
|
|
5
|
+
}
|
package/docs/EXAMPLES.md
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
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
|
+
|
|
15
|
+
### Passwords
|
|
16
|
+
- BCrypt
|
|
17
|
+
```typescript
|
|
18
|
+
const hasher: BCryptWrapper = new BCryptWrapper();
|
|
19
|
+
const password: string = "ThisOneBadPassword!@";
|
|
20
|
+
const hashedPassword: string = hasher.hashPassword(password);
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
- SCrypt
|
|
24
|
+
```typescript
|
|
25
|
+
const hasher: ScryptWrapper = PasswordHasherFactory.getHasher(
|
|
26
|
+
PasswordHasherType.Scrypt,
|
|
27
|
+
);
|
|
28
|
+
const password: string = "ScryptRocks";
|
|
29
|
+
const hashed: string = hasher.hashPassword(password);
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
- Argon2
|
|
33
|
+
```typescript
|
|
34
|
+
const hasher: ScryptWrapper = PasswordHasherFactory.getHasher(
|
|
35
|
+
PasswordHasherType.Argon2,
|
|
36
|
+
);
|
|
37
|
+
const password: string = "ScryptRocks";
|
|
38
|
+
const hashed: string = hasher.hashPassword(password);
|
|
39
|
+
```
|
package/index.d.ts
CHANGED
|
@@ -29,6 +29,14 @@ export function encryptPlaintextRsa(publicKey: string, plaintext: Array<number>)
|
|
|
29
29
|
export function decryptCiphertextRsa(privateKey: string, ciphertext: Array<number>): Array<number>
|
|
30
30
|
export function signRsa(privateKey: string, hash: Array<number>): Array<number>
|
|
31
31
|
export function verifyRsa(publicKey: string, hash: Array<number>, signature: Array<number>): boolean
|
|
32
|
+
export function sha512RsaDigitalSignature(rsaKeySize: number, dataToSign: Array<number>): RsaDigitalSignatureResult
|
|
33
|
+
export function sha512RsaVerifyDigitalSignature(publicKey: string, dataToVerify: Array<number>, signature: Array<number>): boolean
|
|
34
|
+
export function sha256RsaDigitalSignature(rsaKeySize: number, dataToSign: Array<number>): RsaDigitalSignatureResult
|
|
35
|
+
export function sha256RsaVerifyDigitalSignature(publicKey: string, dataToVerify: Array<number>, signature: Array<number>): boolean
|
|
36
|
+
export function sha512Ed25519DigitalSignature(dataToSign: Array<number>): Shaed25519DalekDigitalSignatureResult
|
|
37
|
+
export function sha512Ed25519DigitalSignatureVerify(publicKey: Array<number>, dataToVerify: Array<number>, signature: Array<number>): boolean
|
|
38
|
+
export function sha256Ed25519DigitalSignature(dataToSign: Array<number>): Shaed25519DalekDigitalSignatureResult
|
|
39
|
+
export function sha256Ed25519DigitalSignatureVerify(publicKey: Array<number>, dataToVerify: Array<number>, signature: Array<number>): boolean
|
|
32
40
|
export type x25519SecretPublicKeyResult = X25519SecretPublicKeyResult
|
|
33
41
|
export class X25519SecretPublicKeyResult {
|
|
34
42
|
publicKey: Array<number>
|
|
@@ -46,3 +54,16 @@ export class RsaKeyPairResult {
|
|
|
46
54
|
publicKey: string
|
|
47
55
|
constructor(privateKey: string, publicKey: string)
|
|
48
56
|
}
|
|
57
|
+
export type RSADigitalSignatureResult = RsaDigitalSignatureResult
|
|
58
|
+
export class RsaDigitalSignatureResult {
|
|
59
|
+
publicKey: string
|
|
60
|
+
privateKey: string
|
|
61
|
+
signature: Array<number>
|
|
62
|
+
constructor(publicKey: string, privateKey: string, signature: Array<number>)
|
|
63
|
+
}
|
|
64
|
+
export type SHAED25519DalekDigitalSignatureResult = Shaed25519DalekDigitalSignatureResult
|
|
65
|
+
export class Shaed25519DalekDigitalSignatureResult {
|
|
66
|
+
publicKey: Array<number>
|
|
67
|
+
signature: Array<number>
|
|
68
|
+
constructor(publicKey: Array<number>, signature: Array<number>)
|
|
69
|
+
}
|
package/index.node
CHANGED
|
Binary file
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { RsaDigitalSignatureResult, SHAED25519DalekDigitalSignatureResult } from "../../index";
|
|
2
|
+
import { IDigitalSignature } from "./digital-signature-base";
|
|
3
|
+
export declare class DigitalSignatureSHA512Wrapper implements IDigitalSignature {
|
|
4
|
+
createED25519(dataToSign: number[]): SHAED25519DalekDigitalSignatureResult;
|
|
5
|
+
verifyED25519(publicKey: number[], dataToVerify: number[], signature: number[]): boolean;
|
|
6
|
+
createRsa(rsa_key_size: number, data_to_sign: number[]): RsaDigitalSignatureResult;
|
|
7
|
+
verifyRSa(public_key: string, data_to_verify: number[], signature: number[]): boolean;
|
|
8
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DigitalSignatureSHA512Wrapper = void 0;
|
|
4
|
+
const index_1 = require("../../index");
|
|
5
|
+
class DigitalSignatureSHA512Wrapper {
|
|
6
|
+
createED25519(dataToSign) {
|
|
7
|
+
if (dataToSign?.length === 0) {
|
|
8
|
+
throw new Error("Must provide allocated data to sign");
|
|
9
|
+
}
|
|
10
|
+
return (0, index_1.sha512Ed25519DigitalSignature)(dataToSign);
|
|
11
|
+
}
|
|
12
|
+
verifyED25519(publicKey, dataToVerify, signature) {
|
|
13
|
+
if (!publicKey) {
|
|
14
|
+
throw new Error("You must provide a public key for verify with ED25519");
|
|
15
|
+
}
|
|
16
|
+
if (dataToVerify?.length === 0) {
|
|
17
|
+
throw new Error("Must provide allocated data to verify");
|
|
18
|
+
}
|
|
19
|
+
if (signature?.length === 0) {
|
|
20
|
+
throw new Error("Must provide allocated signature to verify");
|
|
21
|
+
}
|
|
22
|
+
return (0, index_1.sha512Ed25519DigitalSignatureVerify)(publicKey, dataToVerify, signature);
|
|
23
|
+
}
|
|
24
|
+
createRsa(rsa_key_size, data_to_sign) {
|
|
25
|
+
if (rsa_key_size !== 1024 && rsa_key_size !== 2048 && rsa_key_size !== 4096) {
|
|
26
|
+
throw new Error("You need to provide an appropriate RSA key size.");
|
|
27
|
+
}
|
|
28
|
+
if (data_to_sign?.length === 0) {
|
|
29
|
+
throw new Error("Must provide allocated data to sign");
|
|
30
|
+
}
|
|
31
|
+
return (0, index_1.sha512RsaDigitalSignature)(rsa_key_size, data_to_sign);
|
|
32
|
+
}
|
|
33
|
+
verifyRSa(public_key, data_to_verify, signature) {
|
|
34
|
+
if (!public_key) {
|
|
35
|
+
throw new Error("Must provide a public key");
|
|
36
|
+
}
|
|
37
|
+
if (data_to_verify?.length === 0) {
|
|
38
|
+
throw new Error("Must provide an allocated data to verify");
|
|
39
|
+
}
|
|
40
|
+
if (signature?.length === 0) {
|
|
41
|
+
throw new Error("Must provide an allocated signature");
|
|
42
|
+
}
|
|
43
|
+
return (0, index_1.sha512RsaVerifyDigitalSignature)(public_key, data_to_verify, signature);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
exports.DigitalSignatureSHA512Wrapper = DigitalSignatureSHA512Wrapper;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { RSADigitalSignatureResult, SHAED25519DalekDigitalSignatureResult } from "../../index";
|
|
2
|
+
export interface IDigitalSignature {
|
|
3
|
+
createRsa(rsa_key_size: number, data_to_sign: Array<number>): RSADigitalSignatureResult;
|
|
4
|
+
verifyRSa(public_key: string, data_to_verify: Array<number>, signature: Array<number>): boolean;
|
|
5
|
+
createED25519(dataToSign: Array<number>): SHAED25519DalekDigitalSignatureResult;
|
|
6
|
+
verifyED25519(publicKey: Array<number>, dataToVerify: Array<number>, signature: Array<number>): boolean;
|
|
7
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { DigitalSignatureSHA512Wrapper } from "./digital-siganture-sha-512";
|
|
2
|
+
export declare enum DigitalSignatureType {
|
|
3
|
+
SHA512 = 1,
|
|
4
|
+
SHA256 = 2
|
|
5
|
+
}
|
|
6
|
+
export declare class DigitalSignatureFactory {
|
|
7
|
+
static get(type: DigitalSignatureType): DigitalSignatureSHA512Wrapper;
|
|
8
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DigitalSignatureFactory = exports.DigitalSignatureType = void 0;
|
|
4
|
+
const digital_siganture_sha_512_1 = require("./digital-siganture-sha-512");
|
|
5
|
+
const digital_signaturte_sha_256_1 = require("./digital-signaturte-sha-256");
|
|
6
|
+
var DigitalSignatureType;
|
|
7
|
+
(function (DigitalSignatureType) {
|
|
8
|
+
DigitalSignatureType[DigitalSignatureType["SHA512"] = 1] = "SHA512";
|
|
9
|
+
DigitalSignatureType[DigitalSignatureType["SHA256"] = 2] = "SHA256";
|
|
10
|
+
})(DigitalSignatureType || (exports.DigitalSignatureType = DigitalSignatureType = {}));
|
|
11
|
+
class DigitalSignatureFactory {
|
|
12
|
+
static get(type) {
|
|
13
|
+
let ds = new digital_siganture_sha_512_1.DigitalSignatureSHA512Wrapper();
|
|
14
|
+
switch (type) {
|
|
15
|
+
case DigitalSignatureType.SHA256:
|
|
16
|
+
ds = new digital_signaturte_sha_256_1.DigitalSignatureSHA256Wrapper();
|
|
17
|
+
break;
|
|
18
|
+
}
|
|
19
|
+
return ds;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
exports.DigitalSignatureFactory = DigitalSignatureFactory;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { RsaDigitalSignatureResult, Shaed25519DalekDigitalSignatureResult } from "../../index";
|
|
2
|
+
import { IDigitalSignature } from "./digital-signature-base";
|
|
3
|
+
export declare class DigitalSignatureSHA256Wrapper implements IDigitalSignature {
|
|
4
|
+
createED25519(dataToSign: number[]): Shaed25519DalekDigitalSignatureResult;
|
|
5
|
+
verifyED25519(publicKey: number[], dataToVerify: number[], signature: number[]): boolean;
|
|
6
|
+
createRsa(rsa_key_size: number, data_to_sign: number[]): RsaDigitalSignatureResult;
|
|
7
|
+
verifyRSa(public_key: string, data_to_verify: number[], signature: number[]): boolean;
|
|
8
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DigitalSignatureSHA256Wrapper = void 0;
|
|
4
|
+
const index_1 = require("../../index");
|
|
5
|
+
class DigitalSignatureSHA256Wrapper {
|
|
6
|
+
createED25519(dataToSign) {
|
|
7
|
+
if (dataToSign?.length === 0) {
|
|
8
|
+
throw new Error("Must provide allocated data to sign");
|
|
9
|
+
}
|
|
10
|
+
return (0, index_1.sha256Ed25519DigitalSignature)(dataToSign);
|
|
11
|
+
}
|
|
12
|
+
verifyED25519(publicKey, dataToVerify, signature) {
|
|
13
|
+
if (!publicKey) {
|
|
14
|
+
throw new Error("You must provide a public key for verify with ED25519");
|
|
15
|
+
}
|
|
16
|
+
if (dataToVerify?.length === 0) {
|
|
17
|
+
throw new Error("Must provide allocated data to verify");
|
|
18
|
+
}
|
|
19
|
+
if (signature?.length === 0) {
|
|
20
|
+
throw new Error("Must provide allocated signature to verify");
|
|
21
|
+
}
|
|
22
|
+
return (0, index_1.sha256Ed25519DigitalSignatureVerify)(publicKey, dataToVerify, signature);
|
|
23
|
+
}
|
|
24
|
+
createRsa(rsa_key_size, data_to_sign) {
|
|
25
|
+
if (rsa_key_size !== 1024 && rsa_key_size !== 2048 && rsa_key_size !== 4096) {
|
|
26
|
+
throw new Error("You need to provide an appropriate RSA key size.");
|
|
27
|
+
}
|
|
28
|
+
if (data_to_sign?.length === 0) {
|
|
29
|
+
throw new Error("Must provide allocated data to sign");
|
|
30
|
+
}
|
|
31
|
+
return (0, index_1.sha256RsaDigitalSignature)(rsa_key_size, data_to_sign);
|
|
32
|
+
}
|
|
33
|
+
verifyRSa(public_key, data_to_verify, signature) {
|
|
34
|
+
if (!public_key) {
|
|
35
|
+
throw new Error("Must provide a public key");
|
|
36
|
+
}
|
|
37
|
+
if (data_to_verify?.length === 0) {
|
|
38
|
+
throw new Error("Must provide an allocated data to verify");
|
|
39
|
+
}
|
|
40
|
+
if (signature?.length === 0) {
|
|
41
|
+
throw new Error("Must provide an allocated signature");
|
|
42
|
+
}
|
|
43
|
+
return (0, index_1.sha256RsaVerifyDigitalSignature)(public_key, data_to_verify, signature);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
exports.DigitalSignatureSHA256Wrapper = DigitalSignatureSHA256Wrapper;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { DigitalSignatureType } from "./digital-signature-factory";
|
|
2
|
+
import { DigitalSignatureFactory } from "./digital-signature-factory";
|
|
3
|
+
import { DigitalSignatureSHA256Wrapper } from "./digital-signaturte-sha-256";
|
|
4
|
+
import { DigitalSignatureSHA512Wrapper } from "./digital-siganture-sha-512";
|
|
5
|
+
export { DigitalSignatureFactory, DigitalSignatureSHA256Wrapper, DigitalSignatureSHA512Wrapper, DigitalSignatureType };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DigitalSignatureType = exports.DigitalSignatureSHA512Wrapper = exports.DigitalSignatureSHA256Wrapper = exports.DigitalSignatureFactory = void 0;
|
|
4
|
+
const digital_signature_factory_1 = require("./digital-signature-factory");
|
|
5
|
+
Object.defineProperty(exports, "DigitalSignatureType", { enumerable: true, get: function () { return digital_signature_factory_1.DigitalSignatureType; } });
|
|
6
|
+
const digital_signature_factory_2 = require("./digital-signature-factory");
|
|
7
|
+
Object.defineProperty(exports, "DigitalSignatureFactory", { enumerable: true, get: function () { return digital_signature_factory_2.DigitalSignatureFactory; } });
|
|
8
|
+
const digital_signaturte_sha_256_1 = require("./digital-signaturte-sha-256");
|
|
9
|
+
Object.defineProperty(exports, "DigitalSignatureSHA256Wrapper", { enumerable: true, get: function () { return digital_signaturte_sha_256_1.DigitalSignatureSHA256Wrapper; } });
|
|
10
|
+
const digital_siganture_sha_512_1 = require("./digital-siganture-sha-512");
|
|
11
|
+
Object.defineProperty(exports, "DigitalSignatureSHA512Wrapper", { enumerable: true, get: function () { return digital_siganture_sha_512_1.DigitalSignatureSHA512Wrapper; } });
|
package/lib/index.d.ts
CHANGED
|
@@ -4,4 +4,5 @@ import { X25519Wrapper } from "./key_exchange/index";
|
|
|
4
4
|
import { AESWrapper } from "./symmetric/index";
|
|
5
5
|
import { RsaKeyPairResult, RSAWrapper } from "./asymmetric/index";
|
|
6
6
|
import { AesRsaHybridEncryptResult, AESRSAHybridInitializer, HybridEncryptionWrapper } from "./hybrid/index";
|
|
7
|
-
|
|
7
|
+
import { DigitalSignatureFactory, DigitalSignatureSHA256Wrapper, DigitalSignatureSHA512Wrapper, DigitalSignatureType } from "./digital-signature";
|
|
8
|
+
export { AesRsaHybridEncryptResult, AESRSAHybridInitializer, AESWrapper, Argon2Wrapper, BCryptWrapper, HasherFactory, HasherType, HybridEncryptionWrapper, PasswordHasherFactory, PasswordHasherType, RsaKeyPairResult, RSAWrapper, ScryptWrapper, SHAWrapper, X25519Wrapper, DigitalSignatureFactory, DigitalSignatureSHA256Wrapper, DigitalSignatureSHA512Wrapper, DigitalSignatureType, };
|
package/lib/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.X25519Wrapper = exports.SHAWrapper = exports.ScryptWrapper = exports.RSAWrapper = exports.RsaKeyPairResult = exports.PasswordHasherType = exports.PasswordHasherFactory = exports.HybridEncryptionWrapper = exports.HasherType = exports.HasherFactory = exports.BCryptWrapper = exports.Argon2Wrapper = exports.AESWrapper = exports.AESRSAHybridInitializer = exports.AesRsaHybridEncryptResult = void 0;
|
|
3
|
+
exports.DigitalSignatureType = exports.DigitalSignatureSHA512Wrapper = exports.DigitalSignatureSHA256Wrapper = exports.DigitalSignatureFactory = exports.X25519Wrapper = exports.SHAWrapper = exports.ScryptWrapper = exports.RSAWrapper = exports.RsaKeyPairResult = exports.PasswordHasherType = exports.PasswordHasherFactory = exports.HybridEncryptionWrapper = exports.HasherType = exports.HasherFactory = exports.BCryptWrapper = exports.Argon2Wrapper = exports.AESWrapper = exports.AESRSAHybridInitializer = exports.AesRsaHybridEncryptResult = void 0;
|
|
4
4
|
const index_1 = require("./password-hashers/index");
|
|
5
5
|
Object.defineProperty(exports, "Argon2Wrapper", { enumerable: true, get: function () { return index_1.Argon2Wrapper; } });
|
|
6
6
|
Object.defineProperty(exports, "BCryptWrapper", { enumerable: true, get: function () { return index_1.BCryptWrapper; } });
|
|
@@ -22,3 +22,8 @@ const index_6 = require("./hybrid/index");
|
|
|
22
22
|
Object.defineProperty(exports, "AesRsaHybridEncryptResult", { enumerable: true, get: function () { return index_6.AesRsaHybridEncryptResult; } });
|
|
23
23
|
Object.defineProperty(exports, "AESRSAHybridInitializer", { enumerable: true, get: function () { return index_6.AESRSAHybridInitializer; } });
|
|
24
24
|
Object.defineProperty(exports, "HybridEncryptionWrapper", { enumerable: true, get: function () { return index_6.HybridEncryptionWrapper; } });
|
|
25
|
+
const digital_signature_1 = require("./digital-signature");
|
|
26
|
+
Object.defineProperty(exports, "DigitalSignatureFactory", { enumerable: true, get: function () { return digital_signature_1.DigitalSignatureFactory; } });
|
|
27
|
+
Object.defineProperty(exports, "DigitalSignatureSHA256Wrapper", { enumerable: true, get: function () { return digital_signature_1.DigitalSignatureSHA256Wrapper; } });
|
|
28
|
+
Object.defineProperty(exports, "DigitalSignatureSHA512Wrapper", { enumerable: true, get: function () { return digital_signature_1.DigitalSignatureSHA512Wrapper; } });
|
|
29
|
+
Object.defineProperty(exports, "DigitalSignatureType", { enumerable: true, get: function () { return digital_signature_1.DigitalSignatureType; } });
|
package/package.json
CHANGED
|
@@ -1,41 +1,41 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
"
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
"
|
|
7
|
-
"
|
|
8
|
-
|
|
9
|
-
"
|
|
10
|
-
"
|
|
11
|
-
"
|
|
12
|
-
"build
|
|
13
|
-
"build:
|
|
14
|
-
"prepare": "npm run build"
|
|
15
|
-
},
|
|
16
|
-
"repository": {
|
|
17
|
-
"type": "git",
|
|
18
|
-
"url": "git+https://github.com/Cryptographic-API-Services/cas-typescript-sdk"
|
|
19
|
-
},
|
|
20
|
-
"keywords": [],
|
|
21
|
-
"author": "Mike Mulchrone <mikemulchrone987@gmail.com>",
|
|
22
|
-
"license": "Apache 2.0",
|
|
23
|
-
"bugs": {
|
|
24
|
-
"url": "https://github.com/Cryptographic-API-Services/cas-typescript-sdk/issues"
|
|
25
|
-
},
|
|
26
|
-
"homepage": "https://github.com/Cryptographic-API-Services/cas-typescript-sdk#readme",
|
|
27
|
-
"publishConfig": {
|
|
28
|
-
"access": "public",
|
|
29
|
-
"registry": "https://registry.npmjs.org/"
|
|
30
|
-
},
|
|
31
|
-
"devDependencies": {
|
|
32
|
-
"@napi-rs/cli": "^2.17.0",
|
|
33
|
-
"@types/chai": "^4.3.11",
|
|
34
|
-
"@types/mocha": "^10.0.6",
|
|
35
|
-
"@types/node-fetch": "^2.6.3",
|
|
36
|
-
"chai": "^4.4.1",
|
|
37
|
-
"mocha": "^10.2.0",
|
|
38
|
-
"ts-node": "^10.9.1",
|
|
39
|
-
"typescript": "^5.0.3"
|
|
40
|
-
}
|
|
41
|
-
}
|
|
1
|
+
|
|
2
|
+
{
|
|
3
|
+
"name": "cas-typescript-sdk",
|
|
4
|
+
"version": "1.0.17",
|
|
5
|
+
"description": "",
|
|
6
|
+
"main": "lib/index.js",
|
|
7
|
+
"types": "lib/index.d.ts",
|
|
8
|
+
"scripts": {
|
|
9
|
+
"test": "cargo test && npm run build && mocha -r ts-node/register ./test-ts/**/*.ts --timeout 20000 --recursive",
|
|
10
|
+
"node:test": "mocha -r ts-node/register ./test-ts/**/*.ts --timeout 20000 --recursive",
|
|
11
|
+
"rust:test": "cargo test",
|
|
12
|
+
"build": "npm run build:rust && rm -rf lib && tsc",
|
|
13
|
+
"build:rust": "napi build --release",
|
|
14
|
+
"prepare": "npm run build"
|
|
15
|
+
},
|
|
16
|
+
"repository": {
|
|
17
|
+
"type": "git",
|
|
18
|
+
"url": "git+https://github.com/Cryptographic-API-Services/cas-typescript-sdk"
|
|
19
|
+
},
|
|
20
|
+
"keywords": [],
|
|
21
|
+
"author": "Mike Mulchrone <mikemulchrone987@gmail.com>",
|
|
22
|
+
"license": "Apache 2.0",
|
|
23
|
+
"bugs": {
|
|
24
|
+
"url": "https://github.com/Cryptographic-API-Services/cas-typescript-sdk/issues"
|
|
25
|
+
},
|
|
26
|
+
"homepage": "https://github.com/Cryptographic-API-Services/cas-typescript-sdk#readme",
|
|
27
|
+
"publishConfig": {
|
|
28
|
+
"access": "public",
|
|
29
|
+
"registry": "https://registry.npmjs.org/"
|
|
30
|
+
},
|
|
31
|
+
"devDependencies": {
|
|
32
|
+
"@napi-rs/cli": "^2.17.0",
|
|
33
|
+
"@types/chai": "^4.3.11",
|
|
34
|
+
"@types/mocha": "^10.0.6",
|
|
35
|
+
"@types/node-fetch": "^2.6.3",
|
|
36
|
+
"chai": "^4.4.1",
|
|
37
|
+
"mocha": "^10.2.0",
|
|
38
|
+
"ts-node": "^10.9.1",
|
|
39
|
+
"typescript": "^5.0.3"
|
|
40
|
+
}
|
|
41
|
+
}
|
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
use napi_derive::napi;
|
|
2
|
-
|
|
3
|
-
#[napi(constructor)]
|
|
4
|
-
pub struct RSAKeyPairResult {
|
|
5
|
-
pub private_key: String,
|
|
6
|
-
pub public_key: String
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
pub trait CASRSAEncryption {
|
|
10
|
-
fn generate_rsa_keys(key_size: u32) -> RSAKeyPairResult;
|
|
11
|
-
fn encrypt_plaintext(public_key: String, plaintext: Vec<u8>) -> Vec<u8>;
|
|
12
|
-
fn decrypt_ciphertext(private_key: String, ciphertext: Vec<u8>) -> Vec<u8>;
|
|
13
|
-
fn sign(private_key: String, hash: Vec<u8>) -> Vec<u8>;
|
|
14
|
-
fn verify(public_key: String, hash: Vec<u8>, signed_text: Vec<u8>) -> bool;
|
|
15
|
-
}
|
|
1
|
+
use napi_derive::napi;
|
|
2
|
+
|
|
3
|
+
#[napi(constructor)]
|
|
4
|
+
pub struct RSAKeyPairResult {
|
|
5
|
+
pub private_key: String,
|
|
6
|
+
pub public_key: String,
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
pub trait CASRSAEncryption {
|
|
10
|
+
fn generate_rsa_keys(key_size: u32) -> RSAKeyPairResult;
|
|
11
|
+
fn encrypt_plaintext(public_key: String, plaintext: Vec<u8>) -> Vec<u8>;
|
|
12
|
+
fn decrypt_ciphertext(private_key: String, ciphertext: Vec<u8>) -> Vec<u8>;
|
|
13
|
+
fn sign(private_key: String, hash: Vec<u8>) -> Vec<u8>;
|
|
14
|
+
fn verify(public_key: String, hash: Vec<u8>, signed_text: Vec<u8>) -> bool;
|
|
15
|
+
}
|