Options
All
  • Public
  • Public/Protected
  • All
Menu

Package crypto

@typed/crypto

A handful of cryptographic use-cases built upon @typed/effects.

Index

Type aliases

AesEncryptedData

AesEncryptedData: keyof [ArrayBuffer, Uint8Array]

CryptoEffects

CryptoEffects<E, A>: Effects<CryptoEnv & CryptoFailure & E, A>

Type parameters

  • E

  • A

EncryptionEffects

EncryptionEffects<E, A>: Effects<EncryptionEnv & E, A>

Type parameters

  • E

  • A

EncryptionEnv

ExportedKeyPair

ExportedKeyPair: { privateKey: ArrayBuffer; publicKey: ArrayBuffer }

Type declaration

  • Readonly privateKey: ArrayBuffer
  • Readonly publicKey: ArrayBuffer

JsonWebKeyPair

JsonWebKeyPair: { privateKey: JsonWebKey; publicKey: JsonWebKey }

Type declaration

  • Readonly privateKey: JsonWebKey
  • Readonly publicKey: JsonWebKey

ShaHashSize

ShaHashSize: 1 | 256 | 348 | 512

Variables

Const AES_ALGORITHM

AES_ALGORITHM: "AES-GCM" = "AES-GCM"

Const AES_IV_SIZE

AES_IV_SIZE: 12 = 12

Const CryptoFailure

CryptoFailure: unique symbol = Symbol.for('CryptoFailure')

Const DEFAULT_ITERATIONS

DEFAULT_ITERATIONS: 2000 = 2000

Const ENCRYPT_AND_DECRYPT

ENCRYPT_AND_DECRYPT: KeyUsage[] = ['encrypt', 'decrypt']

Const EXTRACTABLE

EXTRACTABLE: false = false

Const HASH

HASH: "SHA-256" = "SHA-256"

Const MODULUS_LENGTH

MODULUS_LENGTH: 2048 = 2048

Const PUBLIC_EXPONENT

PUBLIC_EXPONENT: Uint8Array = new Uint8Array([0x01, 0x00, 0x01])

Const SIGN_AND_VERIFY

SIGN_AND_VERIFY: KeyUsage[] = ['sign', 'verify']

Const decrypt

decrypt: (Anonymous function) = createCryptoEffect('decrypt')

Const deriveBits

deriveBits: (Anonymous function) = createCryptoEffect('deriveBits')

Const deriveKey

deriveKey: (Anonymous function) = createCryptoEffect('deriveKey')

Const digest

digest: (Anonymous function) = createCryptoEffect('digest')

Const encrypt

encrypt: (Anonymous function) = createCryptoEffect('encrypt')

Const exportKey

exportKey: { (format: "jwk", key: CryptoKey): CryptoEffects<unknown, JsonWebKey>; (format: "raw" | "pkcs8" | "spki", key: CryptoKey): CryptoEffects<unknown, ArrayBuffer>; (format: string, key: CryptoKey): CryptoEffects<unknown, ArrayBuffer | JsonWebKey> } = createCryptoEffect('exportKey') as {(format: 'jwk', key: CryptoKey): CryptoEffects<unknown, JsonWebKey>(format: 'raw' | 'pkcs8' | 'spki', key: CryptoKey): CryptoEffects<unknown, ArrayBuffer>(format: string, key: CryptoKey): CryptoEffects<unknown, ArrayBuffer | JsonWebKey>}

Type declaration

    • (format: "jwk", key: CryptoKey): CryptoEffects<unknown, JsonWebKey>
    • (format: "raw" | "pkcs8" | "spki", key: CryptoKey): CryptoEffects<unknown, ArrayBuffer>
    • (format: string, key: CryptoKey): CryptoEffects<unknown, ArrayBuffer | JsonWebKey>
    • Parameters

      • format: "jwk"
      • key: CryptoKey

      Returns CryptoEffects<unknown, JsonWebKey>

    • Parameters

      • format: "raw" | "pkcs8" | "spki"
      • key: CryptoKey

      Returns CryptoEffects<unknown, ArrayBuffer>

    • Parameters

      • format: string
      • key: CryptoKey

      Returns CryptoEffects<unknown, ArrayBuffer | JsonWebKey>

