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

Add support of secp256k1 key pairs #440

Open
alexauroradev opened this issue Oct 19, 2020 · 8 comments
Open

Add support of secp256k1 key pairs #440

alexauroradev opened this issue Oct 19, 2020 · 8 comments
Assignees
Labels
enhancement New feature or request good_first_issue P2 Pretty important Support

Comments

@alexauroradev
Copy link

The rollout of EVM feature implies support of EVM-native keys generation, encoding, signing and verification. Users that are familiar with Ethereum should be able to use their accounts for working with NEAR EVM implementation.

@mikedotexe
Copy link
Contributor

With Aurora launching, this is likely becoming high priority

@mikedotexe mikedotexe added the P2 Pretty important label May 11, 2021
@mehtaphysical
Copy link
Contributor

It sounds like secp256k1 support in nearcore has been pushed until next quarter.

We should take this time to audit the elliptic package. If it looks good we can replace tweetnacl with it to prepare the way for secp256k1 support.

@bowenwang1996
Copy link
Contributor

It sounds like secp256k1 support in nearcore has been pushed until next quarter.

Can you elaborate on that? On the account level we already support secp256k1 key for a while now.

@mehtaphysical
Copy link
Contributor

@bowenwang1996 that is just what I heard when I asked about this.

I've been messing around with adding a secp256k1 key with this code:

async function run() {
  const account = await near.account("rnm.testnet");
  const ec = new EC("secp256k1");
  const kp = ec.genKeyPair();

  const publicKey = `secp256k1:${base_encode(
    kp.getPublic().getX().toBuffer()
  )}`;
  // const kp = KeyPair.fromRandom("ed25519");
  // const publicKey = kp.getPublicKey().toString();

  const res = await account.addKey(publicKey);
  console.log(res);
}

But am getting the following error:

[-32602] Invalid params: Failed to decode transaction: Unexpected variant index: 31

If I do the same thing, replacing secp256k1 with ed25519 everything works fine:

async function run() {
  const account = await near.account("rnm.testnet");
  const ec = new EC("ed25519");
  const kp = ec.genKeyPair();

  const publicKey = `ed25519:${base_encode(
    kp.getPublic().getX().toBuffer()
  )}`;
  // const kp = KeyPair.fromRandom("ed25519");
  // const publicKey = kp.getPublicKey().toString();

  const res = await account.addKey(publicKey);
  console.log(res);
}

I can play around with it more.

@bowenwang1996
Copy link
Contributor

That is probably a borsh serialization issue in near-api-js

@mehtaphysical
Copy link
Contributor

Created issue with borsh-js. near/borsh-js#19

Waiting for feedback, then will implement a fix and implement this change

@mikedotexe
Copy link
Contributor

mikedotexe commented Dec 15, 2021

I think we still need this, and want to bump it. Been fielding some questions from builders and believe it'd be good to remember it.

This is a good lead:
https://www.npmjs.com/package/@ethersproject/signing-key

@samingle
Copy link

Have a draft of this in #810

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good_first_issue P2 Pretty important Support
Projects
Status: NEW❗
Development

No branches or pull requests

9 participants