@btc-vision/transaction 1.2.5 → 1.2.7

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 (62) hide show
  1. package/README.md +4 -19
  2. package/browser/_version.d.ts +1 -1
  3. package/browser/generators/Generator.d.ts +1 -0
  4. package/browser/generators/builders/CalldataGenerator.d.ts +1 -1
  5. package/browser/generators/builders/DeploymentGenerator.d.ts +1 -1
  6. package/browser/generators/builders/LegacyCalldataGenerator.d.ts +1 -1
  7. package/browser/index.js +1 -1
  8. package/browser/transaction/browser/extensions/UnisatSigner.d.ts +2 -1
  9. package/browser/transaction/browser/extensions/XverseSigner.d.ts +2 -1
  10. package/browser/transaction/browser/types/Unisat.d.ts +5 -0
  11. package/browser/transaction/browser/types/Xverse.d.ts +10 -6
  12. package/browser/transaction/builders/MultiSignTransaction.d.ts +1 -1
  13. package/browser/transaction/builders/TransactionBuilder.d.ts +1 -0
  14. package/browser/transaction/interfaces/ITransactionParameters.d.ts +1 -0
  15. package/browser/verification/TapscriptVerificator.d.ts +1 -0
  16. package/build/_version.d.ts +1 -1
  17. package/build/_version.js +1 -1
  18. package/build/generators/Generator.d.ts +1 -0
  19. package/build/generators/Generator.js +7 -0
  20. package/build/generators/builders/CalldataGenerator.d.ts +1 -1
  21. package/build/generators/builders/CalldataGenerator.js +2 -2
  22. package/build/generators/builders/DeploymentGenerator.d.ts +1 -1
  23. package/build/generators/builders/DeploymentGenerator.js +4 -4
  24. package/build/generators/builders/LegacyCalldataGenerator.d.ts +1 -1
  25. package/build/generators/builders/LegacyCalldataGenerator.js +5 -23
  26. package/build/transaction/TransactionFactory.js +7 -3
  27. package/build/transaction/browser/extensions/UnisatSigner.d.ts +2 -1
  28. package/build/transaction/browser/extensions/UnisatSigner.js +6 -1
  29. package/build/transaction/browser/extensions/XverseSigner.d.ts +2 -1
  30. package/build/transaction/browser/extensions/XverseSigner.js +17 -0
  31. package/build/transaction/browser/types/Unisat.d.ts +5 -0
  32. package/build/transaction/browser/types/Unisat.js +5 -0
  33. package/build/transaction/browser/types/Xverse.d.ts +10 -6
  34. package/build/transaction/browser/types/Xverse.js +5 -0
  35. package/build/transaction/builders/DeploymentTransaction.js +1 -1
  36. package/build/transaction/builders/InteractionTransaction.js +1 -1
  37. package/build/transaction/builders/MultiSignTransaction.d.ts +1 -1
  38. package/build/transaction/builders/MultiSignTransaction.js +1 -0
  39. package/build/transaction/builders/TransactionBuilder.d.ts +1 -0
  40. package/build/transaction/builders/TransactionBuilder.js +5 -2
  41. package/build/transaction/interfaces/ITransactionParameters.d.ts +1 -0
  42. package/build/utxo/OPNetLimitedProvider.js +2 -1
  43. package/build/verification/TapscriptVerificator.d.ts +1 -0
  44. package/build/verification/TapscriptVerificator.js +2 -2
  45. package/package.json +2 -2
  46. package/src/_version.ts +1 -1
  47. package/src/generators/Generator.ts +9 -0
  48. package/src/generators/builders/CalldataGenerator.ts +4 -1
  49. package/src/generators/builders/DeploymentGenerator.ts +6 -3
  50. package/src/generators/builders/LegacyCalldataGenerator.ts +11 -40
  51. package/src/transaction/TransactionFactory.ts +10 -3
  52. package/src/transaction/browser/extensions/UnisatSigner.ts +9 -2
  53. package/src/transaction/browser/extensions/XverseSigner.ts +31 -1
  54. package/src/transaction/browser/types/Unisat.ts +8 -1
  55. package/src/transaction/browser/types/Xverse.ts +23 -13
  56. package/src/transaction/builders/DeploymentTransaction.ts +1 -0
  57. package/src/transaction/builders/InteractionTransaction.ts +1 -0
  58. package/src/transaction/builders/MultiSignTransaction.ts +2 -1
  59. package/src/transaction/builders/TransactionBuilder.ts +6 -2
  60. package/src/transaction/interfaces/ITransactionParameters.ts +1 -0
  61. package/src/utxo/OPNetLimitedProvider.ts +2 -1
  62. package/src/verification/TapscriptVerificator.ts +3 -0
@@ -1,6 +1,6 @@
1
1
  import { Network, Psbt } from '@btc-vision/bitcoin';
