@btc-vision/bitcoin 6.3.6 → 6.4.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.
Files changed (71) hide show
  1. package/.mocharc.json +13 -0
  2. package/browser/address.d.ts +1 -1
  3. package/browser/index.js +1 -1
  4. package/browser/index.js.LICENSE.txt +3 -3
  5. package/browser/networks.d.ts +1 -0
  6. package/build/address.d.ts +1 -1
  7. package/build/address.js +12 -5
  8. package/build/block.js +2 -2
  9. package/build/bufferutils.js +5 -5
  10. package/build/networks.d.ts +1 -0
  11. package/build/networks.js +11 -0
  12. package/build/psbt/psbtutils.js +2 -2
  13. package/build/psbt.js +3 -7
  14. package/package.json +26 -26
  15. package/src/address.ts +20 -6
  16. package/src/block.ts +233 -233
  17. package/src/bufferutils.ts +188 -180
  18. package/src/index.ts +86 -86
  19. package/src/networks.ts +12 -0
  20. package/src/psbt/bip371.ts +441 -441
  21. package/src/psbt/psbtutils.ts +4 -3
  22. package/src/psbt.ts +2187 -2187
  23. package/test/address.spec.ts +155 -177
  24. package/test/bitcoin.core.spec.ts +212 -234
  25. package/test/block.spec.ts +171 -194
  26. package/test/bufferutils.spec.ts +450 -513
  27. package/test/crypto.spec.ts +49 -55
  28. package/test/fixtures/address.json +3 -3
  29. package/test/integration/addresses.spec.ts +142 -154
  30. package/test/integration/bip32.spec.ts +130 -151
  31. package/test/integration/blocks.spec.ts +28 -28
  32. package/test/integration/cltv.spec.ts +241 -283
  33. package/test/integration/csv.spec.ts +452 -527
  34. package/test/integration/payments.spec.ts +110 -135
  35. package/test/integration/taproot.spec.ts +663 -707
  36. package/test/integration/transactions.spec.ts +668 -769
  37. package/test/payments.spec.ts +114 -125
  38. package/test/payments.utils.ts +165 -208
  39. package/test/psbt.spec.ts +1285 -1414
  40. package/test/script.spec.ts +186 -210
  41. package/test/script_number.spec.ts +26 -29
  42. package/test/script_signature.spec.ts +66 -66
  43. package/test/transaction.spec.ts +337 -387
  44. package/test/ts-node-register.js +7 -5
  45. package/test/tsconfig.json +4 -1
  46. package/test/types.spec.ts +53 -58
  47. package/.nyc_output/6368a5b2-daa5-4821-8ed0-b742d6fc7eab.json +0 -1
  48. package/.nyc_output/processinfo/6368a5b2-daa5-4821-8ed0-b742d6fc7eab.json +0 -1
  49. package/.nyc_output/processinfo/index.json +0 -1
  50. package/test/address.spec.js +0 -124
  51. package/test/bitcoin.core.spec.js +0 -170
  52. package/test/block.spec.js +0 -141
  53. package/test/bufferutils.spec.js +0 -427
  54. package/test/crypto.spec.js +0 -41
  55. package/test/integration/_regtest.js +0 -7
  56. package/test/integration/addresses.spec.js +0 -116
  57. package/test/integration/bip32.spec.js +0 -85
  58. package/test/integration/blocks.spec.js +0 -26
  59. package/test/integration/cltv.spec.js +0 -199
  60. package/test/integration/csv.spec.js +0 -362
  61. package/test/integration/payments.spec.js +0 -98
  62. package/test/integration/taproot.spec.js +0 -532
  63. package/test/integration/transactions.spec.js +0 -561
  64. package/test/payments.spec.js +0 -97
  65. package/test/payments.utils.js +0 -190
  66. package/test/psbt.spec.js +0 -1044
  67. package/test/script.spec.js +0 -151
  68. package/test/script_number.spec.js +0 -24
  69. package/test/script_signature.spec.js +0 -52
  70. package/test/transaction.spec.js +0 -269
  71. package/test/types.spec.js +0 -46
@@ -7,8 +7,8 @@
7
7
 
8
8
  /*! ieee754. BSD-3-Clause License. Feross Aboukhadijeh <https://feross.org/opensource> */
9
9
 
10
- /*! noble-secp256k1 - MIT License (c) 2019 Paul Miller (paulmillr.com) */
10
+ /*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */
11
11
 
