fabian-hiller / valibot

The modular and type safe schema library for validating structural data 🤖
https://valibot.dev
MIT License
6.32k stars 204 forks source link

feat: add btcAddress action #911

Open shuaixr opened 2 weeks ago

shuaixr commented 2 weeks ago

Perform checksum validation for a btc address

fabian-hiller commented 2 weeks ago

Thanks for your PR! Is there any way we can simplify the bitcoin address check with a simple regular expression and checksum function? Just a random question. I haven't done any research yet.

shuaixr commented 2 weeks ago

Is there any way we can simplify the bitcoin address check with a simple regular expression and checksum function?

sure, I'll add a regular expression, first using regex then the checksum.

fabian-hiller commented 2 weeks ago

sure, I'll add a regular expression, first using regex then the checksum.

Is it possible to simplify the implementation in this way and reduce the bundle size without losing relevant functionality? The current implementation contains a lot of functions and seems quite complicated.

shuaixr commented 2 weeks ago

Is it possible to simplify the implementation in this way and reduce the bundle size without losing relevant functionality? The current implementation contains a lot of functions and seems quite complicated.

I can use crypto.subtle.digest instead of a library/src/actions/btcAddress/sha256-uint8array.ts file. It's supported in Node 15+, Bun, Deno, and browsers. i think all other functions are still necessary

update: I noticed crypto.subtle.digest is async, so I'm not sure if the whole action needs to be async.

I've already simplified the code as much as possible, and the Bech32 decoding has removed any parts unrelated to validation: https://github.com/bitcoin/bips/blob/master/bip-0173.mediawiki#reference-implementations

fabian-hiller commented 2 weeks ago

Thank you for your research. I want to let you know that I am focusing on our v1 release first before reviewing this PR.