diff --git a/src/core/format/Convert.ts b/src/core/format/Convert.ts index f6d12097b2..f45b7b9eac 100644 --- a/src/core/format/Convert.ts +++ b/src/core/format/Convert.ts @@ -168,7 +168,7 @@ export class Convert { const rawString = Convert.rstr2utf8(input); let result = ''; for (let i = 0; i < rawString.length; i++) { - result += rawString.charCodeAt(i).toString(16); + result += rawString.charCodeAt(i).toString(16).padStart(2, '0'); } return result; } diff --git a/src/core/format/Utilities.ts b/src/core/format/Utilities.ts index fe0fc1b401..90a2180655 100644 --- a/src/core/format/Utilities.ts +++ b/src/core/format/Utilities.ts @@ -133,7 +133,7 @@ export const split = (name, processor) => { export const generateNamespaceId = (parentId, name) => { const hash = sha3_256.create(); - hash.update(Uint32Array.from(parentId).buffer); + hash.update(Uint32Array.from(parentId).buffer as any); hash.update(name); const result = new Uint32Array(hash.arrayBuffer()); // right zero-filling required to keep unsigned number representation diff --git a/test/core/format/Convert.spec.ts b/test/core/format/Convert.spec.ts index d40aa5b8b0..7ed27007fa 100644 --- a/test/core/format/Convert.spec.ts +++ b/test/core/format/Convert.spec.ts @@ -233,6 +233,14 @@ describe('convert', () => { // Assert: expect(actual).to.equal('e58588e7a7a6e585a9e6bca2'); }); + + it('utf8 text to hex with control char', () => { + // Act: + const actual = convert.utf8ToHex(String.fromCodePoint(0x0f) + ' Hello World!'); + + // Assert: + expect(actual).to.equal('0f2048656c6c6f20576f726c6421'); + }); }); describe('signed <-> unsigned byte', () => { diff --git a/test/core/format/IdGenerator.spec.ts b/test/core/format/IdGenerator.spec.ts index 32921fd12b..f81cbc14c4 100644 --- a/test/core/format/IdGenerator.spec.ts +++ b/test/core/format/IdGenerator.spec.ts @@ -143,7 +143,7 @@ const mosaicTestVector = { describe('id generator', () => { function generateNamespaceId(parentId, name) { const hash = sha3_256.create(); - hash.update(Uint32Array.from(parentId).buffer); + hash.update(Uint32Array.from(parentId).buffer as any); hash.update(name); const result = new Uint32Array(hash.arrayBuffer()); // right zero-filling required to keep unsigned number representation diff --git a/tsconfig.json b/tsconfig.json index b2de510219..4059e92227 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -13,7 +13,7 @@ "outDir": "dist", "allowJs": false, "lib": [ - "es2016", + "es2017", "dom" ], "typeRoots": [