Skip to content

Commit 607993e

Browse files
authored
Merge pull request #1 from BackendStack21/fixing-nodejs-build
Fixing Node.js build compatibility
2 parents 9494be8 + b386617 commit 607993e

15 files changed

Lines changed: 128 additions & 77 deletions

File tree

examples/minimal.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// Minimal example to test Node.js compatibility
2+
import { kemGenerateKeyPair, encapsulate, decapsulate } from '../lib/index.js';
3+
4+
console.log('Testing kMOSAIC with Node.js...');
5+
6+
async function main() {
7+
try {
8+
// Generate a key pair
9+
const keyPair = await kemGenerateKeyPair();
10+
console.log('✓ Key pair generated');
11+
12+
// Encapsulate a shared secret
13+
const { ciphertext, sharedSecret: senderSecret } = await encapsulate(keyPair.publicKey);
14+
console.log('✓ Shared secret encapsulated');
15+
16+
// Decapsulate the shared secret
17+
const receiverSecret = await decapsulate(ciphertext, keyPair.secretKey, keyPair.publicKey);
18+
console.log('✓ Shared secret decapsulated');
19+
20+
// Verify the secrets match
21+
const secretsMatch = senderSecret.every((byte, i) => byte === receiverSecret[i]);
22+
console.log(`✓ Secrets match: ${secretsMatch}`);
23+
24+
console.log('\n✅ All tests passed! Node.js compatibility confirmed.');
25+
} catch (error) {
26+
console.error('❌ Error:', error.message);
27+
process.exit(1);
28+
}
29+
}
30+
31+
main();

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "k-mosaic",
3-
"version": "1.0.0",
3+
"version": "1.0.1",
44
"description": "kMOSAIC: A Novel Post-Quantum Cryptographic Algorithm with Heterogeneous Hardness",
55
"type": "module",
66
"main": "lib/index.js",

src/core/params.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
* - EGRW: O(k) for path computation - FASTEST
1414
*/
1515

16-
import { type MOSAICParams, SecurityLevel } from '../types'
16+
import { type MOSAICParams, SecurityLevel } from '../types.js'
1717

1818
/**
1919
* MOS-128: 128-bit post-quantum security

src/entanglement/index.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,14 @@
1212
* - NIZK: Zero-knowledge via Fiat-Shamir with domain separation
1313
*/
1414

15-
import { shake256, hashConcat, hashWithDomain, sha3_256 } from '../utils/shake'
16-
import { secureRandomBytes } from '../utils/random'
17-
import { constantTimeEqual, zeroize } from '../utils/constant-time'
15+
import {
16+
shake256,
17+
hashConcat,
18+
hashWithDomain,
19+
sha3_256,
20+
} from '../utils/shake.js'
21+
import { secureRandomBytes } from '../utils/random.js'
22+
import { constantTimeEqual, zeroize } from '../utils/constant-time.js'
1823

1924
// Domain separation constants for security
2025
const DOMAIN_SHARE = 'kmosaic-share-v1'

src/index.ts

Lines changed: 39 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,13 @@
2121
* @version 0.1.0
2222
*/
2323

24-
import { SecurityLevel } from './types'
24+
import { SecurityLevel } from './types.js'
2525

2626
// =============================================================================
2727
// Core Types
2828
// =============================================================================
2929

30-
export { SecurityLevel } from './types'
30+
export { SecurityLevel } from './types.js'
3131
export type {
3232
MOSAICParams,
3333
SLSSParams,
@@ -45,13 +45,13 @@ export type {
4545
EGRWPublicKey,
4646
EGRWSecretKey,
4747
SL2Element,
48-
} from './types'
48+
} from './types.js'
4949

5050
// =============================================================================
5151
// Core Parameters
5252
// =============================================================================
5353

54-
export { getParams, validateParams, MOS_128, MOS_256 } from './core/params'
54+
export { getParams, validateParams, MOS_128, MOS_256 } from './core/params.js'
5555

5656
// =============================================================================
5757
// KEM (Key Encapsulation Mechanism)
@@ -69,7 +69,7 @@ export {
6969
serializeCiphertext,
7070
deserializeCiphertext,
7171
analyzePublicKey,
72-
} from './kem/index'
72+
} from './kem/index.js'
7373

7474
// =============================================================================
7575
// Digital Signatures
@@ -82,7 +82,7 @@ export {
8282
verify,
8383
serializeSignature,
8484
deserializeSignature,
85-
} from './sign/index'
85+
} from './sign/index.js'
8686

8787
// =============================================================================
8888
// Utilities
@@ -93,16 +93,21 @@ export {
9393
sampleGaussianVector,
9494
randomSparseVector,
9595
randomVectorZq,
96-
} from './utils/random'
96+
} from './utils/random.js'
9797

