EOS多重签名

管理员组 夜小白 4月前 128

EOS多重签名

概述

多重签名主要有EOS系统合约eosio.msig执行实现,主要分为提交提案、审批提案、执行提案;当然也包括查看提案、取消提交的提案等操作,本文档只演示多重签名从提交提案、审批、执行的整个过程;

多重签名概念

一个账户拥有Owner和Active权限。同时账户也能够自定义新的权限。 所谓多重签名,就是一个账户可以将它的权限指派给其它多个账户,一个操作只有得到这些授权用户签名而得到执行。多重签名是加强账户安全性的一个方法。EOS的多重复签名是由eos系统智能合约eosio.msig来进行支持的。

多重签名的操作过程

1.创建3个秘钥对并导入到钱包

cleos create key --to-console
  • helloworld51
  • Private key: 5JBLfHKBes9Xs1wVFus49s6yLivHgeuHRGYZV6ngQuU5d6svw1R
  • Public key: UMI8XVnaGMqTqTyBco9wrB2ED1vHytnw2LWczWDmA1rL47N5r8MQY
  • helloworld52
  • Private key: 5Jtt4Npcms6YybAQg3rtkCbN8c5Voc1Rd6XrvU8dcsMQy3XpbPn
  • Public key: UMI72kmkrY5msCAC5gXAmCr4YoSWzDrHGM7su4LvWMv25SQ25Vhbe
  • helloworld53
  • Private key: 5Jkhk5QRYyEhu597mkPCqTbPNUYdLq94S4hiQa4nLhA9BaGo5ih
  • Public key: UMI5QGvcbPhEAegZJKcSggvuwrqJMuJD3jJ3q6PNE2KVXsuuYS4Kz

    2.将秘钥导入钱包

    cleos wallet import  --private-key 5JBLfHKBes9Xs1wVFus49s6yLivHgeuHRGYZV6ngQuU5d6svw1R
    cleos wallet import  --private-key 5Jtt4Npcms6YybAQg3rtkCbN8c5Voc1Rd6XrvU8dcsMQy3XpbPn
    cleos wallet import  --private-key 5Jkhk5QRYyEhu597mkPCqTbPNUYdLq94S4hiQa4nLhA9BaGo5ih

    3.用这3对秘钥分别创建3个账户helloworld51、helloworld52、helloworld53

    helloworld51

    cleos -u http://127.0.0.1:8888 create account  umidata1 helloworld51 UMI8XVnaGMqTqTyBco9wrB2ED1vHytnw2LWczWDmA1rL47N5r8MQY UMI8XVnaGMqTqTyBco9wrB2ED1vHytnw2LWczWDmA1rL47N5r8MQY   -p umidata1

    helloworld52

    cleos -u http://127.0.0.1:8888 create account  umidata1 helloworld52 UMI72kmkrY5msCAC5gXAmCr4YoSWzDrHGM7su4LvWMv25SQ25Vhbe UMI72kmkrY5msCAC5gXAmCr4YoSWzDrHGM7su4LvWMv25SQ25Vhbe -p umidata1

    helloworld53

    cleos -u http://127.0.0.1:8888 create account  umidata1 helloworld53 UMI5QGvcbPhEAegZJKcSggvuwrqJMuJD3jJ3q6PNE2KVXsuuYS4Kz UMI5QGvcbPhEAegZJKcSggvuwrqJMuJD3jJ3q6PNE2KVXsuuYS4Kz -p umidata1

    查询helloworld51账户的权限:

4.将helloworld51的Owner和Active权限按照下表授权给helloworld52和helloworld53

  • 说明:这里有权重weight和阈值threshold,对于owner权限,helloworld52和helloworld53的weight都是1,而threshold为2,则说明owner权限需要,helloworld52和helloworld53一起签名操作才能够执行;对于active权限,helloworld52和helloworld53的weight都是1,而threshold为1,则说明active权限只需要helloworld52或helloworld52任何一个签名操作就能够执行。
4.1先设置helloworld51的owner权限
cleos set account permission helloworld51 owner '{"threshold":2,"keys":[],"accounts":[{"permission":{"actor":"helloworld52","permission":"owner"},"weight":1},{"permission":{"actor":"helloworld53","permission":"owner"},"weight":1}],"waits":[]}' -p helloworld51@owner

4.2设置helloworld51的active权限
 cleos set account permission helloworld51 active '{"threshold":1,"keys":[],"accounts":[{"permission":{"actor":"helloworld52","permission":"owner"},"weight":1},{"permission":{"actor":"helloworld53","permission":"owner"},"weight":1}],"waits":[]}' owner -p helloworld51@owner

再次查看helloworld51的账户权限

cleos get account helloworld51

5.分别给helloworld51、helloworld52、helloworld53转账100UMI

cleos push action eosio.token transfer '["eosio", "helloworld51","100.0000 UMI","INIT"]' -p eosio

cleos push action eosio.token transfer '["eosio", "helloworld52","100.0000 UMI","INIT"]' -p eosio
cleos push action eosio.token transfer '["eosio", "helloworld53","100.0000 UMI","INIT"]' -p eosio

分别查询三个账户的余额

cleos get account helloworld51

cleos get account helloworld52

cleos get account helloworld53

6.提交多重签名操作提案

假如helloworld51不在,要想通过helloworld52和helloworld53两个人来审批本属于helloworld51的操作,这就要比helloworld51本人操作要麻烦一点,需要新建一个提案。这个提案让helloworld51给helloworld52发送25个UMI代币,需要helloworld52和helloworld53一起用owner权限来签名。

cleos multisig propose 51to52 '[{"actor":"helloworld52","permission":"owner"},{"actor":"helloworld53","permission":"owner"}]' '[{"actor":"helloworld51","permission":"owner"}]' eosio.token transfer '{"from":"helloworld51","to":"helloworld52","quantity":"19.0000 UMI","memo":"test multisig"}' -p helloworld51

7.查看刚才创建的提案

cleos multisig review helloworld51 51to52 

8.查看提案审批情况

审批前

cleos get table eosio.msig helloworld51 approvals2

9.审批提案

提案创建完成以后,就需要helloworld52和helloworld52这两个账户分别进行审批,他们各自都需要使用自己的owner权限签名审批这个动作。

9.1helloworld52审批
cleos multisig approve helloworld51 51to52 '{"actor":"helloworld52","permission":"owner"}' -p helloworld52@owner

helloworld52审批查看提案审批结果

cleos get table eosio.msig helloworld51 approvals2

9.2helloworld52审批
cleos multisig approve helloworld51 51to52 '{"actor":"helloworld53","permission":"owner"}' -p helloworld53@owner

helloworld53审批查看提案审批结果

cleos get table eosio.msig helloworld51 approvals2

10.执行提案

cleos multisig exec helloworld51 51to52 -p helloworld51

11.验证结果

分别查询helloworld51、helloworld52、helloworld53账户的余额

cleos get  account helloworld51

cleos get  account helloworld52

cleos get  account helloworld53

附加

给账户添加权限

cleos set account permission helloworld11  publish '{"threshold":1,"keys":[{"key":"UMI8XVnaGMqTqTyBco9wrB2ED1vHytnw2LWczWDmA1rL47N5r8MQY","weight":1}],"accounts":[]}' active

缘雨 等1人收藏了本帖
最新回复 (2)
  • 管理员组 Surou 4月前
    0 引用 2
    忘加格式了吧~
  • 管理员组 夜小白 4月前
    0 引用 3
    surou 忘加格式了吧~
    再修改一下就好了
返回