@btc-vision/transaction 1.2.2 → 1.2.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.
- package/browser/_version.d.ts +1 -1
- package/browser/crypto/crypto-browser.d.ts +1 -1
- package/browser/generators/builders/CalldataGenerator.d.ts +1 -1
- package/browser/generators/builders/DeploymentGenerator.d.ts +1 -1
- package/browser/generators/builders/MineableReward.d.ts +7 -0
- package/browser/index.js +1 -1
- package/browser/opnet.d.ts +4 -0
- package/browser/transaction/TransactionFactory.d.ts +19 -4
- package/browser/transaction/browser/WalletConnection.d.ts +18 -0
- package/browser/transaction/browser/types/Xverse.d.ts +24 -10
- package/browser/transaction/builders/ChallengeSolutionTransaction.d.ts +18 -0
- package/browser/transaction/builders/DeploymentTransaction.d.ts +4 -0
- package/browser/transaction/builders/SharedInteractionTransaction.d.ts +5 -0
- package/browser/transaction/builders/TransactionBuilder.d.ts +2 -0
- package/browser/transaction/enums/TransactionType.d.ts +3 -4
- package/browser/transaction/interfaces/ITransactionParameters.d.ts +6 -0
- package/browser/transaction/mineable/ChallengeGenerator.d.ts +9 -0
- package/browser/utxo/interfaces/IUTXO.d.ts +1 -1
- package/browser/verification/TapscriptVerificator.d.ts +1 -1
- package/build/_version.d.ts +1 -1
- package/build/_version.js +1 -1
- package/build/generators/Generator.js +1 -1
- package/build/generators/builders/CalldataGenerator.d.ts +1 -1
- package/build/generators/builders/CalldataGenerator.js +7 -26
- package/build/generators/builders/DeploymentGenerator.d.ts +1 -1
- package/build/generators/builders/DeploymentGenerator.js +9 -6
- package/build/generators/builders/LegacyCalldataGenerator.js +5 -1
- package/build/generators/builders/MineableReward.d.ts +7 -0
- package/build/generators/builders/MineableReward.js +47 -0
- package/build/opnet.d.ts +4 -0
- package/build/opnet.js +4 -0
- package/build/transaction/TransactionFactory.d.ts +19 -4
- package/build/transaction/TransactionFactory.js +32 -0
- package/build/transaction/browser/WalletConnection.d.ts +18 -0
- package/build/transaction/browser/WalletConnection.js +95 -0
- package/build/transaction/browser/extensions/UnisatSigner.js +5 -2
- package/build/transaction/browser/extensions/XverseSigner.js +15 -9
- package/build/transaction/browser/types/Xverse.d.ts +24 -10
- package/build/transaction/builders/ChallengeSolutionTransaction.d.ts +18 -0
- package/build/transaction/builders/ChallengeSolutionTransaction.js +51 -0
- package/build/transaction/builders/DeploymentTransaction.d.ts +4 -0
- package/build/transaction/builders/DeploymentTransaction.js +23 -4
- package/build/transaction/builders/InteractionTransaction.js +1 -1
- package/build/transaction/builders/SharedInteractionTransaction.d.ts +5 -0
- package/build/transaction/builders/SharedInteractionTransaction.js +35 -13
- package/build/transaction/builders/TransactionBuilder.d.ts +2 -0
- package/build/transaction/builders/TransactionBuilder.js +2 -0
- package/build/transaction/enums/TransactionType.d.ts +3 -4
- package/build/transaction/enums/TransactionType.js +3 -4
- package/build/transaction/interfaces/ITransactionParameters.d.ts +6 -0
- package/build/transaction/mineable/ChallengeGenerator.d.ts +9 -0
- package/build/transaction/mineable/ChallengeGenerator.js +28 -0
- package/build/transaction/shared/TweakedTransaction.js +1 -1
- package/build/utxo/interfaces/IUTXO.d.ts +1 -1
- package/build/verification/TapscriptVerificator.d.ts +1 -1
- package/build/verification/TapscriptVerificator.js +2 -8
- package/package.json +3 -3
- package/src/_version.ts +1 -1
- package/src/generators/Generator.ts +1 -1
- package/src/generators/builders/CalldataGenerator.ts +10 -41
- package/src/generators/builders/DeploymentGenerator.ts +18 -7
- package/src/generators/builders/LegacyCalldataGenerator.ts +5 -1
- package/src/generators/builders/MineableReward.ts +63 -0
- package/src/opnet.ts +5 -0
- package/src/transaction/TransactionFactory.ts +66 -3
- package/src/transaction/browser/WalletConnection.ts +110 -0
- package/src/transaction/browser/extensions/UnisatSigner.ts +7 -3
- package/src/transaction/browser/extensions/XverseSigner.ts +24 -23
- package/src/transaction/browser/types/Xverse.ts +50 -36
- package/src/transaction/builders/ChallengeSolutionTransaction.ts +88 -0
- package/src/transaction/builders/DeploymentTransaction.ts +46 -3
- package/src/transaction/builders/InteractionTransaction.ts +1 -0
- package/src/transaction/builders/SharedInteractionTransaction.ts +54 -14
- package/src/transaction/builders/TransactionBuilder.ts +3 -0
- package/src/transaction/enums/TransactionType.ts +3 -4
- package/src/transaction/interfaces/ITransactionParameters.ts +8 -15
- package/src/transaction/mineable/ChallengeGenerator.ts +39 -0
- package/src/transaction/shared/TweakedTransaction.ts +1 -1
- package/src/utxo/interfaces/IUTXO.ts +1 -1
- package/src/verification/TapscriptVerificator.ts +3 -18
package/browser/opnet.d.ts
CHANGED
|
@@ -5,8 +5,10 @@ export * from './generators/builders/CustomGenerator.js';
|
|
|
5
5
|
export * from './generators/builders/DeploymentGenerator.js';
|
|
6
6
|
export * from './generators/builders/LegacyCalldataGenerator.js';
|
|
7
7
|
export * from './generators/builders/MultiSignGenerator.js';
|
|
8
|
+
export * from './generators/builders/MineableReward.js';
|
|
8
9
|
export * from './generators/Features.js';
|
|
9
10
|
export * from './generators/Generator.js';
|
|
11
|
+
export * from './transaction/mineable/ChallengeGenerator.js';
|
|
10
12
|
export * from './generators/AddressGenerator.js';
|
|
11
13
|
export * from './verification/TapscriptVerificator.js';
|
|
12
14
|
export * from './keypair/AddressVerificator.js';
|
|
@@ -28,6 +30,7 @@ export * from './transaction/builders/InteractionTransaction.js';
|
|
|
28
30
|
export * from './transaction/builders/MultiSignTransaction.js';
|
|
29
31
|
export * from './transaction/builders/SharedInteractionTransaction.js';
|
|
30
32
|
export * from './transaction/builders/TransactionBuilder.js';
|
|
33
|
+
export * from './transaction/builders/ChallengeSolutionTransaction.js';
|
|
31
34
|
export * from './utils/BitcoinUtils.js';
|
|
32
35
|
export * from './utils/lengths.js';
|
|
33
36
|
export * from './utxo/interfaces/IUTXO.js';
|
|
@@ -56,6 +59,7 @@ export * from './transaction/browser/extensions/UnisatSigner.js';
|
|
|
56
59
|
export * from './transaction/browser/extensions/XverseSigner.js';
|
|
57
60
|
export * from './transaction/browser/types/Unisat.js';
|
|
58
61
|
export * from './transaction/browser/types/Xverse.js';
|
|
62
|
+
export * from './transaction/browser/WalletConnection.js';
|
|
59
63
|
export * from './metadata/tokens.js';
|
|
60
64
|
export * from './transaction/browser/Web3Provider.js';
|
|
61
65
|
export * from './transaction/ContractAddress.js';
|
|
@@ -4,12 +4,14 @@ import { ICustomTransactionParameters } from './builders/CustomScriptTransaction
|
|
|
4
4
|
import { FundingTransaction } from './builders/FundingTransaction.js';
|
|
5
5
|
import { TransactionBuilder } from './builders/TransactionBuilder.js';
|
|
6
6
|
import { TransactionType } from './enums/TransactionType.js';
|
|
7
|
-
import { IDeploymentParameters, IFundingTransactionParameters, IInteractionParameters } from './interfaces/ITransactionParameters.js';
|
|
7
|
+
import { IChallengeSolutionTransactionParameters, IDeploymentParameters, IFundingTransactionParameters, IInteractionParameters } from './interfaces/ITransactionParameters.js';
|
|
8
|
+
import { ChallengeSolutionTransaction } from './builders/ChallengeSolutionTransaction.js';
|
|
8
9
|
export interface DeploymentResult {
|
|
9
10
|
readonly transaction: [string, string];
|
|
10
11
|
readonly contractAddress: string;
|
|
11
12
|
readonly contractPubKey: string;
|
|
12
13
|
readonly p2trAddress: string;
|
|
14
|
+
readonly preimage: string;
|
|
13
15
|
readonly utxos: UTXO[];
|
|
14
16
|
}
|
|
15
17
|
export interface WrapResult {
|
|
@@ -25,18 +27,31 @@ export interface FundingTransactionResponse {
|
|
|
25
27
|
readonly estimatedFees: bigint;
|
|
26
28
|
readonly nextUTXOs: UTXO[];
|
|
27
29
|
}
|
|
28
|
-
export interface
|
|
30
|
+
export interface ChallengeSolutionResponse {
|
|
31
|
+
readonly tx: Transaction;
|
|
32
|
+
readonly original: ChallengeSolutionTransaction;
|
|
33
|
+
readonly estimatedFees: bigint;
|
|
34
|
+
readonly nextUTXOs: UTXO[];
|
|
35
|
+
}
|
|
36
|
+
export interface BitcoinTransferBase {
|
|
29
37
|
readonly tx: string;
|
|
30
|
-
readonly original: FundingTransaction;
|
|
31
38
|
readonly estimatedFees: bigint;
|
|
32
39
|
readonly nextUTXOs: UTXO[];
|
|
33
40
|
}
|
|
41
|
+
export interface ChallengeSolution extends BitcoinTransferBase {
|
|
42
|
+
readonly original: ChallengeSolutionTransaction;
|
|
43
|
+
}
|
|
44
|
+
export interface BitcoinTransferResponse extends BitcoinTransferBase {
|
|
45
|
+
readonly original: FundingTransaction;
|
|
46
|
+
}
|
|
34
47
|
export declare class TransactionFactory {
|
|
35
48
|
createCustomScriptTransaction(interactionParameters: ICustomTransactionParameters): Promise<[string, string, UTXO[]]>;
|
|
36
|
-
signInteraction(interactionParameters: IInteractionParameters): Promise<[string, string, UTXO[]]>;
|
|
49
|
+
signInteraction(interactionParameters: IInteractionParameters): Promise<[string, string, UTXO[], string]>;
|
|
37
50
|
signDeployment(deploymentParameters: IDeploymentParameters): Promise<DeploymentResult>;
|
|
38
51
|
createBTCTransfer(parameters: IFundingTransactionParameters): Promise<BitcoinTransferResponse>;
|
|
52
|
+
createChallengeSolution(parameters: IChallengeSolutionTransactionParameters): Promise<ChallengeSolution>;
|
|
39
53
|
getAllNewUTXOs(original: TransactionBuilder<TransactionType>, tx: Transaction, to: string): UTXO[];
|
|
54
|
+
private _createChallengeSolution;
|
|
40
55
|
private createFundTransaction;
|
|
41
56
|
private writePSBTHeader;
|
|
42
57
|
private getPriorityFee;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { Address } from '../../opnet.js';
|
|
2
|
+
import { UnisatSigner } from './extensions/UnisatSigner.js';
|
|
3
|
+
import { XverseSigner } from './extensions/XverseSigner.js';
|
|
4
|
+
export declare enum SupportedWallets {
|
|
5
|
+
Unisat = "unisat",
|
|
6
|
+
Xverse = "xverse"
|
|
7
|
+
}
|
|
8
|
+
export declare class WalletConnection {
|
|
9
|
+
wallet_type: SupportedWallets | null;
|
|
10
|
+
private unisatSigner;
|
|
11
|
+
private xverseSigner;
|
|
12
|
+
connect(): Promise<void>;
|
|
13
|
+
disconnect(): Promise<void>;
|
|
14
|
+
switchTo(walletType: SupportedWallets): Promise<void>;
|
|
15
|
+
getAddress(): Address;
|
|
16
|
+
getSigner(): UnisatSigner | XverseSigner;
|
|
17
|
+
}
|
|
18
|
+
export default WalletConnection;
|
|
@@ -3,12 +3,11 @@ export declare enum XverseNetwork {
|
|
|
3
3
|
testnet = "testnet",
|
|
4
4
|
signet = "Signet"
|
|
5
5
|
}
|
|
6
|
-
|
|
6
|
+
type XverseRPCResponse<T = unknown> = {
|
|
7
7
|
id: string;
|
|
8
8
|
jsonrpc: string;
|
|
9
9
|
result: T;
|
|
10
|
-
}
|
|
11
|
-
export type XverseRPCError = {
|
|
10
|
+
} | {
|
|
12
11
|
id: string;
|
|
13
12
|
jsonrpc: string;
|
|
14
13
|
error: {
|
|
@@ -16,17 +15,29 @@ export type XverseRPCError = {
|
|
|
16
15
|
message: string;
|
|
17
16
|
};
|
|
18
17
|
};
|
|
19
|
-
|
|
18
|
+
type XverseRPCGetAccountResponse = XverseRPCResponse<{
|
|
20
19
|
addresses: {
|
|
21
20
|
address: string;
|
|
22
21
|
addressType: string;
|
|
23
22
|
publicKey: string;
|
|
24
|
-
purpose:
|
|
23
|
+
purpose: 'stacks' | 'payment' | 'ordinals';
|
|
25
24
|
}[];
|
|
26
|
-
|
|
27
|
-
|
|
25
|
+
walletType: string;
|
|
26
|
+
}>;
|
|
27
|
+
type XverseRPCSignPsbtResponse = XverseRPCResponse<{
|
|
28
|
+
psbt: string;
|
|
29
|
+
}>;
|
|
30
|
+
type XverseRPCGetBalanceResponse = XverseRPCResponse<{
|
|
31
|
+
confirmed: string;
|
|
32
|
+
total: string;
|
|
33
|
+
unconfirmed: string;
|
|
34
|
+
}>;
|
|
35
|
+
export type XVersePSBTInput = {
|
|
28
36
|
psbt: string;
|
|
29
|
-
|
|
37
|
+
signInputs: {
|
|
38
|
+
[x: string]: number[];
|
|
39
|
+
} | undefined;
|
|
40
|
+
};
|
|
30
41
|
interface InscriptionData {
|
|
31
42
|
address: string;
|
|
32
43
|
amount: number;
|
|
@@ -66,11 +77,14 @@ interface SignedTransactionResult {
|
|
|
66
77
|
raw: string;
|
|
67
78
|
}
|
|
68
79
|
export interface Xverse {
|
|
69
|
-
|
|
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>;
|
|
70
85
|
addListener: (event: string, callback: (...args: unknown[]) => void) => void;
|
|
71
86
|
createInscription: (data: InscriptionData) => Promise<InscriptionResult>;
|
|
72
87
|
createRepeatInscriptions: (data: RepeatInscriptionsData) => Promise<InscriptionResult[]>;
|
|
73
|
-
request: (method: string, params: unknown) => Promise<XverseRPCResponse>;
|
|
74
88
|
sendBtcTransaction: (transaction: BtcTransaction) => Promise<TransactionResult>;
|
|
75
89
|
signMessage: (message: string) => Promise<SignedMessageResult>;
|
|
76
90
|
signMultipleTransactions: (transactions: BtcTransaction[]) => Promise<SignedTransactionResult[]>;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { TransactionType } from '../enums/TransactionType.js';
|
|
2
|
+
import { IChallengeSolutionTransactionParameters } from '../interfaces/ITransactionParameters.js';
|
|
3
|
+
import { Psbt, PsbtInput, Signer } from '@btc-vision/bitcoin';
|
|
4
|
+
import { TransactionBuilder } from './TransactionBuilder.js';
|
|
5
|
+
import { ECPairInterface } from 'ecpair';
|
|
6
|
+
export declare class ChallengeSolutionTransaction extends TransactionBuilder<TransactionType.CHALLENGE_SOLUTION> {
|
|
7
|
+
readonly type: TransactionType.CHALLENGE_SOLUTION;
|
|
8
|
+
protected amount: bigint;
|
|
9
|
+
protected readonly challengeSolution: Buffer;
|
|
10
|
+
constructor(parameters: IChallengeSolutionTransactionParameters);
|
|
11
|
+
protected buildTransaction(): Promise<void>;
|
|
12
|
+
protected signInput(transaction: Psbt, input: PsbtInput, i: number, signer: Signer | ECPairInterface, reverse?: boolean, errored?: boolean): Promise<void>;
|
|
13
|
+
protected customFinalizerP2SH: (inputIndex: number, input: PsbtInput, scriptA: Buffer, isSegwit: boolean, isP2SH: boolean, isP2WSH: boolean) => {
|
|
14
|
+
finalScriptSig: Buffer | undefined;
|
|
15
|
+
finalScriptWitness: Buffer | undefined;
|
|
16
|
+
};
|
|
17
|
+
protected getSignerKey(): Signer | ECPairInterface;
|
|
18
|
+
}
|
|
@@ -4,9 +4,12 @@ import { Payment, Psbt } from '@btc-vision/bitcoin';
|
|
|
4
4
|
import { TransactionBuilder } from './TransactionBuilder.js';
|
|
5
5
|
import { TapLeafScript } from '../interfaces/Tap.js';
|
|
6
6
|
import { Address } from '../../keypair/Address.js';
|
|
7
|
+
import { IMineableReward } from '../mineable/ChallengeGenerator.js';
|
|
7
8
|
export declare class DeploymentTransaction extends TransactionBuilder<TransactionType.DEPLOYMENT> {
|
|
8
9
|
static readonly MAXIMUM_CONTRACT_SIZE: number;
|
|
9
10
|
type: TransactionType.DEPLOYMENT;
|
|
11
|
+
protected readonly preimage: Buffer;
|
|
12
|
+
protected readonly rewardChallenge: IMineableReward;
|
|
10
13
|
protected readonly _contractAddress: Address;
|
|
11
14
|
protected tapLeafScript: TapLeafScript | null;
|
|
12
15
|
private targetScriptRedeem;
|
|
@@ -25,6 +28,7 @@ export declare class DeploymentTransaction extends TransactionBuilder<Transactio
|
|
|
25
28
|
get contractAddress(): Address;
|
|
26
29
|
get p2trAddress(): string;
|
|
27
30
|
getRndBytes(): Buffer;
|
|
31
|
+
getPreimage(): Buffer;
|
|
28
32
|
protected contractSignerXOnlyPubKey(): Buffer;
|
|
29
33
|
protected buildTransaction(): Promise<void>;
|
|
30
34
|
protected signInputsWalletBased(transaction: Psbt): Promise<void>;
|
|
@@ -4,6 +4,7 @@ import { TransactionBuilder } from './TransactionBuilder.js';
|
|
|
4
4
|
import { TransactionType } from '../enums/TransactionType.js';
|
|
5
5
|
import { CalldataGenerator } from '../../generators/builders/CalldataGenerator.js';
|
|
6
6
|
import { SharedInteractionParameters } from '../interfaces/ITransactionParameters.js';
|
|
7
|
+
import { IMineableReward } from '../mineable/ChallengeGenerator.js';
|
|
7
8
|
export declare abstract class SharedInteractionTransaction<T extends TransactionType> extends TransactionBuilder<T> {
|
|
8
9
|
static readonly MAXIMUM_CALLDATA_SIZE: number;
|
|
9
10
|
readonly randomBytes: Buffer;
|
|
@@ -11,6 +12,8 @@ export declare abstract class SharedInteractionTransaction<T extends Transaction
|
|
|
11
12
|
protected leftOverFundsScriptRedeem: Payment | null;
|
|
12
13
|
protected abstract readonly compiledTargetScript: Buffer;
|
|
13
14
|
protected abstract readonly scriptTree: Taptree;
|
|
15
|
+
protected readonly preimage: Buffer;
|
|
16
|
+
protected readonly rewardChallenge: IMineableReward;
|
|
14
17
|
protected calldataGenerator: CalldataGenerator;
|
|
15
18
|
protected readonly calldata: Buffer;
|
|
16
19
|
protected abstract readonly contractSecret: Buffer;
|
|
@@ -19,6 +22,7 @@ export declare abstract class SharedInteractionTransaction<T extends Transaction
|
|
|
19
22
|
protected constructor(parameters: SharedInteractionParameters);
|
|
20
23
|
getContractSecret(): Buffer;
|
|
21
24
|
getRndBytes(): Buffer;
|
|
25
|
+
getPreimage(): Buffer;
|
|
22
26
|
protected generateSecret(): Buffer;
|
|
23
27
|
protected scriptSignerXOnlyPubKey(): Buffer;
|
|
24
28
|
protected generateKeyPairFromSeed(): ECPairInterface;
|
|
@@ -32,6 +36,7 @@ export declare abstract class SharedInteractionTransaction<T extends Transaction
|
|
|
32
36
|
finalScriptWitness: Buffer<ArrayBufferLike>;
|
|
33
37
|
};
|
|
34
38
|
protected signInputsWalletBased(transaction: Psbt): Promise<void>;
|
|
39
|
+
private createMineableRewardOutputs;
|
|
35
40
|
private signInputsNonWalletBased;
|
|
36
41
|
private getPubKeys;
|
|
37
42
|
private generateRedeemScripts;
|
|
@@ -6,6 +6,8 @@ import { UTXO } from '../../utxo/interfaces/IUTXO.js';
|
|
|
6
6
|
import { ECPairInterface } from 'ecpair';
|
|
7
7
|
import { TweakedTransaction } from '../shared/TweakedTransaction.js';
|
|
8
8
|
import { UnisatSigner } from '../browser/extensions/UnisatSigner.js';
|
|
9
|
+
export declare const MINIMUM_AMOUNT_REWARD: bigint;
|
|
10
|
+
export declare const MINIMUM_AMOUNT_CA: bigint;
|
|
9
11
|
export declare abstract class TransactionBuilder<T extends TransactionType> extends TweakedTransaction {
|
|
10
12
|
static readonly LOCK_LEAF_SCRIPT: Buffer;
|
|
11
13
|
static readonly MINIMUM_DUST: bigint;
|
|
@@ -17,9 +17,14 @@ export interface IFundingTransactionParameters extends ITransactionParameters {
|
|
|
17
17
|
amount: bigint;
|
|
18
18
|
splitInputsInto?: number;
|
|
19
19
|
}
|
|
20
|
+
export interface IChallengeSolutionTransactionParameters extends ITransactionParameters {
|
|
21
|
+
amount: bigint;
|
|
22
|
+
readonly challengeSolution: Buffer;
|
|
23
|
+
}
|
|
20
24
|
export interface SharedInteractionParameters extends ITransactionParameters {
|
|
21
25
|
calldata?: Buffer;
|
|
22
26
|
disableAutoRefund?: boolean;
|
|
27
|
+
readonly preimage?: Buffer;
|
|
23
28
|
readonly randomBytes?: Buffer;
|
|
24
29
|
}
|
|
25
30
|
export interface IInteractionParameters extends SharedInteractionParameters {
|
|
@@ -30,4 +35,5 @@ export interface IDeploymentParameters extends Omit<ITransactionParameters, 'to'
|
|
|
30
35
|
readonly bytecode: Buffer;
|
|
31
36
|
readonly calldata?: Buffer;
|
|
32
37
|
readonly randomBytes?: Buffer;
|
|
38
|
+
readonly preimage?: Buffer;
|
|
33
39
|
}
|
|
@@ -0,0 +1,9 @@
|
|
|
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
|
+
}
|
|
@@ -4,6 +4,7 @@ export interface ContractAddressVerificationParams {
|
|
|
4
4
|
readonly contractSaltPubKey: Buffer;
|
|
5
5
|
readonly originalSalt: Buffer;
|
|
6
6
|
readonly bytecode: Buffer;
|
|
7
|
+
readonly preimage: Buffer;
|
|
7
8
|
readonly calldata?: Buffer;
|
|
8
9
|
readonly network?: Network;
|
|
9
10
|
}
|
|
@@ -12,6 +13,5 @@ export declare class TapscriptVerificator {
|
|
|
12
13
|
static getContractAddress(params: ContractAddressVerificationParams): string | undefined;
|
|
13
14
|
static verifyControlBlock(params: ContractAddressVerificationParams, controlBlock: Buffer): boolean;
|
|
14
15
|
static getContractSeed(deployerPubKey: Buffer, bytecode: Buffer, saltHash: Buffer): Buffer;
|
|
15
|
-
static generateContractVirtualAddress(deployerPubKey: Buffer, bytecode: Buffer, saltHash: Buffer, network?: Network): string;
|
|
16
16
|
static generateAddressFromScript(params: ContractAddressVerificationParams, scriptTree: Taptree): string | undefined;
|
|
17
17
|
}
|
package/build/_version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const version = "1.2.
|
|
1
|
+
export declare const version = "1.2.3";
|
package/build/_version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const version = '1.2.
|
|
1
|
+
export const version = '1.2.3';
|
|
@@ -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,
|
|
7
|
+
compile(calldata: Buffer, contractSecret: Buffer, preimage: Buffer, features?: Features[]): Buffer;
|
|
8
8
|
}
|
|
@@ -25,7 +25,7 @@ export class CalldataGenerator extends Generator {
|
|
|
25
25
|
}
|
|
26
26
|
return compressed;
|
|
27
27
|
}
|
|
28
|
-
compile(calldata, contractSecret,
|
|
28
|
+
compile(calldata, contractSecret, preimage, features = []) {
|
|
29
29
|
if (!this.contractSaltPubKey)
|
|
30
30
|
throw new Error('Contract salt public key not set');
|
|
31
31
|
const dataChunks = this.splitBufferIntoChunks(calldata);
|
|
@@ -34,14 +34,17 @@ export class CalldataGenerator extends Generator {
|
|
|
34
34
|
let compiledData = [
|
|
35
35
|
this.senderFirstByte,
|
|
36
36
|
opcodes.OP_TOALTSTACK,
|
|
37
|
+
preimage,
|
|
38
|
+
opcodes.OP_TOALTSTACK,
|
|
37
39
|
this.xSenderPubKey,
|
|
40
|
+
opcodes.OP_DUP,
|
|
41
|
+
opcodes.OP_HASH256,
|
|
42
|
+
crypto.hash256(this.xSenderPubKey),
|
|
43
|
+
opcodes.OP_EQUALVERIFY,
|
|
38
44
|
opcodes.OP_CHECKSIGVERIFY,
|
|
39
45
|
this.contractSaltPubKey,
|
|
40
46
|
opcodes.OP_CHECKSIGVERIFY,
|
|
41
47
|
opcodes.OP_HASH160,
|
|
42
|
-
crypto.hash160(this.xSenderPubKey),
|
|
43
|
-
opcodes.OP_EQUALVERIFY,
|
|
44
|
-
opcodes.OP_HASH160,
|
|
45
48
|
crypto.hash160(contractSecret),
|
|
46
49
|
opcodes.OP_EQUALVERIFY,
|
|
47
50
|
opcodes.OP_DEPTH,
|
|
@@ -50,28 +53,6 @@ export class CalldataGenerator extends Generator {
|
|
|
50
53
|
opcodes.OP_IF,
|
|
51
54
|
Generator.MAGIC,
|
|
52
55
|
];
|
|
53
|
-
if (vaultPublicKeys.length > 0) {
|
|
54
|
-
const pubKeyBuffer = CalldataGenerator.getPubKeyAsBuffer(vaultPublicKeys, this.network);
|
|
55
|
-
const pubKeyDataChunks = this.splitBufferIntoChunks(pubKeyBuffer);
|
|
56
|
-
compiledData = compiledData.concat(...[
|
|
57
|
-
opcodes.OP_0,
|
|
58
|
-
...pubKeyDataChunks,
|
|
59
|
-
]);
|
|
60
|
-
if (minimumSignatures) {
|
|
61
|
-
if (minimumSignatures > 255) {
|
|
62
|
-
throw new Error('Minimum signatures cannot exceed 255');
|
|
63
|
-
}
|
|
64
|
-
const minSigBuffer = Buffer.alloc(2);
|
|
65
|
-
minSigBuffer.writeUint16LE(minimumSignatures, 0);
|
|
66
|
-
compiledData = compiledData.concat(...[
|
|
67
|
-
opcodes.OP_1,
|
|
68
|
-
minSigBuffer,
|
|
69
|
-
]);
|
|
70
|
-
}
|
|
71
|
-
else {
|
|
72
|
-
throw new Error('Minimum signatures must be provided');
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
56
|
const featureOpcodes = features.map((feature) => FeatureOpCodes[feature]);
|
|
76
57
|
compiledData = compiledData.concat(...featureOpcodes, ...[opcodes.OP_1NEGATE, ...dataChunks, opcodes.OP_ELSE, opcodes.OP_1, opcodes.OP_ENDIF]);
|
|
77
58
|
const asm = compiledData.flat();
|
|
@@ -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, calldata?: Buffer): Buffer;
|
|
5
|
+
compile(contractBytecode: Buffer, contractSalt: Buffer, preimage: Buffer, 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, calldata) {
|
|
8
|
-
const asm = this.getAsm(contractBytecode, contractSalt, calldata);
|
|
7
|
+
compile(contractBytecode, contractSalt, preimage, calldata) {
|
|
8
|
+
const asm = this.getAsm(contractBytecode, contractSalt, preimage, calldata);
|
|
9
9
|
const compiled = script.compile(asm);
|
|
10
10
|
const decompiled = script.decompile(compiled);
|
|
11
11
|
if (!decompiled) {
|
|
@@ -13,7 +13,7 @@ export class DeploymentGenerator extends Generator {
|
|
|
13
13
|
}
|
|
14
14
|
return compiled;
|
|
15
15
|
}
|
|
16
|
-
getAsm(contractBytecode, contractSalt, calldata) {
|
|
16
|
+
getAsm(contractBytecode, contractSalt, preimage, calldata) {
|
|
17
17
|
if (!this.contractSaltPubKey)
|
|
18
18
|
throw new Error('Contract salt public key not set');
|
|
19
19
|
const dataChunks = this.splitBufferIntoChunks(contractBytecode);
|
|
@@ -21,13 +21,16 @@ export class DeploymentGenerator extends Generator {
|
|
|
21
21
|
const compiledData = [
|
|
22
22
|
this.senderFirstByte,
|
|
23
23
|
opcodes.OP_TOALTSTACK,
|
|
24
|
+
preimage,
|
|
25
|
+
opcodes.OP_TOALTSTACK,
|
|
24
26
|
this.xSenderPubKey,
|
|
27
|
+
opcodes.OP_DUP,
|
|
28
|
+
opcodes.OP_HASH256,
|
|
29
|
+
crypto.hash256(this.xSenderPubKey),
|
|
30
|
+
opcodes.OP_EQUALVERIFY,
|
|
25
31
|
opcodes.OP_CHECKSIGVERIFY,
|
|
26
32
|
this.contractSaltPubKey,
|
|
27
33
|
opcodes.OP_CHECKSIGVERIFY,
|
|
28
|
-
opcodes.OP_HASH160,
|
|
29
|
-
crypto.hash160(this.xSenderPubKey),
|
|
30
|
-
opcodes.OP_EQUALVERIFY,
|
|
31
34
|
opcodes.OP_HASH256,
|
|
32
35
|
crypto.hash256(contractSalt),
|
|
33
36
|
opcodes.OP_EQUALVERIFY,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { networks, opcodes, script } from '@btc-vision/bitcoin';
|
|
1
|
+
import { crypto, networks, opcodes, script } from '@btc-vision/bitcoin';
|
|
2
2
|
import { Compressor } from '../../bytecode/Compressor.js';
|
|
3
3
|
import { EcKeyPair } from '../../keypair/EcKeyPair.js';
|
|
4
4
|
import { FeatureOpCodes } from '../Features.js';
|
|
@@ -31,6 +31,10 @@ export class LegacyCalldataGenerator extends Generator {
|
|
|
31
31
|
throw new Error('No data chunks found');
|
|
32
32
|
let compiledData = [
|
|
33
33
|
this.senderPubKey,
|
|
34
|
+
opcodes.OP_DUP,
|
|
35
|
+
opcodes.OP_HASH256,
|
|
36
|
+
crypto.hash256(this.senderPubKey),
|
|
37
|
+
opcodes.OP_EQUALVERIFY,
|
|
34
38
|
opcodes.OP_CHECKSIGVERIFY,
|
|
35
39
|
contractSecret,
|
|
36
40
|
opcodes.OP_TOALTSTACK,
|
|
@@ -0,0 +1,7 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
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 === networks.testnet || this.network === networks.regtest;
|
|
46
|
+
}
|
|
47
|
+
}
|
package/build/opnet.d.ts
CHANGED
|
@@ -5,8 +5,10 @@ export * from './generators/builders/CustomGenerator.js';
|
|
|
5
5
|
export * from './generators/builders/DeploymentGenerator.js';
|
|
6
6
|
export * from './generators/builders/LegacyCalldataGenerator.js';
|
|
7
7
|
export * from './generators/builders/MultiSignGenerator.js';
|
|
8
|
+
export * from './generators/builders/MineableReward.js';
|
|
8
9
|
export * from './generators/Features.js';
|
|
9
10
|
export * from './generators/Generator.js';
|
|
11
|
+
export * from './transaction/mineable/ChallengeGenerator.js';
|
|
10
12
|
export * from './generators/AddressGenerator.js';
|
|
11
13
|
export * from './verification/TapscriptVerificator.js';
|
|
12
14
|
export * from './keypair/AddressVerificator.js';
|
|
@@ -28,6 +30,7 @@ export * from './transaction/builders/InteractionTransaction.js';
|
|
|
28
30
|
export * from './transaction/builders/MultiSignTransaction.js';
|
|
29
31
|
export * from './transaction/builders/SharedInteractionTransaction.js';
|
|
30
32
|
export * from './transaction/builders/TransactionBuilder.js';
|
|
33
|
+
export * from './transaction/builders/ChallengeSolutionTransaction.js';
|
|
31
34
|
export * from './utils/BitcoinUtils.js';
|
|
32
35
|
export * from './utils/lengths.js';
|
|
33
36
|
export * from './utxo/interfaces/IUTXO.js';
|
|
@@ -56,6 +59,7 @@ export * from './transaction/browser/extensions/UnisatSigner.js';
|
|
|
56
59
|
export * from './transaction/browser/extensions/XverseSigner.js';
|
|
57
60
|
export * from './transaction/browser/types/Unisat.js';
|
|
58
61
|
export * from './transaction/browser/types/Xverse.js';
|
|
62
|
+
export * from './transaction/browser/WalletConnection.js';
|
|
59
63
|
export * from './metadata/tokens.js';
|
|
60
64
|
export * from './transaction/browser/Web3Provider.js';
|
|
61
65
|
export * from './transaction/ContractAddress.js';
|
package/build/opnet.js
CHANGED
|
@@ -5,8 +5,10 @@ export * from './generators/builders/CustomGenerator.js';
|
|
|
5
5
|
export * from './generators/builders/DeploymentGenerator.js';
|
|
6
6
|
export * from './generators/builders/LegacyCalldataGenerator.js';
|
|
7
7
|
export * from './generators/builders/MultiSignGenerator.js';
|
|
8
|
+
export * from './generators/builders/MineableReward.js';
|
|
8
9
|
export * from './generators/Features.js';
|
|
9
10
|
export * from './generators/Generator.js';
|
|
11
|
+
export * from './transaction/mineable/ChallengeGenerator.js';
|
|
10
12
|
export * from './generators/AddressGenerator.js';
|
|
11
13
|
export * from './verification/TapscriptVerificator.js';
|
|
12
14
|
export * from './keypair/AddressVerificator.js';
|
|
@@ -28,6 +30,7 @@ export * from './transaction/builders/InteractionTransaction.js';
|
|
|
28
30
|
export * from './transaction/builders/MultiSignTransaction.js';
|
|
29
31
|
export * from './transaction/builders/SharedInteractionTransaction.js';
|
|
30
32
|
export * from './transaction/builders/TransactionBuilder.js';
|
|
33
|
+
export * from './transaction/builders/ChallengeSolutionTransaction.js';
|
|
31
34
|
export * from './utils/BitcoinUtils.js';
|
|
32
35
|
export * from './utils/lengths.js';
|
|
33
36
|
export * from './utxo/interfaces/IUTXO.js';
|
|
@@ -56,6 +59,7 @@ export * from './transaction/browser/extensions/UnisatSigner.js';
|
|
|
56
59
|
export * from './transaction/browser/extensions/XverseSigner.js';
|
|
57
60
|
export * from './transaction/browser/types/Unisat.js';
|
|
58
61
|
export * from './transaction/browser/types/Xverse.js';
|
|
62
|
+
export * from './transaction/browser/WalletConnection.js';
|
|
59
63
|
export * from './metadata/tokens.js';
|
|
60
64
|
export * from './transaction/browser/Web3Provider.js';
|
|
61
65
|
export * from './transaction/ContractAddress.js';
|
|
@@ -4,12 +4,14 @@ import { ICustomTransactionParameters } from './builders/CustomScriptTransaction
|
|
|
4
4
|
import { FundingTransaction } from './builders/FundingTransaction.js';
|
|
5
5
|
import { TransactionBuilder } from './builders/TransactionBuilder.js';
|
|
6
6
|
import { TransactionType } from './enums/TransactionType.js';
|
|
7
|
-
import { IDeploymentParameters, IFundingTransactionParameters, IInteractionParameters } from './interfaces/ITransactionParameters.js';
|
|
7
|
+
import { IChallengeSolutionTransactionParameters, IDeploymentParameters, IFundingTransactionParameters, IInteractionParameters } from './interfaces/ITransactionParameters.js';
|
|
8
|
+
import { ChallengeSolutionTransaction } from './builders/ChallengeSolutionTransaction.js';
|
|
8
9
|
export interface DeploymentResult {
|
|
9
10
|
readonly transaction: [string, string];
|
|
10
11
|
readonly contractAddress: string;
|
|
11
12
|
readonly contractPubKey: string;
|
|
12
13
|
readonly p2trAddress: string;
|
|
14
|
+
readonly preimage: string;
|
|
13
15
|
readonly utxos: UTXO[];
|
|
14
16
|
}
|
|
15
17
|
export interface WrapResult {
|
|
@@ -25,18 +27,31 @@ export interface FundingTransactionResponse {
|
|
|
25
27
|
readonly estimatedFees: bigint;
|
|
26
28
|
readonly nextUTXOs: UTXO[];
|
|
27
29
|
}
|
|
28
|
-
export interface
|
|
30
|
+
export interface ChallengeSolutionResponse {
|
|
31
|
+
readonly tx: Transaction;
|
|
32
|
+
readonly original: ChallengeSolutionTransaction;
|
|
33
|
+
readonly estimatedFees: bigint;
|
|
34
|
+
readonly nextUTXOs: UTXO[];
|
|
35
|
+
}
|
|
36
|
+
export interface BitcoinTransferBase {
|
|
29
37
|
readonly tx: string;
|
|
30
|
-
readonly original: FundingTransaction;
|
|
31
38
|
readonly estimatedFees: bigint;
|
|
32
39
|
readonly nextUTXOs: UTXO[];
|
|
33
40
|
}
|
|
41
|
+
export interface ChallengeSolution extends BitcoinTransferBase {
|
|
42
|
+
readonly original: ChallengeSolutionTransaction;
|
|
43
|
+
}
|
|
44
|
+
export interface BitcoinTransferResponse extends BitcoinTransferBase {
|
|
45
|
+
readonly original: FundingTransaction;
|
|
46
|
+
}
|
|
34
47
|
export declare class TransactionFactory {
|
|
35
48
|
createCustomScriptTransaction(interactionParameters: ICustomTransactionParameters): Promise<[string, string, UTXO[]]>;
|
|
36
|
-
signInteraction(interactionParameters: IInteractionParameters): Promise<[string, string, UTXO[]]>;
|
|
49
|
+
signInteraction(interactionParameters: IInteractionParameters): Promise<[string, string, UTXO[], string]>;
|
|
37
50
|
signDeployment(deploymentParameters: IDeploymentParameters): Promise<DeploymentResult>;
|
|
38
51
|
createBTCTransfer(parameters: IFundingTransactionParameters): Promise<BitcoinTransferResponse>;
|
|
52
|
+
createChallengeSolution(parameters: IChallengeSolutionTransactionParameters): Promise<ChallengeSolution>;
|
|
39
53
|
getAllNewUTXOs(original: TransactionBuilder<TransactionType>, tx: Transaction, to: string): UTXO[];
|
|
54
|
+
private _createChallengeSolution;
|
|
40
55
|
private createFundTransaction;
|
|
41
56
|
private writePSBTHeader;
|
|
42
57
|
private getPriorityFee;
|