Skip to content

Instantly share code, notes, and snippets.

View kingsleyh's full-sized avatar
😍
Coding

Kingsley Hendrickse kingsleyh

😍
Coding
View GitHub Profile
@kingsleyh
kingsleyh / ba.sh
Last active February 6, 2024 09:01 — forked from bvolpato/ba.sh
Install Chrome Driver with Xvfb (Ubuntu Server)
#!/bin/bash
# Chrome Repo
sudo apt-get install fonts-liberation xdg-utils libxss1 libappindicator1 libindicator7
wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
sudo dpkg -i google-chrome*.deb
sudo apt-get update
# Download
@kingsleyh
kingsleyh / app.cr
Created July 11, 2020 19:27
Entitas
require "crsfml"
require "entitas"
# ---- domain ----
module Domain
struct Dimension
property rows : Int32
property cols : Int32
def initialize(@rows, @cols); end
@kingsleyh
kingsleyh / workers.cr
Created April 27, 2020 18:38
the bit that does the workers
def start_workers(difficulty, block)
@workers = MinerWorker.create(@num_processes)
@workers.each do |w|
spawn do
loop do
break unless w.can_run
nonce_found_message = w.receive.try &.to_s || "error"
debug "received nonce #{nonce_found_message} from worker"
@kingsleyh
kingsleyh / jobs.cr
Last active April 27, 2020 14:46
multi fiber jobs
class Job
def self.create(number_of_jobs : Int32) : Array(Job)
jobs = [] of Job
inbound = Channel(String).new
outbound = Channel(String).new
number_of_jobs.times do |_|
job = Job.new(inbound, outbound)
job.run
jobs << job
@kingsleyh
kingsleyh / verify.cr
Created April 21, 2020 17:12
openssl pkey verify
def self.verify2(hex_public_key : String, message : String, r : String, s : String)
pkey = LibECCrypto.EVP_PKEY_new()
# Create a EC key structure, setting the group type from NID
eccgrp_id = LibECCrypto.OBJ_txt2nid("secp256k1")
raise "Error could not set EC group" unless eccgrp_id != 0
myecc = LibECCrypto.EC_KEY_new_by_curve_name(eccgrp_id)
raise "Error could not create curve" if myecc.null?
# convert binary public key to point
@kingsleyh
kingsleyh / smart_assets_considerations.md
Created September 30, 2019 11:16
Smart assets considerations
  1. when user invokes the asset via the API then all the work it does should be atomic and either succeed in it's entirety of fail with the appropriate message. This includes if the asset invokes other assets.

@kingsleyh
kingsleyh / smart_assets_spec.md
Created September 26, 2019 12:20
Smart Assets Spec

Smart Assets Spec

Summary

A smart asset is an entity which models a digital or real world item and is embedded into the blockchain. If we take the example of a game asset such as a sword we can model its attributes and behaviour in code which when invoked will execute the code and apply the logic.

Smart assets are defined in code and expose a set of external API's that can be invoked by the caller. Both the data that is created by the smart asset and the companion code is stored immutably in the blockchain within versioned transactions. When the code for the smart asset needs to mutate any of the associated data it creates transactions with the updated data and the latest version number. The fast transaction system is essential to make this possible.

@kingsleyh
kingsleyh / Taro_spec.md
Last active September 26, 2019 09:00
Taro spec

Taro Spec

For MVP initial version:

Requirements:

  1. must support basic programming logic, math, functions, variables, collections etc
  2. must support json - encoding / decoding / traversal
  3. must have http client capability
  4. must have crypto capability, openssl
@kingsleyh
kingsleyh / ecdsa.cr
Created December 9, 2018 18:29
OpenSSL EC
# http://fm4dd.com/openssl/eckeycreate.htm
# https://stackoverflow.com/questions/34404427/how-do-i-check-if-an-evp-pkey-contains-a-private-key
# https://davidederosa.com/basic-blockchain-programming/elliptic-curve-keys/
lib LibSSL
fun EC_KEY_generate_key(key : LibC::Int*) : LibC::Int
fun EC_KEY_new_by_curve_name(i : LibC::Int) : LibC::Int*
fun OBJ_txt2nid(s : LibC::Char*) : LibC::Int
fun EVP_PKEY_new : LibC::Int*
fun EVP_PKEY_assign(pkey : LibC::Int*, type : LibC::Int, key : Void*) : LibC::Int
@kingsleyh
kingsleyh / eckeycreate.c
Created December 8, 2018 23:34
create ecdsa keys
/* ------------------------------------------------------------ *
* file: eckeycreate.c *
* purpose: Example code for creating elliptic curve *
* cryptography (ECC) key pairs *
* author: 01/26/2015 Frank4DD *
* *
* gcc -o eckeycreate eckeycreate.c -lssl -lcrypto *
* ------------------------------------------------------------ */
#include <openssl/bio.h>