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

Export Bech32 functions #4100

Closed
10gic opened this issue Nov 6, 2024 · 4 comments
Closed

Export Bech32 functions #4100

10gic opened this issue Nov 6, 2024 · 4 comments
Labels
enhancement New feature or request

Comments

@10gic
Copy link
Contributor

10gic commented Nov 6, 2024

Exporting the bech32 related functions would increase the utility of this library.

For example, Sui uses bech32 to encode its private keys. https://github.com/sui-foundation/sips/blob/main/sips/sip-15.md

Is your feature request related to a problem? Please describe.
N/A

Describe the solution you'd like
Solution 1:

struct TWBech32;
TWString *_Nonnull TWBech32Encode(TWString* _Nonnull hrp, TWData *_Nonnull data);
TWData* _Nullable TWBech32Decode(TWString* _Nonnull string);  // The hrp part is easy to obtain, it will not be returned

struct TWBech32m;
TWString* _Nullable TWBech32mEncode(TWString* _Nonnull hrp, TWData *_Nonnull data);
TWData* _Nullable TWBech32mDecode(TWString* _Nonnull string);  // The hrp part is easy to obtain, it will not be returned

Describe alternatives you've considered
Solution 2:

enum TWBech32ChecksumVariant {
  TWBech32ChecksumVariantBip173
  TWBech32ChecksumVariantBip350
}

struct TWBech32;
TWString *_Nonnull TWBech32Encode(TWString* _Nonnull hrp, TWData *_Nonnull data, enum TWBech32ChecksumVariant variant);
TWData* _Nullable TWBech32Decode(TWString* _Nonnull string, enum TWBech32ChecksumVariant variant);  // The hrp part is easy to obtain, it will not be returned

Checklist

Resources

Resources link
https://github.com/bitcoin/bips/blob/master/bip-0173.mediawiki
https://github.com/bitcoin/bips/blob/master/bip-0350.mediawiki

Additional context

Add any other context or screenshots about the feature request here.

@10gic 10gic added the enhancement New feature or request label Nov 6, 2024
@10gic
Copy link
Contributor Author

10gic commented Nov 6, 2024

Hi @satoshiotomakan, I can work on this. Which solution do you prefer? Do you have any other better solutions?

@satoshiotomakan
Copy link
Collaborator

Hi @10gic, good suggestion. I think the Solution 1 seems to be more unambiguous, homogeneous. For example, we have similar TWBase58Encode, TWBase58EncodeNoCheck.

@10gic
Copy link
Contributor Author

10gic commented Nov 6, 2024

Hi @satoshiotomakan, your comment reminds me that there is one more solution:
Solution 3:

struct TWBech32;
TWString *_Nonnull TWBech32Encode(TWString* _Nonnull hrp, TWData *_Nonnull data);
TWData* _Nullable TWBech32Decode(TWString* _Nonnull string);
TWString *_Nonnull TWBech32EncodeM(TWString* _Nonnull hrp, TWData *_Nonnull data);  // bip350 Variant
TWData* _Nullable TWBech32DecodeM(TWString* _Nonnull string);  // bip350 Variant

It's hard to choose solution 1 and solution 3.

@satoshiotomakan
Copy link
Collaborator

Thank you for the PR @10gic, it's merged finally :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants