Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function createRequest(
action: RequestLogicTypes.IAction,
timestamp: number,
): RequestLogicTypes.IRequest {
if (!action.data.parameters.payee && !action.data.parameters.payer) {
throw new Error('action.parameters.payee or action.parameters.payer must be given');
}
if (
!Utils.isString(action.data.parameters.expectedAmount) ||
!Utils.amount.isValid(action.data.parameters.expectedAmount)
) {
throw new Error(
'action.parameters.expectedAmount must be a string representing a positive integer',
);
}
const signer: IdentityTypes.IIdentity = Action.getSignerIdentityFromAction(action);
// Copy to not modify the action itself
const request: RequestLogicTypes.IRequest = Utils.deepCopy(action.data.parameters);
request.extensions = {};
request.requestId = Action.getRequestId(action);
request.version = Action.getVersionFromAction(action);
request.events = [generateEvent(action, timestamp, signer)];
function isValid(amount: Types.RequestLogicAmount): boolean {
return (
(bigNumber.isBN(amount) && !amount.isNeg()) ||
(Utils.isString(amount) && regexInteger.test(amount)) ||
(typeof amount === 'number' && (Number.isSafeInteger(Number(amount)) && Number(amount) >= 0))
);
}