@kshan0515/cggmp-node-binding 0.1.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 (4) hide show
  1. package/README.md +148 -0
  2. package/index.d.ts +22 -0
  3. package/index.js +16 -0
  4. package/package.json +72 -0
package/README.md ADDED
@@ -0,0 +1,148 @@
1
+ # cggmp-node-binding
2
+
3
+ Node.js native binding for **CGGMP24 MPC ECDSA protocol** - Distributed key generation and threshold signing without exposing private keys.
4
+
5
+ Based on [cggmp21](https://github.com/LFDT-Lockness/cggmp21) Rust implementation.
6
+
7
+ ## Features
8
+
9
+ - **Distributed Key Generation (DKG)**: Generate ECDSA key shares across multiple parties
10
+ - **Threshold Signing**: Sign messages with a subset of parties (t-of-n)
11
+ - **Auxiliary Info Generation**: Generate pre-computation data for efficient signing
12
+ - **State Machine API**: Round-based protocol execution with `CggmpExecutor`
13
+ - **Cross-platform**: Pre-built binaries for macOS, Linux, and Windows
14
+
15
+ ## Installation
16
+
17
+ ```bash
18
+ npm install @kshan0515/cggmp-node-binding
19
+ # or
20
+ pnpm add @kshan0515/cggmp-node-binding
21
+ # or
22
+ yarn add @kshan0515/cggmp-node-binding
23
+ ```
24
+
25
+ ## Supported Platforms
26
+
27
+ | Platform | Architecture |
28
+ |----------|-------------|
29
+ | macOS | x64, arm64 (Apple Silicon) |
30
+ | Linux | x64 (glibc, musl), arm64 (glibc) |
31
+ | Windows | x64 |
32
+
33
+ ## Usage
34
+
35
+ ```typescript
36
+ import { CggmpExecutor, generatePrimes } from '@kshan0515/cggmp-node-binding';
37
+
38
+ // Create executor for party 0 in a 2-of-3 threshold setup
39
+ const executor = new CggmpExecutor(
40
+ 'session-id',
41
+ 'execution-id',
42
+ 0, // party index
43
+ 2, // threshold
44
+ 3 // total parties
45
+ );
46
+
47
+ // Start auxiliary info generation
48
+ executor.startAuxGen();
49
+
50
+ // Process protocol rounds
51
+ const outgoing = executor.step([]);
52
+ // ... exchange messages with other parties ...
53
+
54
+ // Check status
55
+ const snapshot = JSON.parse(executor.snapshot());
56
+ console.log(snapshot.status);
57
+
58
+ // After aux gen, start keygen
59
+ executor.startKeygen();
60
+ // ... continue processing rounds ...
61
+
62
+ // After keygen, export key share
63
+ const keyShare = executor.exportKeyshare();
64
+
65
+ // For signing, import key share and start signing
66
+ executor.importKeyshare(keyShare);
67
+ executor.setSigners('[0, 1]'); // Select signers
68
+ executor.startSigning('0x...'); // Message hash (32 bytes hex)
69
+ ```
70
+
71
+ ## API
72
+
73
+ ### `CggmpExecutor`
74
+
75
+ Main class for MPC protocol execution.
76
+
77
+ #### Constructor
78
+ ```typescript
79
+ new CggmpExecutor(
80
+ sessionId: string,
81
+ executionId: string,
82
+ partyIndex: number,
83
+ threshold: number,
84
+ partiesCount: number
85
+ )
86
+ ```
87
+
88
+ #### Methods
89
+
90
+ | Method | Description |
91
+ |--------|-------------|
92
+ | `startAuxGen()` | Start auxiliary info generation |
93
+ | `startAuxGenWithPrimes(primes: Buffer)` | Start aux gen with pre-generated primes |
94
+ | `startKeygen()` | Start distributed key generation |
95
+ | `startSigning(txHex: string)` | Start signing (32-byte hash as hex) |
96
+ | `step(inputs: Buffer[]): Buffer[]` | Process incoming messages and return outgoing |
97
+ | `snapshot(): string` | Get current state as JSON |
98
+ | `setSigners(json: string)` | Set signer indices for signing |
99
+ | `importKeyshare(data: Buffer)` | Import key share |
100
+ | `exportKeyshare(): Buffer` | Export key share |
101
+ | `importAuxInfo(data: Buffer)` | Import auxiliary info |
102
+ | `exportAuxInfo(): Buffer` | Export auxiliary info |
103
+
104
+ ### `generatePrimes(): Buffer`
105
+
106
+ Pre-generate safe primes for faster auxiliary info generation.
107
+
108
+ ## Protocol Flow
109
+
110
+ 1. **Auxiliary Info Generation**: Generate Paillier keys and ring-Pedersen parameters
111
+ 2. **Key Generation**: Generate ECDSA key shares using VSS
112
+ 3. **Signing**: Create threshold signatures with selected signers
113
+
114
+ ## Building from Source
115
+
116
+ Requirements:
117
+ - Node.js >= 18
118
+ - Rust (stable)
119
+ - pnpm
120
+
121
+ ```bash
122
+ # Install dependencies
123
+ pnpm install
124
+
125
+ # Build native binary
126
+ pnpm build
127
+
128
+ # Run tests
129
+ pnpm test
130
+ ```
131
+
132
+ ## Security
133
+
134
+ This library implements the CGGMP24 protocol which provides:
135
+ - UC-secure key generation
136
+ - Identifiable abort in case of malicious behavior
137
+ - Threshold security (t-of-n)
138
+
139
+ **Warning**: This is a cryptographic library. Use with caution in production environments.
140
+
141
+ ## License
142
+
143
+ MIT
144
+
145
+ ## References
146
+
147
+ - [CGGMP24 Paper](https://eprint.iacr.org/2021/060)
148
+ - [cggmp21 Rust Implementation](https://github.com/LFDT-Lockness/cggmp21)
package/index.d.ts ADDED
@@ -0,0 +1,22 @@
1
+ /* tslint:disable */
2
+ /* eslint-disable */
3
+
4
+ /* auto-generated by NAPI-RS */
5
+
6
+ export function generatePrimes(): Buffer
7
+ export class CggmpExecutor {
8
+ constructor(sessionId: string, executionId: string, partyIndex: number, threshold: number, partiesCount: number)
9
+ exportKeyshare(): Buffer
10
+ exportAuxInfo(): Buffer
11
+ importKeyshare(data: Buffer): void
12
+ importAuxInfo(data: Buffer): void
13
+ startKeygen(): void
14
+ startAuxGen(): void
15
+ startAuxGenWithPrimes(primesBuf: Buffer): void
16
+ setSigners(json: string): void
17
+ startSigning(txHex: string): void
18
+ step(inputs: Array<Buffer>): Array<Buffer>
19
+ snapshot(): string
20
+ exportKeyshareBin(): Buffer
21
+ exportAuxInfoBin(): Buffer
22
+ }
package/index.js ADDED
@@ -0,0 +1,16 @@
1
+ const { existsSync } = require('fs')
2
+ const { join } = require('path')
3
+
4
+ const { platform, arch } = process
5
+
6
+ let nativeBinding = null
7
+ let localBind = join(__dirname, 'cggmp-node-binding.node')
8
+
9
+ if (existsSync(localBind)) {
10
+ nativeBinding = require(localBind)
11
+ } else {
12
+ // 폴백 로직 (필요시 추가)
13
+ throw new Error(`Failed to load native binding from ${localBind}`)
14
+ }
15
+
16
+ module.exports = nativeBinding
package/package.json ADDED
@@ -0,0 +1,72 @@
1
+ {
2
+ "name": "@kshan0515/cggmp-node-binding",
3
+ "version": "0.1.0",
4
+ "description": "Node.js native binding for CGGMP24 MPC ECDSA protocol - Distributed key generation and threshold signing",
5
+ "main": "index.js",
6
+ "types": "index.d.ts",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "https://github.com/anthropics/cggmp-node-binding"
10
+ },
11
+ "keywords": [
12
+ "mpc",
13
+ "ecdsa",
14
+ "cggmp24",
15
+ "threshold-signature",
16
+ "dkg",
17
+ "signing",
18
+ "cryptography",
19
+ "napi",
20
+ "native"
21
+ ],
22
+ "author": "",
23
+ "license": "MIT",
24
+ "engines": {
25
+ "node": ">= 18"
26
+ },
27
+ "napi": {
28
+ "binaryName": "cggmp-node-binding",
29
+ "targets": [
30
+ "aarch64-apple-darwin",
31
+ "x86_64-apple-darwin",
32
+ "x86_64-unknown-linux-gnu",
33
+ "x86_64-unknown-linux-musl",
34
+ "aarch64-unknown-linux-gnu",
35
+ "x86_64-pc-windows-msvc"
36
+ ]
37
+ },
38
+ "scripts": {
39
+ "artifacts": "napi artifacts",
40
+ "build": "napi build --platform --release",
41
+ "build:debug": "napi build --platform",
42
+ "prepublishOnly": "napi prepublish -t npm",
43
+ "test": "jest",
44
+ "universal": "napi universal",
45
+ "version": "napi version"
46
+ },
47
+ "devDependencies": {
48
+ "@napi-rs/cli": "^3.0.0-alpha.60",
49
+ "@types/jest": "^29.5.11",
50
+ "@types/node": "^20.10.4",
51
+ "jest": "^29.7.0",
52
+ "ts-jest": "^29.1.1",
53
+ "ts-proto": "^1.181.0",
54
+ "typescript": "^5.3.3"
55
+ },
56
+ "dependencies": {
57
+ "protobufjs": "^7.5.4",
58
+ "rxjs": "^7.8.2"
59
+ },
60
+ "files": [
61
+ "index.js",
62
+ "index.d.ts"
63
+ ],
64
+ "optionalDependencies": {
65
+ "@kshan0515/cggmp-node-binding-darwin-arm64": "0.1.0",
66
+ "@kshan0515/cggmp-node-binding-darwin-x64": "0.1.0",
67
+ "@kshan0515/cggmp-node-binding-linux-x64-gnu": "0.1.0",
68
+ "@kshan0515/cggmp-node-binding-linux-x64-musl": "0.1.0",
69
+ "@kshan0515/cggmp-node-binding-linux-arm64-gnu": "0.1.0",
70
+ "@kshan0515/cggmp-node-binding-win32-x64-msvc": "0.1.0"
71
+ }
72
+ }