1
0
Эх сурвалжийг харах

Fix crypto import in passwords

painor 4 жил өмнө
parent
commit
2cbded9c3c

+ 3 - 2
gramjs/Password.ts

@@ -1,6 +1,8 @@
 import {Api} from "./tl";
 import {Api} from "./tl";
 import {bigIntMod, generateRandomBytes, modExp, readBigIntFromBuffer, readBufferFromBigInt, sha256} from "./Helpers";
 import {bigIntMod, generateRandomBytes, modExp, readBigIntFromBuffer, readBufferFromBigInt, sha256} from "./Helpers";
 import bigInt from 'big-integer';
 import bigInt from 'big-integer';
+import {isBrowser, isNode} from "browser-or-node";
+const crypto = require(isNode ? 'crypto' : './crypto/crypto');
 
 
 const SIZE_FOR_HASH = 256;
 const SIZE_FOR_HASH = 256;
 
 
@@ -154,8 +156,7 @@ function xor(a: Buffer, b: Buffer) {
 
 
 function pbkdf2sha512(password: Buffer, salt: Buffer, iterations: number) {
 function pbkdf2sha512(password: Buffer, salt: Buffer, iterations: number) {
 
 
-    // @ts-ignore should probably add pollifier
-    return crypto.pbkdf2(password, salt, iterations, 64, 'sha512')
+    return crypto.pbkdf2Sync(password, salt, iterations, 64, 'sha512');
 }
 }
 
 
 /**
 /**

+ 1 - 1
gramjs/crypto/crypto.ts

@@ -114,7 +114,7 @@ export class Hash {
     }
     }
 }
 }
 
 
-export async function pbkdf2(password:any, salt:any, iterations:any) {
+export async function pbkdf2Sync(password:any, salt:any, iterations:any) {
     const passwordKey = await crypto.subtle.importKey('raw', password,
     const passwordKey = await crypto.subtle.importKey('raw', password,
         {name: 'PBKDF2'}, false, ['deriveBits']);
         {name: 'PBKDF2'}, false, ['deriveBits']);
     return Buffer.from(await crypto.subtle.deriveBits({
     return Buffer.from(await crypto.subtle.deriveBits({

Файлын зөрүү хэтэрхий том тул дарагдсан байна
+ 11749 - 2
package-lock.json


+ 1 - 1
package.json

@@ -1,6 +1,6 @@
 {
 {
   "name": "telegram",
   "name": "telegram",
-  "version": "1.2.4",
+  "version": "1.2.5",
   "description": "NodeJS MTProto API Telegram client library,",
   "description": "NodeJS MTProto API Telegram client library,",
   "main": "index.js",
   "main": "index.js",
   "types": "index.d.ts",
   "types": "index.d.ts",

Энэ ялгаанд хэт олон файл өөрчлөгдсөн тул зарим файлыг харуулаагүй болно