Skip to content
Merged
2 changes: 1 addition & 1 deletion src/core/format/Convert.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion src/core/format/Utilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions test/core/format/Convert.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down
2 changes: 1 addition & 1 deletion test/core/format/IdGenerator.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"outDir": "dist",
"allowJs": false,
"lib": [
"es2016",
"es2017",
"dom"
],
"typeRoots": [
Expand Down