12
- /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */
12
+ /*! noble-secp256k1 - MIT License (c) 2019 Paul Miller (paulmillr.com) */
13
13
 
14
- /*! safe-buffer. MIT License. Feross Aboukhadijeh <https://feross.org/opensource> */
14
+ /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/babel/babel/blob/main/packages/babel-helpers/LICENSE */
@@ -7,6 +7,7 @@ export interface Network {
7
7
  bip32: Bip32;
8
8
  messagePrefix: string;
9
9
  bech32: string;
10
+ bech32Opnet?: string;
10
11
  pubKeyHash: number;
11
12
  scriptHash: number;
12
13
  }
@@ -11,6 +11,6 @@ export interface Bech32Result {
11
11
  export declare function fromBase58Check(address: string): Base58CheckResult;
12
12
  export declare function fromBech32(address: string): Bech32Result;
13
13
  export declare function toBase58Check(hash: Buffer, version: number): string;
14
- export declare function toBech32(data: Buffer, version: number, prefix: string): string;
14
+ export declare function toBech32(data: Buffer, version: number, prefix: string, prefixOpnet?: string): string;
15
15
  export declare function fromOutputScript(output: Buffer, network?: Network): string;
16
16
  export declare function toOutputScript(address: string, network?: Network): Buffer;
package/build/address.js CHANGED
@@ -7,6 +7,7 @@ import { Hash160bit, tuple, typeforce, UInt8 } from './types.js';
7
7
  const FUTURE_SEGWIT_MAX_SIZE = 40;
8
8
  const FUTURE_SEGWIT_MIN_SIZE = 2;
9
9
  const FUTURE_SEGWIT_MAX_VERSION = 16;
10
+ const FUTURE_OPNET_VERSION = 16;
10
11
  const FUTURE_SEGWIT_MIN_VERSION = 2;
11
12
  const FUTURE_SEGWIT_VERSION_DIFF = 0x50;
12
13
  const FUTURE_SEGWIT_VERSION_WARNING = 'WARNING: Sending to a future segwit version address can lead to loss of funds. ' +
@@ -22,8 +23,7 @@ function _toFutureSegwitAddress(output, network) {
22
23
  throw new TypeError('Invalid version for segwit address');
23
24
  if (output[1] !== data.length)
24
25
  throw new TypeError('Invalid script for segwit address');
25
- console.warn(FUTURE_SEGWIT_VERSION_WARNING);
26
- return toBech32(data, version, network.bech32);
26
+ return toBech32(data, version, network.bech32, network.bech32Opnet);
27
27
  }
28
28
  export function fromBase58Check(address) {
29
29
  const payload = Buffer.from(bs58check.default.decode(address));
@@ -67,9 +67,12 @@ export function toBase58Check(hash, version) {
67
67
  hash.copy(payload, 1);
68
68
  return bs58check.default.encode(payload);
69
69
  }
70
- export function toBech32(data, version, prefix) {
70
+ export function toBech32(data, version, prefix, prefixOpnet) {
71
71
  const words = bech32.toWords(data);
72
72
  words.unshift(version);
73
+ if (version === FUTURE_OPNET_VERSION && prefixOpnet) {
74
+ return bech32m.encode(prefixOpnet, words);
75
+ }
73
76
  return version === 0 ? bech32.encode(prefix, words) : bech32m.encode(prefix, words);
74
77
  }
75
78
  export function fromOutputScript(output, network) {
@@ -120,7 +123,9 @@ export function toOutputScript(address, network) {
120
123
  }
121
124
  catch (e) { }
122
125
  if (decodeBech32) {
123
- if (decodeBech32.prefix !== network.bech32)
126
+ if (decodeBech32.prefix !== network.bech32 &&
127
+ network.bech32Opnet &&
128
+ decodeBech32.prefix !== network.bech32Opnet)
124
129
  throw new Error(address + ' has an invalid prefix');
125
130
  if (decodeBech32.version === 0) {
126
131
  if (decodeBech32.data.length === 20)
@@ -136,7 +141,9 @@ export function toOutputScript(address, network) {
136
141
  decodeBech32.version <= FUTURE_SEGWIT_MAX_VERSION &&
137
142
  decodeBech32.data.length >= FUTURE_SEGWIT_MIN_SIZE &&
138
143
  decodeBech32.data.length <= FUTURE_SEGWIT_MAX_SIZE) {
139
- console.warn(FUTURE_SEGWIT_VERSION_WARNING);
144
+ if (decodeBech32.version !== FUTURE_OPNET_VERSION) {
145
+ console.warn(FUTURE_SEGWIT_VERSION_WARNING);
146
+ }
140
147
  return bscript.compile([
141
148
  decodeBech32.version + FUTURE_SEGWIT_VERSION_DIFF,
142
149
  decodeBech32.data,
package/build/block.js CHANGED
@@ -123,8 +123,8 @@ export class Block {
123
123
  bufferWriter.writeUInt32(this.nonce);
124
124
  if (headersOnly || !this.transactions)
125
125
  return buffer;
126
- varuint.encode(this.transactions.length, buffer, bufferWriter.offset);
127
- bufferWriter.offset += varuint.encode.bytes;
126
+ const encoded = varuint.encode(this.transactions.length, buffer, bufferWriter.offset);
127
+ bufferWriter.offset += encoded.bytes;
128
128
  this.transactions.forEach((tx) => {
129
129
  const txSize = tx.byteLength();
130
130
  tx.toBuffer(buffer, bufferWriter.offset);
@@ -65,8 +65,8 @@ export class BufferWriter {
65
65
  this.offset = writeUInt64LE(this.buffer, i, this.offset);
66
66
  }
67
67
  writeVarInt(i) {
68
- varuint.encode(i, this.buffer, this.offset);
69
- this.offset += varuint.encode.bytes;
68
+ const encode = varuint.encode(i, this.buffer, this.offset);
69
+ this.offset += encode.bytes;
70
70
  }
71
71
  writeSlice(slice) {
72
72
  if (this.buffer.length < this.offset + slice.length) {
@@ -117,14 +117,14 @@ export class BufferReader {
117
117
  }
118
118
  readVarInt() {
119
119
  const vi = varuint.decode(this.buffer, this.offset);
120
- this.offset += varuint.decode.bytes;
121
- return vi;
120
+ this.offset += vi.bytes;
121
+ return vi.numberValue || 0;
122
122
  }
123
123
  readSlice(n) {
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.slice(this.offset, this.offset + n);
127
+ const result = this.buffer.subarray(this.offset, this.offset + n);
128
128
  this.offset += n;
129
129
  return result;
130
130
  }
@@ -7,6 +7,7 @@ export interface Network {
7
7
  bip32: Bip32;
8
8
  messagePrefix: string;
9
9
  bech32: string;
10
+ bech32Opnet?: string;
10
11
  pubKeyHash: number;
11
12
  scriptHash: number;
12
13
  }
package/build/networks.js CHANGED
@@ -1,6 +1,7 @@
1
1
  export const bitcoin = {
2
2
  messagePrefix: '\x18Bitcoin Signed Message:\n',
3
3
  bech32: 'bc',
4
+ bech32Opnet: 'opnet',
4
5
  bip32: {
5
6
  public: 0x0488b21e,
6
7
  private: 0x0488ade4,
@@ -12,6 +13,7 @@ export const bitcoin = {
12
13
  export const regtest = {
13
14
  messagePrefix: '\x18Bitcoin Signed Message:\n',
14
15
  bech32: 'bcrt',
16
+ bech32Opnet: 'opreg',
15
17
  bip32: {
16
18
  public: 0x043587cf,
17
19
  private: 0x04358394,
@@ -23,6 +25,7 @@ export const regtest = {
23
25
  export const testnet = {
24
26
  messagePrefix: '\x18Bitcoin Signed Message:\n',
25
27
  bech32: 'tb',
28
+ bech32Opnet: 'optest',
26
29
  bip32: {
27
30
  public: 0x043587cf,
28
31
  private: 0x04358394,
@@ -34,6 +37,7 @@ export const testnet = {
34
37
  export const dogecoin = {
35
38
  messagePrefix: '\x19Dogecoin Signed Message:\n',
36
39
  bech32: '',
40
+ bech32Opnet: '',
37
41
  bip32: {
38
42
  public: 0x02facafd,
39
43
  private: 0x02fac398,
@@ -45,6 +49,7 @@ export const dogecoin = {
45
49
  export const dogecoinTestnet = {
46
50
  messagePrefix: '\x19Dogecoin Signed Message:\n',
47
51
  bech32: '',
52
+ bech32Opnet: '',
48
53
  bip32: {
49
54
  public: 0x0432a9a8,
50
55
  private: 0x0432a243,
@@ -56,6 +61,7 @@ export const dogecoinTestnet = {
56
61
  export const litecoin = {
57
62
  messagePrefix: '\x19Litecoin Signed Message:\n',
58
63
  bech32: 'ltc',
64
+ bech32Opnet: 'opltc',
59
65
  bip32: {
60
66
  public: 0x019da462,
61
67
  private: 0x019d9cfe,
@@ -67,6 +73,7 @@ export const litecoin = {
67
73
  export const litecoinTestnet = {
68
74
  messagePrefix: '\x19Litecoin Signed Message:\n',
69
75
  bech32: 'tltc',
76
+ bech32Opnet: 'opltct',
70
77
  bip32: {
71
78
  public: 0x0436ef7d,
72
79
  private: 0x0436f6e1,
@@ -78,6 +85,7 @@ export const litecoinTestnet = {
78
85
  export const bitcoinCash = {
79
86
  messagePrefix: '\x18Bitcoin Signed Message:\n',
80
87
  bech32: 'bitcoincash',
88
+ bech32Opnet: 'opbch',
81
89
  bip32: {
82
90
  public: 0x0488b21e,
83
91
  private: 0x0488ade4,
@@ -89,6 +97,7 @@ export const bitcoinCash = {
89
97
  export const bitcoinCashTestnet = {
90
98
  messagePrefix: '\x18Bitcoin Signed Message:\n',
91
99
  bech32: 'bchtest',
100
+ bech32Opnet: 'opbchtest',
92
101
  bip32: {
93
102
  public: 0x043587cf,
94
103
  private: 0x04358394,
@@ -100,6 +109,7 @@ export const bitcoinCashTestnet = {
100
109
  export const dash = {
101
110
  messagePrefix: '\x19DarkCoin Signed Message:\n',
102
111
  bech32: '',
112
+ bech32Opnet: '',
103
113
  bip32: {
104
114
  public: 0x02fe52cc,
105
115
  private: 0x02fe52f8,
@@ -111,6 +121,7 @@ export const dash = {
111
121
  export const dashTestnet = {
112
122
  messagePrefix: '\x19DarkCoin Signed Message:\n',
113
123
  bech32: '',
124
+ bech32Opnet: '',
114
125
  bip32: {
115
126
  public: 0x3a8061a0,
116
127
  private: 0x3a805837,
@@ -56,8 +56,8 @@ export function decompressPublicKey(realPubKey) {
56
56
  return;
57
57
  }
58
58
  if (![33, 65].includes(realPubKey.length)) {
59
- console.trace(`Unsupported key length=${realPubKey.length}. Must be 33 (compressed) or 65 (uncompressed).`);
60
- throw new Error(`Unsupported key length=${realPubKey.length}. Must be 33 (compressed) or 65 (uncompressed).`);
59
+ console.warn(`Unsupported key length=${realPubKey.length}. Must be 33 (compressed) or 65 (uncompressed).`);
60
+ return;
61
61
  }
62
62
  let point;
63
63
  try {
package/build/psbt.js CHANGED
@@ -3,7 +3,6 @@ import * as varuint from 'bip174/src/lib/converter/varint.js';
3
3
  import { checkForInput, checkForOutput } from 'bip174/src/lib/utils.js';
4
4
  import { fromOutputScript, toOutputScript } from './address.js';
5
5
  import { cloneBuffer, reverseBuffer } from './bufferutils.js';
6
- import { hookSigner } from './hooks/HookedSigner.js';
7
6
  import { payments } from './index.js';
8
7
  import { bitcoin as btcNetwork } from './networks.js';
9
8
  import { tapleafHash } from './payments/bip341.js';
@@ -92,8 +91,7 @@ export class Psbt {
92
91
  return this;
93
92
  }
94
93
  clone() {
95
- const res = Psbt.fromBuffer(this.data.toBuffer(), JSON.parse(JSON.stringify(this.opts)));
96
- return res;
94
+ return Psbt.fromBuffer(this.data.toBuffer(), JSON.parse(JSON.stringify(this.opts)));
97
95
  }
98
96
  setMaximumFeeRate(satoshiPerByte) {
99
97
  check32Bit(satoshiPerByte);
@@ -555,7 +553,6 @@ export class Psbt {
555
553
  return validationResultCount > 0;
556
554
  }
557
555
  _signInput(inputIndex, keyPair, sighashTypes = [Transaction.SIGHASH_ALL]) {
558
- hookSigner(keyPair);
559
556
  const { hash, sighashType } = getHashAndSighashType(this.data.inputs, inputIndex, keyPair.publicKey, this.__CACHE, sighashTypes);
560
557
  const partialSig = [
561
558
  {
@@ -567,7 +564,6 @@ export class Psbt {
567
564
  return this;
568
565
  }
569
566
  _signTaprootInput(inputIndex, input, keyPair, tapLeafHashToSign, allowedSighashTypes = [Transaction.SIGHASH_DEFAULT]) {
570
- hookSigner(keyPair);
571
567
  const hashesForSig = this.checkTaprootHashesForSig(inputIndex, input, keyPair, tapLeafHashToSign, allowedSighashTypes);
572
568
  const tapKeySig = hashesForSig
573
569
  .filter((h) => !h.leafHash)
@@ -588,7 +584,6 @@ export class Psbt {
588
584
  return this;
589
585
  }
590
586
  _signInputAsync(inputIndex, keyPair, sighashTypes = [Transaction.SIGHASH_ALL]) {
591
- hookSigner(keyPair);
592
587
  const { hash, sighashType } = getHashAndSighashType(this.data.inputs, inputIndex, keyPair.publicKey, this.__CACHE, sighashTypes);
593
588
  return Promise.resolve(keyPair.sign(hash)).then((signature) => {
594
589
  const partialSig = [
@@ -601,7 +596,6 @@ export class Psbt {
601
596
  });
602
597
  }
603
598
  async _signTaprootInputAsync(inputIndex, input, keyPair, tapLeafHash, sighashTypes = [Transaction.SIGHASH_DEFAULT]) {
604
- hookSigner(keyPair);
605
599
  const hashesForSig = this.checkTaprootHashesForSig(inputIndex, input, keyPair, tapLeafHash, sighashTypes);
606
600
  const signaturePromises = [];
607
601
  const tapKeyHash = hashesForSig.filter((h) => !h.leafHash)[0];
@@ -684,6 +678,8 @@ function canFinalize(input, script, scriptType) {
684
678
  case 'multisig':
685
679
  const p2ms = payments.p2ms({ output: script });
686
680
  return hasSigs(p2ms.m, input.partialSig, p2ms.pubkeys);
681
+ case 'nonstandard':
682
+ return true;
687
683
  default:
688
684
  return false;
689
685
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@btc-vision/bitcoin",
3
3
  "type": "module",
4
- "version": "6.3.6",
4
+ "version": "6.4.0",
5
5
  "description": "Client-side Bitcoin JavaScript library",
6
6
  "engines": {
7
7
  "node": ">=16.0.0"
@@ -55,7 +55,7 @@
55
55
  "audit": "better-npm-audit audit -l high",
56
56
  "build:tests": "npm run clean:jstests && tsc -p ./test/tsconfig.json",
57
57
  "clean": "rimraf build",
58
- "clean:jstests": "rimraf 'test/**/!(ts-node-register)*.js'",
58
+ "clean:jstests": "rimraf --glob \"test/**/!(ts-node-register).js\"",
59
59
  "coverage-report": "npm run build && npm run nobuild:coverage-report",
60
60
  "coverage-html": "npm run build && npm run nobuild:coverage-html",
61
61
  "coverage": "npm run build && npm run nobuild:coverage",
@@ -65,29 +65,29 @@
65
65
  "format:ci": "npm run prettier -- --check && npm run prettierjs -- --check",
66
66
  "gitdiff:ci": "npm run build && git diff --exit-code",
67
67
  "integration": "npm run build && npm run nobuild:integration",
68
- "lint": "eslint ts_src/**",
68
+ "lint": "eslint src/**",
69
69
  "lint:tests": "eslint test/**/*.spec.ts",
70
- "mocha:ts": "mocha --recursive --require test/ts-node-register",
70
+ "mocha:ts": "cross-env TS_NODE_PROJECT=test/tsconfig.json mocha -n loader=ts-node/esm -n experimental-specifier-resolution=node --extension ts --timeout 10000 --recursive \"test/**/*.spec.ts\"",
71
71
  "nobuild:coverage-report": "nyc report --reporter=lcov",
72
72
  "nobuild:coverage-html": "nyc report --reporter=html",
73
73
  "nobuild:coverage": "npm run build:tests && nyc --check-coverage --branches 85 --functions 90 --lines 90 mocha && npm run clean:jstests",
74
74
  "nobuild:integration": "npm run mocha:ts -- --timeout 50000 'test/integration/*.ts'",
75
75
  "nobuild:unit": "npm run mocha:ts -- 'test/*.ts'",
76
- "prettier": "prettier \"ts_src/**/*.ts\" \"test/**/*.ts\" --ignore-path ./.prettierignore",
76
+ "prettier": "prettier \"src/**/*.ts\" \"test/**/*.ts\" --ignore-path ./.prettierignore",
77
77
  "test": "npm run build && npm run format:ci && npm run lint && npm run nobuild:coverage",
78
78
  "unit": "npm run build && npm run nobuild:unit"
79
79
  },
80
80
  "devDependencies": {
81
- "@babel/core": "^7.26.0",
81
+ "@babel/core": "^7.27.1",
82
82
  "@babel/plugin-proposal-class-properties": "^7.18.6",
83
- "@babel/plugin-transform-runtime": "^7.25.9",
84
- "@babel/preset-env": "^7.26.0",
85
- "@babel/preset-flow": "^7.25.9",
86
- "@babel/preset-react": "^7.26.3",
87
- "@babel/preset-typescript": "^7.26.0",
83
+ "@babel/plugin-transform-runtime": "^7.27.1",
84
+ "@babel/preset-env": "^7.27.2",
85
+ "@babel/preset-flow": "^7.27.1",
86
+ "@babel/preset-react": "^7.27.1",
87
+ "@babel/preset-typescript": "^7.27.1",
88
88
  "@types/bs58check": "^2.1.2",
89
89
  "@types/mocha": "^10.0.10",
90
- "@types/node": "^20.17.10",
90
+ "@types/node": "^22.15.21",
91
91
  "@types/proxyquire": "^1.3.31",
92
92
  "@types/randombytes": "^2.0.3",
93
93
  "better-npm-audit": "^3.11.0",
@@ -97,17 +97,17 @@
97
97
  "bs58": "^6.0.0",
98
98
  "dhttp": "^3.0.3",
99
99
  "ecpair": "^2.0.1",
100
- "eslint": "^9.17.0",
100
+ "eslint": "^9.27.0",
101
101
  "gulp": "^5.0.0",
102
102
  "gulp-cached": "^1.1.1",
103
103
  "gulp-typescript": "^6.0.0-alpha.1",
104
104
  "hoodwink": "^2.0.0",
105
105
  "https-browserify": "^1.0.0",
106
106
  "minimaldata": "^1.0.2",
107
- "mocha": "^11.0.1",
107
+ "mocha": "^11.5.0",
108
108
  "nyc": "^17.1.0",
109
109
  "os-browserify": "^0.3.0",
110
- "prettier": "^3.4.2",
110
+ "prettier": "^3.5.3",
111
111
  "proxyquire": "^2.1.3",
112
112
  "randombytes": "^2.1.0",
113
113
  "regtest-client": "0.2.1",
@@ -115,23 +115,23 @@
115
115
  "stream-browserify": "^3.0.0",
116
116
  "stream-http": "^3.2.0",
117
117
  "tiny-secp256k1": "^2.2.3",
118
- "ts-loader": "^9.5.1",
118
+ "ts-loader": "^9.5.2",
119
119
  "ts-node": "^10.9.2",
120
- "typedoc": "^0.27.6",
121
- "typescript": "^5.7.2",
122
- "typescript-eslint": "^8.19.0",
123
- "webpack": "^5.97.1",
120
+ "typedoc": "^0.28.5",
121
+ "typescript": "^5.8.3",
122
+ "typescript-eslint": "^8.32.1",
123
+ "webpack": "^5.99.9",
124
124
  "webpack-cli": "^6.0.1"
125
125
  },
126
126
  "dependencies": {
127
127
  "@babel/plugin-proposal-object-rest-spread": "^7.20.7",
128
128
  "@btc-vision/logger": "^1.0.6",
129
- "@eslint/js": "^9.17.0",
130
- "@noble/hashes": "^1.6.1",
131
- "@noble/secp256k1": "^2.1.0",
129
+ "@eslint/js": "^9.27.0",
130
+ "@noble/hashes": "^1.8.0",
131
+ "@noble/secp256k1": "^2.2.3",
132
132
  "assert": "^2.1.0",
133
- "babel-loader": "^9.2.1",
134
- "babel-plugin-transform-import-meta": "^2.2.1",
133
+ "babel-loader": "^10.0.0",
134
+ "babel-plugin-transform-import-meta": "^2.3.2",
135
135
  "babel-preset-react": "^6.24.1",
136
136
  "babelify": "^10.0.0",
137
137
  "bip32": "^4.0.0",
@@ -145,6 +145,6 @@
145
145
  "gulp-logger-new": "^1.0.1",
146
146
  "process": "^0.11.10",
147
147
  "typeforce": "^1.18.0",
148
- "varuint-bitcoin": "^1.1.2"
148
+ "varuint-bitcoin": "^2.0.0"
149
149
  }
150
150
  }
package/src/address.ts CHANGED
@@ -36,6 +36,7 @@ export interface Bech32Result {
36
36
  const FUTURE_SEGWIT_MAX_SIZE: number = 40;
37
37
  const FUTURE_SEGWIT_MIN_SIZE: number = 2;
38
38
  const FUTURE_SEGWIT_MAX_VERSION: number = 16;
39
+ const FUTURE_OPNET_VERSION: number = 16;
39
40
  const FUTURE_SEGWIT_MIN_VERSION: number = 2;
40
41
  const FUTURE_SEGWIT_VERSION_DIFF: number = 0x50;
41
42
  const FUTURE_SEGWIT_VERSION_WARNING: string =
@@ -57,9 +58,7 @@ function _toFutureSegwitAddress(output: Buffer, network: Network): string {
57
58
 
58
59
  if (output[1] !== data.length) throw new TypeError('Invalid script for segwit address');
59
60
 
60
- console.warn(FUTURE_SEGWIT_VERSION_WARNING);
61
-
62
- return toBech32(data, version, network.bech32);
61
+ return toBech32(data, version, network.bech32, network.bech32Opnet);
63
62
  }
64
63
 
65
64
  /**
@@ -122,10 +121,19 @@ export function toBase58Check(hash: Buffer, version: number): string {
122
121
  /**
123
122
  * encode address hash to bech32 address with version and prefix
124
123
  */
125
- export function toBech32(data: Buffer, version: number, prefix: string): string {
124
+ export function toBech32(
125
+ data: Buffer,
126
+ version: number,
127
+ prefix: string,
128
+ prefixOpnet?: string,
129
+ ): string {
126
130
  const words = bech32.toWords(data);
127
131
  words.unshift(version);
128
132
 
133
+ if (version === FUTURE_OPNET_VERSION && prefixOpnet) {
134
+ return bech32m.encode(prefixOpnet, words);
135
+ }
136
+
129
137
  return version === 0 ? bech32.encode(prefix, words) : bech32m.encode(prefix, words);
130
138
  }
131
139
 
@@ -181,7 +189,11 @@ export function toOutputScript(address: string, network?: Network): Buffer {
181
189
  } catch (e) {}
182
190
 
183
191
  if (decodeBech32) {
184
- if (decodeBech32.prefix !== network.bech32)
192
+ if (
193
+ decodeBech32.prefix !== network.bech32 &&
194
+ network.bech32Opnet &&
195
+ decodeBech32.prefix !== network.bech32Opnet
196
+ )
185
197
  throw new Error(address + ' has an invalid prefix');
186
198
  if (decodeBech32.version === 0) {
187
199
  if (decodeBech32.data.length === 20)
@@ -197,7 +209,9 @@ export function toOutputScript(address: string, network?: Network): Buffer {
197
209
  decodeBech32.data.length >= FUTURE_SEGWIT_MIN_SIZE &&
198
210
  decodeBech32.data.length <= FUTURE_SEGWIT_MAX_SIZE
199
211
  ) {
200
- console.warn(FUTURE_SEGWIT_VERSION_WARNING);
212
+ if (decodeBech32.version !== FUTURE_OPNET_VERSION) {
213
+ console.warn(FUTURE_SEGWIT_VERSION_WARNING);
214
+ }
201
215
 
202
216
  return bscript.compile([
203
217
  decodeBech32.version + FUTURE_SEGWIT_VERSION_DIFF,