Socket
Book a DemoInstallSign in
Socket

web3-cardano-token

Package Overview
Dependencies
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

web3-cardano-token

Web3 Token is a new way to authenticate users in hybrid dApps using signed messages.

latest
Source
npmnpm
Version
0.0.12
Version published
Maintainers
1
Created
Source

Web3 Cardano Token

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

Install

$ npm i web3-cardano-token

Example usage (Client side)

Using Nami Wallet extension:

import Web3Token from 'web3-cardano-token/dist/browser';

// Connection to Nami wallet
const cardano = window.cardano;
await cardano.nami.enable();

// getting address from which we will sign message
const address = (await cardano.getUsedAddresses())[0];

// generating a token with 1 day of expiration time
const token = await Web3Token.sign(msg => cardano.signData(your_address, toHex(msg)), '1d');

// attaching token to authorization header ... for example

Example usage (Server side)

const Web3Token = require('web3-cardano-token/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)
req.user = await User.findOne({ address });

API

ArgumentNameDescriptionRequiredExample
1signerA function that returns a promise with signature string eg: await namiWallet.signData(address, data)required(body) => await namiWallet.signData(addr1e2..0c, body)
2expire_inA string that represents a time span (see ms module) or a number of millisecondsoptional (default: 1d)1 day
3bodyAn object that will be appended to a signature's body. Can only contain string values. Can be used for some custom data.optional{ 'Custom-data': 'some custom data' }

License

Web3 Cardano Token is released under the MIT license. © 2021 Srdjan Stankovic

Note:

This package is based upon web3-token package and uses the same API.

Keywords

auth

FAQs

Package last updated on 21 Jan 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts