mirror of
https://github.com/zhigang1992/DefinitelyTyped.git
synced 2026-05-10 09:40:21 +08:00
bitcore-lib: Improve and expand type definitions (#27301)
This commit is contained in:
@@ -2,7 +2,8 @@ import * as bitcore from 'bitcore-lib';
|
||||
|
||||
const transaction = new bitcore.Transaction({});
|
||||
|
||||
const output: bitcore.Output = transaction.outputs[0];
|
||||
const output: bitcore.Transaction.Output = transaction.outputs[0];
|
||||
const input: bitcore.Transaction.Input = transaction.inputs[0];
|
||||
|
||||
const privateKey: bitcore.PrivateKey = new bitcore.PrivateKey('privateKey');
|
||||
const publicKey: bitcore.PublicKey = privateKey.publicKey;
|
||||
@@ -24,4 +25,11 @@ const tx = new bitcore.Transaction()
|
||||
.from(utxo)
|
||||
.change('bitcoinAddress')
|
||||
.addData(Buffer.from(''))
|
||||
.sign('bitcoinAddressPrivateKey');
|
||||
.sign('bitcoinAddressPrivateKey')
|
||||
.enableRBF();
|
||||
|
||||
tx.verify();
|
||||
|
||||
new bitcore.Unit(2, 'BTC').toSatoshis();
|
||||
|
||||
bitcore.Unit.fromMilis(1000).toBTC();
|
||||
|
||||
216
types/bitcore-lib/index.d.ts
vendored
216
types/bitcore-lib/index.d.ts
vendored
@@ -9,17 +9,30 @@
|
||||
|
||||
export namespace crypto {
|
||||
class BN { }
|
||||
|
||||
namespace ECDSA {
|
||||
function sign(message: Buffer, key: PrivateKey): Signature;
|
||||
function verify(hashbuf: Buffer, sig: Signature, pubkey: PublicKey, endian?: 'little'): boolean;
|
||||
}
|
||||
|
||||
namespace Hash {
|
||||
function sha256(buffer: Buffer): Uint8Array;
|
||||
function sha1(buffer: Buffer): Buffer;
|
||||
function sha256(buffer: Buffer): Buffer;
|
||||
function sha256sha256(buffer: Buffer): Buffer;
|
||||
function sha256ripemd160(buffer: Buffer): Buffer;
|
||||
function sha512(buffer: Buffer): Buffer;
|
||||
function ripemd160(buffer: Buffer): Buffer;
|
||||
|
||||
function sha256hmac(data: Buffer, key: Buffer): Buffer;
|
||||
function sha512hmac(data: Buffer, key: Buffer): Buffer;
|
||||
}
|
||||
|
||||
namespace Random {
|
||||
function getRandomBuffer(size: number): Buffer;
|
||||
}
|
||||
|
||||
namespace Point {}
|
||||
|
||||
class Signature {
|
||||
static fromDER(sig: Buffer): Signature;
|
||||
static fromString(data: string): Signature;
|
||||
@@ -28,24 +41,6 @@ export namespace crypto {
|
||||
}
|
||||
}
|
||||
|
||||
export class Transaction {
|
||||
inputs: Input[];
|
||||
outputs: Output[];
|
||||
readonly id: string;
|
||||
readonly hash: string;
|
||||
nid: string;
|
||||
|
||||
constructor(serialized?: any);
|
||||
|
||||
from(utxos: Transaction.UnspentOutput[]): Transaction;
|
||||
to(address: Address | string, amount: number): Transaction;
|
||||
change(address: Address | string): Transaction;
|
||||
sign(privateKey: PrivateKey | string): Transaction;
|
||||
applySignature(sig: crypto.Signature): Transaction;
|
||||
addData(data: Buffer): this;
|
||||
serialize(): string;
|
||||
}
|
||||
|
||||
export namespace Transaction {
|
||||
class UnspentOutput {
|
||||
static fromObject(o: object): UnspentOutput;
|
||||
@@ -62,6 +57,62 @@ export namespace Transaction {
|
||||
toObject(): this;
|
||||
toString(): string;
|
||||
}
|
||||
|
||||
class Output {
|
||||
readonly script: Script;
|
||||
readonly satoshis: number;
|
||||
|
||||
constructor(data: object);
|
||||
|
||||
setScript(script: Script | string | Buffer): this;
|
||||
inspect(): string;
|
||||
toObject(): object;
|
||||
}
|
||||
|
||||
class Input {
|
||||
readonly prevTxId: Buffer;
|
||||
readonly outputIndex: number;
|
||||
readonly sequenceNumber: number;
|
||||
readonly script: Script;
|
||||
readonly output?: Output;
|
||||
}
|
||||
}
|
||||
|
||||
export class Transaction {
|
||||
inputs: Transaction.Input[];
|
||||
outputs: Transaction.Output[];
|
||||
readonly id: string;
|
||||
readonly hash: string;
|
||||
nid: string;
|
||||
|
||||
constructor(serialized?: any);
|
||||
|
||||
from(utxos: Transaction.UnspentOutput[]): this;
|
||||
to(address: Address[] | Address | string, amount: number): this;
|
||||
change(address: Address | string): this;
|
||||
fee(amount: number): this;
|
||||
feePerKb(amount: number): this;
|
||||
sign(privateKey: PrivateKey | string): this;
|
||||
applySignature(sig: crypto.Signature): this;
|
||||
addInput(input: Transaction.Input): this;
|
||||
addOutput(output: Transaction.Output): this;
|
||||
addData(value: Buffer): this;
|
||||
lockUntilDate(time: Date | number): this;
|
||||
lockUntilBlockHeight(height: number): this;
|
||||
|
||||
hasWitnesses(): boolean;
|
||||
getFee(): number;
|
||||
getChangeOutput(): Transaction.Output | null;
|
||||
getLockTime(): Date | number;
|
||||
|
||||
verify(): string | boolean;
|
||||
isCoinbase(): boolean;
|
||||
|
||||
enableRBF(): this;
|
||||
isRBF(): boolean;
|
||||
|
||||
inspect(): string;
|
||||
serialize(): string;
|
||||
}
|
||||
|
||||
export class Block {
|
||||
@@ -78,8 +129,16 @@ export class Block {
|
||||
|
||||
export class PrivateKey {
|
||||
readonly publicKey: PublicKey;
|
||||
readonly network: Networks.Network;
|
||||
|
||||
constructor(key: string);
|
||||
toAddress(): Address;
|
||||
toPublicKey(): PublicKey;
|
||||
toString(): string;
|
||||
toObject(): object;
|
||||
toJSON(): object;
|
||||
toWIF(): string;
|
||||
|
||||
constructor(key?: string, network?: Networks.Network);
|
||||
}
|
||||
|
||||
export class PublicKey {
|
||||
@@ -91,18 +150,107 @@ export class PublicKey {
|
||||
toDER(): Buffer;
|
||||
}
|
||||
|
||||
export interface Output {
|
||||
readonly script: any;
|
||||
export class HDPrivateKey {
|
||||
readonly hdPublicKey: HDPublicKey;
|
||||
|
||||
constructor(data?: string | Buffer | object);
|
||||
|
||||
derive(arg: string | number, hardened?: boolean): HDPrivateKey;
|
||||
deriveChild(arg: string | number, hardened?: boolean): HDPrivateKey;
|
||||
deriveNonCompliantChild(arg: string | number, hardened?: boolean): HDPrivateKey;
|
||||
|
||||
toString(): string;
|
||||
toObject(): object;
|
||||
toJSON(): object;
|
||||
}
|
||||
|
||||
export class HDPublicKey {
|
||||
readonly xpubkey: Buffer;
|
||||
readonly network: Networks.Network;
|
||||
readonly depth: number;
|
||||
readonly publicKey: PublicKey;
|
||||
readonly fingerPrint: Buffer;
|
||||
|
||||
constructor(arg: string | Buffer | object);
|
||||
|
||||
derive(arg: string | number, hardened?: boolean): HDPublicKey;
|
||||
deriveChild(arg: string | number, hardened?: boolean): HDPublicKey;
|
||||
|
||||
toString(): string;
|
||||
}
|
||||
|
||||
export namespace Script {
|
||||
const types: {
|
||||
DATA_OUT: string;
|
||||
};
|
||||
function buildMultisigOut(publicKeys: PublicKey[], threshold: number, opts: object): Script;
|
||||
function buildWitnessMultisigOutFromScript(script: Script): Script;
|
||||
function buildMultisigIn(pubkeys: PublicKey[], threshold: number, signatures: Buffer[], opts: object): Script;
|
||||
function buildP2SHMultisigIn(pubkeys: PublicKey[], threshold: number, signatures: Buffer[], opts: object): Script;
|
||||
function buildPublicKeyHashOut(address: Address): Script;
|
||||
function buildPublicKeyOut(pubkey: PublicKey): Script;
|
||||
function buildDataOut(data: string | Buffer, encoding?: string): Script;
|
||||
function buildScriptHashOut(script: Script): Script;
|
||||
function buildPublicKeyIn(signature: crypto.Signature | Buffer, sigtype: number): Script;
|
||||
function buildPublicKeyHashIn(publicKey: PublicKey, signature: crypto.Signature | Buffer, sigtype: number): Script;
|
||||
|
||||
function fromAddress(address: string | Address): Script;
|
||||
|
||||
function empty(): Script;
|
||||
}
|
||||
|
||||
export class Script { }
|
||||
export class Script {
|
||||
constructor(data: string | object);
|
||||
|
||||
set(obj: object): this;
|
||||
|
||||
toBuffer(): Buffer;
|
||||
toASM(): string;
|
||||
toString(): string;
|
||||
toHex(): string;
|
||||
|
||||
isPublicKeyHashOut(): boolean;
|
||||
isPublicKeyHashIn(): boolean;
|
||||
|
||||
getPublicKey(): Buffer;
|
||||
getPublicKeyHash(): Buffer;
|
||||
|
||||
isPublicKeyOut(): boolean;
|
||||
isPublicKeyIn(): boolean;
|
||||
|
||||
isScriptHashOut(): boolean;
|
||||
isWitnessScriptHashOut(): boolean;
|
||||
isWitnessPublicKeyHashOut(): boolean;
|
||||
isWitnessProgram(): boolean;
|
||||
isScriptHashIn(): boolean;
|
||||
isMultisigOut(): boolean;
|
||||
isMultisigIn(): boolean;
|
||||
isDataOut(): boolean;
|
||||
|
||||
getData(): Buffer;
|
||||
isPushOnly(): boolean;
|
||||
|
||||
classify(): string;
|
||||
classifyInput(): string;
|
||||
classifyOutput(): string;
|
||||
|
||||
isStandard(): boolean;
|
||||
|
||||
prepend(obj: any): this;
|
||||
add(obj: any): this;
|
||||
|
||||
hasCodeseparators(): boolean;
|
||||
removeCodeseparators(): this;
|
||||
|
||||
equals(script: Script): boolean;
|
||||
|
||||
getAddressInfo(): Address | boolean;
|
||||
findAndDelete(script: Script): this;
|
||||
checkMinimalPush(i: number): boolean;
|
||||
getSignatureOperationsCount(accurate: boolean): number;
|
||||
|
||||
toAddress(): Address;
|
||||
}
|
||||
|
||||
export interface Util {
|
||||
readonly buffer: {
|
||||
@@ -125,6 +273,24 @@ export namespace Networks {
|
||||
function get(args: string | number | Network, keys: string | string[]): Network;
|
||||
}
|
||||
|
||||
export class Address {}
|
||||
export class Address {
|
||||
readonly hashBuffer: Buffer;
|
||||
readonly network: Networks.Network;
|
||||
readonly type: string;
|
||||
|
||||
export class Input {}
|
||||
constructor(data: Buffer | Uint8Array | string | object, network?: Networks.Network, type?: string);
|
||||
}
|
||||
|
||||
export class Unit {
|
||||
static fromBTC(amount: number): Unit;
|
||||
static fromMilis(amount: number): Unit;
|
||||
static fromBits(amount: number): Unit;
|
||||
static fromSatoshis(amount: number): Unit;
|
||||
|
||||
constructor(amount: number, unitPreference: string);
|
||||
|
||||
toBTC(): number;
|
||||
toMilis(): number;
|
||||
toBits(): number;
|
||||
toSatoshis(): number;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user