@btc-vision/transaction 1.0.112 → 1.0.114

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 (150) hide show
  1. package/browser/_version.d.ts +1 -1
  2. package/browser/abi/ABICoder.d.ts +31 -0
  3. package/browser/buffer/BinaryReader.d.ts +37 -0
  4. package/browser/buffer/BinaryWriter.d.ts +46 -0
  5. package/browser/deterministic/AddressMap.d.ts +10 -0
  6. package/browser/deterministic/AddressSet.d.ts +13 -0
  7. package/browser/deterministic/DeterministicMap.d.ts +17 -0
  8. package/browser/deterministic/DeterministicSet.d.ts +13 -0
  9. package/browser/deterministic/Map.d.ts +14 -0
  10. package/browser/event/NetEvent.d.ts +5 -0
  11. package/browser/generators/AddressGenerator.d.ts +3 -0
  12. package/browser/index.js +1 -1
  13. package/browser/keypair/Address.d.ts +23 -0
  14. package/browser/keypair/AddressVerificator.d.ts +15 -4
  15. package/browser/keypair/EcKeyPair.d.ts +15 -12
  16. package/browser/keypair/Wallet.d.ts +12 -5
  17. package/browser/metadata/ContractBaseMetadata.d.ts +3 -4
  18. package/browser/metadata/contracts/wBTC.d.ts +2 -3
  19. package/browser/metadata/tokens.d.ts +1 -1
  20. package/browser/opnet.d.ts +11 -0
  21. package/browser/signer/TweakedSigner.d.ts +2 -2
  22. package/browser/transaction/TransactionFactory.d.ts +6 -6
  23. package/browser/transaction/browser/BrowserSignerBase.d.ts +3 -4
  24. package/browser/transaction/browser/extensions/UnisatSigner.d.ts +3 -4
  25. package/browser/transaction/browser/types/Unisat.d.ts +2 -3
  26. package/browser/transaction/builders/CustomScriptTransaction.d.ts +4 -5
  27. package/browser/transaction/builders/DeploymentTransaction.d.ts +4 -2
  28. package/browser/transaction/builders/FundingTransaction.d.ts +2 -1
  29. package/browser/transaction/builders/MultiSignTransaction.d.ts +6 -6
  30. package/browser/transaction/builders/SharedInteractionTransaction.d.ts +1 -1
  31. package/browser/transaction/builders/TransactionBuilder.d.ts +6 -7
  32. package/browser/transaction/builders/WrapTransaction.d.ts +2 -2
  33. package/browser/transaction/interfaces/ITransactionParameters.d.ts +6 -6
  34. package/browser/transaction/processor/PsbtTransaction.d.ts +3 -4
  35. package/browser/transaction/shared/P2TR_MS.d.ts +1 -2
  36. package/browser/transaction/shared/TweakedTransaction.d.ts +8 -7
  37. package/browser/utils/BufferHelper.d.ts +11 -0
  38. package/browser/utils/types.d.ts +12 -0
  39. package/browser/utxo/OPNetLimitedProvider.d.ts +1 -2
  40. package/build/_version.d.ts +1 -1
  41. package/build/_version.js +1 -1
  42. package/build/abi/ABICoder.d.ts +31 -0
  43. package/build/abi/ABICoder.js +137 -0
  44. package/build/buffer/BinaryReader.d.ts +37 -0
  45. package/build/buffer/BinaryReader.js +192 -0
  46. package/build/buffer/BinaryWriter.d.ts +46 -0
  47. package/build/buffer/BinaryWriter.js +258 -0
  48. package/build/deterministic/AddressMap.d.ts +10 -0
  49. package/build/deterministic/AddressMap.js +46 -0
  50. package/build/deterministic/AddressSet.d.ts +13 -0
  51. package/build/deterministic/AddressSet.js +44 -0
  52. package/build/deterministic/DeterministicMap.d.ts +17 -0
  53. package/build/deterministic/DeterministicMap.js +83 -0
  54. package/build/deterministic/DeterministicSet.d.ts +13 -0
  55. package/build/deterministic/DeterministicSet.js +46 -0
  56. package/build/deterministic/Map.d.ts +14 -0
  57. package/build/deterministic/Map.js +56 -0
  58. package/build/event/NetEvent.d.ts +5 -0
  59. package/build/event/NetEvent.js +6 -0
  60. package/build/generators/AddressGenerator.d.ts +3 -0
  61. package/build/generators/AddressGenerator.js +8 -1
  62. package/build/keypair/Address.d.ts +23 -0
  63. package/build/keypair/Address.js +129 -0
  64. package/build/keypair/AddressVerificator.d.ts +15 -4
  65. package/build/keypair/AddressVerificator.js +79 -3
  66. package/build/keypair/EcKeyPair.d.ts +15 -12
  67. package/build/keypair/EcKeyPair.js +61 -9
  68. package/build/keypair/Wallet.d.ts +12 -5
  69. package/build/keypair/Wallet.js +19 -5
  70. package/build/metadata/ContractBaseMetadata.d.ts +3 -4
  71. package/build/metadata/contracts/wBTC.d.ts +2 -3
  72. package/build/metadata/contracts/wBTC.js +4 -6
  73. package/build/metadata/tokens.d.ts +1 -1
  74. package/build/metadata/tokens.js +19 -15
  75. package/build/opnet.d.ts +11 -0
  76. package/build/opnet.js +11 -0
  77. package/build/signer/TweakedSigner.d.ts +2 -2
  78. package/build/signer/TweakedSigner.js +1 -1
  79. package/build/transaction/TransactionFactory.d.ts +6 -6
  80. package/build/transaction/TransactionFactory.js +3 -2
  81. package/build/transaction/browser/BrowserSignerBase.d.ts +3 -4
  82. package/build/transaction/browser/extensions/UnisatSigner.d.ts +3 -4
  83. package/build/transaction/browser/types/Unisat.d.ts +2 -3
  84. package/build/transaction/builders/CustomScriptTransaction.d.ts +4 -5
  85. package/build/transaction/builders/CustomScriptTransaction.js +3 -3
  86. package/build/transaction/builders/DeploymentTransaction.d.ts +4 -2
  87. package/build/transaction/builders/DeploymentTransaction.js +10 -6
  88. package/build/transaction/builders/FundingTransaction.d.ts +2 -1
  89. package/build/transaction/builders/MultiSignTransaction.d.ts +6 -6
  90. package/build/transaction/builders/SharedInteractionTransaction.d.ts +1 -1
  91. package/build/transaction/builders/SharedInteractionTransaction.js +4 -4
  92. package/build/transaction/builders/TransactionBuilder.d.ts +6 -7
  93. package/build/transaction/builders/UnwrapSegwitTransaction.js +2 -1
  94. package/build/transaction/builders/UnwrapTransaction.js +4 -3
  95. package/build/transaction/builders/WrapTransaction.d.ts +2 -2
  96. package/build/transaction/builders/WrapTransaction.js +5 -6
  97. package/build/transaction/interfaces/ITransactionParameters.d.ts +6 -6
  98. package/build/transaction/processor/PsbtTransaction.d.ts +3 -4
  99. package/build/transaction/shared/P2TR_MS.d.ts +1 -2
  100. package/build/transaction/shared/TweakedTransaction.d.ts +8 -7
  101. package/build/transaction/shared/TweakedTransaction.js +1 -1
  102. package/build/utils/BufferHelper.d.ts +11 -0
  103. package/build/utils/BufferHelper.js +50 -0
  104. package/build/utils/types.d.ts +12 -0
  105. package/build/utils/types.js +1 -0
  106. package/build/utxo/OPNetLimitedProvider.d.ts +1 -2
  107. package/build/utxo/OPNetLimitedProvider.js +1 -1
  108. package/build/verification/TapscriptVerificator.js +3 -2
  109. package/package.json +4 -2
  110. package/src/_version.ts +1 -1
  111. package/src/abi/ABICoder.ts +158 -0
  112. package/src/buffer/BinaryReader.ts +260 -0
  113. package/src/buffer/BinaryWriter.ts +331 -0
  114. package/src/deterministic/AddressMap.ts +57 -0
  115. package/src/deterministic/AddressSet.ts +62 -0
  116. package/src/deterministic/DeterministicMap.ts +88 -0
  117. package/src/deterministic/DeterministicSet.ts +56 -0
  118. package/src/deterministic/Map.ts +66 -0
  119. package/src/event/NetEvent.ts +6 -0
  120. package/src/generators/AddressGenerator.ts +15 -1
  121. package/src/keypair/Address.ts +235 -0
  122. package/src/keypair/AddressVerificator.ts +149 -6
  123. package/src/keypair/EcKeyPair.ts +146 -47
  124. package/src/keypair/Wallet.ts +72 -15
  125. package/src/metadata/ContractBaseMetadata.ts +3 -4
  126. package/src/metadata/contracts/wBTC.ts +8 -9
  127. package/src/metadata/tokens.ts +21 -16
  128. package/src/opnet.ts +13 -0
  129. package/src/signer/TweakedSigner.ts +3 -2
  130. package/src/transaction/TransactionFactory.ts +11 -10
  131. package/src/transaction/browser/BrowserSignerBase.ts +3 -4
  132. package/src/transaction/browser/extensions/UnisatSigner.ts +6 -7
  133. package/src/transaction/browser/types/Unisat.ts +2 -3
  134. package/src/transaction/builders/CustomScriptTransaction.ts +10 -10
  135. package/src/transaction/builders/DeploymentTransaction.ts +23 -9
  136. package/src/transaction/builders/FundingTransaction.ts +2 -1
  137. package/src/transaction/builders/MultiSignTransaction.ts +10 -7
  138. package/src/transaction/builders/SharedInteractionTransaction.ts +5 -5
  139. package/src/transaction/builders/TransactionBuilder.ts +26 -17
  140. package/src/transaction/builders/UnwrapSegwitTransaction.ts +10 -4
  141. package/src/transaction/builders/UnwrapTransaction.ts +5 -19
  142. package/src/transaction/builders/WrapTransaction.ts +7 -13
  143. package/src/transaction/interfaces/ITransactionParameters.ts +7 -6
  144. package/src/transaction/processor/PsbtTransaction.ts +3 -4
  145. package/src/transaction/shared/P2TR_MS.ts +2 -3
  146. package/src/transaction/shared/TweakedTransaction.ts +12 -12
  147. package/src/utils/BufferHelper.ts +71 -0
  148. package/src/utils/types.ts +19 -0
  149. package/src/utxo/OPNetLimitedProvider.ts +3 -8
  150. package/src/verification/TapscriptVerificator.ts +4 -2
