Skip to content

Instantly share code, notes, and snippets.

@homura
Last active May 8, 2022 15:13
Show Gist options
  • Save homura/d7125f4977241116230b4270d1a9baf0 to your computer and use it in GitHub Desktop.
Save homura/d7125f4977241116230b4270d1a9baf0 to your computer and use it in GitHub Desktop.
Muta misc

Misc

密码学

Muta 使用 secp256k1 参数以实现椭圆曲线数字签名算法(ECDSA) 的功能

如何生成生成地址

记私钥 pr, 对应地址函数 A(pr),则有:

A(pr) = Bit0..160(Keccak(ECDSAPUBKEY(pr)))

Muta 的地址对应成一个 160bit 的值,生成的过程详细描述为:

  1. 私钥 -> 公钥:私钥通过 ECDSA 公钥生成算法转换为公钥
  2. 公钥 -> 哈希:公钥通过 Keccak 函数转换哈希值
  3. 哈希 -> 地址:截取前 160bit 哈希值

如何签名交易

记私钥 pr,待签名消息 x,对应有签名函数 S(x),则有:

S(x) = ECDSASIGN(Keccak(RLP(x)), pr)

由于使用 spec256k1,因此签名对应成一个 512bit 的值,签名过程消息描述为:

  1. 消息 -> 序列化消息:消息通过 RLP 序列化,消息序列为
    1. chainID
    2. cyclesLimit
    3. cyclesPrice
    4. nonce
    5. method
    6. service
    7. payload
    8. timeout
  2. 序列化消息 -> 哈希:序列化消息通过 Keccak 函数转换哈希值
  3. 哈希 -> 签名:哈希值通过 ECDSA 签名算法生成签名
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment