Skip to content

Commit 09cdb3e

Browse files
authored
Merge pull request #23 from jbride/nodejs
removed reference to Falcon in npm packages
2 parents c609824 + fd11cd9 commit 09cdb3e

File tree

13 files changed

+311
-285
lines changed

13 files changed

+311
-285
lines changed

nodejs/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,5 @@ coverage/
2121
.vscode/
2222
*.swp
2323
*.swo
24+
25+
c_sources

nodejs/README.md

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,9 @@ TypeScript bindings for the [libbitcoinpqc](https://github.com/bitcoin/libbitcoi
77
- Full TypeScript support with typings
88
- Clean, ergonomic API
99
- Compatible with NodeJS 16+
10-
- Works with all three PQC algorithms:
10+
- Works with both PQC algorithms:
1111
- ML-DSA-44 (formerly CRYSTALS-Dilithium)
1212
- SLH-DSA-Shake-128s (formerly SPHINCS+)
13-
- FN-DSA-512 (formerly FALCON)
1413

1514
## Installation
1615

@@ -58,12 +57,10 @@ verify(keypair.publicKey, message, signature.bytes);
5857
enum Algorithm {
5958
/** BIP-340 Schnorr + X-Only - Elliptic Curve Digital Signature Algorithm */
6059
SECP256K1_SCHNORR = 0,
61-
/** FN-DSA-512 (FALCON) - Fast Fourier lattice-based signature scheme */
62-
FN_DSA_512 = 1,
6360
/** ML-DSA-44 (CRYSTALS-Dilithium) - Lattice-based signature scheme */
64-
ML_DSA_44 = 2,
61+
ML_DSA_44 = 1,
6562
/** SLH-DSA-Shake-128s (SPHINCS+) - Hash-based signature scheme */
66-
SLH_DSA_SHAKE_128S = 3
63+
SLH_DSA_SHAKE_128S = 2
6764
}
6865
```
6966

@@ -150,11 +147,10 @@ Verify a signature using the specified public key. Throws a `PqcError` if verifi
150147

151148
## Algorithm Characteristics
152149

153-
| Algorithm | Public Key Size | Secret Key Size | Signature Size | Security Level |
154-
|-----------|----------------|----------------|----------------|----------------|
155-
| ML-DSA-44 | 1,312 bytes | 2,528 bytes | 2,420 bytes | NIST Level 2 |
156-
| SLH-DSA-Shake-128s | 32 bytes | 64 bytes | 7,856 bytes | NIST Level 1 |
157-
| FN-DSA-512 | 897 bytes | 1,281 bytes | ~666 bytes (average) | NIST Level 1 |
150+
| Algorithm | Public Key Size | Secret Key Size | Signature Size | Security Level |
151+
| ------------------ | --------------- | --------------- | -------------- | -------------- |
152+
| ML-DSA-44 | 1,312 bytes | 2,528 bytes | 2,420 bytes | NIST Level 2 |
153+
| SLH-DSA-Shake-128s | 32 bytes | 64 bytes | 7,856 bytes | NIST Level 1 |
158154

159155
## Security Notes
160156

nodejs/binding.gyp

Lines changed: 33 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -4,57 +4,42 @@
44
"target_name": "bitcoinpqc",
55
"sources": [
66
"src/native/bitcoinpqc_addon.cc",
7-
"../src/bitcoinpqc.c",
8-
"../src/ml_dsa/keygen.c",
9-
"../src/ml_dsa/sign.c",
10-
"../src/ml_dsa/verify.c",
11-
"../src/ml_dsa/utils.c",
12-
"../src/slh_dsa/keygen.c",
13-
"../src/slh_dsa/sign.c",
14-
"../src/slh_dsa/verify.c",
15-
"../src/slh_dsa/utils.c",
16-
"../src/fn_dsa/keygen.c",
17-
"../src/fn_dsa/sign.c",
18-
"../src/fn_dsa/verify.c",
19-
"../src/fn_dsa/utils.c",
20-
"../dilithium/ref/sign.c",
21-
"../dilithium/ref/packing.c",
22-
"../dilithium/ref/polyvec.c",
23-
"../dilithium/ref/poly.c",
24-
"../dilithium/ref/ntt.c",
25-
"../dilithium/ref/reduce.c",
26-
"../dilithium/ref/rounding.c",
27-
"../dilithium/ref/fips202.c",
28-
"../dilithium/ref/symmetric-shake.c",
29-
"../dilithium/ref/randombytes_custom.c",
30-
"../sphincsplus/ref/address.c",
31-
"../sphincsplus/ref/fors.c",
32-
"../sphincsplus/ref/hash_shake.c",
33-
"../sphincsplus/ref/merkle.c",
34-
"../sphincsplus/ref/sign.c",
35-
"../sphincsplus/ref/thash_shake_simple.c",
36-
"../sphincsplus/ref/utils.c",
37-
"../sphincsplus/ref/utilsx1.c",
38-
"../sphincsplus/ref/wots.c",
39-
"../sphincsplus/ref/wotsx1.c",
40-
"../sphincsplus/ref/fips202.c",
41-
"../falcon/codec.c",
42-
"../falcon/common.c",
43-
"../falcon/falcon.c",
44-
"../falcon/fft.c",
45-
"../falcon/fpr.c",
46-
"../falcon/keygen.c",
47-
"../falcon/shake.c",
48-
"../falcon/sign.c",
49-
"../falcon/vrfy.c",
50-
"../falcon/rng.c"
7+
"src/c_sources/bitcoinpqc.c",
8+
"src/c_sources/ml_dsa/keygen.c",
9+
"src/c_sources/ml_dsa/sign.c",
10+
"src/c_sources/ml_dsa/verify.c",
11+
"src/c_sources/ml_dsa/utils.c",
12+
"src/c_sources/slh_dsa/keygen.c",
13+
"src/c_sources/slh_dsa/sign.c",
14+
"src/c_sources/slh_dsa/verify.c",
15+
"src/c_sources/slh_dsa/utils.c",
16+
"src/c_sources/dilithium_ref/sign.c",
17+
"src/c_sources/dilithium_ref/packing.c",
18+
"src/c_sources/dilithium_ref/polyvec.c",
19+
"src/c_sources/dilithium_ref/poly.c",
20+
"src/c_sources/dilithium_ref/ntt.c",
21+
"src/c_sources/dilithium_ref/reduce.c",
22+
"src/c_sources/dilithium_ref/rounding.c",
23+
"src/c_sources/dilithium_ref/fips202.c",
24+
"src/c_sources/dilithium_ref/symmetric-shake.c",
25+
"src/c_sources/dilithium_ref/randombytes_custom.c",
26+
"src/c_sources/sphincsplus_ref/address.c",
27+
"src/c_sources/sphincsplus_ref/fors.c",
28+
"src/c_sources/sphincsplus_ref/hash_shake.c",
29+
"src/c_sources/sphincsplus_ref/merkle.c",
30+
"src/c_sources/sphincsplus_ref/sign.c",
31+
"src/c_sources/sphincsplus_ref/thash_shake_simple.c",
32+
"src/c_sources/sphincsplus_ref/utils.c",
33+
"src/c_sources/sphincsplus_ref/utilsx1.c",
34+
"src/c_sources/sphincsplus_ref/wots.c",
35+
"src/c_sources/sphincsplus_ref/wotsx1.c",
36+
"src/c_sources/sphincsplus_ref/fips202.c"
5137
],
5238
"include_dirs": [
5339
"<!@(node -p \"require('node-addon-api').include\")",
54-
"../include",
55-
"../dilithium/ref",
56-
"../sphincsplus/ref",
57-
"../falcon"
40+
"src/c_sources/include",
41+
"src/c_sources/dilithium_ref",
42+
"src/c_sources/sphincsplus_ref"
5843
],
5944
"dependencies": [
6045
"<!(node -p \"require('node-addon-api').gyp\")"
@@ -67,7 +52,6 @@
6752
"DILITHIUM_MODE=2",
6853
"CRYPTO_ALGNAME=\"SPHINCS+-shake-128s\"",
6954
"PARAMS=sphincs-shake-128s",
70-
"FALCON_LOGN_512=9",
7155
"CUSTOM_RANDOMBYTES=1"
7256
],
7357
"conditions": [
@@ -88,9 +72,6 @@
8872
"-Wno-implicit-function-declaration"
8973
]
9074
},
91-
"defines": [
92-
"FALCON_FPEMU=1"
93-
]
9475
}]
9576
]
9677
}

nodejs/examples/basic-usage.ts

Lines changed: 22 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -10,48 +10,45 @@ import {
1010
import crypto from "crypto";
1111

1212
/**
13-
* This example demonstrates basic usage of the bitcoinpqc TypeScript bindings.
13+
* This example demonstrates basic usage of the bitcoinpqc TypeScript bindings
14+
* with SLH-DSA-SHAKE-128S (SPHINCS+).
1415
*
1516
* It shows:
16-
* 1. Getting key and signature sizes
17+
* 1. Getting key and signature sizes for SLH-DSA
1718
* 2. Key generation
1819
* 3. Signing messages
1920
* 4. Verifying signatures
2021
* 5. Error handling
2122
*/
2223

23-
// Print key sizes for all algorithms
24-
console.log("===== Key and Signature Sizes =====");
25-
for (const algo of [
26-
Algorithm.ML_DSA_44,
27-
Algorithm.SLH_DSA_SHAKE_128S,
28-
Algorithm.FN_DSA_512,
29-
]) {
30-
const algoName = Algorithm[algo];
31-
console.log(`${algoName}:`);
32-
console.log(` Public key size: ${publicKeySize(algo)} bytes`);
33-
console.log(` Secret key size: ${secretKeySize(algo)} bytes`);
34-
console.log(` Signature size: ${signatureSize(algo)} bytes`);
35-
console.log();
36-
}
24+
// Print key sizes for SLH-DSA algorithm
25+
console.log("===== SLH-DSA Key and Signature Sizes =====");
26+
const algo = Algorithm.SLH_DSA_SHAKE_128S;
27+
const algoName = Algorithm[algo];
28+
console.log(`${algoName}:`);
29+
console.log(` Public key size: ${publicKeySize(algo)} bytes`);
30+
console.log(` Secret key size: ${secretKeySize(algo)} bytes`);
31+
console.log(` Signature size: ${signatureSize(algo)} bytes`);
32+
console.log();
3733

38-
// Generate a keypair
39-
function generateKeysAndSign(algorithm: Algorithm, message: string): void {
40-
console.log(`===== Working with ${Algorithm[algorithm]} =====`);
34+
// Generate a keypair and demonstrate SLH-DSA functionality
35+
function demonstrateSlhDsa(): void {
36+
console.log(`===== Working with ${Algorithm[Algorithm.SLH_DSA_SHAKE_128S]} =====`);
4137

4238
// Generate random data for key generation
4339
console.log("Generating random data...");
4440
const randomData = crypto.randomBytes(128);
4541

4642
try {
4743
// Generate a keypair
48-
console.log("Generating keypair...");
49-
const keypair = generateKeyPair(algorithm, randomData);
44+
console.log("Generating SLH-DSA keypair...");
45+
const keypair = generateKeyPair(Algorithm.SLH_DSA_SHAKE_128S, randomData);
5046
console.log(
5147
`Generated keypair with public key size ${keypair.publicKey.bytes.length} bytes`
5248
);
5349

5450
// Create a message to sign
51+
const message = "Hello from SLH-DSA-SHAKE-128S (SPHINCS+)!";
5552
const messageBytes = Buffer.from(message, "utf-8");
5653
console.log(`Message to sign: "${message}"`);
5754

@@ -69,7 +66,7 @@ function generateKeysAndSign(algorithm: Algorithm, message: string): void {
6966
console.error("❌ Signature verification failed:", error);
7067
}
7168

72-
// Try verifying with a different message (should fail with real implementation)
69+
// Try verifying with a different message (should fail)
7370
const badMessage = Buffer.from(message + " (modified)", "utf-8");
7471
console.log(
7572
`\nAttempting to verify with modified message: "${message} (modified)"`
@@ -83,18 +80,13 @@ function generateKeysAndSign(algorithm: Algorithm, message: string): void {
8380
}
8481
} catch (error) {
8582
console.error(
86-
`❌ Error while working with ${Algorithm[algorithm]}:`,
83+
`❌ Error while working with ${Algorithm[Algorithm.SLH_DSA_SHAKE_128S]}:`,
8784
error
8885
);
8986
}
9087

9188
console.log("\n");
9289
}
9390

94-
// Run examples with working algorithms
95-
generateKeysAndSign(Algorithm.FN_DSA_512, "Hello from FN-DSA-512 (Falcon)!");
96-
generateKeysAndSign(Algorithm.ML_DSA_44, "Hello from ML-DSA-44 (Dilithium)!");
97-
generateKeysAndSign(
98-
Algorithm.SLH_DSA_SHAKE_128S,
99-
"Hello from SLH-DSA-SHAKE-128S (SPHINCS+)!"
100-
);
91+
// Run the SLH-DSA demonstration
92+
demonstrateSlhDsa();

nodejs/package-lock.json

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

nodejs/package.json

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
{
2-
"name": "bitcoinpqc",
3-
"version": "0.1.0",
2+
"name": "@jbride/bitcoinpqc",
3+
"version": "0.2.9",
44
"description": "NodeJS TypeScript bindings for Bitcoin PQC library",
55
"main": "dist/index.js",
66
"types": "dist/index.d.ts",
77
"scripts": {
8-
"build": "tsc && node-gyp rebuild",
8+
"sync-c-sources": "./scripts/sync-c-sources.sh",
9+
"build": "npm run sync-c-sources && tsc -p . && node-gyp rebuild",
910
"install": "node-gyp rebuild",
1011
"test": "jest",
1112
"prepare": "npm run build",
@@ -18,11 +19,19 @@
1819
"cryptography",
1920
"signature",
2021
"dilithium",
21-
"falcon",
2222
"sphincs+"
2323
],
24-
"author": "",
24+
"author": "Hunter Beast <hunter@surmount.systems>",
2525
"license": "MIT",
26+
"repository": {
27+
"type": "git",
28+
"url": "https://github.com/bitcoin/libbitcoinpqc.git",
29+
"directory": "nodejs"
30+
},
31+
"bugs": {
32+
"url": "https://github.com/bitcoin/libbitcoinpqc/issues"
33+
},
34+
"homepage": "https://github.com/bitcoin/libbitcoinpqc#readme",
2635
"type": "commonjs",
2736
"devDependencies": {
2837
"@types/jest": "^29.5.12",
@@ -40,7 +49,12 @@
4049
"dist",
4150
"README.md",
4251
"binding.gyp",
43-
"src/native"
52+
"tsconfig.json",
53+
"src/native",
54+
"src/c_sources"
4455
],
45-
"gypfile": true
56+
"gypfile": true,
57+
"publishConfig": {
58+
"access": "public"
59+
}
4660
}

nodejs/scripts/sync-c-sources.sh

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#!/bin/bash
2+
3+
# Script to sync C source files from parent directory to src/c_sources
4+
# This should be run before building or publishing the package
5+
6+
set -e
7+
8+
echo "Syncing C source files..."
9+
10+
# Remove existing c_sources directory
11+
rm -rf src/c_sources
12+
13+
# Create new c_sources directory
14+
mkdir -p src/c_sources
15+
16+
# Copy C source files
17+
echo "Copying main C source file..."
18+
cp ../src/bitcoinpqc.c src/c_sources/
19+
20+
echo "Copying ML-DSA source files..."
21+
cp -r ../src/ml_dsa src/c_sources/
22+
23+
echo "Copying SLH-DSA source files..."
24+
cp -r ../src/slh_dsa src/c_sources/
25+
26+
echo "Copying Dilithium reference implementation..."
27+
cp -r ../dilithium/ref src/c_sources/dilithium_ref
28+
29+
echo "Copying SPHINCS+ reference implementation..."
30+
cp -r ../sphincsplus/ref src/c_sources/sphincsplus_ref
31+
32+
echo "Copying include files..."
33+
cp -r ../include src/c_sources/
34+
35+
# Update include paths in C source files
36+
echo "Updating include paths..."
37+
find src/c_sources -name "*.c" -exec sed -i 's|../../dilithium/ref/|../dilithium_ref/|g' {} \;
38+
find src/c_sources -name "*.c" -exec sed -i 's|../../sphincsplus/ref/|../sphincsplus_ref/|g' {} \;
39+
find src/c_sources -name "*.c" -exec sed -i 's|../../include/|../include/|g' {} \;
40+
41+
echo "C source files synced successfully!"

0 commit comments

Comments
 (0)