生成账户 (Generating accounts)
表示账户 (Representing accounts)
使用 Namada SDK 表示账户非常简单。Namada 上的一个账户由其公钥和私钥定义(复数用于多重签名)。公钥用于标识账户,而私钥用于签署交易。在下面的代码片段中,我们使用公钥和私钥表示账户。
use namada_sdk::core::types::key::common::{PublicKey, SecretKey};
struct SimpleAccount {
public_key: PublicKey,
private_key: SecretKey
}对于多重签名账户,我们可以通过密钥的向量来表示它。
use namada_sdk::core::types::key::common::{PublicKey, SecretKey};
struct MultisigAccount {
public_keys: Vec<PublicKey>,
private_keys: Vec<SecretKey>
}多重签名账户,因为它们是通过链上交易初始化的,总是会向账本公开它们的公钥。但是,当密钥对以离线方式生成时,用户必须提交交易以公开其公钥。因此,在账户结构中添加字段 revealed 是很有帮助的。
use namada_sdk::core::types::key::common::{PublicKey, SecretKey};
struct Account {
public_key: PublicKey,
private_key: SecretKey,
revealed: bool
}揭示隐式账户的公钥 (Revealing the public key of an implicit account)
为了揭示隐式账户的公钥,用户必须向账本提交交易。
一旦公钥被揭示,该账户就可以用于签署交易。
Last updated