RE: RE: Hivejs开发实战指南
You are viewing a single comment's thread from:

RE: Hivejs开发实战指南

Words
19
Reading
1 min
Listen
Play
8M

使用用户名和发帖密钥(或主密码)登录。

let account = "lucky"
let privWif = "5tikkkxxxxxx"
let result = await hive.api.getAccountsAsync([account])
if(result.length === 0){  
  return ('用户不存在!') 
}

//判断是否私钥
let hiveres = hive.auth.isWif(privWif)
let postWif = privWif
if(hiveres !== true){
  //获取发贴私钥(从主密码)
  let role = ["posting"]
  postWif = hive.auth.toWif(account, privWif, role)
} 

//公私钥是否配对
let pubWif = result[0].posting.key_auths[0][0]
let isvalid3 = hive.auth.wifIsValid(postWif, pubWif)
if(isvalid3 === true){
  return ({
    username: account,
    wif: postWif,
    avatar: `https://images.hive.blog/u/${account}/avatar`
  })
} else {
  return ('密钥错误!')
}
@lemooljiang: 使用用户名和发帖密钥(或主密码)登录。 | Ecency