zkp-ecdsa
This is a TypeScript library for Zero-Knowledge proof for ECDSA.
It enables proving knowledge of a ECDSA-P256 signature under one of many
public keys that are stored in an accumulator or in a list.
Specification
See branch paper of this repository.
Functional Spec.
Proof using Groth-Kohlweiss.
GK Paper: https://eprint.iacr.org/2014/764
import {
SignatureProofList,
SystemParametersList,
generateParamsList,
keyToInt,
proveSignatureList,
verifySignatureList,
} from '../src/zkpAttestList.js'
const keyPair = await crypto.subtle.generateKey(
{ name: 'ECDSA', namedCurve: 'P-256' },
true,
[ 'sign', 'verify']),
enc = new TextEncoder(),
msg = enc.encode('kilroy was here'),
msgHash = new Uint8Array(await crypto.subtle.digest('SHA-256', msg)),
signature = new Uint8Array(
await crypto.subtle.sign({ name: 'ECDSA', hash: 'SHA-256' }, keyPair.privateKey, msg)
)
const testKey = await keyToInt(keyPair.publicKey),
testArray = [testKey, BigInt(4), BigInt(5), BigInt(6), BigInt(7), BigInt(8)],
params = generateParamsList(),
proof = await proveSignatureList(
params,
msgHash,
signature,
keyPair.publicKey,
0,
testArray
),
success = await verifySignatureList(params, msgHash, testArray, proof)
Proof using RSA Accumulators.
import {
SignatureProofAccumulator,
SystemParametersAccumulator,
addKeyToAccumulator,
generateParamsAccumulator,
proveSignatureAccumulator,
verifySignatureAccumulator
} from '../src/zkpAttestAcc.js'
import { Accumulator } from '../src/rsaAccumulator.js'
const keyPair = await crypto.subtle.generateKey(
{ name: 'ECDSA', namedCurve: 'P-256' },
true,
[ 'sign', 'verify']),
enc = new TextEncoder(),
msg = enc.encode('kilroy was here'),
msgHash = new Uint8Array(await crypto.subtle.digest('SHA-256', msg)),
signature = new Uint8Array(
await crypto.subtle.sign({ name: 'ECDSA', hash: 'SHA-256' }, keyPair.privateKey, msg)
)
const { system: params, accumulator: initAcc } = generateParamsAccumulator(),
{ j, acc, witness } = await addKeyToAccumulator(params, initAcc, keyPair.publicKey),
proof = await proveSignatureAccumulator(
params,
msgHash,
signature,
keyPair.publicKey,
j,
witness,
acc
),
success = await verifySignatureAccumulator(params, msgHash, acc, proof)
Building
$ npm ci
$ npm run build
Testing
$ npm ci
$ npm run build
$ npm run test
Future Work / Possible enhancements
- Accelerate verification in another language.
- Use private key so accumulator doesn't change and invalidate older witnesses.
Development Environment
Benchmark
$ npm ci
$ npm run bench
Flamegraph
$ npm ci
$ npm run flame
Webpack
This package compiles to ESModules (instead of CommonJS). More info about ESModules.
Requires to have webpack installed.
$ npm ci
$ npm run build
$ webpack --config webpack.config.cjs
Linter & Formatter
$ npm ci
$ npm run lint
$ npm run lint:fix
$ npm run format