1 |
|
2 | import { Hash as CryptoHash } from "crypto";
|
3 | import { Readable, Transform } from "stream";
|
4 |
|
5 | export interface HashLike {
|
6 | algorithm: string;
|
7 | digest: string;
|
8 | options?: string[] | undefined;
|
9 | }
|
10 |
|
11 | export interface IntegrityLike {
|
12 | [algorithm: string]: HashLike[];
|
13 | }
|
14 |
|
15 | export type IntegrityMap = Integrity & IntegrityLike;
|
16 |
|
17 | export class Hash implements HashLike {
|
18 | constructor(hash: string, opts?: { strict?: boolean | undefined });
|
19 |
|
20 | source: string;
|
21 | algorithm: string;
|
22 | digest: string;
|
23 | options?: string[] | undefined;
|
24 | isHash: boolean;
|
25 |
|
26 | hexDigest(): string;
|
27 |
|
28 | toJSON(): string;
|
29 |
|
30 | toString(opts?: { strict?: boolean | undefined }): string;
|
31 | }
|
32 |
|
33 | export class Integrity {
|
34 | isIntegrity: boolean;
|
35 |
|
36 | toJSON(): string;
|
37 |
|
38 | toString(opts?: { strict?: boolean | undefined; sep?: string | undefined }): string;
|
39 |
|
40 | concat(
|
41 | integrity: string | IntegrityLike | HashLike,
|
42 | opts?: { strict?: boolean | undefined },
|
43 | ): IntegrityMap;
|
44 |
|
45 | hexDigest(): string;
|
46 |
|
47 | match(
|
48 | integrity: string | IntegrityLike | HashLike,
|
49 | opts?: {
|
50 | strict?: boolean | undefined;
|
51 | pickAlgorithm?: ((algo1: string, algo2: string) => string) | undefined;
|
52 | },
|
53 | ): Hash | false;
|
54 |
|
55 | /**
|
56 | * Safely merges another IntegrityLike or integrity string into an Integrity object.
|
57 | */
|
58 | merge(
|
59 | otherIntegrity?: string | IntegrityLike | HashLike,
|
60 | opts?: {
|
61 | single?: boolean | undefined;
|
62 | strict?: boolean | undefined;
|
63 | },
|
64 | ): void;
|
65 |
|
66 | pickAlgorithm(opts?: {
|
67 | pickAlgorithm?: ((algo1: string, algo2: string) => string) | undefined;
|
68 | }): string;
|
69 | }
|
70 |
|
71 | export function parse(
|
72 | sri: string | IntegrityLike | HashLike,
|
73 | opts?: { single?: false | undefined; strict?: boolean | undefined },
|
74 | ): IntegrityMap;
|
75 | export function parse(
|
76 | sri: string | IntegrityLike | HashLike,
|
77 | opts?: { single: true; strict?: boolean | undefined },
|
78 | ): Hash;
|
79 | export function parse(
|
80 | sri: string | IntegrityLike | HashLike,
|
81 | opts?: { single?: boolean | undefined; strict?: boolean | undefined },
|
82 | ): IntegrityMap | Hash;
|
83 |
|
84 | export function stringify(
|
85 | obj: string | IntegrityLike | HashLike,
|
86 | opts?: { strict?: boolean | undefined; sep?: string | undefined },
|
87 | ): string;
|
88 |
|
89 | export function fromHex(
|
90 | hexDigest: string,
|
91 | algorithm: string,
|
92 | opts?: {
|
93 | single?: false | undefined;
|
94 | strict?: boolean | undefined;
|
95 | options?: readonly string[] | undefined;
|
96 | },
|
97 | ): IntegrityMap;
|
98 | export function fromHex(
|
99 | hexDigest: string,
|
100 | algorithm: string,
|
101 | opts?: { single: true; strict?: boolean | undefined; options?: readonly string[] | undefined },
|
102 | ): Hash;
|
103 | export function fromHex(
|
104 | hexDigest: string,
|
105 | algorithm: string,
|
106 | opts?: {
|
107 | single?: boolean | undefined;
|
108 | strict?: boolean | undefined;
|
109 | options?: readonly string[] | undefined;
|
110 | },
|
111 | ): IntegrityMap | Hash;
|
112 |
|
113 | export function fromData(
|
114 | data: string | Buffer | NodeJS.TypedArray | DataView,
|
115 | opts?: {
|
116 | strict?: boolean | undefined;
|
117 | options?: readonly string[] | undefined;
|
118 | algorithms?: readonly string[] | undefined;
|
119 | },
|
120 | ): IntegrityMap;
|
121 |
|
122 | export function fromStream(
|
123 | stream: Readable,
|
124 | opts?: {
|
125 | strict?: boolean | undefined;
|
126 | options?: readonly string[] | undefined;
|
127 | algorithms?: readonly string[] | undefined;
|
128 | },
|
129 | ): Promise<IntegrityMap>;
|
130 | export function fromStream(
|
131 | stream: Readable,
|
132 | opts?: {
|
133 | strict?: boolean | undefined;
|
134 | options?: readonly string[] | undefined;
|
135 | algorithms?: readonly string[] | undefined;
|
136 | Promise?: PromiseConstructorLike | undefined;
|
137 | },
|
138 | ): PromiseLike<IntegrityMap>;
|
139 |
|
140 | export function checkData(
|
141 | data: string | Buffer | NodeJS.TypedArray,
|
142 | sri: string | IntegrityLike | HashLike,
|
143 | opts?: {
|
144 | strict?: boolean | undefined;
|
145 | error?: boolean | undefined;
|
146 | size?: number | undefined;
|
147 | pickAlgorithm?: ((algo1: string, algo2: string) => string) | undefined;
|
148 | },
|
149 | ): Hash | false;
|
150 |
|
151 | export function checkStream(
|
152 | stream: Readable,
|
153 | sri: string | IntegrityLike | HashLike,
|
154 | opts?: {
|
155 | strict?: boolean | undefined;
|
156 | options?: readonly string[] | undefined;
|
157 | size?: number | undefined;
|
158 | pickAlgorithm?: ((algo1: string, algo2: string) => string) | undefined;
|
159 | },
|
160 | ): Promise<Hash>;
|
161 | export function checkStream(
|
162 | stream: Readable,
|
163 | sri: string | IntegrityLike | HashLike,
|
164 | opts?: {
|
165 | strict?: boolean | undefined;
|
166 | options?: readonly string[] | undefined;
|
167 | size?: number | undefined;
|
168 | pickAlgorithm?: ((algo1: string, algo2: string) => string) | undefined;
|
169 | Promise?: PromiseConstructorLike | undefined;
|
170 | },
|
171 | ): PromiseLike<Hash>;
|
172 |
|
173 | export function integrityStream(opts?: {
|
174 | single?: boolean | undefined;
|
175 | strict?: boolean | undefined;
|
176 | options?: readonly string[] | undefined;
|
177 | algorithms?: readonly string[] | undefined;
|
178 | integrity?: string | IntegrityLike | HashLike | undefined;
|
179 | size?: number | undefined;
|
180 | pickAlgorithm?: ((algo1: string, algo2: string) => string) | undefined;
|
181 | }): Transform;
|
182 |
|
183 | export function create(opts?: {
|
184 | strict?: boolean | undefined;
|
185 | options?: readonly string[] | undefined;
|
186 | algorithms?: readonly string[] | undefined;
|
187 | }): CryptoHash;
|
188 |
|
\ | No newline at end of file |