Skip to content

Commit 1aa4902

Browse files
OttoAllmendingerllm-git
andcommitted
feat(abstract-utxo): remove unused addressType param
Remove redundant addressType parameter that was previously being passed around in address verification functions. The parameter was not needed since the address type can be determined from the chain code. Issue: BTC-2668 Co-authored-by: llm-git <llm-git@ttll.de>
1 parent 82e8bf9 commit 1aa4902

3 files changed

Lines changed: 6 additions & 17 deletions

File tree

modules/abstract-utxo/src/abstractUtxoCoin.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -530,6 +530,7 @@ export abstract class AbstractUtxoCoin
530530
}
531531

532532
/**
533+
* @deprecated - will be removed when we drop support for utxolib
533534
* Determine an address' type based on its witness and redeem script presence
534535
* @param addressDetails
535536
*/
@@ -703,7 +704,6 @@ export abstract class AbstractUtxoCoin
703704
address,
704705
keychains,
705706
format: params.format ?? 'base58',
706-
addressType: params.addressType,
707707
chain,
708708
index,
709709
});

modules/abstract-utxo/src/address/fixedScript.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ export interface FixedScriptAddressCoinSpecific {
2424
}
2525

2626
export interface GenerateAddressOptions {
27-
addressType?: ScriptType2Of3;
2827
chain?: number;
2928
index?: number;
3029
segwit?: boolean;
@@ -98,7 +97,7 @@ export function generateAddress(coinName: UtxoCoinName, params: GenerateFixedScr
9897
}
9998
}
10099

101-
const addressType = normalizeScriptType(params.addressType || convertFlagsToAddressType());
100+
const addressType = normalizeScriptType(convertFlagsToAddressType());
102101

103102
if (addressType !== fixedScriptWallet.ChainCode.scriptType(derivationChain)) {
104103
throw new AddressTypeChainMismatchError(addressType, derivationChain);
@@ -146,14 +145,12 @@ export function assertFixedScriptWalletAddress(
146145
index,
147146
keychains,
148147
format,
149-
addressType,
150148
address,
151149
}: {
152150
chain: number | undefined;
153151
index: number;
154152
keychains: Keychain[];
155153
format: CreateAddressFormat;
156-
addressType: string | undefined;
157154
address: string;
158155
}
159156
): void {
@@ -169,7 +166,6 @@ export function assertFixedScriptWalletAddress(
169166

170167
const expectedAddress = generateAddress(coinName, {
171168
format,
172-
addressType: addressType as ScriptType2Of3,
173169
keychains,
174170
chain,
175171
index,

modules/abstract-utxo/src/transaction/fixedScript/parseOutput.ts

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@ function isMigratedAddress(wallet: IWallet, currentAddress: string): boolean {
7171
interface VerifyCustomChangeAddressOptions {
7272
coin: AbstractUtxoCoin;
7373
customChangeKeys: HandleVerifyAddressErrorOptions['customChangeKeys'];
74-
addressType: HandleVerifyAddressErrorOptions['addressType'];
7574
addressDetails: HandleVerifyAddressErrorOptions['addressDetails'];
7675
currentAddress: HandleVerifyAddressErrorOptions['currentAddress'];
7776
}
@@ -82,10 +81,10 @@ interface VerifyCustomChangeAddressOptions {
8281
* @return {boolean}
8382
*/
8483
async function verifyCustomChangeAddress(params: VerifyCustomChangeAddressOptions): Promise<boolean> {
85-
const { coin, customChangeKeys, addressType, addressDetails, currentAddress } = params;
84+
const { coin, customChangeKeys, addressDetails, currentAddress } = params;
8685
try {
8786
return await coin.verifyAddress(
88-
_.extend({ addressType }, addressDetails, {
87+
_.extend({}, addressDetails, {
8988
keychains: customChangeKeys,
9089
address: currentAddress,
9190
})
@@ -106,7 +105,6 @@ interface HandleVerifyAddressErrorOptions {
106105
customChangeKeys?: CustomChangeOptions['keys'];
107106
coin: AbstractUtxoCoin;
108107
addressDetails?: any;
109-
addressType?: string;
110108
considerMigratedFromAddressInternal?: boolean;
111109
}
112110

@@ -118,7 +116,6 @@ async function handleVerifyAddressError({
118116
customChangeKeys,
119117
coin,
120118
addressDetails,
121-
addressType,
122119
considerMigratedFromAddressInternal,
123120
}: HandleVerifyAddressErrorOptions): Promise<HandleVerifyAddressErrorResponse> {
124121
// Todo: name server-side errors to avoid message-based checking [BG-5124]
@@ -137,7 +134,7 @@ async function handleVerifyAddressError({
137134
// attempt to verify address using custom change address keys if the wallet has that feature enabled
138135
if (
139136
customChangeKeys &&
140-
(await verifyCustomChangeAddress({ coin, addressDetails, addressType, currentAddress, customChangeKeys }))
137+
(await verifyCustomChangeAddress({ coin, addressDetails, currentAddress, customChangeKeys }))
141138
) {
142139
// address is valid against the custom change keys. Mark address as not external
143140
// and request signature verification for the custom change keys
@@ -239,7 +236,6 @@ export async function parseOutput({
239236
const addressDetailsVerification: AddressVerificationData = verification?.addresses?.[currentAddress] ?? {};
240237
debug('Parsing address details for %s', currentAddress);
241238
let currentAddressDetails = undefined;
242-
let currentAddressType: string | undefined = undefined;
243239
const RECIPIENT_THRESHOLD = 1000;
244240
try {
245241
// In the case of PSBTs, we can already determine the internal/external status of the output addresses
@@ -256,7 +252,6 @@ export async function parseOutput({
256252
// can just return the current output as is without contacting the server.
257253
if (isWalletOutput(currentOutput)) {
258254
const res = await coin.isWalletAddress({
259-
addressType: AbstractUtxoCoin.inferAddressType({ chain: currentOutput.chain }) || undefined,
260255
keychains: keychainArray,
261256
address: currentAddress,
262257
chain: currentOutput.chain,
@@ -305,10 +300,9 @@ export async function parseOutput({
305300
});
306301
// verify that the address is on the wallet. verifyAddress throws if
307302
// it fails to correctly rederive the address, meaning it's external
308-
currentAddressType = AbstractUtxoCoin.inferAddressType(addressDetails) || undefined;
309303
currentAddressDetails = addressDetails;
310304
await coin.verifyAddress(
311-
_.extend({ addressType: currentAddressType }, addressDetails, {
305+
_.extend({}, addressDetails, {
312306
keychains: keychainArray,
313307
address: currentAddress,
314308
})
@@ -331,7 +325,6 @@ export async function parseOutput({
331325
txParams,
332326
customChangeKeys: customChange && customChange.keys,
333327
addressDetails: currentAddressDetails,
334-
addressType: currentAddressType,
335328
considerMigratedFromAddressInternal: verification.considerMigratedFromAddressInternal,
336329
})
337330
);

0 commit comments

Comments
 (0)