{"id":28076937,"url":"https://github.com/jaredhanson/passport-web3","last_synced_at":"2025-05-13T01:55:55.173Z","repository":{"id":43778745,"uuid":"511622403","full_name":"jaredhanson/passport-web3","owner":"jaredhanson","description":"Web3 authentication strategy for Passport.","archived":false,"fork":false,"pushed_at":"2022-07-07T21:11:59.000Z","size":11,"stargazers_count":5,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-05-13T01:55:48.724Z","etag":null,"topics":["ethereum","passport","siww","web3"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jaredhanson.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null},"funding":{"github":"jaredhanson"}},"created_at":"2022-07-07T17:44:48.000Z","updated_at":"2023-08-21T05:34:18.000Z","dependencies_parsed_at":"2022-09-21T23:14:28.109Z","dependency_job_id":null,"html_url":"https://github.com/jaredhanson/passport-web3","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jaredhanson%2Fpassport-web3","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jaredhanson%2Fpassport-web3/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jaredhanson%2Fpassport-web3/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jaredhanson%2Fpassport-web3/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jaredhanson","download_url":"https://codeload.github.com/jaredhanson/passport-web3/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253856639,"owners_count":21974577,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ethereum","passport","siww","web3"],"created_at":"2025-05-13T01:55:54.394Z","updated_at":"2025-05-13T01:55:55.159Z","avatar_url":"https://github.com/jaredhanson.png","language":"JavaScript","funding_links":["https://github.com/sponsors/jaredhanson"],"categories":[],"sub_categories":[],"readme":"# passport-ethereum-siwe\n\n[Passport](https://www.passportjs.org/) strategy for authenticating\nwith [Sign-In with Ethereum](https://login.xyz/).\n\nThis module lets you authenticate using [Sign-In with Ethereum](https://eips.ethereum.org/EIPS/eip-4361)\nin your Node.js applications.  By plugging into Passport, Ethereum\nauthentication can be easily and unobtrusively integrated into any application\nor framework that supports [Connect](https://github.com/senchalabs/connect#readme)-style\nmiddleware including [Express](https://expressjs.com/).\n\n## Install\n\n```sh\n$ npm install passport-ethereum-siwe\n```\n\n## Usage\n\nThe Ethereum authentication strategy authenticates users using an Ethereum\nwallet.\n\nThe strategy takes a `verify` function as an argument, which accepts `address`\nas an argument.  `address` is the user's Ethereum address.  When authenticating\na user, this strategy obtains this information from a message signed by the\nuser's wallet.\n\nThe `verify` function is responsible for determining the user to which the\naddress belongs.  In cases where the account is logging in for the first time, a\nnew user record is typically created automatically.  On subsequent logins, the\nexisting user record will be found via its relation to the address.\n\nBecause the `verify` function is supplied by the application, the app is free to\nuse any database of its choosing.  The example below illustrates usage of a SQL\ndatabase.\n\n```js\nvar EthereumStrategy = require('passport-ethereum-siwe');\nvar SessionNonceStore = require('passport-ethereum-siwe').SessionNonceStore;\n\nvar store = new SessionChallengeStore();\n\npassport.use(new EthereumStrategy({ store: store },\n  function verify(address, cb) {\n    db.get('SELECT * FROM blockchain_credentials WHERE chain = ? AND address = ?', [\n      'eip155:1',\n      address\n    ], function(err, row) {\n      if (err) { return cb(err); }\n      if (!row) {\n        db.run('INSERT INTO users (username) VALUES (?)', [\n          address\n        ], function(err) {\n          if (err) { return cb(err); }\n          var id = this.lastID;\n          db.run('INSERT INTO blockchain_credentials (user_id, chain, address) VALUES (?, ?, ?)', [\n            id,\n            'eip155:1',\n            address\n          ], function(err) {\n            if (err) { return cb(err); }\n            var user = {\n              id: id,\n              username: address\n            };\n            return cb(null, user);\n          });\n        });\n      } else {\n        db.get('SELECT rowid AS id, * FROM users WHERE rowid = ?', [ row.user_id ], function(err, row) {\n          if (err) { return cb(err); }\n          if (!row) { return cb(null, false); }\n          return cb(null, row);\n        });\n      }\n    });\n  }\n));\n```\n\n#### Define Routes\n\nTwo routes are needed in order to allow users to log in with their Ethereum\nwallet.\n\nThe first route generates a randomized nonce, saves it in the `NonceStore`, and\nsends it to the client-side JavaScript for it to be included in the signed\nmessage.  This is necessary in order to protect against replay attacks.\n\n```js\nrouter.post('/login/ethereum/challenge', function(req, res, next) {\n  store.challenge(req, function(err, nonce) {\n    if (err) { return next(err); }\n    res.json({ nonce: nonce });\n  });\n});\n```\n\nThe second route authenticates the signed message and logs the user in.\n\n```js\nrouter.post('/login/ethereum',\n  passport.authenticate('ethereum', { failWithError: true }),\n  function(req, res, next) {\n    res.json({ ok: true });\n  },\n  function(err, req, res, next) {\n    res.json({ ok: false });\n  });\n```\n\n## Examples\n\n* [todos-express-ethereum](https://github.com/passport/todos-express-ethereum)\n\n  Illustrates how to use the Ethereum strategy within an Express application.\n\n## License\n\n[The MIT License](https://opensource.org/licenses/MIT)\n\nCopyright (c) 2022 Jared Hanson \u003c[https://www.jaredhanson.me/](https://www.jaredhanson.me/)\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjaredhanson%2Fpassport-web3","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjaredhanson%2Fpassport-web3","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjaredhanson%2Fpassport-web3/lists"}