Skip to content

Commit

Permalink
[Fix] Add string support for verifying keys in the AleoKeyProvider
Browse files Browse the repository at this point in the history
  • Loading branch information
iamalwaysuncomfortable authored Nov 27, 2023
2 parents 8e8cce2 + 5961f25 commit 4fd700d
Show file tree
Hide file tree
Showing 7 changed files with 141 additions and 120 deletions.
2 changes: 1 addition & 1 deletion sdk/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@aleohq/sdk",
"version": "0.6.8",
"version": "0.6.9",
"description": "A Software Development Kit (SDK) for Zero-Knowledge Transactions",
"collaborators": [
"The Aleo Team <hello@aleo.org>"
Expand Down
14 changes: 13 additions & 1 deletion sdk/src/function-key-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -501,7 +501,19 @@ class AleoKeyProvider implements FunctionKeyProvider {
case CREDITS_PROGRAM_KEYS.unbond_public.verifier:
return CREDITS_PROGRAM_KEYS.unbond_public.verifyingKey();
default:
return <VerifyingKey>VerifyingKey.fromBytes(await this.fetchBytes(verifierUri));
try {
/// Try to fetch the verifying key from the network as a string
const response = await get(verifierUri);
const text = await response.text();
return <VerifyingKey>VerifyingKey.fromString(text);
} catch (e) {
/// If that fails, try to fetch the verifying key from the network as bytes
try {
return <VerifyingKey>VerifyingKey.fromBytes(await this.fetchBytes(verifierUri));
} catch (inner) {
return new Error("Invalid verifying key. Error: " + inner);
}
}
}
}

Expand Down
11 changes: 10 additions & 1 deletion sdk/tests/key-provider.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,16 @@ describe('KeyProvider', () => {
expect(redownloadedVerifyingKey).toBeInstanceOf(VerifyingKey);
}, 200000);

it("Should not fetch offline keys that haven't already been stored", async () => {
it('Should fetch verifying keys stored as text', async () => {
const provider = new AleoKeyProvider();
provider.useCache(true);
const [provingKey, verifyingKey] = <FunctionKeyPair> await provider.fetchKeys("https://pub-65a47b199b944d48a057ca6603a415a2.r2.dev/tree_mnist_2.prover.30e265c",
"https://pub-65a47b199b944d48a057ca6603a415a2.r2.dev/tree_mnist_2.verifier.17db860", "tree_mnist_2/main");
expect(provingKey).toBeInstanceOf(ProvingKey);
expect(verifyingKey).toBeInstanceOf(VerifyingKey);
}, 120000);

it.skip("Should not fetch offline keys that haven't already been stored", async () => {
// Download the credits.aleo function keys
const [bondPublicProver, bondPublicVerifier] = <FunctionKeyPair>await keyProvider.fetchKeys(CREDITS_PROGRAM_KEYS.bond_public.prover, CREDITS_PROGRAM_KEYS.bond_public.verifier, CREDITS_PROGRAM_KEYS.bond_public.locator);
const [claimUnbondPublicProver, claimUnbondVerifier] = <FunctionKeyPair>await keyProvider.fetchKeys(CREDITS_PROGRAM_KEYS.claim_unbond_public.prover, CREDITS_PROGRAM_KEYS.claim_unbond_public.verifier, CREDITS_PROGRAM_KEYS.claim_unbond_public.locator);
Expand Down
Loading

0 comments on commit 4fd700d

Please sign in to comment.