From 7416fd03c44b5a4d9e9ce6eb5bd4418d754adac0 Mon Sep 17 00:00:00 2001 From: Florian Dreschner Date: Sun, 25 Nov 2018 21:42:31 +0100 Subject: [PATCH 1/4] Add encrypt and decrypt to Pubnub types --- types/pubnub/index.d.ts | 22 +++++++++++++++++++++- types/pubnub/pubnub-tests.ts | 12 ++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/types/pubnub/index.d.ts b/types/pubnub/index.d.ts index 8337acfbe4..1fc38edabf 100644 --- a/types/pubnub/index.d.ts +++ b/types/pubnub/index.d.ts @@ -1,6 +1,6 @@ // Type definitions for pubnub 4.0 // Project: https://github.com/pubnub/javascript -// Definitions by: bitbankinc , rollymaduk , vitosamson +// Definitions by: bitbankinc , rollymaduk , vitosamson , FlorianDr // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // @see https://www.pubnub.com/docs/web-javascript/api-reference-configuration @@ -88,6 +88,18 @@ declare class Pubnub { setState( params: Pubnub.SetStateParameters ): Promise; + + encrypt( + data: string, + customCipherKey?: string, + options?: Pubnub.CryptoParameters, + ): object | string | null; + + decrypt( + data: object, + customCipherKey?: string, + options?: Pubnub.CryptoParameters + ): object | string | null; } declare namespace Pubnub { @@ -296,6 +308,14 @@ declare namespace Pubnub { }; } + // encrypt + interface CryptoParameters { + encryptKey?: boolean; + keyEncoding?: string; + keyLength?: number; + mode?: string; + } + interface Categories { PNNetworkUpCategory: string; PNNetworkDownCategory: string; diff --git a/types/pubnub/pubnub-tests.ts b/types/pubnub/pubnub-tests.ts index 1d8b2bb1ca..50660bd942 100644 --- a/types/pubnub/pubnub-tests.ts +++ b/types/pubnub/pubnub-tests.ts @@ -86,3 +86,15 @@ pubnub.setState({ channels: [] }, (status, res) => { pubnub.setState({ channels: [] }).then(res => { console.log(res.state); }); + +const cryptoOptions = { + encryptKey: true, + keyEncoding: 'utf8', + keyLength: 256, + mode: 'cbc' +}; +const mySecret = { + message: 'Hi!', +}; +pubnub.decrypt(mySecret, undefined, cryptoOptions); +pubnub.encrypt('egrah5rwgrehwqh5eh3hwfwef', undefined, cryptoOptions); From 147d828b80b191986af9e796d635e0cef3fdae14 Mon Sep 17 00:00:00 2001 From: Florian Dreschner Date: Sun, 25 Nov 2018 21:44:14 +0100 Subject: [PATCH 2/4] Add comment for decrypt parameters --- types/pubnub/index.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/types/pubnub/index.d.ts b/types/pubnub/index.d.ts index 1fc38edabf..0b5f75901c 100644 --- a/types/pubnub/index.d.ts +++ b/types/pubnub/index.d.ts @@ -308,7 +308,7 @@ declare namespace Pubnub { }; } - // encrypt + // encrypt & decrypt interface CryptoParameters { encryptKey?: boolean; keyEncoding?: string; From 44ef75a9066b67df3e76d93f12bff05a408e7137 Mon Sep 17 00:00:00 2001 From: Florian Dreschner Date: Sun, 25 Nov 2018 21:58:23 +0100 Subject: [PATCH 3/4] Add version note under header --- types/pubnub/index.d.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/types/pubnub/index.d.ts b/types/pubnub/index.d.ts index 0b5f75901c..7e148bc4c4 100644 --- a/types/pubnub/index.d.ts +++ b/types/pubnub/index.d.ts @@ -3,6 +3,7 @@ // Definitions by: bitbankinc , rollymaduk , vitosamson , FlorianDr // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped // @see https://www.pubnub.com/docs/web-javascript/api-reference-configuration +// TypeScript Version: 2.2 declare class Pubnub { constructor(config: Pubnub.PubnubConfig); From f675d110aae80c33bdc289624c85052a2a1dc858 Mon Sep 17 00:00:00 2001 From: Florian Dreschner Date: Mon, 26 Nov 2018 16:16:36 +0100 Subject: [PATCH 4/4] Change crypto payload to any --- types/pubnub/index.d.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/types/pubnub/index.d.ts b/types/pubnub/index.d.ts index 7e148bc4c4..257ca3cd44 100644 --- a/types/pubnub/index.d.ts +++ b/types/pubnub/index.d.ts @@ -94,13 +94,13 @@ declare class Pubnub { data: string, customCipherKey?: string, options?: Pubnub.CryptoParameters, - ): object | string | null; + ): any; decrypt( data: object, customCipherKey?: string, options?: Pubnub.CryptoParameters - ): object | string | null; + ): any; } declare namespace Pubnub {