Bitcoin Forum

Bitcoin => Development & Technical Discussion => Topic started by: ronmike on October 12, 2017, 12:06:28 PM



Title: Private/public key generated by bitcore API issue!!! please help
Post by: ronmike on October 12, 2017, 12:06:28 PM
hello all,

I am a developer and faced below issue in development, so please help me :)

How do I create multiple addresses based on same private/public key generated by bitcore API?

Thanks in advanced


Title: Re: Private/public key generated by bitcore API issue!!! please help
Post by: DannyHamilton on October 12, 2017, 02:07:33 PM
hello all,

I am a developer and faced below issue in development, so please help me :)

How do I create multiple addresses based on same private/public key generated by bitcore API?

Thanks in advanced

If you are asking about P2PKH addresses (the addresses that start with a 1), then you don't.

It is only possible to create 2 addresses from a single public key.  A compressed key address (which is what you should be using) and an uncompressed key address.

You should not be using uncompressed key addresses. They are more expensive to use, and they provide you no extra benefit at all.

Each private key has ONLY 1 public key.

Each public key has ONLY 1 compressed key P2PKH address.
Each public key has ONLY 1 uncompressed key P2PKH address.

It is clear that you don't understand how bitcoins works, how addresses work, or what you are doing at all.  You should do a lot more learning before you start messing around with real value.


Title: Re: Private/public key generated by bitcore API issue!!! please help
Post by: aplistir on October 12, 2017, 03:13:12 PM
I am a developer and faced below issue in development, so please help me :)
How do I create multiple addresses based on same private/public key generated by bitcore API?

You could invent a nice rule on how to generate a new private key from your private key.

Example.
You could take your private key an multiply it by any number (for example: 36453278)  to get the next private key then multiply that to get the next one and so on.  You can do the multiply as many times as you want to. to generate as many addresses as you need.

Just remember that we are dealing with modular arithmetic, so you need to take a mod from the result, so that it wont get bigger than the maximum allowed value.

eg:

(privkey1*36453278) mod 115792089237316195423570985008687907853269984665640564039457584007908834671663

That is basically what HD wallets do to generate many private keys from one. Except, they use a bit more complicated algorithm and sha256 hash on each result so that even a small change will create a completely different private key.

The advantage of this kind of approach is that you only need to backup your original private key and the multiplier, and not a huge list of different private keys.


Title: Re: Private/public key generated by bitcore API issue!!! please help
Post by: ronmike on October 13, 2017, 06:03:25 AM
I am a developer and faced below issue in development, so please help me :)
How do I create multiple addresses based on same private/public key generated by bitcore API?

You could invent a nice rule on how to generate a new private key from your private key.

Example.
You could take your private key an multiply it by any number (for example: 36453278)  to get the next private key then multiply that to get the next one and so on.  You can do the multiply as many times as you want to. to generate as many addresses as you need.

Just remember that we are dealing with modular arithmetic, so you need to take a mod from the result, so that it wont get bigger than the maximum allowed value.

eg:

(privkey1*36453278) mod 115792089237316195423570985008687907853269984665640564039457584007908834671663

That is basically what HD wallets do to generate many private keys from one. Except, they use a bit more complicated algorithm and sha256 hash on each result so that even a small change will create a completely different private key.

The advantage of this kind of approach is that you only need to backup your original private key and the multiplier, and not a huge list of different private keys.

it is a string "115792089237316195423570985008687907853269984665640564039457584007908834671663" or something else..?


Title: Re: Private/public key generated by bitcore API issue!!! please help
Post by: aplistir on October 13, 2017, 08:58:36 AM
it is a string "115792089237316195423570985008687907853269984665640564039457584007908834671663" or something else..?

It's the value of the moduli. It is the biggest number in the curve secp256k1 that bitcoin uses.
=2^256-2^32-2^9-2^8-2^7-2^6-2^4-1

If your generated private key is bigger than that, then you have to subtract that number from your generated key as many times as necessary, until it becomes smaller than that number.

The security of bitcoin depends on big numbers. That is the reason why the moduli has to be so big.

