Socket
Book a DemoInstallSign in
Socket

eddsa-o1js

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

eddsa-o1js

> ⚠️ **NOTE**: The current implementation produces circuits that are too large to fit within existing constraint limits. PRs that optimize this library are welcome!

latest
npmnpm
Version
0.0.1
Version published
Maintainers
1
Created
Source

eddsa-o1js

⚠️ NOTE: The current implementation produces circuits that are too large to fit within existing constraint limits. PRs that optimize this library are welcome!

License: Apache-2.0 npm version

A provable EdDSA signature verification library for o1js, enabling zkApp developers to verify EdDSA signatures inside zk-SNARKs.

Features

  • EdDSA Verification in ZK: Verify EdDSA signatures within provable o1js code
  • Edwards25519 Support: Built-in support for the popular Edwards25519 curve
  • Twisted Edwards Curves: Implementation of twisted Edwards curves for efficient elliptic curve operations
  • Fully Composable: Designed to work seamlessly with the o1js ecosystem

Installation

npm install eddsa-o1js

Usage

Here's a quick example of how to use eddsa-o1js to verify an EdDSA signature:

import { ZkProgram, Bool, Bytes } from 'o1js';
import { createEddsa, createForeignTwisted, TwistedCurves } from 'eddsa-o1js';

// Create a custom Edwards25519 curve class
class Edwards25519 extends createForeignTwisted(TwistedCurves.Edwards25519) {}
class Scalar extends Edwards25519.Scalar {}
class Eddsa extends createEddsa(Edwards25519) {}
class Bytes32 extends Bytes(32) {}

// Define a ZkProgram that verifies EdDSA signatures
const eddsa = ZkProgram({
  name: 'eddsa',
  publicInput: Bytes32,
  publicOutput: Bool,

  methods: {
    verifyEddsa: {
      privateInputs: [Eddsa, Edwards25519],
      async method(
        message: Bytes32,
        signature: Eddsa,
        publicKey: Edwards25519
      ) {
        return {
          publicOutput: signature.verify(message, publicKey),
        };
      },
    },
  },
});

// Example: Generate a signature and verify it
async function run() {
  // Generate a keypair
  let privateKey = Edwards25519.Scalar.random();
  let publicKey = Edwards25519.generator.scale(privateKey);

  // Sign a message
  let message = Bytes32.fromString('Hello, o1js!');
  let signature = Eddsa.sign(message.toBytes(), privateKey.toBigInt());

  // Compile the program
  await eddsa.compile();

  // Verify the signature in zk
  let { proof } = await eddsa.verifyEddsa(message, signature, publicKey);

  // Check the result
  proof.publicOutput.assertTrue('signature verifies');
}

Advanced Usage

For more detailed examples, please check the examples directory:

API Reference

Core Components

  • createEddsa(TwistedCurve): Factory function that creates an EdDSA implementation for a specific curve
  • createForeignTwisted(TwistedCurveParams): Creates a provable twisted Edwards curve implementation
  • TwistedCurves: Contains parameters for common twisted Edwards curves (e.g., Edwards25519)

Usage Patterns

  • Define your curve by extending the base implementation
  • Create your EdDSA implementation for that curve
  • Use the signature verification methods in your ZkProgram

Development

# Build the project
npm run build
  • o1js - The main framework for writing zero-knowledge applications

License

This project is licensed under the Apache License 2.0 - see the LICENSE file for details.

Keywords

mina-zkapp

FAQs

Package last updated on 03 Apr 2025

Did you know?

Socket

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

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.