From dc60342c7e3e724be8143bbefdc9acdc1019a94c Mon Sep 17 00:00:00 2001 From: junderw Date: Mon, 20 Apr 2020 22:29:04 +0900 Subject: [PATCH 1/2] Some type fixes and js build --- src/index.js | 23 +++++++++++++---------- ts_src/index.ts | 20 +++++++++----------- 2 files changed, 22 insertions(+), 21 deletions(-) diff --git a/src/index.js b/src/index.js index 0aa640c..87ae0e3 100644 --- a/src/index.js +++ b/src/index.js @@ -1,7 +1,6 @@ 'use strict'; Object.defineProperty(exports, '__esModule', { value: true }); const bitcoinjs_lib_1 = require('bitcoinjs-lib'); -const bitcoinjs_lib_2 = require('bitcoinjs-lib'); async function requestPayjoinWithCustomRemoteCall(psbt, remoteCall) { const clonedPsbt = psbt.clone(); clonedPsbt.finalizeAllInputs(); @@ -15,12 +14,6 @@ async function requestPayjoinWithCustomRemoteCall(psbt, remoteCall) { delete clonedPsbt.data.globalMap.globalXpub; const payjoinPsbt = await remoteCall(clonedPsbt); if (!payjoinPsbt) throw new Error("We did not get the receiver's PSBT"); - // no inputs were added? - if (clonedPsbt.inputCount <= payjoinPsbt.inputCount) { - throw new Error( - "There were less inputs than before in the receiver's PSBT", - ); - } if ( payjoinPsbt.data.globalMap.globalXpub && payjoinPsbt.data.globalMap.globalXpub.length > 0 @@ -62,7 +55,7 @@ async function requestPayjoinWithCustomRemoteCall(psbt, remoteCall) { // Can we assume output will contain redeemScript and witnessScript? // If so, we could decompile scriptPubkey, RS, and WS, and search for // the pubkey and its hash160. - bitcoinjs_lib_2.payments.p2wpkh({ + bitcoinjs_lib_1.payments.p2wpkh({ pubkey: originalOutput.bip32Derivation[0].pubkey, }).output, ) @@ -70,8 +63,18 @@ async function requestPayjoinWithCustomRemoteCall(psbt, remoteCall) { payjoinPsbt.updateOutput(index, originalOutput); }); } - // TODO: check payjoinPsbt.version == psbt.version - // TODO: check payjoinPsbt.locktime == psbt.locktime + if ( + getGlobalTransaction(payjoinPsbt).version !== + getGlobalTransaction(psbt).version + ) { + throw new Error('The version field of the transaction has been modified'); + } + if ( + getGlobalTransaction(payjoinPsbt).locktime !== + getGlobalTransaction(psbt).locktime + ) { + throw new Error('The LockTime field of the transaction has been modified'); + } // TODO: check payjoinPsbt.inputs where input belongs to us, that it is not finalized // TODO: check payjoinPsbt.inputs where input belongs to us, that it is was included in psbt.inputs // TODO: check payjoinPsbt.inputs where input belongs to us, that its sequence has not changed from that of psbt.inputs diff --git a/ts_src/index.ts b/ts_src/index.ts index 379f6ab..63a0a40 100644 --- a/ts_src/index.ts +++ b/ts_src/index.ts @@ -1,4 +1,4 @@ -import { Psbt, Transaction, payments } from 'bitcoinjs-lib'; +import { payments, Psbt, Transaction, TxInput } from 'bitcoinjs-lib'; import { Bip32Derivation, GlobalXpub, @@ -6,13 +6,6 @@ import { } from 'bip174/src/lib/interfaces'; type Nullable = T | null; -interface TxInput { - hash: Buffer; - index: number; - script: Buffer; - sequence: number; - witness: Buffer[]; -} export async function requestPayjoinWithCustomRemoteCall( psbt: Psbt, @@ -33,7 +26,6 @@ export async function requestPayjoinWithCustomRemoteCall( const payjoinPsbt = await remoteCall(clonedPsbt); if (!payjoinPsbt) throw new Error("We did not get the receiver's PSBT"); - if ( payjoinPsbt.data.globalMap.globalXpub && (payjoinPsbt.data.globalMap.globalXpub as GlobalXpub[]).length > 0 @@ -87,10 +79,16 @@ export async function requestPayjoinWithCustomRemoteCall( }); } - if (getGlobalTransaction(payjoinPsbt).version !== getGlobalTransaction(psbt).version) { + if ( + getGlobalTransaction(payjoinPsbt).version !== + getGlobalTransaction(psbt).version + ) { throw new Error('The version field of the transaction has been modified'); } - if (getGlobalTransaction(payjoinPsbt).locktime !== getGlobalTransaction(psbt).locktime) { + if ( + getGlobalTransaction(payjoinPsbt).locktime !== + getGlobalTransaction(psbt).locktime + ) { throw new Error('The LockTime field of the transaction has been modified'); } // TODO: check payjoinPsbt.inputs where input belongs to us, that it is not finalized From 6723ad3cc663bddbfd711b8e35748a8f0cd4fa5f Mon Sep 17 00:00:00 2001 From: junderw Date: Mon, 20 Apr 2020 22:30:13 +0900 Subject: [PATCH 2/2] Fix README links (not ready yet though) --- README.md | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index fb76690..1da1f50 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # Payjoin Client -[![Build Status](https://travis-ci.org/bitcoinjs/bip32.png?branch=master)](https://travis-ci.org/bitcoinjs/bip32) +[![Build Status](https://travis-ci.org/bitcoinjs/payjoin-client.png?branch=master)](https://travis-ci.org/bitcoinjs/payjoin-client) -[![NPM](https://img.shields.io/npm/v/bip32.svg)](https://www.npmjs.org/package/bip32) +[![NPM](https://img.shields.io/npm/v/payjoin-client.svg)](https://www.npmjs.org/package/payjoin-client) [![code style: prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat-square)](https://github.com/prettier/prettier) diff --git a/package.json b/package.json index e04548d..947b672 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,5 @@ { - "name": "payjoin-client-js", + "name": "payjoin-client", "version": "1.0.0", "description": "A BTCPay Payjoin compatible client", "keywords": [