https://en.bitcoin.it/wiki/Secp256k1 (https://en.bitcoin.it/wiki/Secp256k1)



Title: Re: Private/public key generated by bitcore API issue!!! please help
Post by: ronmike on October 13, 2017, 10:32:34 AM
it is a string "115792089237316195423570985008687907853269984665640564039457584007908834671663" or something else..?

It's the value of the moduli. It is the biggest number in the curve secp256k1 that bitcoin uses.
=2^256-2^32-2^9-2^8-2^7-2^6-2^4-1

If your generated private key is bigger than that, then you have to subtract that number from your generated key as many times as necessary, until it becomes smaller than that number.

The security of bitcoin depends on big numbers. That is the reason why the moduli has to be so big.

https://en.bitcoin.it/wiki/Secp256k1 (https://en.bitcoin.it/wiki/Secp256k1)




for example :
Here is my private key ="9c63e8e2f6574c197c0626bad843eb47104adf3f01f2901aad1258936feb007e"
var newprimarykey = (9c63e8e2f6574c197c0626bad843eb47104adf3f01f2901aad1258936feb007e * 36453278) mod 115792089237316195423570985008687907853269984665640564039457584007908834671663 );

console.log('newkey = ',newprimarykey);

If i am executing this one then it'll give error :

var t1 = (9c63e8e2f6574c197c0626bad843eb47104adf3f01f2901aad1258936feb007e * 36453278);
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

SyntaxError: Unexpected identifier
    at exports.runInThisContext (vm.js:53:16)
    at Module._compile (module.js:373:25)
    at Object.Module._extensions..js (module.js:416:10)
    at Module.load (module.js:343:32)
    at Function.Module._load (module.js:300:12)
    at Function.Module.runMain (module.js:441:10)
    at startup (node.js:140:18)
    at node.js:1043:3





Title: Re: Private/public key generated by bitcore API issue!!! please help
Post by: luv2drnkbr on October 13, 2017, 10:58:49 AM
it is a string "115792089237316195423570985008687907853269984665640564039457584007908834671663" or something else..?

It's the value of the moduli. It is the biggest number in the curve secp256k1 that bitcoin uses.
=2^256-2^32-2^9-2^8-2^7-2^6-2^4-1

If your generated private key is bigger than that, then you have to subtract that number from your generated key as many times as necessary, until it becomes smaller than that number.

The security of bitcoin depends on big numbers. That is the reason why the moduli has to be so big.

https://en.bitcoin.it/wiki/Secp256k1 (https://en.bitcoin.it/wiki/Secp256k1)




for example :
Here is my private key ="9c63e8e2f6574c197c0626bad843eb47104adf3f01f2901aad1258936feb007e"
var newprimarykey = (9c63e8e2f6574c197c0626bad843eb47104adf3f01f2901aad1258936feb007e * 36453278) mod 115792089237316195423570985008687907853269984665640564039457584007908834671663 );

console.log('newkey = ',newprimarykey);

If i am executing this one then it'll give error :

var t1 = (9c63e8e2f6574c197c0626bad843eb47104adf3f01f2901aad1258936feb007e * 36453278);
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

SyntaxError: Unexpected identifier
    at exports.runInThisContext (vm.js:53:16)
    at Module._compile (module.js:373:25)
    at Object.Module._extensions..js (module.js:416:10)
    at Module.load (module.js:343:32)
    at Function.Module._load (module.js:300:12)
    at Function.Module.runMain (module.js:441:10)
    at startup (node.js:140:18)
    at node.js:1043:3


I'm not a JS dev, but... you do know you have to convert the hex to decimal, right?  The private key is a hex representation of a really large number.  And I assume JS has some kind of BigInteger library or something for large numbers, which you would need to be using.

So you need to convert your private key from hex to decimal, THEN multiply it, and THEN take the result mod that other large number.

That said, you probably should not do any of that.  Instead, you should use the private key as a BIP 32 seed, and use a BIP 32 HD master key to generate your keys.  That's the best way to generate a bunch of addresses from one master private key.