try {
const datastring = Buffer.concat(data).toString()
if (Buffer.byteLength(datastring) > MAX_BODY_SIZE) {
- throw new Error('Invalid data.')
+ throw new Error('Data too large.')
}
const { action, hash, work, difficulty }: WorkGenerateRequest | WorkValidateRequest = JSON.parse(datastring)
if (action !== 'work_generate' && action !== 'work_validate') {
- throw new Error('Invalid action. Must be work_generate or work_validate.')
+ throw new Error('Action must be work_generate or work_validate.')
}
response = `${action} failed`
if (!/^[0-9A-Fa-f]{64}$/.test(hash ?? '')) {
- throw new Error('Invalid hash. Must be a 64-character hex string.')
+ throw new Error('Hash must be a 64-character hex string.')
}
if (difficulty && !/^[0-9A-Fa-f]{0,16}$/.test(difficulty)) {
- throw new Error('Invalid difficulty. Must be a hexadecimal string between 1-FFFFFFFFFFFFFFFF.')
+ throw new Error('Difficulty must be a hex string between 0-FFFFFFFFFFFFFFFF.')
}
if (action === 'work_validate' && !/^[0-9A-Fa-f]{16}$/.test(work ?? '')) {
- throw new Error('Invalid work. Must be a 16-character hex string.')
+ throw new Error('Work must be a 16-character hex string.')
}
const options: NanoPowOptions = {
debug: CONFIG.DEBUG,