Closed KtorZ closed 4 years ago
Some suggestions:
Some roundtrip tests could be added.
There could be some usage examples added to CLI help, e.g.:
$ bech32 --help
Usage: bech32 [PREFIX]
Simple utility for converting to/from bech32 byte strings.
Available options: -h,--help Show this help text PREFIX A human-readable prefix (e.g. 'addr').
Examples: Convert from bech32 to base16: bech32 <<< addr1qzpy4tmfe838pu5zaly90d2tqee2j9vyfurjew5veuu7wx3n7hfkxy3hly0rtt5str0c3ax62c8xu33j50mx64fd600u477qj43ayv4630526j
Convert from base16 to bech32: bech32 addr <<< 00824aaf69c9e270f282efc857b54b0672a915844f072cba8ccf39e71a33f5d3631237f91e35ae9058df88f4da560e6e4632a3f66d552dd3dfcafbc09563d232ba
Convert from base58 to bech32: bech32 addr <<< Ae2tdPwUPEYyDf8J4KQNr1ZPw26iyn9JU9dHWTAxNEaNbi8VDNDTBmjQuXj
- Nicer error message (when required prefix is missing), currently there is:
$ bech32 <<< 00824aaf69c9e270f282efc857b54b0672a915844f072cba8ccf39e71a33f5d3631237f91e35ae9058df88f4da560e6e4632a3f66d552dd3dfcafbc09563d232ba bech32: user error (StringToDecodeContainsInvalidChars [CharPosition 117,CharPosition 128])
$ bech32 <<< Ae2tdPwUPEYyDf8J4KQNr1ZPw26iyn9JU9dHWTAxNEaNbi8VDNDTBmjQuXj bech32: user error (StringToDecodeHasMixedCase)
If the goal here is a MVP (not sure though, is there a jira ticket?) then ugly error messages and other rough edges are fine.
But tests would be easy to do and should be added.
@rvl indeed that is just an MVP / quick'n'dirty draft, not sure why it got the attention of three of you :s I wrote this n half an hour while waiting for a bors build to complete, hence the absence of tests and polish on the interface. This may come later -- perhaps.
ef43e59b225abe60da7d5a0a476e7b6d44ffbaca :round_pushpin: add linters and editor configuration files
4b496c78b5550e365b8552434b5d01926fcc48cd :round_pushpin: quickly implement / draft a command-line for bech32 string manipulation. The command-line is very simple, and it's made of a single command: 'bech32' When given an argument, the command decode an encoded string from stdin in base16, bech32 and base58 and re-encode it in bech32 with the prefix given as argument. For example:
So this can be used to encode raw base16 strings as well as used to change the prefix of a given bech32 string.
When no prefix is given, the command simply decodes a given bech32 string to base16, which is most commonly / simple format supported by basically any interfaces dealing with bytes. For example:
Since the byte string is read from stdin, bech32 can be piped through other commands easily, and it roundtrips nicely:
274e967c9f73aad05e36281ac268ac6cb60a659b :round_pushpin: avoid hard-coded constants in 'detectEncoding'
01e8170f43ce8e5bec896c68bf62cc63eaaa4f8a :round_pushpin: rename 'detectEncoding' intermediate function to make their intent clearer
16dbdd7b7931c9ae58ddef6df5902ada8dbe9d45 :round_pushpin: use 'maybeToEither' from 'extra'
941d329d79472887b5b0931aa1aedf45f4b839d1 :round_pushpin: some style and readability improvements
2ff248c8da4bc132e0781701668b1deddccfd892 :round_pushpin: add property test to exercise bech32 encoding from encoded string Shows that the encoding input can be automatically detected with success.
8c2118193b6f91335b5e476eb8d0033491ec86f1 :round_pushpin: add a similar property for input decoding
7291273cc1a54c135c0ae2be88388b92b418c1e8 :round_pushpin: Improve overall command-line documentation