Documentation
¶
Index ¶
- Constants
- Variables
- func BuildInitAAD(metadata DirectEnvelopeMetadata, body DirectInitBody) ([]byte, error)
- func BuildInitAADV2(meta V2DirectMetadata, body V2DirectInitBody) ([]byte, error)
- func BuildMessageAAD(metadata DirectEnvelopeMetadata, body DirectCipherBody) ([]byte, error)
- func BuildMessageAADV2(meta V2DirectMetadata, body V2DirectCipherBody) ([]byte, error)
- func CanonicalApplicationPlaintextV2(value V2ApplicationPlaintext) ([]byte, error)
- func DecryptWithStep(step ChainStep, ciphertext []byte, aad []byte) ([]byte, error)
- func DirectSendRequestV2(meta V2DirectMetadata, body any) (map[string]any, error)
- func EncryptWithStep(step ChainStep, plaintext []byte, aad []byte) ([]byte, error)
- func ExtractX25519PublicKey(didDocument map[string]any, keyID string) ([32]byte, error)
- func GetPrekeyBundleRequestV2(meta V2KeyServiceMetadata, body V2GetPrekeyBundleBody) (map[string]any, error)
- func ParseGetPrekeyBundleRequestV2(value any) (V2KeyServiceMetadata, V2GetPrekeyBundleBody, error)
- func ParsePublishPrekeyBundleRequestV2(value any) (V2KeyServiceMetadata, V2PublishPrekeyBundleBody, error)
- func PublishPrekeyBundleRequestV2(meta V2KeyServiceMetadata, body V2PublishPrekeyBundleBody) (map[string]any, error)
- func SignedBundleObjectJCSV2(bundle V2PrekeyBundle) ([]byte, error)
- func VerifyPrekeyBundle(bundle PrekeyBundle, didDocument map[string]any) error
- func VerifyPrekeyBundleV2(bundle V2PrekeyBundle, didDocument map[string]any, now time.Time) error
- type ApplicationPlaintext
- type ChainStep
- type DIDResolver
- type DirectCipherBody
- type DirectE2eeSession
- func (DirectE2eeSession) AcceptIncomingInit(metadata DirectEnvelopeMetadata, localStaticKeyID string, ...) (DirectSessionState, ApplicationPlaintext, error)
- func (DirectE2eeSession) AcceptIncomingInitWithOPK(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)
- func (DirectE2eeSession) InitiateSessionWithOPK(metadata DirectEnvelopeMetadata, operationID string, localStaticKeyID string, ...) (DirectSessionState, PendingOutboundRecord, DirectInitBody, error)
- type DirectEnvelopeMetadata
- type DirectInitBody
- type DirectSessionState
- type Error
- type FileOneTimePrekeyStore
- func (s *FileOneTimePrekeyStore) DeleteOneTimePrekey(keyID string) error
- func (s *FileOneTimePrekeyStore) ListOneTimePrekeys() ([]OneTimePrekey, error)
- func (s *FileOneTimePrekeyStore) LoadOneTimePrekey(keyID string) (anp.PrivateKeyMaterial, OneTimePrekey, error)
- func (s *FileOneTimePrekeyStore) SaveOneTimePrekey(keyID string, privateKey anp.PrivateKeyMaterial, metadata OneTimePrekey) 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
- func DeriveInitialMaterialForInitiator(senderStaticPrivate *ecdh.PrivateKey, senderEphemeralPrivate *ecdh.PrivateKey, ...) (InitialMaterial, error)
- func DeriveInitialMaterialForInitiatorWithOPK(senderStaticPrivate *ecdh.PrivateKey, senderEphemeralPrivate *ecdh.PrivateKey, ...) (InitialMaterial, error)
- func DeriveInitialMaterialForResponder(recipientStaticPrivate *ecdh.PrivateKey, ...) (InitialMaterial, error)
- func DeriveInitialMaterialForResponderWithOPK(recipientStaticPrivate *ecdh.PrivateKey, ...) (InitialMaterial, error)
- 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) (VerifiedPrekeyBundle, 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 OneTimePrekey
- type OneTimePrekeyStore
- type PendingOutboundRecord
- type PendingOutboundStore
- type PrekeyBundle
- type PrekeyManager
- func (m *PrekeyManager) BuildPrekeyBundle(signedPrekey SignedPrekey, bundleID string, created string) (PrekeyBundle, error)
- func (m *PrekeyManager) EnsureFreshOneTimePrekeys(minCount int) ([]OneTimePrekey, error)
- func (m *PrekeyManager) EnsureFreshPrekeyBundle() (PrekeyBundle, error)
- func (m *PrekeyManager) GenerateOneTimePrekey(keyID string) (*ecdh.PrivateKey, OneTimePrekey, 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 RootStep
- type SessionStore
- type SignedPrekey
- type SignedPrekeyStore
- type SkippedMessageKey
- type V2ApplicationPlaintext
- type V2DirectCipherBody
- type V2DirectInitBody
- type V2DirectMetadata
- type V2DirectSendResult
- type V2GetPrekeyBundleBody
- type V2GetPrekeyBundleResult
- type V2KeyServiceMetadata
- type V2OneTimePrekey
- type V2PrekeyBundle
- type V2ProtocolError
- type V2PublishPrekeyBundleBody
- type V2PublishPrekeyBundleResult
- type V2RatchetHeader
- type V2SignedPrekey
- type V2Target
- type VerifiedPrekeyBundle
Constants ¶
const ( ContentTypeDirectInit = "application/anp-direct-init+json" ContentTypeDirectCipher = "application/anp-direct-cipher+json" )
const ( SessionStatusPendingConfirmation = "pending-confirmation" SessionStatusEstablished = "established" )
const ( DirectE2EEProfileV2 = "anp.direct.e2ee.v2" DirectE2EESecurityProfile = "direct-e2ee" TransportProtectedSecurityProfile = "transport-protected" ContentTypeDirectInitV2 = "application/anp-direct-init+json" ContentTypeDirectCipherV2 = "application/anp-direct-cipher+json" MTIDirectE2EESuiteV2 = "ANP-DIRECT-E2EE-X3DH-25519-CHACHA20POLY1305-SHA256-V1" )
const MTIDirectE2EESuite = "ANP-DIRECT-E2EE-X3DH-25519-CHACHA20POLY1305-SHA256-V1"
const MaxSkip uint32 = 1000
Variables ¶
var V2ProtocolErrors = []V2ProtocolError{
{4000, "anp.direct.e2ee.bundle_not_found"},
{4001, "anp.direct.e2ee.bundle_invalid"},
{4002, "anp.direct.e2ee.bundle_expired"},
{4003, "anp.direct.e2ee.opk_unavailable"},
{4004, "anp.direct.e2ee.missing_key_agreement"},
{4005, "anp.direct.e2ee.session_not_found"},
{4006, "anp.direct.e2ee.session_conflict"},
{4007, "anp.direct.e2ee.bad_init_message"},
{4008, "anp.direct.e2ee.replay_detected"},
{4009, "anp.direct.e2ee.decrypt_failed"},
{4010, "anp.direct.e2ee.max_skip_exceeded"},
{4011, "anp.direct.e2ee.reset_required"},
{4012, "anp.direct.e2ee.invalid_security_binding"},
}
Functions ¶
func BuildInitAAD ¶
func BuildInitAAD(metadata DirectEnvelopeMetadata, body DirectInitBody) ([]byte, error)
BuildInitAAD builds canonical associated data for a P5 direct init message.
func BuildInitAADV2 ¶ added in v0.9.0
func BuildInitAADV2(meta V2DirectMetadata, body V2DirectInitBody) ([]byte, error)
func BuildMessageAAD ¶
func BuildMessageAAD(metadata DirectEnvelopeMetadata, body DirectCipherBody) ([]byte, error)
BuildMessageAAD builds canonical associated data for a P5 direct cipher message.
func BuildMessageAADV2 ¶ added in v0.9.0
func BuildMessageAADV2(meta V2DirectMetadata, body V2DirectCipherBody) ([]byte, error)
func CanonicalApplicationPlaintextV2 ¶ added in v0.9.0
func CanonicalApplicationPlaintextV2(value V2ApplicationPlaintext) ([]byte, error)
func DecryptWithStep ¶
DecryptWithStep decrypts ciphertext with the derived step.
func DirectSendRequestV2 ¶ added in v0.9.0
func DirectSendRequestV2(meta V2DirectMetadata, body any) (map[string]any, error)
func EncryptWithStep ¶
EncryptWithStep encrypts plaintext with the derived step.
func ExtractX25519PublicKey ¶
ExtractX25519PublicKey extracts an X25519 public key from a DID document.
func GetPrekeyBundleRequestV2 ¶ added in v0.9.0
func GetPrekeyBundleRequestV2(meta V2KeyServiceMetadata, body V2GetPrekeyBundleBody) (map[string]any, error)
func ParseGetPrekeyBundleRequestV2 ¶ added in v0.9.0
func ParseGetPrekeyBundleRequestV2(value any) (V2KeyServiceMetadata, V2GetPrekeyBundleBody, error)
func ParsePublishPrekeyBundleRequestV2 ¶ added in v0.9.0
func ParsePublishPrekeyBundleRequestV2(value any) (V2KeyServiceMetadata, V2PublishPrekeyBundleBody, error)
func PublishPrekeyBundleRequestV2 ¶ added in v0.9.0
func PublishPrekeyBundleRequestV2(meta V2KeyServiceMetadata, body V2PublishPrekeyBundleBody) (map[string]any, error)
func SignedBundleObjectJCSV2 ¶ added in v0.9.0
func SignedBundleObjectJCSV2(bundle V2PrekeyBundle) ([]byte, error)
func VerifyPrekeyBundle ¶
func VerifyPrekeyBundle(bundle PrekeyBundle, didDocument map[string]any) error
VerifyPrekeyBundle verifies a prekey bundle against the owner's DID document.
func VerifyPrekeyBundleV2 ¶ added in v0.9.0
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"`
PayloadB64U string `json:"payload_b64u,omitempty"`
}
ApplicationPlaintext is the decrypted application payload.
func NewBinaryPlaintext ¶ added in v0.8.7
func NewBinaryPlaintext(contentType string, payloadB64U string) ApplicationPlaintext
NewBinaryPlaintext builds a binary 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 implements P5 kdf_ck(CK) -> (CK', MK, NONCE).
type DIDResolver ¶
DIDResolver resolves a DID document.
type DirectCipherBody ¶
type DirectCipherBody struct {
SessionID string `json:"session_id"`
Suite string `json:"suite,omitempty"`
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 P5 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 without OPK.
func (DirectE2eeSession) AcceptIncomingInitWithOPK ¶ added in v0.8.7
func (DirectE2eeSession) AcceptIncomingInitWithOPK(metadata DirectEnvelopeMetadata, localStaticKeyID string, localStaticPrivate *ecdh.PrivateKey, localSignedPrekeyPrivate *ecdh.PrivateKey, localOneTimePrekeyPrivate *ecdh.PrivateKey, senderStaticPublic [32]byte, body DirectInitBody) (DirectSessionState, ApplicationPlaintext, error)
AcceptIncomingInitWithOPK processes an init message for the responder with an optional OPK private key.
func (DirectE2eeSession) DecryptFollowUp ¶
func (DirectE2eeSession) DecryptFollowUp(session *DirectSessionState, metadata DirectEnvelopeMetadata, body DirectCipherBody, _ ...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 without OPK.
func (DirectE2eeSession) InitiateSessionWithOPK ¶ added in v0.8.7
func (DirectE2eeSession) InitiateSessionWithOPK(metadata DirectEnvelopeMetadata, operationID string, localStaticKeyID string, localStaticPrivate *ecdh.PrivateKey, recipientBundle PrekeyBundle, recipientStaticPublic [32]byte, recipientSignedPrekeyPublic [32]byte, recipientOneTimePrekeyPublic *[32]byte, recipientOneTimePrekeyID string, plaintext ApplicationPlaintext) (DirectSessionState, PendingOutboundRecord, DirectInitBody, error)
InitiateSessionWithOPK creates the initial encrypted session message with an optional OPK public key.
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"`
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 P5 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,omitempty"`
RecvChainKeyB64U string `json:"recv_chain_key_b64u,omitempty"`
RatchetPrivateKeyB64U string `json:"ratchet_private_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"`
Status string `json:"status"`
}
DirectSessionState stores direct E2EE session state.
type FileOneTimePrekeyStore ¶ added in v0.8.7
type FileOneTimePrekeyStore struct {
// contains filtered or unexported fields
}
FileOneTimePrekeyStore persists one-time prekeys and metadata to disk.
func NewFileOneTimePrekeyStore ¶ added in v0.8.7
func NewFileOneTimePrekeyStore(root string) (*FileOneTimePrekeyStore, error)
NewFileOneTimePrekeyStore creates a file-backed OPK store.
func (*FileOneTimePrekeyStore) DeleteOneTimePrekey ¶ added in v0.8.7
func (s *FileOneTimePrekeyStore) DeleteOneTimePrekey(keyID string) error
func (*FileOneTimePrekeyStore) ListOneTimePrekeys ¶ added in v0.8.7
func (s *FileOneTimePrekeyStore) ListOneTimePrekeys() ([]OneTimePrekey, error)
func (*FileOneTimePrekeyStore) LoadOneTimePrekey ¶ added in v0.8.7
func (s *FileOneTimePrekeyStore) LoadOneTimePrekey(keyID string) (anp.PrivateKeyMaterial, OneTimePrekey, error)
func (*FileOneTimePrekeyStore) SaveOneTimePrekey ¶ added in v0.8.7
func (s *FileOneTimePrekeyStore) SaveOneTimePrekey(keyID string, privateKey anp.PrivateKeyMaterial, metadata OneTimePrekey) error
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
ChainKey [32]byte
SessionID string
}
InitialMaterial contains the symmetric material derived from P5 X3DH-like.
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 DeriveInitialMaterialForInitiatorWithOPK ¶ added in v0.8.7
func DeriveInitialMaterialForInitiatorWithOPK(senderStaticPrivate *ecdh.PrivateKey, senderEphemeralPrivate *ecdh.PrivateKey, recipientStaticPublic [32]byte, recipientSignedPrekeyPublic [32]byte, recipientOneTimePrekeyPublic *[32]byte) (InitialMaterial, error)
DeriveInitialMaterialForInitiatorWithOPK derives session material with optional OPK DH4.
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.
func DeriveInitialMaterialForResponderWithOPK ¶ added in v0.8.7
func DeriveInitialMaterialForResponderWithOPK(recipientStaticPrivate *ecdh.PrivateKey, recipientSignedPrekeyPrivate *ecdh.PrivateKey, recipientOneTimePrekeyPrivate *ecdh.PrivateKey, senderStaticPublic [32]byte, senderEphemeralPublic [32]byte) (InitialMaterial, error)
DeriveInitialMaterialForResponderWithOPK derives session material with optional OPK DH4.
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, oneTimePrekeyStores ...OneTimePrekeyStore) (*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) (VerifiedPrekeyBundle, 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 OneTimePrekey ¶ added in v0.8.7
type OneTimePrekey struct {
KeyID string `json:"key_id"`
PublicKeyB64U string `json:"public_key_b64u"`
}
OneTimePrekey describes an OPK allocated separately from the static bundle.
type OneTimePrekeyStore ¶ added in v0.8.7
type OneTimePrekeyStore interface {
SaveOneTimePrekey(keyID string, privateKey anp.PrivateKeyMaterial, metadata OneTimePrekey) error
LoadOneTimePrekey(keyID string) (anp.PrivateKeyMaterial, OneTimePrekey, error)
ListOneTimePrekeys() ([]OneTimePrekey, error)
DeleteOneTimePrekey(keyID string) error
}
OneTimePrekeyStore loads and stores OPKs.
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. It MUST NOT embed one_time_prekey.
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, localServiceDID string, staticKeyAgreementID string, signingPrivateKey anp.PrivateKeyMaterial, signingVerificationMethod string, signedPrekeyStore SignedPrekeyStore, rpcClient RPCClient, oneTimePrekeyStores ...OneTimePrekeyStore) *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) EnsureFreshOneTimePrekeys ¶ added in v0.8.7
func (m *PrekeyManager) EnsureFreshOneTimePrekeys(minCount int) ([]OneTimePrekey, error)
EnsureFreshOneTimePrekeys makes sure at least minCount OPKs are available locally.
func (*PrekeyManager) EnsureFreshPrekeyBundle ¶
func (m *PrekeyManager) EnsureFreshPrekeyBundle() (PrekeyBundle, error)
EnsureFreshPrekeyBundle returns the latest prekey bundle or creates one.
func (*PrekeyManager) GenerateOneTimePrekey ¶ added in v0.8.7
func (m *PrekeyManager) GenerateOneTimePrekey(keyID string) (*ecdh.PrivateKey, OneTimePrekey, error)
GenerateOneTimePrekey generates, stores, and returns a new OPK.
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. The publish operation ID identifies the complete publish payload: it is derived from the bundle ID plus a digest of the OPK sidecar key IDs, so an exact retry of the same payload reuses the ID while a replenished OPK sidecar produces a new one.
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 RootStep ¶ added in v0.8.7
RootStep contains root and chain material derived from a DH ratchet step.
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 {
DHPubB64U string `json:"dh_pub_b64u"`
N uint32 `json:"n"`
MessageKeyB64U string `json:"message_key_b64u"`
NonceB64U string `json:"nonce_b64u"`
}
SkippedMessageKey stores skipped ratchet keys.
type V2ApplicationPlaintext ¶ added in v0.9.0
type V2ApplicationPlaintext struct {
ApplicationContentType string `json:"application_content_type"`
LogicalMessageID string `json:"logical_message_id,omitempty"`
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"`
PayloadB64U *string `json:"payload_b64u,omitempty"`
}
func (*V2ApplicationPlaintext) UnmarshalJSON ¶ added in v0.9.0
func (value *V2ApplicationPlaintext) UnmarshalJSON(encoded []byte) error
func (V2ApplicationPlaintext) Validate ¶ added in v0.9.0
func (value V2ApplicationPlaintext) Validate() error
type V2DirectCipherBody ¶ added in v0.9.0
type V2DirectCipherBody struct {
SessionID string `json:"session_id"`
Suite string `json:"suite,omitempty"`
RatchetHeader V2RatchetHeader `json:"ratchet_header"`
CiphertextB64U string `json:"ciphertext_b64u"`
}
func (V2DirectCipherBody) Validate ¶ added in v0.9.0
func (value V2DirectCipherBody) Validate() error
type V2DirectInitBody ¶ added in v0.9.0
type V2DirectInitBody struct {
SessionID string `json:"session_id"`
Suite string `json:"suite"`
SenderStaticKeyAgreementID string `json:"sender_static_key_agreement_id"`
RecipientBundleID string `json:"recipient_bundle_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"`
}
func (V2DirectInitBody) Validate ¶ added in v0.9.0
func (value V2DirectInitBody) Validate() error
type V2DirectMetadata ¶ added in v0.9.0
type V2DirectMetadata struct {
ANPVersion string `json:"anp_version,omitempty"`
Profile string `json:"profile"`
SecurityProfile string `json:"security_profile"`
SenderDID string `json:"sender_did"`
SenderDeviceID string `json:"sender_device_id"`
Target V2Target `json:"target"`
RecipientDeviceID string `json:"recipient_device_id"`
OperationID string `json:"operation_id"`
MessageID string `json:"message_id"`
ContentType string `json:"content_type"`
CreatedAt string `json:"created_at,omitempty"`
}
func ParseDirectSendRequestV2 ¶ added in v0.9.0
func ParseDirectSendRequestV2(value any) (V2DirectMetadata, any, error)
func (V2DirectMetadata) Validate ¶ added in v0.9.0
func (value V2DirectMetadata) Validate() error
type V2DirectSendResult ¶ added in v0.9.0
type V2DirectSendResult struct {
Accepted bool `json:"accepted"`
MessageID string `json:"message_id"`
OperationID string `json:"operation_id"`
TargetDID string `json:"target_did"`
RecipientDeviceID string `json:"recipient_device_id"`
AcceptedAt string `json:"accepted_at"`
}
func ParseDirectSendResultV2 ¶ added in v0.9.0
func ParseDirectSendResultV2(value any) (V2DirectSendResult, error)
func (V2DirectSendResult) Validate ¶ added in v0.9.0
func (value V2DirectSendResult) Validate() error
type V2GetPrekeyBundleBody ¶ added in v0.9.0
type V2GetPrekeyBundleResult ¶ added in v0.9.0
type V2GetPrekeyBundleResult struct {
TargetDID string `json:"target_did"`
TargetDeviceID string `json:"target_device_id"`
PrekeyBundle V2PrekeyBundle `json:"prekey_bundle"`
OneTimePrekey *V2OneTimePrekey `json:"one_time_prekey,omitempty"`
}
func ParseGetPrekeyBundleResultV2 ¶ added in v0.9.0
func ParseGetPrekeyBundleResultV2(value any) (V2GetPrekeyBundleResult, error)
func (V2GetPrekeyBundleResult) Validate ¶ added in v0.9.0
func (value V2GetPrekeyBundleResult) Validate() error
type V2KeyServiceMetadata ¶ added in v0.9.0
type V2KeyServiceMetadata struct {
ANPVersion string `json:"anp_version,omitempty"`
Profile string `json:"profile"`
SecurityProfile string `json:"security_profile"`
SenderDID string `json:"sender_did"`
SenderDeviceID string `json:"sender_device_id"`
Target V2Target `json:"target"`
OperationID string `json:"operation_id"`
CreatedAt string `json:"created_at,omitempty"`
}
func V2KeyServiceMeta ¶ added in v0.9.0
func V2KeyServiceMeta(senderDID, senderDeviceID, serviceDID, operationID string) V2KeyServiceMetadata
func (V2KeyServiceMetadata) Validate ¶ added in v0.9.0
func (value V2KeyServiceMetadata) Validate() error
type V2OneTimePrekey ¶ added in v0.9.0
type V2OneTimePrekey struct {
KeyID string `json:"key_id"`
PublicKeyB64U string `json:"public_key_b64u"`
}
func (V2OneTimePrekey) Validate ¶ added in v0.9.0
func (value V2OneTimePrekey) Validate() error
type V2PrekeyBundle ¶ added in v0.9.0
type V2PrekeyBundle struct {
BundleID string `json:"bundle_id"`
OwnerDID string `json:"owner_did"`
OwnerDeviceID string `json:"owner_device_id"`
Suite string `json:"suite"`
StaticKeyAgreementID string `json:"static_key_agreement_id"`
SignedPrekey V2SignedPrekey `json:"signed_prekey"`
Proof map[string]any `json:"proof"`
}
func BuildPrekeyBundleV2 ¶ added in v0.9.0
func BuildPrekeyBundleV2(bundleID, ownerDID, ownerDeviceID, staticKeyAgreementID string, signedPrekey V2SignedPrekey, signingPrivateKey anp.PrivateKeyMaterial, verificationMethod, created string) (V2PrekeyBundle, error)
func (V2PrekeyBundle) ValidateStructure ¶ added in v0.9.0
func (value V2PrekeyBundle) ValidateStructure() error
type V2ProtocolError ¶ added in v0.9.0
V2ProtocolError is one normative P5 v2 JSON-RPC error allocation.
func DirectE2EEV2ErrorByCode ¶ added in v0.9.0
func DirectE2EEV2ErrorByCode(code int) (V2ProtocolError, bool)
DirectE2EEV2ErrorByCode resolves only the normative 4000-4012 table.
type V2PublishPrekeyBundleBody ¶ added in v0.9.0
type V2PublishPrekeyBundleBody struct {
PrekeyBundle V2PrekeyBundle `json:"prekey_bundle"`
OneTimePrekeys []V2OneTimePrekey `json:"one_time_prekeys,omitempty"`
}
type V2PublishPrekeyBundleResult ¶ added in v0.9.0
type V2PublishPrekeyBundleResult struct {
Published bool `json:"published"`
OwnerDID string `json:"owner_did"`
OwnerDeviceID string `json:"owner_device_id"`
BundleID string `json:"bundle_id"`
PublishedAt string `json:"published_at"`
PublishedOPKCount *uint64 `json:"published_opk_count,omitempty"`
}
func ParsePublishPrekeyBundleResultV2 ¶ added in v0.9.0
func ParsePublishPrekeyBundleResultV2(value any) (V2PublishPrekeyBundleResult, error)
func (V2PublishPrekeyBundleResult) Validate ¶ added in v0.9.0
func (value V2PublishPrekeyBundleResult) Validate() error
type V2RatchetHeader ¶ added in v0.9.0
type V2RatchetHeader struct {
DHPubB64U string `json:"dh_pub_b64u"`
PN string `json:"pn"`
N string `json:"n"`
}
func (V2RatchetHeader) Validate ¶ added in v0.9.0
func (value V2RatchetHeader) Validate() error
type V2SignedPrekey ¶ added in v0.9.0
type V2SignedPrekey struct {
KeyID string `json:"key_id"`
PublicKeyB64U string `json:"public_key_b64u"`
ExpiresAt string `json:"expires_at"`
}
func (V2SignedPrekey) Validate ¶ added in v0.9.0
func (value V2SignedPrekey) Validate() error
type VerifiedPrekeyBundle ¶ added in v0.8.7
type VerifiedPrekeyBundle struct {
Bundle PrekeyBundle
OneTimePrekey *OneTimePrekey
}
VerifiedPrekeyBundle is a verified remote prekey bundle plus an optional leased OPK.