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:
dadepo 2022-07-06 17:05:38 +02:00 committed by GitHub
parent e3ba38c938
commit 6057e93208
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 12 additions and 14 deletions

View File

@ -22,13 +22,11 @@ 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 // class-based interface
const secretKey = SecretKey.fromKeygen(); const secretKey = bls.SecretKey.fromKeygen();
const publicKey = secretKey.toPublicKey(); const publicKey = secretKey.toPublicKey();
const message = new Uint8Array(32); const message = new Uint8Array(32);
@ -37,9 +35,9 @@ import {SecretKey, secretKeyToPublicKey, sign, verify} from "@chainsafe/bls";
// functional interface // functional interface
const sk = secretKey.toBytes(); const sk = secretKey.toBytes();
const pk = secretKeyToPublicKey(sk); const pk = bls.secretKeyToPublicKey(sk);
const sig = sign(sk, message); const sig = bls.sign(sk, message);
console.log("Is valid: ", verify(pk, message, sig)); console.log("Is valid: ", bls.verify(pk, message, sig));
})(); })();
``` ```