token_chain 0.0.1
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 +7 -0
- data/.gitignore +17 -0
- data/.rspec +2 -0
- data/.travis.yml +3 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +50 -0
- data/Rakefile +6 -0
- data/lib/token_chain/anchor.rb +20 -0
- data/lib/token_chain/generator.rb +36 -0
- data/lib/token_chain/version.rb +3 -0
- data/lib/token_chain.rb +20 -0
- data/spec/spec_helper.rb +6 -0
- data/spec/token_chain/anchor_spec.rb +16 -0
- data/spec/token_chain/generator_spec.rb +52 -0
- data/spec/token_chain_spec.rb +7 -0
- data/token_chain.gemspec +25 -0
- metadata +120 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 77ed443045a9c78fbff6abb131d744bae5313eda
|
4
|
+
data.tar.gz: 1fb482fc5cf03cf169c0f72dff3dbe6dc72a2f41
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: d8ed8520e1cdbe1274cbaf361f194382dc90cbc296802de08480e88e523f7c351a2bd5e99e6cace08996ad59d7501c27814fe9095195d96129b3c15fcd322324
|
7
|
+
data.tar.gz: e76df45526a3b45332bff03a5dad49b7c65ec4601969f6ddb0099b26c0a159f708d98a9fcc39e893ac4940cb4bd2c971e86a60e9b111c67fdb0ff5a5fb6b61f7
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2015 Joel Helbling
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
# TokenChain
|
2
|
+
|
3
|
+
Generates a deterministic chain (or sequence) of tokens from a passphrase.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'token_chain'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install token_chain
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
You can create a token chain from a passphrase:
|
22
|
+
|
23
|
+
```ruby
|
24
|
+
chain = TokenChain.from_passphrase 'the rain in spain'
|
25
|
+
chain.generate #=> [first token]
|
26
|
+
chain.generate(2) #=> [second token, third token]
|
27
|
+
chain.anchor_code #=> anchor code for this chain, useful for restarting w/out passphrase
|
28
|
+
```
|
29
|
+
|
30
|
+
Provided you have a chain's anchor code, you can also "restart" a chain without the passphrase:
|
31
|
+
|
32
|
+
```ruby
|
33
|
+
chain = TokenChain.from_anchor [anchor code]
|
34
|
+
chain.generate #=> [first token]
|
35
|
+
```
|
36
|
+
|
37
|
+
You can even jumpstart the chain to generate from a previously generated token:
|
38
|
+
|
39
|
+
```ruby
|
40
|
+
chain = TokenChain.from_anchor [anchor code], [second code]
|
41
|
+
chain.generate #=> [third code]
|
42
|
+
```
|
43
|
+
|
44
|
+
## Contributing
|
45
|
+
|
46
|
+
1. Fork it ( http://github.com/<my-github-username>/token_chain/fork )
|
47
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
48
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
49
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
50
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'digest/sha2'
|
2
|
+
|
3
|
+
module TokenChain
|
4
|
+
module Anchor
|
5
|
+
class << self
|
6
|
+
|
7
|
+
def from passphrase
|
8
|
+
second_seed = sha.base64digest passphrase
|
9
|
+
sha.base64digest second_seed + passphrase
|
10
|
+
end
|
11
|
+
|
12
|
+
private
|
13
|
+
|
14
|
+
def sha
|
15
|
+
@sha ||= Digest::SHA256.new
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'digest/sha2'
|
2
|
+
|
3
|
+
module TokenChain
|
4
|
+
class Generator
|
5
|
+
attr_reader :codes, :anchor_code
|
6
|
+
|
7
|
+
def initialize anchor_code, last_code=nil
|
8
|
+
@anchor_code = anchor_code
|
9
|
+
@last_code = last_code
|
10
|
+
@codes = []
|
11
|
+
end
|
12
|
+
|
13
|
+
def generate quantity=1
|
14
|
+
codes = make_new_codes quantity
|
15
|
+
quantity > 1 ? codes : codes.last
|
16
|
+
end
|
17
|
+
|
18
|
+
def sha
|
19
|
+
@sha ||= Digest::SHA2.new
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
def make_new_codes number
|
25
|
+
(1..number).inject([]) do |memo, _|
|
26
|
+
part_one = memo.last || @codes.last || @last_code || @anchor_code
|
27
|
+
part_two = @anchor_code
|
28
|
+
|
29
|
+
memo << sha.base64digest("#{part_one}#{part_two}")
|
30
|
+
end.tap do |new_codes|
|
31
|
+
@codes.concat new_codes
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
36
|
+
end
|
data/lib/token_chain.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'token_chain/version'
|
2
|
+
require 'token_chain/anchor'
|
3
|
+
require 'token_chain/generator'
|
4
|
+
|
5
|
+
module TokenChain
|
6
|
+
|
7
|
+
class << self
|
8
|
+
|
9
|
+
def from_passphrase passphrase
|
10
|
+
anchor_code = Anchor.from passphrase
|
11
|
+
Generator.new anchor_code
|
12
|
+
end
|
13
|
+
|
14
|
+
def from_anchor anchor_code, last_code=nil
|
15
|
+
Generator.new anchor_code last_code
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'token_chain/anchor'
|
3
|
+
|
4
|
+
module TokenChain
|
5
|
+
describe Anchor do
|
6
|
+
Given(:sha) { Digest::SHA256.new }
|
7
|
+
Given(:passphrase) { 'the rain in spain' }
|
8
|
+
Given(:second_seed) { sha.base64digest passphrase }
|
9
|
+
Given(:anchor_code) { sha.base64digest second_seed + passphrase }
|
10
|
+
When(:anchor) { described_class.from passphrase }
|
11
|
+
|
12
|
+
context 'instantiation' do
|
13
|
+
Then { anchor == anchor_code }
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'token_chain/generator'
|
3
|
+
|
4
|
+
module TokenChain
|
5
|
+
describe Generator do
|
6
|
+
Given(:sha) { Digest::SHA256.new }
|
7
|
+
Given(:passphrase) { 'the rain in spain' }
|
8
|
+
Given(:second_seed) { sha.base64digest passphrase }
|
9
|
+
Given(:anchor_code) { sha.base64digest second_seed + passphrase }
|
10
|
+
Given(:first_code) { sha.base64digest anchor_code + anchor_code }
|
11
|
+
Given(:second_code) { sha.base64digest first_code + anchor_code }
|
12
|
+
Given(:third_code) { sha.base64digest second_code + anchor_code }
|
13
|
+
|
14
|
+
context 'anchor with no last code' do
|
15
|
+
Given(:chain) { described_class.new anchor_code }
|
16
|
+
|
17
|
+
describe 'generates a token' do
|
18
|
+
When(:result) { chain.generate }
|
19
|
+
Then { result == first_code }
|
20
|
+
end
|
21
|
+
|
22
|
+
describe 'generates multiple tokens' do
|
23
|
+
When(:result) { chain.generate(3) }
|
24
|
+
Then { result == [ first_code, second_code, third_code ] }
|
25
|
+
end
|
26
|
+
|
27
|
+
describe 'return just the generated tokens' do
|
28
|
+
When { chain.generate }
|
29
|
+
When(:result) { chain.generate(2) }
|
30
|
+
Then { result == [ second_code, third_code ] }
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
context 'anchor with a last code' do
|
35
|
+
Given(:last_code) { third_code }
|
36
|
+
Given(:fourth_code) { sha.base64digest third_code + anchor_code }
|
37
|
+
Given(:fifth_code) { sha.base64digest fourth_code + anchor_code }
|
38
|
+
Given(:chain) { described_class.new anchor_code, last_code }
|
39
|
+
|
40
|
+
describe 'generates a token' do
|
41
|
+
When(:result) { chain.generate }
|
42
|
+
Then { result == fourth_code }
|
43
|
+
end
|
44
|
+
|
45
|
+
describe 'generates multiple tokens' do
|
46
|
+
When(:result) { chain.generate(2) }
|
47
|
+
Then { result == [ fourth_code, fifth_code ] }
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
52
|
+
end
|
data/token_chain.gemspec
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'token_chain/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "token_chain"
|
8
|
+
spec.version = TokenChain::VERSION
|
9
|
+
spec.authors = ["Joel Helbling"]
|
10
|
+
spec.email = ["joel@joelhelbling.com"]
|
11
|
+
spec.summary = %q{Generates a deterministic chain of tokens from a passphrase.}
|
12
|
+
spec.description = %q{Generates a deterministic chain of tokens from a passphrase.}
|
13
|
+
spec.homepage = "http://github.com/joelhelbling/token_chain"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.5"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
spec.add_development_dependency "rspec"
|
24
|
+
spec.add_development_dependency "rspec-given"
|
25
|
+
end
|
metadata
ADDED
@@ -0,0 +1,120 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: token_chain
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Joel Helbling
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-01-06 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.5'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.5'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '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: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec-given
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
description: Generates a deterministic chain of tokens from a passphrase.
|
70
|
+
email:
|
71
|
+
- joel@joelhelbling.com
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- ".gitignore"
|
77
|
+
- ".rspec"
|
78
|
+
- ".travis.yml"
|
79
|
+
- Gemfile
|
80
|
+
- LICENSE.txt
|
81
|
+
- README.md
|
82
|
+
- Rakefile
|
83
|
+
- lib/token_chain.rb
|
84
|
+
- lib/token_chain/anchor.rb
|
85
|
+
- lib/token_chain/generator.rb
|
86
|
+
- lib/token_chain/version.rb
|
87
|
+
- spec/spec_helper.rb
|
88
|
+
- spec/token_chain/anchor_spec.rb
|
89
|
+
- spec/token_chain/generator_spec.rb
|
90
|
+
- spec/token_chain_spec.rb
|
91
|
+
- token_chain.gemspec
|
92
|
+
homepage: http://github.com/joelhelbling/token_chain
|
93
|
+
licenses:
|
94
|
+
- MIT
|
95
|
+
metadata: {}
|
96
|
+
post_install_message:
|
97
|
+
rdoc_options: []
|
98
|
+
require_paths:
|
99
|
+
- lib
|
100
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
101
|
+
requirements:
|
102
|
+
- - ">="
|
103
|
+
- !ruby/object:Gem::Version
|
104
|
+
version: '0'
|
105
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
106
|
+
requirements:
|
107
|
+
- - ">="
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0'
|
110
|
+
requirements: []
|
111
|
+
rubyforge_project:
|
112
|
+
rubygems_version: 2.4.3
|
113
|
+
signing_key:
|
114
|
+
specification_version: 4
|
115
|
+
summary: Generates a deterministic chain of tokens from a passphrase.
|
116
|
+
test_files:
|
117
|
+
- spec/spec_helper.rb
|
118
|
+
- spec/token_chain/anchor_spec.rb
|
119
|
+
- spec/token_chain/generator_spec.rb
|
120
|
+
- spec/token_chain_spec.rb
|