Skip to content

Commit

Permalink
Rename loader fn.
Browse files Browse the repository at this point in the history
  • Loading branch information
ashwinphatak committed Jul 24, 2019
1 parent 3da44cc commit 4db1bc1
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
22 changes: 11 additions & 11 deletions packages/megafeed2/src/credentials/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ export class AuthProvider {

/**
* Create party invite (written to feed of inviter).
* Signed with the secret key of the inviting feed.
* Signed with the secret key of the inviter.
* @param {Buffer} partyKey
* @param {Object} inviter
* @param {Object} invitee
Expand Down Expand Up @@ -249,10 +249,10 @@ export const createPartyInvite = (partyKey, inviter, invitee) => {
* Verify party genesis block.
* @param {string} partyKey
* @param {Object} partyGenesis
* @param {Function} genesisBlockLoader
* @param {Function} loadFeedGenesisBlock
* @return {Promise<{verified: boolean}|{verified: boolean, error: string}>}
*/
const verifyPartyGenesisBlock = async (partyKey, partyGenesis, genesisBlockLoader) => {
const verifyPartyGenesisBlock = async (partyKey, partyGenesis, loadFeedGenesisBlock) => {
console.assert(partyKey);
console.assert(partyGenesis);
console.assert(partyGenesis.type === 'wrn:protobuf:wirelineio.credential.PartyGenesis');
Expand All @@ -270,7 +270,7 @@ const verifyPartyGenesisBlock = async (partyKey, partyGenesis, genesisBlockLoade
}

// Check genesis block in the chain actually matches the one on the feed.
if (!isEqual(partyGenesis, await genesisBlockLoader(partyGenesis.feedKey))) {
if (!isEqual(partyGenesis, await loadFeedGenesisBlock(partyGenesis.feedKey))) {
return { verified: false, error: 'Party genesis block mismatch.' };
}

Expand All @@ -282,11 +282,11 @@ const verifyPartyGenesisBlock = async (partyKey, partyGenesis, genesisBlockLoade
* Note: Can't reliably check for the party invite on existing feeds as it may not have been written yet.
* @param {string} partyKey
* @param {Object} partyInvite
* @param {Function} genesisBlockLoader
* @param {Function} loadFeedGenesisBlock
* @param {string} inviterFeedKey
* @return {Promise<{verified: boolean}|{verified: boolean, error: string}>}
*/
const verifyPartyInvite = async (partyKey, partyInvite, genesisBlockLoader, inviterFeedKey) => {
const verifyPartyInvite = async (partyKey, partyInvite, loadFeedGenesisBlock, inviterFeedKey) => {
console.assert(partyInvite);
console.assert(partyInvite.type === 'wrn:protobuf:wirelineio.party.Invite');

Expand All @@ -301,7 +301,7 @@ const verifyPartyInvite = async (partyKey, partyInvite, genesisBlockLoader, invi
}

// Load the feed genesis block for more checks.
const feedGenesis = await genesisBlockLoader(partyInvite.inviteeFeedKey);
const feedGenesis = await loadFeedGenesisBlock(partyInvite.inviteeFeedKey);
console.assert(feedGenesis);
console.assert(feedGenesis.type === 'wrn:protobuf:wirelineio.credential.FeedGenesis');

Expand Down Expand Up @@ -337,17 +337,17 @@ const verifyPartyInvite = async (partyKey, partyInvite, genesisBlockLoader, invi
* Verify party invite chain.
* @param {string} partyKey
* @param {Array{Object}} inviteChain
* @param {Function} genesisBlockLoader
* @param {Function} loadFeedGenesisBlock
* @return {Promise<{verified: boolean}|{verified: boolean, error: string}>}
*/
export const verifyPartyInviteChain = async (partyKey, inviteChain, genesisBlockLoader) => {
export const verifyPartyInviteChain = async (partyKey, inviteChain, loadFeedGenesisBlock) => {
console.assert(partyKey);
console.assert(inviteChain);
console.assert(inviteChain.length);

// The invite chain ALWAYS begins with the party genesis block.
const partyGenesis = inviteChain[0];
const { verified, error } = await verifyPartyGenesisBlock(partyKey, partyGenesis, genesisBlockLoader);
const { verified, error } = await verifyPartyGenesisBlock(partyKey, partyGenesis, loadFeedGenesisBlock);
if (!verified) {
return { verified, error };
}
Expand All @@ -358,7 +358,7 @@ export const verifyPartyInviteChain = async (partyKey, inviteChain, genesisBlock
log(partyKey, inviteChain[i]);

const partyInvite = inviteChain[i];
const { verified, error } = await verifyPartyInvite(partyKey, partyInvite, genesisBlockLoader, inviterFeedKey);
const { verified, error } = await verifyPartyInvite(partyKey, partyInvite, loadFeedGenesisBlock, inviterFeedKey);
if (!verified) {
return { verified, error };
}
Expand Down
4 changes: 2 additions & 2 deletions packages/megafeed2/src/credentials/party_invite_chain.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ test('party invite chain', async () => {

// Asynchronously load the genesis block for a feed given the key.
// It might, for example, sparse replicate the feed from a peer and request block zero.
const genesisBlockLoader = async (feedKey) => {
const loadFeedGenesisBlock = async (feedKey) => {
return keyToGenesisBlock.get(feedKey);
};

Expand Down Expand Up @@ -53,7 +53,7 @@ test('party invite chain', async () => {
inviteChain.push(partyInvite);
}

const { verified, error } = await verifyPartyInviteChain(partyGenesis.partyKey, inviteChain, genesisBlockLoader);
const { verified, error } = await verifyPartyInviteChain(partyGenesis.partyKey, inviteChain, loadFeedGenesisBlock);
expect(error).toBeUndefined();
expect(verified).toBeTruthy();
});

0 comments on commit 4db1bc1

Please sign in to comment.