siwe 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.rspec +3 -0
- data/.rubocop.yml +36 -0
- data/.solargraph.yml +22 -0
- data/CHANGELOG.md +5 -0
- data/CODE_OF_CONDUCT.md +84 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +106 -0
- data/LICENSE +21 -0
- data/LICENSE.txt +21 -0
- data/README.md +2 -0
- data/Rakefile +12 -0
- data/bin/console +15 -0
- data/bin/setup +8 -0
- data/lib/siwe/message.rb +220 -0
- data/lib/siwe/util.rb +14 -0
- data/lib/siwe/version.rb +5 -0
- data/lib/siwe.rb +11 -0
- metadata +131 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 3e8191a3015440c3051896d22edba61a3b9f79d87930ec852e294e020afd29d2
|
4
|
+
data.tar.gz: 5a015d2ed004f3e60b84218167bc9759228de7e0cae49c28eac076c6e2e397bd
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 228890a1cd243da5dec618b5a933b911058775fec4a9a0e90266c8a39ec7f80904a11487a810d6aae54badffcde6a09567ec5487f131fb0b3480348d427ece48
|
7
|
+
data.tar.gz: d880c083a7c09042c5b8d1b1a9b9faec683475666f4fe749c78bd25b7d3c2891c0c577eb815b166178461cd6aad0f32f4ad8cc60e2a048649ac3125e8fa5f6cc
|
data/.rspec
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
AllCops:
|
2
|
+
TargetRubyVersion: 2.6
|
3
|
+
NewCops: enable
|
4
|
+
SuggestExtensions: false
|
5
|
+
|
6
|
+
Style/StringLiterals:
|
7
|
+
Enabled: true
|
8
|
+
EnforcedStyle: double_quotes
|
9
|
+
|
10
|
+
Style/StringLiteralsInInterpolation:
|
11
|
+
Enabled: true
|
12
|
+
EnforcedStyle: double_quotes
|
13
|
+
|
14
|
+
Metrics/MethodLength:
|
15
|
+
Enabled: false
|
16
|
+
|
17
|
+
Metrics/AbcSize:
|
18
|
+
Enabled: false
|
19
|
+
|
20
|
+
Metrics/BlockLength:
|
21
|
+
Enabled: false
|
22
|
+
|
23
|
+
Metrics/CyclomaticComplexity:
|
24
|
+
Enabled: false
|
25
|
+
|
26
|
+
Metrics/PerceivedComplexity:
|
27
|
+
Enabled: false
|
28
|
+
|
29
|
+
Metrics/ClassLength:
|
30
|
+
Enabled: false
|
31
|
+
|
32
|
+
Style/OptionalBooleanParameter:
|
33
|
+
Enabled: false
|
34
|
+
|
35
|
+
Layout/LineLength:
|
36
|
+
Max: 120
|
data/.solargraph.yml
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
---
|
2
|
+
include:
|
3
|
+
- "**/*.rb"
|
4
|
+
exclude:
|
5
|
+
- spec/**/*
|
6
|
+
- test/**/*
|
7
|
+
- vendor/**/*
|
8
|
+
- ".bundle/**/*"
|
9
|
+
require: []
|
10
|
+
domains: []
|
11
|
+
reporters:
|
12
|
+
- rubocop
|
13
|
+
- require_not_found
|
14
|
+
formatter:
|
15
|
+
rubocop:
|
16
|
+
cops: safe
|
17
|
+
except: []
|
18
|
+
only: []
|
19
|
+
extra_args: []
|
20
|
+
require_paths: []
|
21
|
+
plugins: []
|
22
|
+
max_files: 5000
|
data/CHANGELOG.md
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
|
6
|
+
|
7
|
+
We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
|
8
|
+
|
9
|
+
## Our Standards
|
10
|
+
|
11
|
+
Examples of behavior that contributes to a positive environment for our community include:
|
12
|
+
|
13
|
+
* Demonstrating empathy and kindness toward other people
|
14
|
+
* Being respectful of differing opinions, viewpoints, and experiences
|
15
|
+
* Giving and gracefully accepting constructive feedback
|
16
|
+
* Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
|
17
|
+
* Focusing on what is best not just for us as individuals, but for the overall community
|
18
|
+
|
19
|
+
Examples of unacceptable behavior include:
|
20
|
+
|
21
|
+
* The use of sexualized language or imagery, and sexual attention or
|
22
|
+
advances of any kind
|
23
|
+
* Trolling, insulting or derogatory comments, and personal or political attacks
|
24
|
+
* Public or private harassment
|
25
|
+
* Publishing others' private information, such as a physical or email
|
26
|
+
address, without their explicit permission
|
27
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
28
|
+
professional setting
|
29
|
+
|
30
|
+
## Enforcement Responsibilities
|
31
|
+
|
32
|
+
Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
|
33
|
+
|
34
|
+
Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
|
35
|
+
|
36
|
+
## Scope
|
37
|
+
|
38
|
+
This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
|
39
|
+
|
40
|
+
## Enforcement
|
41
|
+
|
42
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at greg.magalhaes@gmail.com. All complaints will be reviewed and investigated promptly and fairly.
|
43
|
+
|
44
|
+
All community leaders are obligated to respect the privacy and security of the reporter of any incident.
|
45
|
+
|
46
|
+
## Enforcement Guidelines
|
47
|
+
|
48
|
+
Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
|
49
|
+
|
50
|
+
### 1. Correction
|
51
|
+
|
52
|
+
**Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
|
53
|
+
|
54
|
+
**Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
|
55
|
+
|
56
|
+
### 2. Warning
|
57
|
+
|
58
|
+
**Community Impact**: A violation through a single incident or series of actions.
|
59
|
+
|
60
|
+
**Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
|
61
|
+
|
62
|
+
### 3. Temporary Ban
|
63
|
+
|
64
|
+
**Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
|
65
|
+
|
66
|
+
**Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
|
67
|
+
|
68
|
+
### 4. Permanent Ban
|
69
|
+
|
70
|
+
**Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
|
71
|
+
|
72
|
+
**Consequence**: A permanent ban from any sort of public interaction within the community.
|
73
|
+
|
74
|
+
## Attribution
|
75
|
+
|
76
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0,
|
77
|
+
available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
|
78
|
+
|
79
|
+
Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
|
80
|
+
|
81
|
+
[homepage]: https://www.contributor-covenant.org
|
82
|
+
|
83
|
+
For answers to common questions about this code of conduct, see the FAQ at
|
84
|
+
https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations.
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,106 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
siwe (0.1.3)
|
5
|
+
eth (~> 0.4.17)
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
ast (2.4.2)
|
11
|
+
backport (1.2.0)
|
12
|
+
benchmark (0.2.0)
|
13
|
+
diff-lcs (1.4.4)
|
14
|
+
e2mmap (0.1.0)
|
15
|
+
eth (0.4.17)
|
16
|
+
ffi (~> 1.15)
|
17
|
+
keccak (~> 1.3)
|
18
|
+
money-tree (~> 0.10)
|
19
|
+
rlp (~> 0.7)
|
20
|
+
scrypt (~> 3.0)
|
21
|
+
ffi (1.15.4)
|
22
|
+
ffi-compiler (1.0.1)
|
23
|
+
ffi (>= 1.0.0)
|
24
|
+
rake
|
25
|
+
jaro_winkler (1.5.4)
|
26
|
+
keccak (1.3.0)
|
27
|
+
kramdown (2.3.1)
|
28
|
+
rexml
|
29
|
+
kramdown-parser-gfm (1.1.0)
|
30
|
+
kramdown (~> 2.0)
|
31
|
+
money-tree (0.10.0)
|
32
|
+
ffi
|
33
|
+
nokogiri (1.12.5-x86_64-linux)
|
34
|
+
racc (~> 1.4)
|
35
|
+
parallel (1.21.0)
|
36
|
+
parser (3.0.3.1)
|
37
|
+
ast (~> 2.4.1)
|
38
|
+
racc (1.6.0)
|
39
|
+
rainbow (3.0.0)
|
40
|
+
rake (13.0.6)
|
41
|
+
regexp_parser (2.1.1)
|
42
|
+
reverse_markdown (2.1.1)
|
43
|
+
nokogiri
|
44
|
+
rexml (3.2.5)
|
45
|
+
rlp (0.7.3)
|
46
|
+
rspec (3.10.0)
|
47
|
+
rspec-core (~> 3.10.0)
|
48
|
+
rspec-expectations (~> 3.10.0)
|
49
|
+
rspec-mocks (~> 3.10.0)
|
50
|
+
rspec-core (3.10.1)
|
51
|
+
rspec-support (~> 3.10.0)
|
52
|
+
rspec-expectations (3.10.1)
|
53
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
54
|
+
rspec-support (~> 3.10.0)
|
55
|
+
rspec-mocks (3.10.2)
|
56
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
57
|
+
rspec-support (~> 3.10.0)
|
58
|
+
rspec-support (3.10.3)
|
59
|
+
rubocop (1.23.0)
|
60
|
+
parallel (~> 1.10)
|
61
|
+
parser (>= 3.0.0.0)
|
62
|
+
rainbow (>= 2.2.2, < 4.0)
|
63
|
+
regexp_parser (>= 1.8, < 3.0)
|
64
|
+
rexml
|
65
|
+
rubocop-ast (>= 1.12.0, < 2.0)
|
66
|
+
ruby-progressbar (~> 1.7)
|
67
|
+
unicode-display_width (>= 1.4.0, < 3.0)
|
68
|
+
rubocop-ast (1.13.0)
|
69
|
+
parser (>= 3.0.1.1)
|
70
|
+
ruby-progressbar (1.11.0)
|
71
|
+
scrypt (3.0.7)
|
72
|
+
ffi-compiler (>= 1.0, < 2.0)
|
73
|
+
solargraph (0.44.2)
|
74
|
+
backport (~> 1.2)
|
75
|
+
benchmark
|
76
|
+
bundler (>= 1.17.2)
|
77
|
+
diff-lcs (~> 1.4)
|
78
|
+
e2mmap
|
79
|
+
jaro_winkler (~> 1.5)
|
80
|
+
kramdown (~> 2.3)
|
81
|
+
kramdown-parser-gfm (~> 1.1)
|
82
|
+
parser (~> 3.0)
|
83
|
+
reverse_markdown (>= 1.0.5, < 3)
|
84
|
+
rubocop (>= 0.52)
|
85
|
+
thor (~> 1.0)
|
86
|
+
tilt (~> 2.0)
|
87
|
+
yard (~> 0.9, >= 0.9.24)
|
88
|
+
thor (1.1.0)
|
89
|
+
tilt (2.0.10)
|
90
|
+
unicode-display_width (2.1.0)
|
91
|
+
webrick (1.7.0)
|
92
|
+
yard (0.9.27)
|
93
|
+
webrick (~> 1.7.0)
|
94
|
+
|
95
|
+
PLATFORMS
|
96
|
+
x86_64-linux
|
97
|
+
|
98
|
+
DEPENDENCIES
|
99
|
+
rake (~> 13.0)
|
100
|
+
rspec (~> 3.0)
|
101
|
+
rubocop (~> 1.21)
|
102
|
+
siwe!
|
103
|
+
solargraph (~> 0.44)
|
104
|
+
|
105
|
+
BUNDLED WITH
|
106
|
+
2.2.32
|
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2021 Spruce Systems, Inc.
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2021 Gregório Granado Magalhães
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require "bundler/setup"
|
5
|
+
require "siwe"
|
6
|
+
|
7
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
8
|
+
# with your gem easier. You can also use a different console, if you like.
|
9
|
+
|
10
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
11
|
+
# require "pry"
|
12
|
+
# Pry.start
|
13
|
+
|
14
|
+
require "irb"
|
15
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/lib/siwe/message.rb
ADDED
@@ -0,0 +1,220 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "time"
|
4
|
+
require "eth"
|
5
|
+
require "json"
|
6
|
+
|
7
|
+
SIWE_DOMAIN = "^(?<domain>([^?#]*)) wants you to sign in with your Ethereum account:\\n"
|
8
|
+
SIWE_ADDRESS = "(?<address>0x[a-zA-Z0-9]{40})\\n\\n"
|
9
|
+
SIWE_STATEMENT = "((?<statement>[^\\n]+)\\n)?\\n"
|
10
|
+
SIWE_URI = "(([^:?#]+):)?(([^?#]*))?([^?#]*)(\\?([^#]*))?(#(.*))"
|
11
|
+
SIWE_URI_LINE = "URI: (?<uri>#{SIWE_URI}?)\\n"
|
12
|
+
SIWE_VERSION = "Version: (?<version>1)\\n"
|
13
|
+
SIWE_CHAIN_ID = "Chain ID: (?<chain_id>[0-9]+)\\n"
|
14
|
+
SIWE_NONCE = "Nonce: (?<nonce>[a-zA-Z0-9]{8,})\\n"
|
15
|
+
SIWE_DATETIME = "([0-9]+)-(0[1-9]|1[012])-(0[1-9]|[12][0-9]|3[01])[Tt]([01][0-9]|2[0-3]):([0-5][0-9])"\
|
16
|
+
":([0-5][0-9]|60)(\.[0-9]+)?(([Zz])|([\+|\-]([01][0-9]|2[0-3]):[0-5][0-9]))"
|
17
|
+
SIWE_ISSUED_AT = "Issued At: (?<issued_at>#{SIWE_DATETIME})"
|
18
|
+
SIWE_EXPIRATION_TIME = "(\\nExpiration Time: (?<expiration_time>#{SIWE_DATETIME}))?"
|
19
|
+
SIWE_NOT_BEFORE = "(\\nNot Before: (?<not_before>#{SIWE_DATETIME}))?"
|
20
|
+
SIWE_REQUEST_ID = "(\\nRequest ID: (?<request_id>[-._~!$&'()*+,;=:@%a-zA-Z0-9]*))?"
|
21
|
+
SIWE_RESOURCES = "(\\nResources:(?<resources>(\\n- #{SIWE_URI}?)+))?$"
|
22
|
+
|
23
|
+
SIWE_MESSAGE = "#{SIWE_DOMAIN}#{SIWE_ADDRESS}#{SIWE_STATEMENT}#{SIWE_URI_LINE}#{SIWE_VERSION}#{SIWE_CHAIN_ID}"\
|
24
|
+
"#{SIWE_NONCE}#{SIWE_ISSUED_AT}#{SIWE_EXPIRATION_TIME}#{SIWE_NOT_BEFORE}#{SIWE_REQUEST_ID}"\
|
25
|
+
"#{SIWE_RESOURCES}"
|
26
|
+
|
27
|
+
module Siwe
|
28
|
+
# Class that defines the EIP-4361 message fields and some utility methods to
|
29
|
+
# generate/validate the messages
|
30
|
+
class Message
|
31
|
+
# RFC 4501 dns authority that is requesting the signing.
|
32
|
+
attr_accessor :domain
|
33
|
+
|
34
|
+
# Ethereum address performing the signing conformant to capitalization
|
35
|
+
# encoded checksum specified in EIP-55 where applicable.
|
36
|
+
attr_accessor :address
|
37
|
+
|
38
|
+
# RFC 3986 URI referring to the resource that is the subject of the signing
|
39
|
+
# (as in the __subject__ of a claim).
|
40
|
+
attr_accessor :uri
|
41
|
+
|
42
|
+
# Current version of the message.
|
43
|
+
attr_accessor :version
|
44
|
+
|
45
|
+
# EIP-155 Chain ID to which the session is bound, and the network where
|
46
|
+
# Contract Accounts must be resolved.
|
47
|
+
attr_accessor :chain_id
|
48
|
+
|
49
|
+
# Randomized token used to prevent replay attacks, at least 8 alphanumeric
|
50
|
+
# characters.
|
51
|
+
attr_accessor :nonce
|
52
|
+
|
53
|
+
# ISO 8601 datetime string of the current time.
|
54
|
+
attr_accessor :issued_at
|
55
|
+
|
56
|
+
# Human-readable ASCII assertion that the user will sign, and it must not
|
57
|
+
# contain `\n`.
|
58
|
+
attr_accessor :statement
|
59
|
+
|
60
|
+
# ISO 8601 datetime string that, if present, indicates when the signed
|
61
|
+
# authentication message is no longer valid.
|
62
|
+
attr_accessor :expiration_time
|
63
|
+
|
64
|
+
# ISO 8601 datetime string that, if present, indicates when the signed
|
65
|
+
# authentication message will become valid.
|
66
|
+
attr_accessor :not_before
|
67
|
+
|
68
|
+
# System-specific identifier that may be used to uniquely refer to the
|
69
|
+
# sign-in request.
|
70
|
+
attr_accessor :request_id
|
71
|
+
|
72
|
+
# List of information or references to information the user wishes to have
|
73
|
+
# resolved as part of authentication by the relying party. They are
|
74
|
+
# expressed as RFC 3986 URIs separated by `\n- `.
|
75
|
+
attr_accessor :resources
|
76
|
+
|
77
|
+
# Signature of the message signed by the wallet.
|
78
|
+
attr_accessor :signature
|
79
|
+
|
80
|
+
def initialize(domain, address, uri, version, options = {})
|
81
|
+
@domain = domain
|
82
|
+
@address = address
|
83
|
+
@uri = uri
|
84
|
+
@version = version
|
85
|
+
|
86
|
+
@statement = options.fetch :statement, ""
|
87
|
+
@issued_at = options.fetch :issued_at, Time.now.utc.iso8601
|
88
|
+
@nonce = options.fetch :nonce, Siwe::Util.generate_nonce
|
89
|
+
@chain_id = options.fetch :chain_id, "1"
|
90
|
+
@expiration_time = options.fetch :expiration_time, ""
|
91
|
+
@not_before = options.fetch :not_before, ""
|
92
|
+
@request_id = options.fetch :request_id, ""
|
93
|
+
@resources = options.fetch :resources, []
|
94
|
+
@signature = options.fetch :signature, ""
|
95
|
+
validate(true)
|
96
|
+
end
|
97
|
+
|
98
|
+
def self.from_message(msg)
|
99
|
+
if (message = msg.match SIWE_MESSAGE)
|
100
|
+
msg = new(
|
101
|
+
message[:domain],
|
102
|
+
message[:address],
|
103
|
+
message[:uri],
|
104
|
+
message[:version],
|
105
|
+
{
|
106
|
+
statement: message[:statement] || "",
|
107
|
+
issued_at: message[:issued_at],
|
108
|
+
nonce: message[:nonce],
|
109
|
+
chain_id: message[:chain_id],
|
110
|
+
expiration_time: message[:expiration_time] || "",
|
111
|
+
not_before: message[:not_before] || "",
|
112
|
+
request_id: message[:request_id] || "",
|
113
|
+
resources: message[:resources]&.split("\n- ")&.drop(1) || []
|
114
|
+
}
|
115
|
+
)
|
116
|
+
msg.validate(true)
|
117
|
+
msg
|
118
|
+
else
|
119
|
+
throw "Invalid message input."
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
def to_json_string
|
124
|
+
obj = {
|
125
|
+
domain: @domain,
|
126
|
+
address: @address,
|
127
|
+
uri: @uri,
|
128
|
+
version: @version,
|
129
|
+
chain_id: @chain_id,
|
130
|
+
nonce: @nonce,
|
131
|
+
issued_at: @issued_at,
|
132
|
+
statement: @statement,
|
133
|
+
expiration_time: @expiration_time,
|
134
|
+
not_before: @not_before,
|
135
|
+
request_id: @request_id,
|
136
|
+
resources: @resources,
|
137
|
+
signature: @signature
|
138
|
+
}
|
139
|
+
obj.to_json
|
140
|
+
end
|
141
|
+
|
142
|
+
def self.from_json_string(str)
|
143
|
+
obj = JSON.parse str, { symbolize_names: true }
|
144
|
+
msg = Siwe::Message.new(
|
145
|
+
obj[:domain],
|
146
|
+
obj[:address],
|
147
|
+
obj[:uri],
|
148
|
+
obj[:version], {
|
149
|
+
chain_id: obj[:chain_id],
|
150
|
+
nonce: obj[:nonce],
|
151
|
+
issued_at: obj[:issued_at],
|
152
|
+
statement: obj[:statement],
|
153
|
+
expiration_time: obj[:expiration_time],
|
154
|
+
not_before: obj[:not_before],
|
155
|
+
request_id: obj[:request_id],
|
156
|
+
resources: obj[:resources],
|
157
|
+
signature: obj[:signature]
|
158
|
+
}
|
159
|
+
)
|
160
|
+
msg.validate(true)
|
161
|
+
msg
|
162
|
+
end
|
163
|
+
|
164
|
+
def validate(skip_signature = false)
|
165
|
+
raise "Message expired." if !@expiration_time.empty? && Time.now.utc > Time.parse(@expiration_time)
|
166
|
+
raise "Message not yet valid." if !@not_before.empty? && Time.now.utc < Time.parse(@not_before)
|
167
|
+
|
168
|
+
unless skip_signature
|
169
|
+
raise "Missing signature field." if @signature.empty?
|
170
|
+
|
171
|
+
pub_key = Eth::Key.personal_recover personal_sign, @signature
|
172
|
+
signature_address = Eth::Utils.public_key_to_address pub_key
|
173
|
+
raise "Signature doesn't match message." unless signature_address.downcase.eql? @address.downcase
|
174
|
+
end
|
175
|
+
|
176
|
+
true
|
177
|
+
end
|
178
|
+
|
179
|
+
def personal_sign
|
180
|
+
greeting = "#{@domain} wants you to sign in with your Ethereum account:"
|
181
|
+
address = @address
|
182
|
+
statement = "\n#{@statement}\n"
|
183
|
+
|
184
|
+
header = [greeting, address]
|
185
|
+
|
186
|
+
if @statement.empty?
|
187
|
+
header.push "\n"
|
188
|
+
else
|
189
|
+
header.push statement
|
190
|
+
end
|
191
|
+
|
192
|
+
header = header.join "\n"
|
193
|
+
|
194
|
+
uri = "URI: #{@uri}"
|
195
|
+
version = "Version: #{@version}"
|
196
|
+
chain_id = "Chain ID: #{@chain_id}"
|
197
|
+
nonce = "Nonce: #{@nonce}"
|
198
|
+
issued_at = "Issued At: #{@issued_at}"
|
199
|
+
|
200
|
+
body = [uri, version, chain_id, nonce, issued_at]
|
201
|
+
|
202
|
+
expiration_time = "Expiration Time: #{@expiration_time}"
|
203
|
+
not_before = "Not Before: #{@not_before}"
|
204
|
+
request_id = "Request ID: #{@request_id}"
|
205
|
+
resources = "Resources:\n#{@resources.map { |x| "- #{x}" }.join "\n"}"
|
206
|
+
|
207
|
+
body.push expiration_time unless @expiration_time.to_s.strip.empty?
|
208
|
+
|
209
|
+
body.push not_before unless @not_before.to_s.strip.empty?
|
210
|
+
|
211
|
+
body.push request_id unless @request_id.to_s.strip.empty?
|
212
|
+
|
213
|
+
body.push resources unless @resources.empty?
|
214
|
+
|
215
|
+
body = body.join "\n"
|
216
|
+
|
217
|
+
[header, body].join "\n"
|
218
|
+
end
|
219
|
+
end
|
220
|
+
end
|
data/lib/siwe/util.rb
ADDED
data/lib/siwe/version.rb
ADDED
data/lib/siwe.rb
ADDED
metadata
ADDED
@@ -0,0 +1,131 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: siwe
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.4
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Spruce Systems Inc.
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2021-12-09 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: eth
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.4.17
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.4.17
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '13.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '13.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rubocop
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '1.21'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '1.21'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: solargraph
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0.44'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0.44'
|
83
|
+
description: Sign-In with Ethereum library implementation
|
84
|
+
email:
|
85
|
+
- hello@spruceid.com
|
86
|
+
executables: []
|
87
|
+
extensions: []
|
88
|
+
extra_rdoc_files: []
|
89
|
+
files:
|
90
|
+
- ".rspec"
|
91
|
+
- ".rubocop.yml"
|
92
|
+
- ".solargraph.yml"
|
93
|
+
- CHANGELOG.md
|
94
|
+
- CODE_OF_CONDUCT.md
|
95
|
+
- Gemfile
|
96
|
+
- Gemfile.lock
|
97
|
+
- LICENSE
|
98
|
+
- LICENSE.txt
|
99
|
+
- README.md
|
100
|
+
- Rakefile
|
101
|
+
- bin/console
|
102
|
+
- bin/setup
|
103
|
+
- lib/siwe.rb
|
104
|
+
- lib/siwe/message.rb
|
105
|
+
- lib/siwe/util.rb
|
106
|
+
- lib/siwe/version.rb
|
107
|
+
homepage: https://login.xyz
|
108
|
+
licenses:
|
109
|
+
- MIT
|
110
|
+
metadata:
|
111
|
+
rubygems_mfa_required: 'true'
|
112
|
+
post_install_message:
|
113
|
+
rdoc_options: []
|
114
|
+
require_paths:
|
115
|
+
- lib
|
116
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
117
|
+
requirements:
|
118
|
+
- - ">="
|
119
|
+
- !ruby/object:Gem::Version
|
120
|
+
version: 2.6.0
|
121
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
122
|
+
requirements:
|
123
|
+
- - ">="
|
124
|
+
- !ruby/object:Gem::Version
|
125
|
+
version: '0'
|
126
|
+
requirements: []
|
127
|
+
rubygems_version: 3.2.32
|
128
|
+
signing_key:
|
129
|
+
specification_version: 4
|
130
|
+
summary: Sign-In with Ethereum
|
131
|
+
test_files: []
|