From 8055d9b2b1c677481cc6088cf9bd5eee1eb0c428 Mon Sep 17 00:00:00 2001 From: "Marius N. Nicolaysen" Date: Mon, 2 Oct 2017 19:37:30 +0200 Subject: [PATCH] Update CryptoJS-definition to include lib.WordArray.create and allow the output as input to any Hash (#20072) * Update CryptoJS-definition to include lib.WordArray.create and allow the output as input to any Hash * fixed indentation --- types/crypto-js/crypto-js-tests.ts | 4 ++++ types/crypto-js/index.d.ts | 11 ++++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/types/crypto-js/crypto-js-tests.ts b/types/crypto-js/crypto-js-tests.ts index c36def9f90..9b5dd1be6f 100644 --- a/types/crypto-js/crypto-js-tests.ts +++ b/types/crypto-js/crypto-js-tests.ts @@ -11,6 +11,10 @@ wordArray = CryptoJS.SHA1('some message', 'some key', { any: true }); wordArray = CryptoJS.format.OpenSSL('some message'); wordArray = CryptoJS.format.OpenSSL('some message', 'some key'); +var FR = new FileReader(); +FR.onloadend = () => { + var hash = CryptoJS.SHA1(CryptoJS.lib.WordArray.create(FR.result)).toString() +} // Ciphers var encrypted: CryptoJS.WordArray; diff --git a/types/crypto-js/index.d.ts b/types/crypto-js/index.d.ts index 8e80c74a07..4e35dfbdfb 100644 --- a/types/crypto-js/index.d.ts +++ b/types/crypto-js/index.d.ts @@ -8,7 +8,7 @@ export as namespace CryptoJS; declare var CryptoJS: CryptoJS.Hashes; declare namespace CryptoJS { - type Hash = (message: string, key?: string, ...options: any[]) => WordArray; + type Hash = (message: string | LibWordArray, key?: string, ...options: any[]) => WordArray; interface Cipher { encrypt(message: string, secretPassphrase: string, option?: CipherOption): WordArray; decrypt(encryptedMessage: string | WordArray, secretPassphrase: string, option?: CipherOption): DecryptedMessage; @@ -25,6 +25,10 @@ declare namespace CryptoJS { process(messagePart: string): string; finalize(): string; } + interface LibWordArray { + sigBytes: number, + words: number[], + } export interface WordArray { iv: string; salt: string; @@ -97,6 +101,11 @@ declare namespace CryptoJS { Utf16LE: Encoder; Base64: Encoder; }; + lib: { + WordArray: { + create: (v: any) => LibWordArray; + }; + }; mode: { CBC: Mode; CFB: Mode;