Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export const convertIdentifierToNamespaceId = (value: string) => {
if(/[0-9a-fA-F]{16}/.test(value)) {
return NamespaceId.createFromEncoded(value)
}
try {
const namespaceId = new NamespaceId(value)
return namespaceId
} catch (_) {
// try next
}
const hex = convertUInt64ToHex(value)
if(! /[0-9a-fA-F]{16}/.test(hex)) {
throw new Error("Can't convert")
}
return NamespaceId.createFromEncoded(hex)
}
static getMosaicId(rawMosaicId: string): MosaicId | NamespaceId {
let mosaicId: MosaicId | NamespaceId;
if (rawMosaicId.charAt(0) === MosaicService.ALIAS_TAG) {
mosaicId = new NamespaceId(rawMosaicId.substring(1));
} else {
mosaicId = new MosaicId(rawMosaicId);
}
return mosaicId;
}