Browse Source

Merge pull request #2 from junderw/fixes2

Fixes2
master
Andrew Camilleri 5 years ago
committed by GitHub
parent
commit
53a8d615b4
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 4
      README.md
  2. 2
      package.json
  3. 23
      src/index.js
  4. 20
      ts_src/index.ts

4
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)

2
package.json

@ -1,5 +1,5 @@
{
"name": "payjoin-client-js",
"name": "payjoin-client",
"version": "1.0.0",
"description": "A BTCPay Payjoin compatible client",
"keywords": [

23
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

20
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> = 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

Loading…
Cancel
Save