Blockchain does not verify addresses, so if we mistake it for the right address, we will lose our money.
Every adress has a checksum so it's pretty hard (impossible) to send to an adress with a typo.
https://gobittest.appspot.com/AddressNow suppose I choose a 99 random bytes to generate the private key, it is not a perfect idea but I want to know. How is the addreess, public and private key generated?
Needs to be below
0xFFFF FFFF FFFF FFFF FFFF FFFF FFFF FFFF FFFE BAAE DCE6 AF48 A03B BFD2 5E8C D036 4140
due to the curvature
then you ecsda it (get a public key), so you take a scalar (private key below ^) and repeat that along the the curve.
That results in a public key on which you perform the necessary operations.
for a standard address, see
https://gobittest.appspot.com/AddressSo let's say we have scalar
97668528691423002059228747364507275544785515506959736128404960720826822156012n
which is valid, because it's below
115792089237316195423570985008687907852837564279074904382605163141518161494337
and hex
d7ee6da182177c6be9cf2a14e6c41fb6a692663849f09cb947c3b27c6cdddeec
to get a public key, you simply multiply it (the starting point of the curve) by the scalar. (You should watch a video on how exactly this is done, for example:
https://www.youtube.com/watch?v=F3zzNa42-tQso then you get a point x,y , in my case
x: 37429941216543900232094877115525389998977649641483690331264124109562838279185n,
y: 30224260574053827691919187729967576172484851453209067507073176932097443187763n
Now you have an uncompressed and compressed public key, but really, you should never use uncompressed keys (due to them not working well with nested segwit et al?)
So to get the compressed public key, we look at y, and if it's odd, we add 0x02 in front of the x, otherwise 0x03,
so buffer x, append 0x02 if even, 0x03 if odd
and we get
0352c09891cd7fe1f9eed7776651805973986a9e8e6457e1095634ab72c8346411
Now to get this to an address we can perform a couple operations, for example for P2SH-P2WPKH we can do
we take the buffer of above compressed key
[
3, 82, 192, 152, 145, 205, 127, 225,
249, 238, 215, 119, 102, 81, 128, 89,
115, 152, 106, 158, 142, 100, 87, 225,
9, 86, 52, 171, 114, 200, 52, 100,
17
]
RMD160SHA256 it.
we get:
d9351dcbad5b8f3b8bfa2f2cdc85c28118ca9326
Then we create the redeemscript by adding 0x00 0x14 to the above result, and RDM160SHA256 it again.
7db6766dce18d816eaac1198391e8bdcf70b253a
now paste a prefix in front of it. for mainnet we use 0x05 so we get
057db6766dce18d816eaac1198391e8bdcf70b253a
calculate the checksum by double SHA256 hashing the redeemscript plus the added bytes, so we hash
057db6766dce18d816eaac1198391e8bdcf70b253a
result:
b3e8e9dd2be918e9bf078b4166180cae14a717be79d222debc3f8d50210f6596
& then take the first 4 bytes,
so
b3e8e9dd
add those to the back of the previous step, so we get
057db6766dce18d816eaac1198391e8bdcf70b253ab3e8e9dd
base58 the result ^ and you should get
3D9iyFHi1Zs9KoyynUfrL82rGhJfYTfSG4
I came across Code enthousiast's topic half the way through, so definitely check that out as well.
https://bitcointalksearch.org/topic/step-by-step-guide-to-creating-a-p2sh-p2wpkh-and-p2sh-p2wsh-addresses-5229211