Catalog npm
PACKAGE EXPLORERView in registry

@0xbutterfield/passport-siwe

npm

Sign in with Ethereum and Passport

ethereumpassportsiwe
Versions collected1
Direct dependencies21From release 2.0.0
Last observed20 Oct, 22:44 UTC

README

Current package documentation

MIT License

@sloikaxyz/passport-siwe

Sign in with Ethereum and Passport

@sloikaxyz/passport-siwe provides a Passport authentication strategy for Sign in with Ethereum.

This module can be used with Express, Nest.js, Fastify (via @fastify/passport), or any other framework that supports Connect-style middleware.

Usage

Client-facing API

The strategy expects the request body to contain an object with keys message — a plaintext message conforming to the EIP-4361 spec, and signature — the signature over the message, represented as a hex string. For an example of how to generate this on frontend, see siwe usage examples.

Configuring the strategy

import Strategy from '@sloikaxyz/passport-siwe';
import { SiweMessage } from 'siwe';

passport.use(
  new Strategy(
    {
      domain: 'example.org', // authentication domain, required
    },
    function (
      message: SiweMessage,
      callback: (
        err: Error | null,
        user: unknown,
        info?: unknown,
      ) => void,
    ) {
      // The callback is invoked if the message is valid, i.e.:
      // - the authentication domain matches,
      // - the message is in effect (see "Expiration Time" and "Not Before"),
      // - the signature provided in the request is valid.
      //
      // NOTE: Nonce is not validated by the strategy — it's up to you to implement that.
      //
      // Use `message.address` — an EIP-55 checksummed address — to determine the user.
      //
      // Call...
      // - callback(null, user) to sign the user in
      // - callback(null, null) to fail this authentication attempt
      // - callback(err, null) to signal that a server-side error has occurred while processing this request
    },
  ),
);

Accessing the request object

import Strategy from '@sloikaxyz/passport-siwe';
import express from 'express';
import { SiweMessage } from 'siwe';

passport.use(
  new Strategy(
    {
      domain: 'example.org',
      passReqToCallback: true, // pass the request as the first argument of the callback
    },
    function (
      req: express.Request, // an express-style request object
      message: SiweMessage,
      callback: (
        err: Error | null,
        user: unknown,
        info?: unknown,
      ) => void,
    ) {
      // See "Basic usage" for discussion of the callback.
    },
  ),
);

Installation

Install my-project with npm

  npm install @sloikaxyz/passport-siwe siwe@^2.0.5 ethers@^5.6.8
  # or
  yarn add @sloikaxyz/passport-siwe siwe@^2.0.5 ethers@^5.6.8

Roadmap

  • Nonce verification support

Contributing

Contributions are always welcome!

Quick steps:

  1. Fork and clone the repo.
  2. Make changes to the strategy as necessary — you can run yarn test:watch while developing.
  3. Commit the changes and run yarn test:ci to verify the tests pass.
  4. Send a PR :)

Acknowledgements

License

MIT License

Copyright (c) 2022 Sloika Industries, Inc.

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Downloads & popularity

Awaiting observations

No metric observations yet

Download counts and popularity will appear here as the collector receives them.

Versions 1

Collected releases
VersionPublishedDirect dependenciesOpen version
2.0.0Registry latest18 Jan 202321

Package advisories

0
No matching advisories collected

This describes our collected data; it is not a security assessment.

Repository

PENDING
sloikaxyz/passport-siwe

Shared repository data · GitHub

License detected in repository
Not collected

Metadata history

Meaningful changes
Current collected state Current

Observed since 20 Oct, 22:44 UTC

No superseded metadata states collected. Unchanged observations do not create new revisions.

Record identity

package:6f6653f561d069ca419ab01f49996ab7e24fc3acf643c2b3516e477796c0a0b0