Skip to content

Commit ab4f8e4

Browse files
committed
Update to more effective
1 parent 61eccb0 commit ab4f8e4

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "txms.js",
3-
"version": "1.2.2",
3+
"version": "1.2.3",
44
"description": "Transaction messaging service protocol",
55
"main": "dist/index.js",
66
"types": "dist/index.d.ts",

src/index.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ const txms: Transport = {
5151
(errorHex as Error).code = 415;
5252
throw errorHex;
5353
}
54-
while (hex.length % 4 !== 0) {
55-
hex = '0' + hex;
54+
if (hex.length % 4 !== 0) {
55+
hex = '0'.repeat(4 - (hex.length % 4)) + hex;
5656
}
5757
for (let j = 0; j < hex.length; j += 4) {
5858
let hexchar = hex.substring(j, j + 4);
@@ -67,13 +67,13 @@ const txms: Transport = {
6767
let l;
6868
for (l = 0; l < data.length; l++) {
6969
if (data[l] === '~') {
70-
hex += ('000' + data.charCodeAt(l + 1).toString(16)).slice(-2) + ('000' + data.charCodeAt(l + 2).toString(16)).slice(-2);
70+
hex += ('00' + data.charCodeAt(l + 1).toString(16)).slice(-2) + ('00' + data.charCodeAt(l + 2).toString(16)).slice(-2);
7171
l = l + 2;
7272
} else {
73-
hex += ((l === 0 ? '' : '000') + data.charCodeAt(l).toString(16)).slice(-4);
73+
hex += ('0000' + data.charCodeAt(l).toString(16)).slice(-4);
7474
}
7575
}
76-
return '0x' + hex;
76+
return '0x' + hex.replace(/^0+/, '');
7777
},
7878

7979
getEndpoint(network?: number | string, countriesList?: string | Array<string>): { [key: string]: Array<string> } {

0 commit comments

Comments
 (0)