-
Notifications
You must be signed in to change notification settings - Fork 13
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
ed25519 keys support and import keys new flow #126
Changes from 12 commits
1789692
b624844
7d2fc60
99bc575
a957ebf
02168d0
8586ecc
4e603df
3066336
badf280
d20b635
fe96658
6760d85
0b9aff1
d9ac909
331a9ef
c8ed4d4
c70b131
119c01c
585b89b
52d93e9
12fb612
6950486
855aca0
d9dab31
bd59e70
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
{ | ||
"editor.codeActionsOnSave": { | ||
"source.fixAll": true | ||
"source.fixAll": "explicit" | ||
}, | ||
"cSpell.words": ["Mutex", "Mutexes", "toruslabs"] | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
export const JRPC_METHODS = { | ||
GET_OR_SET_KEY: "GetPubKeyOrKeyAssign", | ||
COMMITMENT_REQUEST: "CommitmentRequest", | ||
IMPORT_SHARE: "ImportShare", | ||
IMPORT_SHARES: "ImportShares", | ||
GET_SHARE_OR_KEY_ASSIGN: "GetShareOrKeyAssign", | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
import BN from "bn.js"; | ||
import { ec } from "elliptic"; | ||
import { curve, ec as EC } from "elliptic"; | ||
import { keccak256 as keccakHash } from "ethereum-cryptography/keccak"; | ||
|
||
import log from "../loglevel"; | ||
|
@@ -31,24 +31,31 @@ export function toChecksumAddress(hexAddress: string): string { | |
return ret; | ||
} | ||
|
||
export function generateAddressFromPrivKey(ecCurve: ec, privateKey: BN): string { | ||
export function generateAddressFromPrivKey(ecCurve: EC, privateKey: BN): string { | ||
const key = ecCurve.keyFromPrivate(privateKey.toString("hex", 64), "hex"); | ||
const publicKey = key.getPublic().encode("hex", false).slice(2); | ||
log.info(publicKey, "public key"); | ||
const evmAddressLower = `0x${keccak256(Buffer.from(publicKey, "hex")).slice(64 - 38)}`; | ||
return toChecksumAddress(evmAddressLower); | ||
} | ||
|
||
export function generateAddressFromPubKey(ecCurve: ec, publicKeyX: BN, publicKeyY: BN): string { | ||
export function generateAddressFromPubKey(ecCurve: EC, publicKeyX: BN, publicKeyY: BN): string { | ||
const key = ecCurve.keyFromPublic({ x: publicKeyX.toString("hex", 64), y: publicKeyY.toString("hex", 64) }); | ||
const publicKey = key.getPublic().encode("hex", false).slice(2); | ||
log.info(key.getPublic().encode("hex", false), "public key"); | ||
const evmAddressLower = `0x${keccak256(Buffer.from(publicKey, "hex")).slice(64 - 38)}`; | ||
return toChecksumAddress(evmAddressLower); | ||
} | ||
|
||
export function getPostboxKeyFrom1OutOf1(ecCurve: ec, privKey: string, nonce: string): string { | ||
export function getPostboxKeyFrom1OutOf1(ecCurve: EC, privKey: string, nonce: string): string { | ||
const privKeyBN = new BN(privKey, 16); | ||
const nonceBN = new BN(nonce, 16); | ||
return privKeyBN.sub(nonceBN).umod(ecCurve.curve.n).toString("hex"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. some users / libraries may expect the hex to be 32 bytes long (64 characters). ideally should use a global function to encode to bytes / hex, so that we don't have to do and check this manually every time. (even better might be to create a package that can be used across libraries.) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. will address these suggestions to make test cases modular in other PRs, thanks for suggesting these improvement |
||
} | ||
|
||
export function derivePubKey(ecCurve: EC, sk: BN): curve.base.BasePoint { | ||
const skHex = sk.toString(16, 64); | ||
return ecCurve.keyFromPrivate(skHex).getPublic(); | ||
} | ||
|
||
export const encryptionEC = new EC("secp256k1"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why are we using only the first key?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So there are cases where it is possible that a user can have multiple keys but all the nodes might not have all those shares/pub keys for ex i have seen these cases when a node is temp down but key was assigned successfully by other threshold number of nodes.
and as a result we should only check threshold for first key rather than checking older keys which are not even being used on frontend and can have mismatch in threshold when some nodes have more keys assigned for a user than others.