bitcoinjs-lib
bitcoinjs-lib copied to clipboard
Better types for opcodes
ops.ts exports the list of opcodes as:
const OPS: { [key: string]: number }
That's not a very safe type, as it permits access with any string key. It also doesn't work with code completion.
Can this type be made more specific? It would technically be a breaking change for anyone using this in an unsafe manner, but I believe it's worth it. I'm happy to work on this.
OPS is pretty straightforward, (just as as const
at the end) but REVERSE_OPS might be tricky to get to only respond to specific number keys...
Admittedly, when I migrated this library to TypeScript I was a TS beginner, and only feel like I now have a semi-intermediate grasp on it...
PRs are welcome, but I think this won't land until the next major version whenever that is.
How about using enum as bitcoin core does? https://github.com/bitcoin/bitcoin/blob/master/src/script/script.h#L72
Made PR for this https://github.com/bitcoinjs/bitcoinjs-lib/pull/2028. Any review or commit would be grateful!