Skip to content

Commit

Permalink
fix: update browser samples to support fixed bbs-signatures v0.4.0
Browse files Browse the repository at this point in the history
This locks the sample for bbs-signatures in a browser to be specific to v0.4.0 now

re #49
  • Loading branch information
kdenhartog-mattr committed Sep 10, 2020
1 parent 35748a1 commit 730bac0
Show file tree
Hide file tree
Showing 4 changed files with 726 additions and 58 deletions.
96 changes: 50 additions & 46 deletions sample/browser/index.web-sample.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,61 +13,65 @@

const stringToBytes = (str) => Uint8Array.from(Buffer.from(str, "utf-8"));

const module = import("../../pkg");
import {
generateBls12381G2KeyPair,
blsSign,
blsVerify,
blsCreateProof,
blsVerifyProof,
} from "@mattrglobal/bbs-signatures";

module.then((m) => {
//Generate a new key pair
const keyPair = m.generateBls12381G2KeyPair();
//Generate a new key pair
const keyPair = generateBls12381G2KeyPair();

console.log("Key pair generated");
console.log(
`Public key base64 = ${Buffer.from(keyPair.publicKey).toString("base64")}`
);
console.log("Key pair generated");
console.log(
`Public key base64 = ${Buffer.from(keyPair.publicKey).toString("base64")}`
);

//Set of messages we wish to sign
const messages = [stringToBytes("message1"), stringToBytes("message2")];
//Set of messages we wish to sign
const messages = [stringToBytes("message1"), stringToBytes("message2")];

console.log("Signing a message set of " + messages);
console.log("Signing a message set of " + messages);

//Create the signature
const signature = m.blsSign({
keyPair,
messages: messages,
});

console.log(
`Output signature base64 = ${Buffer.from(signature).toString("base64")}`
);
//Create the signature
const signature = blsSign({
keyPair,
messages: messages,
});

//Verify the signature
const isVerified = m.blsVerify({
publicKey: Uint8Array.from(keyPair.publicKey),
messages: messages,
signature,
});
console.log(
`Output signature base64 = ${Buffer.from(signature).toString("base64")}`
);

const isVerifiedString = JSON.stringify(isVerified);
console.log(`Signature verified ? ${isVerifiedString}`);
//Verify the signature
const isVerified = blsVerify({
publicKey: Uint8Array.from(keyPair.publicKey),
messages: messages,
signature,
});

//Derive a proof from the signature revealing the first message
const proof = m.blsCreateProof({
signature,
publicKey: Uint8Array.from(keyPair.publicKey),
messages,
nonce: stringToBytes("nonce"),
revealed: [0],
});
const isVerifiedString = JSON.stringify(isVerified);
console.log(`Signature verified ? ${isVerifiedString}`);

console.log(`Output proof base64 = ${Buffer.from(proof).toString("base64")}`);
//Derive a proof from the signature revealing the first message
const proof = blsCreateProof({
signature,
publicKey: Uint8Array.from(keyPair.publicKey),
messages,
nonce: stringToBytes("nonce"),
revealed: [0],
});

//Verify the created proof
const isProofVerified = m.blsVerifyProof({
proof,
publicKey: Uint8Array.from(keyPair.publicKey),
messages: messages.slice(0, 1),
nonce: stringToBytes("nonce"),
});
console.log(`Output proof base64 = ${Buffer.from(proof).toString("base64")}`);

const isProofVerifiedString = JSON.stringify(isProofVerified);
console.log(`Proof verified ? ${isProofVerifiedString}`);
//Verify the created proof
const isProofVerified = blsVerifyProof({
proof,
publicKey: Uint8Array.from(keyPair.publicKey),
messages: messages.slice(0, 1),
nonce: stringToBytes("nonce"),
});

const isProofVerifiedString = JSON.stringify(isProofVerified);
console.log(`Proof verified ? ${isProofVerifiedString}`);
3 changes: 3 additions & 0 deletions sample/browser/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,8 @@
"@wasm-tool/wasm-pack-plugin": "1.3.1",
"html-webpack-plugin": "4.3.0",
"webpack-dev-server": "3.11.0"
},
"dependencies": {
"@mattrglobal/bbs-signatures": "0.4.0"
}
}
1 change: 1 addition & 0 deletions sample/browser/template.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@
<body>
<h1>BBS Signatures Demo</h1>
<label>Go to "Developer Tools->Console" to observe output demo</label>
<script src="index.web-sample.js"></script>
</body>
</html>
Loading

0 comments on commit 730bac0

Please # to comment.