quarkdash 1.0.0

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.
Files changed (75) hide show
  1. package/.idea/modules.xml +8 -0
  2. package/.idea/quarkdash.iml +12 -0
  3. package/.idea/vcs.xml +6 -0
  4. package/LICENSE +21 -0
  5. package/README.md +161 -0
  6. package/coverage/clover.xml +470 -0
  7. package/coverage/coverage-final.json +8 -0
  8. package/coverage/lcov-report/base.css +224 -0
  9. package/coverage/lcov-report/block-navigation.js +87 -0
  10. package/coverage/lcov-report/cipher.ts.html +862 -0
  11. package/coverage/lcov-report/crypto.ts.html +1000 -0
  12. package/coverage/lcov-report/favicon.png +0 -0
  13. package/coverage/lcov-report/index.html +206 -0
  14. package/coverage/lcov-report/index.ts.html +151 -0
  15. package/coverage/lcov-report/kdf.ts.html +274 -0
  16. package/coverage/lcov-report/mac.ts.html +277 -0
  17. package/coverage/lcov-report/prettify.css +1 -0
  18. package/coverage/lcov-report/prettify.js +2 -0
  19. package/coverage/lcov-report/ringlwe.ts.html +895 -0
  20. package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
  21. package/coverage/lcov-report/sorter.js +210 -0
  22. package/coverage/lcov-report/utils.ts.html +1111 -0
  23. package/coverage/lcov.info +740 -0
  24. package/dist/cjs/cipher.js +265 -0
  25. package/dist/cjs/cipher.js.map +1 -0
  26. package/dist/cjs/crypto.js +284 -0
  27. package/dist/cjs/crypto.js.map +1 -0
  28. package/dist/cjs/index.js +37 -0
  29. package/dist/cjs/index.js.map +1 -0
  30. package/dist/cjs/kdf.js +56 -0
  31. package/dist/cjs/kdf.js.map +1 -0
  32. package/dist/cjs/mac.js +55 -0
  33. package/dist/cjs/mac.js.map +1 -0
  34. package/dist/cjs/ringlwe.js +267 -0
  35. package/dist/cjs/ringlwe.js.map +1 -0
  36. package/dist/cjs/types.js +3 -0
  37. package/dist/cjs/types.js.map +1 -0
  38. package/dist/cjs/utils.js +320 -0
  39. package/dist/cjs/utils.js.map +1 -0
  40. package/dist/esm/cipher.js +259 -0
  41. package/dist/esm/cipher.js.map +1 -0
  42. package/dist/esm/crypto.js +280 -0
  43. package/dist/esm/crypto.js.map +1 -0
  44. package/dist/esm/index.js +21 -0
  45. package/dist/esm/index.js.map +1 -0
  46. package/dist/esm/kdf.js +52 -0
  47. package/dist/esm/kdf.js.map +1 -0
  48. package/dist/esm/mac.js +51 -0
  49. package/dist/esm/mac.js.map +1 -0
  50. package/dist/esm/ringlwe.js +263 -0
  51. package/dist/esm/ringlwe.js.map +1 -0
  52. package/dist/esm/types.js +2 -0
  53. package/dist/esm/types.js.map +1 -0
  54. package/dist/esm/utils.js +313 -0
  55. package/dist/esm/utils.js.map +1 -0
  56. package/dist/types/cipher.d.ts +153 -0
  57. package/dist/types/crypto.d.ts +155 -0
  58. package/dist/types/index.d.ts +16 -0
  59. package/dist/types/kdf.d.ts +34 -0
  60. package/dist/types/mac.d.ts +47 -0
  61. package/dist/types/ringlwe.d.ts +127 -0
  62. package/dist/types/types.d.ts +69 -0
  63. package/dist/types/utils.d.ts +132 -0
  64. package/img/cover.png +0 -0
  65. package/package.json +63 -0
  66. package/src/cipher.ts +260 -0
  67. package/src/crypto.ts +306 -0
  68. package/src/index.ts +23 -0
  69. package/src/kdf.ts +64 -0
  70. package/src/mac.ts +65 -0
  71. package/src/ringlwe.ts +271 -0
  72. package/src/types.ts +75 -0
  73. package/src/utils.ts +343 -0
  74. package/tsconfig.cjs.json +7 -0
  75. package/tsconfig.json +18 -0
