Skip to content

Commit

Permalink
Lint + format
Browse files Browse the repository at this point in the history
  • Loading branch information
ThetaSinner committed Mar 27, 2024
1 parent 5f9f481 commit 4d1542b
Show file tree
Hide file tree
Showing 6 changed files with 122 additions and 57 deletions.
2 changes: 1 addition & 1 deletion dnas/checked/zomes/integrity/fetch/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use hdi::prelude::*;

pub mod prelude {
pub use fetch_types::*;
pub use crate::LinkTypes;
pub use crate::{EntryTypes, UnitEntryTypes};
pub use fetch_types::*;
}

#[derive(Serialize, Deserialize)]
Expand Down
2 changes: 1 addition & 1 deletion dnas/checked/zomes/integrity/signing_keys/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ use hdi::prelude::*;
use signing_keys_types::*;

pub mod prelude {
pub use signing_keys_types::*;
pub use crate::key_collection::*;
pub use crate::key_util::*;
pub use crate::verification_key_dist::*;
pub use crate::LinkTypes;
pub use crate::{EntryTypes, UnitEntryTypes};
pub use signing_keys_types::*;
}

#[derive(Serialize, Deserialize)]
Expand Down
94 changes: 56 additions & 38 deletions tests/src/checked/signing_keys/common.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { CallableCell } from "@holochain/tryorama";
import {ActionHash, AgentPubKey, Record} from "@holochain/client";
import { ActionHash, AgentPubKey, Record } from "@holochain/client";
import { decode } from "@msgpack/msgpack";

const utf8Encode = new TextEncoder();
Expand All @@ -16,8 +16,8 @@ export interface VerificationKeyDistMarkCompromised {
}

export type VfKeyDistMark =
| { Rotated: VerificationKeyDistMarkRotated }
| { Compromised: VerificationKeyDistMarkCompromised };
| { Rotated: VerificationKeyDistMarkRotated }
| { Compromised: VerificationKeyDistMarkCompromised };

export interface VerificationKeyDist {
verification_key: string;
Expand Down Expand Up @@ -121,74 +121,92 @@ export async function createKeyCollection(
}

export const getMyKeyCollections = async (
cell: CallableCell,
cell: CallableCell,
): Promise<KeyCollectionWithKeys[]> => {
return cell.callZome({
zome_name: "signing_keys",
fn_name: "get_my_key_collections",
payload: null,
});
}
};

export const linkVerificationKeyToKeyCollection = async (cell: CallableCell, verification_key_dist_address: ActionHash, key_collection_name: string): Promise<ActionHash> => {
export const linkVerificationKeyToKeyCollection = async (
cell: CallableCell,
verification_key_dist_address: ActionHash,
key_collection_name: string,
): Promise<ActionHash> => {
return cell.callZome({
zome_name: "signing_keys",
fn_name: "link_verification_key_to_key_collection",
payload: {
verification_key_dist_address,
key_collection_name,
},
})
}
});
};

export const unlinkVerificationKeyToKeyCollection = async (cell: CallableCell, verification_key_dist_address: ActionHash, key_collection_name: string): Promise<ActionHash> => {
export const unlinkVerificationKeyToKeyCollection = async (
cell: CallableCell,
verification_key_dist_address: ActionHash,
key_collection_name: string,
): Promise<ActionHash> => {
return cell.callZome({
zome_name: "signing_keys",
fn_name: "unlink_verification_key_from_key_collection",
payload: {
verification_key_dist_address,
key_collection_name,
},
})
}
});
};

export const getMyVerificationKeyDistributions = async (cell: CallableCell): Promise<VerificationKeyResponse[]> => {
export const getMyVerificationKeyDistributions = async (
cell: CallableCell,
): Promise<VerificationKeyResponse[]> => {
return cell.callZome({
zome_name: "signing_keys",
fn_name: "get_my_verification_key_distributions",
payload: null,
});
}
zome_name: "signing_keys",
fn_name: "get_my_verification_key_distributions",
payload: null,
});
};

export const searchKeys = async (cell: CallableCell, agent_pub_key: AgentPubKey): Promise<VerificationKeyResponse[]> => {
export const searchKeys = async (
cell: CallableCell,
agent_pub_key: AgentPubKey,
): Promise<VerificationKeyResponse[]> => {
return cell.callZome({
zome_name: "signing_keys",
fn_name: "search_keys",
payload: {
agent_pub_key,
},
});
}
zome_name: "signing_keys",
fn_name: "search_keys",
payload: {
agent_pub_key,
},
});
};

