# hive-uri

> Hive URI parser and encoder

Latest version **0.2.8** (published 2025-06-12) · MIT license · 0 weekly downloads

## Install

```sh
npm install hive-uri
pnpm add hive-uri
yarn add hive-uri
bun add hive-uri
```

## Health

**Score 30/100 (F)** — status: maintenance-mode.

Positive: has types; no vulnerabilities.

Warnings: low downloads; no esm support; pre 1.0.

Negative: stale; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.2.8 |
| Published | 2025-06-12 |
| First published | 2020-03-20 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 21.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Maintainers | feruzm, esteem.app |

## Links

- npm: https://www.npmjs.com/package/hive-uri
- npm.io page: https://npm.io/package/hive-uri

## Dependencies (1)

- [url-parse](https://npm.io/package/url-parse.md) ^1.5.10

## Recent versions

- 0.2.8 (latest) — 2025-06-12
- 0.2.7 — 2025-06-10
- 0.2.6 — 2025-06-10
- 0.2.5 — 2023-09-07
- 0.2.4 — 2022-06-28
- 0.2.3 — 2021-02-18
- 0.2.2 — 2020-03-20
- 0.2.1 — 2020-03-20
- 0.2.0 — 2020-03-20
- 0.1.0 — 2020-03-20

## README

Hive URI protocol
==================

Protocol facilitating signing of hive transactions. Meant to be implemented by secure Hive wallet applications.

This repository contains both the specification and a zero dependency reference implementation that works in node.js and most browsers.


Installation
------------

Via npm or yarn:

```
npm install hive-uri
yarn add hive-uri
```

Manually: clone the repository and run `make`, this will place the built lib in `lib/index.js`.


Example usage
-------------

Encoding operations:

```js
const hiveuri = require('hive-uri')

hiveuri.encodeOp(['vote', {voter: 'foo', author: 'bar', permlink: 'baz', weight: 10000}])
// hive://sign/op/WyJ2b3RlIix7InZvdGVyIjoiZm9vIiwiYXV0aG9yIjoiYmFyIiwicGVybWxpbmsiOiJiYXoiLCJ3ZWlnaHQiOjEwMDAwfV0.

hiveuri.encodeOps([
    ['vote', {voter: 'foo', author: 'bar', permlink: 'baz', weight: 10000}],
    ['transfer', {from: 'foo', to: 'bar', amount: '10.000 HIVE', memo: 'baz'}]
], {callback: 'https://example.com/wallet?tx={{id}}'})
// hive://sign/ops/W1sidm90ZSIseyJ2b3RlciI6ImZvbyIsImF1dGhvciI6ImJhciIsInBlcm1saW5rIjoiYmF6Iiwid2VpZ2h0IjoxMDAwMH1dLFsidHJhbnNmZXIiLHsiZnJvbSI6ImZvbyIsInRvIjoiYmFyIiwiYW1vdW50IjoiMTAuMDAwIFNURUVNIiwibWVtbyI6ImJheiJ9XV0.?cb=aHR0cHM6Ly9leGFtcGxlLmNvbS93YWxsZXQ_dHg9e3tpZH19
```

Decoding and resolving hive:// links (for wallet implementers):

```js
const hiveuri = require('hive-uri')

// parse the hive:// link
const parsed = hiveuri.decode(link)

// resolve the decoded tx and params to a signable tx
let {tx, signer} = hiveuri.resolveTransaction(parsed.tx, parsed.params, {
    // e.g. from a get_dynamic_global_properties call
    ref_block_num: 1234,
    ref_block_prefix: 5678900,
    expiration: '2020-01-01T00:00:00',
    // accounts we are able to sign for
    signers: ['foo', 'bar'],
    // selected signer if none is asked for by the params
    preferred_signer: 'foo',
})

// sign broadcast the transaction to the network
let signature = signTx(tx, myKeys[signer])
let confirmation
if (!parsed.params.no_broadcast) {
    tx.signatures = [signature]
    confirmation = broadcastTx(tx)
}

// redirect to the callback if set
if (parsed.params.callback) {
    let url = hiveuri.resolveCallback(parsed.params.callback, {
        sig: signature,
        id: confirmation.id,
        block: confirmation.block_num,
        txn: confirmation.txn_num,
    })
    redirectTo(url)
}
```

---

Specification
=============

A protocol that allows Hive transactions and operations to be encoded into links that can be shared across applications and devices to sign transactions without implementers having to reveal their private key.


Actions
-------

  * `hive://sign/tx/<base64u(JSON-encoded tx)>`
    Sign an arbitrary transaction.
  * `hive://sign/op/<base64u(JSON-encoded op)>`
    As above but constructs a transaction around the operation before signing.
  * `hive://sign/ops/<base64u(JSON-encoded op array)>`
    As above but allows multiple operations as an array.
  * `hive://sign/msg/<base64u(JSON-encoded message)>`
    Sign an arbitrary messages with given authority.
  * `hive://sign/<operation_name>[/operation_params..]`
    Action aliases, see the "Specialized actions" section for more info.

To facilitate re-usable signing URIs the implementation allows for a set of placeholder variables that can be used in a signing payload.

  * `__signer` - Replaced with the username of the signer
  * `__expiration` - Replaced with current time plus some padding to allow the transaction to be broadcast*
  * `__ref_block_num` - Reference block number*
  * `__ref_block_prefix` - Reference block id*

*Reasonable values are up to the implementer, suggested expiry time is 60 seconds ahead of rpc node time and the reference block set to the current head block.



Parameters
----------

Params are global to all actions and encoded as query string params.

  * `s` (signer) - Preferred signer, if the implementer has multiple signing keys available it should pre-fill the correct authority. If the implementer does not have a key for the preferred signer a warning should be shown to the user. If omitted the implementer may auto select a signer based on the transaction parameters.

  * `nb` (no_broadcast) - If set the implementer should only sign the transaction and pass the signature back in the callback.

  * `cb` (callback) - Base64u encoded url that will be redirected to when the transaction has been signed. The url also allows some templating, see the callback section below for more info.

  * `a` (authority) - Preferred signing authority.

Params uses short names to save space in encoded URIs.


Callbacks
---------

Callbacks should be redirected to once the transaction has been accepted by the network. If the callback url is a web link only `https` should be allowed.

The callbacks also allow simple templating with some response parameters, the templating format is `{{<param_name>}}`, e.g. `https://myapp.com/wallet?tx={{id}}&included_in={{block}}` or `mymobileapp://signed/{{sig}}`

Callback template params:

  * `sig` - Hex-encoded string containing the 65-byte transaction signature
  * `id` - Hex-encoded string containing the 20-byte transaction hash*
  * `block` - The block number the transaction was included in*
  * `txn` - The block transaction index*
  * `data` - Arbitrary message/data

*Will not be available if the `nb` param was set for the action.



Base64u
-------

An URL-safe version base64 where `+` is replaced by `-`, `/` by `_` and the `=` padding by `.`.

```
base64
SGn+dGhlcmUh/k5pY2X+b2b+eW91/nRv/mRlY29kZf5tZf46KQ==
base64u
SGn-dGhlcmUh_k5pY2X-b2b-eW91_nRv_mRlY29kZf5tZf46KQ..
```

JavaScript implementation:

```js
b64u_lookup = {'/': '_', '_': '/', '+': '-', '-': '+', '=': '.', '.': '='}
b64u_enc = (str) => btoa(str).replace(/(\+|\/|=)/g, (m) => b64u_lookup[m])
b64u_dec = (str) => atob(str.replace(/(-|_|\.)/g, (m) => b64u_lookup[m]))
```


Specialized actions
-------------------

To keep the length of the URIs short, and the QR code size manageable, some common operations have aliases. See list below for supported aliases, params noted in operation payloads using the format `{{param_name}}` and optional (`[param_name]`) params should be filled with empty strings unless otherwise specified:

### Transfer tokens

Action: `hive://sign/transfer/<username>/<amount>[/memo]`

Params:

  * `username` - User that should be followed by `__signer`
  * `amount` - Amount to transfer, e.g. `1.000 HIVE`
  * `memo` - Base64u encoded memo, optional.

Operation:

```json
["transfer", {
  "from": "__signer",
  "to": "{{username}}",
  "amount": "{{amount}}",
  "memo": "{{memo}}"
}]
```

### Follow user

Action: `hive://sign/follow/<username>`

Params:

  * `<username>` - User that should be followed by `__signer`.

Operation:

```json
["custom_json", {
  "required_auths": [],
  "required_posting_auths": ["__signer"],
  "id": "follow",
  "json": "[\"follow\",{\"follower\":\"__signer\",\"following\":\"{{username}}\",\"what\":[\"blog\"]}]"
}]
```


Examples
--------

Example usage of the protocol along with data for every step that can be used in tests. Examples assumes a `__signer` of `foo` a `__expiration` of `1970-01-01T00:00:00` and `__ref_block_num`, `__ref_block_prefix` set to `0` unless otherwise stated.

### Send a limit order

Might be requested from a trading app, here we don't use any templating since we never want the transaction to be reusable.

Transaction:

```json
{
  "ref_block_num": 48872,
  "ref_block_prefix": 1543858519,
  "expiration": "2018-05-29T13:17:39",
  "extensions": [],
  "operations": [
    ["limit_order_create2", {
      "owner": "foo",
      "orderid": 1,
      "amount_to_sell": "10.000 HIVE",
      "fill_or_kill": false,
      "exchange_rate": {"base": "1.000 HIVE", "quote": "0.420 HBD"},
      "expiration": "2018-05-30T00:00:00"
    }]
  ]
}
```

Parameters:

```json
{
  "signer": "foo",
  "callback": "https://hive.trader/sign_callback?id={{id}}"
}
```

Encoded:

```
hive://sign/tx/eyJyZWZfYmxvY2tfbnVtIjo0ODg3MiwicmVmX2Jsb2NrX3ByZWZpeCI6MTU0Mzg1ODUxOSwiZXhwaXJhdGlvbiI6IjIwMTgtMDUtMjlUMTM6MTc6MzkiLCJleHRlbnNpb25zIjpbXSwib3BlcmF0aW9ucyI6W1sibGltaXRfb3JkZXJfY3JlYXRlMiIseyJvd25lciI6ImZvbyIsIm9yZGVyaWQiOjEsImFtb3VudF90b19zZWxsIjoiMTAuMDAwIFNURUVNIiwiZmlsbF9vcl9raWxsIjpmYWxzZSwiZXhjaGFuZ2VfcmF0ZSI6eyJiYXNlIjoiMS4wMDAgU1RFRU0iLCJxdW90ZSI6IjAuNDIwIFNCRCJ9LCJleHBpcmF0aW9uIjoiMjAxOC0wNS0zMFQwMDowMDowMCJ9XV19?s=foo&cb=aHR0cHM6Ly9zdGVlbS50cmFkZXIvc2lnbl9jYWxsYmFjaz9pZD17e2lkfX0.
```

### Witness vote

Reusable witness vote URI, e.g. for a "Vote for me!" QR code t-shirt.

Operation:

```json
["account_witness_vote", {
  "account": "__signer",
  "witness": "jesta",
  "approve": true
}]
```

Encoded:

```
hive://sign/op/WyJhY2NvdW50X3dpdG5lc3Nfdm90ZSIseyJhY2NvdW50IjoiX19zaWduZXIiLCJ3aXRuZXNzIjoiamVzdGEiLCJhcHByb3ZlIjp0cnVlfV0.
```


### Multisig

To sign for an account setup with multiple authorities a central service can act as a transaction facilitator using the `nb` (no_broadcast) option.

In the following scenario the account `foo` is setup with an active authority that has three account auths belonging to `bob`, `alice` and `picard`, the weights are setup so that two of those three accounts needs to sign.

`bob` wants to transfer `150.000 HIVE` from the `foo` account to himself so he submits an operation to the signing service:

```json
["transfer", {
  "from": "foo",
  "to": "bob",
  "amount": "150.000 HIVE",
  "memo": "Bob's boat needs plastic padding"
}]
```

The service then generates a signing URI with that operation and the following options:

```json
{
  "no_broadcast": true,
  "callback": "https://sign.hive.vc/collect?id=123&sig={{sig}}"
}
```

```
hive://sign/op/WyJ0cmFuc2ZlciIseyJmcm9tIjoiZm9vIiwidG8iOiJib2IiLCJhbW91bnQiOiIxNTAuMDAwIFNURUVNIiwibWVtbyI6IkJvYidzIGJvYXQgbmVlZHMgcGxhc3RpYyBwYWRkaW5nIn1d?nb=&cb=aHR0cHM6Ly9zaWduLnN0ZWVtLnZjL2NvbGxlY3Q_aWQ9MTIzJnNpZz17e3NpZ319
```

`bob` then signs the transaction using the URI, the service callback is pinged and the service now has his signature. Then he sends the URI to `alice` and `picard` and when one of them signs it the service has enough signatures it broadcasts the transaction.

The UX of a service like this can be excellent with the help of QR codes and collecting emails for signers so they can be notified when a signature is needed and when the transaction is broadcast.

---
_Source: https://npm.io/package/hive-uri · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
