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

0.2.1 • Public • Published

web3-token-cardano

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.

Note

This repository is initially rewritten in Typescript from https://github.com/pyropy/web3-cardano-token and the great contributions of https://github.com/gavinharris-dev for his great contributions.

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 })
// ...

Package Sidebar

Install

npm i web3-token-cardano

Weekly Downloads

0

Version

0.2.1

License

MIT

Unpacked Size

2.2 MB

Total Files

28

Last publish

Collaborators

  • bieric