Skip to content

Commit

Permalink
fix(sample/browser): use byte arrays instead of strings
Browse files Browse the repository at this point in the history
Fixes mattrglobal#49

Signed-off-by: Peter Somogyvari <peter.metz@unarin.com>
  • Loading branch information
petermetz committed Sep 9, 2020
1 parent 691fe74 commit 6fc7759
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions sample/browser/index.web-sample.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
* limitations under the License.
*/

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

const module = import("../../pkg");

module.then((m) => {
Expand All @@ -23,7 +25,7 @@ module.then((m) => {
);

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

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

Expand All @@ -39,7 +41,7 @@ module.then((m) => {

//Verify the signature
const isVerified = m.blsVerify({
publicKey: keyPair.publicKey,
publicKey: Uint8Array.from(keyPair.publicKey),
messages: messages,
signature,
});
Expand All @@ -50,9 +52,9 @@ module.then((m) => {
//Derive a proof from the signature revealing the first message
const proof = m.blsCreateProof({
signature,
publicKey: keyPair.publicKey,
publicKey: Uint8Array.from(keyPair.publicKey),
messages,
nonce: "nonce",
nonce: stringToBytes("nonce"),
revealed: [0],
});

Expand All @@ -61,9 +63,9 @@ module.then((m) => {
//Verify the created proof
const isProofVerified = m.blsVerifyProof({
proof,
publicKey: keyPair.publicKey,
publicKey: Uint8Array.from(keyPair.publicKey),
messages: messages.slice(0, 1),
nonce: "nonce",
nonce: stringToBytes("nonce"),
});

const isProofVerifiedString = JSON.stringify(isProofVerified);
Expand Down

0 comments on commit 6fc7759

Please # to comment.