mirror of
https://github.com/zhigang1992/DefinitelyTyped.git
synced 2026-06-06 06:19:58 +08:00
[ethjs-signer] introduce typings (#18338)
* [ethjs-signer] introduce typings * split function into two overloads in ethjs-signer package
This commit is contained in:
16
types/ethjs-signer/ethjs-signer-tests.ts
Normal file
16
types/ethjs-signer/ethjs-signer-tests.ts
Normal 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
18
types/ethjs-signer/index.d.ts
vendored
Normal 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;
|
||||
22
types/ethjs-signer/tsconfig.json
Normal file
22
types/ethjs-signer/tsconfig.json
Normal 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"
|
||||
]
|
||||
}
|
||||
3
types/ethjs-signer/tslint.json
Normal file
3
types/ethjs-signer/tslint.json
Normal file
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"extends": "dtslint/dt.json"
|
||||
}
|
||||
Reference in New Issue
Block a user