grdn 0.1.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 7b229d9582680e5555879fd1734b774668c4303cba71edfb7a461fd12e599349
4
+ data.tar.gz: 00f51d7b7850b46a0a40fb1dcad251d4ea673373f5880708c21149d5b977a904
5
+ SHA512:
6
+ metadata.gz: fca162b2539e2173073d249fdc5eaca3a5effeb9131e8d2cb805178ea62ac15419fb0b3a040f142ef74115b38c4cdeb0e1414df23d1f8b3b9f1eaafd8cac18c4
7
+ data.tar.gz: 6a7bd6c7a4d5960aea6e32706db92599afd3e113f597dbc794a7ef4ec64c3e8d22e68d819b7035367412a3e1eb9f86e6575e50433ee9e19ad35c14b56b331195
@@ -0,0 +1,16 @@
1
+ name: Ruby
2
+
3
+ on: [push,pull_request]
4
+
5
+ jobs:
6
+ build:
7
+ runs-on: ubuntu-latest
8
+ steps:
9
+ - uses: actions/checkout@v2
10
+ - name: Set up Ruby
11
+ uses: ruby/setup-ruby@v1
12
+ with:
13
+ ruby-version: 2.7.0
14
+ bundler-cache: true
15
+ - name: Run the default task
16
+ run: bundle exec rake
data/.gitignore ADDED
@@ -0,0 +1,13 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ .grdn
11
+
12
+ # rspec failure tracking
13
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/Gemfile ADDED
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in grdn.gemspec
6
+ gemspec
7
+
8
+ gem "rake", "~> 13.0"
9
+
10
+ gem "rspec", "~> 3.0"
data/Gemfile.lock ADDED
@@ -0,0 +1,35 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ grdn (0.1.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ diff-lcs (1.4.4)
10
+ rake (13.0.6)
11
+ rspec (3.10.0)
12
+ rspec-core (~> 3.10.0)
13
+ rspec-expectations (~> 3.10.0)
14
+ rspec-mocks (~> 3.10.0)
15
+ rspec-core (3.10.1)
16
+ rspec-support (~> 3.10.0)
17
+ rspec-expectations (3.10.1)
18
+ diff-lcs (>= 1.2.0, < 2.0)
19
+ rspec-support (~> 3.10.0)
20
+ rspec-mocks (3.10.2)
21
+ diff-lcs (>= 1.2.0, < 2.0)
22
+ rspec-support (~> 3.10.0)
23
+ rspec-support (3.10.2)
24
+
25
+ PLATFORMS
26
+ ruby
27
+ x86_64-darwin-20
28
+
29
+ DEPENDENCIES
30
+ grdn!
31
+ rake (~> 13.0)
32
+ rspec (~> 3.0)
33
+
34
+ BUNDLED WITH
35
+ 2.2.17
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2021 Kevin Smith
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
@@ -0,0 +1,15 @@
1
+ # Garden - a place for your seeds
2
+
3
+ This tool stores seed phrases in a local directory (~/.grdn), and allows you to organize them hierarchically. Seeds are AES-128 encrypted with a password (the same one for all seeds), and stored in a tree structure. This allows organization by purpose, location, application, wallet, or anything else you can think of. They can be nested as deeply as you want. This tool is not recommended for security-critical usecases.
4
+
5
+ ## Installation
6
+
7
+ $ gem install grdn
8
+
9
+ ## Usage
10
+
11
+ To see usage information, run `grdn help`.
12
+
13
+ ## License
14
+
15
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ task default: :spec
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 "grdn"
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
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/exe/grdn ADDED
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "grdn"
4
+ Grdn::CLI.new.execute
data/grdn.gemspec ADDED
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "lib/grdn/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "grdn"
7
+ spec.version = Grdn::VERSION
8
+ spec.authors = ["Kevin Smith"]
9
+ spec.email = ["kevin.smith@coinbase.com"]
10
+
11
+ spec.summary = "This is a program for organizing seed phrases and storing them locally, encrypted"
12
+ spec.homepage = "https://github.com/ksmithbaylor/grdn"
13
+ spec.license = "MIT"
14
+ spec.required_ruby_version = Gem::Requirement.new(">= 2.4.0")
15
+
16
+ spec.metadata["allowed_push_host"] = "https://rubygems.org"
17
+
18
+ spec.metadata["homepage_uri"] = spec.homepage
19
+ spec.metadata["source_code_uri"] = spec.homepage
20
+ spec.metadata["changelog_uri"] = "https://github.com/ksmithbaylor/grdn"
21
+
22
+ # Specify which files should be added to the gem when it is released.
23
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
24
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
25
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{\A(?:test|spec|features)/}) }
26
+ end
27
+ spec.bindir = "exe"
28
+ spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
29
+ spec.require_paths = ["lib"]
30
+
31
+ # Uncomment to register a new dependency of your gem
32
+ # spec.add_dependency "example-gem", "~> 1.0"
33
+
34
+ # For more information and examples about making a new gem, checkout our
35
+ # guide at: https://bundler.io/guides/creating_gem.html
36
+ end
data/lib/grdn/cli.rb ADDED
@@ -0,0 +1,149 @@
1
+ require 'io/console'
2
+
3
+ module Grdn
4
+ class CLI
5
+ def execute
6
+ if ARGV.size == 0 || ['-h', '--help', 'help'].include?(ARGV[0])
7
+ cmd_help
8
+ exit
9
+ end
10
+
11
+ password = ask_password
12
+ @storage = Storage.new(password)
13
+
14
+ case ARGV.shift
15
+ when 'get'
16
+ cmd_get
17
+ when 'set'
18
+ cmd_set
19
+ when 'list'
20
+ cmd_list
21
+ when 'remove'
22
+ cmd_remove
23
+ else
24
+ raise Grdn::Error.new('Unknown command')
25
+ end
26
+ rescue Grdn::Error => e
27
+ STDERR.puts e.message
28
+ exit 1
29
+ end
30
+
31
+ def ask_password
32
+ IO::console.getpass 'Password: '
33
+ end
34
+
35
+ def cmd_help
36
+ puts <<~HELP
37
+ Garden: a place for your seeds
38
+ _
39
+ _(_)_ wWWWw _
40
+ @@@@ (_)@(_) vVVVv _ @@@@ (___) _(_)_
41
+ @@()@@ wWWWw (_)\\ (___) _(_)_ @@()@@ Y (_)@(_)
42
+ @@@@ (___) `|/ Y (_)@(_) @@@@ \\|/ (_)\\
43
+ / Y \\| \\|/ /(_) \\| |/ |
44
+ \\ | \\ |/ | / \\ | / \\|/ |/ \\| \\|/
45
+ \\\\|// \\\\|/// \\\\\\|//\\\\\\|/// \\|/// \\\\\\|// \\\\|// \\\\\\|//
46
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
47
+
48
+ This tool stores seed phrases in a local directory (~/.grdn),
49
+ and allows you to organize them hierarchically. Seeds are
50
+ AES-128 encrypted with a password (the same one for all seeds),
51
+ and stored in a tree structure. This allows organization by
52
+ purpose, location, application, wallet, or anything else you
53
+ can think of. They can be nested as deeply as you want. This
54
+ tool is not recommended for security-critical usecases.
55
+
56
+ =================================================================
57
+
58
+ Usage: grdn <command> [args]
59
+
60
+ Commands:
61
+ list List your seeds
62
+ set a [b c d e f ...] Add a seed
63
+ get a [b c d e f ...] Retrieve a seed
64
+ remove a [b c d e f ...] Remove a seed
65
+
66
+ Example:
67
+ The following commands:
68
+ $ grdn set commerce development my.email+test@domain.com
69
+ $ grdn set commerce production my.email@domain.com
70
+ $ grdn set commerce production my.other.email@domain.com
71
+ $ grdn set phone coinbase-wallet username
72
+ $ grdn set laptop electrum default_wallet
73
+ $ grdn set random
74
+
75
+ would product this output:
76
+ $ grdn list
77
+
78
+ commerce
79
+ development
80
+ my.email+test@domain.com
81
+ production
82
+ my.email@domain.com
83
+ my.other.email@domain.com
84
+ laptop
85
+ electrum
86
+ default_wallet
87
+ phone
88
+ coinbase-wallet
89
+ username
90
+ random
91
+ HELP
92
+ end
93
+
94
+ def cmd_get
95
+ if ARGV.empty?
96
+ STDERR.puts "Path must contain at least one segment"
97
+ exit
98
+ end
99
+ puts @storage.get(ARGV)
100
+ end
101
+
102
+ def cmd_set
103
+ if ARGV.empty?
104
+ STDERR.puts "Path must contain at least one segment"
105
+ exit
106
+ end
107
+
108
+ print 'Seed (type or paste, then hit enter three times): '
109
+ $/ = "\n\n\n"
110
+ input = STDIN.noecho(&:gets)
111
+ $/ = "\n"
112
+ seed = input.strip.split.join(' ')
113
+ words = seed.split.size
114
+ valid_seed_lengths = [12, 24]
115
+ if !valid_seed_lengths.include? words
116
+ STDERR.puts "Invalid seed. That one is #{words} words, must be " \
117
+ "#{valid_seed_lengths.join('/')} words"
118
+ exit 1
119
+ end
120
+ @storage.set(ARGV, seed)
121
+ STDERR.puts 'Seed saved!'
122
+ STDERR.puts "#{seed}"
123
+ end
124
+
125
+ def cmd_list
126
+ print_tree @storage.list
127
+ STDERR.puts
128
+ end
129
+
130
+ def cmd_remove
131
+ STDERR.puts "Printing here for safety: #{@storage.get(ARGV)}"
132
+ @storage.remove(ARGV)
133
+ STDERR.puts 'Seed removed!'
134
+ end
135
+
136
+ private
137
+
138
+ def print_tree(tree, indent = 2)
139
+ puts
140
+ tree.sort.to_h.each do |key, value|
141
+ next if key == Storage::FINAL_MARKER
142
+
143
+ print ' ' * indent
144
+ puts value[Storage::FINAL_MARKER] ? key.underline : key
145
+ print_tree(value, indent + 2) unless value.empty?
146
+ end
147
+ end
148
+ end
149
+ end
@@ -0,0 +1,115 @@
1
+ require 'fileutils'
2
+ require 'openssl'
3
+ require 'digest'
4
+
5
+ module Grdn
6
+ class Storage
7
+ DIR_NAME = '.grdn'
8
+ DEFAULT_LOCATION = File.expand_path(File.join(ENV['HOME'], DIR_NAME))
9
+ SALT = "\xB9R\xB5d\xBC#I?I7\x85<\xCD\xD6UW"
10
+ VALUE_FILENAME = 'seed.enc'
11
+ FINAL_MARKER = '____final____'
12
+ KEY_TEXT = 'password is correct'
13
+
14
+ def initialize(password, location = DEFAULT_LOCATION)
15
+ @location = location
16
+ @key = key_for(password)
17
+ FileUtils.mkdir_p @location
18
+ set_or_verify_password
19
+ end
20
+
21
+ def set(path, value)
22
+ if exists? path
23
+ raise Grdn::Error.new('Already exists, refusing to overwrite')
24
+ end
25
+
26
+ FileUtils.mkdir_p dir_for(path)
27
+ File.write value_file_for(path), encrypt(value)
28
+ end
29
+
30
+ def get(path)
31
+ unless exists? path
32
+ raise Grdn::Error.new('Does not exist')
33
+ end
34
+
35
+ decrypt File.read(value_file_for(path))
36
+ end
37
+
38
+ def remove(path)
39
+ FileUtils.rm_rf dir_for(path)
40
+ end
41
+
42
+ def list
43
+ absolute_paths = Dir.glob(File.join(@location, '**', VALUE_FILENAME))
44
+ paths = absolute_paths
45
+ .map { |p| File.dirname p }
46
+ .map { |p| p.gsub(@location + '/', '') }
47
+ .map { |p| p.split('/') }
48
+
49
+ tree = {}
50
+
51
+ paths.each do |path|
52
+ cursor = tree
53
+ path.each do |part|
54
+ cursor[part] ||= {}
55
+ cursor = cursor[part]
56
+ end
57
+ cursor[FINAL_MARKER] = true
58
+ end
59
+
60
+ tree
61
+ end
62
+
63
+ private
64
+
65
+ def exists?(path)
66
+ File.exist? value_file_for(path)
67
+ end
68
+
69
+ def set_or_verify_password
70
+ keyfile = File.join(@location, '.key')
71
+ if File.exist? keyfile
72
+ decrypt File.read(keyfile)
73
+ else
74
+ File.write(keyfile, encrypt(KEY_TEXT))
75
+ end
76
+ rescue OpenSSL::Cipher::CipherError
77
+ raise Grdn::Error.new('Wrong password')
78
+ end
79
+
80
+ def dir_for(path)
81
+ File.join(@location, *path)
82
+ end
83
+
84
+ def value_file_for(path)
85
+ dir = dir_for(path)
86
+ File.join(dir, VALUE_FILENAME)
87
+ end
88
+
89
+ def encrypt(string)
90
+ cipher = aes.encrypt
91
+ cipher.key = @key
92
+ cipher.update(string) + cipher.final
93
+ end
94
+
95
+ def decrypt(string)
96
+ cipher = aes.decrypt
97
+ cipher.key = @key
98
+ cipher.update(string) + cipher.final
99
+ end
100
+
101
+ def aes
102
+ OpenSSL::Cipher::AES.new(128, :CBC)
103
+ end
104
+
105
+ def key_for(password)
106
+ OpenSSL::KDF.pbkdf2_hmac(
107
+ password,
108
+ salt: SALT,
109
+ iterations: 1,
110
+ length: 16,
111
+ hash: OpenSSL::Digest::SHA256.new
112
+ )
113
+ end
114
+ end
115
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Grdn
4
+ VERSION = "0.1.0"
5
+ end
data/lib/grdn.rb ADDED
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "grdn/version"
4
+
5
+ class String
6
+ def underline
7
+ "\e[4m#{self}\e[24m"
8
+ end
9
+ end
10
+
11
+ module Grdn
12
+ class Error < StandardError; end
13
+ # Your code goes here...
14
+ end
15
+
16
+ require_relative "grdn/storage"
17
+ require_relative "grdn/cli"
metadata ADDED
@@ -0,0 +1,64 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: grdn
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Kevin Smith
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2022-02-09 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description:
14
+ email:
15
+ - kevin.smith@coinbase.com
16
+ executables:
17
+ - grdn
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - ".github/workflows/main.yml"
22
+ - ".gitignore"
23
+ - ".rspec"
24
+ - Gemfile
25
+ - Gemfile.lock
26
+ - LICENSE.txt
27
+ - README.md
28
+ - Rakefile
29
+ - bin/console
30
+ - bin/setup
31
+ - exe/grdn
32
+ - grdn.gemspec
33
+ - lib/grdn.rb
34
+ - lib/grdn/cli.rb
35
+ - lib/grdn/storage.rb
36
+ - lib/grdn/version.rb
37
+ homepage: https://github.com/ksmithbaylor/grdn
38
+ licenses:
39
+ - MIT
40
+ metadata:
41
+ allowed_push_host: https://rubygems.org
42
+ homepage_uri: https://github.com/ksmithbaylor/grdn
43
+ source_code_uri: https://github.com/ksmithbaylor/grdn
44
+ changelog_uri: https://github.com/ksmithbaylor/grdn
45
+ post_install_message:
46
+ rdoc_options: []
47
+ require_paths:
48
+ - lib
49
+ required_ruby_version: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: 2.4.0
54
+ required_rubygems_version: !ruby/object:Gem::Requirement
55
+ requirements:
56
+ - - ">="
57
+ - !ruby/object:Gem::Version
58
+ version: '0'
59
+ requirements: []
60
+ rubygems_version: 3.1.2
61
+ signing_key:
62
+ specification_version: 4
63
+ summary: This is a program for organizing seed phrases and storing them locally, encrypted
64
+ test_files: []