LoginSignup
0

More than 5 years have passed since last update.

EOS のアカウント・ロール・権限 基本編

Last updated at Posted at 2018-12-03

EOS にはロールベースの権限仕組みがあります。基本的な使い方を調査してみました。

アカウント作成

まずアカウント作成時は、owneractiveロールに紐づくキーペアのパブリックキーを指定する必要があります。

# cleos create account 作成者アカウント 新しいアカウント名 ownerに紐付くパブリックキー [activeに紐づくパブリックキー] 
$ cleos create account eosio testuser EOS7PFNHZh3FbeHtSkwAqoQ2yCTzqZktzzuSWQCTBgfTE2RVZLoEj
executed transaction: f115efc2c7eeff5115a5c5cf8cce13e5d8bf9c04ee4a76845770a90cecd5300b  200 bytes  1497 us
#         eosio <= eosio::newaccount            {"creator":"eosio","name":"testuser","owner":{"threshold":1,"keys":[{"key":"EOS7PFNHZh3FbeHtSkwAqoQ2...
warning: transaction executed locally, but may not be confirmed by the network yet         ]

作成者アカウントを使って、新しいアカウントを作成する必要があります。

active に紐づくパブリックキーを省略された場合は、owneractive と両方に ownerに紐づくパブリックキー を紐づくようになります。

アカウント情報を確認すると、owneractiveに同じキーを紐付いていることを確認出来ます。

$ cleos get account testuser
created: 2018-12-02T20:46:24.000
permissions:
     owner     1:    1 EOS7PFNHZh3FbeHtSkwAqoQ2yCTzqZktzzuSWQCTBgfTE2RVZLoEj
        active     1:    1 EOS7PFNHZh3FbeHtSkwAqoQ2yCTzqZktzzuSWQCTBgfTE2RVZLoEj

説明

  • activeのほうがインデントされていることは、owner が active の親権限になっていること
  • owner 1 の数値 1 の意味は、owner権限の閾値は 1 であること。1 EOS7PF...oEj1 の意味は、そのキーペアの重み係数が 1 であること。この場合は、そのキーペアでサインすれば owner 権限を使えること

アカウント編集

仮に最初アカウント作成する時、1つのキーを指定して、作成した後 owner 権限に別のキーを設定したいとします。
ownerキーを変更する為に、owner権限で実行する必要があります

# cleos set account permission 編集対象アカウント 権限名 authority [parent]
$ cleos set account permission testuser owner EOS7Uzo6MoGi2PcF6CG269PzNRbTZuRwgmgUFwTU9NhRNCPoXZdzW -p testuser@owner
executed transaction: 8a7aeb8fad97a59c973c87dbde682e8bbf5f06647e87a1d3d4a8ea1dae086492  160 bytes  550 us
#         eosio <= eosio::updateauth            {"account":"testuser","permission":"owner","parent":"","auth":{"threshold":1,"keys":[{"key":"EOS7Uzo...
warning: transaction executed locally, but may not be confirmed by the network yet         ]

再度アカウント情報を確認すると、owner キーが変更されたことを確認出来ます。

$ cleos get account testuser
created: 2018-12-02T20:46:24.000
permissions:
     owner     1:    1 EOS7Uzo6MoGi2PcF6CG269PzNRbTZuRwgmgUFwTU9NhRNCPoXZdzW
        active     1:    1 EOS7PFNHZh3FbeHtSkwAqoQ2yCTzqZktzzuSWQCTBgfTE2RVZLoEj

カスタムロールの設定方法

アカウントのデフォルトowneractiveロール以外に、他のロールも設定出来ます。

トークンを送金できるるロールを設定したいとします。

$ cleos set account permission testuser trans EOS5fqSZBUYGVXBntM9K9VE88ymQ5nEgBXJswVdqtyW4LwY3zwaf3
executed transaction: 0dff47a2c73ef0bc2d9cbccec05d856dd5ce7daf0a0030060a5e09d36012d3eb  160 bytes  278 us
#         eosio <= eosio::updateauth            {"account":"testuser","permission":"trans","parent":"active","auth":{"threshold":1,"keys":[{"key":"E...
warning: transaction executed locally, but may not be confirmed by the network yet         ]

アカウント情報を確認すると、下記になります。

$ cleos get account testuser
created: 2018-12-02T20:46:24.000
permissions:
     owner     1:    1 EOS7Uzo6MoGi2PcF6CG269PzNRbTZuRwgmgUFwTU9NhRNCPoXZdzW
        active     1:    1 EOS7PFNHZh3FbeHtSkwAqoQ2yCTzqZktzzuSWQCTBgfTE2RVZLoEj
           trans     1:    1 EOS5fqSZBUYGVXBntM9K9VE88ymQ5nEgBXJswVdqtyW4LwY3zwaf3

trans の親ロールが active になっていることを確認出来ます。
これだけでは、まだ trans 権限で送金出来ません。
以下のように、eosio.tokentransfer アクションを実行する権限を trans ロールに任せるように設定する必要があります。

# cleos set action permission [OPTIONS] account code type requirement
$ cleos set action permission testuser eosio.token transfer trans
executed transaction: 993fe8e4fdacb26034cea93a21a2d691bb1289f3c71d046f2211353155f5035f  128 bytes  790 us
#         eosio <= eosio::linkauth              {"account":"testuser","code":"eosio.token","type":"transfer","requirement":"trans"}
warning: transaction executed locally, but may not be confirmed by the network yet         ]

これで trans 権限を使って送金してみます。
最後の testuser@trans を使っていることを注意

$ cleos push action eosio.token transfer '["testuser", "bob", "50.0000 EOS", "try use trans"]' -p testuser@trans
executed transaction: 156907b0254d0417a412e47feb8dfaac8472aa30fd72f1222e4f8616d96ab391  144 bytes  2897 us
#   eosio.token <= eosio.token::transfer        {"from":"testuser","to":"bob","quantity":"50.0000 EOS","memo":"try use trans"}
#      testuser <= eosio.token::transfer        {"from":"testuser","to":"bob","quantity":"50.0000 EOS","memo":"try use trans"}
#           bob <= eosio.token::transfer        {"from":"testuser","to":"bob","quantity":"50.0000 EOS","memo":"try use trans"}
warning: transaction executed locally, but may not be confirmed by the network yet         ]

trans権限でも正常に送金出来ました。

権限の付与を削除したい場合

上記は設定する方法ですが、権限を削除したい場合は、 NULL を渡す形になります。

$ cleos set account permission testuser trans NULL
executed transaction: 5a15aff836f723c14a4b7cdd51083e5578a7e612db5637f8cf240d1e34f53391  112 bytes  617 us
#         eosio <= eosio::deleteauth            {"account":"testuser","permission":"trans"}
warning: transaction executed locally, but may not be confirmed by the network yet         ]

アカウント確認すると、transロールが削除されたことを確認出来ます。

$ cleos get account testuser
created: 2018-12-02T20:46:24.000
permissions:
     owner     1:    1 EOS7Uzo6MoGi2PcF6CG269PzNRbTZuRwgmgUFwTU9NhRNCPoXZdzW
        active     1:    1 EOS7PFNHZh3FbeHtSkwAqoQ2yCTzqZktzzuSWQCTBgfTE2RVZLoEj

まとめ

EOS の権限設定は結構柔軟に設定できるので、より実用的になっていると思います。

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0