EncryptedDirectMessage class
A special event with kind 4, meaning "encrypted direct message".
content MUST be equal to the base64-encoded, aes-256-cbc encrypted string of anything a user wants to write, encrypted using a shared nip4cipher generated by combining the recipient's public-key with the sender's private-key; this appended by the base64-encoded initialization vector as if it was a querystring parameter named "iv". The format is the following: "content": "<encrypted_text>?iv=<initialization_vector>".
tags MUST contain an entry identifying the receiver of the message (such that relays may naturally forward this event to them), in the form "p", "pubkey, as a hex string"
.
tags MAY contain an entry identifying the previous message in a conversation or a message we are explicitly replying to (such that contextual, more organized conversations may happen), in the form "e", "event_id"
.
Note: By default in the libsecp256k1 ECDH implementation, the secret is the SHA256 hash of the shared point (both X and Y coordinates). In Nostr, only the X coordinate of the shared point is used as the secret and it is NOT hashed. If using libsecp256k1, a custom function that copies the X coordinate must be passed as the hashfp argument in secp256k1_ecdh.
NIP-04 considered harmful, READ: https://github.com/ethicnology/dart-nostr/issues/15 and https://github.com/nostr-protocol/nips/issues/107
- Inheritance
- Annotations
-
- @Deprecated(""" NIP-04 a.k.a EncryptedDirectMessage is controversial, please READ: - https://github.com/ethicnology/dart-nostr/issues/15 - https://github.com/nostr-protocol/nips/issues/107 """)
Constructors
- EncryptedDirectMessage(Event event, {dynamic verify = true})
- Default constructor
- EncryptedDirectMessage.receive(Event event, {dynamic verify = true})
- receive an EncryptedDirectMessage
- EncryptedDirectMessage.redact(String senderPrivkey, String receiverPubkey, String message)
-
prepare a EncryptedDirectMessage to send quickly with the minimal needed params
factory
Properties
- content ↔ String
-
arbitrary string
getter/setter pairinherited
- createdAt ↔ int
-
unix timestamp in seconds
getter/setter pairinherited
- hashCode → int
-
The hash code for this object.
no setterinherited
- id ↔ String
-
32-bytes hex-encoded sha256 of the the serialized event data (hex)
getter/setter pairinherited
- kind ↔ int
-
- 0: set_metadata: the content is set to a stringified JSON object {name:
- 1: text_note: the content is set to the text content of a note (anything the user wants to say). Non-plaintext notes should instead use kind 1000-10000 as described in NIP-16.
- 2: recommend_server: the content is set to the URL (e.g., wss://somerelay.com) of a relay the event creator wants to recommend to its followers.
getter/setter pairinherited - nonce → String
-
get nonce/IV
no setter
- previous → String?
-
get previous event id –> MAY contain an entry identifying the previous message in a conversation or a message we are explicitly replying to.
no setter
- pubkey ↔ String
-
32-bytes hex-encoded public key of the event creator (hex)
getter/setter pairinherited
- receiver → String?
-
get receiver public key
no setter
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- sender → String?
-
get sender public key
no setter
- sig ↔ String
-
64-bytes signature of the sha256 hash of the serialized event data, which is the same as the "id" field
getter/setter pairinherited
- subscriptionId ↔ String?
-
subscription_id is a random string that should be used to represent a subscription.
getter/setter pairinherited
-
The tags array can store a tag identifier as the first element of each subarray, plus arbitrary information afterward (always as strings).
getter/setter pairinherited
Methods
-
getEventId(
) → String -
To obtain the event.id, we sha256 the serialized event.
The serialization is done over the UTF-8 JSON-serialized string (with no white space or line breaks) of the following structure:
inherited
-
getPlaintext(
String privkey) → String - get the deciphered message a.k.a. plaintext
-
getSignature(
String privateKey) → String -
Each user has a keypair. Signatures, public key, and encodings are done according to the Schnorr signatures standard for the curve secp256k1
64-bytes signature of the sha256 hash of the serialized event data, which is the same as the "id" field
inherited
-
isValid(
) → bool -
Verify if event checks such as id, signature, non-futuristic are valid
Performances could be a reason to disable event checks
inherited
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
serialize(
) → String -
Serialize to nostr event message
inherited
-
toJson(
) → Map< String, dynamic> -
Serialize an event in JSON
inherited
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited