From 6ed635d7b41b976f2d88dc7492e857c8adda0543 Mon Sep 17 00:00:00 2001 From: Luke Childs Date: Tue, 25 Jun 2019 18:22:00 +0700 Subject: [PATCH] Flesh out signInput interface --- src/psbt.js | 12 ++++++++++++ ts_src/psbt.ts | 18 ++++++++++++++++++ types/psbt.d.ts | 2 ++ 3 files changed, 32 insertions(+) diff --git a/src/psbt.js b/src/psbt.js index 70b60e2..887c814 100644 --- a/src/psbt.js +++ b/src/psbt.js @@ -5,5 +5,17 @@ class Psbt extends bip174_1.Psbt { constructor() { super(); } + signInput(inputIndex, keyPair) { + // TODO: Implement BIP174 pre-sign checks: + // https://github.com/bitcoin/bips/blob/master/bip-0174.mediawiki#signer + // TODO: Get hash to sign + const hash = Buffer.alloc(32); + const partialSig = { + pubkey: keyPair.publicKey, + signature: keyPair.sign(hash), + }; + this.addPartialSigToInput(inputIndex, partialSig); + return this; + } } exports.Psbt = Psbt; diff --git a/ts_src/psbt.ts b/ts_src/psbt.ts index 08d2670..8fec780 100644 --- a/ts_src/psbt.ts +++ b/ts_src/psbt.ts @@ -1,7 +1,25 @@ import { Psbt as PsbtBase } from 'bip174'; +import { Signer } from './ecpair'; export class Psbt extends PsbtBase { constructor() { super(); } + + signInput(inputIndex: number, keyPair: Signer): Psbt { + // TODO: Implement BIP174 pre-sign checks: + // https://github.com/bitcoin/bips/blob/master/bip-0174.mediawiki#signer + + // TODO: Get hash to sign + const hash = Buffer.alloc(32); + + const partialSig = { + pubkey: keyPair.publicKey, + signature: keyPair.sign(hash), + }; + + this.addPartialSigToInput(inputIndex, partialSig); + + return this; + } } diff --git a/types/psbt.d.ts b/types/psbt.d.ts index 880ebd2..a58b982 100644 --- a/types/psbt.d.ts +++ b/types/psbt.d.ts @@ -1,4 +1,6 @@ import { Psbt as PsbtBase } from 'bip174'; +import { Signer } from './ecpair'; export declare class Psbt extends PsbtBase { constructor(); + signInput(inputIndex: number, keyPair: Signer): Psbt; }