-
Notifications
You must be signed in to change notification settings - Fork 774
/
Copy pathWebhooks.d.ts
153 lines (134 loc) · 4.04 KB
/
Webhooks.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
/// <reference types="node" />
declare module 'stripe' {
namespace Stripe {
export class Webhooks {
/**
* Constructs and verifies the signature of an Event from the provided details.
*
* @throws Stripe.errors.StripeSignatureVerificationError
*/
constructEvent(
/**
* Raw text body payload received from Stripe.
*/
payload: string | Buffer,
/**
* Value of the `stripe-signature` header from Stripe.
* Typically a string.
*
* Note that this is typed to accept an array of strings
* so that it works seamlessly with express's types,
* but will throw if an array is passed in practice
* since express should never return this header as an array,
* only a string.
*/
header: string | Buffer | Array<string>,
/**
* Your Webhook Signing Secret for this endpoint (e.g., 'whsec_...').
* You can get this [in your dashboard](https://dashboard.stripe.com/webhooks).
*/
secret: string,
/**
* Seconds of tolerance on timestamps.
*/
tolerance?: number,
/**
* Optional CryptoProvider to use for computing HMAC signatures.
*/
cryptoProvider?: CryptoProvider
): Stripe.Event;
/**
* Asynchronously constructs and verifies the signature of an Event from
* the provided details.
*
* @throws Stripe.errors.StripeSignatureVerificationError
*/
constructEventAsync(
/**
* Raw text body payload received from Stripe.
*/
payload: string | Buffer,
/**
* Value of the `stripe-signature` header from Stripe.
* Typically a string.
*
* Note that this is typed to accept an array of strings
* so that it works seamlessly with express's types,
* but will throw if an array is passed in practice
* since express should never return this header as an array,
* only a string.
*/
header: string | Buffer | Array<string>,
/**
* Your Webhook Signing Secret for this endpoint (e.g., 'whsec_...').
* You can get this [in your dashboard](https://dashboard.stripe.com/webhooks).
*/
secret: string,
/**
* Seconds of tolerance on timestamps.
*/
tolerance?: number,
/**
* Optional CryptoProvider to use for computing HMAC signatures.
*/
cryptoProvider?: CryptoProvider
): Promise<Stripe.Event>;
/**
* Generates a header to be used for webhook mocking
*/
generateTestHeaderString(opts: {
/**
* JSON stringified payload object, containing the 'id' and 'object' parameters.
*/
payload: string;
/**
* Timestamp of the header. Defaults to Date.now().
*/
timestamp?: number;
/**
* Stripe webhook secret, e.g., 'whsec_...'.
*/
secret: string;
/**
* Version of API to hit. Defaults to 'v1'.
*/
scheme?: string;
/**
* Computed webhook signature.
*/
signature?: string;
/**
* Optional CryptoProvider to use for computing HMAC signatures, if no
* signature is given.
*/
cryptoProvider?: CryptoProvider;
}): string;
signature: Signature;
}
export class Signature {
EXPECTED_SCHEME: 'v1';
verifyHeader(
payload: string,
header: string,
secret: string,
tolerance?: number,
cryptoProvider?: CryptoProvider
): boolean;
verifyHeaderAsync(
payload: string,
header: string,
secret: string,
tolerance?: number,
cryptoProvider?: CryptoProvider
): Promise<boolean>;
parseHeader(
header: string,
scheme?: string
): {
t: number;
v0: string;
v1: string;
};
}
}
}