Updated code example that has since diverged from implementation (#133)
* updated code example that has since diverged from implementation * using default export in example in readme.
This commit is contained in:
parent
e3ba38c938
commit
6057e93208
26
README.md
26
README.md
|
@ -22,24 +22,22 @@ yarn add @chainsafe/bls @chainsafe/blst
|
||||||
By default, native bindings will be used if in NodeJS and they are installed. A WASM implementation ("herumi") is used as a fallback in case any error occurs.
|
By default, native bindings will be used if in NodeJS and they are installed. A WASM implementation ("herumi") is used as a fallback in case any error occurs.
|
||||||
|
|
||||||
```ts
|
```ts
|
||||||
import {SecretKey, secretKeyToPublicKey, sign, verify} from "@chainsafe/bls";
|
import bls from "@chainsafe/bls";
|
||||||
|
|
||||||
(async () => {
|
(async () => {
|
||||||
await init("herumi");
|
// class-based interface
|
||||||
|
const secretKey = bls.SecretKey.fromKeygen();
|
||||||
|
const publicKey = secretKey.toPublicKey();
|
||||||
|
const message = new Uint8Array(32);
|
||||||
|
|
||||||
// class-based interface
|
const signature = secretKey.sign(message);
|
||||||
const secretKey = SecretKey.fromKeygen();
|
console.log("Is valid: ", signature.verify(publicKey, message));
|
||||||
const publicKey = secretKey.toPublicKey();
|
|
||||||
const message = new Uint8Array(32);
|
|
||||||
|
|
||||||
const signature = secretKey.sign(message);
|
// functional interface
|
||||||
console.log("Is valid: ", signature.verify(publicKey, message));
|
const sk = secretKey.toBytes();
|
||||||
|
const pk = bls.secretKeyToPublicKey(sk);
|
||||||
// functional interface
|
const sig = bls.sign(sk, message);
|
||||||
const sk = secretKey.toBytes();
|
console.log("Is valid: ", bls.verify(pk, message, sig));
|
||||||
const pk = secretKeyToPublicKey(sk);
|
|
||||||
const sig = sign(sk, message);
|
|
||||||
console.log("Is valid: ", verify(pk, message, sig));
|
|
||||||
})();
|
})();
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
Reference in New Issue