JSPM

web3-heimdall

0.1.17
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • 0
  • Score
    100M100P100Q12710F
  • License MIT

Your wallet is your account. Forget about email and password authentication. Heimdall (Web3 Token) is a new way to authenticate users in hybrid dApps using signed messages on Cardano.

Package Exports

  • web3-heimdall
  • web3-heimdall/dist/node.js
  • web3-heimdall/src/index.ts

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (web3-heimdall) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

Heimdall

Web3 Cardano Token is a new way to authenticate users. A replacement for JWT in hybrid dApps.

Note

This repository is initially rewritten in Typescript from https://github.com/pyropy/web3-cardano-token. gavin-harris made a great contribution to ...

Install

npm i heimdall
# or
yarn add heimdall

Usage

Client Side

import Web3Token from 'heimdall/dist/browser'

async function getWeb3Token (walletApi) {
  const addresses = await walletApi.getUsedAddresses()

  if (!addresses || addresses.length === 0) {
    throw new Error('No wallet address')
  }

  return await Web3Token.sign(async (msg) => {
    return await walletApi.signData(addresses[0], Buffer.from(msg).toString('hex'))
  })
}

Server Side

import Web3Token from 'heimdall/dist/node'

// getting token from authorization header ... for example
const token = req.headers.authorization

const { address, body } = await Web3Token.verify(token)

// now you can find that user by his address
// (better to do it case insensitive)
const user = await User.findOne({ address })
// ...