98-
export { shake256, sha3_256, hashConcat, hashWithDomain } from './utils/shake'
98+
export {
99+
shake256,
100+
sha3_256,
101+
hashConcat,
102+
hashWithDomain,
103+
} from './utils/shake.js'
99104

100105
export {
101106
constantTimeEqual,
102107
constantTimeSelect,
103108
zeroize,
104109
SecureBuffer,
105-
} from './utils/constant-time'
110+
} from './utils/constant-time.js'
106111

107112
// =============================================================================
108113
// Entanglement & Proofs
@@ -116,7 +121,7 @@ export {
116121
verifyCommitment,
117122
generateNIZKProof,
118123
verifyNIZKProof,
119-
} from './entanglement/index'
124+
} from './entanglement/index.js'
120125

121126
// =============================================================================
122127
// Individual Problem Implementations (Advanced Usage)
@@ -128,15 +133,15 @@ export {
128133
slssDecrypt,
129134
slssSerializePublicKey,
130135
slssDeserializePublicKey,
131-
} from './problems/slss/index'
136+
} from './problems/slss/index.js'
132137

133138
export {
134139
tddKeyGen,
135140
tddEncrypt,
136141
tddDecrypt,
137142
tddSerializePublicKey,
138143
tddDeserializePublicKey,
139-
} from './problems/tdd/index'
144+
} from './problems/tdd/index.js'
140145

141146
export {
142147
egrwKeyGen,
@@ -146,7 +151,7 @@ export {
146151
egrwDeserializePublicKey,
147152
bytesToSl2,
148153
sl2ToBytes,
149-
} from './problems/egrw/index'
154+
} from './problems/egrw/index.js'
150155

151156
// =============================================================================
152157
// Convenience API
@@ -167,45 +172,45 @@ const crypto = {
167172
// KEM operations
168173
kem: {
169174
generateKeyPair: () =>
170-
import('./kem/index').then((m) => m.generateKeyPair()),
171-
encapsulate: (pk: import('./types').MOSAICPublicKey) =>
172-
import('./kem/index').then((m) => m.encapsulate(pk)),
175+
import('./kem/index.js').then((m) => m.generateKeyPair()),
176+
encapsulate: (pk: import('./types.js').MOSAICPublicKey) =>
177+
import('./kem/index.js').then((m) => m.encapsulate(pk)),
173178
decapsulate: (
174-
ct: import('./types').MOSAICCiphertext,
175-
sk: import('./types').MOSAICSecretKey,
176-
pk: import('./types').MOSAICPublicKey,
177-
) => import('./kem/index').then((m) => m.decapsulate(ct, sk, pk)),
178-
encrypt: (message: Uint8Array, pk: import('./types').MOSAICPublicKey) =>
179-
import('./kem/index').then((m) => m.encrypt(message, pk)),
179+
ct: import('./types.js').MOSAICCiphertext,
180+
sk: import('./types.js').MOSAICSecretKey,
181+
pk: import('./types.js').MOSAICPublicKey,
182+
) => import('./kem/index.js').then((m) => m.decapsulate(ct, sk, pk)),
183+
encrypt: (message: Uint8Array, pk: import('./types.js').MOSAICPublicKey) =>
184+
import('./kem/index.js').then((m) => m.encrypt(message, pk)),
180185
decrypt: (
181186
ciphertext: Uint8Array,
182-
sk: import('./types').MOSAICSecretKey,
183-
pk: import('./types').MOSAICPublicKey,
184-
) => import('./kem/index').then((m) => m.decrypt(ciphertext, sk, pk)),
187+
sk: import('./types.js').MOSAICSecretKey,
188+
pk: import('./types.js').MOSAICPublicKey,
189+
) => import('./kem/index.js').then((m) => m.decrypt(ciphertext, sk, pk)),
185190
},
186191

187192
// Signature operations
188193
sign: {
189194
generateKeyPair: () =>
190-
import('./sign/index').then((m) => m.generateKeyPair()),
195+
import('./sign/index.js').then((m) => m.generateKeyPair()),
191196
sign: (
192197
message: Uint8Array,
193-
sk: import('./types').MOSAICSecretKey,
194-
pk: import('./types').MOSAICPublicKey,
195-
) => import('./sign/index').then((m) => m.sign(message, sk, pk)),
198+
sk: import('./types.js').MOSAICSecretKey,
199+
pk: import('./types.js').MOSAICPublicKey,
200+
) => import('./sign/index.js').then((m) => m.sign(message, sk, pk)),
196201
verify: (
197202
message: Uint8Array,
198-
sig: import('./types').MOSAICSignature,
199-
pk: import('./types').MOSAICPublicKey,
200-
) => import('./sign/index').then((m) => m.verify(message, sig, pk)),
203+
sig: import('./types.js').MOSAICSignature,
204+
pk: import('./types.js').MOSAICPublicKey,
205+
) => import('./sign/index.js').then((m) => m.verify(message, sig, pk)),
201206
},
202207

