mirror of
https://github.com/zhigang1992/DefinitelyTyped.git
synced 2026-05-28 16:45:10 +08:00
* Revert "Add tsline file" This reverts commita0f8c9acc3. * Revert "Rename .d.ts file per guidelines" This reverts commit7eb6f76ab5. * Revert "Add types for ZeroMQ.js, derived from the 'zmq' type definitions" This reverts commitd5d3cd0fca. * Add new types for the ed25519 NPM package
16 lines
545 B
TypeScript
16 lines
545 B
TypeScript
import * as crypto from 'crypto';
|
|
import * as ed25519 from 'ed25519';
|
|
|
|
function signAndValidatePlaintext() {
|
|
const seed: Buffer = crypto.randomBytes(32);
|
|
const keyPair: ed25519.CurveKeyPair = ed25519.MakeKeypair(seed);
|
|
|
|
const plaintext = Buffer.from('plaintext');
|
|
const signature: Buffer = ed25519.Sign(plaintext, keyPair.privateKey);
|
|
|
|
const matches: boolean = ed25519.Verify(plaintext, signature, keyPair.publicKey);
|
|
if (!matches) {
|
|
throw new Error("Sign and verify should work for the same plaintext");
|
|
}
|
|
}
|