@btc-vision/transaction 1.5.4 → 1.6.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 (103) hide show
  1. package/browser/_version.d.ts +1 -1
  2. package/browser/epoch/ChallengeSolution.d.ts +45 -0
  3. package/browser/epoch/interfaces/IChallengeSolution.d.ts +50 -0
  4. package/browser/epoch/validator/EpochValidator.d.ts +19 -0
  5. package/browser/generators/Features.d.ts +6 -1
  6. package/browser/generators/Generator.d.ts +1 -0
  7. package/browser/generators/builders/CalldataGenerator.d.ts +2 -1
  8. package/browser/generators/builders/DeploymentGenerator.d.ts +3 -1
  9. package/browser/generators/builders/LegacyCalldataGenerator.d.ts +1 -1
  10. package/browser/index.js +1 -1
  11. package/browser/keypair/Address.d.ts +2 -0
  12. package/browser/opnet.d.ts +4 -3
  13. package/browser/transaction/TransactionFactory.d.ts +4 -15
  14. package/browser/transaction/browser/Web3Provider.d.ts +3 -3
  15. package/browser/transaction/builders/ChallengeSolutionTransaction.d.ts +1 -18
  16. package/browser/transaction/builders/CustomScriptTransaction.d.ts +1 -1
  17. package/browser/transaction/builders/DeploymentTransaction.d.ts +6 -4
  18. package/browser/transaction/builders/SharedInteractionTransaction.d.ts +5 -4
  19. package/browser/transaction/builders/TransactionBuilder.d.ts +2 -0
  20. package/browser/transaction/interfaces/ITransactionParameters.d.ts +4 -6
  21. package/browser/transaction/mineable/TimelockGenerator.d.ts +9 -0
  22. package/browser/utils/StringToBuffer.d.ts +1 -0
  23. package/browser/utxo/OPNetLimitedProvider.d.ts +0 -4
  24. package/browser/verification/TapscriptVerificator.d.ts +4 -1
  25. package/build/_version.d.ts +1 -1
  26. package/build/_version.js +1 -1
  27. package/build/epoch/ChallengeSolution.d.ts +45 -0
  28. package/build/epoch/ChallengeSolution.js +105 -0
  29. package/build/epoch/interfaces/IChallengeSolution.d.ts +50 -0
  30. package/build/epoch/interfaces/IChallengeSolution.js +1 -0
  31. package/build/epoch/validator/EpochValidator.d.ts +19 -0
  32. package/build/epoch/validator/EpochValidator.js +99 -0
  33. package/build/generators/Features.d.ts +6 -1
  34. package/build/generators/Features.js +1 -0
  35. package/build/generators/Generator.d.ts +1 -0
  36. package/build/generators/Generator.js +17 -1
  37. package/build/generators/builders/CalldataGenerator.d.ts +2 -1
  38. package/build/generators/builders/CalldataGenerator.js +4 -2
  39. package/build/generators/builders/DeploymentGenerator.d.ts +3 -1
  40. package/build/generators/builders/DeploymentGenerator.js +6 -4
  41. package/build/generators/builders/LegacyCalldataGenerator.d.ts +1 -1
  42. package/build/generators/builders/LegacyCalldataGenerator.js +2 -2
  43. package/build/keypair/Address.d.ts +2 -0
  44. package/build/keypair/Address.js +12 -0
  45. package/build/keypair/EcKeyPair.js +6 -3
  46. package/build/opnet.d.ts +4 -3
  47. package/build/opnet.js +4 -3
  48. package/build/transaction/TransactionFactory.d.ts +4 -15
  49. package/build/transaction/TransactionFactory.js +4 -32
  50. package/build/transaction/browser/Web3Provider.d.ts +3 -3
  51. package/build/transaction/builders/ChallengeSolutionTransaction.d.ts +0 -18
  52. package/build/transaction/builders/ChallengeSolutionTransaction.js +1 -51
  53. package/build/transaction/builders/CustomScriptTransaction.d.ts +1 -1
  54. package/build/transaction/builders/DeploymentTransaction.d.ts +6 -4
  55. package/build/transaction/builders/DeploymentTransaction.js +20 -8
  56. package/build/transaction/builders/InteractionTransaction.js +8 -1
  57. package/build/transaction/builders/SharedInteractionTransaction.d.ts +5 -4
  58. package/build/transaction/builders/SharedInteractionTransaction.js +7 -7
  59. package/build/transaction/builders/TransactionBuilder.d.ts +2 -0
  60. package/build/transaction/builders/TransactionBuilder.js +31 -3
  61. package/build/transaction/interfaces/ITransactionParameters.d.ts +4 -6
  62. package/build/transaction/mineable/TimelockGenerator.d.ts +9 -0
  63. package/build/transaction/mineable/TimelockGenerator.js +24 -0
  64. package/build/utils/StringToBuffer.d.ts +1 -0
  65. package/build/utils/StringToBuffer.js +3 -0
  66. package/build/utxo/OPNetLimitedProvider.d.ts +0 -4
  67. package/build/utxo/OPNetLimitedProvider.js +0 -7
  68. package/build/verification/TapscriptVerificator.d.ts +4 -1
  69. package/build/verification/TapscriptVerificator.js +2 -2
  70. package/package.json +15 -15
  71. package/src/_version.ts +1 -1
  72. package/src/epoch/ChallengeSolution.ts +196 -0
  73. package/src/epoch/interfaces/IChallengeSolution.ts +56 -0
  74. package/src/epoch/validator/EpochValidator.ts +180 -0
  75. package/src/generators/Features.ts +6 -0
  76. package/src/generators/Generator.ts +24 -2
  77. package/src/generators/builders/CalldataGenerator.ts +7 -3
  78. package/src/generators/builders/DeploymentGenerator.ts +18 -6
  79. package/src/generators/builders/LegacyCalldataGenerator.ts +3 -3
  80. package/src/keypair/Address.ts +34 -0
  81. package/src/keypair/EcKeyPair.ts +9 -4
  82. package/src/opnet.ts +6 -3
  83. package/src/transaction/TransactionFactory.ts +7 -62
  84. package/src/transaction/browser/Web3Provider.ts +3 -3
  85. package/src/transaction/builders/ChallengeSolutionTransaction.ts +3 -4
  86. package/src/transaction/builders/CustomScriptTransaction.ts +2 -1
  87. package/src/transaction/builders/DeploymentTransaction.ts +29 -11
  88. package/src/transaction/builders/InteractionTransaction.ts +10 -2
  89. package/src/transaction/builders/SharedInteractionTransaction.ts +12 -28
  90. package/src/transaction/builders/TransactionBuilder.ts +40 -2
  91. package/src/transaction/interfaces/ITransactionParameters.ts +5 -8
  92. package/src/transaction/mineable/TimelockGenerator.ts +42 -0
  93. package/src/utils/StringToBuffer.ts +3 -0
  94. package/src/utxo/OPNetLimitedProvider.ts +0 -17
  95. package/src/verification/TapscriptVerificator.ts +8 -4
  96. package/browser/generators/builders/MineableReward.d.ts +0 -7
  97. package/browser/transaction/mineable/ChallengeGenerator.d.ts +0 -9
  98. package/build/generators/builders/MineableReward.d.ts +0 -7
  99. package/build/generators/builders/MineableReward.js +0 -48
  100. package/build/transaction/mineable/ChallengeGenerator.d.ts +0 -9
  101. package/build/transaction/mineable/ChallengeGenerator.js +0 -28
  102. package/src/generators/builders/MineableReward.ts +0 -66
  103. package/src/transaction/mineable/ChallengeGenerator.ts +0 -39