Const generateKey

generateKey: { (algorithm: string, extractable: boolean, keyUsages: string[]): CryptoEffects<unknown, CryptoKey | CryptoKeyPair>; (algorithm: RsaHashedKeyGenParams | EcKeyGenParams | DhKeyGenParams, extractable: boolean, keyUsages: string[]): CryptoEffects<unknown, CryptoKeyPair>; (algorithm: AesKeyGenParams | HmacKeyGenParams | Pbkdf2Params, extractable: boolean, keyUsages: string[]): CryptoEffects<unknown, CryptoKey> } = createCryptoEffect('generateKey') as {(algorithm: string, extractable: boolean, keyUsages: string[]): CryptoEffects<unknown,CryptoKey | CryptoKeyPair>(algorithm: RsaHashedKeyGenParams | EcKeyGenParams | DhKeyGenParams,extractable: boolean,keyUsages: string[],): CryptoEffects<unknown, CryptoKeyPair>(algorithm: AesKeyGenParams | HmacKeyGenParams | Pbkdf2Params,extractable: boolean,keyUsages: string[],): CryptoEffects<unknown, CryptoKey>}

Type declaration

    • (algorithm: string, extractable: boolean, keyUsages: string[]): CryptoEffects<unknown, CryptoKey | CryptoKeyPair>
    • (algorithm: RsaHashedKeyGenParams | EcKeyGenParams | DhKeyGenParams, extractable: boolean, keyUsages: string[]): CryptoEffects<unknown, CryptoKeyPair>
    • (algorithm: AesKeyGenParams | HmacKeyGenParams | Pbkdf2Params, extractable: boolean, keyUsages: string[]): CryptoEffects<unknown, CryptoKey>
    • Parameters

      • algorithm: string
      • extractable: boolean
      • keyUsages: string[]

      Returns CryptoEffects<unknown, CryptoKey | CryptoKeyPair>

    • Parameters

      • algorithm: RsaHashedKeyGenParams | EcKeyGenParams | DhKeyGenParams
      • extractable: boolean
      • keyUsages: string[]

      Returns CryptoEffects<unknown, CryptoKeyPair>

    • Parameters

      • algorithm: AesKeyGenParams | HmacKeyGenParams | Pbkdf2Params
      • extractable: boolean
      • keyUsages: string[]

      Returns CryptoEffects<unknown, CryptoKey>

Const importKey

importKey: { (format: "raw" | "pkcs8" | "spki", keyData: Int8Array | Int16Array | Int32Array | Uint8Array | Uint16Array | Uint32Array | Uint8ClampedArray | Float32Array | Float64Array | DataView | ArrayBuffer, algorithm: string | RsaHashedImportParams | EcKeyImportParams | HmacImportParams | DhImportKeyParams | AesKeyAlgorithm, extractable: boolean, keyUsages: string[]): CryptoEffects<unknown, CryptoKey>; (format: "jwk", keyData: JsonWebKey, algorithm: string | RsaHashedImportParams | EcKeyImportParams | HmacImportParams | DhImportKeyParams | AesKeyAlgorithm, extractable: boolean, keyUsages: string[]): CryptoEffects<unknown, CryptoKey>; (format: string, keyData: JsonWebKey | Int8Array | Int16Array | Int32Array | Uint8Array | Uint16Array | Uint32Array | Uint8ClampedArray | Float32Array | Float64Array | DataView | ArrayBuffer, algorithm: string | RsaHashedImportParams | EcKeyImportParams | HmacImportParams | DhImportKeyParams | AesKeyAlgorithm, extractable: boolean, keyUsages: string[]): CryptoEffects<unknown, CryptoKey> } = createCryptoEffect('importKey') as {(format: 'raw' | 'pkcs8' | 'spki',keyData:| Int8Array| Int16Array| Int32Array| Uint8Array| Uint16Array| Uint32Array| Uint8ClampedArray| Float32Array| Float64Array| DataView| ArrayBuffer,algorithm:| string| RsaHashedImportParams| EcKeyImportParams| HmacImportParams| DhImportKeyParams| AesKeyAlgorithm,extractable: boolean,keyUsages: string[],): CryptoEffects<unknown, CryptoKey>(format: 'jwk',keyData: JsonWebKey,algorithm:| string| RsaHashedImportParams| EcKeyImportParams| HmacImportParams| DhImportKeyParams| AesKeyAlgorithm,extractable: boolean,keyUsages: string[],): CryptoEffects<unknown, CryptoKey>(format: string,keyData:| JsonWebKey| Int8Array| Int16Array| Int32Array| Uint8Array| Uint16Array| Uint32Array| Uint8ClampedArray| Float32Array| Float64Array| DataView| ArrayBuffer,algorithm:| string| RsaHashedImportParams| EcKeyImportParams| HmacImportParams| DhImportKeyParams| AesKeyAlgorithm,extractable: boolean,keyUsages: string[],): CryptoEffects<unknown, CryptoKey>}

