Skip to main content

Usage

Configure and use Aioha in 5 minutes or less.

Instantiation

Create an instance of Aioha. All providers are registered by default excluding HiveSigner, which is only registered when HiveSigner config is specified. This step also loads any persistent logins stored in localStorage (if available). Returns an Aioha object.

Provider-specific configs are optional with exception of HiveSigner which is required to register HiveSigner provider.

import { initAioha, Asset, KeyTypes, Providers } from '@aioha/aioha'

const aioha = initAioha({
hiveauth: {
name: 'Aioha',
description: 'Aioha test app'
},
hivesigner: {
app: 'ipfsuploader.app',
callbackURL: window.location.origin + '/hivesigner.html',
scope: ['login', 'vote']
}
})

Configuration

  • name: Short name of the app. Default: Aioha Generic App
  • description (optional): App description
  • icon (optional): URL to app icon

Enums

The Providers enum exported are as follows:

export enum Providers {
Keychain = 'keychain',
HiveSigner = 'hivesigner',
HiveAuth = 'hiveauth',
Ledger = 'ledger',
PeakVault = 'peakvault'
}

Login

info

Also known as Connect Wallet.

Login with specified provider and username. A signature request will be made to sign message msg using keyType key that is associated with the Hive account.

const login = await aioha.login(Providers.Keychain, 'hiveusername', {
msg: 'Hello World',
keyType: KeyTypes.Posting,
loginTitle: 'Login',
hiveauth: {
cbWait: (payload, evt, cancel) => {
// display HiveAuth QR code using `payload` as data
}
}
})
  • msg: Message to be signed
  • keyType: Key type to be used to sign the message
  • loginTitle (optional): Title to be displayed on certain providers
  • hiveauth.cbWait: Callback function returning auth payload. It shall display a QR code using payload as data to be scanned by a HiveAuth PKSA. Login request may be cancelled before timeout by calling cancel().

Login and Decrypt Memo

Not Recommended

Login with signatures above are preferred than with memo decryption due to limited support of memo cryptography in certain providers.

Login with specified provider and username by decrypting a memo.

const login = await aioha.loginAndDecryptMemo(Providers.Keychain, 'hiveusername', {
msg: 'Hello World',
keyType: KeyTypes.Posting
})
  • msg: Memo to be decrypted
  • keyType: Key type to be used to decrypt the message

Login Non-Interactively

May be used when authentication info (i.e. access token) is already available. This is especially useful for one-click login.

const loginResult = aioha.loginNonInteractive(Providers.HiveSigner, url.searchParams.get('username')!, {
ignorePersistence: false, // optional, set to true to overwrite persistent logins already stored
hivesigner: {
accessToken: 'hivesigner_access_token_here',
expiry: 123456 // timestamp in seconds
}
})

Logout

info

Also known as Disconnect Wallet.

Logout the current authenticated user.

await aioha.logout()

Decrypt Memo

Decrypt a Hive memo or message.

const decrypted = await aioha.decryptMemo('#encryptedmessage', KeyTypes.Posting)

Required arguments include the encrypted message starting with # and the KeyTypes enum for the key type to be used.

Sign Message

Retrieve an ECDSA signature for a message.

const signed = await aioha.signMessage('Message to sign', KeyTypes.Posting)

Required arguments include the message to sign and the KeyTypes enum for the key type to be used.

Sign Transaction

Sign a Hive transaction without broadcasting it.

const signed = await aioha.signTx({
"ref_block_num": 27912,
"ref_block_prefix": 1175138206,
"expiration": "2024-06-07T10:23:57",
"operations": [
[
"transfer",
{
"from": "randomvlogs",
"to": "randomvlogs",
"amount": "0.001 HIVE",
"memo": "Aioha Test"
}
]
],
"extensions": []
}, KeyTypes.Active)

Required arguments include the message to sign and the KeyTypes enum for the key type to be used (must not be KeyTypes.Memo).

Sign and Broadcast Transaction

