@neuraiproject/neurai-scripts 0.11.0 → 0.12.0

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/dist/index.cjs CHANGED
@@ -1985,12 +1985,19 @@ function parseTransaction(hex) {
1985
1985
  for (let i = 0; i < voutCount; i += 1)
1986
1986
  outputs.push(readOutput(reader));
1987
1987
  }
1988
- // NIP-014: vrefin sits between vout and witness, v3 only (even when empty).
1988
+ // NIP-014: reference inputs sit between vout and witness, announced by flag
1989
+ // 0x02. Without the flag a version 3 transaction reads as 1.0.7 reads it.
1989
1990
  const vrefin = [];
1990
- if (version === 3) {
1991
+ const hasRefInputs = (flags & 2) !== 0;
1992
+ if (hasRefInputs) {
1993
+ flags ^= 2;
1991
1994
  const refCount = reader.readCount(36, 'refinput');
1992
1995
  for (let i = 0; i < refCount; i += 1)
1993
1996
  vrefin.push(readOutpoint(reader));
1997
+ if (vrefin.length === 0) {
1998
+ // One encoding per transaction: the flag means some.
1999
+ throw new Error('Superfluous reference inputs record (flag 0x02 with no reference inputs)');
2000
+ }
1994
2001
  }
1995
2002
  if (flags & 1) {
1996
2003
  flags ^= 1;
@@ -2003,6 +2010,11 @@ function parseTransaction(hex) {
2003
2010
  }
2004
2011
  input.witness = stack;
2005
2012
  }
2013
+ if (hasRefInputs && !inputs.some(inputHasWitness)) {
2014
+ // With reference inputs the witness flag means some witness; 1.0.7 reads
2015
+ // an empty witness record without them, and so does the node.
2016
+ throw new Error('Superfluous witness record (flag 0x01 with no witness data)');
2017
+ }
2006
2018
  }
2007
2019
  if (flags) {
2008
2020
  throw new Error(`Unknown transaction optional data (flags 0x${flags.toString(16)})`);
@@ -2013,6 +2025,9 @@ function parseTransaction(hex) {
2013
2025
  }
2014
2026
  return { version, inputs, outputs, vrefin, locktime };
2015
2027
  }
2028
+ function inputHasWitness(input) {
2029
+ return (input.witness?.length ?? 0) > 0;
2030
+ }
2016
2031
 
2017
2032
  /**
2018
2033
  * Address helpers. Wraps `decodeAddress` from