Type declaration

    • (format: "raw" | "pkcs8" | "spki", keyData: Int8Array | Int16Array | Int32Array | Uint8Array | Uint16Array | Uint32Array | Uint8ClampedArray | Float32Array | Float64Array | DataView | ArrayBuffer, algorithm: string | RsaHashedImportParams | EcKeyImportParams | HmacImportParams | DhImportKeyParams | AesKeyAlgorithm, extractable: boolean, keyUsages: string[]): CryptoEffects<unknown, CryptoKey>
    • (format: "jwk", keyData: JsonWebKey, algorithm: string | RsaHashedImportParams | EcKeyImportParams | HmacImportParams | DhImportKeyParams | AesKeyAlgorithm, extractable: boolean, keyUsages: string[]): CryptoEffects<unknown, CryptoKey>
    • (format: string, keyData: JsonWebKey | Int8Array | Int16Array | Int32Array | Uint8Array | Uint16Array | Uint32Array | Uint8ClampedArray | Float32Array | Float64Array | DataView | ArrayBuffer, algorithm: string | RsaHashedImportParams | EcKeyImportParams | HmacImportParams | DhImportKeyParams | AesKeyAlgorithm, extractable: boolean, keyUsages: string[]): CryptoEffects<unknown, CryptoKey>
    • Parameters

      • format: "raw" | "pkcs8" | "spki"
      • keyData: Int8Array | Int16Array | Int32Array | Uint8Array | Uint16Array | Uint32Array | Uint8ClampedArray | Float32Array | Float64Array | DataView | ArrayBuffer
      • algorithm: string | RsaHashedImportParams | EcKeyImportParams | HmacImportParams | DhImportKeyParams | AesKeyAlgorithm
      • extractable: boolean
      • keyUsages: string[]

      Returns CryptoEffects<unknown, CryptoKey>

    • Parameters

      • format: "jwk"
      • keyData: JsonWebKey
      • algorithm: string | RsaHashedImportParams | EcKeyImportParams | HmacImportParams | DhImportKeyParams | AesKeyAlgorithm
      • extractable: boolean
      • keyUsages: string[]

      Returns CryptoEffects<unknown, CryptoKey>

    • Parameters

      • format: string
      • keyData: JsonWebKey | Int8Array | Int16Array | Int32Array | Uint8Array | Uint16Array | Uint32Array | Uint8ClampedArray | Float32Array | Float64Array | DataView | ArrayBuffer
      • algorithm: string | RsaHashedImportParams | EcKeyImportParams | HmacImportParams | DhImportKeyParams | AesKeyAlgorithm
      • extractable: boolean
      • keyUsages: string[]

      Returns CryptoEffects<unknown, CryptoKey>

Const sign

sign: (Anonymous function) = createCryptoEffect('sign')

Const unwrapKey

unwrapKey: (Anonymous function) = createCryptoEffect('unwrapKey')

Const verify

verify: (Anonymous function) = createCryptoEffect('verify')