@@ -0,0 +1,153 @@
1
+ /**
2
+ * QuarkDash Ciphers Implementation
3
+ *
4
+ * @git https://github.com/devsdaddy/quarkdash
5
+ * @version 1.0.0
6
+ * @author Elijah Rastorguev
7
+ * @build 1000
8
+ * @website https://dev.to/devsdaddy
9
+ */
10
+ import { ICipher } from "./types";
11
+ /**
12
+ * Cipher Type
13
+ */
14
+ export declare enum CipherType {
15
+ ChaCha20 = 0,
16
+ Gimli = 1
17
+ }
18
+ /**
19
+ * Cipher Factory
20
+ */
21
+ export declare class CipherFactory {
22
+ /**
23
+ * Create Cipher
24
+ * @param algorithm {CipherType} Current cipher type
25
+ * @param key {Uint8Array} Key buffer
26
+ * @param nonce {Uint8Array} Nonce buffer
27
+ * @returns {ICipher} Cipher class instance
28
+ */
29
+ static create(algorithm: CipherType, key: Uint8Array, nonce: Uint8Array): ICipher;
30
+ }
31
+ /**
32
+ * ChaCha20 Based Cipher Implementation
33
+ */
34
+ export declare class QuarkDashChaCha implements ICipher {
35
+ private readonly key;
36
+ private readonly nonce;
37
+ /**
38
+ * Create ChaCha20 Cipher
39
+ * @param key {Uint8Array} Key buffer
40
+ * @param nonce {Uint8Array} Nonce buffer
41
+ */
42
+ constructor(key: Uint8Array, nonce: Uint8Array);
43
+ /**
44
+ * Encrypt data async using ChaCha20
45
+ * @param data {Uint8Array} Raw data buffer
46
+ * @returns {Promise<Uint8Array>} Result buffer
47
+ * TODO: GPU Calculations
48
+ */
49
+ encrypt(data: Uint8Array): Promise<Uint8Array>;
50
+ /**
51
+ * Decrypt data async using ChaCha20
52
+ * @param data {Uint8Array} Encrypted raw data buffer
53
+ * @returns {Promise<Uint8Array>} Result buffer
54
+ * TODO: GPU Calculations
55
+ */
56
+ decrypt(data: Uint8Array): Promise<Uint8Array>;
57
+ /**
58
+ * Encrypt data sync using ChaCha20
59
+ * @param data {Uint8Array} Raw data buffer
60
+ * @returns {Uint8Array} Result buffer
61
+ */
62
+ encryptSync(data: Uint8Array): Uint8Array;
63
+ /**
64
+ * Decrypt data sync using ChaCha20
65
+ * @param data {Uint8Array} Encrypted raw data buffer
66
+ * @returns {Uint8Array} Result buffer
67
+ */
68
+ decryptSync(data: Uint8Array): Uint8Array;
69
+ /**
70
+ * Process ChaCha20 Cipher
71
+ * @param data {Uint8Array} Data for processing
72
+ * @returns {Uint8Array} Processing result
73
+ * @private
74
+ */
75
+ private process;
76
+ /**
77
+ * Get keystream block
78
+ * @param counter {number} counter
79
+ * @returns {Uint8Array} result buffer
80
+ * @private
81
+ */
82
+ private keystreamBlock;
83
+ /**
84
+ * Quarter Round
85
+ * @param s {Uint8Array} Buffer
86
+ * @param a {number}
87
+ * @param b {number}
88
+ * @param c {number}
89
+ * @param d {number}
90
+ * @private
91
+ */
92
+ private quarterRound;
93
+ }
94
+ /**
95
+ * Gimli Cipher
96
+ */
97
+ export declare class QuarkDashGimli implements ICipher {
98
+ private readonly key;
99
+ private readonly nonce;
100
+ /**
101
+ * Create Gimli Cipher
102
+ * @param key {Uint8Array} Key buffer
103
+ * @param nonce {Uint8Array} Nonce buffer
104
+ */
105
+ constructor(key: Uint8Array, nonce: Uint8Array);
106
+ /**
107
+ * Encrypt data async using Gimli
108
+ * @param data {Uint8Array} Raw data buffer
109
+ * @returns {Promise<Uint8Array>} Result buffer
110
+ * TODO: GPU Calculations
111
+ */
112
+ encrypt(data: Uint8Array): Promise<Uint8Array>;
113
+ /**
114
+ * Decrypt data async using Gimli
115
+ * @param data {Uint8Array} Encrypted raw data buffer
116
+ * @returns {Promise<Uint8Array>} Result buffer
117
+ * TODO: GPU Calculations
118
+ */
119
+ decrypt(data: Uint8Array): Promise<Uint8Array>;
120
+ /**
121
+ * Encrypt data sync using Gimli
122
+ * @param data {Uint8Array} Raw data buffer
123
+ * @returns {Uint8Array} Result buffer
124
+ */
125
+ encryptSync(data: Uint8Array): Uint8Array;
126
+ /**
127
+ * Decrypt data sync using Gimli
128
+ * @param data {Uint8Array} Encrypted raw data buffer
129
+ * @returns {Uint8Array} Result buffer
130
+ */
131
+ decryptSync(data: Uint8Array): Uint8Array;
132
+ /**
133
+ * Process Gimli Cipher
134
+ * @param data {Uint8Array} Input buffer
135
+ * @returns {Uint8Array} Output buffer
136
+ * @private
137
+ */
138
+ private process;
139
+ /**
140
+ * Get keystream block
141
+ * @param counter {number} Counter
142
+ * @returns {Uint8Array} Result buffer
143
+ * @private
144
+ */
145
+ private keystreamBlock;
146
+ /**
147
+ * Gimli Round
148
+ * @param state {Uint32Array} State buffer
149
+ * @param round {number} Round number
150
+ * @private
151
+ */
152
+ private gimliRound;
153
+ }
@@ -0,0 +1,155 @@
1
+ /**
2
+ * QuarkDash Crypto Algorithm Implementation
3
+ *
4
+ * @git https://github.com/devsdaddy/quarkdash
5
+ * @version 1.0.0
6
+ * @author Elijah Rastorguev
7
+ * @build 1000
8
+ * @website https://dev.to/devsdaddy
9
+ */
10
+ import { CipherType } from "./cipher";
11
+ import { ICryptoMethodAsync, ICryptoMethodSync, IKDF, IKeyExchange, IMAC } from "./types";
12
+ /**
13
+ * Quark Dash parsed encrypted packet
14
+ */
15
+ export interface QDEncryptedPacket {
16
+ metadata: Uint8Array;
17
+ encrypted: Uint8Array;
18
+ mac: Uint8Array;
19
+ }
20
+ /**
21
+ * QuarkDash options
22
+ */
23
+ export interface QuarkDashOptions {
24
+ cipher: CipherType;
25
+ kdf: IKDF;
26
+ mac: IMAC;
27
+ keyExchange: IKeyExchange;
28
+ maxPacketWindow: number;
29
+ timestampToleranceMs: number;
30
+ }
31
+ /**
32
+ * QuarkDash Crypto Algorithm Implementation
33
+ */
34
+ export declare class QuarkDash implements ICryptoMethodAsync, ICryptoMethodSync {
35
+ private config;
36
+ private sessionKey;
37
+ private cipher;
38
+ private macKey;
39
+ private sendSeq;
40
+ private recvSeq;
41
+ private receivedPackets;
42
+ private myKeyPair?;
43
+ private peerPublicKey?;
44
+ /**
45
+ * Create QuarkDash Crypto
46
+ * @param config {QuarkDashOptions} Crypto Options
47
+ */
48
+ constructor(config?: Partial<QuarkDashOptions>);
49
+ /**
50
+ * Generate key pair async
51
+ * @returns {Promise<Uint8Array>} Key pair buffer
52
+ * TODO: GPU Computing
53
+ */
54
+ generateKeyPair(): Promise<Uint8Array>;
55
+ /**
56
+ * Generate key pair sync
57
+ * @returns {Uint8Array} Key pair buffer
58
+ */
59
+ generateKeyPairSync(): Uint8Array;
60
+ /**
61
+ * Initialize session async
62
+ * @param peerPublicKey {Uint8Array} Peer public key buffer
63
+ * @param isInitiator {boolean} Is session initiator
64
+ * @returns {Promise<Uint8Array|number>} Returns derived session key or null
65
+ * TODO: GPU Computing
66
+ */
67
+ initializeSession(peerPublicKey: Uint8Array, isInitiator: boolean): Promise<Uint8Array | null>;
68
+ /**
69
+ * Initialize session sync
70
+ * @param peerPublicKey {Uint8Array} Peer public key buffer
71
+ * @param isInitiator {boolean} Is session initiator
72
+ * @returns {Uint8Array|number} Returns derived session key or null
73
+ */
74
+ initializeSessionSync(peerPublicKey: Uint8Array, isInitiator: boolean): Uint8Array | null;
75
+ /**
76
+ * Finalize session async
77
+ * @param ciphertext {Uint8Array} Cipher text buffer
78
+ * TODO: GPU Computing
79
+ */
80
+ finalizeSession(ciphertext: Uint8Array): Promise<void>;
81
+ /**
82
+ * Finalize session sync
83
+ * @param ciphertext {Uint8Array} Cipher text buffer
84
+ */
85
+ finalizeSessionSync(ciphertext: Uint8Array): void;
86
+ /**
87
+ * Derive session keys async
88
+ * @param sharedSecret {Uint8Array} Shared secret buffer
89
+ * @private
90
+ * TODO: GPU Computing
91
+ */
92
+ private deriveSessionKeys;
93
+ /**
94
+ * Derive session keys sync
95
+ * @param sharedSecret {Uint8Array} Shared secret buffer
96
+ * @private
97
+ */
98
+ private deriveSessionKeysSync;
99
+ /**
100
+ * Process derive session keys
101
+ * @param keyMaterial {Uint8Array} Key material buffer
102
+ * @param sharedSecret {Uint8Array} Shared secret buffer
103
+ * @private
104
+ */
105
+ private processDeriveSessionKeys;
106
+ /**
107
+ * Encrypt sync
108
+ * @param decryptedData {Uint8Array} Decrypted buffer
109
+ * @returns {Promise<Uint8Array>} Encrypted buffer
110
+ * TODO: GPU Computing
111
+ */
112
+ encrypt(decryptedData: Uint8Array): Promise<Uint8Array>;
113
+ /**
114
+ * Encrypt sync
115
+ * @param decryptedData {Uint8Array} Decrypted buffer
116
+ * @returns {Uint8Array} Encrypted buffer
117
+ */
118
+ encryptSync(decryptedData: Uint8Array): Uint8Array;
119
+ /**
120
+ * Decrypt async
121
+ * @param encryptedData {Uint8Array} Encrypted buffer
122
+ * @returns {Promise<Uint8Array>} Decrypted buffer
123
+ * TODO: GPU Computing
124
+ */
125
+ decrypt(encryptedData: Uint8Array): Promise<Uint8Array>;
126
+ /**
127
+ * Decrypt sync
128
+ * @param encryptedData {Uint8Array} Encrypted buffer
129
+ * @returns {Uint8Array} Decrypted buffer
130
+ */
131
+ decryptSync(encryptedData: Uint8Array): Uint8Array;
132
+ /**
133
+ * Process decrypt
134
+ * @param encryptedData {Uint8Array} encrypted buffer
135
+ * @returns {QDEncryptedPacket} Parsed encrypted packet
136
+ * @private
137
+ */
138
+ private processDecrypt;
139
+ /**
140
+ * Build meta-data
141
+ * @returns {Uint8Array} Meta-data buffer
142
+ * @private
143
+ */
144
+ private buildMetadata;
145
+ /**
146
+ * Check Meta-Data
147
+ * @param metadata {Uint8Array} Meta-data buffer
148
+ * @private
149
+ */
150
+ private checkMetadata;
151
+ /**
152
+ * Dispose QuarkDash Crypto
153
+ */
154
+ dispose(): void;
155
+ }
@@ -0,0 +1,16 @@
1
+ /**
2
+ * QuarkDash Crypto Library
3
+ *
4
+ * @git https://github.com/devsdaddy/quarkdash
5
+ * @version 1.0.0
6
+ * @author Elijah Rastorguev
7
+ * @build 1000
8
+ * @website https://dev.to/devsdaddy
9
+ */
10
+ export * from "./types";
11
+ export * from "./utils";
12
+ export * from "./kdf";
13
+ export * from "./mac";
14
+ export * from "./cipher";
15
+ export * from "./ringlwe";
16
+ export * from "./crypto";
@@ -0,0 +1,34 @@
1
+ /**
2
+ * QuarkDash Shake256 Based KDF
3
+ *
4
+ * @git https://github.com/devsdaddy/quarkdash
5
+ * @version 1.0.0
6
+ * @author Elijah Rastorguev
7
+ * @build 1000
8
+ * @website https://dev.to/devsdaddy
9
+ */
10
+ import type { IKDF } from "./types";
11
+ /**
12
+ * KDF implementation using Shake-256
13
+ */
14
+ export declare class QuarkDashKDF implements IKDF {
15
+ /**
16
+ * Derive KDF async
17
+ * @param ikm {Uint8Array} IKM buffer
18
+ * @param salt {Uint8Array} Salt buffer
19
+ * @param info {Uint8Array} Meta buffer
20
+ * @param length {number} Buffer length
21
+ * @returns {Promise<Uint8Array>} Result
22
+ * TODO: GPU Calculations
23
+ */
24
+ derive(ikm: Uint8Array, salt: Uint8Array, info: Uint8Array, length: number): Promise<Uint8Array>;
25
+ /**
26
+ * Derive KDF sync
27
+ * @param ikm {Uint8Array} IKM buffer
28
+ * @param salt {Uint8Array} Salt buffer
29
+ * @param info {Uint8Array} Meta buffer
30
+ * @param length {number} Buffer length
31
+ * @returns {Uint8Array} Result
32
+ */
33
+ deriveSync(ikm: Uint8Array, salt: Uint8Array, info: Uint8Array, length: number): Uint8Array;
34
+ }
@@ -0,0 +1,47 @@
1
+ /**
2
+ * QuarkDash Shake256 Based MAC
3
+ *
4
+ * @git https://github.com/devsdaddy/quarkdash
5
+ * @version 1.0.0
6
+ * @author Elijah Rastorguev
7
+ * @build 1000
8
+ * @website https://dev.to/devsdaddy
9
+ */
10
+ import { IMAC } from "./types";
11
+ /**
12
+ * MAC implementation using Shake-256
13
+ */
14
+ export declare class QuarkDashMAC implements IMAC {
15
+ /**
16
+ * Sign data async
17
+ * @param data {Uint8Array} Data buffer
18
+ * @param key {Uint8Array} Key buffer
19
+ * @returns {Promise<Uint8Array>} Signed result buffer
20
+ * TODO: GPU Calculations
21
+ */
22
+ sign(data: Uint8Array, key: Uint8Array): Promise<Uint8Array>;
23
+ /**
24
+ * Verify async
25
+ * @param data {Uint8Array} data buffer
26
+ * @param key {Uint8Array} key buffer
27
+ * @param tag {Uint8Array} tag buffer
28
+ * @returns {Promise<boolean>} Is verified?
29
+ * TODO: GPU Calculations
30
+ */
31
+ verify(data: Uint8Array, key: Uint8Array, tag: Uint8Array): Promise<boolean>;
32
+ /**
33
+ * Sign data sync
34
+ * @param data {Uint8Array} Data buffer
35
+ * @param key {Uint8Array} Key buffer
36
+ * @returns {Uint8Array} Signed result buffer
37
+ */
38
+ signSync(data: Uint8Array, key: Uint8Array): Uint8Array;
39
+ /**
40
+ * Verify sync
41
+ * @param data {Uint8Array} data buffer
42
+ * @param key {Uint8Array} key buffer
43
+ * @param tag {Uint8Array} tag buffer
44
+ * @returns {Promise<boolean>} Is verified?
45
+ */
46
+ verifySync(data: Uint8Array, key: Uint8Array, tag: Uint8Array): boolean;
47
+ }
@@ -0,0 +1,127 @@
1
+ /**
2
+ * QuarkDash Ring-LWE Implementation
3
+ *
4
+ * @git https://github.com/devsdaddy/quarkdash
5
+ * @version 1.0.0
6
+ * @author Elijah Rastorguev
7
+ * @build 1000
8
+ * @website https://dev.to/devsdaddy
9
+ */
10
+ import { ICryptoEncapsulated, ICryptoKeyPair, IKeyExchange } from "./types";
11
+ /**
12
+ * Ring-LWE based key exchange implementation
13
+ */
14
+ export declare class QuarkDashKeyExchange implements IKeyExchange {
15
+ private static readonly N;
16
+ private static readonly Q;
17
+ private static readonly ROOT;
18
+ private static readonly INV_N;
19
+ /**
20
+ * Get small polygon
21
+ * @returns {bigint[]} Small polygon
22
+ * @private
23
+ */
24
+ private static smallPoly;
25
+ /**
26
+ * Uniform polygon
27
+ * @returns {bigint[]}
28
+ * @private
29
+ */
30
+ private static uniformPoly;
31
+ /**
32
+ * NTT Operation
33
+ * @param poly {bigint[]} Polygon
34
+ * @private
35
+ */
36
+ private static ntt;
37
+ /**
38
+ * Inverse NTT
39
+ * @param poly {bigint[]} Polygon
40
+ * @private
41
+ */
42
+ private static invNTT;
43
+ /**
44
+ * Multiply
45
+ * @param a {bigint[]} Polygon
46
+ * @param b {bigint[]} Polygon
47
+ * @returns {bigint[]} Multiplied polygons
48
+ */
49
+ static multiply(a: bigint[], b: bigint[]): bigint[];
50
+ /**
51
+ * Serialize polygon
52
+ * @param poly {bigint[]} Polygon
53
+ * @returns {Uint8Array} Polygon buffer
54
+ * @private
55
+ */
56
+ private static serializePoly;
57
+ /**
58
+ * Deserialize Polygon
59
+ * @param bytes {Uint8Array} Polygon buffer
60
+ * @returns {bigint[]} Polygon
61
+ * @private
62
+ */
63
+ private static deserializePoly;
64
+ /**
65
+ * Round to bits
66
+ * @param poly {bigint[]} Polygon
67
+ * @returns {Uint8Array} rounded buffer
68
+ * @private
69
+ */
70
+ private static roundToBits;
71
+ /**
72
+ * Modular exponentiation
73
+ * @param base {bigint} Base
74
+ * @param exp {bigint} exponential
75
+ * @param mod {bigint} module
76
+ * @returns {bigint} Result of modular exponentiation
77
+ * @private
78
+ */
79
+ private static powMod;
80
+ /**
81
+ * Modular inverse
82
+ * @param a {bigint}
83
+ * @param m {bigint}
84
+ * @returns {bigint} Inversion result
85
+ * @private
86
+ */
87
+ private static modInverse;
88
+ /**
89
+ * Generate crypto key pair async
90
+ * @returns {ICryptoKeyPair} Crypto key pair
91
+ * TODO: GPU Calculations
92
+ */
93
+ generateKeyPair(): Promise<ICryptoKeyPair>;
94
+ /**
95
+ * Generate crypto key pair sync
96
+ * @returns {ICryptoKeyPair} Crypto key pair
97
+ */
98
+ generateKeyPairSync(): ICryptoKeyPair;
99
+ /**
100
+ * Encapsulate async
101
+ * @param publicKey {Uint8Array} Public key buffer
102
+ * @returns {Promise<ICryptoEncapsulated>} Encapsulated data
103
+ * TODO: GPU Calculations
104
+ */
105
+ encapsulate(publicKey: Uint8Array): Promise<ICryptoEncapsulated>;
106
+ /**
107
+ * Encapsulate sync
108
+ * @param publicKey {Uint8Array} Public key buffer
109
+ * @returns {ICryptoEncapsulated} Encapsulated data
110
+ */
111
+ encapsulateSync(publicKey: Uint8Array): ICryptoEncapsulated;
112
+ /**
113
+ * Decapsulate async
114
+ * @param privateKey {Uint8Array} Private key buffer
115
+ * @param ciphertext {Uint8Array} Cipher text buffer
116
+ * @returns {Promise<Uint8Array>} Buffer data
117
+ * TODO: GPU Calculations
118
+ */
119
+ decapsulate(privateKey: Uint8Array, ciphertext: Uint8Array): Promise<Uint8Array>;
120
+ /**
121
+ * Decapsulate sync
122
+ * @param privateKey {Uint8Array} Private key buffer
123
+ * @param ciphertext {Uint8Array} Cipher text buffer
124
+ * @returns {Uint8Array} Buffer data
125
+ */
126
+ decapsulateSync(privateKey: Uint8Array, ciphertext: Uint8Array): Uint8Array;
127
+ }
@@ -0,0 +1,69 @@
1
+ /**
2
+ * QuarkDash Crypto Types
3
+ *
4
+ * @git https://github.com/devsdaddy/quarkdash
5
+ * @version 1.0.0
6
+ * @author Elijah Rastorguev
7
+ * @build 1000
8
+ * @website https://dev.to/devsdaddy
9
+ */
10
+ /**
11
+ * Crypto methods async interface
12
+ */
13
+ export interface ICryptoMethodAsync {
14
+ encrypt(decryptedData: Uint8Array): Promise<Uint8Array>;
15
+ decrypt(encryptedData: Uint8Array): Promise<Uint8Array>;
16
+ }
17
+ /**
18
+ * Crypto methods sync interface
19
+ */
20
+ export interface ICryptoMethodSync {
21
+ encryptSync(decryptedData: Uint8Array): Uint8Array;
22
+ decryptSync(encryptedData: Uint8Array): Uint8Array;
23
+ }
24
+ /**
25
+ * Cipher interface
26
+ */
27
+ export interface ICipher extends ICryptoMethodAsync, ICryptoMethodSync {
28
+ }
29
+ /**
30
+ * KDF interface
31
+ */
32
+ export interface IKDF {
33
+ derive(ikm: Uint8Array, salt: Uint8Array, info: Uint8Array, length: number): Promise<Uint8Array>;
34
+ deriveSync(ikm: Uint8Array, salt: Uint8Array, info: Uint8Array, length: number): Uint8Array;
35
+ }
36
+ /**
37
+ * MAC interface
38
+ */
39
+ export interface IMAC {
40
+ sign(data: Uint8Array, key: Uint8Array): Promise<Uint8Array>;
41
+ verify(data: Uint8Array, key: Uint8Array, tag: Uint8Array): Promise<boolean>;
42
+ signSync(data: Uint8Array, key: Uint8Array): Uint8Array;
43
+ verifySync(data: Uint8Array, key: Uint8Array, tag: Uint8Array): boolean;
44
+ }
45
+ /**
46
+ * Key exchange interface
47
+ */
48
+ export interface IKeyExchange {
49
+ generateKeyPair(): Promise<ICryptoKeyPair>;
50
+ generateKeyPairSync(): ICryptoKeyPair;
51
+ encapsulate(publicKey: Uint8Array): Promise<ICryptoEncapsulated>;
52
+ encapsulateSync(publicKey: Uint8Array): ICryptoEncapsulated;
53
+ decapsulate(privateKey: Uint8Array, ciphertext: Uint8Array): Promise<Uint8Array>;
54
+ decapsulateSync(privateKey: Uint8Array, ciphertext: Uint8Array): Uint8Array;
55
+ }
56
+ /**
57
+ * Crypto key pair
58
+ */
59
+ export interface ICryptoKeyPair {
60
+ publicKey: Uint8Array;
61
+ privateKey: Uint8Array;
62
+ }
63
+ /**
64
+ * Crypto encapsulated
65
+ */
66
+ export interface ICryptoEncapsulated {
67
+ ciphertext: Uint8Array;
68
+ sharedSecret: Uint8Array;
69
+ }