@btc-vision/transaction 1.7.22 → 1.7.24
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/.babelrc +10 -1
- package/README.md +1 -1
- package/browser/_version.d.ts +1 -1
- package/browser/bip39.js +204 -0
- package/browser/bitcoin-utils.js +3172 -0
- package/browser/btc-vision-bip32.js +805 -0
- package/browser/btc-vision-bitcoin.js +4179 -0
- package/browser/btc-vision-logger.js +273 -0
- package/browser/btc-vision-post-quantum.js +542 -0
- package/browser/chain/ChainData.d.ts +1 -1
- package/browser/crypto/crypto.d.ts +1 -1
- package/browser/generators/AddressGenerator.d.ts +1 -1
- package/browser/generators/Generator.d.ts +1 -1
- package/browser/generators/MLDSAData.d.ts +1 -1
- package/browser/generators/builders/CalldataGenerator.d.ts +1 -1
- package/browser/generators/builders/CustomGenerator.d.ts +1 -1
- package/browser/generators/builders/DeploymentGenerator.d.ts +1 -1
- package/browser/generators/builders/HashCommitmentGenerator.d.ts +1 -1
- package/browser/generators/builders/LegacyCalldataGenerator.d.ts +1 -1
- package/browser/generators/builders/P2WDAGenerator.d.ts +1 -1
- package/browser/index.js +10780 -2
- package/browser/keypair/Address.d.ts +2 -2
- package/browser/keypair/AddressVerificator.d.ts +2 -2
- package/browser/keypair/EcKeyPair.d.ts +2 -2
- package/browser/keypair/MessageSigner.d.ts +2 -2
- package/browser/keypair/Wallet.d.ts +2 -2
- package/browser/metadata/ContractBaseMetadata.d.ts +1 -1
- package/browser/mnemonic/Mnemonic.d.ts +2 -2
- package/browser/noble-curves.js +3316 -0
- package/browser/noble-hashes.js +1608 -0
- package/browser/opnet.d.ts +10 -2
- package/browser/p2wda/P2WDADetector.d.ts +2 -2
- package/browser/polyfills.js +4590 -0
- package/browser/scure-base.js +410 -0
- package/browser/signer/AddressRotation.d.ts +1 -1
- package/browser/signer/SignerUtils.d.ts +1 -1
- package/browser/signer/TweakedSigner.d.ts +1 -1
- package/browser/transaction/TransactionFactory.d.ts +1 -1
- package/browser/transaction/browser/BrowserSignerBase.d.ts +1 -1
- package/browser/transaction/browser/Web3Provider.d.ts +1 -1
- package/browser/transaction/browser/extensions/UnisatSigner.d.ts +1 -1
- package/browser/transaction/browser/extensions/XverseSigner.d.ts +1 -1
- package/browser/transaction/builders/CancelTransaction.d.ts +1 -1
- package/browser/transaction/builders/ConsolidatedInteractionTransaction.d.ts +4 -4
- package/browser/transaction/builders/CustomScriptTransaction.d.ts +1 -1
- package/browser/transaction/builders/DeploymentTransaction.d.ts +1 -1
- package/browser/transaction/builders/FundingTransaction.d.ts +1 -1
- package/browser/transaction/builders/InteractionTransaction.d.ts +1 -1
- package/browser/transaction/builders/InteractionTransactionP2WDA.d.ts +2 -2
- package/browser/transaction/builders/MultiSignTransaction.d.ts +1 -1
- package/browser/transaction/builders/SharedInteractionTransaction.d.ts +1 -1
- package/browser/transaction/builders/TransactionBuilder.d.ts +1 -1
- package/browser/transaction/interfaces/ITransactionParameters.d.ts +1 -1
- package/browser/transaction/interfaces/Tap.d.ts +1 -1
- package/browser/transaction/mineable/TimelockGenerator.d.ts +1 -1
- package/browser/transaction/offline/OfflineTransactionManager.d.ts +1 -1
- package/browser/transaction/offline/TransactionReconstructor.d.ts +2 -2
- package/browser/transaction/processor/PsbtTransaction.d.ts +1 -1
- package/browser/transaction/shared/P2TR_MS.d.ts +1 -1
- package/browser/transaction/shared/TweakedTransaction.d.ts +3 -3
- package/browser/utxo/OPNetLimitedProvider.d.ts +1 -1
- package/browser/valibot.js +4948 -0
- package/browser/vendors.js +12913 -0
- package/browser/verification/TapscriptVerificator.d.ts +1 -1
- package/build/_version.d.ts +1 -1
- package/build/_version.js +1 -1
- package/build/keypair/Address.js +4 -4
- package/build/opnet.d.ts +9 -1
- package/build/opnet.js +6 -1
- package/build/transaction/builders/ConsolidatedInteractionTransaction.d.ts +3 -3
- package/build/transaction/builders/ConsolidatedInteractionTransaction.js +16 -16
- package/documentation/README.md +0 -2
- package/package.json +62 -4
- package/src/_version.ts +1 -1
- package/src/keypair/Address.ts +7 -4
- package/src/opnet.ts +9 -1
- package/src/transaction/TransactionFactory.ts +1 -4
- package/src/transaction/builders/ConsolidatedInteractionTransaction.ts +40 -47
- package/vite.config.browser.ts +92 -0
- package/webpack.config.js +143 -2
- package/browser/crypto/crypto-browser.d.ts +0 -11
- package/browser/index.js.LICENSE.txt +0 -29
- package/browser/transaction/offline/index.d.ts +0 -5
- package/browser/transaction/offline/interfaces/index.d.ts +0 -2
- package/build/transaction/offline/index.d.ts +0 -5
- package/build/transaction/offline/index.js +0 -5
- package/build/transaction/offline/interfaces/index.d.ts +0 -2
- package/build/transaction/offline/interfaces/index.js +0 -2
- package/src/transaction/offline/index.ts +0 -8
- package/src/transaction/offline/interfaces/index.ts +0 -2
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Network, Taptree } from '
|
|
1
|
+
import { Network, Taptree } from '../../node_modules/@btc-vision/bitcoin/build/index.js';
|
|
2
2
|
import { ChallengeSolution } from '../epoch/ChallengeSolution.js';
|
|
3
3
|
import { Feature, Features } from '../generators/Features.js';
|
|
4
4
|
export interface ContractAddressVerificationParams {
|
package/build/_version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const version = "1.7.
|
|
1
|
+
export declare const version = "1.7.24";
|
package/build/_version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const version = '1.7.
|
|
1
|
+
export const version = '1.7.24';
|
package/build/keypair/Address.js
CHANGED
|
@@ -42,6 +42,10 @@ export class Address extends Uint8Array {
|
|
|
42
42
|
return;
|
|
43
43
|
}
|
|
44
44
|
if (publicKeyOrTweak) {
|
|
45
|
+
const validLengths = [ADDRESS_BYTE_LENGTH, 33, 65];
|
|
46
|
+
if (!validLengths.includes(publicKeyOrTweak.length)) {
|
|
47
|
+
throw new Error(`Invalid public key length ${publicKeyOrTweak.length}`);
|
|
48
|
+
}
|
|
45
49
|
__classPrivateFieldSet(this, _Address_pendingLegacyKey, new Uint8Array(publicKeyOrTweak.length), "f");
|
|
46
50
|
__classPrivateFieldGet(this, _Address_pendingLegacyKey, "f").set(publicKeyOrTweak);
|
|
47
51
|
}
|
|
@@ -404,10 +408,6 @@ export class Address extends Uint8Array {
|
|
|
404
408
|
const pending = __classPrivateFieldGet(this, _Address_pendingLegacyKey, "f");
|
|
405
409
|
if (!pending)
|
|
406
410
|
return;
|
|
407
|
-
const validLengths = [ADDRESS_BYTE_LENGTH, 33, 65];
|
|
408
|
-
if (!validLengths.includes(pending.length)) {
|
|
409
|
-
throw new Error(`Invalid public key length ${pending.length}`);
|
|
410
|
-
}
|
|
411
411
|
if (pending.length === ADDRESS_BYTE_LENGTH) {
|
|
412
412
|
const buf = Buffer.alloc(ADDRESS_BYTE_LENGTH);
|
|
413
413
|
buf.set(pending);
|
package/build/opnet.d.ts
CHANGED
|
@@ -44,7 +44,15 @@ export * from './transaction/builders/InteractionTransactionP2WDA.js';
|
|
|
44
44
|
export * from './transaction/builders/MultiSignTransaction.js';
|
|
45
45
|
export * from './transaction/builders/SharedInteractionTransaction.js';
|
|
46
46
|
export * from './transaction/builders/TransactionBuilder.js';
|
|
47
|
-
export * from './transaction/offline/
|
|
47
|
+
export * from './transaction/offline/interfaces/ISerializableState.js';
|
|
48
|
+
export * from './transaction/offline/interfaces/ITypeSpecificData.js';
|
|
49
|
+
export { TransactionSerializer } from './transaction/offline/TransactionSerializer.js';
|
|
50
|
+
export { TransactionStateCapture } from './transaction/offline/TransactionStateCapture.js';
|
|
51
|
+
export type { CaptureParams } from './transaction/offline/TransactionStateCapture.js';
|
|
52
|
+
export { TransactionReconstructor } from './transaction/offline/TransactionReconstructor.js';
|
|
53
|
+
export type { ReconstructionOptions } from './transaction/offline/TransactionReconstructor.js';
|
|
54
|
+
export { OfflineTransactionManager } from './transaction/offline/OfflineTransactionManager.js';
|
|
55
|
+
export type { ExportOptions } from './transaction/offline/OfflineTransactionManager.js';
|
|
48
56
|
export * from './epoch/interfaces/IChallengeSolution.js';
|
|
49
57
|
export * from './epoch/validator/EpochValidator.js';
|
|
50
58
|
export * from './epoch/ChallengeSolution.js';
|
package/build/opnet.js
CHANGED
|
@@ -43,7 +43,12 @@ export * from './transaction/builders/InteractionTransactionP2WDA.js';
|
|
|
43
43
|
export * from './transaction/builders/MultiSignTransaction.js';
|
|
44
44
|
export * from './transaction/builders/SharedInteractionTransaction.js';
|
|
45
45
|
export * from './transaction/builders/TransactionBuilder.js';
|
|
46
|
-
export * from './transaction/offline/
|
|
46
|
+
export * from './transaction/offline/interfaces/ISerializableState.js';
|
|
47
|
+
export * from './transaction/offline/interfaces/ITypeSpecificData.js';
|
|
48
|
+
export { TransactionSerializer } from './transaction/offline/TransactionSerializer.js';
|
|
49
|
+
export { TransactionStateCapture } from './transaction/offline/TransactionStateCapture.js';
|
|
50
|
+
export { TransactionReconstructor } from './transaction/offline/TransactionReconstructor.js';
|
|
51
|
+
export { OfflineTransactionManager } from './transaction/offline/OfflineTransactionManager.js';
|
|
47
52
|
export * from './epoch/interfaces/IChallengeSolution.js';
|
|
48
53
|
export * from './epoch/validator/EpochValidator.js';
|
|
49
54
|
export * from './epoch/ChallengeSolution.js';
|
|
@@ -9,12 +9,12 @@ import { IP2WSHAddress } from '../mineable/IP2WSHAddress.js';
|
|
|
9
9
|
import { ChallengeSolution } from '../../epoch/ChallengeSolution.js';
|
|
10
10
|
export declare class ConsolidatedInteractionTransaction extends TransactionBuilder<TransactionType.INTERACTION> {
|
|
11
11
|
readonly type: TransactionType.INTERACTION;
|
|
12
|
+
readonly randomBytes: Buffer;
|
|
12
13
|
protected readonly contractAddress: string;
|
|
13
14
|
protected readonly contractSecret: Buffer;
|
|
14
15
|
protected readonly calldata: Buffer;
|
|
15
16
|
protected readonly challenge: ChallengeSolution;
|
|
16
17
|
protected readonly epochChallenge: IP2WSHAddress;
|
|
17
|
-
readonly randomBytes: Buffer;
|
|
18
18
|
protected readonly scriptSigner: ECPairInterface;
|
|
19
19
|
protected readonly calldataGenerator: CalldataGenerator;
|
|
20
20
|
protected readonly hashCommitmentGenerator: HashCommitmentGenerator;
|
|
@@ -32,12 +32,12 @@ export declare class ConsolidatedInteractionTransaction extends TransactionBuild
|
|
|
32
32
|
getOutputCount(): number;
|
|
33
33
|
getTotalChunkCount(): number;
|
|
34
34
|
build(): Promise<IConsolidatedInteractionResult>;
|
|
35
|
-
protected buildTransaction(): Promise<void>;
|
|
36
35
|
buildRevealTransaction(setupTxId: string): IRevealTransactionResult;
|
|
36
|
+
getValuePerOutput(): bigint;
|
|
37
|
+
protected buildTransaction(): Promise<void>;
|
|
37
38
|
private finalizeCommitmentInput;
|
|
38
39
|
private estimateRevealVBytes;
|
|
39
40
|
private calculateValuePerOutput;
|
|
40
|
-
getValuePerOutput(): bigint;
|
|
41
41
|
private getRefundAddress;
|
|
42
42
|
private generateFeatures;
|
|
43
43
|
private validateOutputCount;
|
|
@@ -102,19 +102,6 @@ export class ConsolidatedInteractionTransaction extends TransactionBuilder {
|
|
|
102
102
|
totalFees: setup.feesPaid + reveal.feesPaid,
|
|
103
103
|
};
|
|
104
104
|
}
|
|
105
|
-
async buildTransaction() {
|
|
106
|
-
this.addInputsFromUTXO();
|
|
107
|
-
const valuePerOutput = this.calculateValuePerOutput();
|
|
108
|
-
for (const commitment of this.commitmentOutputs) {
|
|
109
|
-
this.addOutput({
|
|
110
|
-
value: Number(valuePerOutput),
|
|
111
|
-
address: commitment.address,
|
|
112
|
-
});
|
|
113
|
-
}
|
|
114
|
-
const totalCommitmentValue = BigInt(this.commitmentOutputs.length) * valuePerOutput;
|
|
115
|
-
const optionalAmount = this.addOptionalOutputsAndGetAmount();
|
|
116
|
-
await this.addRefundOutput(totalCommitmentValue + optionalAmount);
|
|
117
|
-
}
|
|
118
105
|
buildRevealTransaction(setupTxId) {
|
|
119
106
|
const revealPsbt = new Psbt({ network: this.network });
|
|
120
107
|
const valuePerOutput = this.calculateValuePerOutput();
|
|
@@ -167,6 +154,22 @@ export class ConsolidatedInteractionTransaction extends TransactionBuilder {
|
|
|
167
154
|
this.log(`Reveal transaction: ${result.txId}`);
|
|
168
155
|
return result;
|
|
169
156
|
}
|
|
157
|
+
getValuePerOutput() {
|
|
158
|
+
return this.calculateValuePerOutput();
|
|
159
|
+
}
|
|
160
|
+
async buildTransaction() {
|
|
161
|
+
this.addInputsFromUTXO();
|
|
162
|
+
const valuePerOutput = this.calculateValuePerOutput();
|
|
163
|
+
for (const commitment of this.commitmentOutputs) {
|
|
164
|
+
this.addOutput({
|
|
165
|
+
value: Number(valuePerOutput),
|
|
166
|
+
address: commitment.address,
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
const totalCommitmentValue = BigInt(this.commitmentOutputs.length) * valuePerOutput;
|
|
170
|
+
const optionalAmount = this.addOptionalOutputsAndGetAmount();
|
|
171
|
+
await this.addRefundOutput(totalCommitmentValue + optionalAmount);
|
|
172
|
+
}
|
|
170
173
|
finalizeCommitmentInput(input, commitment) {
|
|
171
174
|
if (!input.partialSig || input.partialSig.length === 0) {
|
|
172
175
|
throw new Error('No signature for commitment input');
|
|
@@ -213,9 +216,6 @@ export class ConsolidatedInteractionTransaction extends TransactionBuilder {
|
|
|
213
216
|
this.cachedValuePerOutput = valuePerOutput > minValue ? valuePerOutput : minValue;
|
|
214
217
|
return this.cachedValuePerOutput;
|
|
215
218
|
}
|
|
216
|
-
getValuePerOutput() {
|
|
217
|
-
return this.calculateValuePerOutput();
|
|
218
|
-
}
|
|
219
219
|
getRefundAddress() {
|
|
220
220
|
if (this.from) {
|
|
221
221
|
return this.from;
|
package/documentation/README.md
CHANGED
|
@@ -33,5 +33,3 @@ Complete documentation for the OPNet Transaction Library - Bitcoin transaction b
|
|
|
33
33
|
- [Address Generation](./quantum-support/03-address-generation.md) - All address types
|
|
34
34
|
- [Message Signing](./quantum-support/04-message-signing.md) - ML-DSA and Schnorr signatures
|
|
35
35
|
- [Address Verification](./quantum-support/05-address-verification.md) - Validation and type detection
|
|
36
|
-
- [Complete Examples](./quantum-support/06-complete-examples.md) - Production-ready code
|
|
37
|
-
- [Complete Message Signing Example](./quantum-support/complete-message-signing-example.md) - Full working example with proper typings
|
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@btc-vision/transaction",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "1.7.
|
|
4
|
+
"version": "1.7.24",
|
|
5
5
|
"author": "BlobMaster41",
|
|
6
6
|
"description": "OPNet transaction library allows you to create and sign transactions for the OPNet network.",
|
|
7
7
|
"engines": {
|
|
8
|
-
"node": ">=
|
|
8
|
+
"node": ">=24.0.0"
|
|
9
9
|
},
|
|
10
10
|
"exports": {
|
|
11
11
|
".": {
|
|
@@ -18,6 +18,58 @@
|
|
|
18
18
|
"import": "./browser/index.js",
|
|
19
19
|
"require": "./browser/index.js",
|
|
20
20
|
"types": "./browser/index.d.ts"
|
|
21
|
+
},
|
|
22
|
+
"./browser/noble-curves": {
|
|
23
|
+
"import": "./browser/noble-curves.js",
|
|
24
|
+
"require": "./browser/noble-curves.js"
|
|
25
|
+
},
|
|
26
|
+
"./browser/noble-hashes": {
|
|
27
|
+
"import": "./browser/noble-hashes.js",
|
|
28
|
+
"require": "./browser/noble-hashes.js"
|
|
29
|
+
},
|
|
30
|
+
"./browser/btc-vision-bitcoin": {
|
|
31
|
+
"import": "./browser/btc-vision-bitcoin.js",
|
|
32
|
+
"require": "./browser/btc-vision-bitcoin.js"
|
|
33
|
+
},
|
|
34
|
+
"./browser/btc-vision-bip32": {
|
|
35
|
+
"import": "./browser/btc-vision-bip32.js",
|
|
36
|
+
"require": "./browser/btc-vision-bip32.js"
|
|
37
|
+
},
|
|
38
|
+
"./browser/btc-vision-post-quantum": {
|
|
39
|
+
"import": "./browser/btc-vision-post-quantum.js",
|
|
40
|
+
"require": "./browser/btc-vision-post-quantum.js"
|
|
41
|
+
},
|
|
42
|
+
"./browser/btc-vision-logger": {
|
|
43
|
+
"import": "./browser/btc-vision-logger.js",
|
|
44
|
+
"require": "./browser/btc-vision-logger.js"
|
|
45
|
+
},
|
|
46
|
+
"./browser/valibot": {
|
|
47
|
+
"import": "./browser/valibot.js",
|
|
48
|
+
"require": "./browser/valibot.js"
|
|
49
|
+
},
|
|
50
|
+
"./browser/pako": {
|
|
51
|
+
"import": "./browser/pako.js",
|
|
52
|
+
"require": "./browser/pako.js"
|
|
53
|
+
},
|
|
54
|
+
"./browser/bip39": {
|
|
55
|
+
"import": "./browser/bip39.js",
|
|
56
|
+
"require": "./browser/bip39.js"
|
|
57
|
+
},
|
|
58
|
+
"./browser/bitcoin-utils": {
|
|
59
|
+
"import": "./browser/bitcoin-utils.js",
|
|
60
|
+
"require": "./browser/bitcoin-utils.js"
|
|
61
|
+
},
|
|
62
|
+
"./browser/scure-base": {
|
|
63
|
+
"import": "./browser/scure-base.js",
|
|
64
|
+
"require": "./browser/scure-base.js"
|
|
65
|
+
},
|
|
66
|
+
"./browser/polyfills": {
|
|
67
|
+
"import": "./browser/polyfills.js",
|
|
68
|
+
"require": "./browser/polyfills.js"
|
|
69
|
+
},
|
|
70
|
+
"./browser/vendors": {
|
|
71
|
+
"import": "./browser/vendors.js",
|
|
72
|
+
"require": "./browser/vendors.js"
|
|
21
73
|
}
|
|
22
74
|
},
|
|
23
75
|
"browser": {
|
|
@@ -60,7 +112,7 @@
|
|
|
60
112
|
"watch": "gulp watch",
|
|
61
113
|
"build": "gulp build",
|
|
62
114
|
"setup": "npm i && npm run build",
|
|
63
|
-
"browserBuild": "
|
|
115
|
+
"browserBuild": "vite build --config vite.config.browser.ts",
|
|
64
116
|
"docs": "typedoc --out docs --exclude 'src/tests/*.ts' --tsconfig tsconfig.json --readme README.md --name OPNet --plugin typedoc-material-theme --themeColor '#cb9820' --exclude src/tests/test.ts --exclude src/index.ts src",
|
|
65
117
|
"test": "npm run build && vitest run",
|
|
66
118
|
"test:watch": "npm run build && vitest",
|
|
@@ -75,8 +127,10 @@
|
|
|
75
127
|
"@babel/preset-flow": "^7.27.1",
|
|
76
128
|
"@babel/preset-react": "^7.28.5",
|
|
77
129
|
"@babel/preset-typescript": "^7.28.5",
|
|
130
|
+
"@rollup/plugin-typescript": "^12.3.0",
|
|
78
131
|
"@types/node": "^24.10.0",
|
|
79
132
|
"@types/sha.js": "^2.4.4",
|
|
133
|
+
"@vitejs/plugin-legacy": "^7.2.1",
|
|
80
134
|
"@vitest/ui": "^4.0.8",
|
|
81
135
|
"eslint": "^9.39.1",
|
|
82
136
|
"gulp": "^5.0.1",
|
|
@@ -87,8 +141,12 @@
|
|
|
87
141
|
"prettier": "^3.6.2",
|
|
88
142
|
"stream-browserify": "^3.0.0",
|
|
89
143
|
"stream-http": "^3.2.0",
|
|
144
|
+
"tslib": "^2.8.1",
|
|
90
145
|
"typedoc": "^0.28.14",
|
|
91
146
|
"typescript-eslint": "^8.46.3",
|
|
147
|
+
"vite": "^7.3.0",
|
|
148
|
+
"vite-plugin-dts": "^4.5.4",
|
|
149
|
+
"vite-plugin-node-polyfills": "^0.24.0",
|
|
92
150
|
"vitest": "^4.0.8",
|
|
93
151
|
"webpack-cli": "^6.0.1"
|
|
94
152
|
},
|
|
@@ -96,7 +154,7 @@
|
|
|
96
154
|
"@babel/plugin-proposal-object-rest-spread": "^7.20.7",
|
|
97
155
|
"@bitcoinerlab/secp256k1": "^1.2.0",
|
|
98
156
|
"@btc-vision/bip32": "^6.0.3",
|
|
99
|
-
"@btc-vision/bitcoin": "^6.
|
|
157
|
+
"@btc-vision/bitcoin": "^6.5.1",
|
|
100
158
|
"@btc-vision/bitcoin-rpc": "^1.0.5",
|
|
101
159
|
"@btc-vision/logger": "^1.0.7",
|
|
102
160
|
"@btc-vision/post-quantum": "^0.5.3",
|
package/src/_version.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const version = '1.7.
|
|
1
|
+
export const version = '1.7.24';
|
package/src/keypair/Address.ts
CHANGED
|
@@ -51,6 +51,12 @@ export class Address extends Uint8Array {
|
|
|
51
51
|
}
|
|
52
52
|
|
|
53
53
|
if (publicKeyOrTweak) {
|
|
54
|
+
// Validate length immediately (cheap check), defer EC operations
|
|
55
|
+
const validLengths = [ADDRESS_BYTE_LENGTH, 33, 65];
|
|
56
|
+
if (!validLengths.includes(publicKeyOrTweak.length)) {
|
|
57
|
+
throw new Error(`Invalid public key length ${publicKeyOrTweak.length}`);
|
|
58
|
+
}
|
|
59
|
+
|
|
54
60
|
// Store but don't process yet - defer EC operations
|
|
55
61
|
this.#pendingLegacyKey = new Uint8Array(publicKeyOrTweak.length);
|
|
56
62
|
this.#pendingLegacyKey.set(publicKeyOrTweak);
|
|
@@ -784,10 +790,7 @@ export class Address extends Uint8Array {
|
|
|
784
790
|
const pending = this.#pendingLegacyKey;
|
|
785
791
|
if (!pending) return;
|
|
786
792
|
|
|
787
|
-
|
|
788
|
-
if (!validLengths.includes(pending.length)) {
|
|
789
|
-
throw new Error(`Invalid public key length ${pending.length}`);
|
|
790
|
-
}
|
|
793
|
+
// Length validation already done in constructor
|
|
791
794
|
|
|
792
795
|
if (pending.length === ADDRESS_BYTE_LENGTH) {
|
|
793
796
|
// 32-byte input: already tweaked x-only, just generate hybrid
|
package/src/opnet.ts
CHANGED
|
@@ -77,7 +77,15 @@ export * from './transaction/builders/SharedInteractionTransaction.js';
|
|
|
77
77
|
export * from './transaction/builders/TransactionBuilder.js';
|
|
78
78
|
|
|
79
79
|
/** Offline Transaction Signing */
|
|
80
|
-
export * from './transaction/offline/
|
|
80
|
+
export * from './transaction/offline/interfaces/ISerializableState.js';
|
|
81
|
+
export * from './transaction/offline/interfaces/ITypeSpecificData.js';
|
|
82
|
+
export { TransactionSerializer } from './transaction/offline/TransactionSerializer.js';
|
|
83
|
+
export { TransactionStateCapture } from './transaction/offline/TransactionStateCapture.js';
|
|
84
|
+
export type { CaptureParams } from './transaction/offline/TransactionStateCapture.js';
|
|
85
|
+
export { TransactionReconstructor } from './transaction/offline/TransactionReconstructor.js';
|
|
86
|
+
export type { ReconstructionOptions } from './transaction/offline/TransactionReconstructor.js';
|
|
87
|
+
export { OfflineTransactionManager } from './transaction/offline/OfflineTransactionManager.js';
|
|
88
|
+
export type { ExportOptions } from './transaction/offline/OfflineTransactionManager.js';
|
|
81
89
|
|
|
82
90
|
/** Epoch */
|
|
83
91
|
export * from './epoch/interfaces/IChallengeSolution.js';
|
|
@@ -32,10 +32,7 @@ import { Address } from '../keypair/Address.js';
|
|
|
32
32
|
import { BitcoinUtils } from '../utils/BitcoinUtils.js';
|
|
33
33
|
import { CancelTransaction, ICancelTransactionParameters } from './builders/CancelTransaction.js';
|
|
34
34
|
import { ConsolidatedInteractionTransaction } from './builders/ConsolidatedInteractionTransaction.js';
|
|
35
|
-
import {
|
|
36
|
-
IConsolidatedInteractionParameters,
|
|
37
|
-
IConsolidatedInteractionResult,
|
|
38
|
-
} from './interfaces/IConsolidatedTransactionParameters.js';
|
|
35
|
+
import { IConsolidatedInteractionParameters } from './interfaces/IConsolidatedTransactionParameters.js';
|
|
39
36
|
|
|
40
37
|
export interface DeploymentResult {
|
|
41
38
|
readonly transaction: [string, string];
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Buffer } from 'buffer';
|
|
2
|
-
import { Psbt, PsbtInput,
|
|
2
|
+
import { Psbt, PsbtInput, toXOnly, Transaction } from '@btc-vision/bitcoin';
|
|
3
3
|
import { ECPairInterface } from 'ecpair';
|
|
4
4
|
import { TransactionType } from '../enums/TransactionType.js';
|
|
5
5
|
import { MINIMUM_AMOUNT_REWARD, TransactionBuilder } from './TransactionBuilder.js';
|
|
@@ -68,25 +68,18 @@ import { AddressGenerator } from '../../generators/AddressGenerator.js';
|
|
|
68
68
|
*/
|
|
69
69
|
export class ConsolidatedInteractionTransaction extends TransactionBuilder<TransactionType.INTERACTION> {
|
|
70
70
|
public readonly type: TransactionType.INTERACTION = TransactionType.INTERACTION;
|
|
71
|
-
|
|
71
|
+
/** Random bytes for interaction (same as InteractionTransaction) */
|
|
72
|
+
public readonly randomBytes: Buffer;
|
|
72
73
|
/** The contract address (same as InteractionTransaction.to) */
|
|
73
74
|
protected readonly contractAddress: string;
|
|
74
|
-
|
|
75
75
|
/** The contract secret - 32 bytes (same as InteractionTransaction) */
|
|
76
76
|
protected readonly contractSecret: Buffer;
|
|
77
|
-
|
|
78
77
|
/** The compressed calldata (same as InteractionTransaction) */
|
|
79
78
|
protected readonly calldata: Buffer;
|
|
80
|
-
|
|
81
79
|
/** Challenge solution for epoch (same as InteractionTransaction) */
|
|
82
80
|
protected readonly challenge: ChallengeSolution;
|
|
83
|
-
|
|
84
81
|
/** Epoch challenge P2WSH address (same as InteractionTransaction) */
|
|
85
82
|
protected readonly epochChallenge: IP2WSHAddress;
|
|
86
|
-
|
|
87
|
-
/** Random bytes for interaction (same as InteractionTransaction) */
|
|
88
|
-
public readonly randomBytes: Buffer;
|
|
89
|
-
|
|
90
83
|
/** Script signer for interaction (same as InteractionTransaction) */
|
|
91
84
|
protected readonly scriptSigner: ECPairInterface;
|
|
92
85
|
|
|
@@ -288,36 +281,6 @@ export class ConsolidatedInteractionTransaction extends TransactionBuilder<Trans
|
|
|
288
281
|
};
|
|
289
282
|
}
|
|
290
283
|
|
|
291
|
-
/**
|
|
292
|
-
* Build the setup transaction.
|
|
293
|
-
* Creates P2WSH outputs with hash commitments to the compiled data chunks.
|
|
294
|
-
* This is called by signTransaction() in the base class.
|
|
295
|
-
*/
|
|
296
|
-
protected override async buildTransaction(): Promise<void> {
|
|
297
|
-
// Add funding UTXOs as inputs
|
|
298
|
-
this.addInputsFromUTXO();
|
|
299
|
-
|
|
300
|
-
// Calculate value per output (includes reveal fee + OPNet fee)
|
|
301
|
-
const valuePerOutput = this.calculateValuePerOutput();
|
|
302
|
-
|
|
303
|
-
// Add each hash-committed P2WSH as an output
|
|
304
|
-
for (const commitment of this.commitmentOutputs) {
|
|
305
|
-
this.addOutput({
|
|
306
|
-
value: Number(valuePerOutput),
|
|
307
|
-
address: commitment.address,
|
|
308
|
-
});
|
|
309
|
-
}
|
|
310
|
-
|
|
311
|
-
// Calculate total spent on commitment outputs
|
|
312
|
-
const totalCommitmentValue = BigInt(this.commitmentOutputs.length) * valuePerOutput;
|
|
313
|
-
|
|
314
|
-
// Add optional outputs
|
|
315
|
-
const optionalAmount = this.addOptionalOutputsAndGetAmount();
|
|
316
|
-
|
|
317
|
-
// Add refund/change output
|
|
318
|
-
await this.addRefundOutput(totalCommitmentValue + optionalAmount);
|
|
319
|
-
}
|
|
320
|
-
|
|
321
284
|
/**
|
|
322
285
|
* Build the reveal transaction.
|
|
323
286
|
* Spends the P2WSH commitment outputs, revealing the compiled data in witnesses.
|
|
@@ -404,6 +367,43 @@ export class ConsolidatedInteractionTransaction extends TransactionBuilder<Trans
|
|
|
404
367
|
return result;
|
|
405
368
|
}
|
|
406
369
|
|
|
370
|
+
/**
|
|
371
|
+
* Get the value per commitment output (for external access).
|
|
372
|
+
*/
|
|
373
|
+
public getValuePerOutput(): bigint {
|
|
374
|
+
return this.calculateValuePerOutput();
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
/**
|
|
378
|
+
* Build the setup transaction.
|
|
379
|
+
* Creates P2WSH outputs with hash commitments to the compiled data chunks.
|
|
380
|
+
* This is called by signTransaction() in the base class.
|
|
381
|
+
*/
|
|
382
|
+
protected override async buildTransaction(): Promise<void> {
|
|
383
|
+
// Add funding UTXOs as inputs
|
|
384
|
+
this.addInputsFromUTXO();
|
|
385
|
+
|
|
386
|
+
// Calculate value per output (includes reveal fee + OPNet fee)
|
|
387
|
+
const valuePerOutput = this.calculateValuePerOutput();
|
|
388
|
+
|
|
389
|
+
// Add each hash-committed P2WSH as an output
|
|
390
|
+
for (const commitment of this.commitmentOutputs) {
|
|
391
|
+
this.addOutput({
|
|
392
|
+
value: Number(valuePerOutput),
|
|
393
|
+
address: commitment.address,
|
|
394
|
+
});
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
// Calculate total spent on commitment outputs
|
|
398
|
+
const totalCommitmentValue = BigInt(this.commitmentOutputs.length) * valuePerOutput;
|
|
399
|
+
|
|
400
|
+
// Add optional outputs
|
|
401
|
+
const optionalAmount = this.addOptionalOutputsAndGetAmount();
|
|
402
|
+
|
|
403
|
+
// Add refund/change output
|
|
404
|
+
await this.addRefundOutput(totalCommitmentValue + optionalAmount);
|
|
405
|
+
}
|
|
406
|
+
|
|
407
407
|
/**
|
|
408
408
|
* Finalize a commitment input.
|
|
409
409
|
*
|
|
@@ -496,13 +496,6 @@ export class ConsolidatedInteractionTransaction extends TransactionBuilder<Trans
|
|
|
496
496
|
return this.cachedValuePerOutput;
|
|
497
497
|
}
|
|
498
498
|
|
|
499
|
-
/**
|
|
500
|
-
* Get the value per commitment output (for external access).
|
|
501
|
-
*/
|
|
502
|
-
public getValuePerOutput(): bigint {
|
|
503
|
-
return this.calculateValuePerOutput();
|
|
504
|
-
}
|
|
505
|
-
|
|
506
499
|
/**
|
|
507
500
|
* Get refund address.
|
|
508
501
|
*/
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { resolve } from 'path';
|
|
2
|
+
import { defineConfig } from 'vite';
|
|
3
|
+
import { nodePolyfills } from 'vite-plugin-node-polyfills';
|
|
4
|
+
import dts from 'vite-plugin-dts';
|
|
5
|
+
|
|
6
|
+
export default defineConfig({
|
|
7
|
+
build: {
|
|
8
|
+
outDir: 'browser',
|
|
9
|
+
emptyOutDir: true,
|
|
10
|
+
target: 'esnext',
|
|
11
|
+
minify: 'esbuild',
|
|
12
|
+
lib: {
|
|
13
|
+
entry: resolve(__dirname, 'src/index.ts'),
|
|
14
|
+
formats: ['es'],
|
|
15
|
+
fileName: () => 'index.js',
|
|
16
|
+
},
|
|
17
|
+
rollupOptions: {
|
|
18
|
+
output: {
|
|
19
|
+
chunkFileNames: '[name].js',
|
|
20
|
+
manualChunks: (id) => {
|
|
21
|
+
// BTC Vision packages (check before node_modules since aliases resolve differently)
|
|
22
|
+
if (id.includes('@btc-vision/bitcoin') || id.includes('/bitcoin/build/') || id.includes('/bitcoin/src/')) {
|
|
23
|
+
return 'btc-vision-bitcoin';
|
|
24
|
+
}
|
|
25
|
+
if (id.includes('@btc-vision/bip32') || id.includes('/bip32/src/')) {
|
|
26
|
+
return 'btc-vision-bip32';
|
|
27
|
+
}
|
|
28
|
+
if (id.includes('node_modules')) {
|
|
29
|
+
// Noble crypto
|
|
30
|
+
if (id.includes('@noble/curves')) return 'noble-curves';
|
|
31
|
+
if (id.includes('@noble/hashes')) return 'noble-hashes';
|
|
32
|
+
// BTC Vision packages
|
|
33
|
+
if (id.includes('@btc-vision/post-quantum')) return 'btc-vision-post-quantum';
|
|
34
|
+
if (id.includes('@btc-vision/logger')) return 'btc-vision-logger';
|
|
35
|
+
// Bitcoin utilities
|
|
36
|
+
if (id.includes('bip39')) return 'bip39';
|
|
37
|
+
if (id.includes('ecpair') || id.includes('@bitcoinerlab/secp256k1') ||
|
|
38
|
+
id.includes('bech32') || id.includes('bip174') || id.includes('bs58') ||
|
|
39
|
+
id.includes('typeforce') || id.includes('varuint')) {
|
|
40
|
+
return 'bitcoin-utils';
|
|
41
|
+
}
|
|
42
|
+
// Validation
|
|
43
|
+
if (id.includes('valibot')) return 'valibot';
|
|
44
|
+
// Scure
|
|
45
|
+
if (id.includes('@scure/')) return 'scure-base';
|
|
46
|
+
// Polyfills
|
|
47
|
+
if (id.includes('buffer/') || id.includes('process/') || id.includes('stream-browserify') ||
|
|
48
|
+
id.includes('readable-stream') || id.includes('safe-buffer') || id.includes('events/') ||
|
|
49
|
+
id.includes('util/') || id.includes('inherits') || id.includes('ieee754') ||
|
|
50
|
+
id.includes('base64-js') || id.includes('string_decoder')) {
|
|
51
|
+
return 'polyfills';
|
|
52
|
+
}
|
|
53
|
+
// Other vendors
|
|
54
|
+
return 'vendors';
|
|
55
|
+
}
|
|
56
|
+
},
|
|
57
|
+
},
|
|
58
|
+
},
|
|
59
|
+
},
|
|
60
|
+
resolve: {
|
|
61
|
+
alias: {
|
|
62
|
+
crypto: resolve(__dirname, 'src/crypto/crypto-browser.js'),
|
|
63
|
+
stream: 'stream-browserify',
|
|
64
|
+
buffer: 'buffer',
|
|
65
|
+
// Use source versions for proper tree-shaking (not browser bundles)
|
|
66
|
+
'@btc-vision/bitcoin': resolve(__dirname, 'node_modules/@btc-vision/bitcoin/build/index.js'),
|
|
67
|
+
'@btc-vision/bip32': resolve(__dirname, 'node_modules/@btc-vision/bip32/src/cjs/index.cjs'),
|
|
68
|
+
},
|
|
69
|
+
mainFields: ['module', 'main'],
|
|
70
|
+
},
|
|
71
|
+
define: {
|
|
72
|
+
'process.env.NODE_ENV': JSON.stringify('production'),
|
|
73
|
+
global: 'globalThis',
|
|
74
|
+
},
|
|
75
|
+
plugins: [
|
|
76
|
+
nodePolyfills({
|
|
77
|
+
globals: {
|
|
78
|
+
Buffer: true,
|
|
79
|
+
global: true,
|
|
80
|
+
process: true,
|
|
81
|
+
},
|
|
82
|
+
// Exclude heavy polyfills we don't need
|
|
83
|
+
exclude: ['fs', 'path', 'os', 'http', 'https', 'zlib', 'net', 'tls', 'dns', 'child_process', 'cluster', 'dgram', 'readline', 'repl', 'tty', 'vm', 'worker_threads', 'perf_hooks', 'inspector', 'async_hooks', 'trace_events', 'v8', 'wasi'],
|
|
84
|
+
}),
|
|
85
|
+
dts({
|
|
86
|
+
outDir: 'browser',
|
|
87
|
+
include: ['src/**/*.ts'],
|
|
88
|
+
exclude: ['src/**/*.test.ts', 'src/**/*.spec.ts'],
|
|
89
|
+
insertTypesEntry: true,
|
|
90
|
+
}),
|
|
91
|
+
],
|
|
92
|
+
});
|