Skip to content

Conversation

avlo
Copy link
Collaborator

@avlo avlo commented Jan 8, 2025

hi, eric. REQ message filter/json (plus GenericEvent & PublicKey) validations per NIP-01 specification have been implemented and tested in this PR (with following synopsis for reference) and a note for you at bottom re: NIP-04.

pls advise if any issues i've overlooked/mis-implemented per your understanding/etc.

"ids": , 32-bytes lowercase hex

implementation in:
GenericEvent.setId(), calls HexStringValidator.validateHex()

tested in:
JsonParseTest.testReqMessageFilterIdLength()

"authors": , 32-bytes lowercase hex

implementation in:
PublicKey(String hexPubKey) calls NostrUtil.hexToBytes(), calls HexStringValidator.validateHex()

tested in:
BaseKeyTest.java

"kinds": , integer between 0 and 65535

implementation in:
Kind.valueOf()
tested
JsonParseTest.testBaseMessageDecoderKind()

"#<single-letter (a-zA-Z)>": <a list of tag values, for #e — a list of event ids, for #p — a list of pubkeys, etc.>,

implementation in:
GenericEvent.setId() calls HexStringValidator.validateHex()
PublicKey(String hexPubKey) calls NostrUtil.hexToBytes(), calls HexStringValidator.validateHex()
tested in:
JsonParseTest.testReqMessageDecoderETag()
JsonParseTest.testReqMessageDecoderPTag()

"since": = to this to pass>,

implemented in:
Filters.setSince()
tested in:
JsonParseTest.testReqMessageFilterSince()

"until": <an integer unix timestamp in seconds. Events must have a created_at <= to this to pass>,

implemented in
Filters.setUntil()
tested
JsonParseTest.testReqMessageFilterUntil()

"limit":
no changes/tests
<subscription_id> non-empty string of max length 64 chars.

implemented in:
ReqMessage ctor(), line 42
tested
JsonParseTest.testReqMessageSubscriptionIdLength()

not surprisingly, introduction of validations uncovered a few existing/minor issues related to NIP-01 hex-string length requirements. i've fixed the few obvious ones, however, two still exist related to NIP-04, likely ideally addressed by @tcheeric's domain-expertise in this area.

they are readily visible upon running test suite for this branch, reporting incorrect hex-string length error messages that should be a helpful starting point:

[ERROR]   ApiEventTest.testNIP04EncryptDecrypt:144 » IllegalArgument Invalid hex string: [0256adf01ca1aa9d6f1c35953833bbe6d99a0c85b73af222e6bd305b51f2749f6f], length: [66], target length: [64]
[ERROR]   ApiEventTest.testNIP04SendDirectMessage:107 » IllegalArgument Invalid hex string: [0256adf01ca1aa9d6f1c35953833bbe6d99a0c85b73af222e6bd305b51f2749f6f], length: [66], target length: [64]

avlo added 10 commits January 6, 2025 20:52
ReqMessage subscriptionId, added 0 < #characters < 65 string length constraint
NostrUtil, added hexString validations:
	- non-null
	- 128-character string length for Signature/SignatureDeserializer
	- 64-character string length for all others
	- (lower)case-sensitive
JsonParseTest methods for the above
JsonParseTest removed EVENT JSON id
@avlo avlo requested a review from tcheeric January 8, 2025 01:38
@tcheeric
Copy link
Owner

Hi Nick, I have been busy lately but will merge this in the coming days.

@avlo
Copy link
Collaborator Author

avlo commented Jan 26, 2025

hi, eric. thx for heads up & no rush here, pls lmk if any questions/issues/etc.

in the meanwhile, adding SC NIP-09 (deletion events) support as i noticed you've implemented it in nostr-java along with an integration test- which, for the moment- will fail if/when running against SC. will keep you posted when it's available.

@tcheeric tcheeric merged commit 0640798 into tcheeric:develop Feb 15, 2025
@avlo avlo deleted the req_message-validation branch February 23, 2025 22:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants