CityOfZion / neon-js

Javascript libraries that allow the applications to interact with NEO blockchain
https://docs.coz.io/neo3/neon-js/index.html
MIT License
183 stars 166 forks source link

length of hex string for curve.sign #844

Closed bettybao1209 closed 2 years ago

bettybao1209 commented 2 years ago

https://github.com/CityOfZion/neon-js/blob/804b20a34872be3d6ae70bc036bdf367fc50b280/packages/neon-core/src/u/basic/curve.ts#L32 Hi, I'd like to know the length of parameter message should be even number, right?

ixje commented 2 years ago

it should be even yes

bettybao1209 commented 2 years ago

it should be even yes

https://github.com/NeoNEXT/neoline/blob/08f0d7f3d4df0bd30e3e75be61c193ad5d628e37/src/app/popup/notification/signature/signature.component.ts#L49

so I tried to sign the message, of which the length of serializedTransaction is odd while it can still output the result. Do you know why?

ixje commented 2 years ago

because it is your responsibility that message is a valid hex string and Buffer.from (used here) oddly enough doesn't care if the input is odd or even and just drops 1 character to make it even

bettybao1209 commented 2 years ago

image

image image

Here we invoke the sign method, it will call sha256 which use hexEncoding.parse(hex) first the get thewordArray, can the hexEncoding.parse method take the odd length of the hex string?

snowypowers commented 2 years ago

It is possible to introduce an odd-length string if parameterHexString.length is larger than 0xff since the code only pads up to length of 2.