203208
// Parameter sets
204209
params: {
205210
[SecurityLevel.MOS_128]: () =>
206-
import('./core/params').then((m) => m.MOS_128),
211+
import('./core/params.js').then((m) => m.MOS_128),
207212
[SecurityLevel.MOS_256]: () =>
208-
import('./core/params').then((m) => m.MOS_256),
213+
import('./core/params.js').then((m) => m.MOS_256),
209214
},
210215
}
211216

src/kem/index.ts

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,38 +25,43 @@ import {
2525
type MOSAICCiphertext,
2626
type EncapsulationResult,
2727
type SecurityAnalysis,
28-
} from '../types'
28+
} from '../types.js'
2929

30-
import { getParams, validateParams } from '../core/params'
31-
import { shake256, hashConcat, hashWithDomain, sha3_256 } from '../utils/shake'
32-
import { secureRandomBytes, validateSeedEntropy } from '../utils/random'
30+
import { getParams, validateParams } from '../core/params.js'
31+
import {
32+
shake256,
33+
hashConcat,
34+
hashWithDomain,
35+
sha3_256,
36+
} from '../utils/shake.js'
37+
import { secureRandomBytes, validateSeedEntropy } from '../utils/random.js'
3338
import {
3439
constantTimeEqual,
3540
constantTimeSelect,
3641
zeroize,
37-
} from '../utils/constant-time'
42+
} from '../utils/constant-time.js'
3843

3944
import {
4045
slssKeyGen,
4146
slssEncrypt,
4247
slssDecrypt,
4348
slssSerializePublicKey,
44-
} from '../problems/slss/index'
49+
} from '../problems/slss/index.js'
4550

4651
import {
4752
tddKeyGen,
4853
tddEncrypt,
4954
tddDecrypt,
5055
tddSerializePublicKey,
51-
} from '../problems/tdd/index'
56+
} from '../problems/tdd/index.js'
5257

5358
import {
5459
egrwKeyGen,
5560
egrwEncrypt,
5661
egrwDecrypt,
5762
egrwSerializePublicKey,
5863
sl2ToBytes,
59-
} from '../problems/egrw/index'
64+
} from '../problems/egrw/index.js'
6065

6166
import {
6267
secretShareDeterministic,
@@ -66,7 +71,7 @@ import {
6671
verifyNIZKProof,
6772
serializeNIZKProof,
6873
deserializeNIZKProof,
69-
} from '../entanglement/index'
74+
} from '../entanglement/index.js'
7075

7176
// Domain separation constants for security
7277
const DOMAIN_SLSS = 'kmosaic-kem-slss-v1'

src/problems/egrw/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ import type {
2424
EGRWSecretKey,
2525
EGRWCiphertext,
2626
SL2Element,
27-
} from '../../types'
28-
import { shake256, hashWithDomain, hashConcat } from '../../utils/shake'
27+
} from '../../types.js'
28+
import { shake256, hashWithDomain, hashConcat } from '../../utils/shake.js'
2929

3030
// Domain separation constants
3131
const DOMAIN_START = 'kmosaic-egrw-start-v1'

src/problems/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22
* Problems module exports
33
*/
44

5-
export * from './slss/index'
6-
export * from './tdd/index'
7-
export * from './egrw/index'
5+
export * from './slss/index.js'
6+
export * from './tdd/index.js'
7+
export * from './egrw/index.js'

src/problems/slss/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ import type {
2222
SLSSPublicKey,
2323
SLSSSecretKey,
2424
SLSSCiphertext,
25-
} from '../../types'
26-
import { shake256, hashWithDomain } from '../../utils/shake'
27-
import { zeroize } from '../../utils/constant-time'
25+
} from '../../types.js'
26+
import { shake256, hashWithDomain } from '../../utils/shake.js'
27+
import { zeroize } from '../../utils/constant-time.js'
2828

2929
// Domain separation constants (versioned for future-proofing)
3030
const DOMAIN_MATRIX = 'kmosaic-slss-matrix-v1'

src/problems/tdd/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ import type {
2323
TDDPublicKey,
2424
TDDSecretKey,
2525
TDDCiphertext,
26-
} from '../../types'
27-
import { shake256, hashWithDomain, hashConcat } from '../../utils/shake'
28-
import { zeroize } from '../../utils/constant-time'
26+
} from '../../types.js'
27+
import { shake256, hashWithDomain, hashConcat } from '../../utils/shake.js'
28+
import { zeroize } from '../../utils/constant-time.js'
2929

3030
// Domain separation constants (versioned for future-proofing)
3131
const DOMAIN_FACTORS = 'kmosaic-tdd-factors-v1'

0 commit comments

Comments
 (0)