rotateSigningKey method
Signs with newSecret from now on, and with the current key as well
until overlap has passed (DV-WEBHOOK-007), so a customer can switch
keys without a window in which every delivery fails verification.
Implementation
Future<DVWebhookSubscription> rotateSigningKey(
String subscriptionId,
String newSecret, {
required Duration overlap,
}) async {
final DVWebhookSubscription current = await _require(subscriptionId);
final DateTime until = clock().add(overlap);
final DVWebhookSubscription rotated = current._copyWith(
previousSigningSecret: current.signingSecret,
signingSecret: newSecret,
overlapUntil: until,
);
await _DVWebhookTables.updateSubscription(await _db(), rotated);
DVObservability.log(
'Webhook signing key rotated for $subscriptionId; both signatures are '
'sent until ${until.toIso8601String()}.',
level: DVLogLevel.info,
code: 'DV-WEBHOOK-007',
context: <String, Object?>{
'subscription': subscriptionId,
'overlapUntil': until.toIso8601String(),
},
);
return rotated;
}