Module: identity_key_pair

class x3dh.identity_key_pair.IdentityKeyPair[source]

Bases: ABC

An identity key pair.

There are following requirements for the identity key pair:

  • It must be able to create and verify Ed25519-compatible signatures.

  • It must be able to perform X25519-compatible Diffie-Hellman key agreements.

There are at least two different kinds of key pairs that can fulfill these requirements: Ed25519 key pairs and Curve25519 key pairs. The birational equivalence of both curves can be used to “convert” one pair to the other.

Both types of key pairs share the same private key, however instead of a private key, a seed can be used which the private key is derived from using SHA-512. This is standard practice for Ed25519, where the other 32 bytes of the SHA-512 seed hash are used as a nonce during signing. If a new key pair has to be generated, this implementation generates a seed.

property model: IdentityKeyPairModel

Returns: The internal state of this IdentityKeyPair as a pydantic model.

property json: JSONObject

Returns: The internal state of this IdentityKeyPair as a JSON-serializable Python object.

static from_model(model)[source]
Parameters:

model (IdentityKeyPairModel) – The pydantic model holding the internal state of an IdentityKeyPair, as produced by model.

Return type:

IdentityKeyPair

Returns:

A configured instance of IdentityKeyPair, with internal state restored from the model.

Warning

Migrations are not provided via the model/from_model() API. Use json/from_json() instead. Refer to Serialization and Migration in the documentation for details.

static from_json(serialized)[source]
Parameters:

serialized (JSONObject) – A JSON-serializable Python object holding the internal state of an IdentityKeyPair, as produced by json.

Return type:

IdentityKeyPair

Returns:

A configured instance of IdentityKeyPair, with internal state restored from the serialized data.

abstract property secret_type: SecretType

Returns: The type of secret used by this identity key (i.e. a seed or private key).

abstract property secret: bytes

Returns: The secret used by this identity key, i.e. the seed or private key.

abstractmethod as_priv()[source]
Return type:

IdentityKeyPairPriv

Returns:

An IdentityKeyPairPriv derived from this instance, or the instance itself if it already is an IdentityKeyPairPriv.

class x3dh.identity_key_pair.IdentityKeyPairPriv(priv)[source]

Bases: IdentityKeyPair

An IdentityKeyPair represented by a Curve25519/Ed25519 private key.

Parameters:

priv (bytes)

property secret_type: SecretType

Returns: The type of secret used by this identity key (i.e. a seed or private key).

property secret: bytes

Returns: The secret used by this identity key, i.e. the seed or private key.

as_priv()[source]
Return type:

IdentityKeyPairPriv

Returns:

An IdentityKeyPairPriv derived from this instance, or the instance itself if it already is an IdentityKeyPairPriv.

property priv: bytes

Returns: The Curve25519/Ed25519 private key.

class x3dh.identity_key_pair.IdentityKeyPairSeed(seed)[source]

Bases: IdentityKeyPair

An IdentityKeyPair represented by a Curve25519/Ed25519 seed.

Parameters:

seed (bytes)

property secret_type: SecretType

Returns: The type of secret used by this identity key (i.e. a seed or private key).

property secret: bytes

Returns: The secret used by this identity key, i.e. the seed or private key.

as_priv()[source]
Return type:

IdentityKeyPairPriv

Returns:

An IdentityKeyPairPriv derived from this instance, or the instance itself if it already is an IdentityKeyPairPriv.

property seed: bytes

Returns: The Curve25519/Ed25519 seed.