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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
|
export default (text) => {
if (!text) return;
if (text.includes('@') && text.includes('.')) {
let [name, domain] = text.split('@');
try {
clearTimeout(debounce);
await new Promise((r) => (debounce = setTimeout(r, 1500)));
({ data: text } = await Vue.axios.get(
`/encode?domain=${domain}&name=${name}`
));
} catch (e) {}
}
try {
if (text.toLowerCase().slice(0, 10) === 'lightning:')
text = text.slice(10);
let payreq = text.toLowerCase();
payment.payreq = payreq;
payment.payobj = bolt11.decode(payment.payreq);
let {
network: { bech32 },
} = payment.payobj;
if (!networks.includes('lightning'))
return commit('error', 'Lightning not supported in this account');
if (bech32 !== process.env.VUE_APP_NETWORK_BECH32) {
dispatch('clearPayment');
commit(
'error',
`Wrong network prefix '${bech32}' instead of '${process.env.VUE_APP_NETWORK_BECH32}'`
);
throw new Error('Wrong network');
}
if (user.account.ticker !== 'BTC')
await dispatch(
'shiftAccount',
user.accounts.find((a) => a.asset === BTC).id
);
let { tags, satoshis, millisatoshis } = payment.payobj;
let description = tags.find((t) => t.tagName === 'description');
if (description) payment.memo = description.data;
payment.amount = millisatoshis
? Math.round(millisatoshis / 1000)
: satoshis;
payment.fiatAmount = ((payment.amount * getters.rate) / SATS).toFixed(
2
);
payment.network = 'lightning';
await Vue.axios.post('/lightning/query', { payreq });
if (!getters.payment.recipient)
go({ name: 'send', params: { keep: true } });
return;
} catch (e) {
if (e.response) commit('error', e.response.data);
}
//
// let url;
// try {
// if (nodes.includes('bitcoin')) {
// url = bip21.decode(text);
// if (!networks.includes('bitcoin'))
// return commit('error', 'Bitcoin not supported in this account');
// payment.network = 'bitcoin';
// url.options.asset = BTC;
// }
// } catch (e) {
// if (nodes.includes('liquid')) {
// try {
// url = bip21.decode(text, 'liquidnetwork');
// if (!networks.includes('liquid'))
// return commit('error', 'Liquid not supported in this account');
// payment.network = 'liquid';
// } catch (e) {
// /**/
// }
// }
// }
//
// if (url) {
// let { amount, asset, assetid, message } = url.options;
// if (assetid) asset = assetid;
// if (!asset) asset = BTC;
// let account = user.accounts.find((a) => a.asset === asset);
// if (account) {
// if (account.asset !== user.account.asset)
// await dispatch('shiftAccount', account.id);
// } else return commit('error', 'Unrecognized asset');
//
// payment.address = url.address;
//
// if (message) payment.memo = message;
//
// if (amount) {
// payment.amount = parseInt((amount * SATS).toFixed(0));
// payment.fiatAmount = ((payment.amount * getters.rate) / SATS).toFixed(
// 2
// );
// }
//
// await dispatch('isInternal');
// await dispatch('estimateFee');
// go({ name: 'send', params: { keep: true } });
// return;
// }
//
// if (nodes.includes('bitcoin') && validate(text)) {
// if (!networks.includes('bitcoin'))
// return commit('error', 'Bitcoin not supported in this account');
// payment.address = text;
// payment.network = 'bitcoin';
// await dispatch('isInternal');
// go({ name: 'send', params: { keep: true } });
// return;
// }
//
// // Liquid
// if (nodes.includes('liquid') && isLiquid(text)) {
// if (!networks.includes('liquid'))
// return commit('error', 'Liquid not supported in this account');
// payment.address = text;
// payment.network = 'liquid';
// await dispatch('isInternal');
// go({ name: 'send', params: { keep: true } });
// return;
// }
//
// if (text.startsWith('6P')) {
// commit('text', text);
// return go('/decrypt');
// }
//
// try {
// let ecpair = ECPair.fromWIF(text, {
// ...this._vm.$network,
// confidentialPrefix: 1,
// assetHash: '',
// });
// commit('ecpair', ecpair);
// go('/sweep');
// } catch (e) {
// /* */
// }
//
// if (text.toLowerCase().startsWith('lnurl:')) {
// try {
// const { data: lnurl } = await Vue.axios.get(`/url?code=${text}`);
// await dispatch('handleScan', lnurl);
// return;
// } catch (e) {
// commit('error', e.response ? e.response.data : e.message);
// }
// }
//
// if (text.toLowerCase().includes('lnurl')) {
// commit('loading', true);
// let txt = text.toLowerCase().match(/lnurl[a-z0-9]+/);
//
// try {
// const { data: params } = await Vue.axios.get(`/decode?text=${txt}`);
// if (params.status === 'ERROR') {
// let { reason } = params;
// try {
// ({ reason } = JSON.parse(reason.replace(/.*{/, '{')));
// } catch {
// /**/
// }
//
// commit('loading', false);
// return commit('error', reason);
// }
//
// let { seed } = getters;
//
// switch (params.tag) {
// case 'channelRequest':
// await dispatch('openChannel', params);
// break;
// case 'login':
// if (!seed) ({ seed } = await dispatch('passwordPrompt'));
// try {
// const key = linkingKey(params.domain, seed);
// const signedMessage = secp256k1.ecdsaSign(
// hexToUint8Array(params.k1),
// key.privateKey
// );
// const signedMessageDER = secp256k1.signatureExport(
// signedMessage.signature
// );
// const linkingKeyPub = secp256k1.publicKeyCreate(
// key.privateKey,
// true
// );
// const sig = bytesToHexString(signedMessageDER);
//
// const response = await Vue.axios.post('/login', {
// params,
// sig,
// key: bytesToHexString(linkingKeyPub),
// });
//
// if (response.data.status === 'OK') {
// commit('snack', 'Login success');
// } else {
// commit('error', response.status);
// }
//
// go('/home');
// } catch (e) {
// commit('error', e.response ? e.response.data : e.message);
// }
// break;
//
// case 'withdrawRequest':
// commit('lnurl', params);
// go('/withdraw');
// break;
// case 'payRequest':
// commit('lnurl', params);
// go('/pay');
// break;
// }
// } catch (e) {
// commit('error', e.response ? e.response.data : e.message);
// }
//
// commit('loading', false);
// }
//
// if (isUuid(text)) {
// try {
// const { data: payment } = await Vue.axios.post('/checkRedeemCode', {
// redeemcode: text,
// });
//
// if (payment) {
// window.location.href = `${window.location.protocol}//${window.location.host}/redeem/${text}`;
// return;
// }
// } catch (e) {
// commit('error', e.response ? e.response.data : e.message);
// }
//
// try {
// const { data: invoice } = await Vue.axios.get(
// `/invoice?uuid=${text}`
// );
// await dispatch('handleScan', invoice.text);
// return;
// } catch (e) {
// commit('error', e.response ? e.response.data : e.message);
// }
// }
//
// if (
// text.startsWith(
// `${window.location.protocol}//${window.location.host}/redeem`
// )
// ) {
// window.location.href = text;
// }
//
// commit('stopScanning', true);
//
// return 'no';
};
|