feat: add sncrypto client side packages
This commit is contained in:
17
packages/sncrypto-common/src/AES-GCM/Aes256GcmEncrypted.ts
Normal file
17
packages/sncrypto-common/src/AES-GCM/Aes256GcmEncrypted.ts
Normal 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
|
||||
}
|
||||
15
packages/sncrypto-common/src/AES-GCM/Aes256GcmInput.ts
Normal file
15
packages/sncrypto-common/src/AES-GCM/Aes256GcmInput.ts
Normal 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
|
||||
}
|
||||
@@ -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>
|
||||
}
|
||||
3
packages/sncrypto-common/src/AES-GCM/index.ts
Normal file
3
packages/sncrypto-common/src/AES-GCM/index.ts
Normal file
@@ -0,0 +1,3 @@
|
||||
export * from './Aes256GcmEncrypted'
|
||||
export * from './Aes256GcmInput'
|
||||
export * from './CryptoAes256GcmInterface'
|
||||
Reference in New Issue
Block a user