blob: 4108bcb55c2e8f615fef7cd6ae896fd147646a67 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
import validate from 'bitcoin-address-validation';
import bip21 from 'bip21';
import { get } from '$lib/utils';
import { invalid, redirect } from '@sveltejs/kit';
export const actions = {
default: async ({ request }) => {
const values = await request.formData();
const t = values.get('text');
if (!t) return;
// lightning
if (t.startsWith('ln')) {
throw redirect(303, `/send/lightning/${t}`);
}
// bitcoin
if (validate(t)) {
throw redirect(303, `/send/bitcoin/${t}`);
}
// ln address
if (t.includes('@') && t.includes('.')) {
let [name, domain] = t.split('@');
try {
let lnurl = await get(`/encode?domain=${domain}&name=${name}`);
} catch (e) {}
}
// user
return invalid(403, { error: 'Failed to parse destination' });
}
};
|