hyperledger-archives / ursa

Hyperledger Ursa (a shared cryptographic library) has moved to end-of-life status, with the components of Ursa still in use moved to their relevant Hyperledger projects (AnonCreds, Indy, Aries and Iroha).
https://wiki.hyperledger.org/display/ursa
Apache License 2.0
321 stars 142 forks source link

fix(wasm): compilable and updated some of the bindings #217

Closed berendsliedrecht closed 1 year ago

berendsliedrecht commented 1 year ago

Did some local testing and ed25519sha512 and bls seem to work.

import { Ed25519Sha512 } from "ursa";
import assert from "assert";

// Test vectors from ursa/libursa/src/signatures/ed25519.rs

const message = new TextEncoder().encode(
  "This is a dummy message for use with tests"
);

const signature = Buffer.from(
  "451b5b8e8725321541954997781de51f4142e4a56bab68d24f6a6b92615de5eefb74134138315859a32c7cf5fe5a488bc545e2e08e5eedfd1fb10188d532d808",
  "hex"
);

const publicKey = Buffer.from(
  "27c96646f2d4632d4fc241f84cbc427fbc3ecaa95becba55088d6c7b81fc5bbf",
  "hex"
);

assert(Ed25519Sha512.verify(message, signature, publicKey));

bls has some issues, maybe intentional, with dropping values (see g1 and g2).

import assert from "assert";
import { Bls, Generator, SignKey, VerKey } from "ursa";

const msg = new Uint8Array([1, 1, 1]);

const seed = new Uint8Array(32);
const b = new Generator().toBytes();

// Creating of the same two generators as `Bls.sign` drops one and `Bls.verify` as well.
const g1 = Generator.fromBytes(b);
const g2 = Generator.fromBytes(b);

const signKey = SignKey.fromSeed(seed);
const signKey2 = SignKey.fromSeed(seed);

const verKey = new VerKey(g1, signKey);
const signature = Bls.sign(msg, signKey2);

assert(Bls.verify(msg, signature, verKey, g2));

Signed-off-by: blu3beri blu3beri@proton.me

berendsliedrecht commented 1 year ago

Also, I was curious what the intention of the wasmprivatekey and wasmpublickey were. I assume that you do not deal with the keys themselves in the JS side.

appetrosyan commented 1 year ago

In principle it looks good. Let me know once you've addressed the comments, and I'll approve.

berendsliedrecht commented 1 year ago

In principle it looks good. Let me know once you've addressed the comments, and I'll approve.

All comments should be resolved.