UNPKG

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