TypeScript icon, indicating that this package has built-in type declarations

    0.2.4 • Public • Published

    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.


    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:

    const hiveuri = require('hive-uri')
    hiveuri.encodeOp(['vote', {voter: 'foo', author: 'bar', permlink: 'baz', weight: 10000}])
    // hive://sign/op/WyJ2b3RlIix7InZvdGVyIjoiZm9vIiwiYXV0aG9yIjoiYmFyIiwicGVybWxpbmsiOiJiYXoiLCJ3ZWlnaHQiOjEwMDAwfV0.
        ['vote', {voter: 'foo', author: 'bar', permlink: 'baz', weight: 10000}],
        ['transfer', {from: 'foo', to: 'bar', amount: '10.000 HIVE', memo: 'baz'}]
    ], {callback: '{{id}}'})
    // hive://sign/ops/W1sidm90ZSIseyJ2b3RlciI6ImZvbyIsImF1dGhvciI6ImJhciIsInBlcm1saW5rIjoiYmF6Iiwid2VpZ2h0IjoxMDAwMH1dLFsidHJhbnNmZXIiLHsiZnJvbSI6ImZvbyIsInRvIjoiYmFyIiwiYW1vdW50IjoiMTAuMDAwIFNURUVNIiwibWVtbyI6ImJheiJ9XV0.?cb=aHR0cHM6Ly9leGFtcGxlLmNvbS93YWxsZXQ_dHg9e3tpZH19

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

    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,
            block: confirmation.block_num,
            txn: confirmation.txn_num,


    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.


    • 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/<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.


    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.

    Params uses short names to save space in encoded URIs.


    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.{{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*

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


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


    JavaScript implementation:

    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]


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


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

    Follow user

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


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


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


    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.


      "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"


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



    Witness vote

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


    ["account_witness_vote", {
      "account": "__signer",
      "witness": "jesta",
      "approve": true




    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:

    ["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:

      "no_broadcast": true,
      "callback": "{{sig}}"

    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.




    npm i hive-uri

    DownloadsWeekly Downloads






    Unpacked Size

    21.2 kB

    Total Files


    Last publish


    • feruzm