@btc-vision/bitcoin 6.4.7 → 6.4.9

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.
@@ -7,6 +7,7 @@ export declare const isP2WSHScript: (script: Buffer) => boolean;
7
7
  export declare const isP2SHScript: (script: Buffer) => boolean;
8
8
  export declare const isP2TR: (script: Buffer) => boolean;
9
9
  export declare const isP2OP: (script: Buffer) => boolean;
10
+ export declare const isP2A: (script: Buffer) => boolean;
10
11
  export declare function witnessStackToScriptWitness(witness: Buffer[]): Buffer;
11
12
  export interface UncompressedPublicKey {
12
13
  hybrid: Buffer;
package/browser/psbt.d.ts CHANGED
@@ -106,6 +106,7 @@ export interface PsbtOpts {
106
106
  maximumFeeRate: number;
107
107
  }
108
108
  export interface PsbtInputExtended extends PsbtInput, TransactionInput {
109
+ isPayToAnchor?: boolean;
109
110
  }
110
111
  export type PsbtOutputExtended = PsbtOutputExtendedAddress | PsbtOutputExtendedScript;
111
112
  export interface PsbtOutputExtendedAddress extends PsbtOutput {
package/build/address.js CHANGED
@@ -17,7 +17,7 @@ const FUTURE_SEGWIT_VERSION_WARNING = 'WARNING: Sending to a future segwit versi
17
17
  'then decide when it is safe to use which version of segwit.';
18
18
  export const isUnknownSegwitVersion = (output) => {
19
19
  try {
20
- const data = output.subarray(2);
20
+ const data = Buffer.from(output.subarray(2));
21
21
  if (data.length < FUTURE_SEGWIT_MIN_SIZE || data.length > FUTURE_SEGWIT_MAX_SIZE) {
22
22
  throw new TypeError('Invalid program length for segwit address');
23
23
  }
@@ -50,7 +50,7 @@ export function toFutureOPNetAddress(output, network) {
50
50
  else {
51
51
  throw new TypeError('Unsupported push opcode in script');
52
52
  }
53
- const program = output.subarray(pushPos, pushPos + progLen);
53
+ const program = Buffer.from(output.subarray(pushPos, pushPos + progLen));
54
54
  if (program.length < FUTURE_SEGWIT_MIN_SIZE || program.length > FUTURE_SEGWIT_MAX_SIZE)
55
55
  throw new TypeError('Invalid program length for segwit address');
56
56
  const version = opcode === opcodes.OP_0
@@ -64,7 +64,7 @@ export function toFutureOPNetAddress(output, network) {
64
64
  return bech32m.encode(network.bech32Opnet, words);
65
65
  }
66
66
  export function _toFutureSegwitAddress(output, network) {
67
- const data = output.subarray(2);
67
+ const data = Buffer.from(output.subarray(2));
68
68
  if (data.length < FUTURE_SEGWIT_MIN_SIZE || data.length > FUTURE_SEGWIT_MAX_SIZE) {
69
69
  throw new TypeError('Invalid program length for segwit address');
70
70
  }
@@ -84,7 +84,7 @@ export function fromBase58Check(address) {
84
84
  if (payload.length > 21)
85
85
  throw new TypeError(address + ' is too long');
86
86
  const version = payload.readUInt8(0);
87
- const hash = payload.subarray(1);
87
+ const hash = Buffer.from(payload.subarray(1));
88
88
  return { version, hash };
89
89
  }
90
90
  export function fromBech32(address) {
@@ -124,7 +124,7 @@ export class BufferReader {
124
124
  if (this.buffer.length < this.offset + n) {
125
125
  throw new Error('Cannot read slice out of bounds');
126
126
  }
127
- const result = this.buffer.subarray(this.offset, this.offset + n);
127
+ const result = Buffer.from(this.buffer.subarray(this.offset, this.offset + n));
128
128
  this.offset += n;
129
129
  return result;
130
130
  }
@@ -7,6 +7,7 @@ export declare const isP2WSHScript: (script: Buffer) => boolean;
7
7
  export declare const isP2SHScript: (script: Buffer) => boolean;
8
8
  export declare const isP2TR: (script: Buffer) => boolean;
9
9
  export declare const isP2OP: (script: Buffer) => boolean;
10
+ export declare const isP2A: (script: Buffer) => boolean;
10
11
  export declare function witnessStackToScriptWitness(witness: Buffer[]): Buffer;
11
12
  export interface UncompressedPublicKey {
12
13
  hybrid: Buffer;
@@ -31,6 +31,13 @@ export const isP2WSHScript = isPaymentFactory(p2wsh);
31
31
  export const isP2SHScript = isPaymentFactory(p2sh);
32
32
  export const isP2TR = isPaymentFactory(p2tr);
33
33
  export const isP2OP = isPaymentFactory(p2op);
34
+ export const isP2A = (script) => {
35
+ return (script.length === 4 &&
36
+ script[0] === 0x51 &&
37
+ script[1] === 0x02 &&
38
+ script[2] === 0x4e &&
39
+ script[3] === 0x73);
40
+ };
34
41
  export function witnessStackToScriptWitness(witness) {
35
42
  let buffer = Buffer.allocUnsafe(0);
36
43
  function writeSlice(slice) {
package/build/psbt.d.ts CHANGED
@@ -106,6 +106,7 @@ export interface PsbtOpts {
106
106
  maximumFeeRate: number;
107
107
  }
108
108
  export interface PsbtInputExtended extends PsbtInput, TransactionInput {
109
+ isPayToAnchor?: boolean;
109
110
  }
110
111
  export type PsbtOutputExtended = PsbtOutputExtendedAddress | PsbtOutputExtendedScript;
111
112
  export interface PsbtOutputExtendedAddress extends PsbtOutput {
package/build/psbt.js CHANGED
@@ -948,10 +948,10 @@ function getAllTaprootHashesForSig(inputIndex, input, inputs, cache) {
948
948
  }
949
949
  function getPrevoutTaprootKey(inputIndex, input, cache) {
950
950
  const { script } = getScriptAndAmountFromUtxo(inputIndex, input, cache);
951
- return isP2TR(script) ? script.subarray(2, 34) : null;
951
+ return isP2TR(script) ? Buffer.from(script.subarray(2, 34)) : null;
952
952
  }
953
953
  function trimTaprootSig(signature) {
954
- return signature.length === 64 ? signature : signature.subarray(0, 64);
954
+ return signature.length === 64 ? signature : Buffer.from(signature.subarray(0, 64));
955
955
  }
956
956
  function getTaprootHashesForSig(inputIndex, input, inputs, pubkey, cache, tapLeafHashToSign, allowedSighashTypes) {
957
957
  const unsignedTx = cache.__TX;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@btc-vision/bitcoin",
3
3
  "type": "module",
4
- "version": "6.4.7",
4
+ "version": "6.4.9",
5
5
  "description": "Client-side Bitcoin JavaScript library",
6
6
  "engines": {
7
7
  "node": ">=16.0.0"
package/src/address.ts CHANGED
@@ -48,7 +48,7 @@ const FUTURE_SEGWIT_VERSION_WARNING: string =
48
48
 
49
49
  export const isUnknownSegwitVersion = (output: Buffer): boolean => {
50
50
  try {
51
- const data = output.subarray(2);
51
+ const data = Buffer.from(output.subarray(2));
52
52
  if (data.length < FUTURE_SEGWIT_MIN_SIZE || data.length > FUTURE_SEGWIT_MAX_SIZE) {
53
53
  throw new TypeError('Invalid program length for segwit address');
54
54
  }
@@ -93,7 +93,7 @@ export function toFutureOPNetAddress(output: Buffer, network: Network): string {
93
93
  throw new TypeError('Unsupported push opcode in script');
94
94
  }
95
95
 
96
- const program = output.subarray(pushPos, pushPos + progLen);
96
+ const program = Buffer.from(output.subarray(pushPos, pushPos + progLen));
97
97
 
98
98
  if (program.length < FUTURE_SEGWIT_MIN_SIZE || program.length > FUTURE_SEGWIT_MAX_SIZE)
99
99
  throw new TypeError('Invalid program length for segwit address');
@@ -113,7 +113,7 @@ export function toFutureOPNetAddress(output: Buffer, network: Network): string {
113
113
  }
114
114
 
115
115
  export function _toFutureSegwitAddress(output: Buffer, network: Network): string {
116
- const data = output.subarray(2);
116
+ const data = Buffer.from(output.subarray(2));
117
117
  if (data.length < FUTURE_SEGWIT_MIN_SIZE || data.length > FUTURE_SEGWIT_MAX_SIZE) {
118
118
  throw new TypeError('Invalid program length for segwit address');
119
119
  }
@@ -141,7 +141,7 @@ export function fromBase58Check(address: string): Base58CheckResult {
141
141
  if (payload.length > 21) throw new TypeError(address + ' is too long');
142
142
 
143
143
  const version = payload.readUInt8(0);
144
- const hash = payload.subarray(1);
144
+ const hash = Buffer.from(payload.subarray(1));
145
145
 
146
146
  return { version, hash };
147
147
  }
@@ -170,7 +170,7 @@ export class BufferReader {
170
170
  throw new Error('Cannot read slice out of bounds');
171
171
  }
172
172
 
173
- const result = this.buffer.subarray(this.offset, this.offset + n);
173
+ const result = Buffer.from(this.buffer.subarray(this.offset, this.offset + n));
174
174
  this.offset += n;
175
175
  return result;
176
176
  }
@@ -33,6 +33,15 @@ export const isP2WSHScript = isPaymentFactory(p2wsh);
33
33
  export const isP2SHScript = isPaymentFactory(p2sh);
34
34
  export const isP2TR = isPaymentFactory(p2tr);
35
35
  export const isP2OP = isPaymentFactory(p2op);
36
+ export const isP2A = (script: Buffer): boolean => {
37
+ return (
38
+ script.length === 4 &&
39
+ script[0] === 0x51 && // OP_1
40
+ script[1] === 0x02 && // push 2 bytes
41
+ script[2] === 0x4e &&
42
+ script[3] === 0x73
43
+ );
44
+ };
36
45
 
37
46
  /**
38
47
  * Converts a witness stack to a script witness.
package/src/psbt.ts CHANGED
@@ -1134,7 +1134,9 @@ export interface PsbtOpts {
1134
1134
  maximumFeeRate: number;
1135
1135
  }
1136
1136
 
1137
- export interface PsbtInputExtended extends PsbtInput, TransactionInput {}
1137
+ export interface PsbtInputExtended extends PsbtInput, TransactionInput {
1138
+ isPayToAnchor?: boolean;
1139
+ }
1138
1140
 
1139
1141
  export type PsbtOutputExtended = PsbtOutputExtendedAddress | PsbtOutputExtendedScript;
1140
1142
 
@@ -1710,11 +1712,11 @@ function getPrevoutTaprootKey(
1710
1712
  cache: PsbtCache,
1711
1713
  ): Buffer | null {
1712
1714
  const { script } = getScriptAndAmountFromUtxo(inputIndex, input, cache);
1713
- return isP2TR(script) ? script.subarray(2, 34) : null;
1715
+ return isP2TR(script) ? Buffer.from(script.subarray(2, 34)) : null;
1714
1716
  }
1715
1717
 
1716
1718
  function trimTaprootSig(signature: Buffer): Buffer {
1717
- return signature.length === 64 ? signature : signature.subarray(0, 64);
1719
+ return signature.length === 64 ? signature : Buffer.from(signature.subarray(0, 64));
1718
1720
  }
1719
1721
 
1720
1722
  function getTaprootHashesForSig(