@btc-vision/transaction 1.8.0-beta.0 → 1.8.0-beta.3

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.
@@ -1 +1 @@
1
- export declare const version = "1.8.0-beta.0";
1
+ export declare const version = "1.8.0-beta.1";
package/build/_version.js CHANGED
@@ -1 +1 @@
1
- export const version = '1.8.0-beta.0';
1
+ export const version = '1.8.0-beta.1';
@@ -18,7 +18,7 @@ import { ContractAddress } from '../transaction/ContractAddress.js';
18
18
  import { BitcoinUtils } from '../utils/BitcoinUtils.js';
19
19
  import { TimeLockGenerator } from '../transaction/mineable/TimelockGenerator.js';
20
20
  import { P2WDADetector } from '../p2wda/P2WDADetector.js';
21
- import { sha256 } from '@noble/hashes/sha2';
21
+ import { sha256 } from '@noble/hashes/sha2.js';
22
22
  export class Address extends Uint8Array {
23
23
  constructor(mldsaPublicKey, publicKeyOrTweak) {
24
24
  super(ADDRESS_BYTE_LENGTH);
@@ -2,6 +2,7 @@ import { BIP32API, BIP32Interface, MLDSAKeyPair, MLDSASecurityLevel } from '@btc
2
2
  import { Network, Signer } from '@btc-vision/bitcoin';
3
3
  import { ECPairAPI, ECPairInterface } from 'ecpair';
4
4
  import { IWallet } from './interfaces/IWallet.js';
5
+ import { Buffer } from 'buffer';
5
6
  export declare class EcKeyPair {
6
7
  static BIP32: BIP32API;
7
8
  static ECPair: ECPairAPI;
@@ -2,10 +2,11 @@ import * as ecc from '@bitcoinerlab/secp256k1';
2
2
  import bip32, { BIP32Factory, MLDSASecurityLevel, QuantumBIP32Factory, } from '@btc-vision/bip32';
3
3
  import bitcoin, { address, fromOutputScript, initEccLib, networks, opcodes, payments, script, toXOnly, } from '@btc-vision/bitcoin';
4
4
  import { ECPairFactory } from 'ecpair';
5
- import { secp256k1 } from '@noble/curves/secp256k1';
6
- import { mod } from '@noble/curves/abstract/modular';
7
- import { sha256 } from '@noble/hashes/sha2';
8
- import { bytesToNumberBE, concatBytes, randomBytes, utf8ToBytes } from '@noble/curves/utils.js';
5
+ import { secp256k1 } from '@noble/curves/secp256k1.js';
6
+ import { mod } from '@noble/curves/abstract/modular.js';
7
+ import { sha256 } from '@noble/hashes/sha2.js';
8
+ import { bytesToNumberBE, concatBytes, randomBytes } from '@noble/curves/utils.js';
9
+ import { Buffer } from 'buffer';
9
10
  initEccLib(ecc);
10
11
  const BIP32factory = typeof bip32 === 'function' ? bip32 : BIP32Factory;
11
12
  if (!BIP32factory) {
@@ -13,7 +14,7 @@ if (!BIP32factory) {
13
14
  }
14
15
  const Point = secp256k1.Point;
15
16
  const CURVE_N = Point.Fn.ORDER;
16
- const TAP_TAG = utf8ToBytes('TapTweak');
17
+ const TAP_TAG = Buffer.from('TapTweak', 'utf-8');
17
18
  const TAP_TAG_HASH = sha256(TAP_TAG);
18
19
  function tapTweakHash(x) {
19
20
  return sha256(concatBytes(TAP_TAG_HASH, TAP_TAG_HASH, x));
@@ -111,7 +112,7 @@ export class EcKeyPair {
111
112
  static tweakPublicKey(pub) {
112
113
  if (typeof pub === 'string' && pub.startsWith('0x'))
113
114
  pub = pub.slice(2);
114
- const P = Point.fromHex(pub);
115
+ const P = Point.fromHex(Buffer.from(pub).toString('hex'));
115
116
  const Peven = (P.y & 1n) === 0n ? P : P.negate();
116
117
  const xBytes = Buffer.from(Peven.toBytes(true).subarray(1));
117
118
  const tBytes = tapTweakHash(xBytes);
@@ -122,7 +123,7 @@ export class EcKeyPair {
122
123
  static tweakBatchSharedT(pubkeys, tweakScalar) {
123
124
  const T = Point.BASE.multiply(tweakScalar);
124
125
  return pubkeys.map((bytes) => {
125
- const P = Point.fromHex(bytes);
126
+ const P = Point.fromHex(Buffer.from(bytes).toString('hex'));
126
127
  const P_even = P.y % 2n === 0n ? P : P.negate();
127
128
  const Q = P_even.add(T);
128
129
  return Q.toBytes(true);
@@ -131,6 +132,10 @@ export class EcKeyPair {
131
132
  static generateWallet(network = networks.bitcoin, securityLevel = MLDSASecurityLevel.LEVEL2) {
132
133
  const keyPair = this.ECPair.makeRandom({
133
134
  network: network,
135
+ rng: (size) => {
136
+ const bytes = randomBytes(size);
137
+ return Buffer.from(bytes);
138
+ },
134
139
  });
135
140
  const wallet = this.getP2WPKHAddress(keyPair, network);
136
141
  if (!wallet) {
@@ -193,6 +198,10 @@ export class EcKeyPair {
193
198
  static generateRandomKeyPair(network = networks.bitcoin) {
194
199
  return this.ECPair.makeRandom({
195
200
  network: network,
201
+ rng: (size) => {
202
+ const bytes = randomBytes(size);
203
+ return Buffer.from(bytes);
204
+ },
196
205
  });
197
206
  }
198
207
  static fromSeed(seed, network = networks.bitcoin) {