A class representing a user.

By default, includes two "main" keypairs, and a "main" AES key.

  • encryptionKey -- asymmetric key for encrypting
  • signingKey -- asymmetric key for signing

This will serialize some properties like a human-readable name to localStorage also. Choose the storage key by setting the static property STORAGE_KEY. The default is identity.

Constructors

  • Parameters

    • opts: {
          aes: CryptoKey;
          deviceName: string;
          devices: Record<string, Device>;
          DID: `did:key:z${string}`;
          encryptionKey: CryptoKeyPair;
          humanName: string;
          signingKey: CryptoKeyPair;
          username: string;
      }

    Returns Identity

Properties

aes: CryptoKey
deviceName: string
devices: Record<string, Device>
DID: `did:key:z${string}`
encryptionKey: CryptoKeyPair
humanName: string
rootDeviceName: string
rootDID: `did:key:z${string}`
signingKey: CryptoKeyPair
username: string
ENCRYPTION_KEY_NAME: string = 'encryption-key'
SIGNING_KEY_NAME: string = 'signing-key'
STORAGE_KEY: string = 'identity'

Accessors

  • get keys(): Record<string, string>
  • Returns Record<string, string>

Methods

  • Add another device to this identity.

    Parameters

    • opts: Omit<Device, "aes">

    Returns Promise<Identity>

  • Decrypt the given message. Throws if the message does not contain a key for this device.

    Parameters

    Returns Promise<string>

  • Generate a new AES key and use it to encrypt a message to the given recipients. The message author (this ID) is appended to the devices in the message, so the author will be able to decrypt the message.

    Omit the recipients to create a self-encrypted message.

    Parameters

    • data: string | Uint8Array<ArrayBufferLike>

      The thing to encrypt

    • Optionalrecipients: SerializedIdentity[]

      The recipients

    Returns Promise<EncryptedMessage<string>>

  • Get the device name -- a 32 character, DNS-friendly name

    Returns Promise<string>

  • Return a JSON stringifiable version of this Identity.

    Returns Promise<SerializedIdentity>

  • Parameters

    • msg: Msg
    • Optionalcharsize: CharSize

    Returns Promise<Uint8Array<ArrayBufferLike>>

  • Parameters

    • msg: string

    Returns Promise<string>

  • Create a new Identity. Use this because async.

    Parameters

    • opts: { humanName: string; humanReadableDeviceName: string; type?: "rsa" }

      Key names used for storing the main keypairs in indexedDB.

    Returns Promise<Identity>

    A new identity instance

  • Create a new device record. This does not include an AES key in the device record, because typically you create a device record before adding this device to a different Identity, so you would add an AES key at that point.

    Parameters

    • opts: { humanReadableName: string }

      A human-readable name for the device.

    Returns Promise<Omit<Device, "aes">>

    The device record without aes key.

  • Create an identity, loading saved keys from indexedDB, and saved properties from localStorage.

    Returns Promise<Identity>

  • Save a serialized Identity to localStorage. Crypto keys are already saved to indexedDB.

    Parameters

    • id: SerializedIdentity

      The serialized Identity

    Returns void