用hive.js实现给用户授权

in hive-180932 •  3 years ago 

一个A用户给另一位B用户授权后,B用户就可以直接使用A的帐户发帖和点赞等操作,至于能否转帐就看他授权的级别,一般是低级的posting授权。这个授权有两个参数account_authskey_auths,这两者略有区别,一个不能登录,另一个可以。

以下三篇帖子可以用做参考:
add posting auth
STEEM/HIVE 账户多签研究
steemit下多用户维护同一个公共账户

//此函数可以用于用户授权,更新介绍,更改密码等操作。
hive.broadcast.accountUpdate(wif, account, owner, active, posting, memoKey, jsonMetadata, function(err, result) {
  console.log(err, result)
})

///给用户授权account_auths 被授权用户可以直接使用授权用户发帖,点赞,但是不能登录!
let username = 'scisan'
let approved = 'cn-book' //被授权用户
let wif = '5Jbxxxxxx'  //active key
let s = await this.hive.api.getAccountsAsync([username])
let account = s[0]
let postingAuth = account.posting
postingAuth.account_auths.push([approved, postingAuth.weight_threshold])  //添加授权
let res = await this.hive.broadcast.accountUpdateAsync(wif, username, undefined, undefined,
        postingAuth, account.memo_key, account.json_metadata)
console.log(112, res)   

///给用户授权key_auths 被授权用户可以直接使用授权用户发帖,点赞,也可以登录!
let username = 'scisan'
let approved = 'STM8XLcxxxxxx4G' //被授权用户的posting公钥
let wif = '5Jbxxxxxx'  //active key
let s = await this.hive.api.getAccountsAsync([username])
let account = s[0]
let postingAuth = account.posting
postingAuth.key_auths.push([approved, postingAuth.weight_threshold])
let res = await this.hive.broadcast.accountUpdateAsync(wif, username, undefined, undefined,
        postingAuth, account.memo_key, account.json_metadata)
console.log(112, res)   

上面也介绍到accountUpdate还可用于更新介绍,更改密码,多签等操作,功能还是蛮强大的。

Authors get paid when people like you upvote their post.
If you enjoyed what you read here, create your account today and start earning FREE STEEM!
Sort Order:  
  ·  3 years ago 

厉害!!shop