Closed hfossli closed 4 years ago
This happened because you need call toString
as toString('hex', 2)
for padding. If you check getPrivate
code, you can see that getPrivate('hex')
equal to getPrivate().toString(16, 2)
.
https://github.com/indutny/elliptic/blob/60489415e545efdfd3010ae74b9726facbf08ca8/lib/elliptic/ec/key.js#L69-L74
Aweeesome!🥰
🤔 what if.... what if the key randomly has 2 or more leading zeros, wouldn't it then be better to say toString(16, 32)? Doesn't matter?
Yes, right call will be toString(16, 32)
. Sorry for first wrong example.
Thanks. I don't know. I know from secp256r1 that leading zeros is important if the first hex value is >= 80
When running this code
I get
But I expected
(notice the leading zero is missing when exporting the key as
.getPrivate().toString("hex")
instead of.getPrivate("hex")
)Is this a bug or is it by design?