Create @types/ed25519 for ed25519 NPM package (#20966)

* Revert "Add tsline file"

This reverts commit a0f8c9acc3.

* Revert "Rename .d.ts file per guidelines"

This reverts commit 7eb6f76ab5.

* Revert "Add types for ZeroMQ.js, derived from the 'zmq' type definitions"

This reverts commit d5d3cd0fca.

* Add new types for the ed25519 NPM package
This commit is contained in:
Erik Mavrinac
2017-10-24 11:36:34 -07:00
committed by Sheetal Nandi
parent 0e623f50a7
commit b8660a296a
4 changed files with 87 additions and 0 deletions
+15
View File
@@ -0,0 +1,15 @@
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");
}
}
+46
View File
@@ -0,0 +1,46 @@
// Type definitions for ed25519 0.0
// Project: https://github.com/dazoe/ed25519
// Definitions by: Erik Mavrinac <https://github.com/erikma>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// Main site: https://ed25519.cr.yp.to/
// Manually generated and maintained because the package is a
// veneer on an underlying C library; auto-generation won't work.
// The JavaScript-C interface is well described at
// https://github.com/dazoe/ed25519/blob/master/src/ed25519.cc
/// <reference types="node" />
/** The key material returned from a call to MakeKeypair(). */
export interface CurveKeyPair {
/**
* A Buffer containing the public portion of the Curve25519 key.
*/
publicKey: Buffer;
/**
* A Buffer containing the private, secret portion of the Curve25519 key.
*/
privateKey: Buffer;
}
/**
* Uses the crytpographically strong random seed to generate a
* Curve25519 key pair.
* @return The public and private key pair.
*/
export function MakeKeypair(seed: Buffer): CurveKeyPair;
/**
* Signs a plaintext message buffer using the private key generated using
* MakeKeypair().
* @return The signature calculated on the plaintext.
*/
export function Sign(message: Buffer, privateKeyOrKeyPair: Buffer | CurveKeyPair): Buffer;
/**
* Verifies a signature for a message buffer using a
* public key generated using MakeKeypair().
* @return True if the signature validates correctly, false otherwise.
*/
export function Verify(message: Buffer, signature: Buffer, publicKey: Buffer): boolean;
+23
View File
@@ -0,0 +1,23 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": [
"es6"
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": true,
"strictFunctionTypes": true,
"baseUrl": "../",
"typeRoots": [
"../"
],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true
},
"files": [
"index.d.ts",
"ed25519-tests.ts"
]
}
+3
View File
@@ -0,0 +1,3 @@
{
"extends": "dtslint/dt.json"
}