2
2
  import { CustomKeypair } from '../BrowserSignerBase.js';
3
- import { Unisat } from '../types/Unisat.js';
3
+ import { SignatureType, Unisat } from '../types/Unisat.js';
4
4
  declare global {
5
5
  interface Window {
6
6
  unisat?: Unisat;
@@ -21,6 +21,7 @@ export declare class UnisatSigner extends CustomKeypair {
21
21
  _network: Network | undefined;
22
22
  get network(): Network;
23
23
  get unisat(): Unisat;
24
+ signData(data: Buffer, type: SignatureType): Promise<Buffer>;
24
25
  init(): Promise<void>;
25
26
  getPublicKey(): Buffer;
26
27
  sign(_hash: Buffer, _lowR?: boolean): Buffer;
@@ -1,6 +1,6 @@
1
1
  import { Network, Psbt } from '@btc-vision/bitcoin';
2
2
  import { CustomKeypair } from '../BrowserSignerBase.js';
3
- import { Xverse } from '../types/Xverse.js';
3
+ import { SigningProtocol, Xverse } from '../types/Xverse.js';
4
4
  declare global {
5
5
  interface Window {
6
6
  BitcoinProvider?: Xverse;
@@ -21,6 +21,7 @@ export declare class XverseSigner extends CustomKeypair {
21
21
  get network(): Network;
22
22
  get BitcoinProvider(): Xverse;
23
23
  init(): Promise<void>;
24
+ signData(data: Buffer, address: string, protocol: SigningProtocol): Promise<Buffer>;
24
25
  getPublicKey(): Buffer;
25
26
  sign(_hash: Buffer, _lowR?: boolean): Buffer;
26
27
  signSchnorr(_hash: Buffer): Buffer;
@@ -27,6 +27,10 @@ export declare enum MessageType {
27
27
  ecdsa = "ecdsa",
28
28
  bip322 = "bip322-simple"
29
29
  }
30
+ export declare enum SignatureType {
31
+ ecdsa = "ecdsa",
32
+ schnorr = "schnorr"
33
+ }
30
34
  interface ToSignInputBase {
31
35
  readonly index: number;
32
36
  readonly sighashTypes?: number[];
@@ -60,6 +64,7 @@ export interface Unisat {
60
64
  getPublicKey(): Promise<string>;
61
65
  getBalance(): Promise<Balance>;
62
66
  signMessage(message: string, type?: MessageType): Promise<string>;
67
+ signData(hex: string, type?: SignatureType): Promise<string>;
63
68
  pushTx(options: {
64
69
  rawtx: string;
65
70
  }): Promise<string>;
@@ -76,18 +76,22 @@ interface SignedTransactionResult {
76
76
  txid: string;
77
77
  raw: string;
78
78
  }
79
+ export declare enum SigningProtocol {
80
+ ECDSA = "ECDSA",
81
+ BIP322 = "BIP322"
82
+ }
79
83
  export interface Xverse {
80
- request(method: string, params: unknown): Promise<XverseRPCResponse>;
81
- request(method: 'wallet_connect' | 'wallet_getAccount', params: null): Promise<XverseRPCGetAccountResponse>;
82
- request(method: 'wallet_disconnect', params: null): Promise<XverseRPCResponse<null>>;
83
- request(method: 'getBalance', params: null): Promise<XverseRPCGetBalanceResponse>;
84
- request(method: 'signPsbt', params: XVersePSBTInput): Promise<XverseRPCSignPsbtResponse>;
85
84
  addListener: (event: string, callback: (...args: unknown[]) => void) => void;
86
85
  createInscription: (data: InscriptionData) => Promise<InscriptionResult>;
87
86
  createRepeatInscriptions: (data: RepeatInscriptionsData) => Promise<InscriptionResult[]>;
88
87
  sendBtcTransaction: (transaction: BtcTransaction) => Promise<TransactionResult>;
89
- signMessage: (message: string) => Promise<SignedMessageResult>;
88
+ signMessage: (address: string, message: string, protocol: SigningProtocol) => Promise<SignedMessageResult>;
90
89
  signMultipleTransactions: (transactions: BtcTransaction[]) => Promise<SignedTransactionResult[]>;
91
90
  signTransaction: (transaction: BtcTransaction) => Promise<SignedTransactionResult>;
91
+ request(method: string, params: unknown): Promise<XverseRPCResponse>;
92
+ request(method: 'wallet_connect' | 'wallet_getAccount', params: null): Promise<XverseRPCGetAccountResponse>;
93
+ request(method: 'wallet_disconnect', params: null): Promise<XverseRPCResponse<null>>;
94
+ request(method: 'getBalance', params: null): Promise<XverseRPCGetBalanceResponse>;
95
+ request(method: 'signPsbt', params: XVersePSBTInput): Promise<XverseRPCSignPsbtResponse>;
92
96
  }
93
97
  export {};
@@ -3,7 +3,7 @@ import { TransactionBuilder } from './TransactionBuilder.js';
3
3
  import { TransactionType } from '../enums/TransactionType.js';
4
4
  import { ITransactionParameters } from '../interfaces/ITransactionParameters.js';
5
5
  import { ECPairInterface } from 'ecpair';
6
- export interface MultiSignParameters extends Omit<ITransactionParameters, 'priorityFee' | 'signer'> {
6
+ export interface MultiSignParameters extends Omit<ITransactionParameters, 'gasSatFee' | 'priorityFee' | 'signer'> {
7
7
  readonly pubkeys: Buffer[];
8
8
  readonly minimumSignatures: number;
9
9
  readonly from?: undefined;
@@ -26,6 +26,7 @@ export declare abstract class TransactionBuilder<T extends TransactionType> exte
26
26
  protected readonly network: Network;
27
27
  protected readonly feeRate: number;
28
28
  protected priorityFee: bigint;
29
+ protected gasSatFee: bigint;
29
30
  protected utxos: UTXO[];
30
31
  protected to: string | undefined;
31
32
  protected from: string;
@@ -12,6 +12,7 @@ export interface ITransactionParameters extends ITweakedTransactionData {
12
12
  chainId?: ChainId;
13
13
  readonly feeRate: number;
14
14
  readonly priorityFee: bigint;
15
+ readonly gasSatFee: bigint;
15
16
  }
16
17
  export interface IFundingTransactionParameters extends ITransactionParameters {
17
18
  amount: bigint;
@@ -5,6 +5,7 @@ export interface ContractAddressVerificationParams {
5
5
  readonly originalSalt: Buffer;
6
6
  readonly bytecode: Buffer;
7
7
  readonly preimage: Buffer;
8
+ readonly priorityFee: bigint;
8
9
  readonly calldata?: Buffer;
9
10
  readonly network?: Network;
10
11
  }
@@ -1 +1 @@
1
- export declare const version = "1.2.5";
1
+ export declare const version = "1.2.7";
package/build/_version.js CHANGED
@@ -1 +1 @@
1
- export const version = '1.2.5';
1
+ export const version = '1.2.7';
@@ -8,6 +8,7 @@ export declare abstract class Generator {
8
8
  protected readonly network: Network;
9
9
  protected constructor(senderPubKey: Buffer, contractSaltPubKey?: Buffer, network?: Network);
10
10
  get senderFirstByte(): Buffer;
11
+ getHeader(maxPriority: bigint): Buffer;
11
12
  abstract compile(...args: unknown[]): Buffer;
12
13
  protected splitBufferIntoChunks(buffer: Buffer, chunkSize?: number): Array<Buffer[]>;
13
14
  }
@@ -1,4 +1,5 @@
1
1
  import { networks, toXOnly } from '@btc-vision/bitcoin';
2
+ import { BinaryWriter } from '../buffer/BinaryWriter.js';
2
3
  export class Generator {
3
4
  constructor(senderPubKey, contractSaltPubKey, network = networks.bitcoin) {
4
5
  this.network = networks.bitcoin;
@@ -10,6 +11,12 @@ export class Generator {
10
11
  get senderFirstByte() {
11
12
  return Buffer.from([this.senderPubKey[0], 0, 0, 0]);
12
13
  }
14
+ getHeader(maxPriority) {
15
+ const writer = new BinaryWriter(8 + 4);
16
+ writer.writeBytes(this.senderFirstByte);
17
+ writer.writeU64(maxPriority);
18
+ return Buffer.from(writer.getBuffer());
19
+ }
13
20
  splitBufferIntoChunks(buffer, chunkSize = Generator.DATA_CHUNK_SIZE) {
14
21
  const chunks = [];
15
22
  for (let i = 0; i < buffer.length; i += chunkSize) {
@@ -4,5 +4,5 @@ import { Generator } from '../Generator.js';
4
4
  export declare class CalldataGenerator extends Generator {
5
5
  constructor(senderPubKey: Buffer, contractSaltPubKey: Buffer, network?: Network);
6
6
  static getPubKeyAsBuffer(witnessKeys: Buffer[], network: Network): Buffer;
7
- compile(calldata: Buffer, contractSecret: Buffer, preimage: Buffer, features?: Features[]): Buffer;
7
+ compile(calldata: Buffer, contractSecret: Buffer, preimage: Buffer, maxPriority: bigint, features?: Features[]): Buffer;
8
8
  }
@@ -25,14 +25,14 @@ export class CalldataGenerator extends Generator {
25
25
  }
26
26
  return compressed;
27
27
  }
28
- compile(calldata, contractSecret, preimage, features = []) {
28
+ compile(calldata, contractSecret, preimage, maxPriority, features = []) {
29
29
  if (!this.contractSaltPubKey)
30
30
  throw new Error('Contract salt public key not set');
31
31
  const dataChunks = this.splitBufferIntoChunks(calldata);
32
32
  if (!dataChunks.length)
33
33
  throw new Error('No data chunks found');
34
34
  let compiledData = [
35
- this.senderFirstByte,
35
+ this.getHeader(maxPriority),
36
36
  opcodes.OP_TOALTSTACK,
37
37
  preimage,
38
38
  opcodes.OP_TOALTSTACK,
@@ -2,6 +2,6 @@ import { Network } from '@btc-vision/bitcoin';
2
2
  import { Generator } from '../Generator.js';
3
3
  export declare class DeploymentGenerator extends Generator {
4
4
  constructor(senderPubKey: Buffer, contractSaltPubKey: Buffer, network?: Network);
5
- compile(contractBytecode: Buffer, contractSalt: Buffer, preimage: Buffer, calldata?: Buffer): Buffer;
5
+ compile(contractBytecode: Buffer, contractSalt: Buffer, preimage: Buffer, maxPriority: bigint, calldata?: Buffer): Buffer;
6
6
  private getAsm;
7
7
  }
@@ -4,8 +4,8 @@ export class DeploymentGenerator extends Generator {
4
4
  constructor(senderPubKey, contractSaltPubKey, network = networks.bitcoin) {
5
5
  super(senderPubKey, contractSaltPubKey, network);
6
6
  }
7
- compile(contractBytecode, contractSalt, preimage, calldata) {
8
- const asm = this.getAsm(contractBytecode, contractSalt, preimage, calldata);
7
+ compile(contractBytecode, contractSalt, preimage, maxPriority, calldata) {
8
+ const asm = this.getAsm(contractBytecode, contractSalt, preimage, maxPriority, calldata);
9
9
  const compiled = script.compile(asm);
10
10
  const decompiled = script.decompile(compiled);
11
11
  if (!decompiled) {
@@ -13,13 +13,13 @@ export class DeploymentGenerator extends Generator {
13
13
  }
14
14
  return compiled;
15
15
  }
16
- getAsm(contractBytecode, contractSalt, preimage, calldata) {
16
+ getAsm(contractBytecode, contractSalt, preimage, maxPriority, calldata) {
17
17
  if (!this.contractSaltPubKey)
18
18
  throw new Error('Contract salt public key not set');
19
19
  const dataChunks = this.splitBufferIntoChunks(contractBytecode);
20
20
  const calldataChunks = calldata ? this.splitBufferIntoChunks(calldata) : [];
21
21
  const compiledData = [
22
- this.senderFirstByte,
22
+ this.getHeader(maxPriority),
23
23
  opcodes.OP_TOALTSTACK,
24
24
  preimage,
25
25
  opcodes.OP_TOALTSTACK,
@@ -4,5 +4,5 @@ import { Generator } from '../Generator.js';
4
4
  export declare class LegacyCalldataGenerator extends Generator {
5
5
  constructor(senderPubKey: Buffer, network?: Network);
6
6
  static getPubKeyAsBuffer(witnessKeys: Buffer[], network: Network): Buffer;
7
- compile(calldata: Buffer, contractSecret: Buffer, features?: Features[], vaultPublicKeys?: Buffer[], minimumSignatures?: number): Buffer;
7
+ compile(calldata: Buffer, contractSecret: Buffer, preimage: Buffer, maxPriority: bigint, features?: Features[]): Buffer;
8
8
  }
@@ -25,11 +25,15 @@ export class LegacyCalldataGenerator extends Generator {
25
25
  }
26
26
  return compressed;
27
27
  }
28
- compile(calldata, contractSecret, features = [], vaultPublicKeys = [], minimumSignatures = 0) {
28
+ compile(calldata, contractSecret, preimage, maxPriority, features = []) {
29
29
  const dataChunks = this.splitBufferIntoChunks(calldata);
30
30
  if (!dataChunks.length)
31
31
  throw new Error('No data chunks found');
32
32
  let compiledData = [
33
+ this.getHeader(maxPriority),
34
+ opcodes.OP_TOALTSTACK,
35
+ preimage,
36
+ opcodes.OP_TOALTSTACK,
33
37
  this.senderPubKey,
34
38
  opcodes.OP_DUP,
35
39
  opcodes.OP_HASH256,
@@ -44,28 +48,6 @@ export class LegacyCalldataGenerator extends Generator {
44
48
  opcodes.OP_IF,
45
49
  Generator.MAGIC,
46
50
  ];
47
- if (vaultPublicKeys.length > 0) {
48
- const pubKeyBuffer = LegacyCalldataGenerator.getPubKeyAsBuffer(vaultPublicKeys, this.network);
49
- const pubKeyDataChunks = this.splitBufferIntoChunks(pubKeyBuffer);
50
- compiledData = compiledData.concat(...[
51
- opcodes.OP_0,
52
- ...pubKeyDataChunks,
53
- ]);
54
- if (minimumSignatures) {
55
- if (minimumSignatures > 255) {
56
- throw new Error('Minimum signatures cannot exceed 255');
57
- }
58
- const minSigBuffer = Buffer.alloc(2);
59
- minSigBuffer.writeUint16LE(minimumSignatures, 0);
60
- compiledData = compiledData.concat(...[
61
- opcodes.OP_1,
62
- minSigBuffer,
63
- ]);
64
- }
65
- else {
66
- throw new Error('Minimum signatures must be provided');
67
- }
68
- }
69
51
  const featureOpcodes = features.map((feature) => FeatureOpCodes[feature]);
70
52
  compiledData = compiledData.concat(...featureOpcodes, ...[opcodes.OP_1NEGATE, ...dataChunks, opcodes.OP_ELSE, opcodes.OP_1, opcodes.OP_ENDIF]);
71
53
  const asm = compiledData.flat();
@@ -208,7 +208,10 @@ export class TransactionFactory {
208
208
  return null;
209
209
  }
210
210
  const opnet = window.opnet.web3;
211
- const interaction = await opnet.signInteraction(interactionParameters);
211
+ const interaction = await opnet.signInteraction({
212
+ ...interactionParameters,
213
+ signer: undefined,
214
+ });
212
215
  if (!interaction) {
213
216
  throw new Error('Could not sign interaction transaction.');
214
217
  }
@@ -252,10 +255,11 @@ export class TransactionFactory {
252
255
  return Buffer.concat([header, buf]).toString('hex');
253
256
  }
254
257
  getPriorityFee(params) {
255
- if (params.priorityFee < TransactionBuilder.MINIMUM_DUST) {
258
+ const totalFee = params.priorityFee + params.gasSatFee;
259
+ if (totalFee < TransactionBuilder.MINIMUM_DUST) {
256
260
  return TransactionBuilder.MINIMUM_DUST;
257
261
  }
258
- return params.priorityFee;
262
+ return totalFee;
259
263
  }
260
264
  getUTXOAsTransaction(tx, to, index) {
261
265
  if (!tx.outs[index])
@@ -1,6 +1,6 @@
1
1
  import { Network, Psbt } from '@btc-vision/bitcoin';
2
2
  import { CustomKeypair } from '../BrowserSignerBase.js';
3
- import { Unisat } from '../types/Unisat.js';
3
+ import { SignatureType, Unisat } from '../types/Unisat.js';
4
4
  declare global {
5
5
  interface Window {
6
6
  unisat?: Unisat;
@@ -21,6 +21,7 @@ export declare class UnisatSigner extends CustomKeypair {
21
21
  _network: Network | undefined;
22
22
  get network(): Network;
23
23
  get unisat(): Unisat;
24
+ signData(data: Buffer, type: SignatureType): Promise<Buffer>;
24
25
  init(): Promise<void>;
25
26
  getPublicKey(): Buffer;
26
27
  sign(_hash: Buffer, _lowR?: boolean): Buffer;
@@ -1,4 +1,4 @@
1
- import { crypto as bitCrypto, script as bitScript, networks, Psbt, toXOnly, } from '@btc-vision/bitcoin';
1
+ import { crypto as bitCrypto, networks, Psbt, script as bitScript, toXOnly, } from '@btc-vision/bitcoin';
2
2
  import { EcKeyPair } from '../../../keypair/EcKeyPair.js';
3
3
  import { canSignNonTaprootInput, isTaprootInput } from '../../../signer/SignerUtils.js';
4
4
  import { CustomKeypair } from '../BrowserSignerBase.js';
@@ -48,6 +48,11 @@ export class UnisatSigner extends CustomKeypair {
48
48
  }
49
49
  return module;
50
50
  }
51
+ async signData(data, type) {
52
+ const str = data.toString('hex');
53
+ const signature = await this.unisat.signData(str, type);
54
+ return Buffer.from(signature, 'hex');
55
+ }
51
56
  async init() {
52
57
  if (this.isInitialized) {
53
58
  return;
@@ -1,6 +1,6 @@
1
1
  import { Network, Psbt } from '@btc-vision/bitcoin';
2
2
  import { CustomKeypair } from '../BrowserSignerBase.js';
3
- import { Xverse } from '../types/Xverse.js';
3
+ import { SigningProtocol, Xverse } from '../types/Xverse.js';
4
4
  declare global {
5
5
  interface Window {
6
6
  BitcoinProvider?: Xverse;
@@ -21,6 +21,7 @@ export declare class XverseSigner extends CustomKeypair {
21
21
  get network(): Network;
22
22
  get BitcoinProvider(): Xverse;
23
23
  init(): Promise<void>;
24
+ signData(data: Buffer, address: string, protocol: SigningProtocol): Promise<Buffer>;
24
25
  getPublicKey(): Buffer;
25
26
  sign(_hash: Buffer, _lowR?: boolean): Buffer;
26
27
  signSchnorr(_hash: Buffer): Buffer;
@@ -71,6 +71,23 @@ export class XverseSigner extends CustomKeypair {
71
71
  this._addresses = [this._p2wpkh, this._p2tr];
72
72
  this.isInitialized = true;
73
73
  }
74
+ async signData(data, address, protocol) {
75
+ if (!this.isInitialized) {
76
+ throw new Error('UnisatSigner not initialized');
77
+ }
78
+ const callSign = await this.BitcoinProvider.request('signMessage', {
79
+ address,
80
+ message: data.toString(),
81
+ protocol,
82
+ });
83
+ if ('error' in callSign)
84
+ throw new Error(callSign.error.message);
85
+ const res = callSign.result;
86
+ if (!res.signature) {
87
+ throw new Error('Signature not found');
88
+ }
89
+ return Buffer.from(res.signature, 'hex');
90
+ }
74
91
  getPublicKey() {
75
92
  if (!this.isInitialized) {
76
93
  throw new Error('UnisatSigner not initialized');
@@ -27,6 +27,10 @@ export declare enum MessageType {
27
27
  ecdsa = "ecdsa",
28
28
  bip322 = "bip322-simple"
29
29
  }
30
+ export declare enum SignatureType {
31
+ ecdsa = "ecdsa",
32
+ schnorr = "schnorr"
33
+ }
30
34
  interface ToSignInputBase {
31
35
  readonly index: number;
32
36
  readonly sighashTypes?: number[];
@@ -60,6 +64,7 @@ export interface Unisat {
60
64
  getPublicKey(): Promise<string>;
61
65
  getBalance(): Promise<Balance>;
62
66
  signMessage(message: string, type?: MessageType): Promise<string>;
67
+ signData(hex: string, type?: SignatureType): Promise<string>;
63
68
  pushTx(options: {
64
69
  rawtx: string;
65
70
  }): Promise<string>;
@@ -19,3 +19,8 @@ export var MessageType;
19
19
  MessageType["ecdsa"] = "ecdsa";
20
20
  MessageType["bip322"] = "bip322-simple";
21
21
  })(MessageType || (MessageType = {}));
22
+ export var SignatureType;
23
+ (function (SignatureType) {
24
+ SignatureType["ecdsa"] = "ecdsa";
25
+ SignatureType["schnorr"] = "schnorr";
26
+ })(SignatureType || (SignatureType = {}));
@@ -76,18 +76,22 @@ interface SignedTransactionResult {
76
76
  txid: string;
77
77
  raw: string;
78
78
  }
79
+ export declare enum SigningProtocol {
80
+ ECDSA = "ECDSA",
81
+ BIP322 = "BIP322"
82
+ }
79
83
  export interface Xverse {
80
- request(method: string, params: unknown): Promise<XverseRPCResponse>;
81
- request(method: 'wallet_connect' | 'wallet_getAccount', params: null): Promise<XverseRPCGetAccountResponse>;
82
- request(method: 'wallet_disconnect', params: null): Promise<XverseRPCResponse<null>>;
83
- request(method: 'getBalance', params: null): Promise<XverseRPCGetBalanceResponse>;
84
- request(method: 'signPsbt', params: XVersePSBTInput): Promise<XverseRPCSignPsbtResponse>;
85
84
  addListener: (event: string, callback: (...args: unknown[]) => void) => void;
86
85
  createInscription: (data: InscriptionData) => Promise<InscriptionResult>;
87
86
  createRepeatInscriptions: (data: RepeatInscriptionsData) => Promise<InscriptionResult[]>;
88
87
  sendBtcTransaction: (transaction: BtcTransaction) => Promise<TransactionResult>;
89
- signMessage: (message: string) => Promise<SignedMessageResult>;
88
+ signMessage: (address: string, message: string, protocol: SigningProtocol) => Promise<SignedMessageResult>;
90
89
  signMultipleTransactions: (transactions: BtcTransaction[]) => Promise<SignedTransactionResult[]>;
91
90
  signTransaction: (transaction: BtcTransaction) => Promise<SignedTransactionResult>;
91
+ request(method: string, params: unknown): Promise<XverseRPCResponse>;
92
+ request(method: 'wallet_connect' | 'wallet_getAccount', params: null): Promise<XverseRPCGetAccountResponse>;
93
+ request(method: 'wallet_disconnect', params: null): Promise<XverseRPCResponse<null>>;
94
+ request(method: 'getBalance', params: null): Promise<XverseRPCGetBalanceResponse>;
95
+ request(method: 'signPsbt', params: XVersePSBTInput): Promise<XverseRPCSignPsbtResponse>;
92
96
  }
93
97
  export {};
@@ -4,3 +4,8 @@ export var XverseNetwork;
4
4
  XverseNetwork["testnet"] = "testnet";
5
5
  XverseNetwork["signet"] = "Signet";
6
6
  })(XverseNetwork || (XverseNetwork = {}));
7
+ export var SigningProtocol;
8
+ (function (SigningProtocol) {
9
+ SigningProtocol["ECDSA"] = "ECDSA";
10
+ SigningProtocol["BIP322"] = "BIP322";
11
+ })(SigningProtocol || (SigningProtocol = {}));
@@ -47,7 +47,7 @@ export class DeploymentTransaction extends TransactionBuilder {
47
47
  this.contractSeed = this.getContractSeed();
48
48
  this.contractSigner = EcKeyPair.fromSeedKeyPair(this.contractSeed, this.network);
49
49
  this.deploymentGenerator = new DeploymentGenerator(Buffer.from(this.signer.publicKey), this.contractSignerXOnlyPubKey(), this.network);
50
- this.compiledTargetScript = this.deploymentGenerator.compile(this.bytecode, this.randomBytes, this.preimage, this.calldata);
50
+ this.compiledTargetScript = this.deploymentGenerator.compile(this.bytecode, this.randomBytes, this.preimage, this.priorityFee, this.calldata);
51
51
  this.scriptTree = this.getScriptTree();
52
52
  this.internalInit();
53
53
  this._contractPubKey = '0x' + this.contractSeed.toString('hex');
@@ -6,7 +6,7 @@ export class InteractionTransaction extends SharedInteractionTransaction {
6
6
  this.type = TransactionType.INTERACTION;
7
7
  this.tapLeafScript = null;
8
8
  this.contractSecret = this.generateSecret();
9
- this.compiledTargetScript = this.calldataGenerator.compile(this.calldata, this.contractSecret, this.preimage);
9
+ this.compiledTargetScript = this.calldataGenerator.compile(this.calldata, this.contractSecret, this.preimage, this.priorityFee);
10
10
  this.scriptTree = this.getScriptTree();
11
11
  this.internalInit();
12
12
  }
@@ -3,7 +3,7 @@ import { TransactionBuilder } from './TransactionBuilder.js';
3
3
  import { TransactionType } from '../enums/TransactionType.js';
4
4
  import { ITransactionParameters } from '../interfaces/ITransactionParameters.js';
5
5
  import { ECPairInterface } from 'ecpair';
6
- export interface MultiSignParameters extends Omit<ITransactionParameters, 'priorityFee' | 'signer'> {
6
+ export interface MultiSignParameters extends Omit<ITransactionParameters, 'gasSatFee' | 'priorityFee' | 'signer'> {
7
7
  readonly pubkeys: Buffer[];
8
8
  readonly minimumSignatures: number;
9
9
  readonly from?: undefined;
@@ -18,6 +18,7 @@ export class MultiSignTransaction extends TransactionBuilder {
18
18
  ...parameters,
19
19
  signer: EcKeyPair.fromPrivateKey(bitcoinCrypto.sha256(Buffer.from('aaaaaaaa', 'utf-8'))),
20
20
  priorityFee: 0n,
21
+ gasSatFee: 0n,
21
22
  });
22
23
  this.type = TransactionType.MULTI_SIG;
23
24
  this.targetScriptRedeem = null;
@@ -26,6 +26,7 @@ export declare abstract class TransactionBuilder<T extends TransactionType> exte
26
26
  protected readonly network: Network;
27
27
  protected readonly feeRate: number;
28
28
  protected priorityFee: bigint;
29
+ protected gasSatFee: bigint;
29
30
  protected utxos: UTXO[];
30
31
  protected to: string | undefined;
31
32
  protected from: string;
@@ -24,6 +24,7 @@ export class TransactionBuilder extends TweakedTransaction {
24
24
  this.network = parameters.network;
25
25
  this.feeRate = parameters.feeRate;
26
26
  this.priorityFee = parameters.priorityFee ?? 0n;
27
+ this.gasSatFee = parameters.gasSatFee ?? 0n;
27
28
  this.utxos = parameters.utxos;
28
29
  this.to = parameters.to || undefined;
29
30
  this.isPubKeyDestination = this.to
@@ -76,6 +77,7 @@ export class TransactionBuilder extends TweakedTransaction {
76
77
  network: this.network,
77
78
  feeRate: this.feeRate,
78
79
  priorityFee: this.priorityFee ?? 0n,
80
+ gasSatFee: this.gasSatFee ?? 0n,
79
81
  from: this.from,
80
82
  amount: this.estimatedFees,
81
83
  optionalOutputs: this.optionalOutputs,
@@ -241,8 +243,9 @@ export class TransactionBuilder extends TweakedTransaction {
241
243
  throw new Error('Output not found');
242
244
  }
243
245
  getTransactionOPNetFee() {
244
- if (this.priorityFee > TransactionBuilder.MINIMUM_DUST) {
245
- return this.priorityFee;
246
+ const totalFee = this.priorityFee + this.gasSatFee;
247
+ if (totalFee > TransactionBuilder.MINIMUM_DUST) {
248
+ return totalFee;
246
249
  }
247
250
  return TransactionBuilder.MINIMUM_DUST;
248
251
  }
@@ -12,6 +12,7 @@ export interface ITransactionParameters extends ITweakedTransactionData {
12
12
  chainId?: ChainId;
13
13
  readonly feeRate: number;
14
14
  readonly priorityFee: bigint;
15
+ readonly gasSatFee: bigint;
15
16
  }
16
17
  export interface IFundingTransactionParameters extends ITransactionParameters {
17
18
  amount: bigint;
@@ -122,7 +122,8 @@ export class OPNetLimitedProvider {
122
122
  network,
123
123
  to: wallet.p2tr,
124
124
  splitInputsInto,
125
- priorityFee: 330n,
125
+ priorityFee: 0n,
126
+ gasSatFee: 330n,
126
127
  };
127
128
  const transactionFactory = new TransactionFactory();
128
129
  const fundingTx = await transactionFactory.createBTCTransfer(fundingTransactionParameters);
@@ -5,6 +5,7 @@ export interface ContractAddressVerificationParams {
5
5
  readonly originalSalt: Buffer;
6
6
  readonly bytecode: Buffer;
7
7
  readonly preimage: Buffer;
8
+ readonly priorityFee: bigint;
8
9
  readonly calldata?: Buffer;
9
10
  readonly network?: Network;
10
11
  }
@@ -5,7 +5,7 @@ export class TapscriptVerificator {
5
5
  static getContractAddress(params) {
6
6
  const network = params.network || networks.bitcoin;
7
7
  const scriptBuilder = new DeploymentGenerator(params.deployerPubKey, toXOnly(params.contractSaltPubKey), network);
8
- const compiledTargetScript = scriptBuilder.compile(params.bytecode, params.originalSalt, params.preimage, params.calldata);
8
+ const compiledTargetScript = scriptBuilder.compile(params.bytecode, params.originalSalt, params.preimage, params.priorityFee, params.calldata);
9
9
  const scriptTree = [
10
10
  {
11
11
  output: compiledTargetScript,
@@ -21,7 +21,7 @@ export class TapscriptVerificator {
21
21
  static verifyControlBlock(params, controlBlock) {
22
22
  const network = params.network || networks.bitcoin;
23
23
  const scriptBuilder = new DeploymentGenerator(params.deployerPubKey, toXOnly(params.contractSaltPubKey), network);
24
- const compiledTargetScript = scriptBuilder.compile(params.bytecode, params.originalSalt, params.preimage, params.calldata);
24
+ const compiledTargetScript = scriptBuilder.compile(params.bytecode, params.originalSalt, params.preimage, params.priorityFee, params.calldata);
25
25
  const scriptTree = [
26
26
  {
27
27
  output: compiledTargetScript,
package/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "@btc-vision/transaction",
3
3
  "type": "module",
4
- "version": "1.2.5",
4
+ "version": "1.2.7",
5
5
  "author": "BlobMaster41",
6
6
  "description": "OPNet transaction library allows you to create and sign transactions for the OPNet network.",
7
7
  "engines": {
8
- "node": ">=16.0.0"
8
+ "node": ">=20.0.0"
9
9
  },
10
10
  "exports": {
11
11
  ".": {
package/src/_version.ts CHANGED
@@ -1 +1 @@
1
- export const version = '1.2.5';
1
+ export const version = '1.2.7';
@@ -1,4 +1,5 @@
1
1
  import { Network, networks, toXOnly } from '@btc-vision/bitcoin';
2
+ import { BinaryWriter } from '../buffer/BinaryWriter.js';
2
3
 
3
4
  /** Bitcoin Script Generator */
4
5
  export abstract class Generator {
@@ -51,6 +52,14 @@ export abstract class Generator {
51
52
  return Buffer.from([this.senderPubKey[0], 0, 0, 0]);
52
53
  }
53
54
 
55
+ public getHeader(maxPriority: bigint): Buffer {
56
+ const writer = new BinaryWriter(8 + 4);
57
+ writer.writeBytes(this.senderFirstByte);
58
+ writer.writeU64(maxPriority);
59
+
60
+ return Buffer.from(writer.getBuffer());
61
+ }
62
+
54
63
  /**
55
64
  * Compile the script
56
65
  * @param args - The arguments to use when compiling the script