Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 | 41x 41x 43x 43x 67x 67x | /* @flow */
import bitcoinjs from 'bitcoinjs-lib'
import { hexStringToECPair, ecPairToAddress } from '../utils'
export interface TransactionSigner {
/**
* @returns version number of the signer, currently, should always be 1
* @private
*/
signerVersion(): number;
/**
* @returns a string representing the transaction signer's address
* (usually Base58 check encoding)
* @private
*/
getAddress(): Promise<string>;
/**
* Signs a transaction input
* @param {TransactionBuilder} transaction - the transaction to sign
* @param {number} inputIndex - the input on the transaction to sign
* @private
*/
signTransaction(transaction: bitcoinjs.TransactionBuilder, inputIndex: number): Promise<void>;
}
/**
* Class representing a transaction signer for pubkeyhash addresses
* (a.k.a. single-sig addresses)
* @private
*/
export class PubkeyHashSigner implements TransactionSigner {
ecPair: bitcoinjs.ECPair
constructor(ecPair: bitcoinjs.ECPair) {
this.ecPair = ecPair
}
static fromHexString(keyHex: string) {
return new PubkeyHashSigner(hexStringToECPair(keyHex))
}
signerVersion(): number {
return 1
}
getAddress(): Promise<string> {
return Promise.resolve()
.then(() => ecPairToAddress(this.ecPair))
}
signTransaction(transaction: bitcoinjs.TransactionBuilder, inputIndex: number) : Promise<void> {
return Promise.resolve()
.then(() => {
transaction.sign(inputIndex, this.ecPair)
})
}
}
|