hubiinetwork / nahmii-sdk

Javascript SDK for using the hubii nahmii APIs
http://hubii.com
GNU Lesser General Public License v3.0
8 stars 0 forks source link

Consistent hash function #12

Closed katat closed 6 years ago

katat commented 6 years ago

The SDK seems to have a different hash function from the one expected in the smart contracts. The SDK hash an array of arguments, while the smart contract requires the hashing to be done in another way (hash of hash), please see: https://github.com/hubiinetwork/striim-contracts/blob/develop/test/mocks.js#L419

Therefore, the signature generated by the SDK failed to pass the genuine checks in the startChallengeFromPayment function on the smart contract.

Also, the signature needs to be in the following format:

"signature": {
       "v": {"_bn": "1c"},
       "r": "0x23...",
       "s": "0x23..."
}

The r and s properties need to be prefixed with 0x, otherwise it can't go through the ethers lib's contract object's input validator when calling the functions that accept the payment receipt as an argument.

morfj commented 6 years ago

The hash and sign method was implemented based on what jens ivar told us in #4 If that no longer holds true we need to sit down and re-evaluate how to stay in sync with the contracts.

morfj commented 6 years ago

@jijordre clarified in slack that the hash in the smart contracts support both numbers and strings (bignumber style) as equal inputs, so the discrepancy between the signature.v property in SDK and in the SC test code is insignificant when it comes to actually validating hashes.

katat commented 6 years ago

That's good news. Thanks