From 9a3173490cc5d457207eed6ee60004cda3ddb5dc Mon Sep 17 00:00:00 2001 From: jasonandjay <342690199@qq.com> Date: Fri, 26 Jul 2024 19:44:58 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=F0=9F=90=9E=20fix:=20update=20build=20stat?= =?UTF-8?q?us=20link=20&=20set=20leafHashes=20as=20optional?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 +- src/lib/converter/shared/tapBip32Derivation.js | 14 +++++++------- ts_src/lib/converter/shared/tapBip32Derivation.ts | 15 ++++++++------- 3 files changed, 16 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index 5f50bc5..3cf2bcc 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ # bip174 -[![Build Status](https://travis-ci.org/bitcoinjs/bip174.png?branch=master)](https://travis-ci.org/bitcoinjs/bip174) +[![Build Status](https://github.com/bitcoinjs/bip174/actions/workflows/main_ci.yml/badge.svg)](https://github.com/bitcoinjs/bip174/actions/workflows/main_ci.yml) [![NPM](https://img.shields.io/npm/v/bip174.svg)](https://www.npmjs.org/package/bip174) [![code style: prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat-square)](https://github.com/prettier/prettier) diff --git a/src/lib/converter/shared/tapBip32Derivation.js b/src/lib/converter/shared/tapBip32Derivation.js index 021ca9e..9e71091 100644 --- a/src/lib/converter/shared/tapBip32Derivation.js +++ b/src/lib/converter/shared/tapBip32Derivation.js @@ -31,16 +31,16 @@ function makeConverter(TYPE_BYTE) { 'masterFingerprint: Buffer; ' + 'pubkey: Buffer; ' + 'path: string; ' + - 'leafHashes: Buffer[]; ' + + 'leafHashes?: Buffer[]; ' + '}'; function check(data) { - return ( - Array.isArray(data.leafHashes) && - data.leafHashes.every( + let leafHashesStatus = true; + if (data.leafHashes && data.leafHashes.length) { + leafHashesStatus = data.leafHashes.every( leafHash => Buffer.isBuffer(leafHash) && leafHash.length === 32, - ) && - parent.check(data) - ); + ); + } + return leafHashesStatus && parent.check(data); } return { decode, diff --git a/ts_src/lib/converter/shared/tapBip32Derivation.ts b/ts_src/lib/converter/shared/tapBip32Derivation.ts index 25ac61c..0c1c768 100644 --- a/ts_src/lib/converter/shared/tapBip32Derivation.ts +++ b/ts_src/lib/converter/shared/tapBip32Derivation.ts @@ -46,16 +46,17 @@ export function makeConverter( 'masterFingerprint: Buffer; ' + 'pubkey: Buffer; ' + 'path: string; ' + - 'leafHashes: Buffer[]; ' + + 'leafHashes?: Buffer[]; ' + '}'; function check(data: any): data is TapBip32Derivation { - return ( - Array.isArray(data.leafHashes) && - data.leafHashes.every( + let leafHashesStatus = true; + if (data.leafHashes && data.leafHashes.length){ + leafHashesStatus = data.leafHashes.every( (leafHash: any) => Buffer.isBuffer(leafHash) && leafHash.length === 32, - ) && - parent.check(data) - ); + ) + } + + return leafHashesStatus && parent.check(data) } return { From 5000cf8e186a8efd270c850ef21e8dfe65b4f36c Mon Sep 17 00:00:00 2001 From: jasonandjay <342690199@qq.com> Date: Sun, 28 Jul 2024 11:58:52 +0800 Subject: [PATCH 2/3] feat: set leafHashes as required, but allow empty --- src/lib/converter/shared/tapBip32Derivation.js | 2 +- ts_src/lib/converter/shared/tapBip32Derivation.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/lib/converter/shared/tapBip32Derivation.js b/src/lib/converter/shared/tapBip32Derivation.js index 9e71091..be76f03 100644 --- a/src/lib/converter/shared/tapBip32Derivation.js +++ b/src/lib/converter/shared/tapBip32Derivation.js @@ -31,7 +31,7 @@ function makeConverter(TYPE_BYTE) { 'masterFingerprint: Buffer; ' + 'pubkey: Buffer; ' + 'path: string; ' + - 'leafHashes?: Buffer[]; ' + + 'leafHashes: Buffer[]; ' + '}'; function check(data) { let leafHashesStatus = true; diff --git a/ts_src/lib/converter/shared/tapBip32Derivation.ts b/ts_src/lib/converter/shared/tapBip32Derivation.ts index 0c1c768..be32e50 100644 --- a/ts_src/lib/converter/shared/tapBip32Derivation.ts +++ b/ts_src/lib/converter/shared/tapBip32Derivation.ts @@ -46,7 +46,7 @@ export function makeConverter( 'masterFingerprint: Buffer; ' + 'pubkey: Buffer; ' + 'path: string; ' + - 'leafHashes?: Buffer[]; ' + + 'leafHashes: Buffer[]; ' + '}'; function check(data: any): data is TapBip32Derivation { let leafHashesStatus = true; From 79289c13a67a4c61e937c6a96d2977f579055cc5 Mon Sep 17 00:00:00 2001 From: jasonandjay <342690199@qq.com> Date: Sun, 28 Jul 2024 18:43:59 +0800 Subject: [PATCH 3/3] fix: rollback TapBip32Derivation check --- src/lib/converter/shared/tapBip32Derivation.js | 12 ++++++------ ts_src/lib/converter/shared/tapBip32Derivation.ts | 13 ++++++------- 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/src/lib/converter/shared/tapBip32Derivation.js b/src/lib/converter/shared/tapBip32Derivation.js index be76f03..021ca9e 100644 --- a/src/lib/converter/shared/tapBip32Derivation.js +++ b/src/lib/converter/shared/tapBip32Derivation.js @@ -34,13 +34,13 @@ function makeConverter(TYPE_BYTE) { 'leafHashes: Buffer[]; ' + '}'; function check(data) { - let leafHashesStatus = true; - if (data.leafHashes && data.leafHashes.length) { - leafHashesStatus = data.leafHashes.every( + return ( + Array.isArray(data.leafHashes) && + data.leafHashes.every( leafHash => Buffer.isBuffer(leafHash) && leafHash.length === 32, - ); - } - return leafHashesStatus && parent.check(data); + ) && + parent.check(data) + ); } return { decode, diff --git a/ts_src/lib/converter/shared/tapBip32Derivation.ts b/ts_src/lib/converter/shared/tapBip32Derivation.ts index be32e50..25ac61c 100644 --- a/ts_src/lib/converter/shared/tapBip32Derivation.ts +++ b/ts_src/lib/converter/shared/tapBip32Derivation.ts @@ -49,14 +49,13 @@ export function makeConverter( 'leafHashes: Buffer[]; ' + '}'; function check(data: any): data is TapBip32Derivation { - let leafHashesStatus = true; - if (data.leafHashes && data.leafHashes.length){ - leafHashesStatus = data.leafHashes.every( + return ( + Array.isArray(data.leafHashes) && + data.leafHashes.every( (leafHash: any) => Buffer.isBuffer(leafHash) && leafHash.length === 32, - ) - } - - return leafHashesStatus && parent.check(data) + ) && + parent.check(data) + ); } return {