Sign and broadcast a Hive transaction.

const result = aioha.signAndBroadcastTx([
['vote', {
author: 'sagarkothari88',
permlink: '2024-06-05-daily-updates-from-sagarkothari88',
voter: 'techcoderx',
weight: 10000
}]
], KeyTypes.Posting)

Required arguments include an array of operations for the transaction and the KeyTypes enum for the key type to be used (must not be KeyTypes.Memo).

Getters

Registered Providers

List all registered providers.

aioha.getProviders() // ['keychain', 'peakvault', 'ledger', 'hiveauth', 'hivesigner']

Current Provider

Returns one of the providers above that the user logs in with.

aioha.getCurrentProvider()

Current User

Returns logged in Hive username.

aioha.getCurrentUser()

Is Logged In

Returns a boolean of whether a user is logged in or not.

aioha.isLoggedIn()

Is Provider Registered

Returns a boolean of whether the specified provider is registered. This does not indicate that the said provider is available to the user (i.e. due to required browser extension not installed).

aioha.isProviderRegistered(Providers.HiveAuth)

Is Provider Enabled

Returns a boolean of whether the specified provider is registered and available for use by the user.

aioha.isProviderEnabled(Providers.HiveAuth)

Setters

Set Hive API

Set a Hive API node for RPC calls made by Aioha (i.e. HIVE/VEST calculation, broadcast transaction)

aioha.setApi('https://techcoderx.com', [
'https://api.hive.blog',
'https://api.openhive.network',
// ...more fallback nodes
])

Set VSC Network ID

Set VSC network ID for VSC related functions.

aioha.vscSetNetId('testnet/0bf2e474-6b9e-4165-ad4e-a0d78968d20c')

Operations

The return value for these method calls will be equivalent to sign and broadcast transaction result above.

Social

const vote = await aioha.vote('author', 'permlink', 10000)
const voteMany = await aioha.voteMany([
{
author: 'author1',
permlink: 'permlink1',
weight: 10000
},
{
author: 'author2',
permlink: 'permlink2',
weight: 5000
}
])

Custom JSON

Publish an arbitrary JSON data.

const customJson = await aioha.customJSON(KeyTypes.Posting, 'my-id', { foo: 'bar' }, 'Display Title')

Claim Rewards

Claim Hive rewards that have paid out from content reward pool.

const rewardClaim = await aioha.claimRewards()

Transfer

Transfer HIVE/HBD to another account.

// transfer 1 HIVE with memo
const xfer = await aioha.transfer('recipient', 1, Asset.HIVE, 'Transferred using Aioha with memo')

// transfer 1 HBD without memo
const xferNoMemo = await aioha.transfer('recipient2', 1, Asset.HBD)

HIVE staking

// stake 1000 HIVE to itself
const stake = await aioha.stakeHive(1000)

// stake 1000 HIVE to another account
const stakeToOtherAccount = await aioha.stakeHive(1000, 'anotheraccount')

Governance

const voteWitness = await aioha.voteWitness('thewitness', true)
const unvoteWitness = await aioha.voteWitness('thewitness', false)

Authority

// Add 'aioha' account to posting auths with weight 1
const addAccount = await aioha.addAccountAuthority('aioha', KeyTypes.Posting, 1)

// Remove 'aioha' account from posting auths
const rmAccount = await aioha.removeAccountAuthority('aioha', KeyTypes.Posting)

Call VSC Contract

Call a VSC contract from L1.

const contractCall = await aioha.vscCallContract('vs41q9c3yg82k4q76nprqk89xzk2n8zhvedrz5prnrrqpy6v9css3seg2q43uvjdc500', 'dumpEnv', 'tx payload', KeyTypes.Active)

JSON-RPC Request

Make an EIP-1193 style JSON-RPC request. For more details, refer to JSON-RPC specs page.

const result = await aioha.request({
method: 'aioha_api.your_method_name',
params: {
foo: 'bar'
}
})