@btc-vision/transaction 1.1.17 → 1.2.1

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 (82) hide show
  1. package/browser/_version.d.ts +1 -1
  2. package/browser/crypto/crypto-browser.d.ts +2 -2
  3. package/browser/index.js +1 -1
  4. package/browser/index.js.LICENSE.txt +2 -0
  5. package/browser/keypair/Address.d.ts +8 -0
  6. package/browser/keypair/Secp256k1PointDeriver.d.ts +16 -0
  7. package/browser/opnet.d.ts +2 -0
  8. package/browser/signer/SignerUtils.d.ts +0 -1
  9. package/browser/transaction/ContractAddress.d.ts +6 -0
  10. package/browser/transaction/builders/CustomScriptTransaction.d.ts +1 -1
  11. package/browser/transaction/builders/InteractionTransaction.d.ts +1 -1
  12. package/browser/transaction/builders/MultiSignTransaction.d.ts +3 -4
  13. package/browser/transaction/builders/SharedInteractionTransaction.d.ts +2 -3
  14. package/browser/verification/TapscriptVerificator.d.ts +1 -2
  15. package/build/_version.d.ts +1 -1
  16. package/build/_version.js +1 -1
  17. package/build/buffer/BinaryReader.js +2 -2
  18. package/build/buffer/BinaryWriter.js +1 -1
  19. package/build/generators/AddressGenerator.js +1 -2
  20. package/build/generators/Generator.js +1 -2
  21. package/build/generators/builders/MultiSignGenerator.js +1 -2
  22. package/build/keypair/Address.d.ts +8 -0
  23. package/build/keypair/Address.js +67 -7
  24. package/build/keypair/AddressVerificator.js +5 -2
  25. package/build/keypair/EcKeyPair.js +3 -4
  26. package/build/keypair/MessageSigner.js +1 -2
  27. package/build/keypair/Secp256k1PointDeriver.d.ts +16 -0
  28. package/build/keypair/Secp256k1PointDeriver.js +80 -0
  29. package/build/keypair/Wallet.js +1 -2
  30. package/build/opnet.d.ts +2 -0
  31. package/build/opnet.js +2 -0
  32. package/build/signer/SignerUtils.d.ts +0 -1
  33. package/build/signer/SignerUtils.js +1 -17
  34. package/build/signer/TweakedSigner.js +1 -3
  35. package/build/transaction/ContractAddress.d.ts +6 -0
  36. package/build/transaction/ContractAddress.js +12 -0
  37. package/build/transaction/browser/extensions/UnisatSigner.js +1 -2
  38. package/build/transaction/browser/extensions/XverseSigner.js +1 -2
  39. package/build/transaction/builders/CustomScriptTransaction.d.ts +1 -1
  40. package/build/transaction/builders/CustomScriptTransaction.js +1 -2
  41. package/build/transaction/builders/DeploymentTransaction.js +2 -2
  42. package/build/transaction/builders/FundingTransaction.js +2 -2
  43. package/build/transaction/builders/InteractionTransaction.d.ts +1 -1
  44. package/build/transaction/builders/MultiSignTransaction.d.ts +3 -4
  45. package/build/transaction/builders/MultiSignTransaction.js +1 -2
  46. package/build/transaction/builders/SharedInteractionTransaction.d.ts +2 -3
  47. package/build/transaction/builders/SharedInteractionTransaction.js +1 -2
  48. package/build/transaction/builders/TransactionBuilder.js +11 -2
  49. package/build/transaction/shared/TweakedTransaction.js +1 -4
  50. package/build/utils/BufferHelper.js +1 -1
  51. package/build/verification/TapscriptVerificator.d.ts +1 -2
  52. package/build/verification/TapscriptVerificator.js +1 -2
  53. package/package.json +9 -9
  54. package/src/_version.ts +1 -1
  55. package/src/buffer/BinaryReader.ts +2 -2
  56. package/src/buffer/BinaryWriter.ts +1 -1
  57. package/src/generators/AddressGenerator.ts +1 -2
  58. package/src/generators/Generator.ts +1 -2
  59. package/src/generators/builders/MultiSignGenerator.ts +1 -2
  60. package/src/keypair/Address.ts +91 -10
  61. package/src/keypair/AddressVerificator.ts +6 -2
  62. package/src/keypair/EcKeyPair.ts +14 -5
  63. package/src/keypair/MessageSigner.ts +1 -2
  64. package/src/keypair/Secp256k1PointDeriver.ts +170 -0
  65. package/src/keypair/Wallet.ts +1 -2
  66. package/src/opnet.ts +2 -0
  67. package/src/signer/SignerUtils.ts +7 -19
  68. package/src/signer/TweakedSigner.ts +1 -3
  69. package/src/transaction/ContractAddress.ts +13 -0
  70. package/src/transaction/TransactionFactory.ts +4 -5
  71. package/src/transaction/browser/extensions/UnisatSigner.ts +1 -1
  72. package/src/transaction/browser/extensions/XverseSigner.ts +1 -2
  73. package/src/transaction/builders/CustomScriptTransaction.ts +10 -3
  74. package/src/transaction/builders/DeploymentTransaction.ts +13 -3
  75. package/src/transaction/builders/FundingTransaction.ts +2 -2
  76. package/src/transaction/builders/InteractionTransaction.ts +1 -1
  77. package/src/transaction/builders/MultiSignTransaction.ts +2 -2
  78. package/src/transaction/builders/SharedInteractionTransaction.ts +1 -3
  79. package/src/transaction/builders/TransactionBuilder.ts +11 -1
  80. package/src/transaction/shared/TweakedTransaction.ts +9 -93
  81. package/src/utils/BufferHelper.ts +1 -1
  82. package/src/verification/TapscriptVerificator.ts +9 -3
