devise-web3 0.2.0 → 0.4.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: e68bc1f6d3c232ed313716ffd75366da08cab7aff45a3595aabe257e0b395aaf
4
- data.tar.gz: 051273f57948614a0dbe571102e2e92471ea88a8fd4922c6b17142e25bdc63c1
3
+ metadata.gz: 8b7d601a1bb5dbde83761481d45c26312a094bec9f2402492dcca3d0c6bd6ff1
4
+ data.tar.gz: 966885d97dfec348b2ddbb370eb54ed4ab136ef8fe95a228ae1fdde4fc17535c
5
5
  SHA512:
6
- metadata.gz: f174021a37f7ea1a6b3e405c1a91bb3bdbb96f78307741b66a6354eb5b3e7fcb34c8215be94ac3bed93b95979ca4eb54d50cb39409d81092799b3e89eb7e50f1
7
- data.tar.gz: e09a3c332cda09742cf51bbbc83a2c78df141f320b9565f0fb0ba9af8451b9869ec996ce40d133081993f1a211efa263811fac05c953bc24dc0ba7f9b0ca84bc
6
+ metadata.gz: feac226f0c0abc9049da5846035745521a63050fd24c3289e0db7a6e14ca8144db618ae8a79a303cab9bb4b60779b4db3f6df234d8b81b1600a18a11eb3720a3
7
+ data.tar.gz: 7f794ecd75037258717d9a7f4d6545e633c17daca0dacab2a9c92194e865c4a7560e29f3ae4f63e64715325137802d17be499da68cab4d537935c9cf9ccbe3ba
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.4.0)
5
5
  devise (~> 4.0)
6
6
  eth (~> 0.5.15)
7
7
  redis
data/README.md CHANGED
@@ -31,6 +31,11 @@ end
31
31
 
32
32
  ```
33
33
 
34
+ Generate migration
35
+ ```shell
36
+ bin/rails g active_record:devise_web3 users
37
+ ```
38
+
34
39
  ## Development
35
40
 
36
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.
@@ -9,6 +9,6 @@ class Devise::NoncesController < DeviseController
9
9
  private
10
10
 
11
11
  def redis_store
12
- @redis_store ||= Devise::Web3::RedisStore.new(nil)
12
+ @redis_store ||= Devise::Web3::RedisStore.new
13
13
  end
14
14
  end
@@ -0,0 +1,7 @@
1
+ module Devise
2
+ module Web3
3
+ class Config
4
+ mattr_accessor :redis_url
5
+ end
6
+ end
7
+ end
@@ -1,5 +1,3 @@
1
- require 'redis'
2
-
3
1
  module Devise
4
2
  module Web3
5
3
  class Engine < ::Rails::Engine
@@ -8,8 +8,8 @@ module Devise
8
8
  TTL = 10.minutes.to_i
9
9
  NONCE_KEY = "web3-auth-nonce"
10
10
 
11
- def initialize(redis_url)
12
- @redis = Redis.new(url: redis_url)
11
+ def initialize
12
+ @redis = Redis.new(url: Devise::Web3::Config.redis_url)
13
13
  end
14
14
 
15
15
  def generate_nonce_with_id
@@ -3,7 +3,7 @@ module Devise
3
3
  module Strategies
4
4
  class Web3Authenticatable < Authenticatable
5
5
  def authenticate!
6
- redis_store = Devise::Web3::RedisStore.new(nil)
6
+ redis_store = Devise::Web3::RedisStore.new
7
7
 
8
8
  nonce = redis_store.fetch_nonce(nonce_id)
9
9
  return fail!("Nonce coldn't be found. Perhaps it's already expired") if nonce.blank?
@@ -1,5 +1,5 @@
1
1
  module Devise
2
2
  module Web3
3
- VERSION = "0.2.0"
3
+ VERSION = "0.4.0"
4
4
  end
5
5
  end
data/lib/devise/web3.rb CHANGED
@@ -7,12 +7,17 @@ require 'devise/web3/engine'
7
7
  require 'devise/web3/models/web3_authenticatable'
8
8
  require 'devise/web3/strategies/web3_authenticatable'
9
9
  require 'devise/web3/routes'
10
+ require 'devise/web3/config'
10
11
 
11
12
  module Devise
13
+ def self.web3
14
+ yield(Devise::Web3::Config)
15
+ end
12
16
 
13
17
  module Web3
14
18
  class Error < StandardError; end
15
19
 
20
+
16
21
  Devise.add_module :web3_authenticatable,
17
22
  strategy: true,
18
23
  model: 'devise/web3/models/web3_authenticatable',
@@ -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
@@ -0,0 +1,31 @@
1
+ module Devise
2
+ module Web3
3
+ class InstallGenerator < Rails::Generators::Base
4
+ source_root File.expand_path('../templates', __FILE__)
5
+ desc 'Add DeviseInvitable config variables to the Devise initializer and copy DeviseInvitable locale files to your application.'
6
+ INSTALL_CONTENT = <<-CONTENT
7
+ # ==> Configuration for :web3_authenticatable
8
+ # config.web3 do |web3|
9
+ # web3.redis_url = nil
10
+ # end
11
+
12
+ CONTENT
13
+
14
+ def add_config_options_to_initializer
15
+ devise_initializer_path = 'config/initializers/devise.rb'
16
+
17
+ if File.exist?(devise_initializer_path)
18
+ old_content = File.read(devise_initializer_path)
19
+
20
+ if old_content.match(Regexp.new(/^\s # config.web3 do/))
21
+ say_status(:identical, "Configuration for :web3_authenticatable already exists", :blue)
22
+ else
23
+ inject_into_file(devise_initializer_path, before: " # ==> Configuration for :confirmable\n") do
24
+ INSTALL_CONTENT
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
31
+ 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.2.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - TheSmartnik
8
8
  bindir: exe
9
9
  cert_chain: []
10
- date: 2025-09-12 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
@@ -144,12 +144,17 @@ files:
144
144
  - bin/setup
145
145
  - devise-web3.gemspec
146
146
  - lib/devise/web3.rb
147
+ - lib/devise/web3/config.rb
147
148
  - lib/devise/web3/engine.rb
148
149
  - lib/devise/web3/models/web3_authenticatable.rb
149
150
  - lib/devise/web3/redis_store.rb
150
151
  - lib/devise/web3/routes.rb
151
152
  - lib/devise/web3/strategies/web3_authenticatable.rb
152
153
  - lib/devise/web3/version.rb
154
+ - lib/generators/active_record/devise_web3_generator.rb
155
+ - lib/generators/active_record/templates/migration.rb
156
+ - lib/generators/devise/web3/install_generator.rb
157
+ - lib/generators/devise/web3/templates/install_config.rb
153
158
  homepage: https://thesmartnik.com
154
159
  licenses:
155
160
  - MIT