@@ -1 +1 @@
1
- export declare const version = "1.5.3";
1
+ export declare const version = "1.6.1";
@@ -0,0 +1,45 @@
1
+ import { IChallengeSolution, IChallengeSubmission, IChallengeVerification, RawChallenge, RawChallengeSubmission, RawChallengeVerification } from './interfaces/IChallengeSolution.js';
2
+ import { Address } from '../keypair/Address.js';
3
+ export declare class ChallengeVerification implements IChallengeVerification {
4
+ readonly epochHash: Buffer;
5
+ readonly epochRoot: Buffer;
6
+ readonly targetHash: Buffer;
7
+ readonly targetChecksum: Buffer;
8
+ readonly startBlock: bigint;
9
+ readonly endBlock: bigint;
10
+ readonly proofs: readonly Buffer[];
11
+ constructor(data: RawChallengeVerification);
12
+ }
13
+ export declare class ChallengeSubmission implements IChallengeSubmission {
14
+ readonly epochNumber: bigint;
15
+ readonly publicKey: Address;
16
+ readonly solution: Buffer;
17
+ readonly graffiti: Buffer | undefined;
18
+ readonly signature: Buffer;
19
+ constructor(data: RawChallengeSubmission, epochNumber: bigint);
20
+ verifySignature(): boolean;
21
+ }
22
+ export declare class ChallengeSolution implements IChallengeSolution {
23
+ readonly epochNumber: bigint;
24
+ readonly publicKey: Address;
25
+ readonly solution: Buffer;
26
+ readonly salt: Buffer;
27
+ readonly graffiti: Buffer;
28
+ readonly difficulty: number;
29
+ readonly verification: ChallengeVerification;
30
+ private readonly submission?;
31
+ constructor(data: RawChallenge);
32
+ static validateRaw(data: RawChallenge): Promise<boolean>;
33
+ verifySubmissionSignature(): boolean;
34
+ getSubmission(): ChallengeSubmission | undefined;
35
+ verify(): Promise<boolean>;
36
+ toBuffer(): Buffer;
37
+ toHex(): string;
38
+ toRaw(): RawChallenge;
39
+ calculateSolution(): Promise<Buffer>;
40
+ checkDifficulty(minDifficulty: number): {
41
+ valid: boolean;
42
+ difficulty: number;
43
+ };
44
+ getMiningTargetBlock(): bigint | null;
45
+ }
@@ -0,0 +1,50 @@
1
+ import { Address } from '../../keypair/Address.js';
2
+ export interface IChallengeVerification {
3
+ readonly epochHash: Buffer;
4
+ readonly epochRoot: Buffer;
5
+ readonly targetHash: Buffer;
6
+ readonly targetChecksum: Buffer;
7
+ readonly startBlock: bigint;
8
+ readonly endBlock: bigint;
9
+ readonly proofs: readonly Buffer[];
10
+ }
11
+ export interface IChallengeSolution {
12
+ readonly epochNumber: bigint;
13
+ readonly publicKey: Address;
14
+ readonly solution: Buffer;
15
+ readonly salt: Buffer;
16
+ readonly graffiti: Buffer;
17
+ readonly difficulty: number;
18
+ readonly verification: IChallengeVerification;
19
+ }
20
+ export interface RawChallengeVerification {
21
+ readonly epochHash: string;
22
+ readonly epochRoot: string;
23
+ readonly targetHash: string;
24
+ readonly targetChecksum: string;
25
+ readonly startBlock: string;
26
+ readonly endBlock: string;
27
+ readonly proofs: readonly string[];
28
+ }
29
+ export interface RawChallengeSubmission {
30
+ readonly publicKey: string;
31
+ readonly solution: string;
32
+ readonly graffiti?: string;
33
+ readonly signature: string;
34
+ }
35
+ export interface IChallengeSubmission {
36
+ readonly publicKey: Address;
37
+ readonly solution: Buffer;
38
+ readonly graffiti?: Buffer;
39
+ readonly signature: Buffer;
40
+ }
41
+ export interface RawChallenge {
42
+ readonly epochNumber: string;
43
+ readonly publicKey: string;
44
+ readonly solution: string;
45
+ readonly salt: string;
46
+ readonly graffiti: string;
47
+ readonly difficulty: number;
48
+ readonly verification: RawChallengeVerification;
49
+ readonly submission?: RawChallengeSubmission;
50
+ }
@@ -0,0 +1,19 @@
1
+ import { IChallengeSolution, RawChallenge } from '../interfaces/IChallengeSolution.js';
2
+ export declare class EpochValidator {
3
+ private static readonly BLOCKS_PER_EPOCH;
4
+ private static readonly GRAFFITI_LENGTH;
5
+ static bufferToUint8Array(buffer: Buffer): Uint8Array;
6
+ static uint8ArrayToBuffer(array: Uint8Array): Buffer;
7
+ static sha1(data: Uint8Array): Promise<Uint8Array>;
8
+ static calculatePreimage(checksumRoot: Buffer, publicKey: Buffer, salt: Buffer): Buffer;
9
+ static countMatchingBits(hash1: Buffer, hash2: Buffer): number;
10
+ static verifySolution(challenge: IChallengeSolution, log?: boolean): Promise<boolean>;
11
+ static getMiningTargetBlock(epochNumber: bigint): bigint | null;
12
+ static validateEpochWinner(epochData: RawChallenge): Promise<boolean>;
13
+ static validateChallengeSolution(challenge: IChallengeSolution): Promise<boolean>;
14
+ static calculateSolution(targetChecksum: Buffer, publicKey: Buffer, salt: Buffer): Promise<Buffer>;
15
+ static checkDifficulty(solution: Buffer, targetHash: Buffer, minDifficulty: number): {
16
+ valid: boolean;
17
+ difficulty: number;
18
+ };
19
+ }
@@ -1,6 +1,8 @@
1
1
  import { LoadedStorage } from '../transaction/interfaces/ITransactionParameters.js';