@@ -1,25 +1,28 @@
1
- import { Address } from '@btc-vision/bsi-binary';
2
1
  import { BIP32API, BIP32Interface } from 'bip32';
3
- import { Network } from 'bitcoinjs-lib';
2
+ import { Network, Signer } from 'bitcoinjs-lib';
4
3
  import { ECPairAPI, ECPairInterface } from 'ecpair';
5
4
  import { IWallet } from './interfaces/IWallet.js';
6
5
  export declare class EcKeyPair {
7
6
  static BIP32: BIP32API;
8
7
  static ECPair: ECPairAPI;
9
8
  static fromWIF(wif: string, network?: Network): ECPairInterface;
10
- static fromPrivateKey(privateKey: Buffer, network?: Network): ECPairInterface;
11
- static fromPublicKey(publicKey: Buffer, network?: Network): ECPairInterface;
12
- static generateMultiSigAddress(pubKeys: Buffer[], minimumSignatureRequired: number, network?: Network): Address;
9
+ static fromPrivateKey(privateKey: Buffer | Uint8Array, network?: Network): ECPairInterface;
10
+ static fromPublicKey(publicKey: Buffer | Uint8Array, network?: Network): ECPairInterface;
11
+ static generateMultiSigAddress(pubKeys: Buffer[], minimumSignatureRequired: number, network?: Network): string;
13
12
  static verifyPubKeys(pubKeys: Buffer[], network?: Network): Buffer[];
14
- static getP2WPKHAddress(keyPair: ECPairInterface, network?: Network): Address;
13
+ static getP2WPKHAddress(keyPair: ECPairInterface, network?: Network): string;
14
+ static tweakedPubKeyToAddress(tweakedPubKeyHex: string, network: Network): string;
15
+ static tweakedPubKeyBufferToAddress(tweakedPubKeyBuffer: Buffer | Uint8Array, network: Network): string;
16
+ static xOnlyTweakedPubKeyToAddress(tweakedPubKeyHex: string, network: Network): string;
17
+ static tweakPublicKey(compressedPubKeyHex: string): string;
15
18
  static generateWallet(network?: Network): IWallet;
16
- static verifyContractAddress(contractAddress: Address, network?: Network): boolean;
17
- static getLegacySegwitAddress(keyPair: ECPairInterface, network?: Network): Address;
18
- static getLegacyAddress(keyPair: ECPairInterface, network?: Network): Address;
19
- static getP2PKAddress(keyPair: ECPairInterface, network?: Network): Address;
19
+ static verifyContractAddress(contractAddress: string, network?: Network): boolean;
20
+ static getLegacySegwitAddress(keyPair: ECPairInterface, network?: Network): string;
21
+ static getLegacyAddress(keyPair: ECPairInterface, network?: Network): string;
22
+ static getP2PKAddress(keyPair: ECPairInterface, network?: Network): string;
20
23
  static generateRandomKeyPair(network?: Network): ECPairInterface;
21
24
  static fromSeed(seed: Buffer, network?: Network): BIP32Interface;
22
- static getTaprootAddress(keyPair: ECPairInterface, network?: Network): Address;
23
- static getTaprootAddressFromAddress(inAddr: Address, network?: Network): Address;
25
+ static getTaprootAddress(keyPair: ECPairInterface | Signer, network?: Network): string;
26
+ static getTaprootAddressFromAddress(inAddr: string, network?: Network): string;
24
27
  static fromSeedKeyPair(seed: Buffer, network?: Network): ECPairInterface;
25
28
  }
