Socket
Socket
Sign inDemoInstall

@cloudflare/zkp-ecdsa

Package Overview
Dependencies
2
Maintainers
57
Versions
8
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @cloudflare/zkp-ecdsa

Zero-Knowledge Proof for ECDSA


Version published
Weekly downloads
978
decreased by-2.2%
Maintainers
57
Install size
1.04 MB
Created
Weekly downloads
 

Readme

Source

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

Keywords

FAQs

Last updated on 03 Mar 2021

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc