GitXplorerGitXplorer
p

web3-cardano-token

public
28 stars
15 forks
5 issues

Commits

List of commits on branch main.
Unverified
863c02346bb565f3555cc1548b555892311ef102

Update babel config and remove stale tests

ppyropy committed 3 years ago
Unverified
ebf9e91d668d6b3fc2bfb4c656316d80f501cbbb

Update webpack config

ppyropy committed 3 years ago
Unverified
1b8d0e8b217eb88ec76f287481519f4a1e6a09fe

Change global self object to 'this'

ppyropy committed 3 years ago
Unverified
8fc23f54a66b1e7c92025adc09ea1f3745e8d241

Change builder to webpack

ppyropy committed 3 years ago
Unverified
a38a53f66cba250cb0253b790653342829a37fd9

Load wasm modules from npm

ppyropy committed 3 years ago
Unverified
61c05741f0e10fe6729f1564613e4a0e554c62a3

setup different build targets

ppyropy committed 3 years ago

README

The README file for this repository.

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

Argument Name Description Required Example
1 signer A function that returns a promise with signature string eg: await namiWallet.signData(address, data) required (body) => await namiWallet.signData(addr1e2..0c, body)
2 expire_in A string that represents a time span (see ms module) or a number of milliseconds optional (default: 1d) 1 day
3 body An 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.