1
- import { bytesFromArrayBuffer , bytesFromHex } from '../helpers/bytes' ;
1
+ import { bytesFromArrayBuffer , bytesFromHex , bytesToHex } from '../helpers/bytes' ;
2
2
import CryptoWorker from '../lib/crypto/cryptoworker' ;
3
3
4
4
test ( 'factorize' , ( ) => {
@@ -11,7 +11,8 @@ test('factorize', () => {
11
11
} ) ;
12
12
13
13
test ( 'sha1' , ( ) => {
14
- CryptoWorker . sha1Hash ( bytesFromHex ( 'ec5ac983081eeb1da706316227000000044af6cfb1000000046995dd57000000d55105998729349339eb322d86ec13bc0884f6ba0449d8ecbad0ef574837422579a11a88591796cdcc4c05690da0652462489286450179a635924bcc0ab83848' ) )
14
+ const bytes = new Uint8Array ( bytesFromHex ( 'ec5ac983081eeb1da706316227000000044af6cfb1000000046995dd57000000d55105998729349339eb322d86ec13bc0884f6ba0449d8ecbad0ef574837422579a11a88591796cdcc4c05690da0652462489286450179a635924bcc0ab83848' ) ) ;
15
+ CryptoWorker . sha1Hash ( bytes )
15
16
. then ( buffer => {
16
17
//console.log(bytesFromArrayBuffer(buffer));
17
18
@@ -26,9 +27,34 @@ test('sha1', () => {
26
27
} ) ;
27
28
28
29
test ( 'sha256' , ( ) => {
29
- CryptoWorker . sha256Hash ( new Uint8Array ( [ 112 , 20 , 211 , 20 , 106 , 249 , 203 , 252 , 39 , 107 , 106 , 194 , 63 , 60 , 13 , 130 , 51 , 78 , 107 , 6 , 110 , 156 , 214 , 65 , 205 , 10 , 30 , 150 , 79 , 10 , 145 , 194 , 232 , 240 , 127 , 55 , 146 , 103 , 248 , 227 , 160 , 172 , 30 , 153 , 122 , 189 , 110 , 162 , 33 , 86 , 174 , 117 ] ) ) . then ( bytes => {
30
+ CryptoWorker . sha256Hash ( new Uint8Array ( [ 112 , 20 , 211 , 20 , 106 , 249 , 203 , 252 , 39 , 107 , 106 , 194 , 63 , 60 , 13 , 130 , 51 , 78 , 107 , 6 , 110 , 156 , 214 , 65 , 205 , 10 , 30 , 150 , 79 , 10 , 145 , 194 , 232 , 240 , 127 , 55 , 146 , 103 , 248 , 227 , 160 , 172 , 30 , 153 , 122 , 189 , 110 , 162 , 33 , 86 , 174 , 117 ] ) )
31
+ . then ( bytes => {
30
32
expect ( bytes ) . toEqual ( new Uint8Array ( [ 158 , 59 , 39 , 247 , 130 , 244 , 235 , 160 , 16 , 249 , 34 , 114 , 67 , 171 , 203 , 208 , 187 , 72 , 217 , 106 , 253 , 62 , 195 , 242 , 52 , 118 , 99 , 72 , 221 , 29 , 203 , 95 ] ) ) ;
31
33
} ) ;
34
+
35
+ const client_salt = new Uint8Array ( [ 58 , 45 , 208 , 42 , 210 , 96 , 229 , 224 , 220 , 241 , 61 , 180 , 91 , 93 , 132 , 127 , 29 , 81 , 244 , 35 , 114 , 240 , 134 , 109 , 60 , 129 , 157 , 117 , 214 , 173 , 161 , 93 , 61 , 215 , 199 , 129 , 184 , 20 , 247 , 52 ] ) ;
36
+
37
+ // ! ! ! ! ! ! ! ! ! ! THIS IS WRONG WAY TO ENCODE AND CONCAT THEM AFTER ! ! ! ! ! ! ! ! ! ! ! ! !
38
+ /* let clientSaltString = '';
39
+ for(let i = 0; i < client_salt.length; i++) clientSaltString += String.fromCharCode(client_salt[i]); */
40
+
41
+ const payload = [
42
+ [ '£' , 'b4fe151e413445357b1c0935e7cf04a429492ebd23dc62bfadb2f898c431c1fd' ] ,
43
+ [ 'haha' , '090b235e9eb8f197f2dd927937222c570396d971222d9009a9189e2b6cc0a2c1' ] ,
44
+ [ '😂😘❤️😍😊😁👁👍🏿' , 'f3cd34d2345934e10d95d01c7eae9040a6f3c4e20a02a392078b762d876ece8a' ] ,
45
+ [ '$' , '09fc96082d34c2dfc1295d92073b5ea1dc8ef8da95f14dfded011ffb96d3e54b' ] ,
46
+ //[clientSaltString + '😂😘❤️😍😊😁👁👍🏿' + clientSaltString, 'c2ac294f00e8ac4db6b94099f2014d763315cb2127b1e1ea178cfc3f302680d0'],
47
+ [ new Uint8Array ( Array . from ( client_salt ) . concat ( Array . from ( new TextEncoder ( ) . encode ( '😂😘❤️😍😊😁👁👍🏿' ) ) , Array . from ( client_salt ) ) ) , 'f11950fb40baf391b06a57e7490c8ad4d99ec0c1516c2bc7e529895296616ea7' ]
48
+ ] ;
49
+
50
+ payload . forEach ( pair => {
51
+ //const uint8 = new TextEncoder().encode(pair[0]);
52
+ //CryptoWorker.sha256Hash(new Uint8Array(pair[0].split('').map(c => c.charCodeAt(0)))).then(bytes => {
53
+ CryptoWorker . sha256Hash ( pair [ 0 ] ) . then ( bytes => {
54
+ const hex = bytesToHex ( bytes ) ;
55
+ expect ( hex ) . toEqual ( pair [ 1 ] ) ;
56
+ } ) ;
57
+ } ) ;
32
58
} ) ;
33
59
34
60
test ( 'pbkdf2' , ( ) => {
0 commit comments