1 | /// <reference types="node" />
|
2 | import objectSorter from './objectSorter';
|
3 | import { BinaryToTextEncoding } from 'crypto';
|
4 | declare namespace hasher {
|
5 | /**
|
6 | * Object hasher options
|
7 | */
|
8 | interface HasherOptions extends objectSorter.SorterOptions {
|
9 | /**
|
10 | * Hash algorithm to use
|
11 | * @default 'sha256'
|
12 | */
|
13 | alg?: string;
|
14 | /**
|
15 | * String encoding for hash
|
16 | * @default 'hex'
|
17 | */
|
18 | enc?: BinaryToTextEncoding;
|
19 | }
|
20 | /**
|
21 | * If object implements Hashable interface then value from toHash
|
22 | * will be used for hash function. It means that the different objects
|
23 | * with the function toHash that return the same value will have the same hash
|
24 | */
|
25 | interface Hashable {
|
26 | toHashableString: () => string;
|
27 | }
|
28 | interface Hasher {
|
29 | /**
|
30 | * Create hash of an object
|
31 | * @param object source object
|
32 | * @returns hash string of an object
|
33 | */
|
34 | hash(object: Hashable | any, opts?: hasher.HasherOptions): string;
|
35 | /**
|
36 | * Create sorted string from an object
|
37 | * @param object source object
|
38 | * @returns sorted string from an object
|
39 | */
|
40 | sort(object: any): string;
|
41 | /**
|
42 | * Create sorted string from an object
|
43 | * @param object source object
|
44 | * @returns sorted string from an object
|
45 | * @alias sort
|
46 | */
|
47 | sortObject(object: any): string;
|
48 | }
|
49 | }
|
50 | /**
|
51 | * Hasher constructor
|
52 | * @param options hasher options
|
53 | * @return hasher instance
|
54 | */
|
55 | declare function hasher(options?: hasher.HasherOptions): hasher.Hasher;
|
56 | export = hasher;
|
57 | //# sourceMappingURL=hasher.d.ts.map |
\ | No newline at end of file |