Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

账户的重要信息变化时提示用户 #70

Open
jolestar opened this issue Jul 6, 2022 · 8 comments
Open

账户的重要信息变化时提示用户 #70

jolestar opened this issue Jul 6, 2022 · 8 comments
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@jolestar
Copy link
Member

jolestar commented Jul 6, 2022

普通交易执行后,用户 Account Resource 主要是 sequence_number 变化,以及 events handle 变化。但如果有其他的字段变化,说明账户的重要信息有变化。如下面的 Account 数据结构:

    struct Account has key {
        /// The current authentication key.
        /// This can be different than the key used to create the account
        authentication_key: vector<u8>,
        /// A `withdrawal_capability` allows whoever holds this capability
        /// to withdraw from the account. At the time of account creation
        /// this capability is stored in this option. It can later be
        /// "extracted" from this field via `extract_withdraw_capability`,
        /// and can also be restored via `restore_withdraw_capability`.
        withdrawal_capability: Option<WithdrawCapability>,
        /// A `key_rotation_capability` allows whoever holds this capability
        /// the ability to rotate the authentication key for the account. At
        /// the time of account creation this capability is stored in this
        /// option. It can later be "extracted" from this field via
        /// `extract_key_rotation_capability`, and can also be restored via
        /// `restore_key_rotation_capability`.
        key_rotation_capability: Option<KeyRotationCapability>,

        /// event handle for account balance withdraw event
        withdraw_events: Event::EventHandle<WithdrawEvent>,
        /// event handle for account balance deposit event
        deposit_events: Event::EventHandle<DepositEvent>,

        /// Event handle for accept_token event
        accept_token_events: Event::EventHandle<AcceptTokenEvent>,

        /// The current sequence number.
        /// Incremented by one each time a transaction is submitted
        sequence_number: u64,
    }
  • authentication_key: 如果 authentication_key 变化说明 authentication_key 被重置了。不过要注意,用户的第一次交易(sequence_number 为 0),authentication_key 会从空 bytes 赋值为真正的 authentication_key。
  • withdrawal_capability: 如果变为 Option::None 表明 WithdrawCapability 被代理了,拥有 WithdrawCapability 的合约可以该账户下 withdraw 任意 Token。
  • key_rotation_capability: 如果变为 Option::None 表明 KeyRotationCapability 被代理来,拥有 KeyRotationCapability 的合约可以代用户重置 authentication_key。
@jolestar jolestar added enhancement New feature or request help wanted Extra attention is needed labels Jul 6, 2022
@jolestar
Copy link
Member Author

jolestar commented Jul 6, 2022

比较方法类似于 #55

@jolestar
Copy link
Member Author

jolestar commented Jul 6, 2022

等下次 starcoin-framework 升级,starcoinorg/starcoin-framework#40 部署到主网后,还可以通过 Event 判断这几个字段的变化。

@wk3368
Copy link
Contributor

wk3368 commented Jul 6, 2022

最好在barnard上面提供一个scriptFunction,这样我可以根据dry run这个scriptfunction,来模拟变化,然后实现各种判断的逻辑。

否则不能保障写的逻辑是对的。

@WGB5445
Copy link

WGB5445 commented Jul 6, 2022

account execute-function -s 0xdaf8e186dc97ee9ba6971b08115d4dc2 --function 0x1::Account::rotate_authentication_key --arg x"39353fabc51eb1b472c2c5ef6e74c91bc04c62b99fd053ac31d21d6e06619aed" -b

这是一个例子
可以在 cookbook 中找到详细步骤: https://starcoinorg.github.io/starcoin-cookbook/zh/docs/getting-started/accounts/rotate-authentication-key

@jolestar
Copy link
Member Author

jolestar commented Jul 6, 2022

后面两个没办法直接提供 script,需要有个应用的场景去构造合约完成。先考虑第一个 authentication_key 的变化,后两个看看能不能想个例子。

@uvd
Copy link

uvd commented Jul 13, 2022

https://uvd.github.io/dapps/#/game/free-bank WithdrawCapability 被代理的的提示演示例子这里做好了,这是我的个人测试地址,extract 是交给合约代理,应该是要重点提醒了,restore,是退出合约代理, withdraw ,deposit是取出自己的 WithdrawCapability 和合约地址互换 token 用于测试这种情况只需要正确提示变化量就行,但是发现目前的一个bug是,假如是自己地址地址不持有的币,转进来的时候不会提示新币的变化量

@uvd
Copy link

uvd commented Jul 13, 2022

https://uvd.github.io/dapps/#/game/reset-auth 重置私钥的测试地址,auth key的 格式个公钥的一样
这是例子 可以这个填 0x可以不要 0x04af83b19668c6d541d0b2ef33a653b7deb616291d17fb94046c37fa156e3113

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

4 participants