mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2025-10-16 12:05:41 +00:00
Add type definitions for cryptex (#35345)
* Add type information for cryptex module * update tests * Add test file to 'files' * fix definitions for cryptex * create additional tests
This commit is contained in:
parent
e4d71d1dd4
commit
b7f07cfbbd
16
types/cryptex/cryptex-tests.ts
Normal file
16
types/cryptex/cryptex-tests.ts
Normal file
@ -0,0 +1,16 @@
|
||||
import * as cryptex from "cryptex";
|
||||
|
||||
cryptex.update({
|
||||
config: {
|
||||
keySource: "none",
|
||||
algorithm: "plaintext",
|
||||
secretEncoding: "binary",
|
||||
secrets: {
|
||||
foo: "bar"
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
const value: Promise<string> = cryptex.getSecret("foo", true);
|
||||
const decryptedValue: Promise<string> = cryptex.decrypt("foo");
|
||||
const encryptedValue: Promise<string> = cryptex.encrypt("bar");
|
||||
42
types/cryptex/index.d.ts
vendored
Normal file
42
types/cryptex/index.d.ts
vendored
Normal file
@ -0,0 +1,42 @@
|
||||
// Type definitions for cryptex 1.0
|
||||
// Project: https://github.com/technologyadvice/cryptex
|
||||
// Definitions by: Robert Brownstein <https://github.com/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<string>;
|
||||
export function encrypt(data: string, encoding?: string): Promise<string>;
|
||||
export function getSecret(secret: string, optional?: boolean): Promise<string>;
|
||||
export function getSecrets(secrets: string[], optional?: boolean): Promise<string[]>;
|
||||
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<string>;
|
||||
getSecrets(secrets: string[], optional?: boolean): Promise<string[]>;
|
||||
update(opts: CryptexOpts): void;
|
||||
}
|
||||
23
types/cryptex/tsconfig.json
Normal file
23
types/cryptex/tsconfig.json
Normal file
@ -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"
|
||||
]
|
||||
}
|
||||
1
types/cryptex/tslint.json
Normal file
1
types/cryptex/tslint.json
Normal file
@ -0,0 +1 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
Loading…
Reference in New Issue
Block a user