create account

HiveAuth client library by quochuy

View this thread on: hive.blogpeakd.comecency.com
· @quochuy ·
$450.55
HiveAuth client library
Yesterday, HiveAuth (formely Hive Authentication Services or HAS) has been released.  Hive Keychains, Peakd and Hive.Blog have released a new version that adds support to this new secure way of login yourself to a Hive frontend without having to enter your private key on a computer. All you need is a compatible wallet app (Hive Keychain) installed on your mobile phone.

@arcange is the person behind the HiveAuth project and has made available a HiveAuth server and a [wrapper library](https://peakd.com/hive-139531/@arcange/has-wrapper-library) that facilitate the integration into an existing app.

## HiveAuth in a nutshell
The basic idea of HiveAuth is to create a communication channel between an app (frontend such as Hive.Blog or Peakd) installed on your computer (or also your mobile phone) and a wallet app installed on your mobile phone. When authenticating yourself or performing an action that requires signing with your private key (post, comment, vote etc...), instead of giving your private key to the app, or instead of installing a browser extension (Hive Keychain) on a computer you don't trust, you can use the wallet app on your mobile phone.

The app makes a request to HiveAuth server which then transmit it to the mobile wallet app. The mobile wallet app then uses the key you already stored in it to sign the transaction and returns the signed data to the app via HiveAuth server. During this process, neither the app or HiveAuth server will know the private key. Only the trusted mobile wallet app will have the key.

## HiveAuth Client library
When I integrated HiveAuth to the Condenser, I took the opportunity to create my own wrapper library. It is based on @arcange's [HiveAuth Wrapper Library](https://peakd.com/hive-139531/@arcange/has-wrapper-library) but it's taking the event based approach to minimise the use of callback functions for more clarity and it also minimises the user of timeout and intervals internally. This refactoring of the library also allowed me to understand more how things work.

### Installation
The HiveAuth Client library is available on GitHub: https://github.com/quochuy/hive-auth-client

It's also available as an NPM package that can be installed to your project with the following command:
`yarn add hive-auth-client`

Then simply import it into your script:
`import HasClient from 'hive-auth-client';`

### Configuration
Once imported, you will need some little configuration. The following command, will instantiate the client class and define the hostname for the HiveAuth server to use:
`const client = new HasClient('hive-auth.arcange.eu', '', true);`

You will also need to configure some metadata to identify your app to the mobile wallet app:
```
const APP_META = {
    name: 'Hive Blog',
    description: 'Hive Blog',
    icon: 'https://hive.blog/images/hive-blog-logo.png',
};
```

Finally, you will have to create an `auth` object that will store authentication data for the user. This auth data is to identify your session with the HiveAuth server:
```
const auth = {
    username: undefined,
    token: undefined,
    expire: undefined,
    key: undefined,
};
```

### Authentication + Challenge
The first thing you'll need to do is handle the login to your app by requesting an authentication with the mobile wallet app and at the same time request a challenge to sign with a posting key (or any other type of private keys depending on what your app needs to do).

https://gist.github.com/quochuy/045bd6604aa9dd02bec088742e0b9bf3

The client library will auto-connect the websocket when attempting to send a message and will automatically attempt a reconnection if it is dropped.

### Broadcasting a transaction
Similarly to authenticating, to broadcast a transaction you just setup your event handlers first, then call `client.broadcast()`;

https://gist.github.com/quochuy/95ec5d5459d3a45c5616dd78f005d17e

## Documentations
My HiveAuth Client library will only help you handle communication between your app and the HiveAuth server. You can see the list of available methods and events on the NPM page:
https://www.npmjs.com/package/hive-auth-wrapper

For a complete integration, you still need to understand and handle the rest of the HiveAuth protocol. For that, checkout the HiveAuth documentations:
https://docs.hiveauth.com/
👍  , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , and 468 others
👎  ,
properties (23)
authorquochuy
permlinkhiveauth-client-library
categoryhive-139531
json_metadata"{"tags":["hive-139531","development","hiveauth","hiveprojects","hive","witness-update"],"users":["arcange"],"links":["https://peakd.com/hive-139531/@arcange/has-wrapper-library"],"app":"hiveblog/0.1","format":"markdown","description":"Description on the new client library for HiveAuth"}"
created2022-02-23 05:25:15
last_update2022-02-23 05:25:15
depth0
children21
last_payout2022-03-02 05:25:15
cashout_time1969-12-31 23:59:59
total_payout_value225.388 HBD
curator_payout_value225.161 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length4,315
author_reputation759,310,520,205,076
root_title"HiveAuth client library"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id110,731,785
net_rshares386,084,132,336,731
author_curate_reward""
vote details (534)
@amberkashif ·
$0.04
Does it mean we can connectvour hivevkeys to any wallet app we have?
👍  
properties (23)
authoramberkashif
permlinkre-quochuy-r7r992
categoryhive-139531
json_metadata{"tags":["hive-139531"],"app":"peakd/2022.02.4"}
created2022-02-23 11:29:33
last_update2022-02-23 11:29:33
depth1
children2
last_payout2022-03-02 11:29:33
cashout_time1969-12-31 23:59:59
total_payout_value0.020 HBD
curator_payout_value0.020 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length68
author_reputation116,238,002,324,595
root_title"HiveAuth client library"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id110,738,846
net_rshares35,516,265,387
author_curate_reward""
vote details (1)
@quochuy ·
No. Only Hive Keychain app at the moment.
properties (22)
authorquochuy
permlinkr7r9v1
categoryhive-139531
json_metadata{"app":"hiveblog/0.1"}
created2022-02-23 11:42:54
last_update2022-02-23 11:42:54
depth2
children1
last_payout2022-03-02 11:42:54
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length41
author_reputation759,310,520,205,076
root_title"HiveAuth client library"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id110,739,089
net_rshares0
@amberkashif ·
Ok.
properties (22)
authoramberkashif
permlinkre-quochuy-r7rb8e
categoryhive-139531
json_metadata{"tags":["hive-139531"],"app":"peakd/2022.02.4"}
created2022-02-23 12:12:21
last_update2022-02-23 12:12:21
depth3
children0
last_payout2022-03-02 12:12:21
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length3
author_reputation116,238,002,324,595
root_title"HiveAuth client library"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id110,739,617
net_rshares0
@arcange ·
$0.05
Thank you for all the hard work you did to make the HiveAuth launch a success.
👍  ,
properties (23)
authorarcange
permlinkre-quochuy-r7s70w
categoryhive-139531
json_metadata{"tags":["hive-139531"],"app":"peakd/2022.02.6"}
created2022-02-23 23:39:03
last_update2022-02-23 23:39:03
depth1
children0
last_payout2022-03-02 23:39:03
cashout_time1969-12-31 23:59:59
total_payout_value0.026 HBD
curator_payout_value0.026 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length78
author_reputation1,148,349,221,690,653
root_title"HiveAuth client library"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id110,755,600
net_rshares44,719,656,940
author_curate_reward""
vote details (2)
@borislavzlatanov ·
$0.08
> instead of giving your private key to the app, or instead of installing a browser extension (Hive Keychain) on a computer you don't trust

So is the main use case that you can perform actions on a computer that you don't trust? So you can for example have your phone with you and go to a friend's computer and log in to your own Hive account on their computer and perform actions without ever having to enter your private key on their computer?
👍  
properties (23)
authorborislavzlatanov
permlinkre-quochuy-r7r4xv
categoryhive-139531
json_metadata{"tags":["hive-139531"],"app":"peakd/2022.02.2"}
created2022-02-23 09:56:18
last_update2022-02-23 09:56:18
depth1
children8
last_payout2022-03-02 09:56:18
cashout_time1969-12-31 23:59:59
total_payout_value0.041 HBD
curator_payout_value0.041 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length446
author_reputation23,556,498,017,463
root_title"HiveAuth client library"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id110,736,888
net_rshares71,115,119,961
author_curate_reward""
vote details (1)
@quochuy ·
Or if you go on travel and need to access Hive from a computer in an Internet cafe.
👍  
properties (23)
authorquochuy
permlinkr7r58n
categoryhive-139531
json_metadata{"app":"hiveblog/0.1"}
created2022-02-23 10:03:00
last_update2022-02-23 10:03:00
depth2
children6
last_payout2022-03-02 10:03:00
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length83
author_reputation759,310,520,205,076
root_title"HiveAuth client library"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id110,736,998
net_rshares8,544,192,638
author_curate_reward""
vote details (1)
@borislavzlatanov ·
Yep, makes sense. And I get now how it is useful for that. I think it wasn't presented in that way, though (ability to use your Hive account on computers you don't trust), but rather as a new, standard way to log in, which didn't make sense to me as I didn't see how it improves the security of an app making a signing request directly to a wallet like Hive Keychain.
properties (22)
authorborislavzlatanov
permlinkre-quochuy-r7rhtj
categoryhive-139531
json_metadata{"tags":["hive-139531"],"app":"peakd/2022.02.2"}
created2022-02-23 14:34:30
last_update2022-02-23 14:34:30
depth3
children5
last_payout2022-03-02 14:34:30
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length367
author_reputation23,556,498,017,463
root_title"HiveAuth client library"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id110,742,959
net_rshares0
@smooth ·
$0.04
You shouldn't really trust even your own computer. It's very hard to prevent desktop and browser exploits.
👍  
properties (23)
authorsmooth
permlinkr7ruo3
categoryhive-139531
json_metadata{"app":"hiveblog/0.1"}
created2022-02-23 19:12:03
last_update2022-02-23 19:12:03
depth2
children0
last_payout2022-03-02 19:12:03
cashout_time1969-12-31 23:59:59
total_payout_value0.020 HBD
curator_payout_value0.021 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length106
author_reputation260,342,945,372,716
root_title"HiveAuth client library"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id110,749,865
net_rshares35,364,019,681
author_curate_reward""
vote details (1)
@ecency ·
Your content has been **voted** as a part of [Encouragement program](https://ecency.com/ecency/@good-karma/encouragement-program-continues-82eafcd10a299). Keep up the good work! <br><br>Use Ecency daily to boost your growth on platform! <br><br><b>Support Ecency</b><br>[Vote for new Proposal](https://hivesigner.com/sign/update-proposal-votes?proposal_ids=%5B197%5D&approve=true)<br>[Delegate HP and earn more](https://ecency.com/hive-125125/@ecency/daily-100-curation-rewards)
properties (22)
authorecency
permlinkre-2022223t52928216z
categoryhive-139531
json_metadata{"tags":["ecency"],"app":"ecency/3.0.16-welcome","format":"markdown+html"}
created2022-02-23 05:29:30
last_update2022-02-23 05:29:30
depth1
children0
last_payout2022-03-02 05:29:30
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length478
author_reputation630,676,919,199,283
root_title"HiveAuth client library"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id110,731,858
net_rshares0
@hivebuzz ·
Congratulations @quochuy! You have completed the following achievement on the Hive blockchain and have been rewarded with new badge(s):

<table><tr><td><img src="https://images.hive.blog/60x70/http://hivebuzz.me/@quochuy/upvotes.png?202202230720"></td><td>You distributed more than 100000 upvotes.<br>Your next target is to reach 105000 upvotes.</td></tr>
</table>

<sub>_You can view your badges on [your board](https://hivebuzz.me/@quochuy) and compare yourself to others in the [Ranking](https://hivebuzz.me/ranking)_</sub>
<sub>_If you no longer want to receive notifications, reply to this comment with the word_ `STOP`</sub>


To support your work, I also upvoted your post!


**Check out the last post from @hivebuzz:**
<table><tr><td><a href="/hive-122221/@hivebuzz/pum-202202-20"><img src="https://images.hive.blog/64x128/https://i.imgur.com/R2XacsJ.png"></a></td><td><a href="/hive-122221/@hivebuzz/pum-202202-20">Hive Power Up Month - Feedback from February day 20</a></td></tr></table>
properties (22)
authorhivebuzz
permlinknotify-quochuy-20220223t072322
categoryhive-139531
json_metadata{"image":["http://hivebuzz.me/notify.t6.png"]}
created2022-02-23 07:23:21
last_update2022-02-23 07:23:21
depth1
children0
last_payout2022-03-02 07:23:21
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length997
author_reputation369,374,582,916,091
root_title"HiveAuth client library"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id110,734,041
net_rshares0
@hivebuzz ·
Congratulations @quochuy! Your post has been a top performer on the Hive blockchain and you have been rewarded with the following badge:

<table><tr><td><img src="https://images.hive.blog/60x60/http://hivebuzz.me/badges/toppayoutday.png"></td><td>Post with the highest payout of the day.</td></tr>
</table>

<sub>_You can view your badges on [your board](https://hivebuzz.me/@quochuy) and compare yourself to others in the [Ranking](https://hivebuzz.me/ranking)_</sub>
<sub>_If you no longer want to receive notifications, reply to this comment with the word_ `STOP`</sub>



**Check out the last post from @hivebuzz:**
<table><tr><td><a href="/hive-122221/@hivebuzz/pum-202202-22"><img src="https://images.hive.blog/64x128/https://i.imgur.com/nSxk3aq.png"></a></td><td><a href="/hive-122221/@hivebuzz/pum-202202-22">Hive Power Up Month - Feedback from February day 22</a></td></tr></table>
properties (22)
authorhivebuzz
permlinknotify-quochuy-20220224t035353
categoryhive-139531
json_metadata{"image":["http://hivebuzz.me/notify.t6.png"]}
created2022-02-24 03:53:54
last_update2022-02-24 03:53:54
depth1
children0
last_payout2022-03-03 03:53:54
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length890
author_reputation369,374,582,916,091
root_title"HiveAuth client library"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id110,760,205
net_rshares0
@mnurhiver ·
this is very convenient for users, thanks to all friends who have worked hard to release it.
properties (22)
authormnurhiver
permlinkre-quochuy-2022224t05758350z
categoryhive-139531
json_metadata{"tags":["hive-139531","development","hiveauth","hiveprojects","hive","witness-update"],"app":"ecency/3.0.21-vision","format":"markdown+html"}
created2022-02-23 17:58:00
last_update2022-02-23 17:58:00
depth1
children0
last_payout2022-03-02 17:58:00
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length92
author_reputation666,555,540,685,831
root_title"HiveAuth client library"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id110,748,201
net_rshares0
@nicholasrichards ·
Thanks for the tutorial. I have to reblog.
properties (22)
authornicholasrichards
permlinkre-quochuy-2022223t164137997z
categoryhive-139531
json_metadata{"tags":["hive-139531","development","hiveauth","hiveprojects","hive","witness-update"],"app":"ecency/3.0.21-vision","format":"markdown+html"}
created2022-02-23 07:41:39
last_update2022-02-23 07:41:39
depth1
children0
last_payout2022-03-02 07:41:39
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length42
author_reputation2,514,308,607,606
root_title"HiveAuth client library"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id110,734,325
net_rshares0
@poshtoken ·
https://twitter.com/ilbiscom/status/1496380682800619520
<sub> The rewards earned on this comment will go directly to the person sharing the post on Twitter as long as they are registered with @poshtoken. Sign up at https://hiveposh.com.</sub>
properties (22)
authorposhtoken
permlinkre-quochuy-hiveauth-client-library-1654
categoryhive-139531
json_metadata"{"app":"Poshtoken 0.0.1"}"
created2022-02-23 07:06:45
last_update2022-02-23 07:06:45
depth1
children0
last_payout2022-03-02 07:06:45
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length243
author_reputation5,706,557,119,668,353
root_title"HiveAuth client library"
beneficiaries
0.
accountreward.app
weight10,000
max_accepted_payout1,000,000.000 HBD
percent_hbd0
post_id110,733,743
net_rshares0
@shohana1 ·
I really love experiencing updated versions and good to know that peaked now updated though I love using ecency for hive more.
👍  
properties (23)
authorshohana1
permlinkre-quochuy-2022225t5341628z
categoryhive-139531
json_metadata{"tags":["hive-139531","development","hiveauth","hiveprojects","hive","witness-update"],"app":"ecency/3.0.25-mobile","format":"markdown+html"}
created2022-02-24 23:34:15
last_update2022-02-24 23:34:15
depth1
children0
last_payout2022-03-03 23:34:15
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length126
author_reputation75,357,217,090,889
root_title"HiveAuth client library"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id110,784,326
net_rshares280,506,918
author_curate_reward""
vote details (1)
@urun ·
good job!
properties (22)
authorurun
permlinkre-quochuy-r7t4ag
categoryhive-139531
json_metadata{"tags":["hive-139531"],"app":"peakd/2022.02.6"}
created2022-02-24 11:37:27
last_update2022-02-24 11:37:27
depth1
children0
last_payout2022-03-03 11:37:27
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length9
author_reputation94,129,224,984,132
root_title"HiveAuth client library"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id110,768,505
net_rshares0