Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ark encoding #6

Merged
merged 9 commits into from
Nov 15, 2023
Merged

Ark encoding #6

merged 9 commits into from
Nov 15, 2023

Conversation

altafan
Copy link
Collaborator

@altafan altafan commented Nov 14, 2023

This fixes the existing method for secret/public key encoding and adds support for:

  • encoding/decoding ark addresses
  • encoding/decoding ark relays
  • encoding/decoding ark url

This also fixes the name of the submodule, called now github.com/ark-network/ark/common.

This also adds a replacement in the main go.mod for the import of the submodule for future tasks.

Last but not least, this adds (few) tests for all the encoding methods.

Please @louisinger review.

@altafan altafan requested a review from louisinger November 14, 2023 16:10
Copy link
Collaborator

@louisinger louisinger left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't be better to include the Ark provider public key into Ark addresses ? most of the time, you don't want to receive VTXOs on every arks but only on a specific one

pkg/common/encoding.go Outdated Show resolved Hide resolved
@bordalix
Copy link
Collaborator

Just my 2 sats:

  1. Should we include a version prefix on addresses?
  2. Why bech32 and not bech32m?

Bech32 has an unexpected sipa/bech32#51: whenever the final character is a 'p', inserting or deleting any number of 'q' characters immediately preceding it does not invalidate the checksum. This does not affect existing uses of witness version 0 BIP173 addresses due to their restriction to two specific lengths, but may affect future uses and/or other applications using the Bech32 encoding.

@tiero
Copy link
Member

tiero commented Nov 14, 2023

Why do we need to encode the relay on his own? Shouldn't just be part of the address?

pkg/common/encoding.go Outdated Show resolved Hide resolved
pkg/common/encoding.go Outdated Show resolved Hide resolved
@altafan
Copy link
Collaborator Author

altafan commented Nov 15, 2023

Why do we need to encode the relay on his own? Shouldn't just be part of the address?

@tiero It's part of the ark url used to connect to an ASP, not the address you get from a receiver.

Since nostr has a dedicated prefix for relays, I thought it was worth keeping this distinction.

@altafan
Copy link
Collaborator Author

altafan commented Nov 15, 2023

  • Should we include a version prefix on addresses?

@bordalix for the PoC i would say no, but if you take a closer look at the fixtures, you can see the prefixes are actually asec1, apub1, ark1, arelay1. It seems the bech32 pkg already adds a version byte and I think it's enough for us now. In alpha, we will definitely add our own version byte.

  • Why bech32 and not bech32m?

Nice catch, I moved to bech32m indeed. The btcutil's bech32 package already supports it.


return secp256k1.ParsePubKey(buf)
func DecodeAddress(addr string) (*secp256k1.PublicKey, *secp256k1.PublicKey, error) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: what do u think of having a struct as return type instead of a tuple key, key, err ? Saying this because it's hard to discriminate user/asp key looking at the signature as it is

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll add a name to the return values

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done.

@bordalix
Copy link
Collaborator

No, the 1 in bc1 is the separator, not the version (bc1 = hrp + separator). The version comes after the separator, and bech32(0) = q and bech32m(1) = p

