Skip to content

Commit 8cd0d2e

Browse files
authored
fix: accept single prover publisher (#16651)
This PR lifts `mnemonicConfigSchema` to the `ethAccountSchema` union instead of `ethAccountsSchema` (plural) allowing the use of mnemonics for publishers and attesters as well. Also the type `prover.publisher` is now `EthAccounts` rather than `EthAccounts[]` allowing keystores to specify a single publisher or an array of publishers (previously only array and array of array were accepted)
2 parents a40bb6b + 262492e commit 8cd0d2e

File tree

6 files changed

+41
-29
lines changed

6 files changed

+41
-29
lines changed

yarn-project/node-keystore/examples/everything.json

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -69,19 +69,17 @@
6969
"mnemonic": "test test test test test test test test test test test junk",
7070
"addressCount": 1
7171
},
72-
[
73-
"0x5555555555555555555555555555555555555555555555555555555555555555",
74-
"0x6666666666666666666666666666666666666666",
75-
{
76-
"address": "0x7777777777777777777777777777777777777777",
77-
"remoteSignerUrl": "https://localhost:9300",
78-
"certPath": "/path/to/prover-cert.pem"
79-
},
80-
{
81-
"path": "/tmp/prover-publishers",
82-
"password": "prover-pass"
83-
}
84-
]
72+
"0x5555555555555555555555555555555555555555555555555555555555555555",
73+
"0x6666666666666666666666666666666666666666",
74+
{
75+
"address": "0x7777777777777777777777777777777777777777",
76+
"remoteSignerUrl": "https://localhost:9300",
77+
"certPath": "/path/to/prover-cert.pem"
78+
},
79+
{
80+
"path": "/tmp/prover-publishers",
81+
"password": "prover-pass"
82+
}
8583
]
8684
}
8785
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"schemaVersion": 1,
3+
"prover": {
4+
"id": "0x1234567890123456789012345678901234567890",
5+
"publisher": "0x1234567890123456789012345678901234567890123456789012345678901234"
6+
}
7+
}

yarn-project/node-keystore/src/keystore_manager.ts

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -218,19 +218,10 @@ export class KeystoreManager {
218218
};
219219
}
220220

221-
// Handle complex prover case with id and publishers
222-
const proverConfig = this.keystore.prover;
223-
const signers: EthSigner[] = [];
224-
225-
for (const publisherAccounts of proverConfig.publisher) {
226-
const publisherSigners = this.createSignersFromEthAccounts(publisherAccounts, this.keystore.remoteSigner);
227-
signers.push(...publisherSigners);
228-
}
221+
const id = EthAddress.fromString(this.keystore.prover.id);
222+
const signers = this.createSignersFromEthAccounts(this.keystore.prover.publisher, this.keystore.remoteSigner);
229223

230-
return {
231-
id: EthAddress.fromString(proverConfig.id),
232-
signers,
233-
};
224+
return { id, signers };
234225
}
235226

236227
/**

yarn-project/node-keystore/src/schemas.test.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,17 @@ describe('Keystore Schema Validation', () => {
5757
expect((parsed.prover as any).publisher).toHaveLength(2);
5858
});
5959

60+
it('should validate prover with single publisher example', () => {
61+
const keystore = loadExample('prover-with-single-publisher.json');
62+
expect(() => keystoreSchema.parse(keystore)).not.toThrow();
63+
64+
const parsed = keystoreSchema.parse(keystore);
65+
expect(parsed.schemaVersion).toBe(1);
66+
expect(typeof parsed.prover).toBe('object');
67+
expect((parsed.prover as any).id).toBe('0x1234567890123456789012345678901234567890');
68+
expect((parsed.prover as any).publisher).toBe('0x1234567890123456789012345678901234567890123456789012345678901234');
69+
});
70+
6071
it('should reject keystore with invalid schema version', () => {
6172
const keystore = {
6273
schemaVersion: 2, // Invalid

yarn-project/node-keystore/src/schemas.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,17 +51,22 @@ const mnemonicConfigSchema = z.object({
5151
});
5252

5353
// EthAccount schema
54-
const ethAccountSchema = z.union([ethPrivateKeySchema, remoteSignerAccountSchema, jsonKeyFileV3Schema]);
54+
const ethAccountSchema = z.union([
55+
ethPrivateKeySchema,
56+
remoteSignerAccountSchema,
57+
jsonKeyFileV3Schema,
58+
mnemonicConfigSchema,
59+
]);
5560

5661
// EthAccounts schema
57-
const ethAccountsSchema = z.union([ethAccountSchema, z.array(ethAccountSchema), mnemonicConfigSchema]);
62+
const ethAccountsSchema = z.union([ethAccountSchema, z.array(ethAccountSchema)]);
5863

5964
// Prover keystore schema
6065
const proverKeyStoreSchema = z.union([
6166
ethAccountSchema,
6267
z.object({
6368
id: ethAddressSchema,
64-
publisher: z.array(ethAccountsSchema),
69+
publisher: ethAccountsSchema,
6570
}),
6671
]);
6772

yarn-project/node-keystore/src/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ export type ProverKeyStore =
6868
/** Address that identifies the prover. This address will receive the rewards. */
6969
id: EthAddressHex;
7070
/** One or more EOAs used for sending proof L1 txs. */
71-
publisher: EthAccounts[];
71+
publisher: EthAccounts;
7272
}
7373
| EthAccount;
7474

0 commit comments

Comments
 (0)