An open API service indexing awesome lists of open source software.

https://github.com/nodefactoryio/server-eth-auth

Validation of web3 signatures (i.e. from MetaMask) for server Ethereum authentication
https://github.com/nodefactoryio/server-eth-auth

authentication ethereum metamask typescript

Last synced: about 1 month ago
JSON representation

Validation of web3 signatures (i.e. from MetaMask) for server Ethereum authentication

Awesome Lists containing this project

README

          

# Server-eth-auth
![Build Status](https://img.shields.io/github/workflow/status/nodefactoryio/server-eth-auth/ci)
![GitHub](https://img.shields.io/github/license/NodeFactoryIo/server-eth-auth)
![Node](https://img.shields.io/node/v/@nodefactory/server-eth-auth)
![Npm](https://img.shields.io/npm/v/@nodefactory/server-eth-auth)

This repository contains TypeScript implementation of validation for web3 signers
signatures used for authenticating on server.

# Usage

Install with `yarn add @nodefactory/server-eth-auth` or `npm i @nodefactory/server-eth-auth`

Example of usage:

```typescript
import {EthAuth} from "@nodefactory/server-eth-auth";

const domain = "Nodefactory" // shown in signer when requesting signature
const ethAuth = new EthAuth(storage: IChallengeStorage, domain)

// Creating challenge for sending to user for signature
ethAuth.createChallenge(userEthereumAddress);

const challengeHash = "hash" // user sent value that was created in createChallenge under challenge.message.value
const signature = "signature" // signature returned from signer
// Validating user signature
const address = ethAuth.checkChallenge(challengeHash, signature)
```

This package should be used in controller with 2 api endpoints:
- challenge endpoint that returns created challenge for user given ethereum address
- login endpoint that validates signature generated by signer with checkChallenge and creates and returns authentication token that can be later validated

This package requires for [IChallengeStorage](src/@types/index.d.ts) to be implemented to store created challenge hashes. Type of storage is open to choice (eg. db, cache, memory, etc.)

## License

[MIT](LICENSE)