Giter Club home page Giter Club logo

aztec-crypto-js's Introduction

aztec-crypto-js

This library contains methods required to construct AZTEC zero-knowledge proofs, and to create the required EIP712 signatures in order to spend AZTEC notes.

IMPORTANT: The deployed AZTEC smart contracts use a trusted setup created by AZTEC in-house and should only be used for testing and development purposes. We will be launching a multiparty computation protocol to create a trusted setup that is secured by the wider Ethereum community, where only one person has to act honestly for the setup database to be secure. If you wish to participate please let us know at [email protected]

To see how this library can be used to issue AZTEC confidential transactions and create AZTEC notes, view our demonstration script and documentation in the Aztec repository

For full API docs, view our github pages API

Install

clone this repo to your desired directory and run npm install

Usage

const note = require('./note/note');
const proof = require('./proof/proof');
const secp256k1 = require('./secp256k1/secp256k1');
const sign = require('./eip712/sign');

// address of confidential AZTEC - DAI smart contract
const aztecContract = '0x0000';
// main-net chain Id
const chainId = 1;

const accounts = [
    secp256k1.generateAccount(),
    secp256k1.generateAccount(),
];

const inputNotes = [
    note.create(accounts[0].publicKey, 80),
    note.create(accounts[0].publicKey, 60),
];

const outputNotes = [
    note.create(accounts[1].publicKey, 50),
    note.create(accounts[1].publicKey, 100),
];

const kPublic = -10; // input notes contain 10 fewer than output notes = deposit of 10 public tokens
const sender = accounts[0].address; // address of transaction sender

// proofData and challenge are ABI-encoded and ready to beused as inputs to an AZTEC smart contract
const { proofData, challenge } = proof.constructJoinSplit([...inputNotes, ...outputNotes], inputNotes.length, sender, kPublic);

// construct EIP712-compatible ECDSA sigantures over input notes, required to spend input notes
const inputSignatures = [
    sign.signNote(proofData[0], challenge, sender, aztecContract, accounts[0].privateKey, chainId),
    sign.signNote(proofData[0], challenge, sender, aztecContract, accounts[0].privateKey, chainId),
];

const outputOwners = [accounts[1].address, accounts[1].address];

// transactionData's members can be directly fed into an AZTECERC20Bridge.sol contract's confidentialTransfer method
const transactionData = {
    proofData,
    m: inputNotes.length,
    challenge,
    inputSignatures,
    outputOwners,
    metadata: note.encodeMetadata(outputNotes),
};

return transactionData;

Notation

Unless stated otherwise, public keys, private keys and addresses are encoded as hex-strings, prepended by the characters 0x.

Tests

Run the repository's tests with npm run test

aztec-crypto-js's People

Contributors

zac-williamson avatar thomas-waite avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.