Skip to content

Commit

Permalink
Merge pull request #27 from Joystream/handle-fix
Browse files Browse the repository at this point in the history
convert handle string to Bytes
  • Loading branch information
mnaamani authored Oct 30, 2023
2 parents dafec1f + 9cee8f9 commit 75e02dd
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/joyApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ export class JoyApi {
}

async handleIsAlreadyRegistered(handle: string): Promise<boolean> {
const handleHash = blake2AsHex(handle)
const handleHash = blake2AsHex(Buffer.from(handle).toString('hex'))
const storageSize = await this.api.query.members.memberIdByHandleHash.size(
handleHash
)
Expand All @@ -142,7 +142,7 @@ export class JoyApi {
return this.api.tx.members.giftMembership({
rootAccount: account,
controllerAccount: account,
handle: handle,
handle: createType('Bytes', '0x' + Buffer.from(handle).toString('hex')),
metadata: createType(
'Bytes',
'0x' +
Expand Down
18 changes: 18 additions & 0 deletions src/test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@

import { blake2AsHex } from '@polkadot/util-crypto'

console.log(blake2AsHex('0xfeed'))
// console.log(blake2AsHex(Buffer.from('0xfeed'))) // what user intended
console.log(blake2AsHex('0xada5'))
// console.log(blake2AsHex(Buffer.from('0xada5'))) // what user intended

console.log(Buffer.from([254, 237]).toString('utf16le'))
console.log(Buffer.from([254, 237]).toString('utf-8'))


console.log(Buffer.from([173, 165]).toString('utf16le'))


let str = Buffer.from('A', 'utf16le').toString('utf16le')
console.log(blake2AsHex(str))
console.log(blake2AsHex('A'))

0 comments on commit 75e02dd

Please sign in to comment.