From a7d8aff2ff499272b65c0f1babd82289622de93a Mon Sep 17 00:00:00 2001 From: Hrishikesh Jain <51024681+hrishikeshjain@users.noreply.github.com> Date: Tue, 7 Apr 2026 13:35:48 +0530 Subject: [PATCH] Revert "fix: add getAddressDetails method for canton" --- modules/sdk-coin-canton/src/canton.ts | 64 ++-------------------- modules/sdk-coin-canton/test/unit/index.ts | 32 +---------- 2 files changed, 5 insertions(+), 91 deletions(-) diff --git a/modules/sdk-coin-canton/src/canton.ts b/modules/sdk-coin-canton/src/canton.ts index 64d3d6391a..0a1d184d72 100644 --- a/modules/sdk-coin-canton/src/canton.ts +++ b/modules/sdk-coin-canton/src/canton.ts @@ -24,7 +24,6 @@ import { } from '@bitgo/sdk-core'; import { auditEddsaPrivateKey } from '@bitgo/sdk-lib-mpc'; import { BaseCoin as StaticsBaseCoin, coins } from '@bitgo/statics'; -import * as querystring from 'querystring'; import { TransactionBuilderFactory } from './lib'; import { KeyPair as CantonKeyPair } from './lib/keyPair'; import utils from './lib/utils'; @@ -37,11 +36,6 @@ export interface ExplainTransactionOptions { txHex: string; } -interface AddressDetails { - address: string; - memoId?: string; -} - export class Canton extends BaseCoin { protected readonly _staticsCoin: Readonly; @@ -125,10 +119,10 @@ export class Canton extends BaseCoin { case TransactionType.Send: if (txParams.recipients !== undefined) { const filteredRecipients = txParams.recipients?.map((recipient) => { - const { amount, tokenName } = recipient; - const { address, memoId } = this.getAddressDetails(recipient.address); + const { address, amount, tokenName } = recipient; + const [addressPart, memoId] = address.split('?memoId='); return { - address, + address: addressPart, amount, ...(memoId && { memo: memoId }), ...(tokenName && { tokenName }), @@ -159,7 +153,7 @@ export class Canton extends BaseCoin { // TODO: refactor this and use the `verifyEddsaMemoBasedWalletAddress` once published from sdk-core // https://bitgoinc.atlassian.net/browse/COIN-6347 const { keychains, address: newAddress, index } = params; - const { address: addressPart, memoId } = this.getAddressDetails(newAddress); + const [addressPart, memoId] = newAddress.split('?memoId='); if (!this.isValidAddress(addressPart)) { throw new InvalidAddressError(`invalid address: ${newAddress}`); } @@ -220,56 +214,6 @@ export class Canton extends BaseCoin { return utils.isValidAddress(address); } - /** - * Process address into address and optional memo id - * - * @param address the address - * @returns object containing base address and optional memo id - */ - getAddressDetails(address: string): AddressDetails { - const queryIndex = address.indexOf('?'); - const destinationAddress = queryIndex >= 0 ? address.slice(0, queryIndex) : address; - const query = queryIndex >= 0 ? address.slice(queryIndex + 1) : undefined; - - // Address without memoId query parameter. - if (query === undefined) { - return { - address, - memoId: undefined, - }; - } - - if (!query || destinationAddress.length === 0) { - throw new InvalidAddressError(`invalid address: ${address}`); - } - - const queryDetails = querystring.parse(query); - if (!queryDetails.memoId) { - throw new InvalidAddressError(`invalid address: ${address}`); - } - - if (Array.isArray(queryDetails.memoId)) { - throw new InvalidAddressError( - `memoId may only be given at most once, but found ${queryDetails.memoId.length} instances in address ${address}` - ); - } - - const queryKeys = Object.keys(queryDetails); - if (queryKeys.length !== 1) { - throw new InvalidAddressError(`invalid address: ${address}`); - } - - const [memoId] = [queryDetails.memoId].filter((value): value is string => typeof value === 'string'); - if (!memoId || memoId.trim().length === 0) { - throw new InvalidAddressError(`invalid address: ${address}`); - } - - return { - address: destinationAddress, - memoId, - }; - } - /** @inheritDoc */ getTokenEnablementConfig(): TokenEnablementConfig { return { diff --git a/modules/sdk-coin-canton/test/unit/index.ts b/modules/sdk-coin-canton/test/unit/index.ts index a70f7feef8..b401d09823 100644 --- a/modules/sdk-coin-canton/test/unit/index.ts +++ b/modules/sdk-coin-canton/test/unit/index.ts @@ -1,45 +1,15 @@ -import should from 'should'; +import 'should'; import { BitGoAPI } from '@bitgo/sdk-api'; -import { InvalidAddressError } from '@bitgo/sdk-core'; import { TestBitGo, TestBitGoAPI } from '@bitgo/sdk-test'; import { Canton, Tcanton } from '../../src'; -import { CANTON_ADDRESSES } from '../resources'; describe('Canton:', function () { let bitgo: TestBitGoAPI; - let basecoin: Canton; before(function () { bitgo = TestBitGo.decorate(BitGoAPI, { env: 'mock' }); bitgo.safeRegister('canton', Canton.createInstance); bitgo.safeRegister('tcanton', Tcanton.createInstance); bitgo.initializeTestVars(); - basecoin = bitgo.coin('canton') as Canton; - }); - - describe('getAddressDetails', function () { - it('should get address details without memoId', function () { - const addressDetails = basecoin.getAddressDetails(CANTON_ADDRESSES.VALID_ADDRESS); - addressDetails.address.should.equal(CANTON_ADDRESSES.VALID_ADDRESS); - should.not.exist(addressDetails.memoId); - }); - - it('should get address details with memoId', function () { - const addressWithMemoId = CANTON_ADDRESSES.VALID_MEMO_ID; - const addressDetails = basecoin.getAddressDetails(addressWithMemoId); - addressDetails.address.should.equal(CANTON_ADDRESSES.VALID_ADDRESS); - should.exist(addressDetails.memoId); - addressDetails.memoId!.should.equal('1'); - }); - - it('should throw on multiple memoId query params', function () { - (() => basecoin.getAddressDetails(`${CANTON_ADDRESSES.VALID_ADDRESS}?memoId=1&memoId=2`)).should.throw( - InvalidAddressError - ); - }); - - it('should throw on unknown query params', function () { - (() => basecoin.getAddressDetails(`${CANTON_ADDRESSES.VALID_ADDRESS}?foo=bar`)).should.throw(InvalidAddressError); - }); }); });