export const searchKeysLocal = async (cell: CallableCell, agent_pub_key: AgentPubKey): Promise<VerificationKeyResponse[]> => {
export const searchKeysLocal = async (
cell: CallableCell,
agent_pub_key: AgentPubKey,
): Promise<VerificationKeyResponse[]> => {
return cell.callZome({
zome_name: "signing_keys",
fn_name: "search_keys_local",
payload: {
agent_pub_key,
},
});
}
};

export const markVerificationKeyRotated = async (cell: CallableCell, verification_key_dist_address: ActionHash, mark: VfKeyDistMark): Promise<ActionHash> => {
export const markVerificationKeyRotated = async (
cell: CallableCell,
verification_key_dist_address: ActionHash,
mark: VfKeyDistMark,
): Promise<ActionHash> => {
return cell.callZome({
zome_name: "signing_keys",
fn_name: "mark_verification_key_dist",
payload: {
verification_key_dist_address,
mark,
},
})
}


zome_name: "signing_keys",
fn_name: "mark_verification_key_dist",
payload: {
verification_key_dist_address,
mark,
},
});
};
33 changes: 26 additions & 7 deletions tests/src/checked/signing_keys/key-collection.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { runScenario, dhtSync } from "@holochain/tryorama";
import { Record } from "@holochain/client";

