Skip to content

Commit 1544fb9

Browse files
authored
Merge pull request #7536 from BitGo/COIN-6566
feat(sdk-coin-canton): added memoId check for isValidAddress
2 parents 704a646 + f79d2ad commit 1544fb9

File tree

3 files changed

+12
-2
lines changed

3 files changed

+12
-2
lines changed

modules/sdk-coin-canton/src/lib/utils.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,11 @@ export class Utils implements BaseUtils {
1515
isValidAddress(address: string): boolean {
1616
if (!address || address.trim() === '') return false;
1717
const [partyHint, fingerprint] = address.trim().split('::');
18-
if (!partyHint || !fingerprint) return false;
19-
return this.isValidCantonHex(fingerprint);
18+
if (!fingerprint) return false;
19+
// all memoIds are considered valid as long as strings are passed
20+
const [fingerprintPart] = fingerprint.trim().split('?memoId=');
21+
if (!partyHint || !fingerprintPart) return false;
22+
return this.isValidCantonHex(fingerprintPart);
2023
}
2124

2225
/** @inheritdoc */

modules/sdk-coin-canton/test/resources.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ export const CANTON_ADDRESSES = {
8484
INVALID_FINGERPRINT: '12205::12205b4e3537a95126d9060459234gd8ad3c3ddccda4f79901954280ee19c576714d',
8585
MISSING_PARTY_HINT: '::12205b4e3537a95126d9060459234gd8ad3c3ddccda4f79901954280ee19c576714d',
8686
MISSING_FINGERPRINT: '12205::',
87+
VALID_MEMO_ID: '1220a::1220a43d89dc7d8f85316116aac093667f769fce55411aef6846ccb933b2e1a3b598?memoId=1',
8788
};
8889

8990
export const CANTON_BLOCK_HEIGHT = {

modules/sdk-coin-canton/test/unit/utils.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,12 @@ describe('Canton Util', function () {
137137
should.exist(isValid);
138138
assert.strictEqual(isValid, false);
139139
});
140+
141+
it('should return true when memo id is valid', function () {
142+
const isValid = utils.isValidAddress(CANTON_ADDRESSES.VALID_MEMO_ID);
143+
should.exist(isValid);
144+
assert.strictEqual(isValid, true);
145+
});
140146
});
141147

142148
describe('Check if block hash is valid', function () {

0 commit comments

Comments
 (0)