diff --git a/types/cryptex/cryptex-tests.ts b/types/cryptex/cryptex-tests.ts new file mode 100644 index 0000000000..431ad26fee --- /dev/null +++ b/types/cryptex/cryptex-tests.ts @@ -0,0 +1,16 @@ +import * as cryptex from "cryptex"; + +cryptex.update({ + config: { + keySource: "none", + algorithm: "plaintext", + secretEncoding: "binary", + secrets: { + foo: "bar" + } + } +}); + +const value: Promise = cryptex.getSecret("foo", true); +const decryptedValue: Promise = cryptex.decrypt("foo"); +const encryptedValue: Promise = cryptex.encrypt("bar"); diff --git a/types/cryptex/index.d.ts b/types/cryptex/index.d.ts new file mode 100644 index 0000000000..4e38b8baad --- /dev/null +++ b/types/cryptex/index.d.ts @@ -0,0 +1,42 @@ +// Type definitions for cryptex 1.0 +// Project: https://github.com/technologyadvice/cryptex +// Definitions by: Robert Brownstein +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.2 + +// this is the config structure for a given env +// typically, you find these in cryptex.json +export interface CryptexConfig { + keySource: string; + keySourceOpts?: { + dataKey?: string; + region?: string; + }; + algorithm?: string; + secretEncoding?: string; + secrets: object; +} +// constructor and update params +export interface CryptexOpts { + file?: string; + env?: string; + cacheKey?: boolean; + cacheKeyTimeout?: number; + config?: CryptexConfig; +} +// cryptex exports a module-level instance by default +export function decrypt(data: string, encoding?: string): Promise; +export function encrypt(data: string, encoding?: string): Promise; +export function getSecret(secret: string, optional?: boolean): Promise; +export function getSecrets(secrets: string[], optional?: boolean): Promise; +export function update(opts: CryptexOpts): void; + +// but you can still create individual instances +export class Cryptex { + constructor(opts: CryptexOpts) + decrypt(data: string, encoding?: string): string; + encrypt(data: string, encoding?: string): string; + getSecret(secret: string, optional?: boolean): Promise; + getSecrets(secrets: string[], optional?: boolean): Promise; + update(opts: CryptexOpts): void; +} diff --git a/types/cryptex/tsconfig.json b/types/cryptex/tsconfig.json new file mode 100644 index 0000000000..b2b1111305 --- /dev/null +++ b/types/cryptex/tsconfig.json @@ -0,0 +1,23 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "strictFunctionTypes": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "cryptex-tests.ts" + ] +} diff --git a/types/cryptex/tslint.json b/types/cryptex/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/cryptex/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }