@btc-vision/transaction 1.6.4 → 1.6.5
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/generators/builders/P2WDAGenerator.d.ts +13 -0
- package/browser/index.js +1 -1
- package/browser/keypair/Address.d.ts +3 -2
- package/browser/keypair/AddressVerificator.d.ts +12 -1
- package/browser/keypair/Wallet.d.ts +3 -0
- package/browser/opnet.d.ts +4 -0
- package/browser/p2wda/P2WDADetector.d.ts +16 -0
- package/browser/transaction/TransactionFactory.d.ts +3 -1
- package/browser/transaction/builders/DeploymentTransaction.d.ts +3 -3
- package/browser/transaction/builders/InteractionTransactionP2WDA.d.ts +37 -0
- package/browser/transaction/builders/SharedInteractionTransaction.d.ts +4 -4
- package/browser/transaction/mineable/IP2WSHAddress.d.ts +4 -0
- package/browser/transaction/mineable/TimelockGenerator.d.ts +2 -5
- package/browser/transaction/shared/TweakedTransaction.d.ts +5 -0
- package/build/_version.d.ts +1 -1
- package/build/_version.js +1 -1
- package/build/generators/builders/P2WDAGenerator.d.ts +13 -0
- package/build/generators/builders/P2WDAGenerator.js +62 -0
- package/build/keypair/Address.d.ts +3 -2
- package/build/keypair/Address.js +28 -2
- package/build/keypair/AddressVerificator.d.ts +12 -1
- package/build/keypair/AddressVerificator.js +78 -1
- package/build/keypair/Wallet.d.ts +3 -0
- package/build/keypair/Wallet.js +4 -0
- package/build/opnet.d.ts +4 -0
- package/build/opnet.js +4 -0
- package/build/p2wda/P2WDADetector.d.ts +16 -0
- package/build/p2wda/P2WDADetector.js +97 -0
- package/build/transaction/TransactionFactory.d.ts +3 -1
- package/build/transaction/TransactionFactory.js +35 -4
- package/build/transaction/builders/DeploymentTransaction.d.ts +3 -3
- package/build/transaction/builders/DeploymentTransaction.js +1 -1
- package/build/transaction/builders/InteractionTransactionP2WDA.d.ts +37 -0
- package/build/transaction/builders/InteractionTransactionP2WDA.js +205 -0
- package/build/transaction/builders/SharedInteractionTransaction.d.ts +4 -4
- package/build/transaction/builders/SharedInteractionTransaction.js +3 -3
- package/build/transaction/mineable/IP2WSHAddress.d.ts +4 -0
- package/build/transaction/mineable/IP2WSHAddress.js +1 -0
- package/build/transaction/mineable/TimelockGenerator.d.ts +2 -5
- package/build/transaction/shared/TweakedTransaction.d.ts +5 -0
- package/build/transaction/shared/TweakedTransaction.js +19 -0
- package/doc/README.md +0 -0
- package/doc/addresses/P2OP.md +1 -0
- package/doc/addresses/P2WDA.md +240 -0
- package/package.json +1 -1
- package/src/_version.ts +1 -1
- package/src/generators/builders/P2WDAGenerator.ts +174 -0
- package/src/keypair/Address.ts +58 -3
- package/src/keypair/AddressVerificator.ts +140 -1
- package/src/keypair/Wallet.ts +16 -0
- package/src/opnet.ts +4 -0
- package/src/p2wda/P2WDADetector.ts +218 -0
- package/src/transaction/TransactionFactory.ts +79 -5
- package/src/transaction/builders/DeploymentTransaction.ts +4 -3
- package/src/transaction/builders/InteractionTransactionP2WDA.ts +376 -0
- package/src/transaction/builders/SharedInteractionTransaction.ts +7 -6
- package/src/transaction/mineable/IP2WSHAddress.ts +4 -0
- package/src/transaction/mineable/TimelockGenerator.ts +2 -6
- package/src/transaction/shared/TweakedTransaction.ts +36 -0
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Network } from '@btc-vision/bitcoin';
|
|
2
|
-
import {
|
|
2
|
+
import { IP2WSHAddress } from '../transaction/mineable/IP2WSHAddress.js';
|
|
3
3
|
export declare class Address extends Uint8Array {
|
|
4
4
|
#private;
|
|
5
5
|
constructor(bytes?: ArrayLike<number>);
|
|
@@ -29,7 +29,8 @@ export declare class Address extends Uint8Array {
|
|
|
29
29
|
toString(): string;
|
|
30
30
|
toJSON(): string;
|
|
31
31
|
p2tr(network: Network): string;
|
|
32
|
-
|
|
32
|
+
p2wda(network: Network): IP2WSHAddress;
|
|
33
|
+
toCSV(duration: bigint | number | string, network: Network): IP2WSHAddress;
|
|
33
34
|
p2op(network: Network): string;
|
|
34
35
|
toTweakedHybridPublicKeyHex(): string;
|
|
35
36
|
toTweakedHybridPublicKeyBuffer(): Buffer;
|
|
@@ -6,13 +6,24 @@ export declare enum AddressTypes {
|
|
|
6
6
|
P2PK = "P2PK",
|
|
7
7
|
P2TR = "P2TR",
|
|
8
8
|
P2WPKH = "P2WPKH",
|
|
9
|
-
P2WSH = "P2WSH"
|
|
9
|
+
P2WSH = "P2WSH",
|
|
10
|
+
P2WDA = "P2WDA"
|
|
11
|
+
}
|
|
12
|
+
export interface ValidatedP2WDAAddress {
|
|
13
|
+
readonly isValid: boolean;
|
|
14
|
+
readonly isPotentiallyP2WDA: boolean;
|
|
15
|
+
readonly isDefinitelyP2WDA: boolean;
|
|
16
|
+
readonly publicKey?: Buffer;
|
|
17
|
+
readonly error?: string;
|
|
10
18
|
}
|
|
11
19
|
export declare class AddressVerificator {
|
|
12
20
|
static isValidP2TRAddress(inAddress: string, network: Network): boolean;
|
|
13
21
|
static isP2WPKHAddress(inAddress: string, network: Network): boolean;
|
|
22
|
+
static isP2WDAWitnessScript(witnessScript: Buffer): boolean;
|
|
14
23
|
static isP2PKHOrP2SH(addy: string, network: Network): boolean;
|
|
15
24
|
static isValidPublicKey(input: string, network: Network): boolean;
|
|
16
25
|
static requireRedeemScript(addy: string, network: Network): boolean;
|
|
17
26
|
static detectAddressType(addy: string, network: Network): AddressTypes | null;
|
|
27
|
+
static detectAddressTypeWithWitnessScript(addy: string, network: Network, witnessScript?: Buffer): AddressTypes | null;
|
|
28
|
+
static validateP2WDAAddress(address: string, network: Network, witnessScript?: Buffer): ValidatedP2WDAAddress;
|
|
18
29
|
}
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import { ECPairInterface } from 'ecpair';
|
|
2
2
|
import { Network } from '@btc-vision/bitcoin';
|
|
3
3
|
import { Address } from './Address.js';
|
|
4
|
+
import { IP2WSHAddress } from '../transaction/mineable/IP2WSHAddress.js';
|
|
4
5
|
export declare class Wallet {
|
|
5
6
|
readonly network: Network;
|
|
6
7
|
private readonly _keypair;
|
|
7
8
|
private readonly _p2wpkh;
|
|
8
9
|
private readonly _p2tr;
|
|
10
|
+
private readonly _p2wda;
|
|
9
11
|
private readonly _legacy;
|
|
10
12
|
private readonly _segwitLegacy;
|
|
11
13
|
private readonly _bufferPubKey;
|
|
@@ -17,6 +19,7 @@ export declare class Wallet {
|
|
|
17
19
|
get keypair(): ECPairInterface;
|
|
18
20
|
get p2wpkh(): string;
|
|
19
21
|
get p2tr(): string;
|
|
22
|
+
get p2wda(): IP2WSHAddress;
|
|
20
23
|
get legacy(): string;
|
|
21
24
|
get addresses(): string[];
|
|
22
25
|
get segwitLegacy(): string;
|
package/browser/opnet.d.ts
CHANGED
|
@@ -6,9 +6,12 @@ export * from './generators/builders/CustomGenerator.js';
|
|
|
6
6
|
export * from './generators/builders/DeploymentGenerator.js';
|
|
7
7
|
export * from './generators/builders/LegacyCalldataGenerator.js';
|
|
8
8
|
export * from './generators/builders/MultiSignGenerator.js';
|
|
9
|
+
export * from './generators/builders/P2WDAGenerator.js';
|
|
9
10
|
export * from './generators/Features.js';
|
|
10
11
|
export * from './generators/Generator.js';
|
|
11
12
|
export * from './transaction/mineable/TimelockGenerator.js';
|
|
13
|
+
export * from './transaction/mineable/IP2WSHAddress.js';
|
|
14
|
+
export * from './p2wda/P2WDADetector.js';
|
|
12
15
|
export * from './generators/AddressGenerator.js';
|
|
13
16
|
export * from './verification/TapscriptVerificator.js';
|
|
14
17
|
export * from './keypair/AddressVerificator.js';
|
|
@@ -27,6 +30,7 @@ export * from './transaction/builders/CustomScriptTransaction.js';
|
|
|
27
30
|
export * from './transaction/builders/DeploymentTransaction.js';
|
|
28
31
|
export * from './transaction/builders/FundingTransaction.js';
|
|
29
32
|
export * from './transaction/builders/InteractionTransaction.js';
|
|
33
|
+
export * from './transaction/builders/InteractionTransactionP2WDA.js';
|
|
30
34
|
export * from './transaction/builders/MultiSignTransaction.js';
|
|
31
35
|
export * from './transaction/builders/SharedInteractionTransaction.js';
|
|
32
36
|
export * from './transaction/builders/TransactionBuilder.js';
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Buffer } from 'buffer';
|
|
2
|
+
import { Network } from '@btc-vision/bitcoin';
|
|
3
|
+
import { UTXO } from '../utxo/interfaces/IUTXO.js';
|
|
4
|
+
import { IP2WSHAddress } from '../transaction/mineable/IP2WSHAddress.js';
|
|
5
|
+
export declare class P2WDADetector {
|
|
6
|
+
static isP2WDAUTXO(utxo: UTXO): boolean;
|
|
7
|
+
static isP2WDAWitnessScript(witnessScript: Buffer): boolean;
|
|
8
|
+
static generateP2WDAAddress(publicKey: Buffer, network: Network): IP2WSHAddress & {
|
|
9
|
+
scriptPubKey: Buffer;
|
|
10
|
+
};
|
|
11
|
+
static extractPublicKeyFromP2WDA(witnessScript: Buffer): Buffer | null;
|
|
12
|
+
static createSimpleP2WDAWitness(transactionSignature: Buffer, witnessScript: Buffer): Buffer[];
|
|
13
|
+
static validateP2WDASignature(publicKey: Buffer, dataSignature: Buffer, operationData: Buffer): boolean;
|
|
14
|
+
static estimateP2WDAWitnessSize(dataSize?: number): number;
|
|
15
|
+
static couldBeP2WDA(scriptPubKey: Buffer): boolean;
|
|
16
|
+
}
|
|
@@ -26,7 +26,7 @@ export interface BitcoinTransferBase {
|
|
|
26
26
|
readonly nextUTXOs: UTXO[];
|
|
27
27
|
}
|
|
28
28
|
export interface InteractionResponse {
|
|
29
|
-
readonly fundingTransaction: string;
|
|
29
|
+
readonly fundingTransaction: string | null;
|
|
30
30
|
readonly interactionTransaction: string;
|
|
31
31
|
readonly estimatedFees: bigint;
|
|
32
32
|
readonly nextUTXOs: UTXO[];
|
|
@@ -45,7 +45,9 @@ export declare class TransactionFactory {
|
|
|
45
45
|
private detectInteractionOPWallet;
|
|
46
46
|
private detectDeploymentOPWallet;
|
|
47
47
|
private createFundTransaction;
|
|
48
|
+
private hasP2WDAInputs;
|
|
48
49
|
private writePSBTHeader;
|
|
50
|
+
private signP2WDAInteraction;
|
|
49
51
|
private getPriorityFee;
|
|
50
52
|
private getUTXOAsTransaction;
|
|
51
53
|
}
|
|
@@ -4,13 +4,13 @@ import { P2TRPayment, 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 { ITimeLockOutput } from '../mineable/TimelockGenerator.js';
|
|
8
7
|
import { ChallengeSolution } from '../../epoch/ChallengeSolution.js';
|
|
8
|
+
import { IP2WSHAddress } from '../mineable/IP2WSHAddress.js';
|
|
9
9
|
export declare class DeploymentTransaction extends TransactionBuilder<TransactionType.DEPLOYMENT> {
|
|
10
10
|
static readonly MAXIMUM_CONTRACT_SIZE: number;
|
|
11
11
|
type: TransactionType.DEPLOYMENT;
|
|
12
12
|
protected readonly challenge: ChallengeSolution;
|
|
13
|
-
protected readonly epochChallenge:
|
|
13
|
+
protected readonly epochChallenge: IP2WSHAddress;
|
|
14
14
|
protected readonly _contractAddress: Address;
|
|
15
15
|
protected tapLeafScript: TapLeafScript | null;
|
|
16
16
|
private readonly deploymentVersion;
|
|
@@ -31,7 +31,7 @@ export declare class DeploymentTransaction extends TransactionBuilder<Transactio
|
|
|
31
31
|
get contractAddress(): Address;
|
|
32
32
|
get p2trAddress(): string;
|
|
33
33
|
getRndBytes(): Buffer;
|
|
34
|
-
|
|
34
|
+
getChallenge(): ChallengeSolution;
|
|
35
35
|
getContractAddress(): string;
|
|
36
36
|
protected contractSignerXOnlyPubKey(): Buffer;
|
|
37
37
|
protected buildTransaction(): Promise<void>;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { Buffer } from 'buffer';
|
|
2
|
+
import { Psbt } from '@btc-vision/bitcoin';
|
|
3
|
+
import { TransactionType } from '../enums/TransactionType.js';
|
|
4
|
+
import { IInteractionParameters } from '../interfaces/ITransactionParameters.js';
|
|
5
|
+
import { TransactionBuilder } from './TransactionBuilder.js';
|
|
6
|
+
import { ChallengeSolution } from '../../epoch/ChallengeSolution.js';
|
|
7
|
+
import { IP2WSHAddress } from '../mineable/IP2WSHAddress.js';
|
|
8
|
+
export declare class InteractionTransactionP2WDA extends TransactionBuilder<TransactionType.INTERACTION> {
|
|
9
|
+
private static readonly MAX_WITNESS_FIELDS;
|
|
10
|
+
private static readonly MAX_BYTES_PER_WITNESS;
|
|
11
|
+
readonly type: TransactionType.INTERACTION;
|
|
12
|
+
protected readonly epochChallenge: IP2WSHAddress;
|
|
13
|
+
protected readonly disableAutoRefund: boolean;
|
|
14
|
+
private readonly contractAddress;
|
|
15
|
+
private readonly contractSecret;
|
|
16
|
+
private readonly calldata;
|
|
17
|
+
private readonly challenge;
|
|
18
|
+
private readonly randomBytes;
|
|
19
|
+
private p2wdaGenerator;
|
|
20
|
+
private scriptSigner;
|
|
21
|
+
private p2wdaInputIndices;
|
|
22
|
+
private readonly compiledOperationData;
|
|
23
|
+
constructor(parameters: IInteractionParameters);
|
|
24
|
+
getRndBytes(): Buffer;
|
|
25
|
+
getChallenge(): ChallengeSolution;
|
|
26
|
+
getContractSecret(): Buffer;
|
|
27
|
+
protected buildTransaction(): Promise<void>;
|
|
28
|
+
protected createMineableRewardOutputs(): Promise<void>;
|
|
29
|
+
protected signInputs(transaction: Psbt): Promise<void>;
|
|
30
|
+
private generateFeatures;
|
|
31
|
+
private generateKeyPairFromSeed;
|
|
32
|
+
private scriptSignerXOnlyPubKey;
|
|
33
|
+
private validateP2WDAInputs;
|
|
34
|
+
private validateOperationDataSize;
|
|
35
|
+
private finalizePrimaryP2WDA;
|
|
36
|
+
private splitIntoWitnessChunks;
|
|
37
|
+
}
|
|
@@ -4,8 +4,8 @@ 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 { ITimeLockOutput } from '../mineable/TimelockGenerator.js';
|
|
8
7
|
import { ChallengeSolution } from '../../epoch/ChallengeSolution.js';
|
|
8
|
+
import { IP2WSHAddress } from '../mineable/IP2WSHAddress.js';
|
|
9
9
|
export declare abstract class SharedInteractionTransaction<T extends TransactionType> extends TransactionBuilder<T> {
|
|
10
10
|
static readonly MAXIMUM_CALLDATA_SIZE: number;
|
|
11
11
|
readonly randomBytes: Buffer;
|
|
@@ -14,7 +14,7 @@ export declare abstract class SharedInteractionTransaction<T extends Transaction
|
|
|
14
14
|
protected abstract readonly compiledTargetScript: Buffer;
|
|
15
15
|
protected abstract readonly scriptTree: Taptree;
|
|
16
16
|
protected readonly challenge: ChallengeSolution;
|
|
17
|
-
protected readonly epochChallenge:
|
|
17
|
+
protected readonly epochChallenge: IP2WSHAddress;
|
|
18
18
|
protected calldataGenerator: CalldataGenerator;
|
|
19
19
|
protected readonly calldata: Buffer;
|
|
20
20
|
protected abstract readonly contractSecret: Buffer;
|
|
@@ -23,7 +23,7 @@ export declare abstract class SharedInteractionTransaction<T extends Transaction
|
|
|
23
23
|
protected constructor(parameters: SharedInteractionParameters);
|
|
24
24
|
getContractSecret(): Buffer;
|
|
25
25
|
getRndBytes(): Buffer;
|
|
26
|
-
|
|
26
|
+
getChallenge(): ChallengeSolution;
|
|
27
27
|
protected scriptSignerXOnlyPubKey(): Buffer;
|
|
28
28
|
protected generateKeyPairFromSeed(): ECPairInterface;
|
|
29
29
|
protected buildTransaction(): Promise<void>;
|
|
@@ -37,7 +37,7 @@ export declare abstract class SharedInteractionTransaction<T extends Transaction
|
|
|
37
37
|
};
|
|
38
38
|
protected signInputsWalletBased(transaction: Psbt): Promise<void>;
|
|
39
39
|
protected signInputsNonWalletBased(transaction: Psbt): Promise<void>;
|
|
40
|
-
|
|
40
|
+
protected createMineableRewardOutputs(): Promise<void>;
|
|
41
41
|
private getPubKeys;
|
|
42
42
|
private generateRedeemScripts;
|
|
43
43
|
}
|
|
@@ -1,9 +1,6 @@
|
|
|
1
1
|
import { Network } from '@btc-vision/bitcoin';
|
|
2
|
-
|
|
3
|
-
address: string;
|
|
4
|
-
witnessScript: Buffer;
|
|
5
|
-
}
|
|
2
|
+
import { IP2WSHAddress } from './IP2WSHAddress.js';
|
|
6
3
|
export declare class TimeLockGenerator {
|
|
7
4
|
private static readonly CSV_BLOCKS;
|
|
8
|
-
static generateTimeLockAddress(publicKey: Buffer, network?: Network, csvBlocks?: number):
|
|
5
|
+
static generateTimeLockAddress(publicKey: Buffer, network?: Network, csvBlocks?: number): IP2WSHAddress;
|
|
9
6
|
}
|
|
@@ -5,6 +5,7 @@ import { UTXO } from '../../utxo/interfaces/IUTXO.js';
|
|
|
5
5
|
import { TapLeafScript } from '../interfaces/Tap.js';
|
|
6
6
|
import { ChainId } from '../../network/ChainId.js';
|
|
7
7
|
import { UnisatSigner } from '../browser/extensions/UnisatSigner.js';
|
|
8
|
+
import { Buffer } from 'buffer';
|
|
8
9
|
export type SupportedTransactionVersion = 1 | 2 | 3;
|
|
9
10
|
export interface ITweakedTransactionData {
|
|
10
11
|
readonly signer: Signer | ECPairInterface | UnisatSigner;
|
|
@@ -88,6 +89,10 @@ export declare abstract class TweakedTransaction extends Logger {
|
|
|
88
89
|
finalScriptSig: Buffer | undefined;
|
|
89
90
|
finalScriptWitness: Buffer | undefined;
|
|
90
91
|
};
|
|
92
|
+
protected finalizeSecondaryP2WDA(inputIndex: number, input: PsbtInput): {
|
|
93
|
+
finalScriptWitness: Buffer | undefined;
|
|
94
|
+
finalScriptSig: Buffer | undefined;
|
|
95
|
+
};
|
|
91
96
|
protected signInputsWalletBased(transaction: Psbt): Promise<void>;
|
|
92
97
|
protected isCSVScript(decompiled: (number | Buffer)[]): boolean;
|
|
93
98
|
protected setCSVSequence(csvBlocks: number, currentSequence: number): number;
|
package/build/_version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const version = "1.6.
|
|
1
|
+
export declare const version = "1.6.5";
|
package/build/_version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const version = '1.6.
|
|
1
|
+
export const version = '1.6.5';
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Network } from '@btc-vision/bitcoin';
|
|
2
|
+
import { Feature, Features } from '../Features.js';
|
|
3
|
+
import { Generator } from '../Generator.js';
|
|
4
|
+
import { ChallengeSolution } from '../../epoch/ChallengeSolution.js';
|
|
5
|
+
export declare class P2WDAGenerator extends Generator {
|
|
6
|
+
private static readonly P2WDA_VERSION;
|
|
7
|
+
constructor(senderPubKey: Buffer, contractSaltPubKey: Buffer, network?: Network);
|
|
8
|
+
static validateWitnessSize(dataSize: number, maxWitnessFields?: number, maxBytesPerWitness?: number): boolean;
|
|
9
|
+
compile(calldata: Buffer, contractSecret: Buffer, challenge: ChallengeSolution, maxPriority: bigint, features?: Feature<Features>[]): Buffer;
|
|
10
|
+
getHeader(maxPriority: bigint, features?: Features[]): Buffer;
|
|
11
|
+
private writeFeatures;
|
|
12
|
+
private encodeFeatureData;
|
|
13
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { networks } from '@btc-vision/bitcoin';
|
|
2
|
+
import { BinaryWriter } from '../../buffer/BinaryWriter.js';
|
|
3
|
+
import { Features } from '../Features.js';
|
|
4
|
+
import { Generator } from '../Generator.js';
|
|
5
|
+
export class P2WDAGenerator extends Generator {
|
|
6
|
+
constructor(senderPubKey, contractSaltPubKey, network = networks.bitcoin) {
|
|
7
|
+
super(senderPubKey, contractSaltPubKey, network);
|
|
8
|
+
}
|
|
9
|
+
static validateWitnessSize(dataSize, maxWitnessFields = 10, maxBytesPerWitness = 80) {
|
|
10
|
+
const signatureSize = 64;
|
|
11
|
+
const compressionRatio = 0.7;
|
|
12
|
+
const totalSize = dataSize + signatureSize;
|
|
13
|
+
const compressedSize = Math.ceil(totalSize * compressionRatio);
|
|
14
|
+
const requiredFields = Math.ceil(compressedSize / maxBytesPerWitness);
|
|
15
|
+
return requiredFields <= maxWitnessFields;
|
|
16
|
+
}
|
|
17
|
+
compile(calldata, contractSecret, challenge, maxPriority, features = []) {
|
|
18
|
+
if (!this.contractSaltPubKey) {
|
|
19
|
+
throw new Error('Contract salt public key not set');
|
|
20
|
+
}
|
|
21
|
+
if (contractSecret.length !== 32) {
|
|
22
|
+
throw new Error('Contract secret must be exactly 32 bytes');
|
|
23
|
+
}
|
|
24
|
+
const writer = new BinaryWriter();
|
|
25
|
+
writer.writeU8(P2WDAGenerator.P2WDA_VERSION);
|
|
26
|
+
writer.writeBytes(this.getHeader(maxPriority, features.map((f) => f.opcode)));
|
|
27
|
+
writer.writeBytes(contractSecret);
|
|
28
|
+
writer.writeBytes(challenge.publicKey.originalPublicKeyBuffer());
|
|
29
|
+
writer.writeBytes(challenge.solution);
|
|
30
|
+
writer.writeU32(calldata.length);
|
|
31
|
+
writer.writeBytes(calldata);
|
|
32
|
+
this.writeFeatures(writer, features);
|
|
33
|
+
return Buffer.from(writer.getBuffer());
|
|
34
|
+
}
|
|
35
|
+
getHeader(maxPriority, features = []) {
|
|
36
|
+
return super.getHeader(maxPriority, features);
|
|
37
|
+
}
|
|
38
|
+
writeFeatures(writer, features) {
|
|
39
|
+
writer.writeU16(features.length);
|
|
40
|
+
for (const feature of features) {
|
|
41
|
+
writer.writeU8(feature.opcode);
|
|
42
|
+
const encodedData = this.encodeFeatureData(feature);
|
|
43
|
+
writer.writeU32(encodedData.length);
|
|
44
|
+
writer.writeBytes(encodedData);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
encodeFeatureData(feature) {
|
|
48
|
+
switch (feature.opcode) {
|
|
49
|
+
case Features.ACCESS_LIST: {
|
|
50
|
+
const chunks = this.encodeFeature(feature);
|
|
51
|
+
return Buffer.concat(chunks.flat());
|
|
52
|
+
}
|
|
53
|
+
case Features.EPOCH_SUBMISSION: {
|
|
54
|
+
const chunks = this.encodeFeature(feature);
|
|
55
|
+
return Buffer.concat(chunks.flat());
|
|
56
|
+
}
|
|
57
|
+
default:
|
|
58
|
+
throw new Error(`Unknown feature type: ${feature.opcode}`);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
P2WDAGenerator.P2WDA_VERSION = 0x01;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Network } from '@btc-vision/bitcoin';
|
|
2
|
-
import {
|
|
2
|
+
import { IP2WSHAddress } from '../transaction/mineable/IP2WSHAddress.js';
|
|
3
3
|
export declare class Address extends Uint8Array {
|
|
4
4
|
#private;
|
|
5
5
|
constructor(bytes?: ArrayLike<number>);
|
|
@@ -29,7 +29,8 @@ export declare class Address extends Uint8Array {
|
|
|
29
29
|
toString(): string;
|
|
30
30
|
toJSON(): string;
|
|
31
31
|
p2tr(network: Network): string;
|
|
32
|
-
|
|
32
|
+
p2wda(network: Network): IP2WSHAddress;
|
|
33
|
+
toCSV(duration: bigint | number | string, network: Network): IP2WSHAddress;
|
|
33
34
|
p2op(network: Network): string;
|
|
34
35
|
toTweakedHybridPublicKeyHex(): string;
|
|
35
36
|
toTweakedHybridPublicKeyBuffer(): Buffer;
|
package/build/keypair/Address.js
CHANGED
|
@@ -9,7 +9,7 @@ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (
|
|
|
9
9
|
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
10
10
|
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
11
11
|
};
|
|
12
|
-
var _Address_p2tr, _Address_p2op, _Address_network, _Address_originalPublicKey, _Address_keyPair, _Address_uncompressed, _Address_tweakedUncompressed;
|
|
12
|
+
var _Address_p2tr, _Address_p2op, _Address_network, _Address_originalPublicKey, _Address_keyPair, _Address_uncompressed, _Address_tweakedUncompressed, _Address_p2wda;
|
|
13
13
|
import { decompressPublicKey, toXOnly } from '@btc-vision/bitcoin';
|
|
14
14
|
import { ADDRESS_BYTE_LENGTH } from '../utils/lengths.js';
|
|
15
15
|
import { AddressVerificator } from './AddressVerificator.js';
|
|
@@ -17,6 +17,7 @@ import { EcKeyPair } from './EcKeyPair.js';
|
|
|
17
17
|
import { ContractAddress } from '../transaction/ContractAddress.js';
|
|
18
18
|
import { BitcoinUtils } from '../utils/BitcoinUtils.js';
|
|
19
19
|
import { TimeLockGenerator } from '../transaction/mineable/TimelockGenerator.js';
|
|
20
|
+
import { P2WDADetector } from '../p2wda/P2WDADetector.js';
|
|
20
21
|
export class Address extends Uint8Array {
|
|
21
22
|
constructor(bytes) {
|
|
22
23
|
super(ADDRESS_BYTE_LENGTH);
|
|
@@ -27,6 +28,7 @@ export class Address extends Uint8Array {
|
|
|
27
28
|
_Address_keyPair.set(this, void 0);
|
|
28
29
|
_Address_uncompressed.set(this, void 0);
|
|
29
30
|
_Address_tweakedUncompressed.set(this, void 0);
|
|
31
|
+
_Address_p2wda.set(this, void 0);
|
|
30
32
|
if (!bytes) {
|
|
31
33
|
return;
|
|
32
34
|
}
|
|
@@ -195,6 +197,30 @@ export class Address extends Uint8Array {
|
|
|
195
197
|
}
|
|
196
198
|
throw new Error('Public key not set');
|
|
197
199
|
}
|
|
200
|
+
p2wda(network) {
|
|
201
|
+
if (__classPrivateFieldGet(this, _Address_p2wda, "f") && __classPrivateFieldGet(this, _Address_network, "f") === network) {
|
|
202
|
+
return __classPrivateFieldGet(this, _Address_p2wda, "f");
|
|
203
|
+
}
|
|
204
|
+
if (!__classPrivateFieldGet(this, _Address_originalPublicKey, "f")) {
|
|
205
|
+
throw new Error('Cannot create P2WDA address: public key not set');
|
|
206
|
+
}
|
|
207
|
+
const publicKeyBuffer = Buffer.from(__classPrivateFieldGet(this, _Address_originalPublicKey, "f"));
|
|
208
|
+
if (publicKeyBuffer.length !== 33) {
|
|
209
|
+
throw new Error('P2WDA requires a compressed public key (33 bytes)');
|
|
210
|
+
}
|
|
211
|
+
try {
|
|
212
|
+
const p2wdaInfo = P2WDADetector.generateP2WDAAddress(publicKeyBuffer, network);
|
|
213
|
+
__classPrivateFieldSet(this, _Address_network, network, "f");
|
|
214
|
+
__classPrivateFieldSet(this, _Address_p2wda, p2wdaInfo, "f");
|
|
215
|
+
return {
|
|
216
|
+
address: p2wdaInfo.address,
|
|
217
|
+
witnessScript: p2wdaInfo.witnessScript,
|
|
218
|
+
};
|
|
219
|
+
}
|
|
220
|
+
catch (error) {
|
|
221
|
+
throw new Error(`Failed to generate P2WDA address: ${error.message}`);
|
|
222
|
+
}
|
|
223
|
+
}
|
|
198
224
|
toCSV(duration, network) {
|
|
199
225
|
const n = Number(duration);
|
|
200
226
|
if (n < 1 || n > 65535) {
|
|
@@ -245,4 +271,4 @@ export class Address extends Uint8Array {
|
|
|
245
271
|
super.set(tweakedBytes);
|
|
246
272
|
}
|
|
247
273
|
}
|
|
248
|
-
_Address_p2tr = new WeakMap(), _Address_p2op = new WeakMap(), _Address_network = new WeakMap(), _Address_originalPublicKey = new WeakMap(), _Address_keyPair = new WeakMap(), _Address_uncompressed = new WeakMap(), _Address_tweakedUncompressed = new WeakMap();
|
|
274
|
+
_Address_p2tr = new WeakMap(), _Address_p2op = new WeakMap(), _Address_network = new WeakMap(), _Address_originalPublicKey = new WeakMap(), _Address_keyPair = new WeakMap(), _Address_uncompressed = new WeakMap(), _Address_tweakedUncompressed = new WeakMap(), _Address_p2wda = new WeakMap();
|
|
@@ -6,13 +6,24 @@ export declare enum AddressTypes {
|
|
|
6
6
|
P2PK = "P2PK",
|
|
7
7
|
P2TR = "P2TR",
|
|
8
8
|
P2WPKH = "P2WPKH",
|
|
9
|
-
P2WSH = "P2WSH"
|
|
9
|
+
P2WSH = "P2WSH",
|
|
10
|
+
P2WDA = "P2WDA"
|
|
11
|
+
}
|
|
12
|
+
export interface ValidatedP2WDAAddress {
|
|
13
|
+
readonly isValid: boolean;
|
|
14
|
+
readonly isPotentiallyP2WDA: boolean;
|
|
15
|
+
readonly isDefinitelyP2WDA: boolean;
|
|
16
|
+
readonly publicKey?: Buffer;
|
|
17
|
+
readonly error?: string;
|
|
10
18
|
}
|
|
11
19
|
export declare class AddressVerificator {
|
|
12
20
|
static isValidP2TRAddress(inAddress: string, network: Network): boolean;
|
|
13
21
|
static isP2WPKHAddress(inAddress: string, network: Network): boolean;
|
|
22
|
+
static isP2WDAWitnessScript(witnessScript: Buffer): boolean;
|
|
14
23
|
static isP2PKHOrP2SH(addy: string, network: Network): boolean;
|
|
15
24
|
static isValidPublicKey(input: string, network: Network): boolean;
|
|
16
25
|
static requireRedeemScript(addy: string, network: Network): boolean;
|
|
17
26
|
static detectAddressType(addy: string, network: Network): AddressTypes | null;
|
|
27
|
+
static detectAddressTypeWithWitnessScript(addy: string, network: Network, witnessScript?: Buffer): AddressTypes | null;
|
|
28
|
+
static validateP2WDAAddress(address: string, network: Network, witnessScript?: Buffer): ValidatedP2WDAAddress;
|
|
18
29
|
}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { address, initEccLib } from '@btc-vision/bitcoin';
|
|
1
|
+
import { address, initEccLib, payments } from '@btc-vision/bitcoin';
|
|
2
2
|
import * as ecc from '@bitcoinerlab/secp256k1';
|
|
3
3
|
import { EcKeyPair } from './EcKeyPair.js';
|
|
4
4
|
import { BitcoinUtils } from '../utils/BitcoinUtils.js';
|
|
5
|
+
import { P2WDADetector } from '../p2wda/P2WDADetector.js';
|
|
5
6
|
initEccLib(ecc);
|
|
6
7
|
export var AddressTypes;
|
|
7
8
|
(function (AddressTypes) {
|
|
@@ -12,6 +13,7 @@ export var AddressTypes;
|
|
|
12
13
|
AddressTypes["P2TR"] = "P2TR";
|
|
13
14
|
AddressTypes["P2WPKH"] = "P2WPKH";
|
|
14
15
|
AddressTypes["P2WSH"] = "P2WSH";
|
|
16
|
+
AddressTypes["P2WDA"] = "P2WDA";
|
|
15
17
|
})(AddressTypes || (AddressTypes = {}));
|
|
16
18
|
export class AddressVerificator {
|
|
17
19
|
static isValidP2TRAddress(inAddress, network) {
|
|
@@ -39,6 +41,9 @@ export class AddressVerificator {
|
|
|
39
41
|
catch { }
|
|
40
42
|
return isValidSegWitAddress;
|
|
41
43
|
}
|
|
44
|
+
static isP2WDAWitnessScript(witnessScript) {
|
|
45
|
+
return P2WDADetector.isP2WDAWitnessScript(witnessScript);
|
|
46
|
+
}
|
|
42
47
|
static isP2PKHOrP2SH(addy, network) {
|
|
43
48
|
try {
|
|
44
49
|
const decodedBase58 = address.fromBase58Check(addy);
|
|
@@ -124,4 +129,76 @@ export class AddressVerificator {
|
|
|
124
129
|
catch { }
|
|
125
130
|
return null;
|
|
126
131
|
}
|
|
132
|
+
static detectAddressTypeWithWitnessScript(addy, network, witnessScript) {
|
|
133
|
+
const baseType = AddressVerificator.detectAddressType(addy, network);
|
|
134
|
+
if (baseType === AddressTypes.P2WSH && witnessScript) {
|
|
135
|
+
if (AddressVerificator.isP2WDAWitnessScript(witnessScript)) {
|
|
136
|
+
return AddressTypes.P2WDA;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
return baseType;
|
|
140
|
+
}
|
|
141
|
+
static validateP2WDAAddress(address, network, witnessScript) {
|
|
142
|
+
try {
|
|
143
|
+
const addressType = AddressVerificator.detectAddressType(address, network);
|
|
144
|
+
if (addressType !== AddressTypes.P2WSH) {
|
|
145
|
+
return {
|
|
146
|
+
isValid: false,
|
|
147
|
+
isPotentiallyP2WDA: false,
|
|
148
|
+
isDefinitelyP2WDA: false,
|
|
149
|
+
error: 'Not a P2WSH address',
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
if (!witnessScript) {
|
|
153
|
+
return {
|
|
154
|
+
isValid: true,
|
|
155
|
+
isPotentiallyP2WDA: true,
|
|
156
|
+
isDefinitelyP2WDA: false,
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
if (!AddressVerificator.isP2WDAWitnessScript(witnessScript)) {
|
|
160
|
+
return {
|
|
161
|
+
isValid: true,
|
|
162
|
+
isPotentiallyP2WDA: true,
|
|
163
|
+
isDefinitelyP2WDA: false,
|
|
164
|
+
error: 'Witness script does not match P2WDA pattern',
|
|
165
|
+
};
|
|
166
|
+
}
|
|
167
|
+
const p2wsh = payments.p2wsh({
|
|
168
|
+
redeem: { output: witnessScript },
|
|
169
|
+
network,
|
|
170
|
+
});
|
|
171
|
+
if (p2wsh.address !== address) {
|
|
172
|
+
return {
|
|
173
|
+
isValid: false,
|
|
174
|
+
isPotentiallyP2WDA: false,
|
|
175
|
+
isDefinitelyP2WDA: false,
|
|
176
|
+
error: 'Witness script does not match address',
|
|
177
|
+
};
|
|
178
|
+
}
|
|
179
|
+
const publicKey = P2WDADetector.extractPublicKeyFromP2WDA(witnessScript);
|
|
180
|
+
if (!publicKey) {
|
|
181
|
+
return {
|
|
182
|
+
isValid: false,
|
|
183
|
+
isPotentiallyP2WDA: false,
|
|
184
|
+
isDefinitelyP2WDA: false,
|
|
185
|
+
error: 'Failed to extract public key from witness script',
|
|
186
|
+
};
|
|
187
|
+
}
|
|
188
|
+
return {
|
|
189
|
+
isValid: true,
|
|
190
|
+
isPotentiallyP2WDA: true,
|
|
191
|
+
isDefinitelyP2WDA: true,
|
|
192
|
+
publicKey,
|
|
193
|
+
};
|
|
194
|
+
}
|
|
195
|
+
catch (error) {
|
|
196
|
+
return {
|
|
197
|
+
isValid: false,
|
|
198
|
+
isPotentiallyP2WDA: false,
|
|
199
|
+
isDefinitelyP2WDA: false,
|
|
200
|
+
error: error.message,
|
|
201
|
+
};
|
|
202
|
+
}
|
|
203
|
+
}
|
|
127
204
|
}
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import { ECPairInterface } from 'ecpair';
|
|
2
2
|
import { Network } from '@btc-vision/bitcoin';
|
|
3
3
|
import { Address } from './Address.js';
|
|
4
|
+
import { IP2WSHAddress } from '../transaction/mineable/IP2WSHAddress.js';
|
|
4
5
|
export declare class Wallet {
|
|
5
6
|
readonly network: Network;
|
|
6
7
|
private readonly _keypair;
|
|
7
8
|
private readonly _p2wpkh;
|
|
8
9
|
private readonly _p2tr;
|
|
10
|
+
private readonly _p2wda;
|
|
9
11
|
private readonly _legacy;
|
|
10
12
|
private readonly _segwitLegacy;
|
|
11
13
|
private readonly _bufferPubKey;
|
|
@@ -17,6 +19,7 @@ export declare class Wallet {
|
|
|
17
19
|
get keypair(): ECPairInterface;
|
|
18
20
|
get p2wpkh(): string;
|
|
19
21
|
get p2tr(): string;
|
|
22
|
+
get p2wda(): IP2WSHAddress;
|
|
20
23
|
get legacy(): string;
|
|
21
24
|
get addresses(): string[];
|
|
22
25
|
get segwitLegacy(): string;
|
package/build/keypair/Wallet.js
CHANGED
|
@@ -20,6 +20,7 @@ export class Wallet {
|
|
|
20
20
|
this._p2wpkh = this._address.p2wpkh(this.network);
|
|
21
21
|
this._legacy = this._address.p2pkh(this.network);
|
|
22
22
|
this._segwitLegacy = this._address.p2wpkh(this.network);
|
|
23
|
+
this._p2wda = this._address.p2wda(this.network);
|
|
23
24
|
this._tweakedKey = this._address.toBuffer();
|
|
24
25
|
}
|
|
25
26
|
get address() {
|
|
@@ -39,6 +40,9 @@ export class Wallet {
|
|
|
39
40
|
get p2tr() {
|
|
40
41
|
return this._p2tr;
|
|
41
42
|
}
|
|
43
|
+
get p2wda() {
|
|
44
|
+
return this._p2wda;
|
|
45
|
+
}
|
|
42
46
|
get legacy() {
|
|
43
47
|
return this._legacy;
|
|
44
48
|
}
|
package/build/opnet.d.ts
CHANGED
|
@@ -6,9 +6,12 @@ export * from './generators/builders/CustomGenerator.js';
|
|
|
6
6
|
export * from './generators/builders/DeploymentGenerator.js';
|
|
7
7
|
export * from './generators/builders/LegacyCalldataGenerator.js';
|
|
8
8
|
export * from './generators/builders/MultiSignGenerator.js';
|
|
9
|
+
export * from './generators/builders/P2WDAGenerator.js';
|
|
9
10
|
export * from './generators/Features.js';
|
|
10
11
|
export * from './generators/Generator.js';
|
|
11
12
|
export * from './transaction/mineable/TimelockGenerator.js';
|
|
13
|
+
export * from './transaction/mineable/IP2WSHAddress.js';
|
|
14
|
+
export * from './p2wda/P2WDADetector.js';
|
|
12
15
|
export * from './generators/AddressGenerator.js';
|
|
13
16
|
export * from './verification/TapscriptVerificator.js';
|
|
14
17
|
export * from './keypair/AddressVerificator.js';
|
|
@@ -27,6 +30,7 @@ export * from './transaction/builders/CustomScriptTransaction.js';
|
|
|
27
30
|
export * from './transaction/builders/DeploymentTransaction.js';
|
|
28
31
|
export * from './transaction/builders/FundingTransaction.js';
|
|
29
32
|
export * from './transaction/builders/InteractionTransaction.js';
|
|
33
|
+
export * from './transaction/builders/InteractionTransactionP2WDA.js';
|
|
30
34
|
export * from './transaction/builders/MultiSignTransaction.js';
|
|
31
35
|
export * from './transaction/builders/SharedInteractionTransaction.js';
|
|
32
36
|
export * from './transaction/builders/TransactionBuilder.js';
|
package/build/opnet.js
CHANGED
|
@@ -5,9 +5,12 @@ 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/P2WDAGenerator.js';
|
|
8
9
|
export * from './generators/Features.js';
|
|
9
10
|
export * from './generators/Generator.js';
|
|
10
11
|
export * from './transaction/mineable/TimelockGenerator.js';
|
|
12
|
+
export * from './transaction/mineable/IP2WSHAddress.js';
|
|
13
|
+
export * from './p2wda/P2WDADetector.js';
|
|
11
14
|
export * from './generators/AddressGenerator.js';
|
|
12
15
|
export * from './verification/TapscriptVerificator.js';
|
|
13
16
|
export * from './keypair/AddressVerificator.js';
|
|
@@ -26,6 +29,7 @@ export * from './transaction/builders/CustomScriptTransaction.js';
|
|
|
26
29
|
export * from './transaction/builders/DeploymentTransaction.js';
|
|
27
30
|
export * from './transaction/builders/FundingTransaction.js';
|
|
28
31
|
export * from './transaction/builders/InteractionTransaction.js';
|
|
32
|
+
export * from './transaction/builders/InteractionTransactionP2WDA.js';
|
|
29
33
|
export * from './transaction/builders/MultiSignTransaction.js';
|
|
30
34
|
export * from './transaction/builders/SharedInteractionTransaction.js';
|
|
31
35
|
export * from './transaction/builders/TransactionBuilder.js';
|