@@ -3,6 +3,8 @@ import bip32, { BIP32Factory } from 'bip32';
3
3
  import { address, initEccLib, networks, payments } from 'bitcoinjs-lib';
4
4
  import { toXOnly } from 'bitcoinjs-lib/src/psbt/bip371.js';
5
5
  import { ECPairFactory } from 'ecpair';
6
+ import { CURVE, Point, utils } from '@noble/secp256k1';
7
+ import { taggedHash } from 'bitcoinjs-lib/src/crypto.js';
6
8
  initEccLib(ecc);
7
9
  const BIP32factory = typeof bip32 === 'function' ? bip32 : BIP32Factory;
8
10
  if (!BIP32factory) {
@@ -13,10 +15,11 @@ export class EcKeyPair {
13
15
  return this.ECPair.fromWIF(wif, network);
14
16
  }
15
17
  static fromPrivateKey(privateKey, network = networks.bitcoin) {
16
- return this.ECPair.fromPrivateKey(privateKey, { network });
18
+ return this.ECPair.fromPrivateKey(!Buffer.isBuffer(privateKey) ? Buffer.from(privateKey) : privateKey, { network });
17
19
  }
18
20
  static fromPublicKey(publicKey, network = networks.bitcoin) {
19
- return this.ECPair.fromPublicKey(publicKey, { network });
21
+ const buf = !Buffer.isBuffer(publicKey) ? Buffer.from(publicKey) : publicKey;
22
+ return this.ECPair.fromPublicKey(buf, { network });
20
23
  }
21
24
  static generateMultiSigAddress(pubKeys, minimumSignatureRequired, network = networks.bitcoin) {
22
25
  const publicKeys = this.verifyPubKeys(pubKeys, network);
@@ -40,16 +43,65 @@ export class EcKeyPair {
40
43
  if (!key) {
41
44
  throw new Error('Failed to regenerate key');
42
45
  }
43
- return key.publicKey;
46
+ return Buffer.from(key.publicKey);
44
47
  });
45
48
  }
46
49
  static getP2WPKHAddress(keyPair, network = networks.bitcoin) {
47
- const res = payments.p2wpkh({ pubkey: keyPair.publicKey, network: network });
50
+ const res = payments.p2wpkh({ pubkey: Buffer.from(keyPair.publicKey), network: network });
48
51
  if (!res.address) {
49
52
  throw new Error('Failed to generate wallet');
50
53
  }
51
54
  return res.address;
52
55
  }
