Skip to content

Commit

Permalink
Clean up example code
Browse files Browse the repository at this point in the history
  • Loading branch information
mariano-perez-rodriguez committed Nov 4, 2024
1 parent 6320ea6 commit 12ba7b2
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,22 +53,28 @@ import {
verifiers,
} from '@opentimestamps/typescript-opentimestamps';

type VerificationResult = {
attestations: Record<number, string[]>;
errors: Record<string, Error[]>;
};

type AttestationEntry = [string, string[]];
type ErrorEntry = [string, Error[]];

const rawTimestamp: Uint8Array = Uint8Array.from(someTimestampBytes);
const timestamp: Timestamp = read(rawTimestamp);

verify(
timestamp,
verifiers,
).then(
({ attestations, errors }: { attestations: Record<number, string[]>; errors: Record<string, Error[]> }): 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));
});
},
);
Expand Down

0 comments on commit 12ba7b2

Please sign in to comment.