Giter Club home page Giter Club logo

aioha's Introduction

Aioha

Aioha is an API that provides a common interface for working with different Hive login providers. This allows easier integration of Hive login and transacting on the network with fewer code.

This repository contains the core API designed for use in browser contexts. Ready to use packages with UI included are to follow soon.

Supported Providers

Installation

pnpm i @aioha/aioha

Usage Example

import { Aioha } from '@aioha/aioha'

// Instantiation
const aioha = new Aioha()

// Register providers
aioha.registerKeychain()
aioha.registerHiveSigner({
  app: 'ipfsuploader.app',
  callbackURL: window.location.origin + '/hivesigner.html',
  scope: ['login', 'vote']
})
aioha.registerHiveAuth({
  name: 'Aioha',
  description: 'Aioha test app'
})
aioha.registerLedger()

// Load persistent login from local storage
// returns boolean of whether a login has been loaded
const authLoaded = aioha.loadAuth()

// Get registered providers
console.log(aioha.getProviders())

// Get current logged in user and provider name
if (authLoaded) {
  console.log(aioha.getCurrentUser(), aioha.getCurrentProvider())
}

// Login with provider
// Supported providers are listed above, names converted to lowercase
const login = await aioha.login('keychain', 'hiveusername', {
  msg: 'Hello World',
  keyType: 'posting',
  hiveauth: {
    cbWait: (payload, evt) => {
      // display HiveAuth QR code using `payload` as data
    }
  }
})

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

// Vote comment with 100% weight
const vote = await aioha.vote('author', 'permlink', 10000)

// Claim rewards
const rewardClaim = await aioha.claimRewards()

More usage details can be found on the Aioha documentation (TBD).

Local storage reserved keys

Aioha uses certain keys in browser localStorage to store persistent logins, and in the case of HiveSigner provider, pass info from callback URL.

The following keys are reserved:

  • General: aiohaUsername, aiohaProvider
  • HiveAuth: hiveauthToken, hiveauthKey, hiveauthExp
  • HiveSigner: hivesignerTxId, hivesignerToken, hivesignerExpiry, hivesignerUsername
  • Ledger: ledgerPath

HiveSigner callback page

A callback page is required for HiveSigner provider. An example HTML with the code which parses the response data and stores them into localStorage has been included in snippets/hivesigner.html file.

Build

pnpm run build
pnpm run webpack

tsc output can be found in build folder and the Webpack output can be found in dist folder with bundle.js being the entrypoint. All Webpack output files are to be served and will be loaded on-demand depending on the provider selected upon login.

aioha's People

Contributors

techcoderx avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.