address = hrp + separator + bech32x(version + ripe160(sha256(pubkey))

That's why all segwit addresses (version 0) start with "bc1q" and all taproot addresses (version 1) start with "bc1p"

https://en.bitcoin.it/wiki/Bech32

@tiero
Copy link
Member

tiero commented Nov 15, 2023

I propose to keep relays outside of the Ark address, and only the two pubkeys. Fine to have apub and asec for now.

We can have it as part of a BIP21 address URI

ark1[...]?relays=[wss://my.domain.com/]  

together with other things BIP21 may specify

@altafan
Copy link
Collaborator Author

altafan commented Nov 15, 2023

@tiero ATM the address encodes only user and asp pubkeys, while relays are encoded in the ark URL. This is an example of valid address.
The idea is that this URL is used only at client setup, to connect with an asp. This is an example of valid ark URL.

Clients can verify that the asp pubkey encoded in a receiving address matches the one they have in their ark URL.

Therefore, the pubkey of the asp is used as its identifier and shouldn't change.

Does this make sense to you?

@tiero
Copy link
Member

tiero commented Nov 15, 2023

Yes, not sure the ark:// has real utility compared to a simple BIP21 address.

The idea is that this URL is used only at client setup

Not sure this is something desirable for the ASP ie. having user to "connect" to them, rather than just listening on the common channel for payment requests.
But not holding this PR for this, we can always deprecate later.

@altafan
Copy link
Collaborator Author

altafan commented Nov 15, 2023

Not sure this is something desirable for the ASP ie. having user to "connect" to them, rather than just listening on the common channel for payment requests.

In my mind it's not a "direct" connection.. rather, the ASP announces in the ark URL his identity, ie his public key, and the list of relays through which he communicates with the users. It feels overkilling to me carrying on this info in every receiving address generated by users (if that's what you mean when you speak about ark addresses).

@altafan altafan merged commit 19cbaeb into master Nov 15, 2023
1 check passed
@altafan altafan deleted the ark-encoding branch December 4, 2023 16:01
altafan added a commit to altafan/ark that referenced this pull request Nov 20, 2024
* Hotfix: Prevent ZMQ-based bitcoin wallet to panic  (ark-network#383)

* Hotfix bct embedded wallet w/ ZMQ

* Fixes

* Rename vtxo is_oor to is_pending (ark-network#385)

* Rename vtxo is_oor > is_pending

* Clean swaggers

* Revert changes to client and sdk
altafan added a commit that referenced this pull request Nov 20, 2024
* migrate descriptors --> tapscripts

* fix covenantless

* dynamic boarding exit delay

* remove duplicates in tree and bitcointree

* agnostic signatures validation

* revert GetInfo change

* renaming VtxoScript var

* Agnostic script server (#6)

* Hotfix: Prevent ZMQ-based bitcoin wallet to panic  (#383)

* Hotfix bct embedded wallet w/ ZMQ

* Fixes

* Rename vtxo is_oor to is_pending (#385)

* Rename vtxo is_oor > is_pending

* Clean swaggers

* Revert changes to client and sdk

* descriptor in oneof

* support CHECKSIG_ADD in MultisigClosure

* use right witness size in OOR tx fee estimation

* Revert changes

---------

Co-authored-by: Pietralberto Mazza <[email protected]>
sekulicd pushed a commit that referenced this pull request Nov 21, 2024
* migrate descriptors --> tapscripts

* fix covenantless

* dynamic boarding exit delay

* remove duplicates in tree and bitcointree

* agnostic signatures validation

* revert GetInfo change

* renaming VtxoScript var

* Agnostic script server (#6)

* Hotfix: Prevent ZMQ-based bitcoin wallet to panic  (#383)

* Hotfix bct embedded wallet w/ ZMQ

* Fixes

* Rename vtxo is_oor to is_pending (#385)

* Rename vtxo is_oor > is_pending

* Clean swaggers

* Revert changes to client and sdk

* descriptor in oneof

* support CHECKSIG_ADD in MultisigClosure

* use right witness size in OOR tx fee estimation

* Revert changes

---------

Co-authored-by: Pietralberto Mazza <[email protected]>
altafan added a commit that referenced this pull request Nov 22, 2024
* wasm e2e test

* Remove ark-sdk.wasm.gz from repository

* pr review

* exclude test files from linting

* fix

* test fix

* go work sync

* gha fix

* gha fix

* wasm e2e test

* kill webserver

* Fix nonce encoding/decoding & Fix pop from queue of payment requests (#375)

* bug fix - paymentMap pop input traversal

* bug fix - nonce encode/decode

* pr review

* pr review

* Fix trivy gh action (#381)

* Update trivy gha

* Update tryvy gha

* Fix

* merge

* Panic recovery in app svc (#372)

* panic recovery

* pr review

* Support connecting to bitcoind via ZMQ (#286)

* add ZMQ env vars

* consolidate config and app-config naming

* [Server] Validate forfeit txs without re-building them (#382)

* compute forfeit partial tx client-side first

* fix conflict

* go work sync

* move verify sig in VerifyForfeits

* move check after len(inputs)

* Hotfix: Prevent ZMQ-based bitcoin wallet to panic  (#383)

* Hotfix bct embedded wallet w/ ZMQ

* Fixes

* Rename vtxo is_oor to is_pending (#385)

* Rename vtxo is_oor > is_pending

* Clean swaggers

* Change representation of taproot trees & Internal fixes (#384)

* migrate descriptors --> tapscripts

* fix covenantless

* dynamic boarding exit delay

* remove duplicates in tree and bitcointree

* agnostic signatures validation

* revert GetInfo change

* renaming VtxoScript var

* Agnostic script server (#6)

* Hotfix: Prevent ZMQ-based bitcoin wallet to panic  (#383)

* Hotfix bct embedded wallet w/ ZMQ

* Fixes

* Rename vtxo is_oor to is_pending (#385)

* Rename vtxo is_oor > is_pending

* Clean swaggers

* Revert changes to client and sdk

* descriptor in oneof

* support CHECKSIG_ADD in MultisigClosure

* use right witness size in OOR tx fee estimation

* Revert changes

---------

Co-authored-by: Pietralberto Mazza <[email protected]>

* fix unit test

* fix unit test

* fix unit test

---------

Co-authored-by: Pietralberto Mazza <[email protected]>
Co-authored-by: Marco Argentieri <[email protected]>
Co-authored-by: Louis Singer <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants