active_hashcash 0.6.2 → 0.6.3
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 +4 -4
- data/CHANGELOG.md +5 -0
- data/README.md +2 -0
- data/app/assets/javascripts/hashcash.js +17 -33
- data/lib/active_hashcash/version.rb +1 -1
- data/lib/active_hashcash.rb +3 -1
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: cb6b667de99d773ec58e9fe9a45f63085f3215600ef7a370c215cda854380856
|
|
4
|
+
data.tar.gz: f6d2c14d1c15c430784bf164f16c8c63ae533da821f951c5cd1f5c00ea39279b
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 290b6a154e9395302d7b51d5cd45fa89adcc54b1e6f3a9f65a381afeb06775230a927f084c064d7c5998994df1d2e8dbce432efc236d59964ad99fa102e94bc0
|
|
7
|
+
data.tar.gz: abb0d050396b1aa6ea43a8d25c091e20ab6bfff1518d13af53344547d051ee682c150c73feac2e9a580022f65e798829e826ec3c4933ee5867180e20267e8eb8
|
data/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
# Changelog of ActiveHashcash
|
|
2
2
|
|
|
3
|
+
## 0.6.3 (2026-11-15)
|
|
4
|
+
|
|
5
|
+
- Make `Hashcash.setup()` idempotent so it can be called again after navigations #26
|
|
6
|
+
- Fix lost original submit button text with Turbo Drive #29
|
|
7
|
+
|
|
3
8
|
## 0.6.2 (2026-11-13)
|
|
4
9
|
|
|
5
10
|
- Fix #25 Stop adding lib/ to asset paths so Propshaft doesn't publish Ruby sources (@Spone)
|
data/README.md
CHANGED
|
@@ -84,6 +84,8 @@ Or, link hashcash to your JavaScript manifest and load it to your head.
|
|
|
84
84
|
<%= javascript_include_tag "hashcash", "data-turbo-track": "reload", defer: true %>
|
|
85
85
|
```
|
|
86
86
|
|
|
87
|
+
`Hashcash.setup()` runs when the script loads and is safe to call again: it will not mint twice for the same input. If the form appears after a navigation without reloading the script, call `Hashcash.setup()` yourself.
|
|
88
|
+
|
|
87
89
|
The hashcash stamp will be set in the hidden input once computed and the submit button enabled.
|
|
88
90
|
|
|
89
91
|
To customize behaviours, you can override methods of ActiveHashcash module.
|
|
@@ -1,18 +1,16 @@
|
|
|
1
1
|
// http://www.hashcash.org/docs/hashcash.html
|
|
2
2
|
// <input type="hidden" name="hashcash" data-hashcash="{resource: 'site.example', bits: 16}"/>
|
|
3
|
-
Hashcash = function(input) {
|
|
3
|
+
Hashcash = window.Hashcash || function(input) {
|
|
4
4
|
options = JSON.parse(input.getAttribute("data-hashcash"))
|
|
5
5
|
Hashcash.disableParentForm(input, options)
|
|
6
6
|
input.dispatchEvent(new CustomEvent("hashcash:mint", {bubbles: true}))
|
|
7
7
|
|
|
8
8
|
Hashcash.mint(options.resource, options, function(stamp) {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
Hashcash.enableParentForm(input, options)
|
|
15
|
-
input.dispatchEvent(new CustomEvent("hashcash:minted", {bubbles: true, detail: {stamp: stamp}}))
|
|
9
|
+
if (input.isConnected) {
|
|
10
|
+
input.value = stamp.toString()
|
|
11
|
+
Hashcash.enableParentForm(input, options)
|
|
12
|
+
input.dispatchEvent(new CustomEvent("hashcash:minted", {bubbles: true, detail: {stamp: stamp}}))
|
|
13
|
+
}
|
|
16
14
|
})
|
|
17
15
|
|
|
18
16
|
this.input = input
|
|
@@ -20,11 +18,15 @@ Hashcash = function(input) {
|
|
|
20
18
|
}
|
|
21
19
|
|
|
22
20
|
Hashcash.setup = function() {
|
|
23
|
-
if (document.readyState
|
|
24
|
-
var input = document.querySelector("input#hashcash")
|
|
25
|
-
input && new Hashcash(input)
|
|
26
|
-
} else
|
|
21
|
+
if (document.readyState == "loading") {
|
|
27
22
|
document.addEventListener("DOMContentLoaded", Hashcash.setup)
|
|
23
|
+
} else {
|
|
24
|
+
var input = document.querySelector("input#hashcash")
|
|
25
|
+
if (input && !input.dataset.hashcashStarted) {
|
|
26
|
+
input.dataset.hashcashStarted = "1"
|
|
27
|
+
new Hashcash(input)
|
|
28
|
+
}
|
|
29
|
+
}
|
|
28
30
|
}
|
|
29
31
|
|
|
30
32
|
// Terminate the active worker and clean up its Blob URL.
|
|
@@ -39,33 +41,15 @@ Hashcash.cleanup = function() {
|
|
|
39
41
|
}
|
|
40
42
|
}
|
|
41
43
|
|
|
42
|
-
// Turbo Drive: terminate the worker when navigating away so it doesn't
|
|
43
|
-
// complete after the page has changed, and restore the form state for
|
|
44
|
-
// Turbo's page cache so the snapshot doesn't have disabled buttons.
|
|
45
|
-
document.addEventListener("turbo:before-visit", Hashcash.cleanup)
|
|
46
|
-
document.addEventListener("turbo:before-cache", function() {
|
|
47
|
-
Hashcash.cleanup()
|
|
48
|
-
var input = document.querySelector("input#hashcash")
|
|
49
|
-
if (input && input.form) {
|
|
50
|
-
input.value = ""
|
|
51
|
-
input.form.querySelectorAll("[type=submit]").forEach(function(submit) {
|
|
52
|
-
if (submit.originalValue) {
|
|
53
|
-
Hashcash.setSubmitText(submit, submit.originalValue)
|
|
54
|
-
}
|
|
55
|
-
submit.disabled = null
|
|
56
|
-
})
|
|
57
|
-
}
|
|
58
|
-
})
|
|
59
|
-
|
|
60
44
|
Hashcash.setSubmitText = function(submit, text) {
|
|
61
45
|
if (!text) {
|
|
62
46
|
return
|
|
63
47
|
}
|
|
64
48
|
if (submit.tagName == "BUTTON") {
|
|
65
|
-
!submit.originalValue && (submit.originalValue = submit.innerHTML)
|
|
49
|
+
!submit.dataset.originalValue && (submit.dataset.originalValue = submit.innerHTML)
|
|
66
50
|
submit.innerHTML = text
|
|
67
51
|
} else {
|
|
68
|
-
!submit.originalValue && (submit.originalValue = submit.value)
|
|
52
|
+
!submit.dataset.originalValue && (submit.dataset.originalValue = submit.value)
|
|
69
53
|
submit.value = text
|
|
70
54
|
}
|
|
71
55
|
}
|
|
@@ -79,7 +63,7 @@ Hashcash.disableParentForm = function(input, options) {
|
|
|
79
63
|
|
|
80
64
|
Hashcash.enableParentForm = function(input, options) {
|
|
81
65
|
input.form.querySelectorAll("[type=submit]").forEach(function(submit) {
|
|
82
|
-
Hashcash.setSubmitText(submit, submit.originalValue)
|
|
66
|
+
Hashcash.setSubmitText(submit, submit.dataset.originalValue)
|
|
83
67
|
submit.disabled = null
|
|
84
68
|
})
|
|
85
69
|
}
|
data/lib/active_hashcash.rb
CHANGED
|
@@ -151,7 +151,9 @@ module ActiveHashcash
|
|
|
151
151
|
# Override me for your own needs.
|
|
152
152
|
end
|
|
153
153
|
|
|
154
|
-
# Call it inside the form that have to be protected
|
|
154
|
+
# Call it inside the form that have to be protected.
|
|
155
|
+
# hashcash.js calls Hashcash.setup() on load; call it again after navigations that
|
|
156
|
+
# insert the field without reloading the script. setup is idempotent per input.
|
|
155
157
|
# Unless you need something really special, you should not need to override this method.
|
|
156
158
|
#
|
|
157
159
|
# <% form_for model do |form| %>
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: active_hashcash
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.6.
|
|
4
|
+
version: 0.6.3
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Alexis Bernard
|
|
@@ -107,7 +107,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
107
107
|
- !ruby/object:Gem::Version
|
|
108
108
|
version: '0'
|
|
109
109
|
requirements: []
|
|
110
|
-
rubygems_version: 4.0.
|
|
110
|
+
rubygems_version: 4.0.20
|
|
111
111
|
specification_version: 4
|
|
112
112
|
summary: Protect Rails applications against bots and brute force attacks without annoying
|
|
113
113
|
humans.
|