Skip to content

Commit aa87e45

Browse files
committed
refactor: simplify
TICKET: WP-7081
1 parent 642fce1 commit aa87e45

File tree

1 file changed

+10
-31
lines changed
  • modules/sdk-coin-apt/src

1 file changed

+10
-31
lines changed

modules/sdk-coin-apt/src/apt.ts

Lines changed: 10 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import {
33
BaseCoin,
44
BaseTransaction,
55
BitGoBase,
6-
InvalidAddressError,
76
KeyPair,
87
MPCAlgorithm,
98
MultisigType,
@@ -15,8 +14,9 @@ import {
1514
SignedTransaction,
1615
SignTransactionOptions,
1716
TssVerifyAddressOptions,
17+
UnexpectedAddressError,
18+
verifyEddsaTssWalletAddress,
1819
VerifyTransactionOptions,
19-
verifyMPCWalletAddress,
2020
} from '@bitgo/sdk-core';
2121
import { BaseCoin as StaticsBaseCoin, coins } from '@bitgo/statics';
2222
import { KeyPair as AptKeyPair, TransactionBuilderFactory } from './lib';
@@ -31,11 +31,6 @@ export interface AptParseTransactionOptions extends ParseTransactionOptions {
3131
txHex: string;
3232
}
3333

34-
export interface TssVerifyAptAddressOptions extends TssVerifyAddressOptions {
35-
address: string;
36-
rootAddress?: string;
37-
}
38-
3934
export class Apt extends BaseCoin {
4035
protected readonly _staticsCoin: Readonly<StaticsBaseCoin>;
4136
protected constructor(bitgo: BitGoBase, staticsCoin?: Readonly<StaticsBaseCoin>) {
@@ -129,33 +124,17 @@ export class Apt extends BaseCoin {
129124
/**
130125
* Verify that an address belongs to this wallet.
131126
*
132-
* @param {TssVerifyAptAddressOptions} params - Verification parameters
133-
* @returns {Promise<boolean>} True if address belongs to wallet
134-
* @throws {InvalidAddressError} If address format is invalid or doesn't match derived address
127+
* @param params - Verification parameters including address, keychains, and index
128+
* @returns True if address belongs to wallet
129+
* @throws UnexpectedAddressError if address doesn't match derived address
135130
*/
136-
async isWalletAddress(params: TssVerifyAptAddressOptions): Promise<boolean> {
137-
const { address, rootAddress } = params;
138-
139-
if (!this.isValidAddress(address)) {
140-
throw new InvalidAddressError(`invalid address: ${address}`);
141-
}
142-
143-
const isVerifyingRootAddress = rootAddress && address.toLowerCase() === rootAddress.toLowerCase();
144-
if (isVerifyingRootAddress) {
145-
const index = typeof params.index === 'string' ? parseInt(params.index, 10) : params.index;
146-
if (index !== 0) {
147-
throw new Error(`Root address verification requires index 0, but got index ${params.index}.`);
148-
}
149-
}
150-
151-
const result = await verifyMPCWalletAddress(
152-
{ ...params, keyCurve: 'ed25519' },
153-
this.isValidAddress.bind(this),
154-
(pubKey) => utils.getAddressFromPublicKey(pubKey)
131+
async isWalletAddress(params: TssVerifyAddressOptions): Promise<boolean> {
132+
const isValid = await verifyEddsaTssWalletAddress(params, this.isValidAddress.bind(this), (pubKey) =>
133+
utils.getAddressFromPublicKey(pubKey)
155134
);
156135

157-
if (!result) {
158-
throw new InvalidAddressError(`invalid address: ${address}`);
136+
if (!isValid) {
137+
throw new UnexpectedAddressError();
159138
}
160139

161140
return true;

0 commit comments

Comments
 (0)