mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-10-05 15:27:05 +00:00
Merge pull request #30812 from FlorianDr/master
[pubnub] Add encrypt and decrypt methods
This commit is contained in:
Vendored
+22
-1
@@ -1,8 +1,9 @@
|
||||
// Type definitions for pubnub 4.0
|
||||
// Project: https://github.com/pubnub/javascript
|
||||
// Definitions by: bitbankinc <https://github.com/bitbankinc>, rollymaduk <https://github.com/rollymaduk>, vitosamson <https://github.com/vitosamson>
|
||||
// Definitions by: bitbankinc <https://github.com/bitbankinc>, rollymaduk <https://github.com/rollymaduk>, vitosamson <https://github.com/vitosamson>, FlorianDr <https://github.com/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);
|
||||
@@ -88,6 +89,18 @@ declare class Pubnub {
|
||||
setState(
|
||||
params: Pubnub.SetStateParameters
|
||||
): Promise<Pubnub.SetStateResponse>;
|
||||
|
||||
encrypt(
|
||||
data: string,
|
||||
customCipherKey?: string,
|
||||
options?: Pubnub.CryptoParameters,
|
||||
): any;
|
||||
|
||||
decrypt(
|
||||
data: object,
|
||||
customCipherKey?: string,
|
||||
options?: Pubnub.CryptoParameters
|
||||
): any;
|
||||
}
|
||||
|
||||
declare namespace Pubnub {
|
||||
@@ -296,6 +309,14 @@ declare namespace Pubnub {
|
||||
};
|
||||
}
|
||||
|
||||
// encrypt & decrypt
|
||||
interface CryptoParameters {
|
||||
encryptKey?: boolean;
|
||||
keyEncoding?: string;
|
||||
keyLength?: number;
|
||||
mode?: string;
|
||||
}
|
||||
|
||||
interface Categories {
|
||||
PNNetworkUpCategory: string;
|
||||
PNNetworkDownCategory: string;
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user