create account

NPM module for Hive Keychain by therealwolf

View this thread on: hive.blogpeakd.comecency.com
· @therealwolf ·
$12.48
NPM module for Hive Keychain
Greetings #Hivers,

I've created a small Keychain helper for myself a while ago and recently converted it to an npm module to make it easier for other devs to integrate Keychain into their websites. Seriously, just install it and you're good to go.

> https://www.npmjs.com/package/@hiveio/keychain

> https://gitlab.syncad.com/hive/keychain-node

## Example Code

```
import {keychain, isKeychainInstalled, hasKeychainBeenUsed} from '@hiveio/keychain'

const {success, msg, cancel, notInstalled, notActive} = await keychain(window, 'requestTransfer', 'test', 'therealwolf', 5, 'test memo', 'HIVE')

// All good
if(success) {
 // do your thing
}
// User didn't cancel, so something must have happened
else if(!cancel) {
  if(notActive) {
    // alert('Please allow Keychain to access this website')
  } else if(notInstalled) {
    // alert('Please install Keychain')
  } else {
    // error happened - check msg
  }
}
```

## Explanation

- `keychain`: run a specific keychain function
- `isKeychainInstalled`: checks whether keychain is installed and can be found within the window object.
- `hasKeychainBeenUsed`: checks whether a key/value inside the localStorage exists, which means Keychain has been used before, but isn't active. That can happen if extensions have to be activated per site.

- `notInstalled`: Return boolean from `keychain` with same logic as `isKeychainInstalled`
- `notActive`: Return boolean from `keychain` with same logic as `hasKeychainBeenUsed`
- `cancel`: Return boolean from `keychain` which indicates whether the Keychain popup has been closed, thus cancelled. Should be ignored.
- `success`: Return boolean from `keychain` which indicates whether the transaction was successful. Will be false in case of `cancel`.
- `msg`: Return string from `keychain` which can be an error.

For the normal workflow, you don't need to use `isKeychainInstalled` or `hasKeychainBeenUsed` as it's automatically checked when running `keychain`. These functions mostly matter for UX purposes.

---

Happy coding!
👍  , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , and 187 others
properties (23)
authortherealwolf
permlinknpm-module-for-hive-keychain
categoryhive-139531
json_metadata{"app":"peakd/2020.11.4","format":"markdown","tags":["hive","hivedevs","leofinance"],"users":["hiveio"],"links":["/trending/hivers","https://www.npmjs.com/package/@hiveio/keychain","https://gitlab.syncad.com/hive/keychain-node"]}
created2020-12-02 10:19:03
last_update2020-12-02 10:19:03
depth0
children5
last_payout2020-12-09 10:19:03
cashout_time1969-12-31 23:59:59
total_payout_value6.698 HBD
curator_payout_value5.786 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length2,026
author_reputation581,692,974,428,498
root_title"NPM module for Hive Keychain"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id100,776,875
net_rshares55,388,403,461,425
author_curate_reward""
vote details (251)
@hivebuzz ·
Congratulations @therealwolf! 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/@therealwolf/upvotes.png?202012040546"></td><td>You distributed more than 96000 upvotes. Your next target is to reach 97000 upvotes.</td></tr>
</table>

<sub>_You can view your badges on [your board](https://hivebuzz.me/@therealwolf) 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>



**Do not miss the last post from @hivebuzz:**
<table><tr><td><a href="/hive-106258/@hivebuzz/hivefest5-badge"><img src="https://images.hive.blog/64x128/https://i.imgur.com/YctqirB.png"></a></td><td><a href="/hive-106258/@hivebuzz/hivefest5-badge">The new HiveFest⁵ Attendee badge is waiting for you</a></td></tr><tr><td><a href="/hivebuzz/@hivebuzz/pud-202012-feedback"><img src="https://images.hive.blog/64x128/https://i.imgur.com/zHjYI1k.jpg"></a></td><td><a href="/hivebuzz/@hivebuzz/pud-202012-feedback">Feedback from the December 1st Hive Power Up Day</a></td></tr></table>
properties (22)
authorhivebuzz
permlinkhivebuzz-notify-therealwolf-20201204t061344000z
categoryhive-139531
json_metadata{"image":["http://hivebuzz.me/notify.t6.png"]}
created2020-12-04 06:13:42
last_update2020-12-04 06:13:42
depth1
children0
last_payout2020-12-11 06:13:42
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_length1,220
author_reputation370,789,792,960,723
root_title"NPM module for Hive Keychain"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id100,804,072
net_rshares0
@omarrojas ·
Grateful for the evaluations of my publications. Successes in your Healing work. With my 68 years of age I have learned a lot in hive. Hugs from Omar Gustavo Rojas Ortiz from Cumaná-Venezuela.
properties (22)
authoromarrojas
permlinkre-therealwolf-qkriw9
categoryhive-139531
json_metadata{"tags":["hive-139531"],"app":"peakd/2020.11.4"}
created2020-12-03 12:05:00
last_update2020-12-03 12:05:00
depth1
children0
last_payout2020-12-10 12:05: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_length192
author_reputation419,036,938,754,034
root_title"NPM module for Hive Keychain"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id100,792,636
net_rshares0
@sanjeevm ·
An idea on my mind on a dapp - offersworld.com, that would list all offers from local shops, validity, and will disappear after validity. So the dapp rewards hive to consumers, who buy through this ( some kind of authentication to make sure, they used the code from the site when they bought physically). So let's say, if we continuously reward consumers, then publishers ( local shops ) will be more and then adds can be built ( in fact designed from beginning). And offers may be shown based on user local. 

What do you think ?
properties (22)
authorsanjeevm
permlinkre-therealwolf-qkpkxk
categoryhive-139531
json_metadata{"tags":["hive-139531"],"app":"peakd/2020.11.4"}
created2020-12-02 10:53:45
last_update2020-12-02 10:53:45
depth1
children0
last_payout2020-12-09 10:53: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_length530
author_reputation694,329,052,853,347
root_title"NPM module for Hive Keychain"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id100,777,150
net_rshares0
@simplegame ·
This is super helpful
work like this is why you are one of my fav Witnesses.
sending it over to our front-end devs right now.
properties (22)
authorsimplegame
permlinkre-therealwolf-2020122t123313868z
categoryhive-139531
json_metadata{"tags":["hive","hivedevs","leofinance"],"app":"ecency/3.0.10-vision","format":"markdown+html"}
created2020-12-02 19:33:15
last_update2020-12-02 19:33:15
depth1
children0
last_payout2020-12-09 19:33: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_length125
author_reputation128,644,944,703,506
root_title"NPM module for Hive Keychain"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id100,784,029
net_rshares0
@stoodkev · (edited)
$0.54
Good work! I've added a link to the module to Keychain documentation.
👍  
properties (23)
authorstoodkev
permlinkre-therealwolf-qkq0er
categoryhive-139531
json_metadata{"tags":["hive-139531"],"app":"peakd/2020.11.4"}
created2020-12-02 16:28:06
last_update2020-12-02 16:28:42
depth1
children0
last_payout2020-12-09 16:28:06
cashout_time1969-12-31 23:59:59
total_payout_value0.272 HBD
curator_payout_value0.272 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length69
author_reputation190,232,841,750,255
root_title"NPM module for Hive Keychain"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id100,781,569
net_rshares3,306,378,075,610
author_curate_reward""
vote details (1)