11import { Address , CrossAccountIdUncapitalized , EnhancedCrossAccountId } from '../index'
22
3- import { Utf8 , Utf16 , HexString } from 'utf-helpers'
4-
53type MakeFieldsNullable < Ob > = { [ K in keyof Ob ] : Ob [ K ] | null }
64
75export enum UNIQUE_CHAINS {
@@ -44,11 +42,31 @@ export type TokenPropertyPermission = {
4442 permission : TokenPropertyPermissionValue
4543}
4644
45+
46+ const decodeUtf8 = ( arr : number [ ] | Uint8Array ) : string => {
47+ const utf8 = new Uint8Array ( arr )
48+ const decoder = new TextDecoder ( 'utf-8' )
49+ return decoder . decode ( utf8 )
50+ }
51+
52+ const decodeUtf16 = ( arr : number [ ] | Uint16Array ) : string => {
53+ const utf16 = new Uint16Array ( arr )
54+ const decoder = new TextDecoder ( 'utf-16le' )
55+ return decoder . decode ( utf16 )
56+ }
57+
58+ const arrayToHex = ( arr : number [ ] | Uint8Array ) : string => {
59+ return '0x' + Array . from ( arr )
60+ . map ( num => num . toString ( 16 ) . padStart ( 2 , '0' ) )
61+ . join ( '' )
62+ }
63+
64+
4765const decodeTPPArray = ( arr : Array < { key : number [ ] , permission : any } > ) : TokenPropertyPermission [ ] => {
4866 return arr . map ( ( { key, permission} ) => {
4967 return {
50- key : Utf8 . numberArrayToString ( key ) ,
51- keyHex : HexString . fromArray ( key ) ,
68+ key : decodeUtf8 ( key ) ,
69+ keyHex : arrayToHex ( key ) ,
5270 permission : permission as TokenPropertyPermissionValue ,
5371 }
5472 } )
@@ -75,10 +93,10 @@ const decodeCollectionProperties = (arr: Array<{ key: number[], value: number[]
7593 for ( const elem of arr ) {
7694 const { key, value} = elem
7795 const decoded : DecodedProperty = {
78- key : Utf8 . numberArrayToString ( key ) ,
79- keyHex : HexString . fromArray ( key ) ,
80- value : Utf8 . numberArrayToString ( value ) ,
81- valueHex : HexString . fromArray ( value ) ,
96+ key : decodeUtf8 ( key ) ,
97+ keyHex : arrayToHex ( key ) ,
98+ value : decodeUtf8 ( value ) ,
99+ valueHex : arrayToHex ( value ) ,
82100 }
83101 properties . push ( decoded )
84102 propertiesMap [ decoded . key ] = decoded
@@ -252,9 +270,9 @@ export const requestCollection = async (requestRPC: RequestRPC, collectionId: nu
252270 owner : Address . extract . enhancedCrossAccountId ( rawCollection . owner , ss58Prefix ) ,
253271 adminList,
254272 mode : rawCollection . mode ,
255- name : Utf16 . numberArrayToString ( rawCollection . name ) ,
256- description : Utf16 . numberArrayToString ( rawCollection . description ) ,
257- tokenPrefix : Utf8 . numberArrayToString ( rawCollection . token_prefix ) ,
273+ name : decodeUtf16 ( rawCollection . name ) ,
274+ description : decodeUtf16 ( rawCollection . description ) ,
275+ tokenPrefix : decodeUtf8 ( rawCollection . token_prefix ) ,
258276 sponsorship : rawCollection . sponsorship ,
259277 decodedSponsorship,
260278 lastTokenId,
0 commit comments