56
+ static tweakedPubKeyToAddress(tweakedPubKeyHex, network) {
57
+ if (tweakedPubKeyHex.startsWith('0x')) {
58
+ tweakedPubKeyHex = tweakedPubKeyHex.slice(2);
59
+ }
60
+ let tweakedPubKeyBuffer = Buffer.from(tweakedPubKeyHex, 'hex');
61
+ if (tweakedPubKeyBuffer.length !== 32)
62
+ tweakedPubKeyBuffer = toXOnly(tweakedPubKeyBuffer);
63
+ return EcKeyPair.tweakedPubKeyBufferToAddress(tweakedPubKeyBuffer, network);
64
+ }
65
+ static tweakedPubKeyBufferToAddress(tweakedPubKeyBuffer, network) {
66
+ const { address } = payments.p2tr({
67
+ pubkey: Buffer.isBuffer(tweakedPubKeyBuffer)
68
+ ? tweakedPubKeyBuffer
69
+ : Buffer.from(tweakedPubKeyBuffer),
70
+ network: network,
71
+ });
72
+ if (!address) {
73
+ throw new Error('Failed to generate Taproot address');
74
+ }
75
+ return address;
76
+ }
77
+ static xOnlyTweakedPubKeyToAddress(tweakedPubKeyHex, network) {
78
+ if (tweakedPubKeyHex.startsWith('0x')) {
79
+ tweakedPubKeyHex = tweakedPubKeyHex.slice(2);
80
+ }
81
+ const tweakedPubKeyBuffer = Buffer.from(tweakedPubKeyHex, 'hex');
82
+ const { address } = payments.p2tr({
83
+ pubkey: tweakedPubKeyBuffer,
84
+ network: network,
85
+ });
86
+ if (!address) {
87
+ throw new Error('Failed to generate Taproot address');
88
+ }
89
+ return address;
90
+ }
91
+ static tweakPublicKey(compressedPubKeyHex) {
92
+ if (compressedPubKeyHex.startsWith('0x')) {
93
+ compressedPubKeyHex = compressedPubKeyHex.slice(2);
94
+ }
95
+ let P = Point.fromHex(compressedPubKeyHex);
96
+ if (!P.hasEvenY()) {
97
+ P = P.negate();
98
+ }
99
+ const x = P.toRawBytes(true).slice(1);
100
+ const tHash = taggedHash('TapTweak', Buffer.from(x));
101
+ const t = utils.mod(BigInt('0x' + Buffer.from(tHash).toString('hex')), CURVE.n);
102
+ const Q = P.add(Point.BASE.multiply(t));
103
+ return Q.toHex(true);
104
+ }
53
105
  static generateWallet(network = networks.bitcoin) {
54
106
  const keyPair = this.ECPair.makeRandom({
55
107
  network: network,
@@ -61,7 +113,7 @@ export class EcKeyPair {
61
113
  return {
62
114
  address: wallet,
63
115
  privateKey: keyPair.toWIF(),
64
- publicKey: keyPair.publicKey.toString('hex'),
116
+ publicKey: Buffer.from(keyPair.publicKey).toString('hex'),
65
117
  };
66
118
  }
67
119
  static verifyContractAddress(contractAddress, network = networks.bitcoin) {
@@ -69,7 +121,7 @@ export class EcKeyPair {
69
121
  }
70
122
  static getLegacySegwitAddress(keyPair, network = networks.bitcoin) {
71
123
  const wallet = payments.p2sh({
72
- redeem: payments.p2wpkh({ pubkey: keyPair.publicKey, network: network }),
124
+ redeem: payments.p2wpkh({ pubkey: Buffer.from(keyPair.publicKey), network: network }),
73
125
  network: network,
74
126
  });
75
127
  if (!wallet.address) {
@@ -78,14 +130,14 @@ export class EcKeyPair {
78
130
  return wallet.address;
79
131
  }
80
132
  static getLegacyAddress(keyPair, network = networks.bitcoin) {
81
- const wallet = payments.p2pkh({ pubkey: keyPair.publicKey, network: network });
133
+ const wallet = payments.p2pkh({ pubkey: Buffer.from(keyPair.publicKey), network: network });
82
134
  if (!wallet.address) {
83
135
  throw new Error('Failed to generate wallet');
84
136
  }
85
137
  return wallet.address;
86
138
  }
87
139
  static getP2PKAddress(keyPair, network = networks.bitcoin) {
88
- const wallet = payments.p2pk({ pubkey: keyPair.publicKey, network: network });
140
+ const wallet = payments.p2pk({ pubkey: Buffer.from(keyPair.publicKey), network: network });
89
141
  if (!wallet.output) {
90
142
  throw new Error('Failed to generate wallet');
91
143
  }
@@ -101,7 +153,7 @@ export class EcKeyPair {
101
153
  }
102
154
  static getTaprootAddress(keyPair, network = networks.bitcoin) {
103
155
  const { address } = payments.p2tr({
104
- internalPubkey: toXOnly(keyPair.publicKey),
156
+ internalPubkey: toXOnly(Buffer.from(keyPair.publicKey)),
105
157
  network: network,
106
158
  });
107
159
  if (!address) {
@@ -1,19 +1,26 @@
1
1
  import { IWallet } from './interfaces/IWallet.js';
2
2
  import { ECPairInterface } from 'ecpair';
3
3
  import { Network } from 'bitcoinjs-lib';
4
- import { Address } from '@btc-vision/bsi-binary';
4
+ import { Address } from './Address.js';
5
5
  export declare class Wallet {
6
6
  readonly network: Network;
7
7
  private readonly _keypair;
8
8
  private readonly _p2wpkh;
9
9
  private readonly _p2tr;
10
10
  private readonly _legacy;
11
+ private readonly _segwitLegacy;
12
+ private readonly _bufferPubKey;
13
+ private readonly _tweakedKey;
14
+ private readonly _address;
11
15
  constructor(wallet: IWallet, network?: Network);
16
+ get address(): Address;
17
+ get tweakedPubKeyKey(): Buffer;
12
18
  get keypair(): ECPairInterface;
13
- get p2wpkh(): Address;
14
- get p2tr(): Address;
15
- get legacy(): Address;
16
- get addresses(): Address[];
19
+ get p2wpkh(): string;
20
+ get p2tr(): string;
21
+ get legacy(): string;
22
+ get addresses(): string[];
23
+ get segwitLegacy(): string;
17
24
  get publicKey(): Buffer;
18
25
  get xOnly(): Buffer;
19
26
  static fromWif(wif: string, network?: Network): Wallet;
@@ -1,6 +1,7 @@
1
1
  import { EcKeyPair } from './EcKeyPair.js';
2
2
  import { networks } from 'bitcoinjs-lib';
3
3
  import { toXOnly } from 'bitcoinjs-lib/src/psbt/bip371.js';
4
+ import { Address } from './Address.js';
4
5
  export class Wallet {
5
6
  constructor(wallet, network = networks.bitcoin) {
6
7
  this.network = network;
@@ -8,6 +9,16 @@ export class Wallet {
8
9
  this._p2wpkh = EcKeyPair.getP2WPKHAddress(this._keypair, this.network);
9
10
  this._p2tr = EcKeyPair.getTaprootAddress(this._keypair, this.network);
10
11
  this._legacy = EcKeyPair.getLegacyAddress(this._keypair, this.network);
12
+ this._segwitLegacy = EcKeyPair.getLegacySegwitAddress(this._keypair, this.network);
13
+ this._tweakedKey = Buffer.from(EcKeyPair.tweakPublicKey(this._keypair.publicKey.toString('hex')), 'hex');
14
+ this._bufferPubKey = Buffer.from(wallet.publicKey, 'hex');
15
+ this._address = new Address(this._keypair.publicKey);
16
+ }
17
+ get address() {
18
+ return this._address;
19
+ }
20
+ get tweakedPubKeyKey() {
21
+ return this._tweakedKey;
11
22
  }
12
23
  get keypair() {
13
24
  if (!this._keypair)
@@ -24,17 +35,20 @@ export class Wallet {
24
35
  return this._legacy;
25
36
  }
26
37
  get addresses() {
27
- return [this.p2wpkh, this.p2tr, this.legacy];
38
+ return [this.p2wpkh, this.p2tr, this.legacy, this.segwitLegacy];
39
+ }
40
+ get segwitLegacy() {
41
+ return this._segwitLegacy;
28
42
  }
29
43
  get publicKey() {
30
- if (!this.keypair)
31
- throw new Error('Keypair not set');
32
- return this.keypair.publicKey;
44
+ if (!this._bufferPubKey)
45
+ throw new Error('Public key not set');
46
+ return this._bufferPubKey;
33
47
  }
34
48
  get xOnly() {
35
49
  if (!this.keypair)
36
50
  throw new Error('Keypair not set');
37
- return toXOnly(this.keypair.publicKey);
51
+ return toXOnly(this._bufferPubKey);
38
52
  }
39
53
  static fromWif(wif, network = networks.bitcoin) {
40
54
  return new Wallet({ privateKey: wif, address: '', publicKey: '' }, network);
@@ -1,9 +1,8 @@
1
- import { Address } from '@btc-vision/bsi-binary';
2
1
  import { Network } from 'bitcoinjs-lib';
3
2
  export declare abstract class ContractBaseMetadata {
4
3
  protected network: Network;
5
- protected abstract readonly address: Address;
4
+ protected abstract readonly address: string;
6
5
  protected constructor(network?: Network);
7
- static getAddress(network?: Network): Address;
8
- getAddress(): Address;
6
+ static getAddress(network?: Network): string;
7
+ getAddress(): string;
9
8
  }
@@ -1,4 +1,3 @@
1
- import { Address } from '@btc-vision/bsi-binary';
2
1
  import { Network } from 'bitcoinjs-lib';
3
2
  import { ChainId } from '../../network/ChainId.js';
4
3
  import { ContractBaseMetadata } from '../ContractBaseMetadata.js';
@@ -7,8 +6,8 @@ export declare class wBTC extends ContractBaseMetadata {
7
6
  readonly tokenName: string;
8
7
  readonly tokenSymbol: string;
9
8
  readonly decimals: number;
10
- protected readonly address: Address;
9
+ protected readonly address: string;
11
10
  constructor(network?: Network, chainId?: ChainId);
12
- static getAddress(network?: Network, chainId?: ChainId): Address;
11
+ static getAddress(network?: Network, chainId?: ChainId): string;
13
12
  private static getWBTCAddressForChain;
14
13
  }
@@ -14,23 +14,21 @@ export class wBTC extends ContractBaseMetadata {
14
14
  static getAddress(network = networks.bitcoin, chainId) {
15
15
  switch (network.bech32) {
16
16
  case networks.bitcoin.bech32:
17
- return this.getWBTCAddressForChain(chainId ?? ChainId.Bitcoin);
17
+ return this.getWBTCAddressForChain(chainId ?? ChainId.Bitcoin).p2tr(network);
18
18
  case networks.regtest.bech32:
19
- return WBTC_ADDRESS_REGTEST;
19
+ return WBTC_ADDRESS_REGTEST.p2tr(network);
20
20
  case networks.testnet.bech32:
21
- return WBTC_ADDRESS_TESTNET;
21
+ return WBTC_ADDRESS_TESTNET.p2tr(network);
22
22
  default:
23
23
  throw new Error(`Invalid network: ${network.bech32}`);
24
24
  }
25
25
  }
26
26
  static getWBTCAddressForChain(chainId) {
27
27
  switch (chainId) {
28
- case ChainId.Bitcoin:
29
- return 'unknown';
30
28
  case ChainId.Fractal:
31
29
  return WBTC_ADDRESS_FRACTAL;
32
30
  default:
33
- throw new Error(`Invalid chainId: ${chainId}`);
31
+ throw new Error(`Unsupported chainId: ${chainId}`);
34
32
  }
35
33
  }
36
34
  }
@@ -1,5 +1,5 @@
1
- import { Address } from '@btc-vision/bsi-binary';
2
1
  import { ChainId } from '../network/ChainId.js';
2
+ import { Address } from '../keypair/Address.js';
3
3
  export declare const FACTORY_ADDRESS_REGTEST: Address;
4
4
  export declare const POOL_ADDRESS_REGTEST: Address;
5
5
  export declare const WBTC_ADDRESS_REGTEST: Address;
@@ -1,19 +1,23 @@
1
1
  import { ChainId } from '../network/ChainId.js';
2
- export const FACTORY_ADDRESS_REGTEST = 'bcrt1q9pf9fnpch9z2qrp5e3dgr2avzu3mypq3km2k40';
3
- export const POOL_ADDRESS_REGTEST = 'bcrt1qg87nx9v9ln3qyadcn0llekzjn0hx8js46ztwky';
4
- export const WBTC_ADDRESS_REGTEST = 'bcrt1qamv2ejattjgsc6k3yf3zqrp0wpuyedqgjmwx0v';
5
- export const MOTO_ADDRESS_REGTEST = 'bcrt1qw8w4ejas2k22y54avv7hgrslg3cd0hme58h28r';
6
- export const ROUTER_ADDRESS_REGTEST = 'bcrt1q9yd6mk324k0q4krmlxjky0pk65ul6hkf4u35e6';
7
- export const FACTORY_ADDRESS_TESTNET = 'tb1qgev5kldhp5zvg6j8t9vl6x4phkrwn8nk9felxh';
8
- export const POOL_ADDRESS_TESTNET = 'tb1q6a7yw353hjmresphupytw5vczpqxtg4yrupayk';
9
- export const WBTC_ADDRESS_TESTNET = 'tb1qp28xna6pv47x6wflcplhu0a9hkld5shtvjx6xv';
10
- export const MOTO_ADDRESS_TESTNET = 'tb1q4tyhf8hpu04qjj3qaag20knun0spctultxzakw';
11
- export const ROUTER_ADDRESS_TESTNET = 'tb1qnh9mj95nnej25dwhjvvsppwmdm0myhxv7tllgt';
12
- export const FACTORY_ADDRESS_FRACTAL = 'bc1qr4g85824m58wu0zffjtnf56n425fp0e8azhc7q';
13
- export const POOL_ADDRESS_FRACTAL = 'bc1qv55cht4zzlt29ea7vdgwsedsn63a2sxtkgpv6h';
14
- export const WBTC_ADDRESS_FRACTAL = 'bc1qdtzlucslvrvu4useyh9r69supqrw3w4xn9t4yv';
15
- export const MOTO_ADDRESS_FRACTAL = 'bc1qfzq6w5uvgg5489egv0lj4shlqx4dagqt0ewdnu';
16
- export const ROUTER_ADDRESS_FRACTAL = 'bc1q9w2zvmkzlezt2fu34u57y9vuw6rll5sp2090kn';
2
+ import { Address } from '../keypair/Address.js';
3
+ function deadAddress() {
4
+ return Address.dead();
5
+ }
6
+ export const FACTORY_ADDRESS_REGTEST = deadAddress();
7
+ export const POOL_ADDRESS_REGTEST = deadAddress();
8
+ export const WBTC_ADDRESS_REGTEST = deadAddress();
9
+ export const MOTO_ADDRESS_REGTEST = deadAddress();
10
+ export const ROUTER_ADDRESS_REGTEST = deadAddress();
11
+ export const FACTORY_ADDRESS_TESTNET = deadAddress();
12
+ export const POOL_ADDRESS_TESTNET = deadAddress();
13
+ export const WBTC_ADDRESS_TESTNET = deadAddress();
14
+ export const MOTO_ADDRESS_TESTNET = deadAddress();
15
+ export const ROUTER_ADDRESS_TESTNET = deadAddress();
16
+ export const FACTORY_ADDRESS_FRACTAL = deadAddress();
17
+ export const POOL_ADDRESS_FRACTAL = deadAddress();
18
+ export const WBTC_ADDRESS_FRACTAL = deadAddress();
19
+ export const MOTO_ADDRESS_FRACTAL = deadAddress();
20
+ export const ROUTER_ADDRESS_FRACTAL = deadAddress();
17
21
  export var OPNetNetwork;
18
22
  (function (OPNetNetwork) {
19
23
  OPNetNetwork["Mainnet"] = "mainnet";
package/build/opnet.d.ts CHANGED
@@ -43,6 +43,17 @@ export * from './wbtc/UnwrapGeneration.js';
43
43
  export * from './consensus/ConsensusConfig.js';
44
44
  export * from './consensus/Consensus.js';
45
45
  export * from './consensus/metadata/RoswellConsensus.js';
46
+ export * from './utils/BufferHelper.js';
47
+ export * from './utils/types.js';
48
+ export * from './keypair/Address.js';
49
+ export * from './event/NetEvent.js';
50
+ export * from './deterministic/DeterministicMap.js';
51
+ export * from './deterministic/DeterministicSet.js';
52
+ export * from './deterministic/AddressMap.js';
53
+ export * from './deterministic/AddressSet.js';
54
+ export * from './abi/ABICoder.js';
55
+ export * from './buffer/BinaryWriter.js';
56
+ export * from './buffer/BinaryReader.js';
46
57
  export * from './transaction/browser/BrowserSignerBase.js';
47
58
  export * from './transaction/browser/extensions/UnisatSigner.js';
48
59
  export * from './transaction/browser/types/Unisat.js';
package/build/opnet.js CHANGED
@@ -43,6 +43,17 @@ export * from './wbtc/UnwrapGeneration.js';
43
43
  export * from './consensus/ConsensusConfig.js';
44
44
  export * from './consensus/Consensus.js';
45
45
  export * from './consensus/metadata/RoswellConsensus.js';
46
+ export * from './utils/BufferHelper.js';
47
+ export * from './utils/types.js';
48
+ export * from './keypair/Address.js';
49
+ export * from './event/NetEvent.js';
50
+ export * from './deterministic/DeterministicMap.js';
51
+ export * from './deterministic/DeterministicSet.js';
52
+ export * from './deterministic/AddressMap.js';
53
+ export * from './deterministic/AddressSet.js';
54
+ export * from './abi/ABICoder.js';
55
+ export * from './buffer/BinaryWriter.js';
56
+ export * from './buffer/BinaryReader.js';
46
57
  export * from './transaction/browser/BrowserSignerBase.js';
47
58
  export * from './transaction/browser/extensions/UnisatSigner.js';
48
59
  export * from './transaction/browser/types/Unisat.js';
@@ -1,9 +1,9 @@
1
- import { Network, Signer } from 'bitcoinjs-lib';
1
+ import { Network } from 'bitcoinjs-lib';
2
2
  import { ECPairInterface } from 'ecpair';
3
3
  export interface TweakSettings {
4
4
  readonly network?: Network;
5
5
  tweakHash?: Buffer;
6
6
  }
7
7
  export declare class TweakedSigner {
8
- static tweakSigner(signer: ECPairInterface, opts?: TweakSettings): Signer;
8
+ static tweakSigner(signer: ECPairInterface, opts?: TweakSettings): ECPairInterface;
9
9
  }
@@ -13,7 +13,7 @@ export class TweakedSigner {
13
13
  if (signer.publicKey[0] === 3) {
14
14
  privateKey = ecc.privateNegate(privateKey);
15
15
  }
16
- const tweakedPrivateKey = ecc.privateAdd(privateKey, tapTweakHash(toXOnly(signer.publicKey), opts.tweakHash));
16
+ const tweakedPrivateKey = ecc.privateAdd(privateKey, tapTweakHash(toXOnly(Buffer.from(signer.publicKey)), opts.tweakHash));
17
17
  if (!tweakedPrivateKey) {
18
18
  throw new Error('Invalid tweaked private key!');
19
19
  }
@@ -1,4 +1,3 @@
1
- import { Address } from '@btc-vision/bsi-binary';
2
1
  import { Transaction } from 'bitcoinjs-lib';
3
2
  import { UTXO } from '../utxo/interfaces/IUTXO.js';
4
3
  import { ICustomTransactionParameters } from './builders/CustomScriptTransaction.js';
@@ -8,15 +7,16 @@ import { TransactionType } from './enums/TransactionType.js';
8
7
  import { IDeploymentParameters, IFundingTransactionParameters, IInteractionParameters, IUnwrapParameters, IWrapParameters } from './interfaces/ITransactionParameters.js';
9
8
  export interface DeploymentResult {
10
9
  readonly transaction: [string, string];
11
- readonly contractAddress: Address;
12
- readonly p2trAddress: Address;
10
+ readonly contractAddress: string;
11
+ readonly contractPubKey: string;
12
+ readonly p2trAddress: string;
13
13
  readonly utxos: UTXO[];
14
14
  }
15
15
  export interface WrapResult {
16
16
  readonly transaction: [string, string];
17
- readonly vaultAddress: Address;
17
+ readonly vaultAddress: string;
18
18
  readonly amount: bigint;
19
- readonly receiverAddress: Address;
19
+ readonly receiverAddress: string;
20
20
  readonly utxos: UTXO[];
21
21
  }
22
22
  export interface FundingTransactionResponse {
@@ -45,7 +45,7 @@ export declare class TransactionFactory {
45
45
  unwrapSegwit(unwrapParameters: IUnwrapParameters): Promise<UnwrapResult>;
46
46
  unwrap(unwrapParameters: IUnwrapParameters): Promise<UnwrapResult>;
47
47
  createBTCTransfer(parameters: IFundingTransactionParameters): Promise<BitcoinTransferResponse>;
48
- getAllNewUTXOs(original: TransactionBuilder<TransactionType>, tx: Transaction, to: Address): UTXO[];
48
+ getAllNewUTXOs(original: TransactionBuilder<TransactionType>, tx: Transaction, to: string): UTXO[];
49
49
  private createFundTransaction;
50
50
  private calculateNumSignatures;
51
51
  private calculateNumInputs;
@@ -137,7 +137,8 @@ export class TransactionFactory {
137
137
  };
138
138
  return {
139
139
  transaction: [signedTransaction.toHex(), outTx.toHex()],
140
- contractAddress: finalTransaction.contractAddress,
140
+ contractAddress: finalTransaction.contractAddress.p2tr(deploymentParameters.network),
141
+ contractPubKey: finalTransaction.contractPubKey,
141
142
  p2trAddress: finalTransaction.p2trAddress,
142
143
  utxos: [refundUTXO],
143
144
  };
@@ -179,7 +180,7 @@ export class TransactionFactory {
179
180
  transaction: [signedTransaction.tx.toHex(), outTx.toHex()],
180
181
  vaultAddress: finalTransaction.vault,
181
182
  amount: finalTransaction.amount,
182
- receiverAddress: finalTransaction.receiver,
183
+ receiverAddress: finalTransaction.receiver.p2tr(wrapParameters.network),
183
184
  utxos: this.getUTXOAsTransaction(signedTransaction.tx, wrapParameters.from, 1),
184
185
  };
185
186
  }
@@ -1,11 +1,10 @@
1
1
  import { Network, Psbt, Signer } from 'bitcoinjs-lib';
2
- import { Address } from '@btc-vision/bsi-binary';
3
2
  export declare abstract class CustomKeypair implements Signer {
4
3
  abstract network: Network;
5
4
  abstract publicKey: Buffer;
6
- abstract addresses: Address[];
7
- abstract p2tr: Address;
8
- abstract p2wpkh: Address;
5
+ abstract addresses: string[];
6
+ abstract p2tr: string;
7
+ abstract p2wpkh: string;
9
8
  protected constructor();
10
9
  abstract signTaprootInput(transaction: Psbt, i: number, sighashTypes: number[]): Promise<void>;
11
10
  abstract signInput(transaction: Psbt, i: number, sighashTypes: number[]): Promise<void>;
@@ -1,4 +1,3 @@
1
- import { Address } from '@btc-vision/bsi-binary';
2
1
  import { Network, Psbt } from 'bitcoinjs-lib';
3
2
  import { CustomKeypair } from '../BrowserSignerBase.js';
4
3
  import { Unisat } from '../types/Unisat.js';
@@ -12,11 +11,11 @@ export declare class UnisatSigner extends CustomKeypair {
12
11
  private isInitialized;
13
12
  constructor();
14
13
  private _p2tr;
15
- get p2tr(): Address;
14
+ get p2tr(): string;
16
15
  private _p2wpkh;
17
- get p2wpkh(): Address;
16
+ get p2wpkh(): string;
18
17
  private _addresses;
19
- get addresses(): Address[];
18
+ get addresses(): string[];
20
19
  private _publicKey;
21
20
  get publicKey(): Buffer;
22
21
  _network: Network | undefined;
@@ -1,4 +1,3 @@
1
- import { Address } from '@btc-vision/bsi-binary';
2
1
  import { Web3Provider } from '../Web3Provider.js';
3
2
  export declare enum UnisatNetwork {
4
3
  testnet = "testnet",
@@ -37,7 +36,7 @@ export interface ToSignInputPublicKey extends ToSignInputBase {
37
36
  readonly publicKey: string;
38
37
  }
39
38
  export interface ToSignInputAddress extends ToSignInputBase {
40
- readonly address: Address;
39
+ readonly address: string;
41
40
  }
42
41
  export type ToSignInput = ToSignInputPublicKey | ToSignInputAddress;
43
42
  export interface PsbtSignatureOptions {
@@ -46,7 +45,7 @@ export interface PsbtSignatureOptions {
46
45
  }
47
46
  export interface Unisat {
48
47
  web3?: Web3Provider;
49
- sendBitcoin(toAddress: Address, satoshis: number, options: {
48
+ sendBitcoin(toAddress: string, satoshis: number, options: {
50
49
  feeRate: number;
51
50
  memo?: string;
52
51
  memos?: string[];
@@ -1,17 +1,16 @@
1
1
  import { TransactionType } from '../enums/TransactionType.js';
2
2
  import { TapLeafScript } from '../interfaces/Tap.js';
3
3
  import { SharedInteractionParameters } from '../interfaces/ITransactionParameters.js';
4
- import { Address } from '@btc-vision/bsi-binary';
5
4
  import { Payment, Psbt, Stack } from 'bitcoinjs-lib';
6
5
  import { TransactionBuilder } from './TransactionBuilder.js';
7
6
  export interface ICustomTransactionParameters extends SharedInteractionParameters {
8
7
  readonly script: (Buffer | Stack)[];
9
8
  readonly witnesses: Buffer[];
10
- readonly to: Address;
9
+ readonly to: string;
11
10
  }
12
11
  export declare class CustomScriptTransaction extends TransactionBuilder<TransactionType.CUSTOM_CODE> {
13
12
  type: TransactionType.CUSTOM_CODE;
14
- protected readonly _scriptAddress: Address;
13
+ protected readonly _scriptAddress: string;
15
14
  protected tapLeafScript: TapLeafScript | null;
16
15
  private targetScriptRedeem;
17
16
  private leftOverFundsScriptRedeem;
@@ -23,8 +22,8 @@ export declare class CustomScriptTransaction extends TransactionBuilder<Transact
23
22
  private readonly randomBytes;
24
23
  private readonly witnesses;
25
24
  constructor(parameters: ICustomTransactionParameters);
26
- get scriptAddress(): Address;
27
- get p2trAddress(): Address;
25
+ get scriptAddress(): string;
26
+ get p2trAddress(): string;
28
27
  getRndBytes(): Buffer;
29
28
  protected contractSignerXOnlyPubKey(): Buffer;
30
29
  protected buildTransaction(): Promise<void>;
@@ -49,7 +49,7 @@ export class CustomScriptTransaction extends TransactionBuilder {
49
49
  return this.randomBytes;
50
50
  }
51
51
  contractSignerXOnlyPubKey() {
52
- return toXOnly(this.contractSigner.publicKey);
52
+ return toXOnly(Buffer.from(this.contractSigner.publicKey));
53
53
  }
54
54
  async buildTransaction() {
55
55
  if (!this.to) {
@@ -125,9 +125,9 @@ export class CustomScriptTransaction extends TransactionBuilder {
125
125
  return bitCrypto.hash256(this.randomBytes);
126
126
  }
127
127
  getPubKeys() {
128
- const pubkeys = [this.signer.publicKey];
128
+ const pubkeys = [Buffer.from(this.signer.publicKey)];
129
129
  if (this.contractSigner) {
130
- pubkeys.push(this.contractSigner.publicKey);
130
+ pubkeys.push(Buffer.from(this.contractSigner.publicKey));
131
131
  }
132
132
  return pubkeys;
133
133
  }
@@ -3,7 +3,7 @@ import { IDeploymentParameters } from '../interfaces/ITransactionParameters.js';
3
3
  import { Payment, Psbt } from 'bitcoinjs-lib';
4
4
  import { TransactionBuilder } from './TransactionBuilder.js';
5
5
  import { TapLeafScript } from '../interfaces/Tap.js';
6
- import { Address } from '@btc-vision/bsi-binary';
6
+ import { Address } from '../../keypair/Address.js';
7
7
  export declare class DeploymentTransaction extends TransactionBuilder<TransactionType.DEPLOYMENT> {
8
8
  static readonly MAXIMUM_CONTRACT_SIZE: number;
9
9
  type: TransactionType.DEPLOYMENT;
@@ -18,10 +18,12 @@ export declare class DeploymentTransaction extends TransactionBuilder<Transactio
18
18
  private readonly bytecode;
19
19
  private readonly calldata?;
20
20
  private readonly contractSigner;
21
+ private readonly _contractPubKey;
21
22
  private readonly randomBytes;
22
23
  constructor(parameters: IDeploymentParameters);
24
+ get contractPubKey(): string;
23
25
  get contractAddress(): Address;
24
- get p2trAddress(): Address;
26
+ get p2trAddress(): string;
25
27
  getRndBytes(): Buffer;
26
28
  protected contractSignerXOnlyPubKey(): Buffer;
27
29
  protected buildTransaction(): Promise<void>;