A Ruby Gem for layered action validation!
Go to file
VetheonGames ebc71cebf9 update readme 2023-10-07 10:44:55 -06:00
bin First draft at working code 2023-09-19 18:35:57 -06:00
lib add some comments, upadte gemspec, up minor subver 2023-09-19 23:53:38 -06:00
sig First draft at working code 2023-09-19 18:35:57 -06:00
spec First draft at working code 2023-09-19 18:35:57 -06:00
tests refactor a lot, add tests, add readme 2023-09-19 22:24:23 -06:00
.gitignore update gitignore 2023-09-19 23:59:03 -06:00
.rspec First draft at working code 2023-09-19 18:35:57 -06:00
.rubocop.yml First draft at working code 2023-09-19 18:35:57 -06:00
CODE_OF_CONDUCT.md First draft at working code 2023-09-19 18:35:57 -06:00
Gemfile First draft at working code 2023-09-19 18:35:57 -06:00
Gemfile.lock First draft at working code 2023-09-19 18:35:57 -06:00
LICENSE Update LICENSE to PixelRidge-BEGPULSE v1.3 2023-09-19 22:54:39 -06:00
README.md update readme 2023-10-07 10:44:55 -06:00
Rakefile First draft at working code 2023-09-19 18:35:57 -06:00
actionhash.gemspec Update gemspec and gitignore 2023-09-19 23:58:28 -06:00

README.md

ActionHash

If you'd like to support PixelRidge Softworks OpenSource Development, check out our Patreon
If you need more direct help, join our Discord

Overview

ActionHash is a Ruby gem designed to validate a series of actions while obfuscating the associated data. It's particularly useful in scenarios where you want to ensure the integrity of a sequence of actions or data points, such as in gaming, financial transactions, IoT devices, and more.

⚠️ Security Note: While ActionHash does obfuscate data, it should not be considered a form of encryption. If someone gains access to the generated secret key, the hashes can be undone. Use this gem as a part of your security strategy, not as the sole mechanism for securing sensitive information.

Installation

gem install actionhash

Or add it to your Gemfile:

gem 'actionhash'

Then run:

bundle install

Basic Usage

Here's a simple example to get you started:

require 'actionhash'

# Initialize
keys = [ActionHash.generate_new_key]
hashes = []  # Array to store finished hashes
action_count = 0
prev_hash = '0'
data = "some_data"

# Create a hash
new_hash = ActionHash.create(prev_hash, data, keys.last)
hashes << new_hash  # Store the hash

Validating a Hash

You can validate a hash using the valid_hash? method as follows:

# Validate the hash
is_valid = ActionHash.valid_hash?(hashes.last, keys.last, 20)

if is_valid
  puts "Hash is valid."
else
  puts "Hash is invalid."
end

The valid_hash? method works by recursively decrypting the hash and checking if it reaches a base hash of '0'. It takes the hash, the key, and an optional level parameter to limit the depth of validation.

Here's the method definition for your reference:

def self.valid_hash?(hash, key, level = 20)
  current_level = 0
  loop do
    puts "Debug: Validating hash=#{hash} with key=#{key} at level=#{current_level}"
    return false if current_level >= level

    decrypted_data = down_layer(hash, key)
    return true if decrypted_data[:prev_hash] == '0'
    return false if decrypted_data[:prev_hash].nil? || decrypted_data[:prev_hash].empty?

    hash = decrypted_data[:prev_hash]
    current_level += 1
  end
end

Development Builds

For those interested in using development builds of ActionHash, you can install them directly from our Gem server hosted at PixelRidge Softworks.

Here's how you can install a development build:

gem install ActionHash --source "https://git.pixelridgesoftworks.com/api/packages/PixelRidge-Softworks/rubygems"

As an example, if you want to install a different gem from our Gem server, you can use the following command:

gem install Miniparser --source "https://git.pixelridgesoftworks.com/api/packages/PixelRidge-Softworks/rubygems"