import { ProcessRawTokenFeatureErrorType , ProcessRawTokenFeatureErrorTypes , RawTokenFeatures , TokenFeature } from "../types/Metadata" ; export function bytesToString ( byteArray ) { return Array . from ( byteArray , function ( byte ) { return ( '0' + ( byte & 0xFF ) . toString ( 16 ) ) . slice ( - 2 ) ; } ) . join ( '' ) ; } export function stringToByteString ( str ) { const bytes = [ ] ; for ( let i = 0 ; i < str . length ; i ++ ) { bytes . push ( str . charCodeAt ( i ) ) ; } return bytesToString ( bytes ) ; } export function processRawTokenFeatures ( rawFeatures ) { try { const features = [ ] ; if ( typeof rawFeatures !== "object" || Array . isArray ( rawFeatures ) || ! rawFeatures ) { throw { type : ProcessRawTokenFeatureErrorType . INVALID_FEATURES_SIGNATURE } ; } for ( const name in rawFeatures ) { if ( ! ( typeof rawFeatures [ name ] === "boolean" || typeof rawFeatures [ name ] === "string" || typeof rawFeatures [ name ] === "number" ) ) { throw { type : ProcessRawTokenFeatureErrorType . INVALID_PROPERTY_TYPE , extra : ` property "${ name }" is of type ${ typeof rawFeatures [ name ] }, only accepted types are [string, boolean, number]` } ; } features . push ( { name , value : rawFeatures [ name ] } ) ; } return features ; } catch ( err ) { if ( err . type && ProcessRawTokenFeatureErrorTypes . includes ( err . type ) ) { throw err ; } else { throw { type : ProcessRawTokenFeatureErrorType . UNKNOWN } ; } } }