From 12ba7b2c4f4cd1b8ce52d2c17be5efedca3bceab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mariano=20P=C3=A9rez=20Rodr=C3=ADguez?= Date: Mon, 4 Nov 2024 17:38:37 -0300 Subject: [PATCH] Clean up example code --- README.md | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index a7f826e..122023e 100644 --- a/README.md +++ b/README.md @@ -53,6 +53,14 @@ import { verifiers, } from '@opentimestamps/typescript-opentimestamps'; +type VerificationResult = { + attestations: Record; + errors: Record; +}; + +type AttestationEntry = [string, string[]]; +type ErrorEntry = [string, Error[]]; + const rawTimestamp: Uint8Array = Uint8Array.from(someTimestampBytes); const timestamp: Timestamp = read(rawTimestamp); @@ -60,15 +68,13 @@ verify( timestamp, verifiers, ).then( - ({ attestations, errors }: { attestations: Record; errors: Record }): void => { - Object.entries(attestations).forEach(([time, verifiers]: [string, string[]]): void => { - console.log(`Verifiers ${verifiers.join(', ')} attest to this timestamp as of ${time}`); - }); - Object.entries(errors).forEach(([verifier, errorList]: [string, Error[]]): void => { + ({ attestations, errors }: VerificationResult): void => { + Object.entries(attestations).forEach(([time, verifiers]: AttestationEntry): void => + console.log(`Verifiers ${verifiers.join(', ')} attest to this timestamp as of ${time}`) + ); + Object.entries(errors).forEach(([verifier, errorList]: ErrorEntry): void => { console.log(`${verifier} reported the following errors:`); - errorList.forEach((error: Error): void => { - console.log(error.message); - }); + errorList.forEach((error: Error): void => console.log(error.message)); }); }, );