From 983f4875464064583bffa561cf80902ab50e1670 Mon Sep 17 00:00:00 2001 From: Steven Liu Date: Mon, 17 Jun 2019 12:07:53 +0100 Subject: [PATCH 1/9] Added #175 added contol char handler in convert.ts --- src/core/format/Convert.ts | 7 ++++++- test/core/format/Convert.spec.ts | 10 ++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/core/format/Convert.ts b/src/core/format/Convert.ts index f6d12097b2..60b55f3f04 100644 --- a/src/core/format/Convert.ts +++ b/src/core/format/Convert.ts @@ -168,7 +168,12 @@ export class Convert { const rawString = Convert.rstr2utf8(input); let result = ''; for (let i = 0; i < rawString.length; i++) { - result += rawString.charCodeAt(i).toString(16); + if (rawString.charCodeAt(i) < 16) { + // Add insignificant zero for control chars (0x00 - 0x0f) + result += '0' + rawString.charCodeAt(i).toString(16); + } else { + result += rawString.charCodeAt(i).toString(16); + } } return result; } diff --git a/test/core/format/Convert.spec.ts b/test/core/format/Convert.spec.ts index d40aa5b8b0..a4dc3bbae6 100644 --- a/test/core/format/Convert.spec.ts +++ b/test/core/format/Convert.spec.ts @@ -233,6 +233,16 @@ describe('convert', () => { // Assert: expect(actual).to.equal('e58588e7a7a6e585a9e6bca2'); }); + + it('utf8 text to hex with control char', () => { + // Act: + const test = String.fromCodePoint(0x0f) + ' Hello World!'; + console.log('UTF8', test); + const actual = convert.utf8ToHex(test); + + // Assert: + expect(actual).to.equal('0f2048656c6c6f20576f726c6421'); + }); }); describe('signed <-> unsigned byte', () => { From 44e3712de727635cde7dec712fd6e6b5dd77203f Mon Sep 17 00:00:00 2001 From: Steven Liu Date: Mon, 17 Jun 2019 12:07:53 +0100 Subject: [PATCH 2/9] Added #175 added contol char handler in convert.ts --- src/core/format/Convert.ts | 7 ++++++- test/core/format/Convert.spec.ts | 10 ++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/core/format/Convert.ts b/src/core/format/Convert.ts index f6d12097b2..60b55f3f04 100644 --- a/src/core/format/Convert.ts +++ b/src/core/format/Convert.ts @@ -168,7 +168,12 @@ export class Convert { const rawString = Convert.rstr2utf8(input); let result = ''; for (let i = 0; i < rawString.length; i++) { - result += rawString.charCodeAt(i).toString(16); + if (rawString.charCodeAt(i) < 16) { + // Add insignificant zero for control chars (0x00 - 0x0f) + result += '0' + rawString.charCodeAt(i).toString(16); + } else { + result += rawString.charCodeAt(i).toString(16); + } } return result; } diff --git a/test/core/format/Convert.spec.ts b/test/core/format/Convert.spec.ts index d40aa5b8b0..a4dc3bbae6 100644 --- a/test/core/format/Convert.spec.ts +++ b/test/core/format/Convert.spec.ts @@ -233,6 +233,16 @@ describe('convert', () => { // Assert: expect(actual).to.equal('e58588e7a7a6e585a9e6bca2'); }); + + it('utf8 text to hex with control char', () => { + // Act: + const test = String.fromCodePoint(0x0f) + ' Hello World!'; + console.log('UTF8', test); + const actual = convert.utf8ToHex(test); + + // Assert: + expect(actual).to.equal('0f2048656c6c6f20576f726c6421'); + }); }); describe('signed <-> unsigned byte', () => { From 26a9015476001cdd232652e8e44281e62c33530a Mon Sep 17 00:00:00 2001 From: Steven Liu Date: Mon, 17 Jun 2019 14:46:30 +0100 Subject: [PATCH 3/9] removed console log --- test/core/format/Convert.spec.ts | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/test/core/format/Convert.spec.ts b/test/core/format/Convert.spec.ts index a4dc3bbae6..7ed27007fa 100644 --- a/test/core/format/Convert.spec.ts +++ b/test/core/format/Convert.spec.ts @@ -236,9 +236,7 @@ describe('convert', () => { it('utf8 text to hex with control char', () => { // Act: - const test = String.fromCodePoint(0x0f) + ' Hello World!'; - console.log('UTF8', test); - const actual = convert.utf8ToHex(test); + const actual = convert.utf8ToHex(String.fromCodePoint(0x0f) + ' Hello World!'); // Assert: expect(actual).to.equal('0f2048656c6c6f20576f726c6421'); From f7755916193816b50921ed76ad87af59d46e3eb4 Mon Sep 17 00:00:00 2001 From: Steven Liu Date: Thu, 20 Jun 2019 12:30:05 +0100 Subject: [PATCH 4/9] Updated compile option lib to es2017 changed to use padStart on convert.ts --- src/core/format/Convert.ts | 2 +- src/core/format/Utilities.ts | 2 +- test/core/format/IdGenerator.spec.ts | 2 +- tsconfig.json | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/core/format/Convert.ts b/src/core/format/Convert.ts index 60b55f3f04..3f614a780e 100644 --- a/src/core/format/Convert.ts +++ b/src/core/format/Convert.ts @@ -170,7 +170,7 @@ export class Convert { for (let i = 0; i < rawString.length; i++) { if (rawString.charCodeAt(i) < 16) { // Add insignificant zero for control chars (0x00 - 0x0f) - result += '0' + rawString.charCodeAt(i).toString(16); + result += rawString.charCodeAt(i).toString(16).padStart(2, '0'); } else { result += rawString.charCodeAt(i).toString(16); } 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/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": [ From b185c3955f8b76b964d0b5c1f4c7b09e7ffae2fb Mon Sep 17 00:00:00 2001 From: Steven Liu Date: Thu, 20 Jun 2019 12:49:25 +0100 Subject: [PATCH 5/9] updated convert.ts --- src/core/format/Convert.ts | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/src/core/format/Convert.ts b/src/core/format/Convert.ts index 3f614a780e..f45b7b9eac 100644 --- a/src/core/format/Convert.ts +++ b/src/core/format/Convert.ts @@ -168,12 +168,7 @@ export class Convert { const rawString = Convert.rstr2utf8(input); let result = ''; for (let i = 0; i < rawString.length; i++) { - if (rawString.charCodeAt(i) < 16) { - // Add insignificant zero for control chars (0x00 - 0x0f) - result += rawString.charCodeAt(i).toString(16).padStart(2, '0'); - } else { - result += rawString.charCodeAt(i).toString(16); - } + result += rawString.charCodeAt(i).toString(16).padStart(2, '0'); } return result; } From f9cfe69b3718aa4541e75486a4bc9f32021522c1 Mon Sep 17 00:00:00 2001 From: Steven Liu Date: Mon, 17 Jun 2019 12:07:53 +0100 Subject: [PATCH 6/9] Added #175 added contol char handler in convert.ts --- src/core/format/Convert.ts | 7 ++++++- test/core/format/Convert.spec.ts | 10 ++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/core/format/Convert.ts b/src/core/format/Convert.ts index f6d12097b2..60b55f3f04 100644 --- a/src/core/format/Convert.ts +++ b/src/core/format/Convert.ts @@ -168,7 +168,12 @@ export class Convert { const rawString = Convert.rstr2utf8(input); let result = ''; for (let i = 0; i < rawString.length; i++) { - result += rawString.charCodeAt(i).toString(16); + if (rawString.charCodeAt(i) < 16) { + // Add insignificant zero for control chars (0x00 - 0x0f) + result += '0' + rawString.charCodeAt(i).toString(16); + } else { + result += rawString.charCodeAt(i).toString(16); + } } return result; } diff --git a/test/core/format/Convert.spec.ts b/test/core/format/Convert.spec.ts index d40aa5b8b0..a4dc3bbae6 100644 --- a/test/core/format/Convert.spec.ts +++ b/test/core/format/Convert.spec.ts @@ -233,6 +233,16 @@ describe('convert', () => { // Assert: expect(actual).to.equal('e58588e7a7a6e585a9e6bca2'); }); + + it('utf8 text to hex with control char', () => { + // Act: + const test = String.fromCodePoint(0x0f) + ' Hello World!'; + console.log('UTF8', test); + const actual = convert.utf8ToHex(test); + + // Assert: + expect(actual).to.equal('0f2048656c6c6f20576f726c6421'); + }); }); describe('signed <-> unsigned byte', () => { From 4d28007f072d86f07e9d8803bef62874a2bef2bd Mon Sep 17 00:00:00 2001 From: Steven Liu Date: Mon, 17 Jun 2019 14:46:30 +0100 Subject: [PATCH 7/9] removed console log --- test/core/format/Convert.spec.ts | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/test/core/format/Convert.spec.ts b/test/core/format/Convert.spec.ts index a4dc3bbae6..7ed27007fa 100644 --- a/test/core/format/Convert.spec.ts +++ b/test/core/format/Convert.spec.ts @@ -236,9 +236,7 @@ describe('convert', () => { it('utf8 text to hex with control char', () => { // Act: - const test = String.fromCodePoint(0x0f) + ' Hello World!'; - console.log('UTF8', test); - const actual = convert.utf8ToHex(test); + const actual = convert.utf8ToHex(String.fromCodePoint(0x0f) + ' Hello World!'); // Assert: expect(actual).to.equal('0f2048656c6c6f20576f726c6421'); From 633253be186a346debe1a523f211ef9e09cc122f Mon Sep 17 00:00:00 2001 From: Steven Liu Date: Thu, 20 Jun 2019 12:30:05 +0100 Subject: [PATCH 8/9] Updated compile option lib to es2017 changed to use padStart on convert.ts --- src/core/format/Convert.ts | 2 +- src/core/format/Utilities.ts | 2 +- test/core/format/IdGenerator.spec.ts | 2 +- tsconfig.json | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/core/format/Convert.ts b/src/core/format/Convert.ts index 60b55f3f04..3f614a780e 100644 --- a/src/core/format/Convert.ts +++ b/src/core/format/Convert.ts @@ -170,7 +170,7 @@ export class Convert { for (let i = 0; i < rawString.length; i++) { if (rawString.charCodeAt(i) < 16) { // Add insignificant zero for control chars (0x00 - 0x0f) - result += '0' + rawString.charCodeAt(i).toString(16); + result += rawString.charCodeAt(i).toString(16).padStart(2, '0'); } else { result += rawString.charCodeAt(i).toString(16); } 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/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": [ From 86a716c8c5d66e6a067b7037a3db69a17832b403 Mon Sep 17 00:00:00 2001 From: Steven Liu Date: Thu, 20 Jun 2019 12:49:25 +0100 Subject: [PATCH 9/9] updated convert.ts --- src/core/format/Convert.ts | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/src/core/format/Convert.ts b/src/core/format/Convert.ts index 3f614a780e..f45b7b9eac 100644 --- a/src/core/format/Convert.ts +++ b/src/core/format/Convert.ts @@ -168,12 +168,7 @@ export class Convert { const rawString = Convert.rstr2utf8(input); let result = ''; for (let i = 0; i < rawString.length; i++) { - if (rawString.charCodeAt(i) < 16) { - // Add insignificant zero for control chars (0x00 - 0x0f) - result += rawString.charCodeAt(i).toString(16).padStart(2, '0'); - } else { - result += rawString.charCodeAt(i).toString(16); - } + result += rawString.charCodeAt(i).toString(16).padStart(2, '0'); } return result; }