Constructors

  • Parameters

    • Optionalkey: string | Uint8Array
    • Optionalsalt: string | Uint8Array

    Returns Keychain

Properties

authTokenPromise: Promise<Uint8Array>
key: Uint8Array
mainKeyPromise: Promise<CryptoKey>
metaKeyPromise: Promise<CryptoKey>
salt: Uint8Array

Accessors

  • get keyB64(): string
  • Get the main key as a base64url encoded string

    Returns string

  • get saltB64(): string
  • Get the salt as base64 string

    Returns string

Methods

  • Get a header string: Bearer sync-v1 ${authTokenB64}. Pass in a token, or else this will use the authToken derived from the main key.

    Parameters

    • OptionaltokenString: string

    Returns Promise<string>

  • get a promise for the auth token.

    Returns Promise<Uint8Array>

  • Get the auth token as a base64 string

    Returns Promise<string>

  • Decrypt in memory, not streaming.

    Parameters

    • bytes: Uint8Array

    Returns Promise<ArrayBuffer>

  • Parameters

    • ivEncryptedMeta: Uint8Array

    Returns Promise<Uint8Array>

  • Take an encrypted stream, return a decrypted stream.

    Parameters

    • encryptedStream: ReadableStream<Uint8Array>

      The input (encrypted) stream

    Returns Promise<ReadableStream<Uint8Array>>

    The decrypted stream

  • Returns an object containing ranges, an array of objects containing offset and length integers specifying the encrypted byte ranges that are needed to decrypt the client's specified range, and a decrypt function.

    Parameters

    • offset: number

      Integer

    • length: number

      Integer

    • totalEncryptedLength: number

      Integer

    Returns Promise<
        {
            decrypt: (streams: ReadableStream[]) => ReadableStream;
            ranges: { length: number; offset: number }[];
        },
    >

  • Encrypt and return some data; don't stream.

    NOTE: This generates a new key each time it is called, via this.generateKey.

    Parameters

    • bytes: ArrayBuffer | Uint8Array
    • Optionalopts: { iv?: Uint8Array; size?: number }

      Optional params, iv and size. If size is omitted, default is 16 bytes. iv is a random 12 bits, will be generated if not passed in.

    Returns Promise<Uint8Array>

  • Parameters

    • meta: Uint8Array

    Returns Promise<Uint8Array>

  • Take a stream, return an encrypted stream.

    Parameters

    • stream: ReadableStream<Uint8Array>

      Input stream

    Returns Promise<ReadableStream<Uint8Array>>

  • Derive a new AES-GCM key from the main key.

    Parameters

    • OptionalkeyLength: number

      Optional size for the key, in bytes, eg, 16 or 32.

    Returns Promise<CryptoKey>

  • Set the auth token

    Parameters

    • OptionalauthToken: string | Uint8Array

      The new token

    Returns void

  • Get an authentication header as a static method.

    Parameters

    • secretKey: string
    • salt: string | Uint8Array

    Returns Promise<string>

  • Parameters

    • writeToken: string

    Returns string