This commit is contained in:
2023-08-05 16:03:31 +00:00
parent 92a67315f3
commit 743ab3e1aa
16 changed files with 138 additions and 49 deletions
+8 -9
View File
@@ -1,11 +1,10 @@
import type { RNG } from "./RNG";
import type { RNG } from "./RNG.js";
import { sha512 } from './sha2';
import { sha512 } from './sha2.js';
import { convertBytesLikeToUint8Array } from "./convertBytesLikeToUint8Array";
import type { BytesLike } from "./BytesLike";
import { unwrap } from "./unwrap";
import { delay } from "./delay";
import { convertBytesLikeToUint8Array } from "./convertBytesLikeToUint8Array.js";
import type { BytesLike } from "./BytesLike.js";
import { delay } from "./delay.js";
const maxRngSupportBit = 53;
const maxInt = 0x1f_ffff_ffff_ffff; // NOTE: b 0, 10000110011, 11...11
@@ -194,10 +193,10 @@ export class LiteHashDRBG implements RNG {
await delay(0);
const nextBlock = await waiter;
if (nextBlockWait instanceof Promise) {
if (nextBlockWait) {
nextBlockWait();
}
return unwrap(nextBlock);
return nextBlock!;
}
public async nextBits(bits: number, baseBytes?: number): Promise<Uint8Array> {
@@ -207,7 +206,7 @@ export class LiteHashDRBG implements RNG {
const bytes = (bits + 7) >> 3;
const headBits = bits & 0x7;
const result = this.nextBytes(bytes, baseBytes);
const result = await this.nextBytes(bytes, baseBytes);
if (headBits === 0) {
return result;
}