@btc-vision/transaction 1.7.6 → 1.7.10
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 -0
- package/browser/chain/ChainData.d.ts +4 -0
- package/browser/{src/deterministic → deterministic}/DeterministicMap.d.ts +3 -3
- package/browser/deterministic/FastMap.d.ts +24 -0
- package/browser/{src/epoch → epoch}/interfaces/IChallengeSolution.d.ts +4 -4
- package/browser/{src/generators → generators}/Features.d.ts +6 -1
- package/browser/{src/generators → generators}/Generator.d.ts +1 -0
- package/browser/generators/MLDSAData.d.ts +15 -0
- package/browser/index.js +1 -1
- package/browser/{src/keypair → keypair}/Address.d.ts +9 -3
- package/browser/{src/keypair → keypair}/MessageSigner.d.ts +9 -0
- package/browser/{src/opnet.d.ts → opnet.d.ts} +2 -1
- package/browser/{src/transaction → transaction}/browser/Web3Provider.d.ts +15 -4
- package/browser/transaction/browser/types/OPWallet.d.ts +6 -0
- package/browser/{src/transaction → transaction}/builders/CustomScriptTransaction.d.ts +1 -0
- package/browser/{src/transaction → transaction}/builders/DeploymentTransaction.d.ts +1 -0
- package/browser/{src/transaction → transaction}/builders/TransactionBuilder.d.ts +4 -0
- package/browser/{src/transaction → transaction}/interfaces/ITransactionParameters.d.ts +3 -0
- package/browser/{src/transaction → transaction}/shared/TweakedTransaction.d.ts +6 -0
- package/browser/{src/utxo → utxo}/OPNetLimitedProvider.d.ts +1 -0
- package/build/_version.d.ts +1 -1
- package/build/_version.js +1 -1
- package/build/chain/ChainData.d.ts +4 -0
- package/build/chain/ChainData.js +20 -0
- package/build/deterministic/AddressMap.js +2 -2
- package/build/deterministic/DeterministicMap.d.ts +3 -3
- package/build/deterministic/DeterministicMap.js +2 -2
- package/build/deterministic/FastMap.d.ts +24 -0
- package/build/deterministic/{Map.js → FastMap.js} +22 -28
- package/build/epoch/ChallengeSolution.js +4 -4
- package/build/epoch/interfaces/IChallengeSolution.d.ts +4 -4
- package/build/generators/Features.d.ts +6 -1
- package/build/generators/Features.js +1 -0
- package/build/generators/Generator.d.ts +1 -0
- package/build/generators/Generator.js +24 -2
- package/build/generators/MLDSAData.d.ts +15 -0
- package/build/generators/MLDSAData.js +19 -0
- package/build/generators/builders/CalldataGenerator.js +1 -1
- package/build/generators/builders/DeploymentGenerator.js +1 -1
- package/build/generators/builders/P2WDAGenerator.js +1 -1
- package/build/keypair/Address.d.ts +9 -3
- package/build/keypair/Address.js +63 -38
- package/build/keypair/MessageSigner.d.ts +9 -0
- package/build/keypair/MessageSigner.js +101 -3
- package/build/opnet.d.ts +2 -1
- package/build/opnet.js +2 -1
- package/build/transaction/TransactionFactory.js +3 -0
- package/build/transaction/browser/Web3Provider.d.ts +15 -4
- package/build/transaction/browser/types/OPWallet.d.ts +2 -10
- package/build/transaction/browser/types/OPWallet.js +4 -2
- package/build/transaction/builders/CustomScriptTransaction.d.ts +1 -0
- package/build/transaction/builders/CustomScriptTransaction.js +3 -0
- package/build/transaction/builders/DeploymentTransaction.d.ts +1 -0
- package/build/transaction/builders/DeploymentTransaction.js +26 -1
- package/build/transaction/builders/InteractionTransaction.js +14 -1
- package/build/transaction/builders/InteractionTransactionP2WDA.js +14 -1
- package/build/transaction/builders/TransactionBuilder.d.ts +4 -0
- package/build/transaction/builders/TransactionBuilder.js +77 -0
- package/build/transaction/interfaces/ITransactionParameters.d.ts +3 -0
- package/build/transaction/shared/P2TR_MS.js +1 -0
- package/build/transaction/shared/TweakedTransaction.d.ts +6 -0
- package/build/transaction/shared/TweakedTransaction.js +19 -0
- package/build/utxo/OPNetLimitedProvider.d.ts +1 -0
- package/build/utxo/OPNetLimitedProvider.js +11 -1
- package/eslint.config.js +2 -1
- package/package.json +1 -1
- package/src/_version.ts +1 -1
- package/src/chain/ChainData.ts +32 -0
- package/src/deterministic/AddressMap.ts +3 -3
- package/src/deterministic/DeterministicMap.ts +9 -6
- package/src/deterministic/{Map.ts → FastMap.ts} +46 -33
- package/src/epoch/ChallengeSolution.ts +4 -4
- package/src/epoch/interfaces/IChallengeSolution.ts +4 -4
- package/src/generators/Features.ts +8 -2
- package/src/generators/Generator.ts +35 -2
- package/src/generators/MLDSAData.ts +30 -0
- package/src/generators/builders/CalldataGenerator.ts +1 -1
- package/src/generators/builders/DeploymentGenerator.ts +2 -1
- package/src/generators/builders/LegacyCalldataGenerator.ts +1 -0
- package/src/generators/builders/P2WDAGenerator.ts +5 -1
- package/src/keypair/Address.ts +78 -38
- package/src/keypair/MessageSigner.ts +214 -15
- package/src/opnet.ts +3 -1
- package/src/transaction/TransactionFactory.ts +3 -0
- package/src/transaction/browser/Web3Provider.ts +64 -4
- package/src/transaction/browser/types/OPWallet.ts +6 -53
- package/src/transaction/builders/CustomScriptTransaction.ts +4 -0
- package/src/transaction/builders/DeploymentTransaction.ts +36 -8
- package/src/transaction/builders/InteractionTransaction.ts +17 -7
- package/src/transaction/builders/InteractionTransactionP2WDA.ts +17 -7
- package/src/transaction/builders/TransactionBuilder.ts +107 -0
- package/src/transaction/interfaces/ITransactionParameters.ts +12 -0
- package/src/transaction/shared/P2TR_MS.ts +1 -0
- package/src/transaction/shared/TweakedTransaction.ts +35 -0
- package/src/utxo/OPNetLimitedProvider.ts +19 -2
- package/test/address.test.ts +18 -20
- package/test/addressmap.test.ts +783 -0
- package/test/addressverificator-mldsa.test.ts +40 -16
- package/test/fastmap-setall.test.ts +143 -0
- package/test/fastmap.test.ts +917 -0
- package/test/messagesigner-mldsa.test.ts +50 -50
- package/test/messagesigner-schnorr.test.ts +40 -40
- package/test/old/FastBigIntMap.ts +132 -0
- package/test/oldfastmap.test.ts +917 -0
- package/tsconfig.webpack.json +2 -6
- package/webpack.config.js +1 -1
- package/browser/src/_version.d.ts +0 -1
- package/browser/src/deterministic/Map.d.ts +0 -19
- package/browser/src/transaction/browser/types/OPWallet.d.ts +0 -14
- package/browser/test/address.test.d.ts +0 -1
- package/browser/test/addressverificator-mldsa.test.d.ts +0 -1
- package/browser/test/derivePath.test.d.ts +0 -1
- package/browser/test/messagesigner-mldsa.test.d.ts +0 -1
- package/browser/test/messagesigner-schnorr.test.d.ts +0 -1
- package/browser/test/network-awareness.test.d.ts +0 -1
- package/build/deterministic/Map.d.ts +0 -19
- /package/browser/{src/abi → abi}/ABICoder.d.ts +0 -0
- /package/browser/{src/buffer → buffer}/BinaryReader.d.ts +0 -0
- /package/browser/{src/buffer → buffer}/BinaryWriter.d.ts +0 -0
- /package/browser/{src/bytecode → bytecode}/Compressor.d.ts +0 -0
- /package/browser/{src/consensus → consensus}/Consensus.d.ts +0 -0
- /package/browser/{src/consensus → consensus}/ConsensusConfig.d.ts +0 -0
- /package/browser/{src/consensus → consensus}/metadata/RoswellConsensus.d.ts +0 -0
- /package/browser/{src/crypto → crypto}/crypto-browser.d.ts +0 -0
- /package/browser/{src/crypto → crypto}/crypto.d.ts +0 -0
- /package/browser/{src/deterministic → deterministic}/AddressMap.d.ts +0 -0
- /package/browser/{src/deterministic → deterministic}/AddressSet.d.ts +0 -0
- /package/browser/{src/deterministic → deterministic}/CustomMap.d.ts +0 -0
- /package/browser/{src/deterministic → deterministic}/DeterministicSet.d.ts +0 -0
- /package/browser/{src/epoch → epoch}/ChallengeSolution.d.ts +0 -0
- /package/browser/{src/epoch → epoch}/validator/EpochValidator.d.ts +0 -0
- /package/browser/{src/event → event}/NetEvent.d.ts +0 -0
- /package/browser/{src/generators → generators}/AddressGenerator.d.ts +0 -0
- /package/browser/{src/generators → generators}/builders/CalldataGenerator.d.ts +0 -0
- /package/browser/{src/generators → generators}/builders/CustomGenerator.d.ts +0 -0
- /package/browser/{src/generators → generators}/builders/DeploymentGenerator.d.ts +0 -0
- /package/browser/{src/generators → generators}/builders/LegacyCalldataGenerator.d.ts +0 -0
- /package/browser/{src/generators → generators}/builders/MultiSignGenerator.d.ts +0 -0
- /package/browser/{src/generators → generators}/builders/P2WDAGenerator.d.ts +0 -0
- /package/browser/{src/index.d.ts → index.d.ts} +0 -0
- /package/browser/{src/keypair → keypair}/AddressVerificator.d.ts +0 -0
- /package/browser/{src/keypair → keypair}/EcKeyPair.d.ts +0 -0
- /package/browser/{src/keypair → keypair}/Secp256k1PointDeriver.d.ts +0 -0
- /package/browser/{src/keypair → keypair}/Wallet.d.ts +0 -0
- /package/browser/{src/keypair → keypair}/interfaces/IWallet.d.ts +0 -0
- /package/browser/{src/metadata → metadata}/ContractBaseMetadata.d.ts +0 -0
- /package/browser/{src/metadata → metadata}/tokens.d.ts +0 -0
- /package/browser/{src/mnemonic → mnemonic}/BIPStandard.d.ts +0 -0
- /package/browser/{src/mnemonic → mnemonic}/Mnemonic.d.ts +0 -0
- /package/browser/{src/mnemonic → mnemonic}/MnemonicStrength.d.ts +0 -0
- /package/browser/{src/network → network}/ChainId.d.ts +0 -0
- /package/browser/{src/p2wda → p2wda}/P2WDADetector.d.ts +0 -0
- /package/browser/{src/signer → signer}/SignerUtils.d.ts +0 -0
- /package/browser/{src/signer → signer}/TweakedSigner.d.ts +0 -0
- /package/browser/{src/transaction → transaction}/ContractAddress.d.ts +0 -0
- /package/browser/{src/transaction → transaction}/TransactionFactory.d.ts +0 -0
- /package/browser/{src/transaction → transaction}/browser/BrowserSignerBase.d.ts +0 -0
- /package/browser/{src/transaction → transaction}/browser/extensions/UnisatSigner.d.ts +0 -0
- /package/browser/{src/transaction → transaction}/browser/extensions/XverseSigner.d.ts +0 -0
- /package/browser/{src/transaction → transaction}/browser/types/Unisat.d.ts +0 -0
- /package/browser/{src/transaction → transaction}/browser/types/Xverse.d.ts +0 -0
- /package/browser/{src/transaction → transaction}/builders/CancelTransaction.d.ts +0 -0
- /package/browser/{src/transaction → transaction}/builders/ChallengeSolutionTransaction.d.ts +0 -0
- /package/browser/{src/transaction → transaction}/builders/FundingTransaction.d.ts +0 -0
- /package/browser/{src/transaction → transaction}/builders/InteractionTransaction.d.ts +0 -0
- /package/browser/{src/transaction → transaction}/builders/InteractionTransactionP2WDA.d.ts +0 -0
- /package/browser/{src/transaction → transaction}/builders/MultiSignTransaction.d.ts +0 -0
- /package/browser/{src/transaction → transaction}/builders/SharedInteractionTransaction.d.ts +0 -0
- /package/browser/{src/transaction → transaction}/enums/TransactionType.d.ts +0 -0
- /package/browser/{src/transaction → transaction}/interfaces/Tap.d.ts +0 -0
- /package/browser/{src/transaction → transaction}/mineable/IP2WSHAddress.d.ts +0 -0
- /package/browser/{src/transaction → transaction}/mineable/TimelockGenerator.d.ts +0 -0
- /package/browser/{src/transaction → transaction}/processor/PsbtTransaction.d.ts +0 -0
- /package/browser/{src/transaction → transaction}/psbt/PSBTTypes.d.ts +0 -0
- /package/browser/{src/transaction → transaction}/shared/P2TR_MS.d.ts +0 -0
- /package/browser/{src/utils → utils}/BitcoinUtils.d.ts +0 -0
- /package/browser/{src/utils → utils}/BufferHelper.d.ts +0 -0
- /package/browser/{src/utils → utils}/StringToBuffer.d.ts +0 -0
- /package/browser/{src/utils → utils}/lengths.d.ts +0 -0
- /package/browser/{src/utils → utils}/types.d.ts +0 -0
- /package/browser/{src/utxo → utxo}/interfaces/BroadcastResponse.d.ts +0 -0
- /package/browser/{src/utxo → utxo}/interfaces/IUTXO.d.ts +0 -0
- /package/browser/{src/verification → verification}/TapscriptVerificator.d.ts +0 -0
|
@@ -27,6 +27,12 @@ import { TweakedTransaction } from '../shared/TweakedTransaction.js';
|
|
|
27
27
|
import { UnisatSigner } from '../browser/extensions/UnisatSigner.js';
|
|
28
28
|
import { IP2WSHAddress } from '../mineable/IP2WSHAddress.js';
|
|
29
29
|
import { P2WDADetector } from '../../p2wda/P2WDADetector.js';
|
|
30
|
+
import { Feature, Features, MLDSALinkRequest } from '../../generators/Features.js';
|
|
31
|
+
import { BITCOIN_PROTOCOL_ID, getChainId } from '../../chain/ChainData.js';
|
|
32
|
+
import { BinaryWriter } from '../../buffer/BinaryWriter.js';
|
|
33
|
+
import { MLDSASecurityLevel } from '@btc-vision/bip32';
|
|
34
|
+
import { MessageSigner } from '../../keypair/MessageSigner.js';
|
|
35
|
+
import { getLevelFromPublicKeyLength } from '../../generators/MLDSAData.js';
|
|
30
36
|
|
|
31
37
|
initEccLib(ecc);
|
|
32
38
|
|
|
@@ -288,6 +294,7 @@ export abstract class TransactionBuilder<T extends TransactionType> extends Twea
|
|
|
288
294
|
amount: this.estimatedFees,
|
|
289
295
|
optionalOutputs: this.optionalOutputs,
|
|
290
296
|
optionalInputs: this.optionalInputs,
|
|
297
|
+
mldsaSigner: null,
|
|
291
298
|
};
|
|
292
299
|
}
|
|
293
300
|
|
|
@@ -874,6 +881,106 @@ export abstract class TransactionBuilder<T extends TransactionType> extends Twea
|
|
|
874
881
|
throw new Error('Output not found');
|
|
875
882
|
}
|
|
876
883
|
|
|
884
|
+
protected generateLegacySignature(): Buffer {
|
|
885
|
+
this.tweakSigner();
|
|
886
|
+
|
|
887
|
+
if (!this.tweakedSigner) {
|
|
888
|
+
throw new Error('Tweaked signer is not defined');
|
|
889
|
+
}
|
|
890
|
+
|
|
891
|
+
const tweakedKey = toXOnly(this.tweakedSigner.publicKey);
|
|
892
|
+
const chainId = getChainId(this.network);
|
|
893
|
+
|
|
894
|
+
const writer = new BinaryWriter();
|
|
895
|
+
|
|
896
|
+
// ONLY SUPPORT MLDSA-44 FOR NOW.
|
|
897
|
+
writer.writeU8(MLDSASecurityLevel.LEVEL2);
|
|
898
|
+
writer.writeBytes(this.hashedPublicKey);
|
|
899
|
+
writer.writeBytes(tweakedKey);
|
|
900
|
+
writer.writeBytes(BITCOIN_PROTOCOL_ID);
|
|
901
|
+
writer.writeBytes(chainId);
|
|
902
|
+
|
|
903
|
+
const message = writer.getBuffer();
|
|
904
|
+
const signature = MessageSigner.signMessage(this.tweakedSigner, message);
|
|
905
|
+
const isValid = MessageSigner.verifySignature(tweakedKey, message, signature.signature);
|
|
906
|
+
|
|
907
|
+
if (!isValid) {
|
|
908
|
+
throw new Error('Could not verify generated legacy signature for MLDSA link request');
|
|
909
|
+
}
|
|
910
|
+
|
|
911
|
+
return Buffer.from(signature.signature);
|
|
912
|
+
}
|
|
913
|
+
|
|
914
|
+
protected generateMLDSASignature(): Buffer {
|
|
915
|
+
if (!this.mldsaSigner) {
|
|
916
|
+
throw new Error('MLDSA signer is not defined');
|
|
917
|
+
}
|
|
918
|
+
|
|
919
|
+
this.tweakSigner();
|
|
920
|
+
|
|
921
|
+
if (!this.tweakedSigner) {
|
|
922
|
+
throw new Error('Tweaked signer is not defined');
|
|
923
|
+
}
|
|
924
|
+
|
|
925
|
+
const tweakedKey = toXOnly(this.tweakedSigner.publicKey);
|
|
926
|
+
const chainId = getChainId(this.network);
|
|
927
|
+
const level = getLevelFromPublicKeyLength(this.mldsaSigner.publicKey.length);
|
|
928
|
+
|
|
929
|
+
if (level !== MLDSASecurityLevel.LEVEL2) {
|
|
930
|
+
throw new Error('Only MLDSA level 2 is supported for link requests');
|
|
931
|
+
}
|
|
932
|
+
|
|
933
|
+
const writer = new BinaryWriter();
|
|
934
|
+
writer.writeU8(level);
|
|
935
|
+
writer.writeBytes(this.hashedPublicKey);
|
|
936
|
+
writer.writeBytes(this.mldsaSigner.publicKey);
|
|
937
|
+
writer.writeBytes(tweakedKey);
|
|
938
|
+
writer.writeBytes(BITCOIN_PROTOCOL_ID);
|
|
939
|
+
writer.writeBytes(chainId);
|
|
940
|
+
|
|
941
|
+
const message = writer.getBuffer();
|
|
942
|
+
const signature = MessageSigner.signMLDSAMessage(this.mldsaSigner, message);
|
|
943
|
+
|
|
944
|
+
const isValid = MessageSigner.verifyMLDSASignature(
|
|
945
|
+
this.mldsaSigner,
|
|
946
|
+
message,
|
|
947
|
+
signature.signature,
|
|
948
|
+
);
|
|
949
|
+
|
|
950
|
+
if (!isValid) {
|
|
951
|
+
throw new Error('Could not verify generated MLDSA signature for link request');
|
|
952
|
+
}
|
|
953
|
+
|
|
954
|
+
return Buffer.from(signature.signature);
|
|
955
|
+
}
|
|
956
|
+
|
|
957
|
+
protected generateMLDSALinkRequest(
|
|
958
|
+
parameters: ITransactionParameters,
|
|
959
|
+
features: Feature<Features>[],
|
|
960
|
+
): void {
|
|
961
|
+
const mldsaSigner = this.mldsaSigner;
|
|
962
|
+
const legacySignature = this.generateLegacySignature();
|
|
963
|
+
|
|
964
|
+
let mldsaSignature: Buffer | null = null;
|
|
965
|
+
if (parameters.revealMLDSAPublicKey) {
|
|
966
|
+
mldsaSignature = this.generateMLDSASignature();
|
|
967
|
+
}
|
|
968
|
+
|
|
969
|
+
const mldsaRequest: MLDSALinkRequest = {
|
|
970
|
+
opcode: Features.MLDSA_LINK_PUBKEY,
|
|
971
|
+
data: {
|
|
972
|
+
verifyRequest: !!parameters.revealMLDSAPublicKey,
|
|
973
|
+
publicKey: mldsaSigner.publicKey,
|
|
974
|
+
hashedPublicKey: this.hashedPublicKey,
|
|
975
|
+
level: getLevelFromPublicKeyLength(mldsaSigner.publicKey.length),
|
|
976
|
+
legacySignature: legacySignature,
|
|
977
|
+
mldsaSignature: mldsaSignature,
|
|
978
|
+
},
|
|
979
|
+
};
|
|
980
|
+
|
|
981
|
+
features.push(mldsaRequest);
|
|
982
|
+
}
|
|
983
|
+
|
|
877
984
|
/**
|
|
878
985
|
* @description Returns the transaction opnet fee
|
|
879
986
|
* @protected
|
|
@@ -13,6 +13,16 @@ export interface ITransactionParameters extends ITweakedTransactionData {
|
|
|
13
13
|
readonly to?: string;
|
|
14
14
|
readonly debugFees?: boolean;
|
|
15
15
|
|
|
16
|
+
/**
|
|
17
|
+
* Reveal this user's MLDSA public key in the transaction features.
|
|
18
|
+
*/
|
|
19
|
+
readonly revealMLDSAPublicKey?: boolean;
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Link the user MLDSA public key to their legacy public key.
|
|
23
|
+
*/
|
|
24
|
+
readonly linkMLDSAPublicKeyToAddress?: boolean;
|
|
25
|
+
|
|
16
26
|
utxos: UTXO[];
|
|
17
27
|
|
|
18
28
|
nonWitnessUtxo?: Buffer;
|
|
@@ -30,6 +40,8 @@ export interface ITransactionParameters extends ITweakedTransactionData {
|
|
|
30
40
|
readonly feeRate: number;
|
|
31
41
|
readonly priorityFee: bigint;
|
|
32
42
|
readonly gasSatFee: bigint;
|
|
43
|
+
|
|
44
|
+
readonly compiledTargetScript?: Buffer | string;
|
|
33
45
|
}
|
|
34
46
|
|
|
35
47
|
export interface IFundingTransactionParameters extends ITransactionParameters {
|
|
@@ -41,10 +41,13 @@ import {
|
|
|
41
41
|
import { TransactionBuilder } from '../builders/TransactionBuilder.js';
|
|
42
42
|
import { Buffer } from 'buffer';
|
|
43
43
|
import { P2WDADetector } from '../../p2wda/P2WDADetector.js';
|
|
44
|
+
import { QuantumBIP32Interface } from '@btc-vision/bip32';
|
|
45
|
+
import { MessageSigner } from '../../keypair/MessageSigner.js';
|
|
44
46
|
|
|
45
47
|
export type SupportedTransactionVersion = 1 | 2 | 3;
|
|
46
48
|
|
|
47
49
|
export interface ITweakedTransactionData {
|
|
50
|
+
readonly mldsaSigner: QuantumBIP32Interface | null;
|
|
48
51
|
readonly signer: Signer | ECPairInterface | UnisatSigner;
|
|
49
52
|
readonly network: Network;
|
|
50
53
|
readonly chainId?: ChainId;
|
|
@@ -161,6 +164,9 @@ export abstract class TweakedTransaction extends Logger {
|
|
|
161
164
|
|
|
162
165
|
protected txVersion: SupportedTransactionVersion = 2;
|
|
163
166
|
|
|
167
|
+
protected readonly _mldsaSigner: QuantumBIP32Interface | null = null;
|
|
168
|
+
protected readonly _hashedPublicKey: Buffer | null = null;
|
|
169
|
+
|
|
164
170
|
protected constructor(data: ITweakedTransactionData) {
|
|
165
171
|
super();
|
|
166
172
|
|
|
@@ -176,6 +182,35 @@ export abstract class TweakedTransaction extends Logger {
|
|
|
176
182
|
if (data.txVersion) {
|
|
177
183
|
this.txVersion = data.txVersion;
|
|
178
184
|
}
|
|
185
|
+
|
|
186
|
+
if (data.mldsaSigner) {
|
|
187
|
+
this._mldsaSigner = data.mldsaSigner;
|
|
188
|
+
this._hashedPublicKey = MessageSigner.sha256(this._mldsaSigner.publicKey);
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
/**
|
|
193
|
+
* Get the MLDSA signer
|
|
194
|
+
* @protected
|
|
195
|
+
*/
|
|
196
|
+
protected get mldsaSigner(): QuantumBIP32Interface {
|
|
197
|
+
if (!this._mldsaSigner) {
|
|
198
|
+
throw new Error('MLDSA Signer is not set');
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
return this._mldsaSigner;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
/**
|
|
205
|
+
* Get the hashed public key
|
|
206
|
+
* @protected
|
|
207
|
+
*/
|
|
208
|
+
protected get hashedPublicKey(): Buffer {
|
|
209
|
+
if (!this._hashedPublicKey) {
|
|
210
|
+
throw new Error('Hashed public key is not set');
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
return this._hashedPublicKey;
|
|
179
214
|
}
|
|
180
215
|
|
|
181
216
|
/**
|
|
@@ -12,6 +12,7 @@ export interface WalletUTXOs {
|
|
|
12
12
|
readonly confirmed: RawUTXOResponse[];
|
|
13
13
|
readonly pending: RawUTXOResponse[];
|
|
14
14
|
readonly spentTransactions: RawUTXOResponse[];
|
|
15
|
+
readonly raw: string[];
|
|
15
16
|
}
|
|
16
17
|
|
|
17
18
|
/**
|
|
@@ -53,6 +54,8 @@ export class OPNetLimitedProvider {
|
|
|
53
54
|
}
|
|
54
55
|
|
|
55
56
|
const fetchedData: WalletUTXOs = (await resp.json()) as WalletUTXOs;
|
|
57
|
+
const rawTransactions = fetchedData.raw ?? [];
|
|
58
|
+
|
|
56
59
|
const allUtxos = settings.usePendingUTXO
|
|
57
60
|
? [...fetchedData.confirmed, ...fetchedData.pending]
|
|
58
61
|
: fetchedData.confirmed;
|
|
@@ -91,18 +94,31 @@ export class OPNetLimitedProvider {
|
|
|
91
94
|
for (const utxo of meetCriteria) {
|
|
92
95
|
const utxoValue: bigint = BigInt(utxo.value);
|
|
93
96
|
|
|
94
|
-
// check if value is greater than 0
|
|
95
97
|
if (utxoValue <= 0n) {
|
|
96
98
|
continue;
|
|
97
99
|
}
|
|
98
100
|
|
|
101
|
+
const rawIndex = utxo.raw as unknown as number;
|
|
102
|
+
if (rawIndex === undefined || rawIndex === null) {
|
|
103
|
+
throw new Error(
|
|
104
|
+
`Missing raw index for UTXO ${utxo.transactionId}:${utxo.outputIndex}`,
|
|
105
|
+
);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
const rawHex = rawTransactions[rawIndex];
|
|
109
|
+
if (!rawHex) {
|
|
110
|
+
throw new Error(
|
|
111
|
+
`Invalid raw index ${rawIndex} - not found in raw transactions array`,
|
|
112
|
+
);
|
|
113
|
+
}
|
|
114
|
+
|
|
99
115
|
currentAmount += utxoValue;
|
|
100
116
|
finalUTXOs.push({
|
|
101
117
|
transactionId: utxo.transactionId,
|
|
102
118
|
outputIndex: utxo.outputIndex,
|
|
103
119
|
value: utxoValue,
|
|
104
120
|
scriptPubKey: utxo.scriptPubKey,
|
|
105
|
-
nonWitnessUtxo: Buffer.from(
|
|
121
|
+
nonWitnessUtxo: Buffer.from(rawHex, 'base64'),
|
|
106
122
|
});
|
|
107
123
|
|
|
108
124
|
if (currentAmount > amountRequested) {
|
|
@@ -213,6 +229,7 @@ export class OPNetLimitedProvider {
|
|
|
213
229
|
splitInputsInto,
|
|
214
230
|
priorityFee: 0n,
|
|
215
231
|
gasSatFee: 330n,
|
|
232
|
+
mldsaSigner: null,
|
|
216
233
|
};
|
|
217
234
|
|
|
218
235
|
const transactionFactory = new TransactionFactory();
|
package/test/address.test.ts
CHANGED
|
@@ -311,7 +311,7 @@ describe('Address - Comprehensive Tests', () => {
|
|
|
311
311
|
const mldsaHash = Buffer.alloc(32, 0x01);
|
|
312
312
|
const address = new Address(mldsaHash);
|
|
313
313
|
|
|
314
|
-
expect(() => address.tweakedToHex()).toThrow('
|
|
314
|
+
expect(() => address.tweakedToHex()).toThrow('Legacy public key not set');
|
|
315
315
|
});
|
|
316
316
|
|
|
317
317
|
it('should convert tweaked public key to buffer', () => {
|
|
@@ -326,9 +326,7 @@ describe('Address - Comprehensive Tests', () => {
|
|
|
326
326
|
const mldsaHash = Buffer.alloc(32, 0x01);
|
|
327
327
|
const address = new Address(mldsaHash);
|
|
328
328
|
|
|
329
|
-
expect(() => address.tweakedPublicKeyToBuffer()).toThrow(
|
|
330
|
-
'Classical public key not set',
|
|
331
|
-
);
|
|
329
|
+
expect(() => address.tweakedPublicKeyToBuffer()).toThrow('Legacy public key not set');
|
|
332
330
|
});
|
|
333
331
|
|
|
334
332
|
it('should get toTweakedHybridPublicKeyHex', () => {
|
|
@@ -343,7 +341,7 @@ describe('Address - Comprehensive Tests', () => {
|
|
|
343
341
|
const address = new Address(mldsaHash);
|
|
344
342
|
|
|
345
343
|
expect(() => address.toTweakedHybridPublicKeyHex()).toThrow(
|
|
346
|
-
'
|
|
344
|
+
'Legacy public key not set',
|
|
347
345
|
);
|
|
348
346
|
});
|
|
349
347
|
|
|
@@ -359,7 +357,7 @@ describe('Address - Comprehensive Tests', () => {
|
|
|
359
357
|
const address = new Address(mldsaHash);
|
|
360
358
|
|
|
361
359
|
expect(() => address.toTweakedHybridPublicKeyBuffer()).toThrow(
|
|
362
|
-
'
|
|
360
|
+
'Legacy public key not set',
|
|
363
361
|
);
|
|
364
362
|
});
|
|
365
363
|
});
|
|
@@ -376,7 +374,7 @@ describe('Address - Comprehensive Tests', () => {
|
|
|
376
374
|
const mldsaHash = Buffer.alloc(32, 0x01);
|
|
377
375
|
const address = new Address(mldsaHash);
|
|
378
376
|
|
|
379
|
-
expect(() => address.toUncompressedHex()).toThrow('
|
|
377
|
+
expect(() => address.toUncompressedHex()).toThrow('Legacy public key not set');
|
|
380
378
|
});
|
|
381
379
|
|
|
382
380
|
it('should get uncompressed buffer', () => {
|
|
@@ -391,7 +389,7 @@ describe('Address - Comprehensive Tests', () => {
|
|
|
391
389
|
const mldsaHash = Buffer.alloc(32, 0x01);
|
|
392
390
|
const address = new Address(mldsaHash);
|
|
393
391
|
|
|
394
|
-
expect(() => address.toUncompressedBuffer()).toThrow('
|
|
392
|
+
expect(() => address.toUncompressedBuffer()).toThrow('Legacy public key not set');
|
|
395
393
|
});
|
|
396
394
|
|
|
397
395
|
it('should get hybrid public key hex', () => {
|
|
@@ -405,7 +403,7 @@ describe('Address - Comprehensive Tests', () => {
|
|
|
405
403
|
const mldsaHash = Buffer.alloc(32, 0x01);
|
|
406
404
|
const address = new Address(mldsaHash);
|
|
407
405
|
|
|
408
|
-
expect(() => address.toHybridPublicKeyHex()).toThrow('
|
|
406
|
+
expect(() => address.toHybridPublicKeyHex()).toThrow('Legacy public key not set');
|
|
409
407
|
});
|
|
410
408
|
|
|
411
409
|
it('should get hybrid public key buffer', () => {
|
|
@@ -419,7 +417,7 @@ describe('Address - Comprehensive Tests', () => {
|
|
|
419
417
|
const mldsaHash = Buffer.alloc(32, 0x01);
|
|
420
418
|
const address = new Address(mldsaHash);
|
|
421
419
|
|
|
422
|
-
expect(() => address.toHybridPublicKeyBuffer()).toThrow('
|
|
420
|
+
expect(() => address.toHybridPublicKeyBuffer()).toThrow('Legacy public key not set');
|
|
423
421
|
});
|
|
424
422
|
|
|
425
423
|
it('should get original public key buffer', () => {
|
|
@@ -434,7 +432,7 @@ describe('Address - Comprehensive Tests', () => {
|
|
|
434
432
|
const mldsaHash = Buffer.alloc(32, 0x01);
|
|
435
433
|
const address = new Address(mldsaHash);
|
|
436
434
|
|
|
437
|
-
expect(() => address.originalPublicKeyBuffer()).toThrow('
|
|
435
|
+
expect(() => address.originalPublicKeyBuffer()).toThrow('Legacy public key not set');
|
|
438
436
|
});
|
|
439
437
|
});
|
|
440
438
|
|
|
@@ -646,7 +644,7 @@ describe('Address - Comprehensive Tests', () => {
|
|
|
646
644
|
const mldsaHash = Buffer.alloc(32, 0x01);
|
|
647
645
|
const address = new Address(mldsaHash);
|
|
648
646
|
|
|
649
|
-
expect(() => address.p2wpkh(networks.bitcoin)).toThrow('
|
|
647
|
+
expect(() => address.p2wpkh(networks.bitcoin)).toThrow('Legacy public key not set');
|
|
650
648
|
});
|
|
651
649
|
});
|
|
652
650
|
|
|
@@ -676,7 +674,7 @@ describe('Address - Comprehensive Tests', () => {
|
|
|
676
674
|
const address = new Address(mldsaHash);
|
|
677
675
|
|
|
678
676
|
expect(() => address.p2pkh(networks.bitcoin)).toThrow(
|
|
679
|
-
'
|
|
677
|
+
'Legacy public key not set for address',
|
|
680
678
|
);
|
|
681
679
|
});
|
|
682
680
|
});
|
|
@@ -707,7 +705,7 @@ describe('Address - Comprehensive Tests', () => {
|
|
|
707
705
|
const address = new Address(mldsaHash);
|
|
708
706
|
|
|
709
707
|
expect(() => address.p2shp2wpkh(networks.bitcoin)).toThrow(
|
|
710
|
-
'
|
|
708
|
+
'Legacy public key not set for address',
|
|
711
709
|
);
|
|
712
710
|
});
|
|
713
711
|
});
|
|
@@ -759,7 +757,7 @@ describe('Address - Comprehensive Tests', () => {
|
|
|
759
757
|
const mldsaHash = Buffer.alloc(32, 0x01);
|
|
760
758
|
const address = new Address(mldsaHash);
|
|
761
759
|
|
|
762
|
-
expect(() => address.p2tr(networks.bitcoin)).toThrow('
|
|
760
|
+
expect(() => address.p2tr(networks.bitcoin)).toThrow('Legacy public key not set');
|
|
763
761
|
});
|
|
764
762
|
});
|
|
765
763
|
|
|
@@ -921,12 +919,12 @@ describe('Address - Comprehensive Tests', () => {
|
|
|
921
919
|
});
|
|
922
920
|
});
|
|
923
921
|
|
|
924
|
-
describe('
|
|
922
|
+
describe('isValidLegacyPublicKey Method', () => {
|
|
925
923
|
it('should validate address on mainnet', () => {
|
|
926
924
|
const addr = getValidAddress();
|
|
927
|
-
const
|
|
925
|
+
const isValidLegacyPublicKey = addr.isValidLegacyPublicKey(networks.bitcoin);
|
|
928
926
|
|
|
929
|
-
expect(
|
|
927
|
+
expect(isValidLegacyPublicKey).toBe(true);
|
|
930
928
|
});
|
|
931
929
|
|
|
932
930
|
it('should validate address on testnet', () => {
|
|
@@ -937,9 +935,9 @@ describe('Address - Comprehensive Tests', () => {
|
|
|
937
935
|
MLDSASecurityLevel.LEVEL2,
|
|
938
936
|
);
|
|
939
937
|
const wallet = mnemonic.derive(0);
|
|
940
|
-
const
|
|
938
|
+
const isValidLegacyPublicKey = wallet.address.isValidLegacyPublicKey(networks.testnet);
|
|
941
939
|
|
|
942
|
-
expect(
|
|
940
|
+
expect(isValidLegacyPublicKey).toBe(true);
|
|
943
941
|
});
|
|
944
942
|
});
|
|
945
943
|
|