Documentation
¶
Index ¶
- Constants
- func BuildInitAAD(metadata DirectEnvelopeMetadata, body DirectInitBody) ([]byte, error)
- func BuildMessageAAD(metadata DirectEnvelopeMetadata, body DirectCipherBody, ...) ([]byte, error)
- func DecryptWithStep(step ChainStep, ciphertext []byte, aad []byte) ([]byte, error)
- func EncryptWithStep(step ChainStep, plaintext []byte, aad []byte) ([]byte, error)
- func ExtractX25519PublicKey(didDocument map[string]any, keyID string) ([32]byte, error)
- func InitialSecretKeyAndNonce(initialSecret [32]byte) ([32]byte, [12]byte, error)
- func VerifyPrekeyBundle(bundle PrekeyBundle, didDocument map[string]any) error
- type ApplicationPlaintext
- type ChainStep
- type DIDResolver
- type DirectCipherBody
- type DirectE2eeSession
- func (DirectE2eeSession) AcceptIncomingInit(metadata DirectEnvelopeMetadata, localStaticKeyID string, ...) (DirectSessionState, ApplicationPlaintext, error)
- func (DirectE2eeSession) DecryptFollowUp(session *DirectSessionState, metadata DirectEnvelopeMetadata, ...) (ApplicationPlaintext, error)
- func (DirectE2eeSession) EncryptFollowUp(session *DirectSessionState, metadata DirectEnvelopeMetadata, ...) (PendingOutboundRecord, DirectCipherBody, error)
- func (DirectE2eeSession) InitiateSession(metadata DirectEnvelopeMetadata, operationID string, localStaticKeyID string, ...) (DirectSessionState, PendingOutboundRecord, DirectInitBody, error)
- type DirectEnvelopeMetadata
- type DirectInitBody
- type DirectSessionState
- type Error
- type FilePendingOutboundStore
- type FileSessionStore
- func (s *FileSessionStore) DeleteSession(sessionID string) error
- func (s *FileSessionStore) FindByPeerDID(peerDID string) (DirectSessionState, bool, error)
- func (s *FileSessionStore) LoadSession(sessionID string) (DirectSessionState, error)
- func (s *FileSessionStore) SaveSession(session DirectSessionState) error
- type FileSignedPrekeyStore
- func (s *FileSignedPrekeyStore) LoadLatestSignedPrekey() (anp.PrivateKeyMaterial, SignedPrekey, bool, error)
- func (s *FileSignedPrekeyStore) LoadSignedPrekey(keyID string) (anp.PrivateKeyMaterial, SignedPrekey, error)
- func (s *FileSignedPrekeyStore) SaveSignedPrekey(keyID string, privateKey anp.PrivateKeyMaterial, metadata SignedPrekey) error
- type IdentityKeyStore
- type InitialMaterial
- type MessageServiceDirectE2eeClient
- func (c *MessageServiceDirectE2eeClient) DecryptHistoryPage(ctx context.Context, messages []map[string]any) ([]map[string]any, error)
- func (c *MessageServiceDirectE2eeClient) EnsureFreshPrekeyBundle() (PrekeyBundle, error)
- func (c *MessageServiceDirectE2eeClient) GetVerifiedPrekeyBundle(ctx context.Context, targetDID string) (PrekeyBundle, error)
- func (c *MessageServiceDirectE2eeClient) ProcessIncoming(ctx context.Context, message map[string]any) (map[string]any, error)
- func (c *MessageServiceDirectE2eeClient) PublishPrekeyBundle() (map[string]any, error)
- func (c *MessageServiceDirectE2eeClient) SendJSON(ctx context.Context, peerDID string, payload map[string]any, ...) (map[string]any, error)
- func (c *MessageServiceDirectE2eeClient) SendText(ctx context.Context, peerDID string, text string, operationID string, ...) (map[string]any, error)
- type PendingOutboundRecord
- type PendingOutboundStore
- type PrekeyBundle
- type PrekeyManager
- func (m *PrekeyManager) BuildPrekeyBundle(signedPrekey SignedPrekey, bundleID string, created string) (PrekeyBundle, error)
- func (m *PrekeyManager) EnsureFreshPrekeyBundle() (PrekeyBundle, error)
- func (m *PrekeyManager) GenerateSignedPrekey(keyID string, expiresAt string) (*ecdh.PrivateKey, SignedPrekey, error)
- func (m *PrekeyManager) PublishPrekeyBundle(bundle PrekeyBundle) (map[string]any, error)
- func (m *PrekeyManager) VerifyRemotePrekeyBundle(bundle PrekeyBundle, didDocument map[string]any) error
- type RPCClient
- type RatchetHeader
- type SessionStore
- type SignedPrekey
- type SignedPrekeyStore
- type SkippedMessageKey
Constants ¶
const MTIDirectE2EESuite = "ANP-DIRECT-E2EE-X3DH-25519-CHACHA20POLY1305-SHA256-V1"
const MaxSkip uint32 = 1000
Variables ¶
This section is empty.
Functions ¶
func BuildInitAAD ¶
func BuildInitAAD(metadata DirectEnvelopeMetadata, body DirectInitBody) ([]byte, error)
BuildInitAAD builds canonical associated data for a direct init message.
func BuildMessageAAD ¶
func BuildMessageAAD(metadata DirectEnvelopeMetadata, body DirectCipherBody, applicationContentType string) ([]byte, error)
BuildMessageAAD builds canonical associated data for a direct cipher message.
func DecryptWithStep ¶
DecryptWithStep decrypts ciphertext with the derived step.
func EncryptWithStep ¶
EncryptWithStep encrypts plaintext with the derived step.
func ExtractX25519PublicKey ¶
ExtractX25519PublicKey extracts an X25519 public key from a DID document.
func InitialSecretKeyAndNonce ¶
InitialSecretKeyAndNonce derives the init-message AEAD key and nonce.
func VerifyPrekeyBundle ¶
func VerifyPrekeyBundle(bundle PrekeyBundle, didDocument map[string]any) error
VerifyPrekeyBundle verifies a prekey bundle against the owner's DID document.
Types ¶
type ApplicationPlaintext ¶
type ApplicationPlaintext struct {
ApplicationContentType string `json:"application_content_type"`
ConversationID string `json:"conversation_id,omitempty"`
ReplyToMessageID string `json:"reply_to_message_id,omitempty"`
Annotations map[string]any `json:"annotations,omitempty"`
Text string `json:"text,omitempty"`
Payload map[string]any `json:"payload,omitempty"`
}
ApplicationPlaintext is the decrypted application payload.
func NewJSONPlaintext ¶
func NewJSONPlaintext(contentType string, payload map[string]any) ApplicationPlaintext
NewJSONPlaintext builds a JSON application payload.
func NewTextPlaintext ¶
func NewTextPlaintext(contentType string, text string) ApplicationPlaintext
NewTextPlaintext builds a text application payload.
type ChainStep ¶
ChainStep contains derived message material for a single ratchet step.
func DeriveChainStep ¶
DeriveChainStep derives message key, nonce, and next chain key.
type DIDResolver ¶
DIDResolver resolves a DID document.
type DirectCipherBody ¶
type DirectCipherBody struct {
SessionID string `json:"session_id"`
Suite string `json:"suite"`
RatchetHeader RatchetHeader `json:"ratchet_header"`
CiphertextB64U string `json:"ciphertext_b64u"`
}
DirectCipherBody is the follow-up encrypted message body.
type DirectE2eeSession ¶
type DirectE2eeSession struct{}
DirectE2eeSession builds and processes direct E2EE init and follow-up messages.
func (DirectE2eeSession) AcceptIncomingInit ¶
func (DirectE2eeSession) AcceptIncomingInit(metadata DirectEnvelopeMetadata, localStaticKeyID string, localStaticPrivate *ecdh.PrivateKey, localSignedPrekeyPrivate *ecdh.PrivateKey, senderStaticPublic [32]byte, body DirectInitBody) (DirectSessionState, ApplicationPlaintext, error)
AcceptIncomingInit processes an init message for the responder.
func (DirectE2eeSession) DecryptFollowUp ¶
func (DirectE2eeSession) DecryptFollowUp(session *DirectSessionState, metadata DirectEnvelopeMetadata, body DirectCipherBody, applicationContentType string) (ApplicationPlaintext, error)
DecryptFollowUp decrypts a follow-up direct message.
func (DirectE2eeSession) EncryptFollowUp ¶
func (DirectE2eeSession) EncryptFollowUp(session *DirectSessionState, metadata DirectEnvelopeMetadata, operationID string, plaintext ApplicationPlaintext) (PendingOutboundRecord, DirectCipherBody, error)
EncryptFollowUp encrypts a follow-up direct message.
func (DirectE2eeSession) InitiateSession ¶
func (DirectE2eeSession) InitiateSession(metadata DirectEnvelopeMetadata, operationID string, localStaticKeyID string, localStaticPrivate *ecdh.PrivateKey, recipientBundle PrekeyBundle, recipientStaticPublic [32]byte, recipientSignedPrekeyPublic [32]byte, plaintext ApplicationPlaintext) (DirectSessionState, PendingOutboundRecord, DirectInitBody, error)
InitiateSession creates the initial encrypted session message.
type DirectEnvelopeMetadata ¶
type DirectEnvelopeMetadata struct {
SenderDID string `json:"sender_did"`
RecipientDID string `json:"recipient_did"`
MessageID string `json:"message_id"`
Profile string `json:"profile"`
SecurityProfile string `json:"security_profile"`
}
DirectEnvelopeMetadata is the envelope metadata shared by all direct E2EE messages.
type DirectInitBody ¶
type DirectInitBody struct {
SessionID string `json:"session_id"`
Suite string `json:"suite"`
SenderStaticKeyAgreementID string `json:"sender_static_key_agreement_id"`
RecipientBundleID string `json:"recipient_bundle_id"`
RecipientStaticKeyAgreementID string `json:"recipient_static_key_agreement_id"`
RecipientSignedPrekeyID string `json:"recipient_signed_prekey_id"`
RecipientOneTimePrekeyID string `json:"recipient_one_time_prekey_id,omitempty"`
SenderEphemeralPubB64U string `json:"sender_ephemeral_pub_b64u"`
CiphertextB64U string `json:"ciphertext_b64u"`
}
DirectInitBody is the init message body.
type DirectSessionState ¶
type DirectSessionState struct {
SessionID string `json:"session_id"`
Suite string `json:"suite"`
PeerDID string `json:"peer_did"`
LocalKeyAgreementID string `json:"local_key_agreement_id"`
PeerKeyAgreementID string `json:"peer_key_agreement_id"`
RootKeyB64U string `json:"root_key_b64u"`
SendChainKeyB64U string `json:"send_chain_key_b64u"`
RecvChainKeyB64U string `json:"recv_chain_key_b64u"`
RatchetPublicKeyB64U string `json:"ratchet_public_key_b64u"`
PeerRatchetPublicKeyB64U string `json:"peer_ratchet_public_key_b64u,omitempty"`
SendN uint32 `json:"send_n"`
RecvN uint32 `json:"recv_n"`
PreviousSendChainLength uint32 `json:"previous_send_chain_length"`
SkippedMessageKeys []SkippedMessageKey `json:"skipped_message_keys,omitempty"`
IsInitiator bool `json:"is_initiator"`
}
DirectSessionState stores direct E2EE session state.
type FilePendingOutboundStore ¶
type FilePendingOutboundStore struct {
// contains filtered or unexported fields
}
FilePendingOutboundStore persists pending outbound messages as JSON files.
func NewFilePendingOutboundStore ¶
func NewFilePendingOutboundStore(root string) (*FilePendingOutboundStore, error)
NewFilePendingOutboundStore creates a file-backed pending outbound store.
func (*FilePendingOutboundStore) DeletePending ¶
func (s *FilePendingOutboundStore) DeletePending(operationID string) error
func (*FilePendingOutboundStore) LoadPending ¶
func (s *FilePendingOutboundStore) LoadPending(operationID string) (PendingOutboundRecord, error)
func (*FilePendingOutboundStore) SavePending ¶
func (s *FilePendingOutboundStore) SavePending(record PendingOutboundRecord) error
type FileSessionStore ¶
type FileSessionStore struct {
// contains filtered or unexported fields
}
FileSessionStore persists session state as JSON files.
func NewFileSessionStore ¶
func NewFileSessionStore(root string) (*FileSessionStore, error)
NewFileSessionStore creates a file-backed session store.
func (*FileSessionStore) DeleteSession ¶
func (s *FileSessionStore) DeleteSession(sessionID string) error
func (*FileSessionStore) FindByPeerDID ¶
func (s *FileSessionStore) FindByPeerDID(peerDID string) (DirectSessionState, bool, error)
func (*FileSessionStore) LoadSession ¶
func (s *FileSessionStore) LoadSession(sessionID string) (DirectSessionState, error)
func (*FileSessionStore) SaveSession ¶
func (s *FileSessionStore) SaveSession(session DirectSessionState) error
type FileSignedPrekeyStore ¶
type FileSignedPrekeyStore struct {
// contains filtered or unexported fields
}
FileSignedPrekeyStore persists signed prekeys and metadata to disk.
func NewFileSignedPrekeyStore ¶
func NewFileSignedPrekeyStore(root string) (*FileSignedPrekeyStore, error)
NewFileSignedPrekeyStore creates a file-backed signed prekey store.
func (*FileSignedPrekeyStore) LoadLatestSignedPrekey ¶
func (s *FileSignedPrekeyStore) LoadLatestSignedPrekey() (anp.PrivateKeyMaterial, SignedPrekey, bool, error)
func (*FileSignedPrekeyStore) LoadSignedPrekey ¶
func (s *FileSignedPrekeyStore) LoadSignedPrekey(keyID string) (anp.PrivateKeyMaterial, SignedPrekey, error)
func (*FileSignedPrekeyStore) SaveSignedPrekey ¶
func (s *FileSignedPrekeyStore) SaveSignedPrekey(keyID string, privateKey anp.PrivateKeyMaterial, metadata SignedPrekey) error
type IdentityKeyStore ¶
type IdentityKeyStore interface {
LoadStaticKey(keyID string) (anp.PrivateKeyMaterial, error)
}
IdentityKeyStore loads static identity keys.
type InitialMaterial ¶
type InitialMaterial struct {
InitialSecret [32]byte
RootKey [32]byte
InitiatorChainKey [32]byte
ResponderChainKey [32]byte
SessionID string
}
InitialMaterial contains the symmetric material derived from X3DH.
func DeriveInitialMaterialForInitiator ¶
func DeriveInitialMaterialForInitiator(senderStaticPrivate *ecdh.PrivateKey, senderEphemeralPrivate *ecdh.PrivateKey, recipientStaticPublic [32]byte, recipientSignedPrekeyPublic [32]byte) (InitialMaterial, error)
DeriveInitialMaterialForInitiator derives session material for the initiator.
func DeriveInitialMaterialForResponder ¶
func DeriveInitialMaterialForResponder(recipientStaticPrivate *ecdh.PrivateKey, recipientSignedPrekeyPrivate *ecdh.PrivateKey, senderStaticPublic [32]byte, senderEphemeralPublic [32]byte) (InitialMaterial, error)
DeriveInitialMaterialForResponder derives session material for the responder.
type MessageServiceDirectE2eeClient ¶
type MessageServiceDirectE2eeClient struct {
// contains filtered or unexported fields
}
MessageServiceDirectE2eeClient is a reference direct E2EE client.
func NewMessageServiceDirectE2eeClient ¶
func NewMessageServiceDirectE2eeClient(localDID string, signingPrivateKey anp.PrivateKeyMaterial, signingVerificationMethod string, staticKeyAgreementPrivate anp.PrivateKeyMaterial, staticKeyAgreementID string, rpcClient RPCClient, didDocumentResolver DIDResolver, sessionStore SessionStore, signedPrekeyStore SignedPrekeyStore) (*MessageServiceDirectE2eeClient, error)
NewMessageServiceDirectE2eeClient creates a reference direct E2EE client.
func (*MessageServiceDirectE2eeClient) DecryptHistoryPage ¶
func (c *MessageServiceDirectE2eeClient) DecryptHistoryPage(ctx context.Context, messages []map[string]any) ([]map[string]any, error)
DecryptHistoryPage processes a page of messages in server order.
func (*MessageServiceDirectE2eeClient) EnsureFreshPrekeyBundle ¶
func (c *MessageServiceDirectE2eeClient) EnsureFreshPrekeyBundle() (PrekeyBundle, error)
EnsureFreshPrekeyBundle ensures a fresh prekey bundle exists locally.
func (*MessageServiceDirectE2eeClient) GetVerifiedPrekeyBundle ¶
func (c *MessageServiceDirectE2eeClient) GetVerifiedPrekeyBundle(ctx context.Context, targetDID string) (PrekeyBundle, error)
GetVerifiedPrekeyBundle fetches and verifies a peer prekey bundle.
func (*MessageServiceDirectE2eeClient) ProcessIncoming ¶
func (c *MessageServiceDirectE2eeClient) ProcessIncoming(ctx context.Context, message map[string]any) (map[string]any, error)
ProcessIncoming processes an inbound message-service notification or message view.
func (*MessageServiceDirectE2eeClient) PublishPrekeyBundle ¶
func (c *MessageServiceDirectE2eeClient) PublishPrekeyBundle() (map[string]any, error)
PublishPrekeyBundle ensures and publishes a fresh prekey bundle.
type PendingOutboundRecord ¶
type PendingOutboundRecord struct {
OperationID string `json:"operation_id"`
MessageID string `json:"message_id"`
WireContentType string `json:"wire_content_type"`
BodyJSON map[string]any `json:"body_json"`
}
PendingOutboundRecord stores outbound messages that await transport delivery.
type PendingOutboundStore ¶
type PendingOutboundStore interface {
SavePending(record PendingOutboundRecord) error
LoadPending(operationID string) (PendingOutboundRecord, error)
DeletePending(operationID string) error
}
PendingOutboundStore loads and stores pending outbound messages.
type PrekeyBundle ¶
type PrekeyBundle struct {
BundleID string `json:"bundle_id"`
OwnerDID string `json:"owner_did"`
Suite string `json:"suite"`
StaticKeyAgreementID string `json:"static_key_agreement_id"`
SignedPrekey SignedPrekey `json:"signed_prekey"`
Proof map[string]any `json:"proof"`
}
PrekeyBundle is the published prekey bundle.
func BuildPrekeyBundle ¶
func BuildPrekeyBundle(bundleID string, ownerDID string, staticKeyAgreementID string, signedPrekey SignedPrekey, signingPrivateKey anp.PrivateKeyMaterial, verificationMethod string, created string) (PrekeyBundle, error)
BuildPrekeyBundle signs and builds a prekey bundle.
type PrekeyManager ¶
type PrekeyManager struct {
// contains filtered or unexported fields
}
PrekeyManager manages signed prekeys and bundle publication.
func NewPrekeyManager ¶
func NewPrekeyManager(localDID string, staticKeyAgreementID string, signingPrivateKey anp.PrivateKeyMaterial, signingVerificationMethod string, signedPrekeyStore SignedPrekeyStore, rpcClient RPCClient) *PrekeyManager
NewPrekeyManager creates a direct E2EE prekey manager.
func (*PrekeyManager) BuildPrekeyBundle ¶
func (m *PrekeyManager) BuildPrekeyBundle(signedPrekey SignedPrekey, bundleID string, created string) (PrekeyBundle, error)
BuildPrekeyBundle signs a prekey bundle.
func (*PrekeyManager) EnsureFreshPrekeyBundle ¶
func (m *PrekeyManager) EnsureFreshPrekeyBundle() (PrekeyBundle, error)
EnsureFreshPrekeyBundle returns the latest prekey bundle or creates one.
func (*PrekeyManager) GenerateSignedPrekey ¶
func (m *PrekeyManager) GenerateSignedPrekey(keyID string, expiresAt string) (*ecdh.PrivateKey, SignedPrekey, error)
GenerateSignedPrekey generates, stores, and returns a new signed prekey.
func (*PrekeyManager) PublishPrekeyBundle ¶
func (m *PrekeyManager) PublishPrekeyBundle(bundle PrekeyBundle) (map[string]any, error)
PublishPrekeyBundle publishes a prekey bundle over the RPC boundary.
func (*PrekeyManager) VerifyRemotePrekeyBundle ¶
func (m *PrekeyManager) VerifyRemotePrekeyBundle(bundle PrekeyBundle, didDocument map[string]any) error
VerifyRemotePrekeyBundle verifies a prekey bundle against a DID document.
type RatchetHeader ¶
type RatchetHeader struct {
DHPubB64U string `json:"dh_pub_b64u"`
PN string `json:"pn"`
N string `json:"n"`
}
RatchetHeader is the per-message ratchet header.
type SessionStore ¶
type SessionStore interface {
SaveSession(session DirectSessionState) error
LoadSession(sessionID string) (DirectSessionState, error)
DeleteSession(sessionID string) error
FindByPeerDID(peerDID string) (DirectSessionState, bool, error)
}
SessionStore loads and stores direct E2EE sessions.
type SignedPrekey ¶
type SignedPrekey struct {
KeyID string `json:"key_id"`
PublicKeyB64U string `json:"public_key_b64u"`
ExpiresAt string `json:"expires_at"`
}
SignedPrekey describes a published signed prekey.
func SignedPrekeyFromPrivateKey ¶
func SignedPrekeyFromPrivateKey(keyID string, privateKey *ecdh.PrivateKey, expiresAt string) SignedPrekey
SignedPrekeyFromPrivateKey builds signed prekey metadata from an X25519 private key.
type SignedPrekeyStore ¶
type SignedPrekeyStore interface {
SaveSignedPrekey(keyID string, privateKey anp.PrivateKeyMaterial, metadata SignedPrekey) error
LoadSignedPrekey(keyID string) (anp.PrivateKeyMaterial, SignedPrekey, error)
LoadLatestSignedPrekey() (anp.PrivateKeyMaterial, SignedPrekey, bool, error)
}
SignedPrekeyStore loads and stores signed prekeys.
type SkippedMessageKey ¶
type SkippedMessageKey struct {
N uint32 `json:"n"`
MessageKeyB64U string `json:"message_key_b64u"`
NonceB64U string `json:"nonce_b64u"`
}
SkippedMessageKey stores skipped ratchet keys.