Skip to content

Commit

Permalink
Fix challengetimeout caused exit in some nodejs version
Browse files Browse the repository at this point in the history
Signed-off-by: Yilun <[email protected]>
  • Loading branch information
yilunzhang committed Apr 4, 2023
1 parent f032f08 commit d2f255a
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 39 deletions.
18 changes: 6 additions & 12 deletions dist/nkn.js
Original file line number Diff line number Diff line change
Expand Up @@ -704,7 +704,8 @@ class Client {
let challengeHandler = new Promise((resolve, reject) => {
challengeDone = resolve;
setTimeout(() => {
reject(new common.errors.ChallengeTimeoutError());
// Some nodejs version might terminate the whole process if we call reject here
resolve(new common.errors.ChallengeTimeoutError());
}, consts.waitForChallengeTimeout);
});

Expand All @@ -713,18 +714,11 @@ class Client {
Action: Action.setClient,
Addr: this.addr
};
let req = await challengeHandler;

try {
let req = await challengeHandler;

if (!!req) {
data.ClientSalt = common.util.bytesToHex(req.ClientSalt);
data.Signature = common.util.bytesToHex(req.Signature);
}
} catch (e) {
if (!e instanceof common.errors.ChallengeTimeoutError) {
console.log(e);
}
if (!!req && !(req instanceof common.errors.ChallengeTimeoutError)) {
data.ClientSalt = common.util.bytesToHex(req.ClientSalt);
data.Signature = common.util.bytesToHex(req.Signature);
}

ws.send(JSON.stringify(data));
Expand Down
2 changes: 1 addition & 1 deletion dist/nkn.min.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<html lang="en">
<head>
<meta charset='utf-8'>
<title>nkn-sdk 1.2.9 | Documentation</title>
<title>nkn-sdk 1.3.0 | Documentation</title>
<meta name='description' content='NKN client and wallet SDK'>
<meta name='viewport' content='width=device-width,initial-scale=1'>
<link href='assets/bass.css' rel='stylesheet'>
Expand All @@ -15,7 +15,7 @@
<div id='split-left' class='overflow-auto fs0 height-viewport-100'>
<div class='py1 px2'>
<h3 class='mb0 no-anchor'>nkn-sdk</h3>
<div class='mb1'><code>1.2.9</code></div>
<div class='mb1'><code>1.3.0</code></div>
<input
placeholder='Filter'
id='filter-input'
Expand Down
18 changes: 6 additions & 12 deletions lib/client/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -703,7 +703,8 @@ class Client {
let challengeHandler = new Promise((resolve, reject) => {
challengeDone = resolve;
setTimeout(() => {
reject(new common.errors.ChallengeTimeoutError());
// Some nodejs version might terminate the whole process if we call reject here
resolve(new common.errors.ChallengeTimeoutError());
}, consts.waitForChallengeTimeout);
});

Expand All @@ -712,18 +713,11 @@ class Client {
Action: Action.setClient,
Addr: this.addr
};
let req = await challengeHandler;

try {
let req = await challengeHandler;

if (!!req) {
data.ClientSalt = common.util.bytesToHex(req.ClientSalt);
data.Signature = common.util.bytesToHex(req.Signature);
}
} catch (e) {
if (!e instanceof common.errors.ChallengeTimeoutError) {
console.log(e);
}
if (!!req && !(req instanceof common.errors.ChallengeTimeoutError)) {
data.ClientSalt = common.util.bytesToHex(req.ClientSalt);
data.Signature = common.util.bytesToHex(req.Signature);
}

ws.send(JSON.stringify(data));
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "nkn-sdk",
"version": "1.2.9",
"version": "1.3.0",
"description": "NKN client and wallet SDK",
"main": "lib/index.js",
"exports": {
Expand Down
17 changes: 6 additions & 11 deletions src/client/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -617,7 +617,8 @@ export default class Client {
let challengeHandler: Promise<SaltAndSignature> = new Promise<SaltAndSignature>((resolve, reject) => {
challengeDone = resolve;
setTimeout(() => {
reject(new common.errors.ChallengeTimeoutError());
// Some nodejs version might terminate the whole process if we call reject here
resolve(new common.errors.ChallengeTimeoutError());
}, waitForChallengeTimeout);
});

Expand All @@ -626,16 +627,10 @@ export default class Client {
Action: Action.setClient,
Addr: this.addr,
};
try {
let req = await challengeHandler;
if (!!req) {
data.ClientSalt = common.util.bytesToHex(req.ClientSalt);
data.Signature = common.util.bytesToHex(req.Signature);
}
} catch (e) {
if (!e instanceof common.errors.ChallengeTimeoutError) {
console.log(e);
}
let req = await challengeHandler;
if (!!req && !(req instanceof common.errors.ChallengeTimeoutError)) {
data.ClientSalt = common.util.bytesToHex(req.ClientSalt);
data.Signature = common.util.bytesToHex(req.Signature);
}
ws.send(JSON.stringify(data));
this.shouldReconnect = true;
Expand Down

0 comments on commit d2f255a

Please sign in to comment.