@@ -49,12 +49,18 @@ export function aoutput(out: any, instance: any): void {
4949}
5050
5151export type IHash = {
52- ( data : string | Uint8Array ) : Uint8Array ;
52+ ( data : Uint8Array ) : Bytes ;
5353 blockLen : number ;
5454 outputLen : number ;
5555 create : any ;
5656} ;
5757
58+ /**
59+ * Unified, backwards-compatible ArrayBuffer-based Uint8Array.
60+ * In ts5.5: `Uint8Array`; in ts5.9: `Uint8Array<ArrayBuffer>`.
61+ */
62+ export type Bytes = ReturnType < typeof Uint8Array . from > ;
63+
5864/** Generic type encompassing 8/16/32-byte arrays - but not 64-byte. */
5965// prettier-ignore
6066export type TypedArray = Int8Array | Uint8ClampedArray | Uint8Array |
@@ -248,10 +254,10 @@ export function equalBytes(a: Uint8Array, b: Uint8Array): boolean {
248254export interface IHash2 {
249255 blockLen : number ; // Bytes per block
250256 outputLen : number ; // Bytes in output
251- update ( buf : string | Uint8Array ) : this;
257+ update ( buf : Uint8Array ) : this;
252258 // Writes digest into buf
253259 digestInto ( buf : Uint8Array ) : void ;
254- digest ( ) : Uint8Array ;
260+ digest ( ) : Bytes ;
255261 /**
256262 * Resets internal state. Makes Hash instance unusable.
257263 * Reset is impossible for keyed hashes if key is consumed into state. If digest is not consumed
@@ -265,20 +271,20 @@ export interface IHash2 {
265271
266272/** Sync cipher: takes byte array and returns byte array. */
267273export type Cipher = {
268- encrypt ( plaintext : Uint8Array ) : Uint8Array ;
269- decrypt ( ciphertext : Uint8Array ) : Uint8Array ;
274+ encrypt ( plaintext : Uint8Array ) : Bytes ;
275+ decrypt ( ciphertext : Uint8Array ) : Bytes ;
270276} ;
271277
272278/** Async cipher e.g. from built-in WebCrypto. */
273279export type AsyncCipher = {
274- encrypt ( plaintext : Uint8Array ) : Promise < Uint8Array > ;
275- decrypt ( ciphertext : Uint8Array ) : Promise < Uint8Array > ;
280+ encrypt ( plaintext : Uint8Array ) : Promise < Bytes > ;
281+ decrypt ( ciphertext : Uint8Array ) : Promise < Bytes > ;
276282} ;
277283
278284/** Cipher with `output` argument which can optimize by doing 1 less allocation. */
279285export type CipherWithOutput = Cipher & {
280- encrypt ( plaintext : Uint8Array , output ?: Uint8Array ) : Uint8Array ;
281- decrypt ( ciphertext : Uint8Array , output ?: Uint8Array ) : Uint8Array ;
286+ encrypt ( plaintext : Uint8Array , output ?: Uint8Array ) : Bytes ;
287+ decrypt ( ciphertext : Uint8Array , output ?: Uint8Array ) : Bytes ;
282288} ;
283289
284290/**
@@ -375,9 +381,9 @@ export type XorStream = (
375381 */
376382export function getOutput (
377383 expectedLength : number ,
378- out ?: Uint8Array ,
384+ out ?: Bytes ,
379385 onlyAligned = true
380- ) : Uint8Array {
386+ ) : Bytes {
381387 if ( out === undefined ) return new Uint8Array ( expectedLength ) ;
382388 if ( out . length !== expectedLength )
383389 throw new Error (
@@ -422,7 +428,7 @@ export function randomBytes(bytesLength = 32): Uint8Array {
422428 */
423429export interface PRG {
424430 addEntropy ( seed : Uint8Array ) : void ;
425- randomBytes ( length : number ) : Uint8Array ;
431+ randomBytes ( length : number ) : Bytes ;
426432 clean ( ) : void ;
427433}
428434
0 commit comments