Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for Event Name Collisions #194

Merged
merged 7 commits into from
Jan 20, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "casperlabs-signer",
"version": "1.4.6",
"version": "1.4.7",
George-cl marked this conversation as resolved.
Show resolved Hide resolved
"private": true,
"dependencies": {
"@babel/core": "^7.14.6",
Expand Down
4 changes: 2 additions & 2 deletions public/manifest.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"manifest_version": 2,
"version": "1.4.6",
"version": "1.4.7",
"name": "CasperLabs Signer",
"author": "https://casperlabs.io",
"description": "CasperLabs Signer tool for signing transactions on the blockchain.",
Expand Down Expand Up @@ -72,4 +72,4 @@
},
"default_title": "CasperLabs Signer"
}
}
}
130 changes: 68 additions & 62 deletions src/background/SigningManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,39 +197,42 @@ export default class SigningManager extends events.EventEmitter {
);
this.popupManager.openPopup('signDeploy');
// Await outcome of user interaction with popup.
this.once(`${deployId}:finished`, (processedDeploy: deployWithID) => {
if (!this.appState.isUnlocked) {
return reject(
new Error(
`Signer locked during signing process, please unlock and try again.`
)
);
}
switch (processedDeploy.status) {
case 'signed':
if (processedDeploy.deploy) {
this.appState.unsignedDeploys.clear();
return resolve(DeployUtil.deployToJson(processedDeploy.deploy));
}
this.appState.unsignedDeploys.remove(processedDeploy);
return reject(new Error(processedDeploy.error?.message));
case 'failed':
this.unsignedDeploys = this.unsignedDeploys.filter(
d => d.id !== processedDeploy.id
);
this.once(
`casper-signer:${deployId}:finished`,
George-cl marked this conversation as resolved.
Show resolved Hide resolved
(processedDeploy: deployWithID) => {
if (!this.appState.isUnlocked) {
return reject(
new Error(
processedDeploy.error?.message! ?? 'User Cancelled Signing'
)
);
default:
return reject(
new Error(
`Signer: Unknown error occurred. Deploy transferDeploy: ${processedDeploy.toString()}`
`Signer locked during signing process, please unlock and try again.`
)
);
}
switch (processedDeploy.status) {
case 'signed':
George-cl marked this conversation as resolved.
Show resolved Hide resolved
if (processedDeploy.deploy) {
this.appState.unsignedDeploys.clear();
return resolve(DeployUtil.deployToJson(processedDeploy.deploy));
}
this.appState.unsignedDeploys.remove(processedDeploy);
return reject(new Error(processedDeploy.error?.message));
case 'failed':
this.unsignedDeploys = this.unsignedDeploys.filter(
d => d.id !== processedDeploy.id
);
return reject(
new Error(
processedDeploy.error?.message! ?? 'User Cancelled Signing'
)
);
default:
return reject(
new Error(
`Signer: Unknown error occurred. Deploy transferDeploy: ${processedDeploy.toString()}`
)
);
}
}
});
);
});
}

Expand Down Expand Up @@ -466,44 +469,47 @@ export default class SigningManager extends events.EventEmitter {

this.updateAppState();
this.popupManager.openPopup('signMessage');
this.once(`${messageId}:finished`, (processedMessage: messageWithID) => {
if (!this.appState.isUnlocked) {
return reject(
new Error(
`Signer locked during signing process, please unlock and try again.`
)
);
}
switch (processedMessage.status) {
case 'signed':
if (processedMessage.messageBytes) {
this.appState.unsignedMessages.remove(processedMessage);
if (activeKeyPair !== this.appState.activeUserAccount?.keyPair)
throw new Error('Active account changed during signing.');
if (!activeKeyPair)
throw new Error('No Active Key set - set it and try again.');
const signature = signFormattedMessage(
activeKeyPair,
processedMessage.messageBytes
);
return resolve(encodeBase16(signature));
} else {
this.appState.unsignedMessages.remove(processedMessage);
return reject(new Error(processedMessage.error?.message));
}
case 'failed':
this.unsignedMessages = this.unsignedMessages.filter(
d => d.id !== processedMessage.id
);
this.once(
`casper-signer:${messageId}:finished`,
(processedMessage: messageWithID) => {
if (!this.appState.isUnlocked) {
return reject(
new Error(
processedMessage.error?.message! ?? 'User Cancelled Signing'
`Signer locked during signing process, please unlock and try again.`
)
);
default:
return reject(new Error(`Signer: Unknown error occurred`));
}
switch (processedMessage.status) {
case 'signed':
if (processedMessage.messageBytes) {
this.appState.unsignedMessages.remove(processedMessage);
if (activeKeyPair !== this.appState.activeUserAccount?.keyPair)
throw new Error('Active account changed during signing.');
George-cl marked this conversation as resolved.
Show resolved Hide resolved
if (!activeKeyPair)
throw new Error('No Active Key set - set it and try again.');
George-cl marked this conversation as resolved.
Show resolved Hide resolved
const signature = signFormattedMessage(
activeKeyPair,
processedMessage.messageBytes
);
return resolve(encodeBase16(signature));
} else {
this.appState.unsignedMessages.remove(processedMessage);
return reject(new Error(processedMessage.error?.message));
}
case 'failed':
this.unsignedMessages = this.unsignedMessages.filter(
d => d.id !== processedMessage.id
);
return reject(
new Error(
processedMessage.error?.message! ?? 'User Cancelled Signing'
)
);
default:
return reject(new Error(`Signer: Unknown error occurred`));
}
}
});
);
});
}

Expand Down Expand Up @@ -637,7 +643,7 @@ export default class SigningManager extends events.EventEmitter {
}
if (status === 'failed' || status === 'signed') {
// fire finished event, so that the Promise can resolve and return result to RPC caller
this.emit(`${itemWithId.id}:finished`, itemWithId);
this.emit(`casper-signer:${itemWithId.id}:finished`, itemWithId);
}
}

Expand Down