Skip to content

Commit e0fd2da

Browse files
committed
Verify reports
1 parent 4c56b41 commit e0fd2da

7 files changed

Lines changed: 1338 additions & 3 deletions

File tree

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
export type Environment = {
2+
chainSelector: bigint
3+
registryAddress: string
4+
}
5+
6+
export type Zone = {
7+
environment: Environment
8+
donID: number
9+
}
10+
11+
export function productionEnvironment(): Environment {
12+
return {
13+
chainSelector: 5009297550715157269n,
14+
registryAddress: '0x76c9cf548b4179F8901cda1f8623568b58215E62',
15+
}
16+
}
17+
18+
export function zoneFromEnvironment(environment: Environment, donID: number): Zone {
19+
return { environment, donID }
20+
}

packages/cre-sdk/src/sdk/errors.ts

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Mode, type SecretRequest } from '@cre/generated/sdk/v1alpha/sdk_pb'
1+
import type { SecretRequest } from '@cre/generated/sdk/v1alpha/sdk_pb'
22

33
export class DonModeError extends Error {
44
constructor() {
@@ -25,3 +25,55 @@ export class SecretsError extends Error {
2525
this.name = 'SecretsError'
2626
}
2727
}
28+
29+
export class NullReportError extends Error {
30+
constructor() {
31+
super('null report')
32+
this.name = 'NullReportError'
33+
}
34+
}
35+
36+
export class WrongSignatureCountError extends Error {
37+
constructor() {
38+
super('wrong number of signatures')
39+
this.name = 'WrongSignatureCountError'
40+
}
41+
}
42+
43+
export class ParseSignatureError extends Error {
44+
constructor() {
45+
super('failed to parse signature')
46+
this.name = 'ParseSignatureError'
47+
}
48+
}
49+
50+
export class RecoverSignerError extends Error {
51+
constructor() {
52+
super('failed to recover signer address from signature')
53+
this.name = 'RecoverSignerError'
54+
}
55+
}
56+
57+
export class UnknownSignerError extends Error {
58+
constructor() {
59+
super('invalid signature')
60+
this.name = 'UnknownSignerError'
61+
}
62+
}
63+
64+
export class DuplicateSignerError extends Error {
65+
constructor() {
66+
super('duplicate signer')
67+
this.name = 'DuplicateSignerError'
68+
}
69+
}
70+
71+
export class RawReportTooShortError extends Error {
72+
constructor(
73+
public readonly need: number,
74+
public readonly got: number,
75+
) {
76+
super(`raw report too short to contain metadata header: need ${need} bytes, got ${got}`)
77+
this.name = 'RawReportTooShortError'
78+
}
79+
}

packages/cre-sdk/src/sdk/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
export * from './cre'
2+
export * from './don-info'
3+
export * from './errors'
24
export * from './report'
35
export type * from './runtime'
46
export * from './runtime'
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import type { Address } from 'viem'
2+
3+
// Do not re-export in index.ts to avoid exposing it to the public API.
4+
// This is public to allow the cache to be cleared in the tests.
5+
6+
export type DonInfo = {
7+
f: number
8+
signers: Map<Address, number>
9+
}
10+
11+
// Do not re-export in index.ts to avoid exposing it to the public API.
12+
// donInfoCache exists outside Report to allow testing to clear the cache.
13+
export var donInfoCache = new Map<string, DonInfo>()

packages/cre-sdk/src/sdk/report.test.ts

Lines changed: 600 additions & 0 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)