|
1 | 1 | import { ValidationUtils } from '../validation-utils/ValidationUtils';
|
2 | 2 | import { FormattableNumber, toNonScientificNumberString } from '../formattable-number/FormattableNumber';
|
| 3 | +import { Utf8Tools } from '../utf8-tools/Utf8Tools'; |
3 | 4 |
|
4 | 5 | // this imports only the type without bundling the library
|
5 | 6 | type BigInteger = import('big-integer').BigInteger;
|
@@ -222,7 +223,11 @@ export function createNimiqRequestLink(
|
222 | 223 |
|
223 | 224 | if (!ValidationUtils.isValidAddress(recipient)) throw new Error(`Not a valid address: ${recipient}`);
|
224 | 225 | if (amount && !isUnsignedSafeInteger(amount)) throw new Error(`Not a valid amount: ${amount}`);
|
225 |
| - if (message && typeof message !== 'string') throw new Error(`Not a valid message: ${message}`); |
| 226 | + if (message && ( |
| 227 | + typeof message !== 'string' |
| 228 | + // Message length is limited to 64 bytes, see BasicAccount.verifyIncomingTransaction in Nimiq core. |
| 229 | + || Utf8Tools.stringToUtf8ByteArray(message).byteLength > 64 |
| 230 | + )) throw new Error(`Not a valid message: ${message}`); |
226 | 231 | if (label && typeof label !== 'string') throw new Error(`Not a valid label: ${label}`);
|
227 | 232 |
|
228 | 233 | recipient = ValidationUtils.normalizeAddress(recipient).replace(/ /g, ''); // normalize and strip spaces
|
@@ -300,6 +305,9 @@ function parseNimiqParams(params: NimiqParams): ParsedNimiqParams | null {
|
300 | 305 |
|
301 | 306 | const { label, message } = params;
|
302 | 307 |
|
| 308 | + // Message length is limited to 64 bytes, see BasicAccount.verifyIncomingTransaction in Nimiq core. |
| 309 | + if (message && Utf8Tools.stringToUtf8ByteArray(message).byteLength > 64) return null; |
| 310 | + |
303 | 311 | return { recipient, amount, label, message };
|
304 | 312 | }
|
305 | 313 |
|
|
0 commit comments