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

gh-pages side of rewriting message queue #133

Merged
merged 3 commits into from
Feb 10, 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
70 changes: 41 additions & 29 deletions bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,37 +53,37 @@ var LedgerBridge = function () {
if (e && e.data && e.data.target === 'LEDGER-IFRAME') {
var _e$data = e.data,
action = _e$data.action,
params = _e$data.params;
params = _e$data.params,
messageId = _e$data.messageId;

var replyAction = action + '-reply';

switch (action) {
case 'ledger-unlock':
_this.unlock(replyAction, params.hdPath);
_this.unlock(replyAction, params.hdPath, messageId);
break;
case 'ledger-sign-transaction':
_this.signTransaction(replyAction, params.hdPath, params.tx);
_this.signTransaction(replyAction, params.hdPath, params.tx, messageId);
break;
case 'ledger-sign-personal-message':
_this.signPersonalMessage(replyAction, params.hdPath, params.message);
_this.signPersonalMessage(replyAction, params.hdPath, params.message, messageId);
break;
case 'ledger-close-bridge':
_this.cleanUp(replyAction);
_this.cleanUp(replyAction, messageId);
break;
case 'ledger-update-transport':
if (params.transportType === 'ledgerLive' || params.useLedgerLive) {
_this.updateTransportTypePreference(replyAction, 'ledgerLive');
_this.updateTransportTypePreference(replyAction, 'ledgerLive', messageId);
} else if (params.transportType === 'webhid') {
_this.updateTransportTypePreference(replyAction, 'webhid');
_this.updateTransportTypePreference(replyAction, 'webhid', messageId);
} else {
_this.updateTransportTypePreference(replyAction, 'u2f');
_this.updateTransportTypePreference(replyAction, 'u2f', messageId);
}
break;
case 'ledger-make-app':
_this.attemptMakeApp(replyAction);
_this.attemptMakeApp(replyAction, messageId);
break;
case 'ledger-sign-typed-data':
_this.signTypedData(replyAction, params.hdPath, params.domainSeparatorHex, params.hashStructMessageHex);
_this.signTypedData(replyAction, params.hdPath, params.domainSeparatorHex, params.hashStructMessageHex, messageId);
break;
}
}
Expand Down Expand Up @@ -118,19 +118,21 @@ var LedgerBridge = function () {
}
}, {
key: 'attemptMakeApp',
value: async function attemptMakeApp(replyAction) {
value: async function attemptMakeApp(replyAction, messageId) {
try {
await this.makeApp({ openOnly: true });
await this.cleanUp();
this.sendMessageToExtension({
action: replyAction,
success: true
success: true,
messageId: messageId
});
} catch (error) {
await this.cleanUp();
this.sendMessageToExtension({
action: replyAction,
success: false,
messageId: messageId,
error: error
});
}
Expand Down Expand Up @@ -174,17 +176,18 @@ var LedgerBridge = function () {
}
}, {
key: 'updateTransportTypePreference',
value: function updateTransportTypePreference(replyAction, transportType) {
value: function updateTransportTypePreference(replyAction, transportType, messageId) {
this.transportType = transportType;
this.cleanUp();
this.sendMessageToExtension({
action: replyAction,
success: true
success: true,
messageId: messageId
});
}
}, {
key: 'cleanUp',
value: async function cleanUp(replyAction) {
value: async function cleanUp(replyAction, messageId) {
this.app = null;
if (this.transport) {
await this.transport.close();
Expand All @@ -193,27 +196,30 @@ var LedgerBridge = function () {
if (replyAction) {
this.sendMessageToExtension({
action: replyAction,
success: true
success: true,
messageId: messageId
});
}
}
}, {
key: 'unlock',
value: async function unlock(replyAction, hdPath) {
value: async function unlock(replyAction, hdPath, messageId) {
try {
await this.makeApp();
var res = await this.app.getAddress(hdPath, false, true);
this.sendMessageToExtension({
action: replyAction,
success: true,
payload: res
payload: res,
messageId: messageId
});
} catch (err) {
var e = this.ledgerErrToMessage(err);
this.sendMessageToExtension({
action: replyAction,
success: false,
payload: { error: e }
payload: { error: e },
messageId: messageId
});
} finally {
if (this.transportType !== 'ledgerLive') {
Expand All @@ -223,21 +229,23 @@ var LedgerBridge = function () {
}
}, {
key: 'signTransaction',
value: async function signTransaction(replyAction, hdPath, tx) {
value: async function signTransaction(replyAction, hdPath, tx, messageId) {
try {
await this.makeApp();
var res = await this.app.signTransaction(hdPath, tx);
this.sendMessageToExtension({
action: replyAction,
success: true,
payload: res
payload: res,
messageId: messageId
});
} catch (err) {
var e = this.ledgerErrToMessage(err);
this.sendMessageToExtension({
action: replyAction,
success: false,
payload: { error: e }
payload: { error: e },
messageId: messageId
});
} finally {
if (this.transportType !== 'ledgerLive') {
Expand All @@ -247,22 +255,24 @@ var LedgerBridge = function () {
}
}, {
key: 'signPersonalMessage',
value: async function signPersonalMessage(replyAction, hdPath, message) {
value: async function signPersonalMessage(replyAction, hdPath, message, messageId) {
try {
await this.makeApp();

var res = await this.app.signPersonalMessage(hdPath, message);
this.sendMessageToExtension({
action: replyAction,
success: true,
payload: res
payload: res,
messageId: messageId
});
} catch (err) {
var e = this.ledgerErrToMessage(err);
this.sendMessageToExtension({
action: replyAction,
success: false,
payload: { error: e }
payload: { error: e },
messageId: messageId
});
} finally {
if (this.transportType !== 'ledgerLive') {
Expand All @@ -272,22 +282,24 @@ var LedgerBridge = function () {
}
}, {
key: 'signTypedData',
value: async function signTypedData(replyAction, hdPath, domainSeparatorHex, hashStructMessageHex) {
value: async function signTypedData(replyAction, hdPath, domainSeparatorHex, hashStructMessageHex, messageId) {
try {
await this.makeApp();
var res = await this.app.signEIP712HashedMessage(hdPath, domainSeparatorHex, hashStructMessageHex);

this.sendMessageToExtension({
action: replyAction,
success: true,
payload: res
payload: res,
messageId: messageId
});
} catch (err) {
var e = this.ledgerErrToMessage(err);
this.sendMessageToExtension({
action: replyAction,
success: false,
payload: { error: e }
payload: { error: e },
messageId: messageId
});
} finally {
this.cleanUp();
Expand Down
Loading