Fix error per invalid bip39 word

This commit is contained in:
ekzyis 2024-07-08 08:26:51 +02:00
parent 8a36bffb85
commit 9af8e63355
1 changed files with 11 additions and 2 deletions

View File

@ -657,9 +657,18 @@ export const lncSchema = object({
if (this.isType(value) && value !== null) {
return value
}
return originalValue ? originalValue.split(/[\s]+/) : []
return originalValue ? originalValue.trim().split(/[\s]+/) : []
})
.test(async (words, context) => {
for (const w of words) {
try {
await string().oneOf(bip39Words).validate(w)
} catch {
return context.createError({ message: `'${w}' is not a valid pairing phrase word` })
}
}
return true
})
.of(string().trim().oneOf(bip39Words, ({ value }) => `'${value}' is not a valid pairing phrase word`))
.min(2, 'needs at least two words')
.max(10, 'max 10 words')
.required('required'),