From 4f76958d1a1971ab652b733dfb320c681f2db65e Mon Sep 17 00:00:00 2001 From: CM Date: Fri, 1 Sep 2023 16:56:28 -0500 Subject: [PATCH 1/4] feat: "a" tag filter since NIP01 update (#33) * Add a tag to filter * Oops. wrong letter * Add a tag to these test cases --------- Co-authored-by: cm --- lib/src/filter.dart | 8 ++++++++ test/filter_test.dart | 4 ++++ test/request_test.dart | 7 ++++++- 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/lib/src/filter.dart b/lib/src/filter.dart index a272936..a8cae6f 100644 --- a/lib/src/filter.dart +++ b/lib/src/filter.dart @@ -12,6 +12,9 @@ class Filter { /// a list of event ids that are referenced in an "e" tag List? e; + /// a list of event ids that are referenced in an "a" tag + List? a; + /// a list of pubkeys that are referenced in a "p" tag List? p; @@ -30,6 +33,7 @@ class Filter { this.authors, this.kinds, this.e, + this.a, this.p, this.since, this.until, @@ -42,6 +46,7 @@ class Filter { json['authors'] == null ? null : List.from(json['authors']); kinds = json['kinds'] == null ? null : List.from(json['kinds']); e = json['#e'] == null ? null : List.from(json['#e']); + a = json['#a'] == null ? null : List.from(json['#a']); p = json['#p'] == null ? null : List.from(json['#p']); since = json['since']; until = json['until']; @@ -63,6 +68,9 @@ class Filter { if (e != null) { data['#e'] = e; } + if (a != null) { + data['#a'] = a; + } if (p != null) { data['#p'] = p; } diff --git a/test/filter_test.dart b/test/filter_test.dart index 43eaa8f..9036239 100644 --- a/test/filter_test.dart +++ b/test/filter_test.dart @@ -12,6 +12,7 @@ void main() { ]; List kinds = [0, 1, 2, 7]; List e = []; + List a = []; List p = []; int since = 1672477960; int until = 1674063680; @@ -22,6 +23,7 @@ void main() { authors: authors, kinds: kinds, e: e, + a: a, p: p, since: since, until: until, @@ -32,6 +34,7 @@ void main() { expect(filter.authors, authors); expect(filter.kinds, kinds); expect(filter.e, e); + expect(filter.e, e); expect(filter.p, p); expect(filter.since, since); expect(filter.until, until); @@ -48,6 +51,7 @@ void main() { ], "kinds": [0, 1, 2, 7], "#e": [], + "#a": [], "#p": [], "since": 1672477960, "until": 1674063680, diff --git a/test/request_test.dart b/test/request_test.dart index 2391150..f9aea63 100644 --- a/test/request_test.dart +++ b/test/request_test.dart @@ -14,6 +14,7 @@ void main() { ], kinds: [0, 1, 2, 7], e: [], + a: [], p: [], since: 1672477960, until: 1674063680, @@ -27,6 +28,7 @@ void main() { expect(req.filters[0].authors, myFilter.authors); expect(req.filters[0].kinds, myFilter.kinds); expect(req.filters[0].e, myFilter.e); + expect(req.filters[0].a, myFilter.a); expect(req.filters[0].p, myFilter.p); expect(req.filters[0].kinds, myFilter.kinds); expect(req.filters[0].since, myFilter.since); @@ -36,7 +38,7 @@ void main() { test('Request.serialize', () { String serialized = - '["REQ","733209259899167",{"ids":["047663d895d56aefa3f528935c7ce7dc8939eb721a0ec76ef2e558a8257955d2"],"authors":["0ba0206887bd61579bf65ec09d7806bea32c64be1cf2c978cf031a811cd238db"],"kinds":[0,1,2,7],"#e":[],"#p":[],"since":1672477960,"until":1674063680,"limit":450},{"kinds":[0,1,2,7],"since":1673980547,"limit":450}]'; + '["REQ","733209259899167",{"ids":["047663d895d56aefa3f528935c7ce7dc8939eb721a0ec76ef2e558a8257955d2"],"authors":["0ba0206887bd61579bf65ec09d7806bea32c64be1cf2c978cf031a811cd238db"],"kinds":[0,1,2,7],"#e":[],"#a":[],"#p":[],"since":1672477960,"until":1674063680,"limit":450},{"kinds":[0,1,2,7],"since":1673980547,"limit":450}]'; var json = [ "REQ", "733209259899167", @@ -49,6 +51,7 @@ void main() { ], "kinds": [0, 1, 2, 7], "#e": [], + "#a": [], "#p": [], "since": 1672477960, "until": 1674063680, @@ -77,6 +80,7 @@ void main() { ], "kinds": [0, 1, 2, 7], "#e": [], + "#a": [], "#p": [], "since": 1672477960, "until": 1674063680, @@ -95,6 +99,7 @@ void main() { expect(req.filters[0].authors, ["0ba0206887bd61579bf65ec09d7806bea32c64be1cf2c978cf031a811cd238db"]); expect(req.filters[0].e, []); + expect(req.filters[0].a, []); expect(req.filters[0].p, []); expect(req.filters[0].kinds, [0, 1, 2, 7]); expect(req.filters[0].since, 1672477960); From 689db80c237a581ded8b0a87c8a959fb9ed45836 Mon Sep 17 00:00:00 2001 From: ethicnology Date: Sat, 2 Sep 2023 00:18:24 +0200 Subject: [PATCH 2/4] fix: unit test filter --- test/filter_test.dart | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/filter_test.dart b/test/filter_test.dart index 9036239..37abf36 100644 --- a/test/filter_test.dart +++ b/test/filter_test.dart @@ -34,7 +34,7 @@ void main() { expect(filter.authors, authors); expect(filter.kinds, kinds); expect(filter.e, e); - expect(filter.e, e); + expect(filter.a, a); expect(filter.p, p); expect(filter.since, since); expect(filter.until, until); @@ -63,6 +63,7 @@ void main() { expect(filter.authors, json['authors']); expect(filter.kinds, json['kinds']); expect(filter.e, json['#e']); + expect(filter.a, json['#a']); expect(filter.p, json['#p']); expect(filter.since, json['since']); expect(filter.until, json['until']); From 44edfc49a0b21623cab6783f94bb71935898d4fe Mon Sep 17 00:00:00 2001 From: ethicnology Date: Sat, 2 Sep 2023 00:18:45 +0200 Subject: [PATCH 3/4] refactor: filter toJson --- lib/src/filter.dart | 36 +++++++++--------------------------- 1 file changed, 9 insertions(+), 27 deletions(-) diff --git a/lib/src/filter.dart b/lib/src/filter.dart index a8cae6f..1e85b1c 100644 --- a/lib/src/filter.dart +++ b/lib/src/filter.dart @@ -56,33 +56,15 @@ class Filter { /// Serialize a filter in JSON Map toJson() { final Map data = {}; - if (ids != null) { - data['ids'] = ids; - } - if (authors != null) { - data['authors'] = authors; - } - if (kinds != null) { - data['kinds'] = kinds; - } - if (e != null) { - data['#e'] = e; - } - if (a != null) { - data['#a'] = a; - } - if (p != null) { - data['#p'] = p; - } - if (since != null) { - data['since'] = since; - } - if (until != null) { - data['until'] = until; - } - if (limit != null) { - data['limit'] = limit; - } + if (ids != null) data['ids'] = ids; + if (authors != null) data['authors'] = authors; + if (kinds != null) data['kinds'] = kinds; + if (e != null) data['#e'] = e; + if (a != null) data['#a'] = a; + if (p != null) data['#p'] = p; + if (since != null) data['since'] = since; + if (until != null) data['until'] = until; + if (limit != null) data['limit'] = limit; return data; } } From 6263385439f73849253efdf326729b6d49a6875e Mon Sep 17 00:00:00 2001 From: ethicnology Date: Sat, 2 Sep 2023 00:21:42 +0200 Subject: [PATCH 4/4] chore: upgrade dependencies & bump version --- CHANGELOG.md | 5 +++++ pubspec.yaml | 4 ++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1548706..1607d58 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -61,3 +61,8 @@ - NIP 20 Command Results - NIP 28 Public Chat - NIP 51 Lists + +## 1.4.1 + +- [new **a** filter](https://github.com/nostr-protocol/nips/commit/e50bf508d9014cfb19bfa8a5c4ec88dc4788d490) +- Upgrade bip340 dependency diff --git a/pubspec.yaml b/pubspec.yaml index 3127442..67777f3 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: nostr description: A library for nostr protocol implemented in dart for flutter -version: 1.4.0 +version: 1.4.1 homepage: https://github.com/ethicnology/dart-nostr environment: @@ -10,7 +10,7 @@ dev_dependencies: lints: ^2.0.0 test: ^1.16.0 dependencies: - bip340: ^0.1.0 + bip340: ^0.2.0 convert: ^3.1.1 pointycastle: ^3.7.3 bech32: ^0.2.2