@alexbosworth/blockchain 4.7.1 → 4.7.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Versions
2
2
 
3
- ## 4.7.1
3
+ ## 4.7.2
4
4
 
5
5
  - `nonWitnessHashToSign`: Add method to calculate the pre-SegWit hash to sign
6
6
 
package/package.json CHANGED
@@ -19,5 +19,5 @@
19
19
  "scripts": {
20
20
  "test": "node --experimental-test-coverage --test test/5bit/*.js test/addresses/*.js test/hashes/*.js test/numbers/*.js test/script/*.js test/transactions/*.js"
21
21
  },
22
- "version": "4.7.1"
22
+ "version": "4.7.2"
23
23
  }
@@ -100,15 +100,20 @@ const tests = [
100
100
  args: {
101
101
  transaction: '010000000002010000000000000000000000000000000000000000000000000000000000000000ffffffff00ffffffff010100000000000000000101510000' + '0000',
102
102
  },
103
- description: 'A witness serialized tx with an unknown flag is rejected',
104
- error: 'UnexpectedWitnessFlagByteValueInTransaction',
103
+ description: 'A zero marker with unknown flag is legacy and has extra data',
104
+ error: 'UnexpectedDataAfterTransactionToGetComponentsOf',
105
105
  },
106
106
  {
107
107
  args: {
108
108
  transaction: '0100000000' + '02' + '01000000000000000151' + '020000000000000000' + '00000000',
109
109
  },
110
- description: 'A zero marker with a non-witness non-zero flag is rejected',
111
- error: 'UnexpectedWitnessFlagByteValueInTransaction',
110
+ description: 'A zero inputs tx with a non-witness flag byte is parsed as legacy',
111
+ expected: {
112
+ inputs: [],
113
+ locktime: 0,
114
+ outputs: [{script: '51', tokens: 1}, {script: '', tokens: 2}],
115
+ version: 1,
116
+ },
112
117
  },
113
118
  {
114
119
  args: {
@@ -17,7 +17,6 @@ const minByteLengthInput = 41;
17
17
  const minByteLengthOutput = 9;
18
18
  const times = n => [...Array(n).keys()];
19
19
  const witnessFlagValue = 1;
20
- const zeroFlagValue = 0;
21
20
 
22
21
  /** Parse a raw transaction out of a buffer at a specific offset start
23
22
 
@@ -87,14 +86,8 @@ module.exports = args => {
87
86
  // The presence of the marker and flag indicates SegWit tx encoding
88
87
  const isSegWit = !marker && flag === witnessFlagValue;
89
88
 
90
- // A zero marker with a zero flag is the legacy encoding of an empty tx: the
91
- // zero marker is an empty inputs count and the zero flag is an empty outputs
92
- // count. Any other flag value following a zero marker is unknown data.
93
- if (!marker && !isSegWit && flag !== zeroFlagValue) {
94
- throw new Error('UnexpectedWitnessFlagByteValueInTransaction');
95
- }
96
-
97
- // When tx isn't SegWit though, the bytes are not marker and flag
89
+ // When tx isn't SegWit though, the bytes are not marker and flag: a zero
90
+ // marker without the witness flag is a legacy tx with an empty inputs count
98
91
  offset += isSegWit ? byteCountMarkerFlag : byteCountNoMarkerFlag;
99
92
 
100
93
  const inputsCount = decodeCompactInt(args.buffer, offset);