[ethjs-signer] introduce typings (#18338)

* [ethjs-signer] introduce typings

* split function into two overloads in ethjs-signer package
This commit is contained in:
Bryson Thill
2017-07-26 07:07:41 -07:00
committed by Andy
parent 0a51536fcb
commit 1968358c88
4 changed files with 59 additions and 0 deletions

View File

@@ -0,0 +1,16 @@
import { sign, recover } from "ethjs-signer";
const nonce = 0;
const privateKey = '0xecbcd9838f7f2afa6e809df8d7cdae69aa5dfc14d563ee98e97effd3f6a652f2';
const transaction = {
to: '0xce31a19193d4b23f4e9d6163d7247243bAF801c3',
value: 300000,
gasPrice: 2000000,
nonce
};
const signedTransactionString = sign(transaction, privateKey) as string;
const signedTransaction = sign(transaction, privateKey, true) as any[];
const publicKey = recover(signedTransactionString, -1, signedTransaction[7], signedTransaction[8]);

18
types/ethjs-signer/index.d.ts vendored Normal file
View File

@@ -0,0 +1,18 @@
// Type definitions for ethjs-signer 0.1
// Project: https://github.com/ethjs/ethjs-signer/
// Definitions by: Bryson Thill <https://github.com/doppio>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.3
/// <reference types="node" />
/**
* Signs a raw transaction and return it either as a serialized hex string or raw tx object.
*/
export function sign(transaction: object, privateKey: string, toObject?: false): string;
export function sign(transaction: object, privateKey: string, toObject: true): any[];
/**
* Recovers a ECDSA public key from a raw transaction.
*/
export function recover(rawTx: string | Buffer, v: number, r: Buffer, s: Buffer): Buffer;

View File

@@ -0,0 +1,22 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": [
"es6"
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": true,
"baseUrl": "../",
"typeRoots": [
"../"
],
"types": [ ],
"noEmit": true,
"forceConsistentCasingInFileNames": true
},
"files": [
"index.d.ts",
"ethjs-signer-tests.ts"
]
}

View File

@@ -0,0 +1,3 @@
{
"extends": "dtslint/dt.json"
}