Skip to content

Commit 2ead909

Browse files
committed
feat(sdk-coin-canton): added memoId check for isValidAddress
Ticket: COIN-6566
1 parent 994d837 commit 2ead909

3 files changed

Lines changed: 26 additions & 1 deletion

File tree

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

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,10 @@ 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+
const [fingerprintPart, memoIdPart] = address.trim().split('?memoId=');
19+
if (memoIdPart && !this.isValidMemoId(memoIdPart)) return false;
1820
if (!partyHint || !fingerprint) return false;
19-
return this.isValidCantonHex(fingerprint);
21+
return this.isValidCantonHex(fingerprintPart);
2022
}
2123

2224
/** @inheritdoc */
@@ -56,6 +58,15 @@ export class Utils implements BaseUtils {
5658
return regex.test(value);
5759
}
5860

61+
/**
62+
* Method to validate the input is a valid memo id
63+
* @param {String} value the memo id value
64+
* @returns {Boolean} true if valid
65+
*/
66+
isValidMemoId(value: string): boolean {
67+
return /^[0-9]+$/.test(value);
68+
}
69+
5970
/**
6071
* Helper method to convert hex value to base64
6172
* @param {String} hexString - hex encoded string

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,8 @@ export const CANTON_ADDRESSES = {
8484
INVALID_FINGERPRINT: '12205::12205b4e3537a95126d9060459234gd8ad3c3ddccda4f79901954280ee19c576714d',
8585
MISSING_PARTY_HINT: '::12205b4e3537a95126d9060459234gd8ad3c3ddccda4f79901954280ee19c576714d',
8686
MISSING_FINGERPRINT: '12205::',
87+
INVALID_MEMO_ID: '1220a::1220a43d89dc7d8f85316116aac093667f769fce55411aef6846ccb933b2e1a3b598?memoId=xyz',
88+
VALID_MEMO_ID: '1220a::1220a43d89dc7d8f85316116aac093667f769fce55411aef6846ccb933b2e1a3b598?memoId=1',
8789
};
8890

8991
export const CANTON_BLOCK_HEIGHT = {

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

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

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

0 commit comments

Comments
 (0)