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
- Host: GitHub
- URL: https://github.com/nodefactoryio/server-eth-auth
- Owner: NodeFactoryIo
- License: mit
- Created: 2020-07-03T09:54:07.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2023-01-06T10:31:43.000Z (over 3 years ago)
- Last Synced: 2025-02-03T07:02:40.724Z (over 1 year ago)
- Topics: authentication, ethereum, metamask, typescript
- Language: TypeScript
- Homepage:
- Size: 335 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 10
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# 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)