Closed DenisCarriere closed 6 years ago
Right now I've got a working generateHash
method in NodeJS, it might be worth doing that for Python as well since the Remix Python implementation isn't the same as the Java/NodeJS.
import bs58 from 'bs58'
/**
* Generates Hash for SharedStreets Reference ID
*
* @param {string} hashInput Hash Input
* @returns {string} SharedStreets Reference ID
* @example
* sharedstreets.generateHash('Intersection 110 45')
* // => 'NzUsPtY2FHmqaHuyaVzedp'
*/
export function generateHash (hashInput) {
// https://github.com/sharedstreets/sharedstreets-builder/issues/5
// hashInput = encodeURI(hashInput)
var bytesOfMessage = getBytes(hashInput)
var bytes = createHash('md5').update(Buffer.from(bytesOfMessage)).digest()
return bs58.encode(bytes)
}
function getBytes (hashInput) {
return Buffer.from(hashInput).toJSON()
}
Maybe I was thinking of something else, seems like the only thing that needs to happen is to confirm that the String
is in UTF8.
java
byte[] bytesOfMessage = hashInput.getBytes("UTF-8");
node
const bytesOfMessage = Buffer.from(hashInput, 'utf8')
python
bytesOfMessage = hashInput.encode('utf8')
Safe encoding in
generateHash
forhashInput
@kpwebb Noticed in the Java
sharedstreets-builder
UniqueId.java => generateHash method that were not encoding thehashInput
, is that intended to not escape the spaces (%20
)?Example