Const wrapKey

wrapKey: (Anonymous function) = createCryptoEffect('wrapKey')

Functions

arrayBufferToString

  • arrayBufferToString(buffer: ArrayBuffer): string

createServerCrypto

  • createServerCrypto(): Crypto

decryptEncryptedKeys

decryptWithAesKey

  • decryptWithAesKey(aesKey: CryptoKey, data: ArrayBuffer, iv: Uint8Array): CryptoEffects<unknown, ArrayBuffer>

decryptWithRsaKeyPair

deriveAesKey

deriveSalt

  • deriveSalt(sizeOrValue: string | number): Uint8Array

encryptExportedKeyPair

encryptWithAesKey

encryptWithRsaKeyPair

exportKeyPair

exportedKeysToEncryptedKeyPair

  • exportedKeysToEncryptedKeyPair(aesKey: CryptoKey, params: RsaHashedImportParams | EcKeyImportParams | HmacImportParams | DhImportKeyParams | AesKeyAlgorithm, exportedKeys: ExportedKeyPair): CryptoEffects<unknown, EncryptedKeyPair>

Const fromPromise

  • fromPromise<A>(promise: PromiseLike<A>): Env<unknown, Left<Error> | Right<A>>

generateEcdsaExportedKeys

generateEcdsaKeyPair

generateEncryptedEcdsaKeyPair

generateEncryptedRsaKeyPair

  • Using an AES CryptoKey, a non-extractable CryptoKeyPair is generated. Encrypted copies of the CryptoKeyPair are also generated to allow persistence and sending over the internet.

    Ideally your supplied CryptoKey is non-extractable, never persisted, and generated with user-supplied information in a way that the key can be derived again and again. The generated CryptoKeyPair should then be used to encrypt/decrypt all application data. The encrypted views of the CryptoKeyPair can safely be persisted or sent over the internet. Furthermore, if the user chooses to change their password one must only re-encrypt the generated CryptoKeyPair with the new AES CryptoKey.

    Parameters

    • aesKey: CryptoKey

      A symmetrical key that is allowed to encrypt/decrypt

    Returns CryptoEffects<unknown, EncryptedKeyPair>

Const generateHashFromString

  • generateHashFromString(str: string): CryptoEffects<unknown, ArrayBuffer>

generateRsaExportedKeys

generateRsaKeyPair

generateShaHash

getRandomValues

  • getRandomValues<A>(input: A): Effects<CryptoEnv, A>

getSubtleCrypto

  • getSubtleCrypto(): Effects<CryptoEnv, SubtleCrypto>

importEncryptedKeys

  • importEncryptedKeys(decryptionKey: CryptoKey, params: RsaHashedImportParams | EcKeyImportParams | HmacImportParams | DhImportKeyParams | AesKeyAlgorithm, encryptedKeys: AesEncryptedKeys): CryptoEffects<unknown, CryptoKeyPair>

importExportedKeyPair

signWithEcdsaKeyPair

  • signWithEcdsaKeyPair(data: ArrayBuffer, privateKey: CryptoKey): CryptoEffects<unknown, ArrayBuffer>

stringToArrayBuffer

  • stringToArrayBuffer(str: string): ArrayBuffer

verifyWithEcdsaKeyPair

  • verifyWithEcdsaKeyPair(data: ArrayBuffer, signature: ArrayBuffer, publicKey: CryptoKey): CryptoEffects<unknown, boolean>

Object literals

Const ECDSA_KEY_PARAMS

ECDSA_KEY_PARAMS: object

name

name: string = "ECDSA"

namedCurve

namedCurve: string = "P-256"

Const ECDSA_PARAMS

ECDSA_PARAMS: object

hash

hash: string = HASH

name

name: string = "ECDSA"

Const RSA_PARAMS

RSA_PARAMS: object

hash

hash: string = HASH

modulusLength

modulusLength: number = MODULUS_LENGTH

name

name: string = "RSA-OAEP"

publicExponent

publicExponent: Uint8Array = PUBLIC_EXPONENT

Generated using TypeDoc