@@ -1,13 +1,13 @@
1
1
  import { TransactionType } from '../enums/TransactionType.js';
2
- import { crypto as bitCrypto } from '@btc-vision/bitcoin';
2
+ import { crypto as bitCrypto, toXOnly, } from '@btc-vision/bitcoin';
3
3
  import { TransactionBuilder } from './TransactionBuilder.js';
4
4
  import { DeploymentGenerator } from '../../generators/builders/DeploymentGenerator.js';
5
- import { toXOnly } from '@btc-vision/bitcoin/src/psbt/bip371.js';
6
5
  import { EcKeyPair } from '../../keypair/EcKeyPair.js';
7
6
  import { BitcoinUtils } from '../../utils/BitcoinUtils.js';
8
7
  import { Compressor } from '../../bytecode/Compressor.js';
9
8
  import { SharedInteractionTransaction } from './SharedInteractionTransaction.js';
10
9
  import { Address } from '../../keypair/Address.js';
10
+ const p = 0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2fn;
11
11
  export class DeploymentTransaction extends TransactionBuilder {
12
12
  constructor(parameters) {
13
13
  super(parameters);
@@ -18,13 +18,13 @@ export class FundingTransaction extends TransactionBuilder {
18
18
  this.splitInputs(this.amount);
19
19
  }
20
20
  else if (this.isPubKeyDestination) {
21
- const p2pkScript = script.compile([
21
+ const pubKeyScript = script.compile([
22
22
  Buffer.from(this.to.replace('0x', ''), 'hex'),
23
23
  opcodes.OP_CHECKSIG,
24
24
  ]);
25
25
  this.addOutput({
26
26
  value: Number(this.amount),
27
- script: p2pkScript,
27
+ script: pubKeyScript,
28
28
  });
29
29
  }
30
30
  else {
@@ -1,4 +1,4 @@
1
- import { Taptree } from '@btc-vision/bitcoin/src/types.js';
1
+ import { Taptree } from '@btc-vision/bitcoin';
2
2
  import { TransactionType } from '../enums/TransactionType.js';
3
3
  import { TapLeafScript } from '../interfaces/Tap.js';
4
4
  import { IInteractionParameters } from '../interfaces/ITransactionParameters.js';
@@ -1,5 +1,4 @@
1
- import { Payment, Psbt, PsbtInput, Signer, TapScriptSig } from '@btc-vision/bitcoin';
2
- import { Taptree } from '@btc-vision/bitcoin/src/types.js';
1
+ import { Payment, Psbt, PsbtInput, Signer, TapScriptSig, Taptree } from '@btc-vision/bitcoin';
3
2
  import { TransactionBuilder } from './TransactionBuilder.js';
4
3
  import { TransactionType } from '../enums/TransactionType.js';
5
4
  import { ITransactionParameters } from '../interfaces/ITransactionParameters.js';
@@ -20,7 +19,7 @@ export interface MultiSignFromBase64Params extends Omit<MultiSignParameters, 'ps
20
19
  export declare class MultiSignTransaction extends TransactionBuilder<TransactionType.MULTI_SIG> {
21
20
  static readonly LOCK_LEAF_SCRIPT: Buffer;
22
21
  static readonly signHashTypesArray: number[];
23
- static readonly numsPoint: Buffer;
22
+ static readonly numsPoint: Buffer<ArrayBuffer>;
24
23
  type: TransactionType.MULTI_SIG;
25
24
  protected targetScriptRedeem: Payment | null;
26
25
  protected leftOverFundsScriptRedeem: Payment | null;
@@ -41,7 +40,7 @@ export declare class MultiSignTransaction extends TransactionBuilder<Transaction
41
40
  signed: boolean;
42
41
  };
43
42
  static partialFinalizer: (inputIndex: number, input: PsbtInput, partialSignatures: Buffer[], orderedPubKeys: Buffer[], isFinal: boolean) => {
44
- finalScriptWitness: Buffer;
43
+ finalScriptWitness: Buffer<ArrayBufferLike>;
45
44
  };
46
45
  static dedupeSignatures(original: TapScriptSig[], partial: TapScriptSig[]): TapScriptSig[];
47
46
  static attemptFinalizeInputs(psbt: Psbt, startIndex: number, orderedPubKeys: Buffer[][], isFinal: boolean): boolean;
@@ -1,8 +1,7 @@
1
- import { crypto as bitcoinCrypto, opcodes, Psbt, script, } from '@btc-vision/bitcoin';
1
+ import { crypto as bitcoinCrypto, opcodes, Psbt, script, toXOnly, } from '@btc-vision/bitcoin';
2
2
  import { TransactionBuilder } from './TransactionBuilder.js';
3
3
  import { TransactionType } from '../enums/TransactionType.js';
4
4
  import { MultiSignGenerator } from '../../generators/builders/MultiSignGenerator.js';
5
- import { toXOnly } from '@btc-vision/bitcoin/src/psbt/bip371.js';
6
5
  import { EcKeyPair } from '../../keypair/EcKeyPair.js';
7
6
  export class MultiSignTransaction extends TransactionBuilder {
8
7
  constructor(parameters) {
@@ -1,5 +1,4 @@
1
- import { Payment, Psbt, PsbtInput, Signer } from '@btc-vision/bitcoin';
2
- import { Taptree } from '@btc-vision/bitcoin/src/types.js';
1
+ import { Payment, Psbt, PsbtInput, Signer, Taptree } from '@btc-vision/bitcoin';
3
2
  import { ECPairInterface } from 'ecpair';
4
3
  import { TransactionBuilder } from './TransactionBuilder.js';
5
4
  import { TransactionType } from '../enums/TransactionType.js';
@@ -30,7 +29,7 @@ export declare abstract class SharedInteractionTransaction<T extends Transaction
30
29
  protected getScriptSolution(input: PsbtInput): Buffer[];
31
30
  protected getScriptTree(): Taptree;
32
31
  protected customFinalizer: (_inputIndex: number, input: PsbtInput) => {
33
- finalScriptWitness: Buffer;
32
+ finalScriptWitness: Buffer<ArrayBufferLike>;
34
33
  };
35
34
  protected signInputsWalletBased(transaction: Psbt): Promise<void>;
36
35
  private signInputsNonWalletBased;
@@ -1,10 +1,9 @@
1
- import { address } from '@btc-vision/bitcoin';
1
+ import { address, toXOnly } from '@btc-vision/bitcoin';
2
2
  import { TransactionBuilder } from './TransactionBuilder.js';
3
3
  import { CalldataGenerator } from '../../generators/builders/CalldataGenerator.js';
4
4
  import { Compressor } from '../../bytecode/Compressor.js';
5
5
  import { EcKeyPair } from '../../keypair/EcKeyPair.js';
6
6
  import { BitcoinUtils } from '../../utils/BitcoinUtils.js';
7
- import { toXOnly } from '@btc-vision/bitcoin/src/psbt/bip371.js';
8
7
  export class SharedInteractionTransaction extends TransactionBuilder {
9
8
  constructor(parameters) {
10
9
  super(parameters);
@@ -1,5 +1,4 @@
1
- import { initEccLib, opcodes, Psbt, script, Transaction, } from '@btc-vision/bitcoin';
2
- import { varuint } from '@btc-vision/bitcoin/src/bufferutils.js';
1
+ import { initEccLib, opcodes, Psbt, script, Transaction, varuint, } from '@btc-vision/bitcoin';
3
2
  import * as ecc from '@bitcoinerlab/secp256k1';
4
3
  import { EcKeyPair } from '../../keypair/EcKeyPair.js';
5
4
  import { AddressVerificator } from '../../keypair/AddressVerificator.js';
@@ -207,6 +206,16 @@ export class TransactionBuilder extends TweakedTransaction {
207
206
  tapInternalKey: this.internalPubKeyToXOnly(),
208
207
  });
209
208
  }
209
+ else if (AddressVerificator.isValidPublicKey(this.from, this.network)) {
210
+ const pubKeyScript = script.compile([
211
+ Buffer.from(this.from.replace('0x', ''), 'hex'),
212
+ opcodes.OP_CHECKSIG,
213
+ ]);
214
+ await this.setFeeOutput({
215
+ value: Number(sendBackAmount),
216
+ script: pubKeyScript,
217
+ });
218
+ }
210
219
  else {
211
220
  await this.setFeeOutput({
212
221
  value: Number(sendBackAmount),
@@ -1,10 +1,7 @@
1
1
  import { Logger } from '@btc-vision/logger';
2
- import { address as bitAddress, crypto as bitCrypto, getFinalScripts, opcodes, payments, script, } from '@btc-vision/bitcoin';
2
+ import { address as bitAddress, crypto as bitCrypto, getFinalScripts, isP2MS, isP2PK, isP2PKH, isP2SHScript, isP2TR, isP2WPKH, isP2WSHScript, opcodes, payments, script, toXOnly, varuint, } from '@btc-vision/bitcoin';
3
3
  import { TweakedSigner } from '../../signer/TweakedSigner.js';
4
- import { toXOnly } from '@btc-vision/bitcoin/src/psbt/bip371.js';
5
- import { varuint } from '@btc-vision/bitcoin/src/bufferutils.js';
6
4
  import { canSignNonTaprootInput, isTaprootInput, pubkeyInScript, } from '../../signer/SignerUtils.js';
7
- import { isP2MS, isP2PK, isP2PKH, isP2SHScript, isP2TR, isP2WPKH, isP2WSHScript, } from '@btc-vision/bitcoin/src/psbt/psbtutils.js';
8
5
  export var TransactionSequence;
9
6
  (function (TransactionSequence) {
10
7
  TransactionSequence[TransactionSequence["REPLACE_BY_FEE"] = 4294967293] = "REPLACE_BY_FEE";
@@ -13,7 +13,7 @@ export class BufferHelper {
13
13
  return buffer;
14
14
  }
15
15
  static uint8ArrayToHex(input) {
16
- return Buffer.from(input, 0, input.byteLength).toString('hex');
16
+ return Buffer.from(input.buffer, 0, input.byteLength).toString('hex');
17
17
  }
18
18
  static hexToUint8Array(input) {
19
19
  if (input.startsWith('0x')) {
@@ -1,5 +1,4 @@
1
- import { Network } from '@btc-vision/bitcoin';
2
- import { Taptree } from '@btc-vision/bitcoin/src/types.js';
1
+ import { Network, Taptree } from '@btc-vision/bitcoin';
3
2
  export interface ContractAddressVerificationParams {
4
3
  readonly deployerPubKey: Buffer;
5
4
  readonly contractSaltPubKey: Buffer;
@@ -1,5 +1,4 @@
1
- import { crypto as bitCrypto, networks, payments } from '@btc-vision/bitcoin';
2
- import { toXOnly } from '@btc-vision/bitcoin/src/psbt/bip371.js';
1
+ import { crypto as bitCrypto, networks, payments, toXOnly, } from '@btc-vision/bitcoin';
3
2
  import { DeploymentGenerator } from '../generators/builders/DeploymentGenerator.js';
4
3
  import { TransactionBuilder } from '../transaction/builders/TransactionBuilder.js';
5
4
  import { Address } from '../keypair/Address.js';
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@btc-vision/transaction",
3
3
  "type": "module",
4
- "version": "1.1.17",
4
+ "version": "1.2.1",
5
5
  "author": "BlobMaster41",
6
6
  "description": "OPNet transaction library allows you to create and sign transactions for the OPNet network.",
7
7
  "engines": {
@@ -71,7 +71,7 @@
71
71
  "@babel/preset-flow": "^7.25.9",
72
72
  "@babel/preset-react": "^7.25.9",
73
73
  "@babel/preset-typescript": "^7.26.0",
74
- "@types/node": "^22.8.7",
74
+ "@types/node": "^22.10.2",
75
75
  "@types/sha.js": "^2.4.4",
76
76
  "eslint": "^9.14.0",
77
77
  "gulp": "^5.0.0",
@@ -82,16 +82,14 @@
82
82
  "prettier": "^3.3.3",
83
83
  "stream-browserify": "^3.0.0",
84
84
  "stream-http": "^3.2.0",
85
- "typedoc": "^0.26.11",
86
- "typedoc-material-theme": "^1.1.0",
87
- "typescript-eslint": "^8.13.0",
88
- "webpack": "^5.96.1",
89
- "webpack-cli": "^5.1.4"
85
+ "typedoc": "^0.27.6",
86
+ "typescript-eslint": "^8.19.0",
87
+ "webpack-cli": "^6.0.1"
90
88
  },
91
89
  "dependencies": {
92
90
  "@babel/plugin-proposal-object-rest-spread": "^7.20.7",
93
91
  "@bitcoinerlab/secp256k1": "^1.1.1",
94
- "@btc-vision/bitcoin": "^6.3.1",
92
+ "@btc-vision/bitcoin": "^6.3.2",
95
93
  "@btc-vision/bsi-bitcoin-rpc": "^1.0.29",
96
94
  "@btc-vision/logger": "^1.0.6",
97
95
  "@eslint/js": "^9.14.0",
@@ -102,6 +100,7 @@
102
100
  "babel-preset-react": "^6.24.1",
103
101
  "babelify": "^10.0.0",
104
102
  "bech32": "^2.0.0",
103
+ "bip174": "^2.1.1",
105
104
  "bip32": "^5.0.0-rc.0",
106
105
  "browserify-zlib": "^0.2.0",
107
106
  "buffer": "^6.0.3",
@@ -113,6 +112,7 @@
113
112
  "sha.js": "^2.4.11",
114
113
  "ts-loader": "^9.5.1",
115
114
  "ts-node": "^10.9.2",
116
- "typescript": "^5.6.3"
115
+ "typescript": "^5.7.2",
116
+ "webpack": "^5.97.1"
117
117
  }
118
118
  }
package/src/_version.ts CHANGED
@@ -1 +1 @@
1
- export const version = '1.1.17';
1
+ export const version = '1.2.1';
@@ -17,7 +17,7 @@ export class BinaryReader {
17
17
  private currentOffset: i32 = 0;
18
18
 
19
19
  constructor(bytes: BufferLike) {
20
- this.buffer = new DataView(bytes.buffer);
20
+ this.buffer = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
21
21
  }
22
22
 
23
23
  public static stringCompare(a: string, b: string): number {
@@ -37,7 +37,7 @@ export class BinaryReader {
37
37
  }
38
38
 
39
39
  public setBuffer(bytes: BufferLike): void {
40
- this.buffer = new DataView(bytes.buffer);
40
+ this.buffer = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
41
41
 
42
42
  this.currentOffset = 0;
43
43
  }
@@ -354,7 +354,7 @@ export class BinaryWriter {
354
354
  buf[i] = this.buffer.getUint8(i);
355
355
  }
356
356
 
357
- this.buffer = new DataView(buf.buffer);
357
+ this.buffer = new DataView(buf.buffer, buf.byteOffset, buf.byteLength);
358
358
  }
359
359
 
360
360
  private getDefaultBuffer(length: number = 0): DataView {
@@ -1,7 +1,6 @@
1
1
  import { bech32, bech32m } from 'bech32';
2
- import { initEccLib, Network } from '@btc-vision/bitcoin';
2
+ import { initEccLib, Network, ripemd160 } from '@btc-vision/bitcoin';
3
3
  import * as ecc from '@bitcoinerlab/secp256k1';
4
- import { ripemd160 } from '@btc-vision/bitcoin/src/crypto.js';
5
4
 
6
5
  initEccLib(ecc);
7
6
 
@@ -1,5 +1,4 @@
1
- import { Network, networks } from '@btc-vision/bitcoin';
2
- import { toXOnly } from '@btc-vision/bitcoin/src/psbt/bip371.js';
1
+ import { Network, networks, toXOnly } from '@btc-vision/bitcoin';
3
2
 
4
3
  /** Bitcoin Script Generator */
5
4
  export abstract class Generator {
@@ -1,5 +1,4 @@
1
- import { opcodes, script } from '@btc-vision/bitcoin';
2
- import { toXOnly } from '@btc-vision/bitcoin/src/psbt/bip371.js';
1
+ import { opcodes, script, toXOnly } from '@btc-vision/bitcoin';
3
2
 
4
3
  /**
5
4
  * Generate a bitcoin script for a multisign interaction
@@ -1,9 +1,9 @@
1
- import { Network } from '@btc-vision/bitcoin';
2
- import { toXOnly } from '@btc-vision/bitcoin/src/psbt/bip371.js';
1
+ import { decompressPublicKey, Network, toXOnly, UncompressedPublicKey } from '@btc-vision/bitcoin';
3
2
  import { ECPairInterface } from 'ecpair';
4
3
  import { ADDRESS_BYTE_LENGTH } from '../utils/lengths.js';
5
4
  import { AddressVerificator } from './AddressVerificator.js';
6
5
  import { EcKeyPair } from './EcKeyPair.js';
6
+ import { ContractAddress } from '../transaction/ContractAddress.js';
7
7
 
8
8
  const hexPattern = /^[0-9a-fA-F]+$/;
9
9
  const isHexadecimal = (input: string): boolean => {
@@ -19,6 +19,8 @@ export class Address extends Uint8Array {
19
19
  #network: Network | undefined;
20
20
  #originalPublicKey: Uint8Array | undefined;
21
21
  #keyPair: ECPairInterface | undefined;
22
+ #uncompressed: UncompressedPublicKey | undefined;
23
+ #tweakedUncompressed: Buffer | undefined;
22
24
 
23
25
  public constructor(bytes?: ArrayLike<number>) {
24
26
  super(ADDRESS_BYTE_LENGTH);
@@ -88,6 +90,19 @@ export class Address extends Uint8Array {
88
90
  return new Address(bytes);
89
91
  }
90
92
 
93
+ public static uncompressedToCompressed(publicKey: ArrayLike<number>): Buffer {
94
+ const buffer = Uint8Array.from(publicKey);
95
+
96
+ const x = buffer.slice(1, 33);
97
+ const y = buffer.slice(33);
98
+
99
+ const compressed = Buffer.alloc(33);
100
+ compressed[0] = 0x02 + (y[y.length - 1] & 0x01);
101
+ compressed.set(x, 1);
102
+
103
+ return compressed;
104
+ }
105
+
91
106
  /**
92
107
  * Converts the address to a hex string
93
108
  * @returns {string} The hex string
@@ -104,6 +119,38 @@ export class Address extends Uint8Array {
104
119
  return Buffer.from(this);
105
120
  }
106
121
 
122
+ public toUncompressedHex(): string {
123
+ if (!this.#uncompressed) {
124
+ throw new Error('Public key not set');
125
+ }
126
+
127
+ return '0x' + this.#uncompressed.uncompressed.toString('hex');
128
+ }
129
+
130
+ public toUncompressedBuffer(): Buffer {
131
+ if (!this.#uncompressed) {
132
+ throw new Error('Public key not set');
133
+ }
134
+
135
+ return this.#uncompressed.uncompressed;
136
+ }
137
+
138
+ public toHybridPublicKeyHex(): string {
139
+ if (!this.#uncompressed) {
140
+ throw new Error('Public key not set');
141
+ }
142
+
143
+ return '0x' + this.#uncompressed.hybrid.toString('hex');
144
+ }
145
+
146
+ public toHybridPublicKeyBuffer(): Buffer {
147
+ if (!this.#uncompressed) {
148
+ throw new Error('Public key not set');
149
+ }
150
+
151
+ return this.#uncompressed.hybrid;
152
+ }
153
+
107
154
  public originalPublicKeyBuffer(): Buffer {
108
155
  if (!this.#originalPublicKey) {
109
156
  throw new Error('Public key not set');
@@ -186,16 +233,11 @@ export class Address extends Uint8Array {
186
233
  const buf = Buffer.alloc(ADDRESS_BYTE_LENGTH);
187
234
  buf.set(publicKey);
188
235
 
236
+ this.#tweakedUncompressed = ContractAddress.generateHybridKeyFromHash(buf);
237
+
189
238
  super.set(publicKey);
190
239
  } else {
191
- this.#originalPublicKey = Uint8Array.from(publicKey);
192
- this.#keyPair = EcKeyPair.fromPublicKey(this.#originalPublicKey);
193
-
194
- const tweakedBytes = toXOnly(
195
- EcKeyPair.tweakPublicKey(Buffer.from(this.#originalPublicKey)),
196
- );
197
-
198
- super.set(tweakedBytes);
240
+ this.autoFormat(publicKey);
199
241
  }
200
242
  }
201
243
 
@@ -273,4 +315,43 @@ export class Address extends Uint8Array {
273
315
 
274
316
  throw new Error('Public key not set');
275
317
  }
318
+
319
+ public toTweakedHybridPublicKeyHex(): string {
320
+ if (!this.#tweakedUncompressed) {
321
+ throw new Error('Public key not set');
322
+ }
323
+
324
+ return '0x' + this.#tweakedUncompressed.toString('hex');
325
+ }
326
+
327
+ public toTweakedHybridPublicKeyBuffer(): Buffer {
328
+ if (!this.#tweakedUncompressed) {
329
+ throw new Error('Public key not set');
330
+ }
331
+
332
+ return this.#tweakedUncompressed;
333
+ }
334
+
335
+ private autoFormat(publicKey: ArrayLike<number>): void {
336
+ const firstByte = publicKey[0];
337
+
338
+ if (firstByte === 0x03 || firstByte === 0x02) {
339
+ // do nothing
340
+ } else if (firstByte === 0x04 || firstByte === 0x06 || firstByte === 0x07) {
341
+ // uncompressed
342
+ publicKey = Address.uncompressedToCompressed(publicKey);
343
+ }
344
+
345
+ this.#originalPublicKey = Uint8Array.from(publicKey);
346
+ this.#keyPair = EcKeyPair.fromPublicKey(this.#originalPublicKey);
347
+ this.#uncompressed = decompressPublicKey(this.#originalPublicKey);
348
+
349
+ const tweakedBytes: Buffer = toXOnly(
350
+ EcKeyPair.tweakPublicKey(Buffer.from(this.#originalPublicKey)),
351
+ );
352
+
353
+ this.#tweakedUncompressed = ContractAddress.generateHybridKeyFromHash(tweakedBytes);
354
+
355
+ super.set(tweakedBytes);
356
+ }
276
357
  }
@@ -109,14 +109,18 @@ export class AddressVerificator {
109
109
  return true;
110
110
  }
111
111
 
112
+ const pubKeyBuffer = Buffer.from(input, 'hex');
113
+ if ((input.length === 130 && pubKeyBuffer[0] === 0x06) || pubKeyBuffer[0] === 0x07) {
114
+ return true;
115
+ }
116
+
112
117
  if (input.length === 66 || input.length === 130) {
113
118
  // Check if the input can be parsed as a valid public key
114
- const pubKeyBuffer = Buffer.from(input, 'hex');
115
119
  EcKeyPair.fromPublicKey(pubKeyBuffer, network);
116
120
 
117
121
  return true;
118
122
  }
119
- } catch {
123
+ } catch (e) {
120
124
  return false;
121
125
  }
122
126
 
@@ -1,11 +1,18 @@
1
1
  import * as ecc from '@bitcoinerlab/secp256k1';
2
2
  import bip32, { BIP32API, BIP32Factory, BIP32Interface } from 'bip32';
3
- import { address, initEccLib, Network, networks, payments, Signer } from '@btc-vision/bitcoin';
3
+ import {
4
+ address,
5
+ initEccLib,
6
+ Network,
7
+ networks,
8
+ payments,
9
+ Signer,
10
+ taggedHash,
11
+ toXOnly,
12
+ } from '@btc-vision/bitcoin';
4
13
  import { ECPairAPI, ECPairFactory, ECPairInterface } from 'ecpair';
5
14
  import { IWallet } from './interfaces/IWallet.js';
6
15
  import { CURVE, ProjectivePoint as Point } from '@noble/secp256k1';
7
- import { taggedHash } from '@btc-vision/bitcoin/src/crypto.js';
8
- import { toXOnly } from '@btc-vision/bitcoin/src/psbt/bip371.js';
9
16
 
10
17
  initEccLib(ecc);
11
18
 
@@ -154,8 +161,10 @@ export class EcKeyPair {
154
161
  }
155
162
 
156
163
  // Convert the tweaked public key hex string to a Buffer
157
- let tweakedPubKeyBuffer = Buffer.from(tweakedPubKeyHex, 'hex');
158
- if (tweakedPubKeyBuffer.length !== 32) tweakedPubKeyBuffer = toXOnly(tweakedPubKeyBuffer);
164
+ let tweakedPubKeyBuffer: Buffer = Buffer.from(tweakedPubKeyHex, 'hex');
165
+ if (tweakedPubKeyBuffer.length !== 32) {
166
+ tweakedPubKeyBuffer = toXOnly(tweakedPubKeyBuffer);
167
+ }
159
168
 
160
169
  return EcKeyPair.tweakedPubKeyBufferToAddress(tweakedPubKeyBuffer, network);
161
170
  }
@@ -1,9 +1,8 @@
1
1
  import { ECPairInterface } from 'ecpair';
2
2
  import * as ecc from '@bitcoinerlab/secp256k1';
3
- import { crypto, Network } from '@btc-vision/bitcoin';
3
+ import { crypto, Network, toXOnly } from '@btc-vision/bitcoin';
4
4
  import { TweakedSigner } from '../signer/TweakedSigner.js';
5
5
  import { EcKeyPair } from './EcKeyPair.js';
6
- import { toXOnly } from '@btc-vision/bitcoin/src/psbt/bip371.js';
7
6
 
8
7
  export interface SignedMessage {
9
8
  readonly signature: Uint8Array;