Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"extends": "airbnb",
"parser": "babel-eslint",
"plugins": [],
"plugins": ["flowtype"],
"ecmaFeatures": {
"jsx": false,
"modules": true
Expand Down Expand Up @@ -31,6 +31,7 @@
"new-cap": 0,
"camelcase": 2,
"semi": [2, "never"],
"valid-jsdoc": ["error"]
"valid-jsdoc": ["error"],
"flowtype/define-flow-type": 1
}
}
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Added

- New `TransactionSigner` interface to allow for different signing agents
in the `transactions` functions (e.g., makePreorder).

## [17.2.0]

### Added
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@
"documentation": "^4.0.0-rc.1",
"eslint": "^2.10.2",
"eslint-config-airbnb": "^9.0.1",
"eslint-plugin-flowtype": "^2.46.3",
"eslint-plugin-import": "^1.8.1",
"eslint-plugin-jsx-a11y": "^1.2.2",
"eslint-plugin-react": "^5.1.1",
Expand Down
1 change: 1 addition & 0 deletions src/operations/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@ export {
export { transactions } from './txbuild'

export * from './utils'
export * from './signers'

export { safety } from './safety'
53 changes: 53 additions & 0 deletions src/operations/signers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/* @flow */
import bitcoinjs from 'bitcoinjs-lib'
import { hexStringToECPair } from '../utils'

export interface TransactionSigner {
/**
* @returns version number of the signer, currently, should always be 1
*/
signerVersion(): number;
/**
* @returns a string representing the transaction signer's address
* (usually Base58 check encoding)
*/
getAddress(): Promise<string>;
/**
* Signs a transaction input
* @param {TransactionBuilder} transaction - the transaction to sign
* @param {number} inputIndex - the input on the transaction to sign
*/
signTransaction(transaction: bitcoinjs.TransactionBuilder, inputIndex: number): Promise<void>;
}

/**
* Class representing a transaction signer for pubkeyhash addresses
* (a.k.a. single-sig addresses)
*/
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(() => this.ecPair.getAddress())
}

signTransaction(transaction: bitcoinjs.TransactionBuilder, inputIndex: number) : Promise<void> {
return Promise.resolve()
.then(() => {
transaction.sign(inputIndex, this.ecPair)
})
}
}
Loading