Skip to content

Commit 14d543f

Browse files
Copilotriccardobl
andcommitted
Initial exploration and understanding of nwcprovider codebase structure
Co-authored-by: riccardobl <[email protected]>
1 parent 49204ad commit 14d543f

File tree

3 files changed

+53
-42
lines changed

3 files changed

+53
-42
lines changed

migrations.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,12 +87,13 @@ async def m004_default_config2(db):
8787
Default config
8888
"""
8989
await db.execute(
90-
"""
90+
"""
9191
INSERT INTO nwcprovider.config (key, value) VALUES ('relay_alias', :value)
9292
ON CONFLICT (key) DO UPDATE SET value = EXCLUDED.value;
9393
""",
94-
{"value": ""},
95-
)
94+
{"value": ""},
95+
)
96+
9697

9798
async def m005_key_last_used(db):
9899
"""

static/js/noble-secp256k1.min.js

Lines changed: 28 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ const B256 = 2n ** 256n,
3030
isPoint = (t) => (t instanceof Point ? t : err("Point expected"));
3131
class Point {
3232
constructor(t, n, e) {
33-
(this.px = t), (this.py = n), (this.pz = e);
33+
((this.px = t), (this.py = n), (this.pz = e));
3434
}
3535
static fromAffine(t) {
3636
return 0n === t.x && 0n === t.y ? Point.ZERO : new Point(t.x, t.y, 1n);
@@ -44,8 +44,8 @@ class Point {
4444
if (33 === i && [2, 3].includes(e)) {
4545
fe(o) || err("Point hex invalid: x not FE");
4646
let t = sqrt(crv(o));
47-
!(1 & ~e) !== (1n === (1n & t)) && (t = mod(-t)),
48-
(n = new Point(o, t, 1n));
47+
(!(1 & ~e) !== (1n === (1n & t)) && (t = mod(-t)),
48+
(n = new Point(o, t, 1n)));
4949
}
5050
return (
5151
65 === i && 4 === e && (n = new Point(o, slcNum(r, 32, 64), 1n)),
@@ -89,7 +89,7 @@ class Point {
8989
f = mod(r * s),
9090
p = mod(n + e),
9191
b = mod(o + i);
92-
(p = mod(p * b)), (b = mod(l + y)), (p = mod(p - b)), (b = mod(n + r));
92+
((p = mod(p * b)), (b = mod(l + y)), (p = mod(p - b)), (b = mod(n + r)));
9393
let g = mod(o + s);
9494
return (
9595
(b = mod(b * g)),
@@ -173,7 +173,7 @@ class Point {
173173
return h2b(this.toHex(t));
174174
}
175175
}
176-
(Point.BASE = new Point(Gx, Gy, 1n)), (Point.ZERO = new Point(0n, 1n, 0n));
176+
((Point.BASE = new Point(Gx, Gy, 1n)), (Point.ZERO = new Point(0n, 1n, 0n)));
177177
const { BASE: G, ZERO: I } = Point,
178178
padh = (t, n) => t.toString(16).padStart(n, "0"),
179179
b2h = (t) =>
@@ -188,7 +188,7 @@ const { BASE: G, ZERO: I } = Point,
188188
const r = 2 * n,
189189
o = t.slice(r, r + 2),
190190
i = Number.parseInt(o, 16);
191-
(Number.isNaN(i) || i < 0) && err("hex invalid 2"), (e[n] = i);
191+
((Number.isNaN(i) || i < 0) && err("hex invalid 2"), (e[n] = i));
192192
}
193193
return e;
194194
},
@@ -202,7 +202,7 @@ const { BASE: G, ZERO: I } = Point,
202202
let e = 0;
203203
return (
204204
t.forEach((t) => {
205-
n.set(t, e), (e += t.length);
205+
(n.set(t, e), (e += t.length));
206206
}),
207207
n
208208
);
@@ -220,14 +220,14 @@ const { BASE: G, ZERO: I } = Point,
220220
n = r % e,
221221
c = o - s * t,
222222
d = i - a * t;
223-
(r = e), (e = n), (o = s), (i = a), (s = c), (a = d);
223+
((r = e), (e = n), (o = s), (i = a), (s = c), (a = d));
224224
}
225225
return 1n === r ? mod(o, n) : err("no inverse");
226226
},
227227
sqrt = (t) => {
228228
let n = 1n;
229229
for (let e = t, r = (P + 1n) / 4n; r > 0n; r >>= 1n)
230-
1n & r && (n = (n * e) % P), (e = (e * e) % P);
230+
(1n & r && (n = (n * e) % P), (e = (e * e) % P));
231231
return mod(n * n) === t ? n : err("sqrt invalid");
232232
},
233233
toPriv = (t) => (
@@ -238,11 +238,12 @@ const { BASE: G, ZERO: I } = Point,
238238
getPublicKey = (t, n = !0) => Point.fromPrivateKey(t).toRawBytes(n);
239239
class Signature {
240240
constructor(t, n, e) {
241-
(this.r = t), (this.s = n), (this.recovery = e), this.assertValidity();
241+
((this.r = t), (this.s = n), (this.recovery = e), this.assertValidity());
242242
}
243243
static fromCompact(t) {
244244
return (
245-
(t = toU8(t, 64)), new Signature(slcNum(t, 0, 32), slcNum(t, 32, 64))
245+
(t = toU8(t, 64)),
246+
new Signature(slcNum(t, 0, 32), slcNum(t, 32, 64))
246247
);
247248
}
248249
assertValidity() {
@@ -306,7 +307,7 @@ const optS = { lowS: !0 },
306307
if (c) {
307308
!0 === c && (c = etc.randomBytes(32));
308309
const t = toU8(c);
309-
32 !== t.length && err(), a.push(t);
310+
(32 !== t.length && err(), a.push(t));
310311
}
311312
const d = o;
312313
return {
@@ -334,38 +335,38 @@ function hmacDrbg(t) {
334335
e = u8n(32),
335336
r = 0;
336337
const o = () => {
337-
n.fill(1), e.fill(0), (r = 0);
338+
(n.fill(1), e.fill(0), (r = 0));
338339
},
339340
i = "drbg: tried 1000 values";
340341
if (t) {
341342
const t = (...t) => etc.hmacSha256Async(e, n, ...t),
342343
s = async (r = u8n()) => {
343-
(e = await t(u8n([0]), r)),
344+
((e = await t(u8n([0]), r)),
344345
(n = await t()),
345-
0 !== r.length && ((e = await t(u8n([1]), r)), (n = await t()));
346+
0 !== r.length && ((e = await t(u8n([1]), r)), (n = await t())));
346347
},
347348
a = async () => (r++ >= 1e3 && err(i), (n = await t()), n);
348349
return async (t, n) => {
349350
let e;
350351
for (o(), await s(t); !(e = n(await a())); ) await s();
351-
return o(), e;
352+
return (o(), e);
352353
};
353354
}
354355
{
355356
const t = (...t) => {
356357
const r = _hmacSync;
357-
return r || err("etc.hmacSha256Sync not set"), r(e, n, ...t);
358+
return (r || err("etc.hmacSha256Sync not set"), r(e, n, ...t));
358359
},
359360
s = (r = u8n()) => {
360-
(e = t(u8n([0]), r)),
361+
((e = t(u8n([0]), r)),
361362
(n = t()),
362-
0 !== r.length && ((e = t(u8n([1]), r)), (n = t()));
363+
0 !== r.length && ((e = t(u8n([1]), r)), (n = t())));
363364
},
364365
a = () => (r++ >= 1e3 && err(i), (n = t()), n);
365366
return (t, n) => {
366367
let e;
367368
for (o(), s(t); !(e = n(a())); ) s();
368-
return o(), e;
369+
return (o(), e);
369370
};
370371
}
371372
}
@@ -382,16 +383,16 @@ const signAsync = async (t, n, e = optS) => {
382383
i,
383384
s,
384385
{ lowS: a } = r;
385-
null == a && (a = !0),
386-
"strict" in r && err("verify() legacy options not supported");
386+
(null == a && (a = !0),
387+
"strict" in r && err("verify() legacy options not supported"));
387388
const c = t && "object" == typeof t && "r" in t;
388389
c || 64 === toU8(t).length || err("signature must be 64 bytes");
389390
try {
390-
(o = c
391+
((o = c
391392
? new Signature(t.r, t.s).assertValidity()
392393
: Signature.fromCompact(t)),
393394
(i = bits2int_modN(toU8(n))),
394-
(s = e instanceof Point ? e.ok() : Point.fromHex(e));
395+
(s = e instanceof Point ? e.ok() : Point.fromHex(e)));
395396
} catch (t) {
396397
return !1;
397398
}
@@ -477,8 +478,8 @@ const W = 8,
477478
let n = G,
478479
e = n;
479480
for (let r = 0; r < 33; r++) {
480-
(e = n), t.push(e);
481-
for (let r = 1; r < 128; r++) (e = e.add(n)), t.push(e);
481+
((e = n), t.push(e));
482+
for (let r = 1; r < 128; r++) ((e = e.add(n)), t.push(e));
482483
n = e.double();
483484
}
484485
return t;
@@ -497,7 +498,7 @@ const wNAF = (t) => {
497498
for (let a = 0; a < 33; a++) {
498499
const c = 128 * a;
499500
let d = Number(t & i);
500-
(t >>= s), d > 128 && ((d -= 256), (t += 1n));
501+
((t >>= s), d > 128 && ((d -= 256), (t += 1n)));
501502
const u = c,
502503
m = c + Math.abs(d) - 1,
503504
h = a % 2 != 0,

tests/integration/test_all.py

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -997,64 +997,73 @@ async def create_valid_invoice(wallet, amount=1000):
997997
raise Exception(f"Failed to create invoice: {error}")
998998
return result["invoice"]
999999

1000+
10001001
@pytest.mark.asyncio
10011002
async def test_list_transactions():
10021003
# Create wallets with required permissions
10031004
nwc1 = await create_nwc(
1004-
"wallet1", "test_list_transactions", ["invoice", "pay", "balance", "history"], [], 0
1005+
"wallet1",
1006+
"test_list_transactions",
1007+
["invoice", "pay", "balance", "history"],
1008+
[],
1009+
0,
10051010
)
10061011
nwc2 = await create_nwc(
1007-
"wallet2", "test_list_transactions", ["invoice", "pay", "balance", "history"], [], 0
1012+
"wallet2",
1013+
"test_list_transactions",
1014+
["invoice", "pay", "balance", "history"],
1015+
[],
1016+
0,
10081017
)
1009-
1018+
10101019
wallet1 = NWCWallet(nwc1["pairing"])
10111020
wallet2 = NWCWallet(nwc2["pairing"])
1012-
1021+
10131022
try:
10141023
await wallet1.start()
10151024
await wallet2.start()
1016-
1025+
10171026
# First invoice
10181027
await wallet1.send_event(
10191028
"make_invoice", {"amount": 1000, "description": "test invoice 1"}
10201029
)
10211030
result1, _, error = await wallet1.wait_for("make_invoice")
10221031
assert not error
10231032
invoice1 = result1["invoice"]
1024-
1033+
10251034
# Pay first invoice
10261035
await wallet2.send_event("pay_invoice", {"invoice": invoice1})
10271036
_, _, error = await wallet2.wait_for("pay_invoice")
10281037
assert not error
1029-
1038+
10301039
# Second invoice
10311040
await wallet1.send_event(
10321041
"make_invoice", {"amount": 2000, "description": "test invoice 2"}
10331042
)
10341043
result2, _, error = await wallet1.wait_for("make_invoice")
10351044
assert not error
10361045
invoice2 = result2["invoice"]
1037-
1046+
10381047
# Pay second invoice
10391048
await wallet2.send_event("pay_invoice", {"invoice": invoice2})
10401049
_, _, error = await wallet2.wait_for("pay_invoice")
10411050
assert not error
1042-
1051+
10431052
# Test basic transaction listing
10441053
await wallet1.send_event("list_transactions", {})
10451054
result, _, error = await wallet1.wait_for("list_transactions")
10461055
assert not error
10471056
assert "transactions" in result
10481057
transactions = result["transactions"]
10491058
assert len(transactions) >= 2
1050-
1059+
10511060
# Test limit
10521061
await wallet1.send_event("list_transactions", {"limit": 1})
10531062
result, _, error = await wallet1.wait_for("list_transactions")
10541063
assert not error
10551064
limited_txs = result["transactions"]
10561065
assert len(limited_txs) == 1
1057-
1066+
10581067
finally:
10591068
await wallet1.close()
1060-
await wallet2.close()
1069+
await wallet2.close()

0 commit comments

Comments
 (0)