-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathdoc.go
52 lines (43 loc) · 1.16 KB
/
doc.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
/*
Package hashcash a library which implements the hashcash proof-of-work algorithm.
Computing a hashcash:
package main
import (
"fmt"
"github.com/umahmood/hashcash"
)
func validateResource(resource string) bool {
// validate resource. resource could be an email, ip
// address, etc... so for an email we could check it
// exists in the database.
return true
}
func main() {
hc, err := hashcash.New(
&hashcash.Resource{
Data: "someone@gmail.com",
ValidatorFunc: validateResource,
},
nil, // use default config.
)
if err != nil {
// handle error
}
solution, err := hc.Compute()
if err != nil {
if err != hashcash.ErrSolutionFail {
// did not find a solution, can call compute again.
}
}
fmt.Println(solution)
}
Verifying a hashcash:
valid, err := hc.Verify(solution)
if err != nil {
// handle error
}
if !valid {
// hashcash token failed verification.
}
*/
package hashcash