@btc-vision/transaction 1.5.3 → 1.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (106) hide show
  1. package/browser/_version.d.ts +1 -1
  2. package/browser/abi/ABICoder.d.ts +1 -0
  3. package/browser/buffer/BinaryWriter.d.ts +1 -1
  4. package/browser/epoch/ChallengeSolution.d.ts +45 -0
  5. package/browser/epoch/interfaces/IChallengeSolution.d.ts +50 -0
  6. package/browser/epoch/validator/EpochValidator.d.ts +19 -0
  7. package/browser/generators/Features.d.ts +6 -1
  8. package/browser/generators/Generator.d.ts +1 -0
  9. package/browser/generators/builders/CalldataGenerator.d.ts +2 -1
  10. package/browser/generators/builders/DeploymentGenerator.d.ts +3 -1
  11. package/browser/index.js +1 -1
  12. package/browser/keypair/Address.d.ts +2 -0
  13. package/browser/opnet.d.ts +4 -3
  14. package/browser/transaction/TransactionFactory.d.ts +4 -15
  15. package/browser/transaction/browser/Web3Provider.d.ts +3 -3
  16. package/browser/transaction/browser/types/Unisat.d.ts +1 -1
  17. package/browser/transaction/builders/ChallengeSolutionTransaction.d.ts +1 -18
  18. package/browser/transaction/builders/CustomScriptTransaction.d.ts +1 -1
  19. package/browser/transaction/builders/DeploymentTransaction.d.ts +6 -4
  20. package/browser/transaction/builders/SharedInteractionTransaction.d.ts +5 -4
  21. package/browser/transaction/builders/TransactionBuilder.d.ts +2 -0
  22. package/browser/transaction/interfaces/ITransactionParameters.d.ts +4 -6
  23. package/browser/transaction/mineable/TimelockGenerator.d.ts +9 -0
  24. package/browser/utils/StringToBuffer.d.ts +1 -0
  25. package/browser/verification/TapscriptVerificator.d.ts +4 -1
  26. package/build/_version.d.ts +1 -1
  27. package/build/_version.js +1 -1
  28. package/build/abi/ABICoder.d.ts +1 -0
  29. package/build/abi/ABICoder.js +4 -0
  30. package/build/buffer/BinaryWriter.d.ts +1 -1
  31. package/build/buffer/BinaryWriter.js +11 -9
  32. package/build/epoch/ChallengeSolution.d.ts +45 -0
  33. package/build/epoch/ChallengeSolution.js +105 -0
  34. package/build/epoch/interfaces/IChallengeSolution.d.ts +50 -0
  35. package/build/epoch/interfaces/IChallengeSolution.js +1 -0
  36. package/build/epoch/validator/EpochValidator.d.ts +19 -0
  37. package/build/epoch/validator/EpochValidator.js +99 -0
  38. package/build/generators/Features.d.ts +6 -1
  39. package/build/generators/Features.js +1 -0
  40. package/build/generators/Generator.d.ts +1 -0
  41. package/build/generators/Generator.js +17 -1
  42. package/build/generators/builders/CalldataGenerator.d.ts +2 -1
  43. package/build/generators/builders/CalldataGenerator.js +4 -2
  44. package/build/generators/builders/DeploymentGenerator.d.ts +3 -1
  45. package/build/generators/builders/DeploymentGenerator.js +5 -3
  46. package/build/keypair/Address.d.ts +2 -0
  47. package/build/keypair/Address.js +12 -0
  48. package/build/keypair/EcKeyPair.js +10 -7
  49. package/build/opnet.d.ts +4 -3
  50. package/build/opnet.js +4 -3
  51. package/build/transaction/TransactionFactory.d.ts +4 -15
  52. package/build/transaction/TransactionFactory.js +4 -32
  53. package/build/transaction/browser/Web3Provider.d.ts +3 -3
  54. package/build/transaction/browser/types/Unisat.d.ts +1 -1
  55. package/build/transaction/builders/ChallengeSolutionTransaction.d.ts +0 -18
  56. package/build/transaction/builders/ChallengeSolutionTransaction.js +1 -51
  57. package/build/transaction/builders/CustomScriptTransaction.d.ts +1 -1
  58. package/build/transaction/builders/DeploymentTransaction.d.ts +6 -4
  59. package/build/transaction/builders/DeploymentTransaction.js +19 -7
  60. package/build/transaction/builders/InteractionTransaction.js +8 -1
  61. package/build/transaction/builders/SharedInteractionTransaction.d.ts +5 -4
  62. package/build/transaction/builders/SharedInteractionTransaction.js +7 -7
  63. package/build/transaction/builders/TransactionBuilder.d.ts +2 -0
  64. package/build/transaction/builders/TransactionBuilder.js +31 -3
  65. package/build/transaction/interfaces/ITransactionParameters.d.ts +4 -6
  66. package/build/transaction/mineable/TimelockGenerator.d.ts +9 -0
  67. package/build/transaction/mineable/TimelockGenerator.js +24 -0
  68. package/build/utils/StringToBuffer.d.ts +1 -0
  69. package/build/utils/StringToBuffer.js +3 -0
  70. package/build/verification/TapscriptVerificator.d.ts +4 -1
  71. package/build/verification/TapscriptVerificator.js +2 -2
  72. package/package.json +16 -16
  73. package/src/_version.ts +1 -1
  74. package/src/abi/ABICoder.ts +4 -0
  75. package/src/buffer/BinaryWriter.ts +13 -11
  76. package/src/epoch/ChallengeSolution.ts +196 -0
  77. package/src/epoch/interfaces/IChallengeSolution.ts +56 -0
  78. package/src/epoch/validator/EpochValidator.ts +180 -0
  79. package/src/generators/Features.ts +6 -0
  80. package/src/generators/Generator.ts +24 -2
  81. package/src/generators/builders/CalldataGenerator.ts +7 -3
  82. package/src/generators/builders/DeploymentGenerator.ts +18 -6
  83. package/src/keypair/Address.ts +34 -0
  84. package/src/keypair/EcKeyPair.ts +13 -8
  85. package/src/opnet.ts +6 -3
  86. package/src/transaction/TransactionFactory.ts +7 -62
  87. package/src/transaction/browser/Web3Provider.ts +3 -3
  88. package/src/transaction/browser/types/Unisat.ts +1 -1
  89. package/src/transaction/builders/ChallengeSolutionTransaction.ts +3 -4
  90. package/src/transaction/builders/CustomScriptTransaction.ts +2 -1
  91. package/src/transaction/builders/DeploymentTransaction.ts +27 -9
  92. package/src/transaction/builders/InteractionTransaction.ts +10 -2
  93. package/src/transaction/builders/SharedInteractionTransaction.ts +12 -28
  94. package/src/transaction/builders/TransactionBuilder.ts +40 -2
  95. package/src/transaction/interfaces/ITransactionParameters.ts +5 -8
  96. package/src/transaction/mineable/TimelockGenerator.ts +42 -0
  97. package/src/utils/StringToBuffer.ts +3 -0
  98. package/src/verification/TapscriptVerificator.ts +8 -4
  99. package/browser/generators/builders/MineableReward.d.ts +0 -7
  100. package/browser/transaction/mineable/ChallengeGenerator.d.ts +0 -9
  101. package/build/generators/builders/MineableReward.d.ts +0 -7
  102. package/build/generators/builders/MineableReward.js +0 -48
  103. package/build/transaction/mineable/ChallengeGenerator.d.ts +0 -9
  104. package/build/transaction/mineable/ChallengeGenerator.js +0 -28
  105. package/src/generators/builders/MineableReward.ts +0 -66
  106. package/src/transaction/mineable/ChallengeGenerator.ts +0 -39
