@kynesyslabs/demosdk 2.1.15 → 2.2.1
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/build/encryption/PQC/enigma.d.ts +83 -0
- package/build/encryption/PQC/enigma.js +243 -0
- package/build/encryption/PQC/enigma.js.map +1 -0
- package/build/encryption/PQC/falconts/falcon.d.ts +1 -1
- package/build/encryption/PQC/falconts/index.d.ts +1 -0
- package/build/encryption/PQC/{ml-dsa/utils.d.ts → utils.d.ts} +2 -2
- package/build/encryption/PQC/{ml-dsa/utils.js → utils.js} +2 -1
- package/build/encryption/PQC/utils.js.map +1 -0
- package/build/encryption/index.d.ts +2 -1
- package/build/encryption/index.js +4 -2
- package/build/encryption/index.js.map +1 -1
- package/build/encryption/unifiedCrypto.d.ts +125 -0
- package/build/encryption/unifiedCrypto.js +408 -0
- package/build/encryption/unifiedCrypto.js.map +1 -0
- package/build/instant_messaging/index.d.ts +300 -0
- package/build/instant_messaging/index.js +630 -0
- package/build/instant_messaging/index.js.map +1 -0
- package/build/multichain/core/btc.js +5 -1
- package/build/multichain/core/btc.js.map +1 -1
- package/build/utils/uint8Serialize.d.ts +2 -0
- package/build/utils/uint8Serialize.js +22 -0
- package/build/utils/uint8Serialize.js.map +1 -0
- package/package.json +4 -2
- package/build/encryption/PQC/index.d.ts +0 -216
- package/build/encryption/PQC/index.js +0 -520
- package/build/encryption/PQC/index.js.map +0 -1
- package/build/encryption/PQC/ml-dsa/utils.js.map +0 -1
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
export declare class Enigma {
|
|
2
|
+
ml_dsa_signing_keypair: {
|
|
3
|
+
publicKey: Uint8Array;
|
|
4
|
+
privateKey: Uint8Array;
|
|
5
|
+
};
|
|
6
|
+
falcon_signing_keypair: {
|
|
7
|
+
genKey: Uint8Array;
|
|
8
|
+
publicKey: Uint8Array;
|
|
9
|
+
privateKey: Uint8Array;
|
|
10
|
+
};
|
|
11
|
+
ml_kem_encryption_keypair: {
|
|
12
|
+
publicKey: Uint8Array;
|
|
13
|
+
privateKey: Uint8Array;
|
|
14
|
+
};
|
|
15
|
+
ml_kem_aes_parameters: string;
|
|
16
|
+
constructor();
|
|
17
|
+
/**
|
|
18
|
+
* Hashes data using SHA-3-256
|
|
19
|
+
* @param data The data to hash
|
|
20
|
+
* @returns The hash of the data
|
|
21
|
+
*/
|
|
22
|
+
static hash(data: string, algorithm?: string): Promise<Uint8Array>;
|
|
23
|
+
/**
|
|
24
|
+
* Verifies a signature using ml-dsa
|
|
25
|
+
* @param signature The signature to verify
|
|
26
|
+
* @param message The message to verify the signature against
|
|
27
|
+
* @param publicKey The public key to verify the signature against
|
|
28
|
+
* @returns True if the signature is valid, false otherwise
|
|
29
|
+
*/
|
|
30
|
+
static verify_ml_dsa(signature: Uint8Array, message: Uint8Array, publicKey: Uint8Array): Promise<boolean>;
|
|
31
|
+
/**
|
|
32
|
+
* Verifies a signature using falcon
|
|
33
|
+
* @param signature The signature to verify
|
|
34
|
+
* @param message The message to verify the signature against
|
|
35
|
+
* @param publicKey The public key to verify the signature against
|
|
36
|
+
* @returns True if the signature is valid, false otherwise
|
|
37
|
+
*/
|
|
38
|
+
static verify_falcon(signature: Uint8Array, message: string, publicKey: Uint8Array): Promise<boolean>;
|
|
39
|
+
/** Sign data using ml_dsa
|
|
40
|
+
* @param message The message to sign
|
|
41
|
+
* @returns The signature of the message
|
|
42
|
+
*/
|
|
43
|
+
sign_ml_dsa(message: Uint8Array): Promise<Uint8Array>;
|
|
44
|
+
/** Sign data using falcon
|
|
45
|
+
* @param message The message to sign
|
|
46
|
+
* @returns The signature of the message
|
|
47
|
+
*/
|
|
48
|
+
sign_falcon(message: string): Promise<Uint8Array>;
|
|
49
|
+
encapsulate_ml_kem(peerPublicKey: Uint8Array): Promise<{
|
|
50
|
+
cipherText: Uint8Array;
|
|
51
|
+
sharedSecret: Uint8Array;
|
|
52
|
+
}>;
|
|
53
|
+
decapsulate_ml_kem(cipherText: Uint8Array): Promise<Uint8Array>;
|
|
54
|
+
/** Encrypt data using ml_kem + aes
|
|
55
|
+
* @param message The message to encrypt
|
|
56
|
+
* @returns The encrypted message
|
|
57
|
+
*/
|
|
58
|
+
encrypt_ml_kem_aes(message: Uint8Array, peerPublicKey: Uint8Array): Promise<{
|
|
59
|
+
cipherText: Uint8Array;
|
|
60
|
+
encryptedMessage: Uint8Array;
|
|
61
|
+
}>;
|
|
62
|
+
/** Decrypt data using ml_kem + aes
|
|
63
|
+
* @param encryptedMessage The encrypted message to decrypt
|
|
64
|
+
* @param cipherText The cipher text containing the encapsulated shared secret
|
|
65
|
+
* @returns The decrypted message
|
|
66
|
+
*/
|
|
67
|
+
decrypt_ml_kem_aes(encryptedMessage: Uint8Array, cipherText: Uint8Array): Promise<Uint8Array>;
|
|
68
|
+
/**
|
|
69
|
+
* Generates a ml_dsa signing keypair given a seed or creating one
|
|
70
|
+
* @param seed (optional) the seed used to generate the keypair
|
|
71
|
+
*/
|
|
72
|
+
generate_ml_dsa_signing_keypair(seed?: Uint8Array): Promise<void>;
|
|
73
|
+
/**
|
|
74
|
+
* Generates a falcon signing keypair given a seed or creating one
|
|
75
|
+
* @param seed (optional) the seed used to generate the keypair
|
|
76
|
+
*/
|
|
77
|
+
generate_falcon_signing_keypair(seed?: Uint8Array): Promise<void>;
|
|
78
|
+
/**
|
|
79
|
+
* Generates a ml_kem encryption keypair given a seed or creating one
|
|
80
|
+
* @param seed (optional) the seed used to generate the keypair
|
|
81
|
+
*/
|
|
82
|
+
generate_ml_kem_encryption_keypair(seed?: Uint8Array): Promise<void>;
|
|
83
|
+
}
|
|
@@ -0,0 +1,243 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.Enigma = void 0;
|
|
37
|
+
/* INFO Enigma - An experimental wrapper for Post Quantum Cryptography in Typescript designed with ease of use in mind
|
|
38
|
+
Currently suggested and tested schemas for each algorithm are:
|
|
39
|
+
- Signing: ml-dsa or falcon
|
|
40
|
+
- Encryption: NTRU
|
|
41
|
+
- Hashing: SHA-3
|
|
42
|
+
|
|
43
|
+
While implemented, the following algorithms are not included in the pqc test suite:
|
|
44
|
+
- Key Encapsulation: McEliece
|
|
45
|
+
|
|
46
|
+
While implemented, the following algorithms are not fully tested:
|
|
47
|
+
- ChaCha20-Poly1305
|
|
48
|
+
To properly test the encryption and decryption of data, please see the pqc test suite.
|
|
49
|
+
*/
|
|
50
|
+
const ml_kem_1 = require("@noble/post-quantum/ml-kem");
|
|
51
|
+
const ml_dsa_1 = require("@noble/post-quantum/ml-dsa");
|
|
52
|
+
const sha3_1 = require("@noble/hashes/sha3");
|
|
53
|
+
const crypto = __importStar(require("crypto"));
|
|
54
|
+
const falconts_1 = require("./falconts");
|
|
55
|
+
const crypto_1 = require("crypto");
|
|
56
|
+
class Enigma {
|
|
57
|
+
constructor() {
|
|
58
|
+
// ml-dsa signing keypair
|
|
59
|
+
this.ml_dsa_signing_keypair = null;
|
|
60
|
+
// falcon signing keypair
|
|
61
|
+
this.falcon_signing_keypair = null;
|
|
62
|
+
// ml-kem encryption keypair
|
|
63
|
+
this.ml_kem_encryption_keypair = null;
|
|
64
|
+
// ml-kem-aes parameters
|
|
65
|
+
this.ml_kem_aes_parameters = null;
|
|
66
|
+
}
|
|
67
|
+
// Static methods
|
|
68
|
+
/**
|
|
69
|
+
* Hashes data using SHA-3-256
|
|
70
|
+
* @param data The data to hash
|
|
71
|
+
* @returns The hash of the data
|
|
72
|
+
*/
|
|
73
|
+
static async hash(data, algorithm = "sha3-256") {
|
|
74
|
+
// NOTE: algorithm is not used yet, but will be used in the future
|
|
75
|
+
return sha3_1.sha3_256.create().update(data).digest();
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Verifies a signature using ml-dsa
|
|
79
|
+
* @param signature The signature to verify
|
|
80
|
+
* @param message The message to verify the signature against
|
|
81
|
+
* @param publicKey The public key to verify the signature against
|
|
82
|
+
* @returns True if the signature is valid, false otherwise
|
|
83
|
+
*/
|
|
84
|
+
static async verify_ml_dsa(signature, message, publicKey) {
|
|
85
|
+
return ml_dsa_1.ml_dsa65.verify(publicKey, message, signature);
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Verifies a signature using falcon
|
|
89
|
+
* @param signature The signature to verify
|
|
90
|
+
* @param message The message to verify the signature against
|
|
91
|
+
* @param publicKey The public key to verify the signature against
|
|
92
|
+
* @returns True if the signature is valid, false otherwise
|
|
93
|
+
*/
|
|
94
|
+
static async verify_falcon(signature, message, publicKey) {
|
|
95
|
+
const falcon = new falconts_1.Falcon(); // Initialize falcon kernel
|
|
96
|
+
await falcon.init();
|
|
97
|
+
return falcon.verify(message, signature, publicKey);
|
|
98
|
+
}
|
|
99
|
+
// Dynamic methods
|
|
100
|
+
/** Sign data using ml_dsa
|
|
101
|
+
* @param message The message to sign
|
|
102
|
+
* @returns The signature of the message
|
|
103
|
+
*/
|
|
104
|
+
async sign_ml_dsa(message) {
|
|
105
|
+
if (!this.ml_dsa_signing_keypair.privateKey) {
|
|
106
|
+
throw new Error("ml_dsa_signing_keypair.privateKey is not set");
|
|
107
|
+
}
|
|
108
|
+
return ml_dsa_1.ml_dsa65.sign(this.ml_dsa_signing_keypair.privateKey, message);
|
|
109
|
+
}
|
|
110
|
+
/** Sign data using falcon
|
|
111
|
+
* @param message The message to sign
|
|
112
|
+
* @returns The signature of the message
|
|
113
|
+
*/
|
|
114
|
+
async sign_falcon(message) {
|
|
115
|
+
if (!this.falcon_signing_keypair.privateKey) {
|
|
116
|
+
throw new Error("falcon_signing_keypair.privateKey is not set");
|
|
117
|
+
}
|
|
118
|
+
const falcon = new falconts_1.Falcon();
|
|
119
|
+
await falcon.init();
|
|
120
|
+
await falcon.setKeypair({
|
|
121
|
+
genkeySeed: this.falcon_signing_keypair.genKey,
|
|
122
|
+
sk: this.falcon_signing_keypair.privateKey,
|
|
123
|
+
pk: this.falcon_signing_keypair.publicKey,
|
|
124
|
+
});
|
|
125
|
+
return falcon.sign(message);
|
|
126
|
+
}
|
|
127
|
+
async encapsulate_ml_kem(peerPublicKey) {
|
|
128
|
+
if (!this.ml_kem_encryption_keypair.privateKey) {
|
|
129
|
+
throw new Error("ml_kem_encryption_keypair.privateKey is not set");
|
|
130
|
+
}
|
|
131
|
+
return ml_kem_1.ml_kem768.encapsulate(peerPublicKey);
|
|
132
|
+
}
|
|
133
|
+
async decapsulate_ml_kem(cipherText) {
|
|
134
|
+
if (!this.ml_kem_encryption_keypair.privateKey) {
|
|
135
|
+
throw new Error("ml_kem_encryption_keypair.privateKey is not set");
|
|
136
|
+
}
|
|
137
|
+
return ml_kem_1.ml_kem768.decapsulate(cipherText, this.ml_kem_encryption_keypair.privateKey);
|
|
138
|
+
}
|
|
139
|
+
/** Encrypt data using ml_kem + aes
|
|
140
|
+
* @param message The message to encrypt
|
|
141
|
+
* @returns The encrypted message
|
|
142
|
+
*/
|
|
143
|
+
async encrypt_ml_kem_aes(message, peerPublicKey) {
|
|
144
|
+
if (!this.ml_kem_encryption_keypair.privateKey) {
|
|
145
|
+
throw new Error("ml_kem_encryption_keypair.privateKey is not set");
|
|
146
|
+
}
|
|
147
|
+
// Generate shared secret and encapsulate it in a cipher text using ml_kem and the peer's public key
|
|
148
|
+
const encapsulatedSecret = ml_kem_1.ml_kem768.encapsulate(peerPublicKey);
|
|
149
|
+
// Encrypt the message using AES-256-GCM with the shared secret
|
|
150
|
+
const iv = crypto.randomBytes(12); // 96-bit IV for GCM mode
|
|
151
|
+
const cipher = crypto.createCipheriv("aes-256-gcm", encapsulatedSecret.sharedSecret, iv);
|
|
152
|
+
// Encrypt the message
|
|
153
|
+
const encryptedMessage = Buffer.concat([
|
|
154
|
+
cipher.update(message),
|
|
155
|
+
cipher.final(),
|
|
156
|
+
]);
|
|
157
|
+
// Get the authentication tag
|
|
158
|
+
const authTag = cipher.getAuthTag();
|
|
159
|
+
// Combine IV, encrypted message, and auth tag for transmission
|
|
160
|
+
const combinedEncryptedData = Buffer.concat([
|
|
161
|
+
iv,
|
|
162
|
+
encryptedMessage,
|
|
163
|
+
authTag,
|
|
164
|
+
]);
|
|
165
|
+
return {
|
|
166
|
+
cipherText: encapsulatedSecret.cipherText,
|
|
167
|
+
encryptedMessage: combinedEncryptedData,
|
|
168
|
+
};
|
|
169
|
+
}
|
|
170
|
+
/** Decrypt data using ml_kem + aes
|
|
171
|
+
* @param encryptedMessage The encrypted message to decrypt
|
|
172
|
+
* @param cipherText The cipher text containing the encapsulated shared secret
|
|
173
|
+
* @returns The decrypted message
|
|
174
|
+
*/
|
|
175
|
+
async decrypt_ml_kem_aes(encryptedMessage, cipherText) {
|
|
176
|
+
if (!this.ml_kem_encryption_keypair.privateKey) {
|
|
177
|
+
throw new Error("ml_kem_encryption_keypair.privateKey is not set");
|
|
178
|
+
}
|
|
179
|
+
// Get the shared secret from the cipher text
|
|
180
|
+
const sharedSecret = ml_kem_1.ml_kem768.decapsulate(cipherText, this.ml_kem_encryption_keypair.privateKey);
|
|
181
|
+
// Decrypt the message using AES-256-GCM with the shared secret
|
|
182
|
+
const iv = encryptedMessage.slice(0, 12);
|
|
183
|
+
const message = encryptedMessage.slice(12, -16);
|
|
184
|
+
const authTag = encryptedMessage.slice(-16);
|
|
185
|
+
// Decrypt the message
|
|
186
|
+
const decipher = crypto.createDecipheriv("aes-256-gcm", sharedSecret, iv);
|
|
187
|
+
decipher.setAuthTag(authTag);
|
|
188
|
+
const decryptedMessage = Buffer.concat([
|
|
189
|
+
decipher.update(message),
|
|
190
|
+
decipher.final(),
|
|
191
|
+
]);
|
|
192
|
+
return decryptedMessage;
|
|
193
|
+
}
|
|
194
|
+
// Keypair generation methods
|
|
195
|
+
/**
|
|
196
|
+
* Generates a ml_dsa signing keypair given a seed or creating one
|
|
197
|
+
* @param seed (optional) the seed used to generate the keypair
|
|
198
|
+
*/
|
|
199
|
+
async generate_ml_dsa_signing_keypair(seed = null) {
|
|
200
|
+
if (!seed) {
|
|
201
|
+
seed = (0, crypto_1.randomBytes)(32);
|
|
202
|
+
}
|
|
203
|
+
const keypair = ml_dsa_1.ml_dsa65.keygen(seed);
|
|
204
|
+
this.ml_dsa_signing_keypair = {
|
|
205
|
+
publicKey: keypair.publicKey,
|
|
206
|
+
privateKey: keypair.secretKey,
|
|
207
|
+
};
|
|
208
|
+
}
|
|
209
|
+
/**
|
|
210
|
+
* Generates a falcon signing keypair given a seed or creating one
|
|
211
|
+
* @param seed (optional) the seed used to generate the keypair
|
|
212
|
+
*/
|
|
213
|
+
async generate_falcon_signing_keypair(seed = null) {
|
|
214
|
+
if (!seed) {
|
|
215
|
+
seed = (0, crypto_1.randomBytes)(48);
|
|
216
|
+
}
|
|
217
|
+
const falcon = new falconts_1.Falcon();
|
|
218
|
+
await falcon.init();
|
|
219
|
+
await falcon.genkey(seed);
|
|
220
|
+
const falconKeyPair = await falcon.getKeypair();
|
|
221
|
+
this.falcon_signing_keypair = {
|
|
222
|
+
genKey: falconKeyPair.genkeySeed,
|
|
223
|
+
publicKey: falconKeyPair.pk,
|
|
224
|
+
privateKey: falconKeyPair.sk,
|
|
225
|
+
};
|
|
226
|
+
}
|
|
227
|
+
/**
|
|
228
|
+
* Generates a ml_kem encryption keypair given a seed or creating one
|
|
229
|
+
* @param seed (optional) the seed used to generate the keypair
|
|
230
|
+
*/
|
|
231
|
+
async generate_ml_kem_encryption_keypair(seed = null) {
|
|
232
|
+
if (!seed) {
|
|
233
|
+
seed = (0, crypto_1.randomBytes)(64);
|
|
234
|
+
}
|
|
235
|
+
let keys = ml_kem_1.ml_kem768.keygen(seed);
|
|
236
|
+
this.ml_kem_encryption_keypair = {
|
|
237
|
+
privateKey: keys.secretKey,
|
|
238
|
+
publicKey: keys.publicKey,
|
|
239
|
+
};
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
exports.Enigma = Enigma;
|
|
243
|
+
//# sourceMappingURL=enigma.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"enigma.js","sourceRoot":"","sources":["../../../../src/encryption/PQC/enigma.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;;;;EAYE;AACF,uDAAsD;AACtD,uDAAqD;AACrD,6CA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1B,MAAM,EAAE,aAAa,CAAC,UAAU;YAChC,SAAS,EAAE,aAAa,CAAC,EAAE;YAC3B,UAAU,EAAE,aAAa,CAAC,EAAE;SAC/B,CAAA;IACL,CAAC;IAED;;;OAGG;IACH,KAAK,CAAC,kCAAkC,CACpC,OAAmB,IAAI;QAEvB,IAAI,CAAC,IAAI,EAAE,CAAC;YACR,IAAI,GAAG,IAAA,oBAAW,EAAC,EAAE,CAAC,CAAA;QAC1B,CAAC;QACD,IAAI,IAAI,GAAG,kBAAS,CAAC,MAAM,CAAC,IAAI,CAAC,CAAA;QACjC,IAAI,CAAC,yBAAyB,GAAG;YAC7B,UAAU,EAAE,IAAI,CAAC,SAAS;YAC1B,SAAS,EAAE,IAAI,CAAC,SAAS;SAC5B,CAAA;IACL,CAAC;CACJ;AA/PD,wBA+PC"}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { utf8ToBytes } from '@noble/hashes/utils';
|
|
1
|
+
import { utf8ToBytes, randomBytes } from '@noble/hashes/utils';
|
|
2
2
|
/**
|
|
3
3
|
* Converts a Uint8Array to a hex string
|
|
4
4
|
* @param bytes The Uint8Array to convert
|
|
5
5
|
* @returns The hex string representation of the Uint8Array
|
|
6
6
|
*/
|
|
7
7
|
declare function bytesToUtf8(bytes: Uint8Array): string;
|
|
8
|
-
export { utf8ToBytes, bytesToUtf8 };
|
|
8
|
+
export { utf8ToBytes, bytesToUtf8, randomBytes };
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.utf8ToBytes = void 0;
|
|
3
|
+
exports.randomBytes = exports.utf8ToBytes = void 0;
|
|
4
4
|
exports.bytesToUtf8 = bytesToUtf8;
|
|
5
5
|
const utils_1 = require("@noble/hashes/utils");
|
|
6
6
|
Object.defineProperty(exports, "utf8ToBytes", { enumerable: true, get: function () { return utils_1.utf8ToBytes; } });
|
|
7
|
+
Object.defineProperty(exports, "randomBytes", { enumerable: true, get: function () { return utils_1.randomBytes; } });
|
|
7
8
|
/**
|
|
8
9
|
* Converts a Uint8Array to a hex string
|
|
9
10
|
* @param bytes The Uint8Array to convert
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../../src/encryption/PQC/utils.ts"],"names":[],"mappings":";;;AAUsB,kCAAW;AAVjC,+CAA+D;AAUtD,4FAVA,mBAAW,OAUA;AAAe,4FAVb,mBAAW,OAUa;AAT9C;;;;GAIG;AACH,SAAS,WAAW,CAAC,KAAiB;IAClC,OAAO,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;AACzC,CAAC"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export * as FHE from './FHE';
|
|
2
|
-
export * as PQC from './PQC';
|
|
2
|
+
export * as PQC from './PQC/enigma';
|
|
3
3
|
export * as zK from './zK';
|
|
4
4
|
export { Cryptography } from './Cryptography';
|
|
5
5
|
export { Hashing } from './Hashing';
|
|
6
|
+
export { unifiedCrypto as ucrypto } from './unifiedCrypto';
|
|
@@ -33,12 +33,14 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
33
33
|
};
|
|
34
34
|
})();
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
-
exports.Hashing = exports.Cryptography = exports.zK = exports.PQC = exports.FHE = void 0;
|
|
36
|
+
exports.ucrypto = exports.Hashing = exports.Cryptography = exports.zK = exports.PQC = exports.FHE = void 0;
|
|
37
37
|
exports.FHE = __importStar(require("./FHE"));
|
|
38
|
-
exports.PQC = __importStar(require("./PQC"));
|
|
38
|
+
exports.PQC = __importStar(require("./PQC/enigma"));
|
|
39
39
|
exports.zK = __importStar(require("./zK"));
|
|
40
40
|
var Cryptography_1 = require("./Cryptography");
|
|
41
41
|
Object.defineProperty(exports, "Cryptography", { enumerable: true, get: function () { return Cryptography_1.Cryptography; } });
|
|
42
42
|
var Hashing_1 = require("./Hashing");
|
|
43
43
|
Object.defineProperty(exports, "Hashing", { enumerable: true, get: function () { return Hashing_1.Hashing; } });
|
|
44
|
+
var unifiedCrypto_1 = require("./unifiedCrypto");
|
|
45
|
+
Object.defineProperty(exports, "ucrypto", { enumerable: true, get: function () { return unifiedCrypto_1.unifiedCrypto; } });
|
|
44
46
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/encryption/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,6CAA4B;AAC5B,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/encryption/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,6CAA4B;AAC5B,oDAAmC;AACnC,2CAA0B;AAE1B,+CAA6C;AAApC,4GAAA,YAAY,OAAA;AACrB,qCAAmC;AAA1B,kGAAA,OAAO,OAAA;AAChB,iDAA0D;AAAjD,wGAAA,aAAa,OAAW"}
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import { Enigma } from "./PQC/enigma";
|
|
2
|
+
import * as forge from "node-forge";
|
|
3
|
+
export interface encryptedObject {
|
|
4
|
+
algorithm: "ml-kem-aes" | "rsa";
|
|
5
|
+
encryptedData: Uint8Array;
|
|
6
|
+
cipherText?: Uint8Array;
|
|
7
|
+
}
|
|
8
|
+
export interface SerializedEncryptedObject {
|
|
9
|
+
algorithm: "ml-kem-aes" | "rsa";
|
|
10
|
+
serializedEncryptedData: string;
|
|
11
|
+
serializedCipherText?: string;
|
|
12
|
+
}
|
|
13
|
+
export interface SerializedSignedObject {
|
|
14
|
+
algorithm: "ml-dsa" | "falcon" | "ed25519";
|
|
15
|
+
serializedSignedData: string;
|
|
16
|
+
serializedPublicKey: string;
|
|
17
|
+
serializedMessage: string;
|
|
18
|
+
}
|
|
19
|
+
interface Ed25519SignedObject {
|
|
20
|
+
algorithm: "ed25519";
|
|
21
|
+
signedData: Uint8Array;
|
|
22
|
+
publicKey: forge.pki.ed25519.NativeBuffer;
|
|
23
|
+
message: Uint8Array;
|
|
24
|
+
}
|
|
25
|
+
interface PqcSignedObject {
|
|
26
|
+
algorithm: "ml-dsa" | "falcon";
|
|
27
|
+
signedData: Uint8Array;
|
|
28
|
+
publicKey: Uint8Array;
|
|
29
|
+
message: Uint8Array;
|
|
30
|
+
}
|
|
31
|
+
export type signedObject = Ed25519SignedObject | PqcSignedObject;
|
|
32
|
+
/**
|
|
33
|
+
* Converts a Uint8Array to a hexadecimal string representation, prefixed with '0x'.
|
|
34
|
+
*
|
|
35
|
+
* @param bytes - The Uint8Array to convert.
|
|
36
|
+
* @returns The hexadecimal string representation (e.g., "0x0a1b2c").
|
|
37
|
+
*/
|
|
38
|
+
export declare function uint8ArrayToHex(bytes: Uint8Array): string;
|
|
39
|
+
/**
|
|
40
|
+
* Converts a hexadecimal string (with or without '0x' prefix) to a Uint8Array.
|
|
41
|
+
*
|
|
42
|
+
* @param hexString - The hexadecimal string to convert (e.g., "0x0a1b2c" or "0a1b2c").
|
|
43
|
+
* @returns The corresponding Uint8Array.
|
|
44
|
+
* @throws {Error} If the input string (after removing '0x') has an odd length
|
|
45
|
+
* or contains non-hexadecimal characters.
|
|
46
|
+
*/
|
|
47
|
+
export declare function hexToUint8Array(hexString: string): Uint8Array;
|
|
48
|
+
/**
|
|
49
|
+
* UnifiedCrypto is a class that provides a unified interface for the different encryption algorithms
|
|
50
|
+
* It is used to encrypt and decrypt messages, sign and verify messages, and generate identities for the different algorithms
|
|
51
|
+
* It uses Enigma for PQC encryption/decryption and Cryptography for RSA encryption/decryption
|
|
52
|
+
* It uses Enigma for PQC signing and Cryptography for Ed25519 signing
|
|
53
|
+
* It uses the master seed to derive seeds for the different algorithms using HKDF
|
|
54
|
+
* Manages encryptedObjects and signedObjects to route data through the supported algorithms
|
|
55
|
+
* REVIEW: Check race conditions
|
|
56
|
+
* REVIEW: Check stability of the master seed transformation
|
|
57
|
+
* TODO: Build a test suite for the UnifiedCrypto class
|
|
58
|
+
*/
|
|
59
|
+
export declare class UnifiedCrypto {
|
|
60
|
+
private static instances;
|
|
61
|
+
private static DEFAULT_INSTANCE_ID;
|
|
62
|
+
enigma: Enigma;
|
|
63
|
+
ed25519KeyPair: {
|
|
64
|
+
publicKey: forge.pki.ed25519.NativeBuffer;
|
|
65
|
+
privateKey: forge.pki.ed25519.NativeBuffer;
|
|
66
|
+
};
|
|
67
|
+
rsaKeyPair: forge.pki.rsa.KeyPair;
|
|
68
|
+
masterSeed: Uint8Array;
|
|
69
|
+
private instanceId;
|
|
70
|
+
private constructor();
|
|
71
|
+
static getInstance(instanceId?: string, masterSeed?: Uint8Array): UnifiedCrypto;
|
|
72
|
+
getId(): string;
|
|
73
|
+
static getInstanceIds(): string[];
|
|
74
|
+
static removeInstance(instanceId: string): boolean;
|
|
75
|
+
/**
|
|
76
|
+
* Ensures that the master seed is set and generates a new one if not set
|
|
77
|
+
* @param masterSeed (optional) The master seed to set, or undefined to generate a new one
|
|
78
|
+
*/
|
|
79
|
+
ensureSeed(masterSeed?: Uint8Array): Promise<void>;
|
|
80
|
+
/**
|
|
81
|
+
* Derives a seed for the given algorithm
|
|
82
|
+
* @param algorithm The algorithm to derive the seed for
|
|
83
|
+
* @param seed (optional) The seed to derive the seed from, or undefined to generate a new one or use the master seed if set
|
|
84
|
+
* @returns The derived seed
|
|
85
|
+
*/
|
|
86
|
+
deriveSeed(algorithm: "ed25519" | "falcon" | "ml-dsa" | "ml-kem-aes" | "rsa", seed?: Uint8Array): Promise<Uint8Array>;
|
|
87
|
+
generateAllIdentities(masterSeed?: Uint8Array): Promise<void>;
|
|
88
|
+
generateIdentity(algorithm: "ed25519" | "falcon" | "ml-dsa" | "ml-kem-aes" | "rsa", masterSeed?: Uint8Array): Promise<void>;
|
|
89
|
+
getIdentity(algorithm: "ed25519" | "falcon" | "ml-dsa" | "ml-kem-aes" | "rsa"): Promise<{
|
|
90
|
+
publicKey: Uint8Array | forge.pki.rsa.PublicKey | forge.pki.ed25519.NativeBuffer;
|
|
91
|
+
privateKey: Uint8Array | forge.pki.rsa.PrivateKey | forge.pki.ed25519.NativeBuffer;
|
|
92
|
+
genKey?: Uint8Array;
|
|
93
|
+
}>;
|
|
94
|
+
/**
|
|
95
|
+
* Encrypts a message based on the algorithm using the previously generated identity
|
|
96
|
+
* @param algorithm The algorithm to encrypt the message with
|
|
97
|
+
* @param data The message to encrypt
|
|
98
|
+
* @param peerPublicKey The public key of the peer to encrypt the message to
|
|
99
|
+
* @returns The encrypted object as an encryptedObject
|
|
100
|
+
*/
|
|
101
|
+
encrypt(algorithm: "ml-kem-aes" | "rsa", data: Uint8Array, peerPublicKey: Uint8Array): Promise<encryptedObject>;
|
|
102
|
+
/**
|
|
103
|
+
* Signs a message based on the algorithm using the previously generated identity
|
|
104
|
+
* @param algorithm The algorithm to sign the message with
|
|
105
|
+
* @param data The message to sign
|
|
106
|
+
* @returns The signed object as a signedObject
|
|
107
|
+
*/
|
|
108
|
+
sign(algorithm: "ml-dsa" | "falcon" | "ed25519", data: Uint8Array): Promise<signedObject>;
|
|
109
|
+
/**
|
|
110
|
+
* Decrypts an encrypted object based on the algorithm
|
|
111
|
+
* @param encryptedObject The encrypted object to decrypt
|
|
112
|
+
* @returns The decrypted data
|
|
113
|
+
*/
|
|
114
|
+
decrypt(encryptedObject: encryptedObject): Promise<Uint8Array>;
|
|
115
|
+
/**
|
|
116
|
+
* Verifies a signed object based on the algorithm
|
|
117
|
+
* @param signedObject The signed object to verify
|
|
118
|
+
* @returns True if the signed object is valid, false otherwise
|
|
119
|
+
* @throws Error if publicKey is not in the expected format for the algorithm
|
|
120
|
+
*/
|
|
121
|
+
verify(signedObject: signedObject): Promise<boolean>;
|
|
122
|
+
}
|
|
123
|
+
export declare const unifiedCrypto: UnifiedCrypto & typeof UnifiedCrypto;
|
|
124
|
+
export declare function getUnifiedCryptoInstance(instanceId: string, masterSeed?: Uint8Array): UnifiedCrypto;
|
|
125
|
+
export {};
|