@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
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Network, networks, toXOnly } from '@btc-vision/bitcoin';
|
|
2
2
|
import { BinaryWriter } from '../buffer/BinaryWriter.js';
|
|
3
|
-
import { AccessListFeature, EpochSubmissionFeature, Feature, Features } from './Features.js';
|
|
3
|
+
import { AccessListFeature, EpochSubmissionFeature, Feature, Features, MLDSALinkRequest, } from './Features.js';
|
|
4
4
|
import { Address } from '../keypair/Address.js';
|
|
5
5
|
import { Compressor } from '../bytecode/Compressor.js';
|
|
6
6
|
|
|
@@ -117,6 +117,11 @@ export abstract class Generator {
|
|
|
117
117
|
this.encodeChallengeSubmission(feature as EpochSubmissionFeature),
|
|
118
118
|
);
|
|
119
119
|
}
|
|
120
|
+
case Features.MLDSA_LINK_PUBKEY: {
|
|
121
|
+
return this.splitBufferIntoChunks(
|
|
122
|
+
this.encodeLinkRequest(feature as MLDSALinkRequest),
|
|
123
|
+
);
|
|
124
|
+
}
|
|
120
125
|
default:
|
|
121
126
|
throw new Error(`Unknown feature type: ${feature.opcode}`);
|
|
122
127
|
}
|
|
@@ -154,7 +159,7 @@ export abstract class Generator {
|
|
|
154
159
|
}
|
|
155
160
|
|
|
156
161
|
const writer = new BinaryWriter();
|
|
157
|
-
writer.writeBytes(feature.data.publicKey.
|
|
162
|
+
writer.writeBytes(feature.data.publicKey.toBuffer());
|
|
158
163
|
writer.writeBytes(feature.data.solution);
|
|
159
164
|
|
|
160
165
|
if (feature.data.graffiti) {
|
|
@@ -163,4 +168,32 @@ export abstract class Generator {
|
|
|
163
168
|
|
|
164
169
|
return Buffer.from(writer.getBuffer());
|
|
165
170
|
}
|
|
171
|
+
|
|
172
|
+
private encodeLinkRequest(feature: MLDSALinkRequest): Buffer {
|
|
173
|
+
const data = feature.data;
|
|
174
|
+
|
|
175
|
+
const writer = new BinaryWriter();
|
|
176
|
+
writer.writeU8(data.level);
|
|
177
|
+
writer.writeBytes(data.hashedPublicKey);
|
|
178
|
+
writer.writeBoolean(data.verifyRequest);
|
|
179
|
+
|
|
180
|
+
if (data.verifyRequest) {
|
|
181
|
+
if (!data.publicKey || !data.mldsaSignature) {
|
|
182
|
+
throw new Error(
|
|
183
|
+
'MLDSA public key and signature required when verifyRequest is true',
|
|
184
|
+
);
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
writer.writeBytes(data.publicKey);
|
|
188
|
+
writer.writeBytes(data.mldsaSignature);
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
if (!data.legacySignature || data.legacySignature.length !== 64) {
|
|
192
|
+
throw new Error('Legacy signature must be exactly 64 bytes');
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
writer.writeBytes(data.legacySignature);
|
|
196
|
+
|
|
197
|
+
return Buffer.from(writer.getBuffer());
|
|
198
|
+
}
|
|
166
199
|
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { MLDSASecurityLevel } from '@btc-vision/bip32';
|
|
2
|
+
|
|
3
|
+
export enum MLDSAPublicKeyMetadata {
|
|
4
|
+
MLDSA44 = 1312,
|
|
5
|
+
MLDSA65 = 1952,
|
|
6
|
+
MLDSA87 = 2592,
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export interface MLDSARequestData {
|
|
10
|
+
readonly verifyRequest: boolean;
|
|
11
|
+
readonly publicKey: Uint8Array | Buffer | null;
|
|
12
|
+
readonly hashedPublicKey: Uint8Array | Buffer;
|
|
13
|
+
readonly level: MLDSASecurityLevel;
|
|
14
|
+
|
|
15
|
+
readonly mldsaSignature: Uint8Array | Buffer | null;
|
|
16
|
+
readonly legacySignature: Uint8Array | Buffer;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function getLevelFromPublicKeyLength(length: number): MLDSASecurityLevel {
|
|
20
|
+
switch (length) {
|
|
21
|
+
case MLDSAPublicKeyMetadata.MLDSA44 as number:
|
|
22
|
+
return MLDSASecurityLevel.LEVEL2;
|
|
23
|
+
case MLDSAPublicKeyMetadata.MLDSA65 as number:
|
|
24
|
+
return MLDSASecurityLevel.LEVEL3;
|
|
25
|
+
case MLDSAPublicKeyMetadata.MLDSA87 as number:
|
|
26
|
+
return MLDSASecurityLevel.LEVEL5;
|
|
27
|
+
default:
|
|
28
|
+
throw new Error(`Invalid MLDSA public key length: ${length}`);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
@@ -41,6 +41,7 @@ export class DeploymentGenerator extends Generator {
|
|
|
41
41
|
calldata,
|
|
42
42
|
features,
|
|
43
43
|
);
|
|
44
|
+
|
|
44
45
|
const compiled = script.compile(asm);
|
|
45
46
|
|
|
46
47
|
/**
|
|
@@ -85,7 +86,7 @@ export class DeploymentGenerator extends Generator {
|
|
|
85
86
|
opcodes.OP_TOALTSTACK,
|
|
86
87
|
|
|
87
88
|
// CHALLENGE PREIMAGE FOR REWARD,
|
|
88
|
-
challenge.publicKey.
|
|
89
|
+
challenge.publicKey.toBuffer(),
|
|
89
90
|
opcodes.OP_TOALTSTACK,
|
|
90
91
|
|
|
91
92
|
challenge.solution,
|
|
@@ -7,6 +7,7 @@ import { Feature, Features } from '../Features.js';
|
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
9
|
* Class to generate bitcoin script for interaction transactions
|
|
10
|
+
* @deprecated
|
|
10
11
|
*/
|
|
11
12
|
export class LegacyCalldataGenerator extends Generator {
|
|
12
13
|
constructor(senderPubKey: Buffer, network: Network = networks.bitcoin) {
|
|
@@ -4,6 +4,10 @@ import { Feature, Features } from '../Features.js';
|
|
|
4
4
|
import { Generator } from '../Generator.js';
|
|
5
5
|
import { ChallengeSolution } from '../../epoch/ChallengeSolution.js';
|
|
6
6
|
|
|
7
|
+
/**
|
|
8
|
+
* @category Generators
|
|
9
|
+
* @remarks Not fully implemented yet
|
|
10
|
+
*/
|
|
7
11
|
export class P2WDAGenerator extends Generator {
|
|
8
12
|
private static readonly P2WDA_VERSION = 0x01;
|
|
9
13
|
|
|
@@ -90,7 +94,7 @@ export class P2WDAGenerator extends Generator {
|
|
|
90
94
|
writer.writeBytes(contractSecret);
|
|
91
95
|
|
|
92
96
|
// Challenge components for epoch rewards
|
|
93
|
-
writer.writeBytes(challenge.publicKey.
|
|
97
|
+
writer.writeBytes(challenge.publicKey.toBuffer());
|
|
94
98
|
writer.writeBytes(challenge.solution);
|
|
95
99
|
|
|
96
100
|
// Calldata with length prefix
|
package/src/keypair/Address.ts
CHANGED
|
@@ -9,6 +9,7 @@ import { TimeLockGenerator } from '../transaction/mineable/TimelockGenerator.js'
|
|
|
9
9
|
import { IP2WSHAddress } from '../transaction/mineable/IP2WSHAddress.js';
|
|
10
10
|
import { P2WDADetector } from '../p2wda/P2WDADetector.js';
|
|
11
11
|
import { sha256 } from '@noble/hashes/sha2';
|
|
12
|
+
import { MLDSASecurityLevel } from '@btc-vision/bip32';
|
|
12
13
|
|
|
13
14
|
/**
|
|
14
15
|
* Objects of type "Address" represent hashed ML-DSA (quantum) public keys (using SHA256 of quantum keys) and maintain classical public keys separately.
|
|
@@ -32,8 +33,10 @@ export class Address extends Uint8Array {
|
|
|
32
33
|
#mldsaPublicKey: Uint8Array | undefined;
|
|
33
34
|
#cachedBigInt: bigint | undefined;
|
|
34
35
|
#cachedUint64Array: [bigint, bigint, bigint, bigint] | undefined;
|
|
36
|
+
#originalMDLSAPublicKey: Uint8Array | undefined;
|
|
37
|
+
#mldsaLevel: MLDSASecurityLevel | undefined;
|
|
35
38
|
|
|
36
|
-
private
|
|
39
|
+
private legacyPublicKey: Uint8Array | undefined;
|
|
37
40
|
|
|
38
41
|
public constructor(mldsaPublicKey?: ArrayLike<number>, publicKeyOrTweak?: ArrayLike<number>) {
|
|
39
42
|
super(ADDRESS_BYTE_LENGTH);
|
|
@@ -43,13 +46,29 @@ export class Address extends Uint8Array {
|
|
|
43
46
|
}
|
|
44
47
|
|
|
45
48
|
if (publicKeyOrTweak) {
|
|
46
|
-
this.
|
|
47
|
-
this.
|
|
49
|
+
this.legacyPublicKey = new Uint8Array(publicKeyOrTweak.length);
|
|
50
|
+
this.legacyPublicKey.set(publicKeyOrTweak);
|
|
48
51
|
}
|
|
49
52
|
|
|
50
53
|
this.set(mldsaPublicKey);
|
|
51
54
|
}
|
|
52
55
|
|
|
56
|
+
public get mldsaLevel(): MLDSASecurityLevel | undefined {
|
|
57
|
+
return this.#mldsaLevel;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
public set mldsaLevel(level: MLDSASecurityLevel) {
|
|
61
|
+
this.#mldsaLevel = level;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
public get originalMDLSAPublicKey(): Uint8Array | undefined {
|
|
65
|
+
return this.#originalMDLSAPublicKey;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
public set originalMDLSAPublicKey(key: Buffer | Uint8Array) {
|
|
69
|
+
this.#originalMDLSAPublicKey = new Uint8Array(key);
|
|
70
|
+
}
|
|
71
|
+
|
|
53
72
|
/**
|
|
54
73
|
* If available, this will return the original public key associated with the address.
|
|
55
74
|
* @returns {Uint8Array} The original public key used to create the address.
|
|
@@ -68,7 +87,7 @@ export class Address extends Uint8Array {
|
|
|
68
87
|
*/
|
|
69
88
|
private get keyPair(): ECPairInterface {
|
|
70
89
|
if (!this.#keyPair) {
|
|
71
|
-
throw new Error('
|
|
90
|
+
throw new Error('Legacy public key not set for address');
|
|
72
91
|
}
|
|
73
92
|
|
|
74
93
|
return this.#keyPair;
|
|
@@ -84,10 +103,10 @@ export class Address extends Uint8Array {
|
|
|
84
103
|
/**
|
|
85
104
|
* Create an address from a hex string
|
|
86
105
|
* @param {string} mldsaPublicKey The ml-dsa public key in hex format
|
|
87
|
-
* @param {string}
|
|
106
|
+
* @param {string} legacyPublicKey The classical public key in hex format
|
|
88
107
|
* @returns {Address} The address
|
|
89
108
|
*/
|
|
90
|
-
public static fromString(mldsaPublicKey: string,
|
|
109
|
+
public static fromString(mldsaPublicKey: string, legacyPublicKey?: string): Address {
|
|
91
110
|
if (!mldsaPublicKey) {
|
|
92
111
|
throw new Error('Invalid public key');
|
|
93
112
|
}
|
|
@@ -103,18 +122,18 @@ export class Address extends Uint8Array {
|
|
|
103
122
|
}
|
|
104
123
|
|
|
105
124
|
let classicBuffer: Buffer | undefined;
|
|
106
|
-
if (
|
|
107
|
-
if (
|
|
108
|
-
|
|
125
|
+
if (legacyPublicKey) {
|
|
126
|
+
if (legacyPublicKey.startsWith('0x')) {
|
|
127
|
+
legacyPublicKey = legacyPublicKey.slice(2);
|
|
109
128
|
}
|
|
110
129
|
|
|
111
|
-
if (!BitcoinUtils.isValidHex(
|
|
130
|
+
if (!BitcoinUtils.isValidHex(legacyPublicKey)) {
|
|
112
131
|
throw new Error(
|
|
113
132
|
'You must only pass classical public keys in hexadecimal format. If you have an address such as bc1q... you must convert it to a public key first. Please refer to await provider.getPublicKeyInfo("bc1q..."). If the public key associated with the address is not found, you must force the user to enter the destination public key. It looks like: 0x020373626d317ae8788ce3280b491068610d840c23ecb64c14075bbb9f670af52c.',
|
|
114
133
|
);
|
|
115
134
|
}
|
|
116
135
|
|
|
117
|
-
classicBuffer = Buffer.from(
|
|
136
|
+
classicBuffer = Buffer.from(legacyPublicKey, 'hex');
|
|
118
137
|
}
|
|
119
138
|
|
|
120
139
|
return new Address(Buffer.from(mldsaPublicKey, 'hex'), classicBuffer);
|
|
@@ -245,6 +264,20 @@ export class Address extends Uint8Array {
|
|
|
245
264
|
return this.#cachedUint64Array;
|
|
246
265
|
}
|
|
247
266
|
|
|
267
|
+
/**
|
|
268
|
+
* Check if the address is the dead address
|
|
269
|
+
* @returns {boolean}
|
|
270
|
+
*/
|
|
271
|
+
public isDead(): boolean {
|
|
272
|
+
for (let i = 0; i < ADDRESS_BYTE_LENGTH; i++) {
|
|
273
|
+
if (this[i] !== 0) {
|
|
274
|
+
return false;
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
return true;
|
|
279
|
+
}
|
|
280
|
+
|
|
248
281
|
/**
|
|
249
282
|
* Converts the address to a hex string
|
|
250
283
|
* @returns {string} The hex string
|
|
@@ -258,11 +291,11 @@ export class Address extends Uint8Array {
|
|
|
258
291
|
* @returns {string} The hex string
|
|
259
292
|
*/
|
|
260
293
|
public tweakedToHex(): string {
|
|
261
|
-
if (!this.
|
|
262
|
-
throw new Error('
|
|
294
|
+
if (!this.legacyPublicKey) {
|
|
295
|
+
throw new Error('Legacy public key not set');
|
|
263
296
|
}
|
|
264
297
|
|
|
265
|
-
return '0x' + Buffer.from(this.
|
|
298
|
+
return '0x' + Buffer.from(this.legacyPublicKey).toString('hex');
|
|
266
299
|
}
|
|
267
300
|
|
|
268
301
|
/**
|
|
@@ -278,16 +311,16 @@ export class Address extends Uint8Array {
|
|
|
278
311
|
* @returns {Buffer} The buffer
|
|
279
312
|
*/
|
|
280
313
|
public tweakedPublicKeyToBuffer(): Buffer {
|
|
281
|
-
if (!this.
|
|
282
|
-
throw new Error('
|
|
314
|
+
if (!this.legacyPublicKey) {
|
|
315
|
+
throw new Error('Legacy public key not set');
|
|
283
316
|
}
|
|
284
317
|
|
|
285
|
-
return Buffer.from(this.
|
|
318
|
+
return Buffer.from(this.legacyPublicKey);
|
|
286
319
|
}
|
|
287
320
|
|
|
288
321
|
public toUncompressedHex(): string {
|
|
289
322
|
if (!this.#uncompressed) {
|
|
290
|
-
throw new Error('
|
|
323
|
+
throw new Error('Legacy public key not set');
|
|
291
324
|
}
|
|
292
325
|
|
|
293
326
|
return '0x' + this.#uncompressed.uncompressed.toString('hex');
|
|
@@ -295,7 +328,7 @@ export class Address extends Uint8Array {
|
|
|
295
328
|
|
|
296
329
|
public toUncompressedBuffer(): Buffer {
|
|
297
330
|
if (!this.#uncompressed) {
|
|
298
|
-
throw new Error('
|
|
331
|
+
throw new Error('Legacy public key not set');
|
|
299
332
|
}
|
|
300
333
|
|
|
301
334
|
return this.#uncompressed.uncompressed;
|
|
@@ -303,7 +336,7 @@ export class Address extends Uint8Array {
|
|
|
303
336
|
|
|
304
337
|
public toHybridPublicKeyHex(): string {
|
|
305
338
|
if (!this.#uncompressed) {
|
|
306
|
-
throw new Error('
|
|
339
|
+
throw new Error('Legacy public key not set');
|
|
307
340
|
}
|
|
308
341
|
|
|
309
342
|
return '0x' + this.#uncompressed.hybrid.toString('hex');
|
|
@@ -311,7 +344,7 @@ export class Address extends Uint8Array {
|
|
|
311
344
|
|
|
312
345
|
public toHybridPublicKeyBuffer(): Buffer {
|
|
313
346
|
if (!this.#uncompressed) {
|
|
314
|
-
throw new Error('
|
|
347
|
+
throw new Error('Legacy public key not set');
|
|
315
348
|
}
|
|
316
349
|
|
|
317
350
|
return this.#uncompressed.hybrid;
|
|
@@ -319,7 +352,7 @@ export class Address extends Uint8Array {
|
|
|
319
352
|
|
|
320
353
|
public originalPublicKeyBuffer(): Buffer {
|
|
321
354
|
if (!this.#originalPublicKey) {
|
|
322
|
-
throw new Error('
|
|
355
|
+
throw new Error('Legacy public key not set');
|
|
323
356
|
}
|
|
324
357
|
|
|
325
358
|
return Buffer.from(this.#originalPublicKey);
|
|
@@ -421,19 +454,19 @@ export class Address extends Uint8Array {
|
|
|
421
454
|
* @returns {void}
|
|
422
455
|
*/
|
|
423
456
|
public override set(mldsaPublicKey: ArrayLike<number>): void {
|
|
424
|
-
if (this.
|
|
457
|
+
if (this.legacyPublicKey) {
|
|
425
458
|
const validLengths = [ADDRESS_BYTE_LENGTH, 33, 65];
|
|
426
|
-
if (!validLengths.includes(this.
|
|
427
|
-
throw new Error(`Invalid public key length ${this.
|
|
459
|
+
if (!validLengths.includes(this.legacyPublicKey.length)) {
|
|
460
|
+
throw new Error(`Invalid public key length ${this.legacyPublicKey.length}`);
|
|
428
461
|
}
|
|
429
462
|
|
|
430
|
-
if (this.
|
|
463
|
+
if (this.legacyPublicKey.length === ADDRESS_BYTE_LENGTH) {
|
|
431
464
|
const buf = Buffer.alloc(ADDRESS_BYTE_LENGTH);
|
|
432
|
-
buf.set(this.
|
|
465
|
+
buf.set(this.legacyPublicKey);
|
|
433
466
|
|
|
434
467
|
this.#tweakedUncompressed = ContractAddress.generateHybridKeyFromHash(buf);
|
|
435
468
|
} else {
|
|
436
|
-
this.autoFormat(this.
|
|
469
|
+
this.autoFormat(this.legacyPublicKey);
|
|
437
470
|
}
|
|
438
471
|
}
|
|
439
472
|
|
|
@@ -475,8 +508,15 @@ export class Address extends Uint8Array {
|
|
|
475
508
|
* @param {Network} network The network
|
|
476
509
|
* @returns {boolean} If the public key is valid
|
|
477
510
|
*/
|
|
478
|
-
public
|
|
479
|
-
|
|
511
|
+
public isValidLegacyPublicKey(network: Network): boolean {
|
|
512
|
+
if (!this.legacyPublicKey) {
|
|
513
|
+
throw new Error(`Legacy key not set.`);
|
|
514
|
+
}
|
|
515
|
+
|
|
516
|
+
return AddressVerificator.isValidPublicKey(
|
|
517
|
+
Buffer.from(this.legacyPublicKey).toString('hex'),
|
|
518
|
+
network,
|
|
519
|
+
);
|
|
480
520
|
}
|
|
481
521
|
|
|
482
522
|
/**
|
|
@@ -529,8 +569,8 @@ export class Address extends Uint8Array {
|
|
|
529
569
|
* @param {Network} network The network
|
|
530
570
|
*/
|
|
531
571
|
public p2tr(network: Network): string {
|
|
532
|
-
if (!this.
|
|
533
|
-
throw new Error('
|
|
572
|
+
if (!this.legacyPublicKey) {
|
|
573
|
+
throw new Error('Legacy public key not set');
|
|
534
574
|
}
|
|
535
575
|
|
|
536
576
|
if (this.#p2tr && this.#network === network) {
|
|
@@ -538,7 +578,7 @@ export class Address extends Uint8Array {
|
|
|
538
578
|
}
|
|
539
579
|
|
|
540
580
|
const p2trAddy: string | undefined = EcKeyPair.tweakedPubKeyBufferToAddress(
|
|
541
|
-
this.
|
|
581
|
+
this.legacyPublicKey,
|
|
542
582
|
network,
|
|
543
583
|
);
|
|
544
584
|
|
|
@@ -549,7 +589,7 @@ export class Address extends Uint8Array {
|
|
|
549
589
|
return p2trAddy;
|
|
550
590
|
}
|
|
551
591
|
|
|
552
|
-
throw new Error('
|
|
592
|
+
throw new Error('Legacy public key not set');
|
|
553
593
|
}
|
|
554
594
|
|
|
555
595
|
/**
|
|
@@ -665,7 +705,7 @@ export class Address extends Uint8Array {
|
|
|
665
705
|
|
|
666
706
|
public toTweakedHybridPublicKeyHex(): string {
|
|
667
707
|
if (!this.#tweakedUncompressed) {
|
|
668
|
-
throw new Error('
|
|
708
|
+
throw new Error('Legacy public key not set');
|
|
669
709
|
}
|
|
670
710
|
|
|
671
711
|
return '0x' + this.#tweakedUncompressed.toString('hex');
|
|
@@ -673,7 +713,7 @@ export class Address extends Uint8Array {
|
|
|
673
713
|
|
|
674
714
|
public toTweakedHybridPublicKeyBuffer(): Buffer {
|
|
675
715
|
if (!this.#tweakedUncompressed) {
|
|
676
|
-
throw new Error('
|
|
716
|
+
throw new Error('Legacy public key not set');
|
|
677
717
|
}
|
|
678
718
|
|
|
679
719
|
return this.#tweakedUncompressed;
|
|
@@ -699,7 +739,7 @@ export class Address extends Uint8Array {
|
|
|
699
739
|
|
|
700
740
|
this.#tweakedUncompressed = ContractAddress.generateHybridKeyFromHash(tweakedBytes);
|
|
701
741
|
|
|
702
|
-
this.
|
|
703
|
-
this.
|
|
742
|
+
this.legacyPublicKey = new Uint8Array(ADDRESS_BYTE_LENGTH);
|
|
743
|
+
this.legacyPublicKey.set(tweakedBytes);
|
|
704
744
|
}
|
|
705
745
|
}
|