2
+ import { ChallengeSubmission } from '../epoch/ChallengeSolution.js';
2
3
  export declare enum Features {
3
- ACCESS_LIST = 1
4
+ ACCESS_LIST = 1,
5
+ EPOCH_SUBMISSION = 2
4
6
  }
5
7
  export interface Feature<T extends Features> {
6
8
  opcode: T;
@@ -9,3 +11,6 @@ export interface Feature<T extends Features> {
9
11
  export interface AccessListFeature extends Feature<Features.ACCESS_LIST> {
10
12
  data: LoadedStorage;
11
13
  }
14
+ export interface EpochSubmissionFeature extends Feature<Features.EPOCH_SUBMISSION> {
15
+ data: ChallengeSubmission;
16
+ }
@@ -14,4 +14,5 @@ export declare abstract class Generator {
14
14
  protected splitBufferIntoChunks(buffer: Buffer, chunkSize?: number): Array<Buffer[]>;
15
15
  protected encodeFeature(feature: Feature<Features>): Buffer[][];
16
16
  private encodeAccessListFeature;
17
+ private encodeChallengeSubmission;
17
18
  }
@@ -1,8 +1,9 @@
1
1
  import { Network } from '@btc-vision/bitcoin';
2
2
  import { Feature, Features } from '../Features.js';
3
3
  import { Generator } from '../Generator.js';
4
+ import { ChallengeSolution } from '../../epoch/ChallengeSolution.js';
4
5
  export declare class CalldataGenerator extends Generator {
5
6
  constructor(senderPubKey: Buffer, contractSaltPubKey: Buffer, network?: Network);
6
7
  static getPubKeyAsBuffer(witnessKeys: Buffer[], network: Network): Buffer;
7
- compile(calldata: Buffer, contractSecret: Buffer, preimage: Buffer, maxPriority: bigint, features?: Feature<Features>[]): Buffer;
8
+ compile(calldata: Buffer, contractSecret: Buffer, challenge: ChallengeSolution, maxPriority: bigint, features?: Feature<Features>[]): Buffer;
8
9
  }
@@ -1,9 +1,11 @@
1
1
  import { Network } from '@btc-vision/bitcoin';
2
2
  import { Generator } from '../Generator.js';
3
+ import { Feature, Features } from '../Features.js';
4
+ import { ChallengeSolution } from '../../epoch/ChallengeSolution.js';
3
5
  export declare const OPNET_DEPLOYMENT_VERSION = 0;
4
6
  export declare const versionBuffer: Buffer<ArrayBuffer>;
5
7
  export declare class DeploymentGenerator extends Generator {
6
8
  constructor(senderPubKey: Buffer, contractSaltPubKey: Buffer, network?: Network);
7
- compile(contractBytecode: Buffer, contractSalt: Buffer, preimage: Buffer, maxPriority: bigint, calldata?: Buffer): Buffer;
9
+ compile(contractBytecode: Buffer, contractSalt: Buffer, challenge: ChallengeSolution, maxPriority: bigint, calldata?: Buffer, features?: Feature<Features>[]): Buffer;
8
10
  private getAsm;
9
11
  }
@@ -4,5 +4,5 @@ import { Feature, Features } from '../Features.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, preimage: Buffer, maxPriority: bigint, features?: Feature<Features>[]): Buffer;
7
+ compile(calldata: Buffer, contractSecret: Buffer, challenge: Buffer, maxPriority: bigint, features?: Feature<Features>[]): Buffer;
8
8
  }