Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

759 sri accept eddsa signatures #781

Closed
wants to merge 16 commits into from

Conversation

biscuitdey
Copy link
Collaborator

Description

This PR introduces the use of EDdsa keys and signature throughout the application.
Ecdsa - Used for login and signing messages
Eddsa - Used for signing transactions (as it needs to verified within a circuit)

Related Issue

#759

Motivation and Context

Eddsa signatures are required for circom circuits

How Has This Been Tested

All units tests have been updated accordingly.

Screenshots (if appropriate)

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Request to be added as a Code Owner/Maintainer

Checklist

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added tests to cover my changes.
  • All new and existing tests passed.
  • I commit to abide by the Responsibilities of Code Owners/Maintainers.

@ognjenkurtic
Copy link
Collaborator

Ecdsa - Used for login and signing messages
Eddsa - Used for signing transactions (as it needs to verified within a circuit)

@biscuitdey it was not possible to use a single key format for both purposes?

@ognjenkurtic
Copy link
Collaborator

Ecdsa - Used for login and signing messages Eddsa - Used for signing transactions (as it needs to verified within a circuit)

@biscuitdey it was not possible to use a single key format for both purposes?

If not, i would vote we introduce a new Prisma model called public key which would store the key type and all relevant information. BpiSubject could contain 1 or more PublicKeys. This way we do not need to place them into JSON blobs and perform hacks around the code to work with the keys.

But i would really prefer if we could stick with a single key format for the time being. Requesting multiple key formats from the end user does not sound fun.

@biscuitdey
Copy link
Collaborator Author

biscuitdey commented Jan 15, 2024

Ecdsa - Used for login and signing messages Eddsa - Used for signing transactions (as it needs to verified within a circuit)
@biscuitdey it was not possible to use a single key format for both purposes?

If not, i would vote we introduce a new Prisma model called public key which would store the key type and all relevant information. BpiSubject could contain 1 or more PublicKeys. This way we do not need to place them into JSON blobs and perform hacks around the code to work with the keys.

But i would really prefer if we could stick with a single key format for the time being. Requesting multiple key formats from the end user does not sound fun.

We need both types of keys. Besides login & messaging, we need to request the ecdsa keys from the user for generating did (because we are using did:ethr and need to use ecdsa/ethereum public key as the id --> which then gets used by a didResolver).

@@ -0,0 +1,29 @@
module.exports = {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe to make scope of PR smaller and easier to figure out what is actual diff and what is changed because of linter, lets not add linter for frontend in this PR too?

@@ -1,37 +1,50 @@
import { Injectable } from '@nestjs/common';
import { BpiSubject as BpiSubjectPrismaModel, BpiSubjectRole as BpiSubjectRolePrismaModel } from '@prisma/client';
import {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@biscuitdey could you please remove linter changes from PR? it will make review easier, for example, i doubt prisma mapper changes are needed here, so its probably linter, but still required to check

we can do linter only changes in separate PR

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will move the linter to a separate PR.

}


const createEddsaPrivateKey = async (publicKeyOwner) => {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

function name indicates it is creating private key, but function is creating and returning a signature

you have bellow createPublicKey which is creating private key and then public key out of it? why is this function needed?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We needed to generate and store Eddsa keypair and signature for the circom circuit (as Ecdsa signatures are too big to handle). But currently the user is using Metamask for key management, which uses Ecdsa keys. So, as a workaround, Andreas suggested we utilise the Metamask public key, generate a signature and use that for our Eddsa private key. You can see the discussion here

*/
-- AlterTable
ALTER TABLE "BpiSubject" DROP COLUMN "publicKey",
ADD COLUMN "publicKey" JSONB NOT NULL;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why storing json { pk1, pk2 } instead of having pk1 and pk2 as separate fields? storing json seems like it can just introduce not needed overhead to always parse and unparse

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will remove the JSON and instead create another table for storing public keys.

@biscuitdey
Copy link
Collaborator Author

Will update the code in smaller PR

@biscuitdey biscuitdey closed this Jan 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

SRI - Accept Eddsa signatures throughout the application
3 participants