Skip to content

Commit

Permalink
Clean-up, improve error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
sisou committed Dec 1, 2022
1 parent ea69e27 commit 132b1e4
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 10 deletions.
3 changes: 1 addition & 2 deletions client/src/PublicRequest.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import * as Nimiq from '@nimiq/core-web';
import { KeyguardCommand } from './KeyguardCommand';

export { KeyguardCommand };

export type ObjectType = {
[key: string]: any;
};
Expand Down Expand Up @@ -425,6 +423,7 @@ export type RedirectRequest
| ConnectRequest
| SignTransactionRequest
| SignBtcTransactionRequest
| SignMultisigTransactionRequest
| SimpleRequest
| DeriveBtcXPubRequest
| SignSwapRequest;
Expand Down
2 changes: 1 addition & 1 deletion client/src/main.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export * from './KeyguardClient';
export * from './RequestBehavior';
// export * from './KeyguardCommand';
export * from './KeyguardCommand';
export * from './KeyguardErrors';
export * from './PublicRequest';
2 changes: 1 addition & 1 deletion demos/ConnectAccount.html
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@
keyId,
keyLabel: 'Some Account',

appLogoUrl: 'http://localhost:3000/src/request/connect/logo.svg',
appLogoUrl: `${window.location.origin}/demos/multisig-logo.svg`,
permissions,
requestedKeyPaths: [`m/44'/242'/0'/0'`],
challenge,
Expand Down
File renamed without changes
2 changes: 2 additions & 0 deletions src/lib/multisig/MultisigUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ class MultisigUtils { // eslint-disable-line no-unused-vars
const loadPromise = new Promise(resolve => script.addEventListener('load', () => resolve()));
document.head.appendChild(script);
await loadPromise;

// `wasm_bindgen` is a global variable from the script above
await wasm_bindgen('../../lib/multisig/wasm/pkg/multisig_bg.wasm'); // Relative path from a request URL
}

Expand Down
Binary file modified src/lib/multisig/wasm/pkg/multisig_bg.wasm
Binary file not shown.
4 changes: 4 additions & 0 deletions src/lib/multisig/wasm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ pub fn aggregate_secrets(concatenated_secrets: &[u8], b: &[u8]) -> Vec<u8> {

let secrets = concatenated_secrets.chunks_exact(32);

if secrets.len() != number_commitments {
panic!("Invalid number of secrects: is {}, must be {}", secrets.len(), number_commitments);
}

if secrets.remainder().len() != 0 {
panic!("Invalid length of concatenated secrets");
}
Expand Down
25 changes: 19 additions & 6 deletions src/request/sign-multisig-transaction/SignMultisigTransaction.js
Original file line number Diff line number Diff line change
Expand Up @@ -247,13 +247,26 @@ class SignMultisigTransaction {
} else {
// If we only have encrypted secrets, decrypt them and aggregate them with the bScalar
const rsaKey = await key.getRsaPrivateKey();
const secrets = await Promise.all(request.multisigConfig.secret.encryptedSecrets.map(
async encrypted => new Uint8Array(
await window.crypto.subtle.decrypt({ name: 'RSA-OAEP' }, rsaKey, encrypted),
),
));

aggregatedSecret = await MultisigUtils.aggregateSecrets(secrets, request.multisigConfig.secret.bScalar);
/** @type {Uint8Array[]} */
let secrets;
try {
secrets = await Promise.all(request.multisigConfig.secret.encryptedSecrets.map(
async encrypted => new Uint8Array(
await window.crypto.subtle.decrypt({ name: 'RSA-OAEP' }, rsaKey, encrypted),
),
));
} catch (e) {
reject(new Errors.InvalidRequestError(`Cannot decrypt secrets: ${e.message}`));
return;
}

try {
aggregatedSecret = await MultisigUtils.aggregateSecrets(secrets, request.multisigConfig.secret.bScalar);
} catch (e) {
reject(new Errors.InvalidRequestError(`Cannot aggregate secrets: ${e.message}`));
return;
}
}

const signature = key.signPartially(
Expand Down

0 comments on commit 132b1e4

Please sign in to comment.