Skip to content

Commit

Permalink
up
Browse files Browse the repository at this point in the history
  • Loading branch information
geraldb committed Dec 11, 2022
1 parent f433407 commit 00a1286
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
11 changes: 6 additions & 5 deletions crypto-lite/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -227,10 +227,10 @@ All-in-one "best-of-both-worlds" helper - first hash with sha256 and than hash w


``` ruby
hash160( '02b9d1cc0b793b03b9f64d022e9c67d5f32670b03f636abf0b3147b34123d13990' ).hexdigest
hash160( hex: '02b9d1cc0b793b03b9f64d022e9c67d5f32670b03f636abf0b3147b34123d13990' ).hexdigest
#=> "e6b145a3908a4d6616b13c1109717add8672c900"

hash160( '02b4632d08485ff1df2db55b9dafd23347d1c47a457072a1e87be26896549a8737' ).hexdigest
hash160( hex: '02b4632d08485ff1df2db55b9dafd23347d1c47a457072a1e87be26896549a8737' ).hexdigest
#=> "93ce48570b55c42c2af816aeaba06cfee1224fae"
```

Expand All @@ -245,10 +245,11 @@ All-in-one double sha256 hash helper, that is, first hash with sha256 and than h

``` ruby
hash256( '6fe6b145a3908a4d6616b13c1109717add8672c900' ).hexdigest
hash256( hex: '6fe6b145a3908a4d6616b13c1109717add8672c900' ).hexdigest
#=> "02335f08b8fe4ddad263a50b7a33c5d38ea1cbd8fd2056a1320a3ddece541711"
```


#### Base58 Encoding / Decoding Helpers

**BASE58**
Expand Down Expand Up @@ -341,7 +342,7 @@ Sign a transaction with an (elliptic curve) private key:
``` ruby
# Step 1 - Calculate the Transaction (tx) Hash
tx = 'from: Alice to: Bob cryptos: 43_000_000_000'
txhash = sha256( tx ).hexdigest
txhash = sha256( tx )

# Step 2 - Get the Signer's Private key
private_key = EC::PrivateKey.new( 1234 ) # This private key is just an example. It should be much more secure!
Expand All @@ -368,7 +369,7 @@ Verify a signed transaction with an (elliptic curve) public key:
``` ruby
# Step 1 - Calculate the Transaction (tx) Hash
tx = 'from: Alice to: Bob cryptos: 43_000_000_000'
txhash = sha256( tx ).hexdigest
txhash = sha256( tx )

# Step 2 - Get the Signer's Public Key
public_key = EC::PublicKey.new(
Expand Down
6 changes: 4 additions & 2 deletions crypto-lite/sandbox/test_sign.rb
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,8 @@


tx = "from: alice, to: bob, $21"
pp tx_hash = sha256( tx ).hexdigest
tx_hash = sha256( tx )
pp tx_hash.hexdigest
#=> "426a472a6c69bf68354391b7822393bea3952cde9df8949ad7a0f5f405b2fcb5"

puts "---"
Expand All @@ -113,7 +114,8 @@
#=> true

tx = "from: alice, to: bob, $22"
pp tx_hash = sha256( tx ).hexdigest
tx_hash = sha256( tx )
pp tx_hash.hexdigest
#=> "e899604bb4c95d2f1a7cfe561ad65941769e2064bdbbcaa79eb64ce0a2832380"

pp RSA.valid_signature?( tx_hash, tx_signature, alice_pub )
Expand Down

0 comments on commit 00a1286

Please sign in to comment.