import config from "$config"; import { CashuMint, CashuWallet, getDecodedToken, getEncodedToken, getEncodedTokenV4, } from "@cashu/cashu-ts"; import { g, s } from "$lib/db"; import { fail } from "$lib/utils"; let m = new CashuMint(config.mintUrl); let w = new CashuWallet(m); let enc = (proofs, v = 4) => (v === 4 ? getEncodedTokenV4 : getEncodedToken)({ token: [{ mint: config.mintUrl, proofs }], }); let dec = (token) => getDecodedToken(token).token[0]; let ext = async (mint) => { let issuer = new CashuMint(mint); let { pubkey: issuerPk } = await issuer.getInfo(); let { pubkey: ourPk } = await m.getInfo(); return issuerPk !== ourPk; }; export async function get(id, v = 4) { let token = await g(`cash:${id}`); if (v < 4) return enc(dec(token).proofs, 3); return token; } export async function claim(token) { let { proofs: current } = dec(await g(`cash`)); let { mint } = dec(token); if (await ext(mint)) fail("Unable to receive from other mints"); let rcvd = await w.receive(token); await s(`cash`, enc([...current, ...rcvd])); return rcvd.reduce((a, b) => a + b.amount, 0); } export async function mint(amount, v = 4) { let { proofs } = dec(await g(`cash`)); let { send, returnChange } = await w.send(amount, proofs); let rcvd = await w.receive(enc(send, v)); let change = enc(returnChange, v); await s(`cash`, change); return enc(rcvd, v); } export async function check(token) { let o = dec(token); let { mint, proofs } = o; let total = proofs.reduce((a, b) => a + b.amount, 0); let external = await ext(mint); let r = await w.checkProofsSpent(proofs); let spent = r.reduce((a, b) => a + b.amount, 0); return { total, spent, mint, external }; } f7768'>diffstats
path: root/tools/feed-new-posts-test.js
blob: aa3e6670ab0b2fa9e0d8323d20322e7ab0ac6c8d (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
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