import {
KeyCollectionWithKeys,
createKeyCollection,
distributeVerificationKey,
sampleMiniSignKey,
Expand Down Expand Up @@ -103,9 +102,13 @@ test("Link verification key distribution to collection", async () => {
assert.ok(key_collection_record);

// Bob links Alice's verification key to the key collection
await linkVerificationKeyToKeyCollection(bob.cells[0], vf_key_dist_address, "a test");
await linkVerificationKeyToKeyCollection(
bob.cells[0],
vf_key_dist_address,
"a test",
);

const key_collections= await getMyKeyCollections(bob.cells[0]);
const key_collections = await getMyKeyCollections(bob.cells[0]);

assert.equal(key_collections.length, 1);
assert.equal(key_collections[0].verification_keys.length, 1);
Expand Down Expand Up @@ -141,10 +144,18 @@ test("Unlink verification key from collection", async () => {
assert.ok(key_collection_record);

// Bob links Alice's verification key to the key collection
await linkVerificationKeyToKeyCollection(bob.cells[0], vf_key_dist_address, "a test");
await linkVerificationKeyToKeyCollection(
bob.cells[0],
vf_key_dist_address,
"a test",
);

// Bob unlinks Alice's verification key from the key collection
await unlinkVerificationKeyToKeyCollection(bob.cells[0], vf_key_dist_address, "a test");
await unlinkVerificationKeyToKeyCollection(
bob.cells[0],
vf_key_dist_address,
"a test",
);

// Now getting key collections should return a single, empty key collection
const key_collections = await getMyKeyCollections(bob.cells[0]);
Expand Down Expand Up @@ -190,13 +201,21 @@ test("Remote validation", async () => {
verification_key_record.signed_action.hashed.hash;

// Bob links Alice's verification key to the key collection
await linkVerificationKeyToKeyCollection(bob.cells[0], vf_key_dist_address, "a test 1");
await linkVerificationKeyToKeyCollection(
bob.cells[0],
vf_key_dist_address,
"a test 1",
);

// The DHT shouldn't sync if the remote validation fails
await dhtSync([alice, bob], alice.cells[0].cell_id[0]);

// Bob unlinks Alice's verification key from the key collection
await unlinkVerificationKeyToKeyCollection(bob.cells[0], vf_key_dist_address, "a test 1");
await unlinkVerificationKeyToKeyCollection(
bob.cells[0],
vf_key_dist_address,
"a test 1",
);

// The DHT shouldn't sync if the remote validation fails
await dhtSync([alice, bob], alice.cells[0].cell_id[0]);
Expand Down
25 changes: 20 additions & 5 deletions tests/src/checked/signing_keys/reference-count.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { runScenario, dhtSync } from "@holochain/tryorama";
import { Record } from "@holochain/client";

import {
KeyCollectionWithKeys,
createKeyCollection,
distributeVerificationKey,
sampleMiniSignKey,
Expand Down Expand Up @@ -45,7 +44,11 @@ test("Get my keys for a key which is in another agent's collection", async () =>
await createKeyCollection(bob.cells[0], "a test");

// Bob links Alice's verification key to their key collection
await linkVerificationKeyToKeyCollection(bob.cells[0], vf_key_dist_address, "a test");
await linkVerificationKeyToKeyCollection(
bob.cells[0],
vf_key_dist_address,
"a test",
);

await dhtSync([alice, bob], alice.cells[0].cell_id[0]);

Expand Down Expand Up @@ -84,7 +87,11 @@ test("Search for a key which is in another agent's collection", async () => {
await createKeyCollection(bob.cells[0], "a test");

// Bob links Alice's verification key to their key collection
await linkVerificationKeyToKeyCollection(bob.cells[0], vf_key_dist_address, "a test");
await linkVerificationKeyToKeyCollection(
bob.cells[0],
vf_key_dist_address,
"a test",
);

await dhtSync([alice, bob], alice.cells[0].cell_id[0]);

Expand Down Expand Up @@ -126,13 +133,21 @@ test("Get my key collections for a key which is in another agent's collection",
await createKeyCollection(bob.cells[0], "bob test");

// Bob links Alice's verification key to their key collection
await linkVerificationKeyToKeyCollection(bob.cells[0], vf_key_dist_address, "bob test");
await linkVerificationKeyToKeyCollection(
bob.cells[0],
vf_key_dist_address,
"bob test",
);

// Carol creates a collection
await createKeyCollection(carol.cells[0], "carol test");

// Carol links Alice's verification key to their key collection
await linkVerificationKeyToKeyCollection(carol.cells[0], vf_key_dist_address, "carol test");
await linkVerificationKeyToKeyCollection(
carol.cells[0],
vf_key_dist_address,
"carol test",
);

await dhtSync([alice, bob, carol], alice.cells[0].cell_id[0]);

Expand Down
23 changes: 18 additions & 5 deletions tests/src/checked/signing_keys/validation-key-dist.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,18 @@ import { runScenario, dhtSync } from "@holochain/tryorama";
import { Record } from "@holochain/client";

import {
VerificationKeyResponse,
distributeVerificationKey,
sampleMiniSignKey,
testAppPath,
sampleMiniSignProof,
sampleMiniSignProofSignature,
sampleMiniSignProofSignature2,
sampleMiniSignProof2,
sampleMiniSignKey2, getMyVerificationKeyDistributions, searchKeys, searchKeysLocal, markVerificationKeyRotated,
sampleMiniSignKey2,
getMyVerificationKeyDistributions,
searchKeys,
searchKeysLocal,
markVerificationKeyRotated,
} from "./common.js";

test("Distribute a key", async () => {
Expand Down Expand Up @@ -116,7 +119,10 @@ test("Search for a key", async () => {

// Note: This is more of a PoC than anything at this point, but it's a start
// Bob searches for Alice's key while offline
const offline_responses = await searchKeysLocal(bob.cells[0], alice.agentPubKey);
const offline_responses = await searchKeysLocal(
bob.cells[0],
alice.agentPubKey,
);

assert.equal(offline_responses.length, 1);
assert.equal(offline_responses[0].verification_key_dist.name, "test");
Expand Down Expand Up @@ -157,7 +163,12 @@ test("Mark a key as compromised", async () => {

// Alice marks her own key as compromised
const compromisedSince = new Date().getUTCMilliseconds() * 1000;
await markVerificationKeyRotated(alice.cells[0], vf_key_dist_address, { Compromised: { note: "I think someone is using my private key!", since: compromisedSince } })
await markVerificationKeyRotated(alice.cells[0], vf_key_dist_address, {
Compromised: {
note: "I think someone is using my private key!",
since: compromisedSince,
},
});

// TODO should not need to DHT sync here. What I actually want is an 'Alice synced' to be serving up the links
// that Bob will need in the next step. For now, the test is flaky without this sync...
Expand Down Expand Up @@ -219,7 +230,9 @@ test("Mark a key as rotated", async () => {
const new_vf_key_dist_address = new_record.signed_action.hashed.hash;

// Alice marks her own key as compromised
await markVerificationKeyRotated(alice.cells[0], vf_key_dist_address, { Rotated: { new_verification_key_dist_address: new_vf_key_dist_address } })
await markVerificationKeyRotated(alice.cells[0], vf_key_dist_address, {
Rotated: { new_verification_key_dist_address: new_vf_key_dist_address },
});

// TODO should not need to DHT sync here. What I actually want is an 'Alice synced' to be serving up the links
// that Bob will need in the next step. For now, the test is flaky without this sync...
Expand Down

0 comments on commit 4d1542b

Please sign in to comment.