Skip to content

Commit

Permalink
update signing methods to return futures
Browse files Browse the repository at this point in the history
  • Loading branch information
ianopolous committed Jul 8, 2024
1 parent 6589e20 commit 3c5317c
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions vendor/priors/gwt.js
Original file line number Diff line number Diff line change
Expand Up @@ -1406,39 +1406,46 @@ function generateSecretbox_open(cipher, nonce, key) {
return convertToByteArray(new Int8Array(bytes.buffer, bytes.byteOffset, bytes.byteLength));
}

function generateCrypto_sign_open(signed, publicSigningKey) {
function generateCrypto_sign_open(signed, publicSigningKey) {
var future = peergos.shared.util.Futures.incomplete();
let signature = signed.slice(0, 64);
let encoded = signed.slice(64, signed.length);
return window.crypto.subtle.importKey("raw", publicSigningKey, "Ed25519", false, ["verify"]).then(publicKey => {
window.crypto.subtle.importKey("raw", publicSigningKey, "Ed25519", false, ["verify"]).then(publicKey => {
return window.crypto.subtle.verify(
"Ed25519",
publicKey,
signature,
encoded
).then(valid => {
if (valid)
return convertToByteArray(new Int8Array(encoded));
throw "Invalid signature";
future.complete(convertToByteArray(new Int8Array(encoded)));
future.completeExceptionally(java.lang.Throwable.of(Error("Invalid signature")));
});
}).catch(t => {
var bytes = nacl.sign.open(new Uint8Array(signed), new Uint8Array(publicSigningKey));
return convertToByteArray(new Int8Array(bytes));
if (bytes != null)
future.complete(convertToByteArray(new Int8Array(bytes)));
else
future.completeExceptionally(java.lang.Throwable.of(Error("Invalid signature")));
});
return future;
}

function generateCrypto_sign(message, secretSigningKey) {
return window.crypto.subtle.importKey("raw", secretSigningKey, "Ed25519", false, ["sign"]).then(secretKey => {
var future = peergos.shared.util.Futures.incomplete();
window.crypto.subtle.importKey("raw", secretSigningKey, "Ed25519", false, ["sign"]).then(secretKey => {
return window.crypto.subtle.sign(
"Ed25519",
secretKey,
message
).then(signature => {
return convertToByteArray(new Int8Array(signature.concat(message)));
future.complete(convertToByteArray(new Int8Array(signature.concat(message))));
});
}).catch (e => {
var bytes = nacl.sign(new Uint8Array(message), new Uint8Array(secretSigningKey));
return convertToByteArray(new Int8Array(bytes));
future.complete(convertToByteArray(new Int8Array(bytes)));
});
return future;
}

function generateCrypto_sign_keypair(publicKey, secretKey) {
Expand Down

0 comments on commit 3c5317c

Please sign in to comment.