ribbit-wallet-connect
Version:
Next-generation multi-chain wallet and payments app that makes crypto simple, secure, and usable in daily life.
53 lines (52 loc) • 2.01 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.ValidationUtils = void 0;
class ValidationUtils {
static validateTransactionPayload(payload) {
if (typeof payload !== 'object' || payload === null)
return false;
const tx = payload;
return (typeof tx.rawTxn === 'string' &&
typeof tx.chainId === 'number' &&
(tx.meta === undefined ||
(typeof tx.meta === 'object' && tx.meta !== null)));
}
static validateRawTxnRequest(req) {
const requiredFields = [
'sender',
'sequenceNumber',
'moduleAddress',
'moduleName',
'functionName',
'args',
'maxGasAmount',
'gasUnitPrice',
'expirationTimestampSecs',
'chainId',
];
for (const field of requiredFields) {
if (req[field] === undefined ||
req[field] === null ||
(typeof req[field] === 'string' &&
req[field] === '')) {
throw new Error(`Missing or invalid required field: ${field}`);
}
}
// if (!Array.isArray(req.args) || req.args.length === 0) {
// throw new Error('args must be a non-empty array');
// }
// if (req.typeArgs && !Array.isArray(req.typeArgs)) {
// throw new Error('typeArgs must be an array if provided');
// }
// // Add more specific checks as needed (e.g., address format, number ranges)
// // Example: check if sender/moduleAddress are valid hex strings
// const hexRegex = /^0x[a-fA-F0-9]{1,64}$/;
// if (!hexRegex.test(req.sender)) {
// throw new Error('sender must be a valid hex address');
// }
// if (!hexRegex.test(req.moduleAddress)) {
// throw new Error('moduleAddress must be a valid hex address');
// }
}
}
exports.ValidationUtils = ValidationUtils;