taurushq-io / multi-party-sig

Implementation of protocols for threshold signatures
Apache License 2.0
312 stars 120 forks source link

Determine public key and generate ethereum address #92

Open ahsan-arif opened 1 year ago

ahsan-arif commented 1 year ago

Hi! I hope you're doing well. I want to generate Ethereum address from the public key and not being able to retrieve it. I read somewhere that the r.(*cmp.Config).PublicPoint()function returns the public key, but its output is as follows:

&{{{[12592655 16781683 10822834 12300466 26973595 26950003 20773628 44589891 15684115 2487632]} {[8737552 54784308 53761210 13758320 57903304 54340575 43964877 39572907 59768444 2127229]} {[16345148 53694071 40827578 35152206 19151206 8418008 32231902 13881133 64847501 846021]}}}
keygen  &{{{[32708375 42551501 65047894 39740003 35144499 14005502 40612690 46015214 22239522 2773756]} {[25477995 13108925 52126466 39235989 28278852 35154078 44428883 22064819 35331873 929806]} {[21566372 10761659 8474927 25003733 66756683 61795828 13810381 7172486 19023670 3610546]}}}
keygen  &{{{[25688337 63875463 10866135 31637987 7569351 63240784 37461504 54980759 66091033 2623583]} {[44236742 23246230 26880624 1243741 14396485 1134731 13343978 1163813 33263876 3283408]} {[119210 58475678 20658911 5621745 64273730 66878327 24229721 1561908 58372961 2601431]}}}

If the output shared above is public key how can I generate Ethereum address from it? Also, the output will change after the CMPRefresh() function is called. Can you please help me in this regard?

singhparshant commented 1 year ago

Hi @ahsan-arif , Were you able to resolve this ?

valli0x commented 11 months ago

@ahsan-arif

publicKey, err := c.PublicPoint().MarshalBinary()
if err != nil {
    return err
}

pubkeyECDSA, err := crypto.DecompressPubkey(publicKey)
if err != nil {
    return err
}

pub := crypto.FromECDSAPub(pubkeyECDSA)
address := crypto.PubkeyToAddress(*pubkeyECDSA).Hex()

fmt.Printf("address: %s\n", address)
fmt.Printf("public key: %s\n", hex.EncodeToString(pub))

crypto package is "github.com/ethereum/go-ethereum/crypto" I hope this helps you.