register matrix user link to author address
Gitea Actions Demo / Explore-Gitea-Actions (push) Failing after 37s Details

This commit is contained in:
Ladd Hoffman 2024-04-26 19:36:02 -05:00
parent 527c844ad0
commit 435553bf05
2 changed files with 25 additions and 7 deletions

View File

@ -4,9 +4,11 @@ const dataDir = process.env.LEVEL_DATA_DIR || 'data';
module.exports = {
forum: new Level(`${dataDir}/forum`, { valueEncoding: 'json' }),
authorAddresses: new Level(`${dataDir}/authorAddresses`, { valueEncoding: 'utf8' }),
authorPrivKeys: new Level(`${dataDir}/authorPrivKeys`, { valueEncoding: 'utf8' }),
authorAddresses: new Level(`${dataDir}/authorAddresses`),
authorPrivKeys: new Level(`${dataDir}/authorPrivKeys`),
appState: new Level(`${dataDir}/appState`, { valueEncoding: 'json' }),
proposalEventIds: new Level(`${dataDir}/proposalEventIds`, { keyEncoding: 'json', valueEncoding: 'utf8' }),
referendumEventIds: new Level(`${dataDir}/referendumEventIds`, { keyEncoding: 'json', valueEncoding: 'utf8' }),
proposalEventIds: new Level(`${dataDir}/proposalEventIds`, { keyEncoding: 'json' }),
referendumEventIds: new Level(`${dataDir}/referendumEventIds`, { keyEncoding: 'json' }),
matrixUserToAuthorAddress: new Level(`${dataDir}/matrixUserToAuthorAddress`),
authorAddressToMatrixUser: new Level(`${dataDir}/authorAddressToMatrixUser`),
};

View File

@ -5,8 +5,14 @@ const {
SimpleFsStorageProvider,
} = require('matrix-bot-sdk');
const fastq = require('fastq');
const { recoverPersonalSignature } = require('@metamask/eth-sig-util');
const { appState, proposalEventIds } = require('./db');
const {
appState,
proposalEventIds,
matrixUserToAuthorAddress,
authorAddressToMatrixUser,
} = require('./db');
const {
MATRIX_HOMESERVER_URL,
@ -111,9 +117,19 @@ const start = async () => {
};
const handleRegisterIdentity = async (roomId, event) => {
// const { message, signature } = event.content;
const { message, signature } = event.content;
console.log('Received request to register identity');
await client.replyNotice(roomId, event, 'Received request to register identity');
let account;
try {
account = recoverPersonalSignature({ data: message, signature });
} catch (e) {
console.log('error: failed to recover signature:', e.message);
}
if (account) {
await matrixUserToAuthorAddress.put(event.sender, account);
await authorAddressToMatrixUser.put(account, event.sender);
}
await client.sendNotice(roomId, `Registered matrix user ${event.sender} to author address ${account}`);
};
// Before we start the bot, register our command handler