@@ -9,14 +9,17 @@ import {
9
9
  } from '@btc-vision/bitcoin';
10
10
  import { DeploymentGenerator } from '../generators/builders/DeploymentGenerator.js';
11
11
  import { TransactionBuilder } from '../transaction/builders/TransactionBuilder.js';
12
+ import { ChallengeSolution } from '../epoch/ChallengeSolution.js';
13
+ import { Feature, Features } from '../generators/Features.js';
12
14
 
13
15
  export interface ContractAddressVerificationParams {
14
16
  readonly deployerPubKey: Buffer;
15
17
  readonly contractSaltPubKey: Buffer;
16
18
  readonly originalSalt: Buffer;
17
19
  readonly bytecode: Buffer;
18
- readonly preimage: Buffer;
20
+ readonly challenge: ChallengeSolution;
19
21
  readonly priorityFee: bigint;
22
+ readonly features: Feature<Features>[];
20
23
  readonly calldata?: Buffer;
21
24
  readonly network?: Network;
22
25
  }
@@ -37,9 +40,10 @@ export class TapscriptVerificator {
37
40
  const compiledTargetScript: Buffer = scriptBuilder.compile(
38
41
  params.bytecode,
39
42
  params.originalSalt,
40
- params.preimage,
43
+ params.challenge,
41
44
  params.priorityFee,
42
45
  params.calldata,
46
+ params.features,
43
47
  );
44
48
 
45
49
  const scriptTree: Taptree = [
@@ -70,9 +74,10 @@ export class TapscriptVerificator {
70
74
  const compiledTargetScript: Buffer = scriptBuilder.compile(
71
75
  params.bytecode,
72
76
  params.originalSalt,
73
- params.preimage,
77
+ params.challenge,
74
78
  params.priorityFee,
75
79
  params.calldata,
80
+ params.features,
76
81
  );
77
82
 
78
83
  const scriptTree: Taptree = [
@@ -91,7 +96,6 @@ export class TapscriptVerificator {
91
96
  network: network,
92
97
  scriptTree: scriptTree,
93
98
  redeem: {
94
- //pubkeys: [params.deployerPubKey, params.contractSaltPubKey],
95
99
  output: compiledTargetScript,
96
100
  redeemVersion: TapscriptVerificator.TAP_SCRIPT_VERSION,
97
101
  },
@@ -1,7 +0,0 @@
1
- import { Network } from '@btc-vision/bitcoin';
2
- import { Generator } from '../Generator.js';
3
- export declare class MineableReward extends Generator {
4
- constructor(senderPubKey: Buffer, network?: Network);
5
- compile(preimage1: Buffer): Buffer;
6
- private isTestnet;
7
- }
@@ -1,9 +0,0 @@
1
- import { Network } from '@btc-vision/bitcoin';
2
- export interface IMineableReward {
3
- address: string;
4
- p2shOutputScript: Buffer;
5
- redeemScript: Buffer;
6
- }
7
- export declare class ChallengeGenerator {
8
- static generateMineableReward(preimage1: Buffer, network: Network): IMineableReward;
9
- }
@@ -1,7 +0,0 @@
1
- import { Network } from '@btc-vision/bitcoin';
2
- import { Generator } from '../Generator.js';
3
- export declare class MineableReward extends Generator {
4
- constructor(senderPubKey: Buffer, network?: Network);
5
- compile(preimage1: Buffer): Buffer;
6
- private isTestnet;
7
- }
@@ -1,48 +0,0 @@
1
- import { networks, opcodes, script } from '@btc-vision/bitcoin';
2
- import { Generator } from '../Generator.js';
3
- export class MineableReward extends Generator {
4
- constructor(senderPubKey, network = networks.bitcoin) {
5
- super(senderPubKey, Buffer.alloc(0), network);
6
- }
7
- compile(preimage1) {
8
- let compiledData;
9
- if (this.isTestnet()) {
10
- compiledData = [
11
- preimage1,
12
- opcodes.OP_SHA1,
13
- opcodes.OP_SHA1,
14
- opcodes.OP_SWAP,
15
- opcodes.OP_SHA1,
16
- opcodes.OP_SHA1,
17
- opcodes.OP_EQUAL,
18
- ];
19
- }
20
- else {
21
- compiledData = [
22
- preimage1,
23
- opcodes.OP_SWAP,
24
- opcodes.OP_2DUP,
25
- opcodes.OP_EQUAL,
26
- opcodes.OP_NOT,
27
- opcodes.OP_VERIFY,
28
- opcodes.OP_SHA1,
29
- opcodes.OP_SHA1,
30
- opcodes.OP_SWAP,
31
- opcodes.OP_SHA1,
32
- opcodes.OP_SHA1,
33
- opcodes.OP_EQUAL,
34
- ];
35
- }
36
- const asm = compiledData.flat();
37
- const compiled = script.compile(asm);
38
- const decompiled = script.decompile(compiled);
39
- if (!decompiled) {
40
- throw new Error('Failed to decompile script??');
41
- }
42
- return compiled;
43
- }
44
- isTestnet() {
45
- return (this.network.bech32 === networks.testnet.bech32 ||
46
- this.network.bech32 === networks.regtest.bech32);
47
- }
48
- }
@@ -1,9 +0,0 @@
1
- import { Network } from '@btc-vision/bitcoin';
2
- export interface IMineableReward {
3
- address: string;
4
- p2shOutputScript: Buffer;
5
- redeemScript: Buffer;
6
- }
7
- export declare class ChallengeGenerator {
8
- static generateMineableReward(preimage1: Buffer, network: Network): IMineableReward;
9
- }
@@ -1,28 +0,0 @@
1
- import bitcoin from '@btc-vision/bitcoin';
2
- import { MineableReward } from '../../generators/builders/MineableReward.js';
3
- export class ChallengeGenerator {
4
- static generateMineableReward(preimage1, network) {
5
- const mineableReward = new MineableReward(Buffer.alloc(0), network);
6
- const redeemScript = mineableReward.compile(preimage1);
7
- const p2sh = bitcoin.payments.p2sh({
8
- redeem: { output: redeemScript },
9
- network,
10
- });
11
- const outputRedeem = p2sh.redeem?.output;
12
- if (!outputRedeem) {
13
- throw new Error('Output redeem is required');
14
- }
15
- if (!p2sh.address) {
16
- throw new Error('P2SH address is required');
17
- }
18
- const p2shOutputScript = p2sh?.redeem?.output;
19
- if (!p2shOutputScript) {
20
- throw new Error('No redeem output');
21
- }
22
- return {
23
- address: p2sh.address,
24
- p2shOutputScript,
25
- redeemScript: redeemScript,
26
- };
27
- }
28
- }
@@ -1,66 +0,0 @@
1
- import { Network, networks, opcodes, script } from '@btc-vision/bitcoin';
2
- import { Generator } from '../Generator.js';
3
-
4
- /**
5
- * Class to generate bitcoin script for interaction transactions
6
- */
7
- export class MineableReward extends Generator {
8
- constructor(senderPubKey: Buffer, network: Network = networks.bitcoin) {
9
- super(senderPubKey, Buffer.alloc(0), network);
10
- }
11
-
12
- /**
13
- * Compile an interaction bitcoin script
14
- * @param {Buffer} preimage1 - Preimage 1
15
- * @returns {Buffer} - The compiled script
16
- * @throws {Error} - If something goes wrong
17
- */
18
- public compile(preimage1: Buffer): Buffer {
19
- let compiledData: (number | Buffer)[];
20
-
21
- if (this.isTestnet()) {
22
- compiledData = [
23
- preimage1,
24
- opcodes.OP_SHA1,
25
- opcodes.OP_SHA1,
26
- opcodes.OP_SWAP,
27
- opcodes.OP_SHA1,
28
- opcodes.OP_SHA1,
29
- opcodes.OP_EQUAL,
30
- ];
31
- } else {
32
- compiledData = [
33
- preimage1,
34
- opcodes.OP_SWAP,
35
- opcodes.OP_2DUP,
36
- opcodes.OP_EQUAL,
37
- opcodes.OP_NOT,
38
- opcodes.OP_VERIFY,
39
- opcodes.OP_SHA1,
40
- opcodes.OP_SHA1,
41
- opcodes.OP_SWAP,
42
- opcodes.OP_SHA1,
43
- opcodes.OP_SHA1,
44
- opcodes.OP_EQUAL,
45
- ];
46
- }
47
-
48
- const asm = compiledData.flat();
49
- const compiled = script.compile(asm);
50
-
51
- /** Verify the validity of the script */
52
- const decompiled = script.decompile(compiled);
53
- if (!decompiled) {
54
- throw new Error('Failed to decompile script??');
55
- }
56
-
57
- return compiled;
58
- }
59
-
60
- private isTestnet(): boolean {
61
- return (
62
- this.network.bech32 === networks.testnet.bech32 ||
63
- this.network.bech32 === networks.regtest.bech32
64
- );
65
- }
66
- }
@@ -1,39 +0,0 @@
1
- import bitcoin, { Network } from '@btc-vision/bitcoin';
2
- import { MineableReward } from '../../generators/builders/MineableReward.js';
3
-
4
- export interface IMineableReward {
5
- address: string;
6
- p2shOutputScript: Buffer;
7
- redeemScript: Buffer;
8
- }
9
-
10
- export class ChallengeGenerator {
11
- public static generateMineableReward(preimage1: Buffer, network: Network): IMineableReward {
12
- const mineableReward = new MineableReward(Buffer.alloc(0), network);
13
- const redeemScript = mineableReward.compile(preimage1);
14
- const p2sh = bitcoin.payments.p2sh({
15
- redeem: { output: redeemScript },
16
- network,
17
- });
18
-
19
- const outputRedeem: Buffer | undefined = p2sh.redeem?.output;
20
- if (!outputRedeem) {
21
- throw new Error('Output redeem is required');
22
- }
23
-
24
- if (!p2sh.address) {
25
- throw new Error('P2SH address is required');
26
- }
27
-
28
- const p2shOutputScript: Buffer | undefined = p2sh?.redeem?.output;
29
- if (!p2shOutputScript) {
30
- throw new Error('No redeem output');
31
- }
32
-
33
- return {
34
- address: p2sh.address,
35
- p2shOutputScript,
36
- redeemScript: redeemScript,
37
- };
38
- }
39
- }