Skip to content

Commit

Permalink
Merge pull request #1776 from okTurtles/e2e-protocol-ricardo
Browse files Browse the repository at this point in the history
E2e protocol ricardo
  • Loading branch information
taoeffect authored Oct 19, 2023
2 parents 58e6c31 + 2cf36e5 commit 5ce96a5
Show file tree
Hide file tree
Showing 11 changed files with 165 additions and 139 deletions.
9 changes: 5 additions & 4 deletions contracts/0.2.0/chatroom-slim.js
Original file line number Diff line number Diff line change
Expand Up @@ -7090,8 +7090,8 @@ ${this.getErrorInfo()}`;
});

// shared/domains/chelonia/utils.js
var findKeyIdByName = (state, name) => state._vm?.authorizedKeys && Object.values(state._vm.authorizedKeys).find((k) => k.name === name && k._notAfterHeight === void 0)?.id;
var findForeignKeysByContractID = (state, contractID) => state._vm?.authorizedKeys && Object.values(state._vm.authorizedKeys).filter((k) => k._notAfterHeight === void 0 && k.foreignKey?.includes(contractID)).map((k) => k.id);
var findKeyIdByName = (state, name) => state._vm?.authorizedKeys && Object.values(state._vm.authorizedKeys).find((k) => k.name === name && k._notAfterHeight == null)?.id;
var findForeignKeysByContractID = (state, contractID) => state._vm?.authorizedKeys && Object.values(state._vm.authorizedKeys).filter((k) => k._notAfterHeight == null && k.foreignKey?.includes(contractID)).map((k) => k.id);

// frontend/model/contracts/shared/constants.js
var CHATROOM_NAME_LIMITS_IN_CHARS = 50;
Expand Down Expand Up @@ -7500,11 +7500,12 @@ ${this.getErrorInfo()}`;
username: optional(string),
member: string
}),
process({ data, meta, hash, id }, { state }) {
process({ data, meta, hash, id, contractID }, { state }) {
const { member } = data;
const isKicked = data.username && member !== data.username;
if (!state.onlyRenderMessage && !state.users[member]) {
throw new Error(`Can not leave the chatroom which ${member} is not part of`);
console.warn(`Can not leave the chatroom ${contractID} which ${member} is not part of`);
return;
}
import_common.Vue.delete(state.users, member);
if (!state.onlyRenderMessage || state.attributes.type === CHATROOM_TYPES.DIRECT_MESSAGE) {
Expand Down
2 changes: 1 addition & 1 deletion contracts/0.2.0/chatroom.0.2.0.manifest.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"head":{"manifestVersion":"1.0.0"},"body":"{\"version\":\"0.2.0\",\"contract\":{\"hash\":\"21XWnNP5tqDKeAYvG6eryALLv7QyKVsooZr42xvVpGKYgZE4ya\",\"file\":\"chatroom.js\"},\"authors\":[{\"cipher\":\"algo\",\"key\":\"<pubkey from deploy-key.json>\"},{\"cipher\":\"algo\",\"key\":\"<pubkey from alex.json>\"}],\"contractSlim\":{\"file\":\"chatroom-slim.js\",\"hash\":\"21XWnNMFtepu694mgggFzcQTfVJHeZLrA6yCaQEs3EypSeC85T\"}}","signature":{"key":"<which of the 'authors' keys was used to sign 'body'>","signature":"<signature>"}}
{"head":{"manifestVersion":"1.0.0"},"body":"{\"version\":\"0.2.0\",\"contract\":{\"hash\":\"21XWnNMSuCrnYWd5k4rfgiER52edE4n4ZsMuMxxgLB8tEXRfpQ\",\"file\":\"chatroom.js\"},\"authors\":[{\"cipher\":\"algo\",\"key\":\"<pubkey from deploy-key.json>\"},{\"cipher\":\"algo\",\"key\":\"<pubkey from alex.json>\"}],\"contractSlim\":{\"file\":\"chatroom-slim.js\",\"hash\":\"21XWnNTNdo9ejZSdvNfCFHnh3kQPqNTXesNScNcXaezGTfJfYF\"}}","signature":{"key":"<which of the 'authors' keys was used to sign 'body'>","signature":"<signature>"}}
9 changes: 5 additions & 4 deletions contracts/0.2.0/chatroom.js
Original file line number Diff line number Diff line change
Expand Up @@ -16184,8 +16184,8 @@ ${this.getErrorInfo()}`;
});

// shared/domains/chelonia/utils.js
var findKeyIdByName = (state, name) => state._vm?.authorizedKeys && Object.values(state._vm.authorizedKeys).find((k) => k.name === name && k._notAfterHeight === void 0)?.id;
var findForeignKeysByContractID = (state, contractID) => state._vm?.authorizedKeys && Object.values(state._vm.authorizedKeys).filter((k) => k._notAfterHeight === void 0 && k.foreignKey?.includes(contractID)).map((k) => k.id);
var findKeyIdByName = (state, name) => state._vm?.authorizedKeys && Object.values(state._vm.authorizedKeys).find((k) => k.name === name && k._notAfterHeight == null)?.id;
var findForeignKeysByContractID = (state, contractID) => state._vm?.authorizedKeys && Object.values(state._vm.authorizedKeys).filter((k) => k._notAfterHeight == null && k.foreignKey?.includes(contractID)).map((k) => k.id);

// frontend/model/contracts/shared/constants.js
var CHATROOM_NAME_LIMITS_IN_CHARS = 50;
Expand Down Expand Up @@ -16594,11 +16594,12 @@ ${this.getErrorInfo()}`;
username: optional(string),
member: string
}),
process({ data, meta, hash: hash2, id }, { state }) {
process({ data, meta, hash: hash2, id, contractID }, { state }) {
const { member } = data;
const isKicked = data.username && member !== data.username;
if (!state.onlyRenderMessage && !state.users[member]) {
throw new Error(`Can not leave the chatroom which ${member} is not part of`);
console.warn(`Can not leave the chatroom ${contractID} which ${member} is not part of`);
return;
}
vue_esm_default.delete(state.users, member);
if (!state.onlyRenderMessage || state.attributes.type === CHATROOM_TYPES.DIRECT_MESSAGE) {
Expand Down
76 changes: 41 additions & 35 deletions contracts/0.2.0/group-slim.js
Original file line number Diff line number Diff line change
Expand Up @@ -7721,8 +7721,8 @@ ${this.getErrorInfo()}`;
});

// shared/domains/chelonia/utils.js
var findKeyIdByName = (state, name) => state._vm?.authorizedKeys && Object.values(state._vm.authorizedKeys).find((k) => k.name === name && k._notAfterHeight === void 0)?.id;
var findForeignKeysByContractID = (state, contractID) => state._vm?.authorizedKeys && Object.values(state._vm.authorizedKeys).filter((k) => k._notAfterHeight === void 0 && k.foreignKey?.includes(contractID)).map((k) => k.id);
var findKeyIdByName = (state, name) => state._vm?.authorizedKeys && Object.values(state._vm.authorizedKeys).find((k) => k.name === name && k._notAfterHeight == null)?.id;
var findForeignKeysByContractID = (state, contractID) => state._vm?.authorizedKeys && Object.values(state._vm.authorizedKeys).filter((k) => k._notAfterHeight == null && k.foreignKey?.includes(contractID)).map((k) => k.id);

// frontend/model/notifications/mutationKeys.js
var REMOVE_NOTIFICATION = "removeNotification";
Expand Down Expand Up @@ -8424,7 +8424,7 @@ ${this.getErrorInfo()}`;
}
}).catch((e) => {
console.error(`sideEffect(removeMember): ${e.name} thrown during queueEvent to ${contractID} by saveOurLoginState:`, e);
}).then(() => (0, import_sbp6.default)("gi.contracts/group/revokeGroupKeyAndRotateOurPEK", contractID)).catch((e) => {
}).then(() => (0, import_sbp6.default)("gi.contracts/group/revokeGroupKeyAndRotateOurPEK", contractID, true)).catch((e) => {
console.error(`sideEffect(removeMember): ${e.name} thrown during revokeGroupKeyAndRotateOurPEK to ${contractID}:`, e);
});
for (const notification of rootGetters.notificationsByGroup(contractID)) {
Expand All @@ -8439,7 +8439,11 @@ ${this.getErrorInfo()}`;
groupID: contractID,
username: memberRemovedThemselves ? meta.username : data.member
});
(0, import_sbp6.default)("gi.contracts/group/rotateKeys", contractID, state);
(0, import_sbp6.default)("gi.contracts/group/rotateKeys", contractID, state).then(() => {
return (0, import_sbp6.default)("gi.contracts/group/revokeGroupKeyAndRotateOurPEK", contractID, false);
}).catch((e) => {
console.error("Error rotating group keys or our PEK", e);
});
const rootGetters2 = (0, import_sbp6.default)("state/vuex/getters");
const userID = rootGetters2.ourContactProfiles[data.member]?.contractID;
if (userID) {
Expand Down Expand Up @@ -8760,8 +8764,8 @@ ${this.getErrorInfo()}`;
},
methods: {
"gi.contracts/group/archiveProposal": async function(contractID, proposalHash, proposal) {
const { username } = (0, import_sbp6.default)("state/vuex/state").loggedIn;
const key = `proposals/${username}/${contractID}`;
const { identityContractID } = (0, import_sbp6.default)("state/vuex/state").loggedIn;
const key = `proposals/${identityContractID}/${contractID}`;
const proposals2 = await (0, import_sbp6.default)("gi.db/archive/load", key) || [];
proposals2.unshift([proposalHash, proposal]);
while (proposals2.length > MAX_ARCHIVED_PROPOSALS) {
Expand All @@ -8772,10 +8776,10 @@ ${this.getErrorInfo()}`;
},
"gi.contracts/group/archivePayments": async function(contractID, archivingPayments) {
const { paymentsByPeriod, payments } = archivingPayments;
const { username } = (0, import_sbp6.default)("state/vuex/state").loggedIn;
const archPaymentsByPeriodKey = `paymentsByPeriod/${username}/${contractID}`;
const { identityContractID, username } = (0, import_sbp6.default)("state/vuex/state").loggedIn;
const archPaymentsByPeriodKey = `paymentsByPeriod/${identityContractID}/${contractID}`;
const archPaymentsByPeriod = await (0, import_sbp6.default)("gi.db/archive/load", archPaymentsByPeriodKey) || {};
const archSentOrReceivedPaymentsKey = `sentOrReceivedPayments/${username}/${contractID}`;
const archSentOrReceivedPaymentsKey = `sentOrReceivedPayments/${identityContractID}/${contractID}`;
const archSentOrReceivedPayments = await (0, import_sbp6.default)("gi.db/archive/load", archSentOrReceivedPaymentsKey) || { sent: [], received: [] };
const sortPayments = (payments2) => payments2.sort((f, l) => compareISOTimestamps(l.meta.createdDate, f.meta.createdDate));
for (const period of Object.keys(paymentsByPeriod).sort()) {
Expand All @@ -8795,13 +8799,13 @@ ${this.getErrorInfo()}`;
}
archSentOrReceivedPayments.sent = [...sortPayments(newSentOrReceivedPayments.sent), ...archSentOrReceivedPayments.sent];
archSentOrReceivedPayments.received = [...sortPayments(newSentOrReceivedPayments.received), ...archSentOrReceivedPayments.received];
const archPaymentsKey = `payments/${username}/${period}/${contractID}`;
const archPaymentsKey = `payments/${identityContractID}/${period}/${contractID}`;
const hashes = paymentHashesFromPaymentPeriod(paymentsByPeriod[period]);
const archPayments = Object.fromEntries(hashes.map((hash) => [hash, payments[hash]]));
while (Object.keys(archPaymentsByPeriod).length > MAX_ARCHIVED_PERIODS) {
const shouldBeDeletedPeriod = Object.keys(archPaymentsByPeriod).sort().shift();
const paymentHashes = paymentHashesFromPaymentPeriod(archPaymentsByPeriod[shouldBeDeletedPeriod]);
await (0, import_sbp6.default)("gi.db/archive/delete", `payments/${shouldBeDeletedPeriod}/${username}/${contractID}`);
await (0, import_sbp6.default)("gi.db/archive/delete", `payments/${shouldBeDeletedPeriod}/${identityContractID}/${contractID}`);
delete archPaymentsByPeriod[shouldBeDeletedPeriod];
archSentOrReceivedPayments.sent = archSentOrReceivedPayments.sent.filter((payment) => !paymentHashes.includes(payment.hash));
archSentOrReceivedPayments.received = archSentOrReceivedPayments.received.filter((payment) => !paymentHashes.includes(payment.hash));
Expand All @@ -8813,17 +8817,17 @@ ${this.getErrorInfo()}`;
(0, import_sbp6.default)("okTurtles.events/emit", PAYMENTS_ARCHIVED, { paymentsByPeriod, payments });
},
"gi.contracts/group/removeArchivedProposals": async function(contractID) {
const { username } = (0, import_sbp6.default)("state/vuex/state").loggedIn;
const key = `proposals/${username}/${contractID}`;
const { identityContractID } = (0, import_sbp6.default)("state/vuex/state").loggedIn;
const key = `proposals/${identityContractID}/${contractID}`;
await (0, import_sbp6.default)("gi.db/archive/delete", key);
},
"gi.contracts/group/removeArchivedPayments": async function(contractID) {
const { username } = (0, import_sbp6.default)("state/vuex/state").loggedIn;
const archPaymentsByPeriodKey = `paymentsByPeriod/${username}/${contractID}`;
const { identityContractID } = (0, import_sbp6.default)("state/vuex/state").loggedIn;
const archPaymentsByPeriodKey = `paymentsByPeriod/${identityContractID}/${contractID}`;
const periods = Object.keys(await (0, import_sbp6.default)("gi.db/archive/load", archPaymentsByPeriodKey) || {});
const archSentOrReceivedPaymentsKey = `sentOrReceivedPayments/${username}/${contractID}`;
const archSentOrReceivedPaymentsKey = `sentOrReceivedPayments/${identityContractID}/${contractID}`;
for (const period of periods) {
const archPaymentsKey = `payments/${username}/${period}/${contractID}`;
const archPaymentsKey = `payments/${identityContractID}/${period}/${contractID}`;
await (0, import_sbp6.default)("gi.db/archive/delete", archPaymentsKey);
}
await (0, import_sbp6.default)("gi.db/archive/delete", archPaymentsByPeriodKey);
Expand Down Expand Up @@ -8873,11 +8877,11 @@ ${this.getErrorInfo()}`;
const CEKid = findKeyIdByName(state, "cek");
import_common3.Vue.set(state._volatile.pendingKeyRevocations, CSKid, true);
import_common3.Vue.set(state._volatile.pendingKeyRevocations, CEKid, true);
(0, import_sbp6.default)("chelonia/queueInvocation", contractID, ["gi.actions/out/rotateKeys", contractID, "gi.contracts/group", "pending", "gi.actions/group/shareNewKeys"]).catch((e) => {
return (0, import_sbp6.default)("chelonia/queueInvocation", contractID, ["gi.actions/out/rotateKeys", contractID, "gi.contracts/group", "pending", "gi.actions/group/shareNewKeys"]).catch((e) => {
console.warn(`rotateKeys: ${e.name} thrown during queueEvent to ${contractID}:`, e);
});
},
"gi.contracts/group/revokeGroupKeyAndRotateOurPEK": (groupContractID) => {
"gi.contracts/group/revokeGroupKeyAndRotateOurPEK": (groupContractID, disconnectGroup) => {
const rootState = (0, import_sbp6.default)("state/vuex/state");
const { identityContractID } = rootState.loggedIn;
const state = rootState[identityContractID];
Expand All @@ -8886,25 +8890,27 @@ ${this.getErrorInfo()}`;
const CSKid = findKeyIdByName(state, "csk");
const CEKid = findKeyIdByName(state, "cek");
const PEKid = findKeyIdByName(state, "pek");
const groupCSKids = findForeignKeysByContractID(state, groupContractID);
import_common3.Vue.set(state._volatile.pendingKeyRevocations, PEKid, true);
if (groupCSKids?.length) {
if (!CEKid) {
throw new Error("Identity CEK not found");
}
(0, import_sbp6.default)("chelonia/queueInvocation", identityContractID, ["chelonia/out/keyDel", {
contractID: identityContractID,
contractName: "gi.contracts/identity",
data: groupCSKids,
signingKeyId: CSKid
}]).catch((e) => {
console.error(`revokeGroupKeyAndRotateOurPEK: ${e.name} thrown during keyDel to ${identityContractID}:`, e);
if (disconnectGroup) {
const groupCSKids = findForeignKeysByContractID(state, groupContractID);
if (groupCSKids?.length) {
if (!CEKid) {
throw new Error("Identity CEK not found");
}
(0, import_sbp6.default)("chelonia/queueInvocation", identityContractID, ["chelonia/out/keyDel", {
contractID: identityContractID,
contractName: "gi.contracts/identity",
data: groupCSKids,
signingKeyId: CSKid
}]).catch((e) => {
console.error(`revokeGroupKeyAndRotateOurPEK: ${e.name} thrown during keyDel to ${identityContractID}:`, e);
});
}
(0, import_sbp6.default)("chelonia/queueInvocation", identityContractID, ["chelonia/contract/disconnect", identityContractID, groupContractID]).catch((e) => {
console.error(`revokeGroupKeyAndRotateOurPEK: ${e.name} thrown during queueEvent to ${identityContractID}:`, e);
});
}
(0, import_sbp6.default)("chelonia/queueInvocation", identityContractID, ["chelonia/contract/disconnect", identityContractID, groupContractID]).catch((e) => {
console.error(`revokeGroupKeyAndRotateOurPEK: ${e.name} thrown during queueEvent to ${identityContractID}:`, e);
});
(0, import_sbp6.default)("chelonia/queueInvocation", identityContractID, ["gi.actions/out/rotateKeys", identityContractID, "gi.contracts/identity", "pending", "gi.actions/identity/shareNewPEK"]).catch((e) => {
return (0, import_sbp6.default)("chelonia/queueInvocation", identityContractID, ["gi.actions/out/rotateKeys", identityContractID, "gi.contracts/identity", "pending", "gi.actions/identity/shareNewPEK"]).catch((e) => {
console.error(`revokeGroupKeyAndRotateOurPEK: ${e.name} thrown during queueEvent to ${identityContractID}:`, e);
});
},
Expand Down
2 changes: 1 addition & 1 deletion contracts/0.2.0/group.0.2.0.manifest.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"head":{"manifestVersion":"1.0.0"},"body":"{\"version\":\"0.2.0\",\"contract\":{\"hash\":\"21XWnNL4g66rNK5wkSH9vZD6H6ZDJXJ84ecvCzPkBoaiCHkgmM\",\"file\":\"group.js\"},\"authors\":[{\"cipher\":\"algo\",\"key\":\"<pubkey from deploy-key.json>\"},{\"cipher\":\"algo\",\"key\":\"<pubkey from alex.json>\"}],\"contractSlim\":{\"file\":\"group-slim.js\",\"hash\":\"21XWnNMhWKeNnBG1upPDBdvrKWuERWGaKdNpCUcyfQ7Bj6QG3y\"}}","signature":{"key":"<which of the 'authors' keys was used to sign 'body'>","signature":"<signature>"}}
{"head":{"manifestVersion":"1.0.0"},"body":"{\"version\":\"0.2.0\",\"contract\":{\"hash\":\"21XWnNVqB5fYNAa2mufrsDVWZUsdeW82snkcx4pa4yWjvfTk3c\",\"file\":\"group.js\"},\"authors\":[{\"cipher\":\"algo\",\"key\":\"<pubkey from deploy-key.json>\"},{\"cipher\":\"algo\",\"key\":\"<pubkey from alex.json>\"}],\"contractSlim\":{\"file\":\"group-slim.js\",\"hash\":\"21XWnNUmvc1AqRF86c4Wk9hixK64uyG7LHkNi8iNqVs1kXKKpg\"}}","signature":{"key":"<which of the 'authors' keys was used to sign 'body'>","signature":"<signature>"}}
Loading

0 comments on commit 5ce96a5

Please sign in to comment.