cosmos 多签/多重签名
- 生成两个普通账户
nscli keys add mykeyname
nscli keys add mykeyname2
- 生成多签账户
lee
,该账户对外转账需要mykeyname
和mykeyname2
的签名
nscli keys add --multisig=mykeyname,mykeyname2 --multisig-threshold=2 lee
- 给多签账户转一点币,便于测试
nscli tx send $(nscli keys show -a alice) $(nscli keys show -a lee) 10bde --chain-id=namechain
- 创建一笔多签交易:多签账户对bob转2bde
nscli tx send $(nscli keys show -a lee) $(nscli keys show -a bob) 2bde --generate-only --chain-id=namechain > unsignedTx.json
unsignedTx.json
{
"type": "cosmos-sdk/StdTx",
"value": {
"msg": [{
"type": "cosmos-sdk/MsgSend",
"value": {
"from_address": "cosmos1zmyxa4a26mnm7vd9r9vr9j73dzlrjxh4ld9s87",
"to_address": "cosmos1y23vxhglf798838xjp048h8em0xk0q6c05aqzp",
"amount": [{
"denom": "bde",
"amount": "2"
}]
}
}],
"fee": {
"amount": [],
"gas": "200000"
},
"signatures": null,
"memo": ""
}
}
- 账户1
mykeyname
签名
nscli tx sign unsignedTx.json --from=$(nscli keys show -a mykeyname) --multisig=$(nscli keys show -a lee) --chain-id=namec
hain > signature1.json
{
"pub_key": {
"type": "tendermint/PubKeySecp256k1",
"value": "A6h0GxSoYceL0azPbQbsFPOTfl6KRzYe9lm5yRNWeU97"
},
"signature": "uerHnA5MtXftQ5RUbGgPNMTaT4JwIX3lg0JkwA7N5RtDA2OXc+G01h/aThs8mt+QmZ3ucy70/ssd7EjctSU5Kw=="
}
- 账户2
mykeyname2
签名
nscli tx sign unsignedTx.json --from=$(nscli keys show -a mykeyname2) --multisig=$(nscli keys show -a lee) --chain-id=namec
hain > signature2.json
{
"pub_key": {
"type": "tendermint/PubKeySecp256k1",
"value": "AhozeSl91stP+jSrP08UjsPD166P0uvo7QIHUA7XH5Ce"
},
"signature": "vkeh7QeVNJodqGdMYf3hhQiEWbTtT1TeRXC1kceqqSx/g6XlFCLwj6P0oP7QRmYKItgNW2e/2HyvP/ieAJXZDw=="
}
- 合并签名
nscli tx multisign unsignedTx.json lee signature1.json signature2.json --chain-id=namechain > signedTx.json
{
"type": "cosmos-sdk/StdTx",
"value": {
"msg": [{
"type": "cosmos-sdk/MsgSend",
"value": {
"from_address": "cosmos1zmyxa4a26mnm7vd9r9vr9j73dzlrjxh4ld9s87",
"to_address": "cosmos1y23vxhglf798838xjp048h8em0xk0q6c05aqzp",
"amount": [{
"denom": "bde",
"amount": "2"
}]
}
}],
"fee": {
"amount": [],
"gas": "200000"
},
"signatures": [{
"pub_key": {
"type": "tendermint/PubKeyMultisigThreshold",
"value": {
"threshold": "2",
"pubkeys": [{
"type": "tendermint/PubKeySecp256k1",
"value": "A6h0GxSoYceL0azPbQbsFPOTfl6KRzYe9lm5yRNWeU97"
}, {
"type": "tendermint/PubKeySecp256k1",
"value": "AhozeSl91stP+jSrP08UjsPD166P0uvo7QIHUA7XH5Ce"
}]
}
},
"signature": "CgUIAhIBwBJAuerHnA5MtXftQ5RUbGgPNMTaT4JwIX3lg0JkwA7N5RtDA2OXc+G01h/aThs8mt+QmZ3ucy70/ssd7EjctSU5KxJAvkeh7QeVNJodqGdMYf3hhQiEWbTtT1TeRXC1kceqqSx/g6XlFCLwj6P0oP7QRmYKItgNW2e/2HyvP/ieAJXZDw=="
}],
"memo": ""
}
}
- 广播交易
nscli tx broadcast signedTx.json
多重签名原理参考:
https://www.ipfsbi.com/%E6%AF%94%E7%89%B9%E5%B8%81%E7%9A%84%E5%A4%9A%E9%87%8D%E7%AD%BE%E5%90%8D/
posted on 2020-09-16 10:46 angry-baby 阅读(494) 评论(0) 编辑 收藏 举报