I’ve generated a bitcoin tackle the usage of the next instructions at the side of a ruby script for compression.
First I generate a key the usage of echo "24 phrase seed word BIP 39" | openssl sha256
Then run the under Ruby script to compress the important thing
# instance non-public key
private_key = "non-public key that has been generated with earlier command"
# --------------------------
# Secp256k1 Curve Parameters
# --------------------------
# y^2 = x^3 + ax + b
$a = 0
$b = 7 # the usage of world variables for comfort
# high modulus
$p = 2 ** 256 - 2 ** 32 - 2 ** 9 - 2 ** 8 - 2 ** 7 - 2 ** 6 - 2 ** 4 - 1
# collection of issues at the curve
$n = 115792089237316195423570985008687907852837564279074904382605163141518161494337
# generator level (the start line at the curve used for all calculations)
$g = {
x: 55066263022277343669578718895168534326250603453777594175500187360389116729240,
y: 32670510020758816978083085130507043184471273380659243275938904335757337482424,
}
# --------------------------
# Elliptic Curve Arithmetic
# --------------------------
# Modular Inverse - Ruby does not have a integrated serve as for locating modular inverses, so here is one the usage of the prolonged Euclidean set of rules.
def modinv(a, m = $p)
a = a % m if a < 0 # be certain that a is certain
prevy, y = 0, 1
whilst a > 1
q = m / a
y, prevy = prevy - q * y, y
a, m = m % a, a
finish
go back y
finish
# Double - Upload some degree at the curve to itself.
def double(level)
# slope = (3x^2 + a) / 2y
slope = ((3 * level[:x] ** 2) * modinv((2 * level[:y]))) % $p # the usage of modular inverse to accomplish "department"
# new x = slope^2 - 2x
x = (slope ** 2 - (2 * level[:x])) % $p
# new y = slope * (x - new x) * y
y = (slope * (level[:x] - x) - level[:y]) % $p
# go back x, y coordinates of level
go back { x: x, y: y }
finish
# Upload - Upload two issues in combination.
def upload(point1, point2)
# double if each issues are the similar
go back double(point1) if point1 == point2
# slope = (y1 - y2) / (x1 - x2)
slope = ((point1[:y] - point2[:y]) * modinv(point1[:x] - point2[:x])) % $p
# new x = slope^2 - x1 - x2
x = (slope ** 2 - point1[:x] - point2[:x]) % $p
# new y = slope * (x1 - new x) - y1
y = ((slope * (point1[:x] - x)) - point1[:y]) % $p
# go back x, y coordinates of level
go back { x: x, y: y }
finish
# Multiply - Use the double and upload operations to briefly multiply some degree through an integer (e.g. a personal key).
def multiply(okay, level = $g) # multiply the generator level through default
# create a replica the preliminary start line (to be used as well as afterward)
present = level
# convert integer to binary illustration (to be used within the double and upload set of rules)
binary = okay.to_s(2)
# double and upload set of rules for quick multiplication
binary.cut up("").drop(1).each and every do |char| # forget about first binary personality
# 0 = double
present = double(present)
# 1 = double and upload
if char == "1"
present = upload(present, level)
finish
finish
# go back the overall level
go back present
finish
# -------------------------
# Non-public Key To Public Key
# -------------------------
# convert non-public key to an integer
okay = private_key.to_i(16)
# multiply generator level through this non-public key
level = multiply(okay, $g) # this level is the general public key
# convert x and y values of this level to hexadecimal
x = level[:x].to_s(16).rjust(64, "0")
y = level[:y].to_s(16).rjust(64, "0")
# uncompressed public key layout (no longer used a lot in this day and age, simply appearing the way it seems to be)
public_key_uncompressed = "04" + x + y
# compressed public key layout (each and every x price has a y that may be one among two imaginable issues)
if (level[:y] % 2 == 0)
prefix = "02" # if y is even
else
prefix = "03" # if y is strange
finish
public_key_compressed = prefix + x # most effective makes use of the total x coordinate
# -------
# Effects
# -------
places private_key #=> ef235aacf90d9f4aadd8c92e4b2562e1d9eb97f0df9ba3b508258739cb013db2
places public_key_compressed
Then hashing the important thing once more with
echo compressed key from ruby script | xxd -r -p | openssl sha256
Then echo hashed key | xxd -r -p | openssl ripemd160
And in the end including 00
to the important thing
echo 00key | xxd -p -r | base58 -c && echo
The tackle I am getting is in a position to receiving finances, however I will’t get well the usage of the 24 phrase seed word the usage of BlueWallet import serve as. What am I doing unsuitable?
https://learnmeabitcoin.com/technical/public-key Hyperlink to Ruby Script
https://medium.com/coinmonks/how-to-generate-a-bitcoin-address-step-by-step-9d7fcbf1ad0b Hyperlink to Openssl Instructions