-
Notifications
You must be signed in to change notification settings - Fork 272
Conversation
r = new BN(r) | ||
s = new BN(s) | ||
const rBN: BN = new BN(r) | ||
const sBN: BN = new BN(s) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In generateAddress2
shadowing variables is not a problem. Any reason to make a distinction here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I couldn't find how to shadow a variable with a different type without the typescript compiler complaining. In generateAddress2
the type stays the same.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the type stays the same then there's no point to have that expression in the first place :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agree! but just tried removing the toBuffer
expressions and it seems like generateAddress2
tests are passing parameters as string
, and not Buffer
contrary to docs. Added string
type to its parameters (and docs). Let me know if you'd rather limit the input types to Buffer
.
exports.fromRpcSig = function (sig) { | ||
sig = exports.toBuffer(sig) | ||
export const fromRpcSig = function(sig: string) { | ||
const buf: Buffer = toBuffer(sig) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same question here.
@krzkaczor This library uses documentation to generate docs. However Are you aware how the typescript community usually generate docs? Is typedoc a good alternative? I'm trying to use it in combination with typedoc-plugin-markdown, which for example generates such an output. Update: Here's the result. |
@s1na Just stumbled above exactly the same on the Would also have chosen |
@holgerd77 @s1na getting to know docs generating tools for TS is on my todo list 😆 I heard good things about |
@holgerd77 @krzkaczor 😄 Then I'll continue with typedoc for now. Let me know if you ever found a better alternative :) |
@holgerd77 I'm trying to specify the type of functions which accept parameters or return values with multiple possible types, and I'm wondering what's the best strategy here.
I've seen a few such inconsistencies so far:
|
src/index.ts
Outdated
| undefined | ||
| BN | ||
| BufferableArray | ||
| Arrayable |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Types and interfaces in the RLP
implementation have gotten their own types.ts file. I'm not deep enough into TypeScript
yet to judge what is better / best practice. So just asking: what is your reasoning here to do it this way?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm just used to defining types where they're relevant, but don't have a strong feeling about it, and if you'd prefer that I can move them to types.ts
.
Alternatively, maybe it'd be possible to break the one big index.ts
into couple of smaller files which contain their relevant types. E.g. buf.ts
(all buffer related funcs), ecdsa.ts
(priv/pub key, sign, ecrecover), hash.ts
(keccak, sha256, ripemd160), addr.ts
(generateAddress, etc.). It's difficult to categorize the functions nicely however 😄
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Have no strong feeling about it, if you want just leave as is. Some reorg likely also makes sense on this library - see also e.g. #38. We should eventually do this in a second round though, think there is enough to concentrate on here.
src/index.ts
Outdated
|
||
/** | ||
* [`secp256k1`](https://github.com/cryptocoinjs/secp256k1-node/) | ||
* @var {Object} | ||
*/ | ||
exports.secp256k1 = secp256k1 | ||
export { secp256k1 } | ||
|
||
/** | ||
* Returns a buffer filled with 0s | ||
* @method zeros | ||
* @param {Number} bytes the number of bytes the buffer should be | ||
* @return {Buffer} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just as a note, maybe you just haven't gotten to that yet: types in doc comments have to be removed, see TSDoc standard.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I still have to do that. I kept them around for now to help me with annotating the types :)
To your multi-type-specification question: I am also very much in favor of your preferred approach and I think opinions stated in the past from e.g. @axic or @whymarrh also stated very much in that direction, so I think we should go on here and get the API (more) right and introduce breaking changes where necessary. I think we should nevertheless do/discuss this on a case-by-case (method-by-method) basis, since the nature and usage setting of the different functions differ very much. So can you post here which method(s) you want to change to what new method signature and/or split-up functionality here so that we can get to a short adjustment/assurance before this is actually changed? Maybe do one post with edits and a curated list of API changes as well as checkboxes if pushed? Then we don't loose oversight. Or otherwise around: I will directly start on the next comment with some suggestions, then we can take this as a starting point. |
Breaking API ChangesList with suggestions for breaking API changes Moved here. |
Also put @vpulim in cc here for comments. |
Ok, I think I am through with suggestions on API changes, see above. I would especially love to hear some explicit statement from @axic if time permits, but also e.g. @krzkaczor being the TypeScript type expert and everyone else. This should be broadly discussed and confirmed/refined. |
@s1na What do you think? |
@holgerd77 Great! Thanks for the detailed suggestions. I think they make sense. Just a few comments:
|
@s1na Numbered your stuff for easier reference.
|
@s1na Before you start nevertheless let's wait 1-2 days more for some more opinions on this. |
I will need to properly read it, but I would prefer if it would be possible to make the agreed breaking changes in Javascript and make a last release with that, before merging the Typescript rewrite. This decouples the two changes and hopefully reduces the potential bugs/issues. Does that makes sense? |
No, not really in my opinion. |
Other opinions on that? |
@holgerd77 would it maybe make the review process easier if for now set the ambiguous types to |
This also lacks displaying the main code changes in a renaming context, which makes it too hard to review and breaks file history. Can you see if you can do this two-step process here as well? Also: I know this is a bit annoying and will probably cause an extra half-an-hour of work. But commit history got really messy here with all the changes and re-changes. Can you re-structure this into some clean commits and then do a force-push on this? I think in this case it would be really worth the effort. |
Yeah it had gotten messy, sorry about that 😅 I rewrote the commit history, hopefully it's more clean now. This time I tried your suggestion and first moved However, this time I applied all of the changes to |
Regarding documentation, added |
Hmm, seems we have to deal with this somehow for now since these are open issues on Can we live with some addition to the README API section, something like: Re-exports of other libraries:
[Link to internal docs] Together with the explicit library linking this might even be some sort of improvement. If you're ok with it can you add? Thanks! |
Yeah, that's probably the best approach for now. Added to README.md. |
Hi Sina, sorry, I merged #171 without thinking about the implications for the I will directly take on this for review after the update. |
Signed-off-by: Sina Mahmoodi <itz.s1na@gmail.com>
Signed-off-by: Sina Mahmoodi <itz.s1na@gmail.com>
Signed-off-by: Sina Mahmoodi <itz.s1na@gmail.com>
Signed-off-by: Sina Mahmoodi <itz.s1na@gmail.com>
Signed-off-by: Sina Mahmoodi <itz.s1na@gmail.com>
Signed-off-by: Sina Mahmoodi <itz.s1na@gmail.com>
Hey, oh no not at all, it was a minor change :) rebased master. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good! 😄 👍
/** | ||
* Keccak-256 hash of the RLP of null | ||
*/ | ||
export const KECCAK256_RLP: Buffer = Buffer.from(KECCAK256_RLP_S, 'hex') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Checked for equivalency of the constants, ok.
* [`secp256k1`](https://github.com/cryptocoinjs/secp256k1-node/) | ||
*/ | ||
export { secp256k1 } | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did some short manual tests on re-export availability, ok.
} | ||
return array | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Methods equivalent, ok.
throw new Error('invalid data') | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did a line-by-line comparison of defineProperties
, should be ok.
Ok, have merged. Especially love this new documentation style, think particularly for this library @s1na I think a |
Great! Yeah I think |
This PR migrates the library to typescript. Part of the diff is only formatting, and due to running
prettier
on the codebase.The PR needs further testing and is work in progress.