devise-web3 0.1.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2ba920bf0ddf9dab801ad64ade277225bc92772de4e68650840b88ef814968dc
4
- data.tar.gz: 0fb54f1b5dac199956226250263d22e9ba823b3b447a7dbc78003740f2d58702
3
+ metadata.gz: 23f6279d9f03f0ae35fca26cf93e9f09036aa241d86f51655cfb93ba2a1e9eac
4
+ data.tar.gz: 8e2908eef867246d6729fe155d5bf2f799664897b8923e8d9834d30afa76e979
5
5
  SHA512:
6
- metadata.gz: 708031b17df449f109f7ca855e00e2027ee04e24900d28091247180d81db6a872c078d405a2109f79b98c8eb3476a65b70c2eeb30210ea1dac09c88c3afc7680
7
- data.tar.gz: '0378ee4ad0d14c51858492550fbffc8a07d332a3b9fe87537fd0ec459cc1c46782789630204b4cbee6371cc5f685a77b2fb44ce15bf7f2e3efccd5bcb171bf8e'
6
+ metadata.gz: 8a320a4db75bb9c700b54c717faca48674b13af02527e1fcb9ea79e66f65131f54104d5d3187c960510e38c48735ea090fe4c5a596a1213ca574e1d9e353661a
7
+ data.tar.gz: c127eb010e7c594d219cc959f85e20ba0e42f66bab31db06de71e4f3cadfda18ef358e0bf96bd1d0bf3aec7735293bbb8ccd572667f41e413145ae6425e2eef1
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- devise-web3 (0.1.0)
4
+ devise-web3 (0.2.0)
5
5
  devise (~> 4.0)
6
6
  eth (~> 0.5.15)
7
7
  redis
data/README.md CHANGED
@@ -1,6 +1,7 @@
1
1
  # Devise::Web3
2
2
 
3
- `Devise::Web3` allows to easily add support for authentication with etherium wallet.
3
+ `Devise-web3` allows to easily implement login with metamask or any other ethereum wallet providers. It works by providing a nonce for a user to sign and then cryptographically checking that signature is valid. This allows for a simple one click login popular among web3 apps.
4
+
4
5
 
5
6
  ## Installation
6
7
 
@@ -30,6 +31,11 @@ end
30
31
 
31
32
  ```
32
33
 
34
+ Generate migration
35
+ ```shell
36
+ bin/rails g active_record:devise_web3 users
37
+ ```
38
+
33
39
  ## Development
34
40
 
35
41
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
@@ -0,0 +1,14 @@
1
+ class Devise::NoncesController < DeviseController
2
+ prepend_before_action :require_no_authentication, only: [:show]
3
+
4
+ def show
5
+ nonce, nonce_id = redis_store.generate_nonce_with_id
6
+ render json: { nonce: nonce, nonce_id: nonce_id }
7
+ end
8
+
9
+ private
10
+
11
+ def redis_store
12
+ @redis_store ||= Devise::Web3::RedisStore.new(nil)
13
+ end
14
+ end
@@ -0,0 +1,8 @@
1
+ require 'redis'
2
+
3
+ module Devise
4
+ module Web3
5
+ class Engine < ::Rails::Engine
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,8 @@
1
+ module ActionDispatch::Routing
2
+ class Mapper
3
+ def devise_web3_authenticatable(mapping, controllers) #:nodoc:
4
+ resource :nonce, only: [:show],
5
+ path: mapping.path_names[:nonce], controller: controllers[:nonces]
6
+ end
7
+ end
8
+ end
@@ -1,5 +1,5 @@
1
1
  module Devise
2
2
  module Web3
3
- VERSION = "0.1.0"
3
+ VERSION = "0.3.0"
4
4
  end
5
5
  end
data/lib/devise/web3.rb CHANGED
@@ -3,16 +3,21 @@ require 'redis'
3
3
  require 'eth'
4
4
  require 'devise/web3/version'
5
5
  require 'devise/web3/redis_store'
6
+ require 'devise/web3/engine'
6
7
  require 'devise/web3/models/web3_authenticatable'
7
8
  require 'devise/web3/strategies/web3_authenticatable'
9
+ require 'devise/web3/routes'
8
10
 
9
11
  module Devise
12
+
10
13
  module Web3
11
14
  class Error < StandardError; end
12
15
 
13
16
  Devise.add_module :web3_authenticatable,
14
17
  strategy: true,
15
- model: 'web3/models/web3_authenticatable',
18
+ model: 'devise/web3/models/web3_authenticatable',
19
+ controller: :nonces,
20
+ route: true,
16
21
  no_input: true
17
22
  end
18
23
  end
@@ -0,0 +1,19 @@
1
+ require 'rails/generators/active_record'
2
+
3
+ module ActiveRecord
4
+ module Generators
5
+ class DeviseWeb3Generator < ActiveRecord::Generators::Base
6
+ source_root File.expand_path('../templates', __FILE__)
7
+
8
+ def copy_devise_migration
9
+ migration_template 'migration.rb', "db/migrate/devise_web3_add_to_#{table_name}.rb", migration_version: migration_version
10
+ end
11
+
12
+ def migration_version
13
+ if Rails::VERSION::MAJOR >= 5
14
+ "[#{Rails::VERSION::MAJOR}.#{Rails::VERSION::MINOR}]"
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,17 @@
1
+ class DeviseWeb3AddTo<%= table_name.camelize %> < ActiveRecord::Migration<%= migration_version %>
2
+ def up
3
+ change_table :<%= table_name %> do |t|
4
+ t.string :public_address
5
+ end
6
+
7
+ add_index :<%= table_name %>, :public_address
8
+ end
9
+
10
+ def down
11
+ change_table :<%= table_name %> do |t|
12
+ t.remove :public_address
13
+ end
14
+
15
+ remove_index :<%= table_name %>, :public_address
16
+ end
17
+ end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: devise-web3
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - TheSmartnik
8
8
  bindir: exe
9
9
  cert_chain: []
10
- date: 2025-09-02 00:00:00.000000000 Z
10
+ date: 2025-09-13 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: devise
@@ -139,14 +139,19 @@ files:
139
139
  - LICENSE.txt
140
140
  - README.md
141
141
  - Rakefile
142
+ - app/controllers/devise/nonces_controller.rb
142
143
  - bin/console
143
144
  - bin/setup
144
145
  - devise-web3.gemspec
145
146
  - lib/devise/web3.rb
147
+ - lib/devise/web3/engine.rb
146
148
  - lib/devise/web3/models/web3_authenticatable.rb
147
149
  - lib/devise/web3/redis_store.rb
150
+ - lib/devise/web3/routes.rb
148
151
  - lib/devise/web3/strategies/web3_authenticatable.rb
149
152
  - lib/devise/web3/version.rb
153
+ - lib/generators/active_record/devise_web3_generator.rb
154
+ - lib/generators/active_record/templates/migration.rb
150
155
  homepage: https://thesmartnik.com
151
156
  licenses:
152
157
  - MIT