feat: add sncrypto client side packages

This commit is contained in:
Karol Sójko
2022-07-06 12:21:21 +02:00
parent 9d1f7043e5
commit 6ec66795d2
71 changed files with 9786 additions and 34 deletions

View File

@@ -0,0 +1,17 @@
import { Base64String } from '../Types/Base64String'
import { HexString } from '../Types/HexString'
/**
* @param iv initialization vector as a hex string
* @param tag authentication tag as a hex string
* @param ciphertext as a base64 string
* @param encoding that will be applied after decrypting
* @param aad additional authenticated data as a hex string
*/
export type Aes256GcmEncrypted<EncodingType> = {
iv: HexString
tag: HexString
ciphertext: Base64String
encoding: EncodingType
aad: HexString
}

View File

@@ -0,0 +1,15 @@
import { HexString } from '../Types/HexString'
import { Unencrypted } from '../Types/Unencrypted'
/**
* @param unencrypted -- UTF-8 string or a `string` with `encoding`
* @param iv initialization vector as a hex string
* @param key encryption key as a hex string
* @param aad additional authenticated data as a hex string
*/
export type Aes256GcmInput<EncodingType> = {
unencrypted: Unencrypted<EncodingType>
iv: HexString
key: HexString
aad?: HexString
}

View File

@@ -0,0 +1,20 @@
import { HexString } from '../Types/HexString'
import { Aes256GcmEncrypted } from './Aes256GcmEncrypted'
import { Aes256GcmInput } from './Aes256GcmInput'
export interface CryptoAes256GcmInterface<EncodingType> {
/**
* Encrypts a string using AES-GCM.
* @param input
* @returns An object which can be run through aes256GcmDecrypt to retrieve the input text.
*/
aes256GcmEncrypt(input: Aes256GcmInput<EncodingType>): Promise<Aes256GcmEncrypted<EncodingType>>
/**
* Decrypts a string using AES-GCM.
* @param encrypted
* @param key - encryption key as a hex string
* @returns A string encoded with encoding provided in the input
*/
aes256GcmDecrypt(encrypted: Aes256GcmEncrypted<EncodingType>, key: HexString): Promise<string>
}

View File

@@ -0,0 +1,3 @@
export * from './Aes256GcmEncrypted'
export * from './Aes256GcmInput'
export * from './CryptoAes256GcmInterface'