Add serialization of account secret key #31

Merged
davidyuk merged 1 commits from github/fork/davidyuk/secret-key into master 2023-11-14 00:13:54 +09:00
davidyuk commented 2023-08-02 02:15:05 +09:00 (Migrated from gitlab.com)

JS SDK misses a fancy way to serialize an account secret key. Currently, it uses a very long hex string representing 64 bytes. Would be good to define a more efficient and distinguishable way to encode account secret keys.

This PR is supported by the Æternity Crypto Foundation

JS SDK misses a fancy way to serialize an account secret key. Currently, it uses [a very long](https://github.com/aeternity/aepp-sdk-js/blob/5df22dd297abebc0607710793a7234e6761570d4/examples/node/transfer-ae.mjs#L23) hex string representing 64 bytes. Would be good to define a more efficient and distinguishable way to encode account secret keys. This PR is supported by the Æternity Crypto Foundation
loxs (Migrated from gitlab.com) approved these changes 2023-08-02 02:15:05 +09:00
davidyuk commented 2023-08-02 02:15:33 +09:00 (Migrated from gitlab.com)

I propose to use BASE64 as it is a low-level thing don't be needed to handle by users in everyday life. Though I'm fine to use BASE58.

I propose to use BASE64 as it is a low-level thing don't be needed to handle by users in everyday life. Though I'm fine to use BASE58.
davidyuk commented 2023-08-02 02:15:46 +09:00 (Migrated from gitlab.com)

Using "secret" instead of "private" to have less visual overlap with "public", also this is consistent with naming in tweetnacl https://www.npmjs.com/package/tweetnacl

Using "secret" instead of "private" to have less visual overlap with "public", also this is consistent with naming in tweetnacl https://www.npmjs.com/package/tweetnacl
davidyuk commented 2023-08-02 02:17:02 +09:00 (Migrated from gitlab.com)

tweetnacl operates with 64-byte secret keys though half of it is a public key, we can safely drop it to reduce key size. Not sure if would it affect performance or so.

tweetnacl operates with 64-byte secret keys though half of it is a public key, we can safely drop it to reduce key size. Not sure if would it affect performance or so.
zxq9 commented 2023-08-10 00:11:18 +09:00 (Migrated from gitlab.com)

Created by: dincho

I'd argue about consistency here: account_prvkey

*Created by: dincho* I'd argue about consistency here: `account_prvkey`
loxs commented 2023-08-10 19:47:16 +09:00 (Migrated from gitlab.com)

I agree with Dincho

I agree with Dincho
davidyuk commented 2023-08-18 02:29:45 +09:00 (Migrated from gitlab.com)

Would prvkey be consistent with naming in this repo or the node? Or you mean in style of pubkey? Maybe to name it seckey, scrtkey, or secrkey?
http://acronymsandslang.com/abbreviation-for/SECRET.html
https://www.allacronyms.com/secret/abbreviated

Would you rename prefix also to "pk"?

Here is one more example from original NaCl docs

unsigned char pk[crypto_sign_PUBLICKEYBYTES];
unsigned char sk[crypto_sign_SECRETKEYBYTES];

https://nacl.cr.yp.to/sign.html

Would `prvkey` be consistent with naming in this repo or the node? Or you mean in style of `pubkey`? Maybe to name it `seckey`, `scrtkey`, or `secrkey`? http://acronymsandslang.com/abbreviation-for/SECRET.html https://www.allacronyms.com/secret/abbreviated Would you rename prefix also to "pk"? Here is one more example from original NaCl docs ```c unsigned char pk[crypto_sign_PUBLICKEYBYTES]; unsigned char sk[crypto_sign_SECRETKEYBYTES]; ``` https://nacl.cr.yp.to/sign.html
davidyuk commented 2023-08-21 15:50:08 +09:00 (Migrated from gitlab.com)

While the public key can always be derived from the seed, the precomputation saves a significant amount of CPU cycles when signing.

https://doc.libsodium.org/public-key_cryptography/public-key_signatures#extracting-the-seed-and-the-public-key-from-the-secret-key
https://github.com/aeternity/protocol/blob/master/consensus/README.md#keys

in the most cases in can be computed once by app and cached 🤷‍♀️ 32 bytes would be easier to read in QR codes (if used in invite links)

> While the public key can always be derived from the seed, the precomputation saves a significant amount of CPU cycles when signing. https://doc.libsodium.org/public-key_cryptography/public-key_signatures#extracting-the-seed-and-the-public-key-from-the-secret-key https://github.com/aeternity/protocol/blob/master/consensus/README.md#keys in the most cases in can be computed once by app and cached 🤷‍♀️ 32 bytes would be easier to read in QR codes (if used in invite links)
zxq9 commented 2023-08-28 16:24:16 +09:00 (Migrated from gitlab.com)

Created by: hanssv

No opinion about the format - just a reminder from the past. It is NOT an omission that there is no way to serialize a secret/private key... You should never be tempted to do it, except for possibly testing, you should not serialize and store a private key.

*Created by: hanssv* No opinion about the format - just a reminder from the past. It is NOT an omission that there is no way to serialize a secret/private key... You should never be tempted to do it, except for possibly testing, you should not serialize and store a private key.
davidyuk commented 2023-08-28 18:14:21 +09:00 (Migrated from gitlab.com)

For a backend service (or an oracle) can serialized private key be stored along with other API tokens in production? I mean as a hot coin storage.

@dincho @loxs Let's agree on sk_ prefix, account_seckey.

For a backend service (or an oracle) can serialized private key be stored along with other API tokens in production? I mean as a hot coin storage. @dincho @loxs Let's agree on `sk_` prefix, `account_seckey`.
loxs commented 2023-08-28 22:44:42 +09:00 (Migrated from gitlab.com)

I don't have hard feelings here, I agree that consistency is good, but I see Denis' point too.

I don't have hard feelings here, I agree that consistency is good, but I see Denis' point too.
loxs commented 2023-08-28 22:51:00 +09:00 (Migrated from gitlab.com)

Probably what Hans has in mind is that such services need to use aex3 wallet files in such cases. As always, the real world is a bit different, even the node gained this ability just recently (not merged yet): https://github.com/aeternity/aeternity/pull/4171

The current state is that we put base64 encoded private keys in the node config file... (of course)

My opinion is that we cannot escape from various people doing it and this PR is more good than bad (although it's a bit debatable).

Probably what Hans has in mind is that such services need to use aex3 wallet files in such cases. As always, the real world is a bit different, even the node gained this ability just recently (not merged yet): https://github.com/aeternity/aeternity/pull/4171 The current state is that we put base64 encoded private keys in the node config file... (of course) My opinion is that we cannot escape from various people doing it and this PR is more good than bad (although it's a bit debatable).
davidyuk commented 2023-08-29 00:44:47 +09:00 (Migrated from gitlab.com)

need to use aex3 wallet files

Where store the AEX-3 password then? (in case of a service, not a user) If you have a good place to store it then you can put the whole private key there. AEX-3 changes the situation only by splitting a secret key into two pieces, not sure how it can be useful.

> need to use aex3 wallet files Where store the AEX-3 password then? (in case of a service, not a user) If you have a good place to store it then you can put the whole private key there. AEX-3 changes the situation only by splitting a secret key into two pieces, not sure how it can be useful.
zxq9 commented 2023-08-29 01:17:14 +09:00 (Migrated from gitlab.com)

Created by: hanssv

Base64 are used for variable sized things base58 for fixed sized things...

*Created by: hanssv* Base64 are used for variable sized things base58 for fixed sized things...
davidyuk commented 2023-09-15 15:10:37 +09:00 (Migrated from gitlab.com)

@hanssv I'm switched it to base58 🙌

@hanssv I'm switched it to base58 🙌
zxq9 commented 2023-09-15 17:20:49 +09:00 (Migrated from gitlab.com)

Created by: hanssv

Review: Approved

*Created by: hanssv* **Review:** Approved
loxs commented 2023-09-16 20:22:10 +09:00 (Migrated from gitlab.com)

approved this merge request

approved this merge request
zxq9 commented 2023-11-07 18:32:51 +09:00 (Migrated from gitlab.com)

Created by: dincho

test trigger CI?!

*Created by: dincho* test trigger CI?!
zxq9 commented 2023-11-14 00:13:54 +09:00 (Migrated from gitlab.com)

Merged by: uwiger at 2023-11-13 15:13:54 UTC

*Merged by: uwiger at 2023-11-13 15:13:54 UTC*
Sign in to join this conversation.
No description provided.