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/lib/src/filter.dart b/lib/src/filter.dart index a272936..1e85b1c 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']; @@ -51,30 +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 (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; } } diff --git a/pubspec.yaml b/pubspec.yaml index 3127442..284ecfd 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,16 +1,16 @@ 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: - sdk: '>=2.18.5 <3.0.0' + sdk: '>=2.18.5 <4.0.0' 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 diff --git a/test/filter_test.dart b/test/filter_test.dart index 43eaa8f..37abf36 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.a, a); 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, @@ -59,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']); 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);