lemon-core
Version:
Lemon Serverless Micro-Service Platform
114 lines (113 loc) • 3.04 kB
TypeScript
/// <reference types="node" />
import { CoreKmsService } from '../core-services';
import 'dotenv/config';
declare const instance: () => any;
export type EncryptResult = ReturnType<typeof instance>['EncryptResult'];
export type DecryptResult = ReturnType<typeof instance>['DecryptResult'];
/**
* check if base64 string.
*/
export declare const isBase64: (text: string) => boolean;
/**
* normal base64 to url encoded.
*/
export declare const fromBase64: (base64: string) => string;
/**
* additional options for KMS signing.
*/
export interface AWSKMSSignOption {
/**
* algorithm used to sign and verify.
* (default RSASSA_PKCS1_V1_5_SHA_256)
*/
algorithm?: EncryptionAlgorithm;
}
type EncryptionAlgorithm = string;
/**
* class: `KeyVaultService`
* - shared Key Management Service to encrypt/decrypt message.
*/
export declare class KeyVaultService implements CoreKmsService {
/**
* environ name of KMS KEY
*/
static ENV_KMS_KEY_ID: string;
static DEF_KMS_TARGET: string;
private _keyId;
private _options;
constructor(keyId?: string, options?: AWSKMSSignOption);
/**
* get name of this
*/
name: () => string;
/**
* hello
*/
hello: () => string;
/**
* get key-id to encrypt.
*/
keyId: () => string;
instance: () => {
keyClient: any;
credentials: any;
CryptographyClient: any;
EncryptResult: any;
DecryptResult: any;
};
/**
* get KMS instance in stock
*/
/**
* Encrypt message
*
* @param {*} message
*/
encrypt: (message: string) => Promise<any>;
/**
* Decrypt message
*
* @param {*} encryptedSecret
*/
decrypt: (encryptedSecret: any) => Promise<any>;
/**
* make signature by message
*
* @param {*} message any string
* @param forJwtSignature (option) flag to get JWT signature format.
*/
sign: (message: any, forJwtSignature?: boolean) => Promise<any>;
/**
* verify signature in asymetric way
* - it tooks around `30ms`
*
* @param {*} message any string
* @param {*} signature signature of Buffer or string(in base64)
*/
verify: (message: any, signature: any) => Promise<any>;
/**
* retrieve public-key for asymetric verification.
* - used to verify signature with JWT library w/o making request to AWS KMS.
* - in general, cache this `public-key` to verify locally.
*
* @param encoding (optional) encoding type
*/
getPublicKey: (encoding?: BufferEncoding) => Promise<any>;
/**
* it should be 'hello lemon'
*
* # Example
* ```sh
* # encrypt text
* $ aws kms encrypt --profile <profile> --key-id <kms-key-id> --plaintext "hello lemon" --query CiphertextBlob --output text
* ```
*/
sample(): Promise<{
KMS_KEY_ID: string;
keyId: string;
message: string;
encrypted: any;
decrypted: any;
}>;
}
export {};