https://medium.com/@antonassocareer/web3-secp256k1-%E7%B0%BD%E7%AB%A0%E8%88%87solidity%E9%A9%97%E7%AB%A0-26ded518cfdc
phone vs secp256k1 vs ethereumjs-util 那代表 phone 產生的是符合ethereum的格式 但因為 signed的長度不符合標準的 secp256k1 ,所以只能用ethereumjs-util的工具,從fromRpcSig 匯入處理,取得 s r v ,後就能進行處理了! Elliptic 和 secp256k1 各別需要不同的方式,請閱code
const secp256k1 = require('secp256k1') const ejsu = require('ethereumjs-util') Web3 = require("web3") var web3 = new Web3(Web3.givenProvider || 'ws://some.local-or-remote.node:8546'); // phone // private key // address 0xAD44A8ea9A9Bb5eF66F041BB921A687331729eB4 // Message Signature Has 0xa05ac71b16172777f683edbc48e9709cffd713a82630232d7c98e0f0df5201d60329658dba83b53fed49307e03d9663c0d2e4476c8b7925c2ed02cc7f881f5271b // Message Hello // public key 034e17dc4aef81e0ce6d16686be5e194274795375fc5525f1cdc46fe0b4643d5d6 console.log("\n----- phone -----\n") var buf_Signed = Buffer.from(web3.utils.hexToBytes("0xa05ac71b16172777f683edbc48e9709cffd713a82630232d7c98e0f0df5201d60329658dba83b53fed49307e03d9663c0d2e4476c8b7925c2ed02cc7f881f5271b")) var buf_pubkey = Buffer.
Sure ethereum signature is 65, but secp256k1 is 64
RangeError: signature length is invalid Web3 = require("web3") var web3 = new Web3(Web3.givenProvider || 'ws://some.local-or-remote.node:8546'); const secp256k1 = require('secp256k1') // or require('secp256k1/elliptic') // if you want to use pure js implementation in node //ethereum test https://github.com/ethereum/go-ethereum/blob/461291882edce0ac4a28f64c4e8725b7f57cbeae/crypto/signature_test.go msg = web3.utils.hexToBytes("0xd301ce462d3e639518f482c7f03821fec1e602018630ce621e1e7851c12343a6") signature = web3.utils.hexToBytes("0x638a54215d80a6713c8d523a6adc4e6e73652d859103a36b700851cb0e61b66b8ebfc1a610c57d732ec6e0a8f06a9a7a28df5051ece514702ff9cdff0b11f454") pubkey = web3.utils.hexToBytes("0x03ca634cae0d49acb401d8a4c6b6fe8c55b70d115bf400769cc1400f3258cd3138") console.log(secp256k1.verify(msg, signature, pubKey))
呼叫web3的部份,都需要使用ethereum geth,這部份有點麻煩
Call web3 must use ethereum, this mean need to run ganache or geth. No ok.
jsrsasign is offline to compute
ECDSA 相關的是 https://kjur.github.io/jsrsasign/sample/sample-ecdsa.html
=====
https://medium.com/@angellopozo/ethereum-signing-and-validating-13a2d7cb0ee3
https://dzone.com/articles/signing-and-verifying-ethereum-signatures
public address 只是 verify後拿來驗證是否相同
另一句話 verify後會產生public address,主要是拿sign後的值產生 r s v ,然後再用 合約的功能 ecrecover 處理
public address only for after verify product check
Other way to explain is
After verify get public address. Take signatures to make r s v, then use r s v with contract ecrecover().