Compare commits

...

30 Commits

Author SHA1 Message Date
Ladd Hoffman 435553bf05 register matrix user link to author address
Gitea Actions Demo / Explore-Gitea-Actions (push) Failing after 37s Details
2024-04-26 19:36:02 -05:00
Ladd Hoffman 527c844ad0 request register identity capability
Gitea Actions Demo / Explore-Gitea-Actions (push) Failing after 32s Details
2024-04-26 19:23:15 -05:00
Ladd Hoffman a204ec7f6f log when receiving a register identity request
Gitea Actions Demo / Explore-Gitea-Actions (push) Failing after 37s Details
2024-04-26 19:18:12 -05:00
Ladd Hoffman e44f43350a proposal info reply in thread
Gitea Actions Demo / Explore-Gitea-Actions (push) Failing after 30s Details
2024-04-26 19:08:02 -05:00
Ladd Hoffman fe5fe522ab stub handler for identity registration
Gitea Actions Demo / Explore-Gitea-Actions (push) Failing after 37s Details
2024-04-26 18:31:34 -05:00
Ladd Hoffman 6a2b647b4b text event
Gitea Actions Demo / Explore-Gitea-Actions (push) Failing after 34s Details
2024-04-26 17:59:17 -05:00
Ladd Hoffman e95d7ac91c m.room.message
Gitea Actions Demo / Explore-Gitea-Actions (push) Failing after 34s Details
2024-04-26 17:54:40 -05:00
Ladd Hoffman 2f6b3d4ed1 m.message 2024-04-25 22:10:08 -05:00
Ladd Hoffman 6f4b2855a8 twiddle
Gitea Actions Demo / Explore-Gitea-Actions (push) Failing after 33s Details
2024-04-25 22:08:42 -05:00
Ladd Hoffman 9e5ccf6470 fixup
Gitea Actions Demo / Explore-Gitea-Actions (push) Failing after 36s Details
2024-04-25 22:03:20 -05:00
Ladd Hoffman ab103d3038 request capability on start
Gitea Actions Demo / Explore-Gitea-Actions (push) Failing after 42s Details
2024-04-25 21:57:51 -05:00
Ladd Hoffman 83d43b8312 caapbility string
Gitea Actions Demo / Explore-Gitea-Actions (push) Failing after 33s Details
2024-04-25 21:54:08 -05:00
Ladd Hoffman 4a38104d10 remove window message listener
Gitea Actions Demo / Explore-Gitea-Actions (push) Failing after 43s Details
2024-04-25 21:45:34 -05:00
Ladd Hoffman 3593fafd91 hardcode domain
Gitea Actions Demo / Explore-Gitea-Actions (push) Failing after 38s Details
2024-04-25 19:50:06 -05:00
Ladd Hoffman 039fc85fff widgetId from params
Gitea Actions Demo / Explore-Gitea-Actions (push) Failing after 37s Details
2024-04-25 19:23:36 -05:00
Ladd Hoffman e4277a229b squiggles
Gitea Actions Demo / Explore-Gitea-Actions (push) Failing after 33s Details
2024-04-25 18:47:38 -05:00
Ladd Hoffman 5b086aab9d tinkering
Gitea Actions Demo / Explore-Gitea-Actions (push) Failing after 28s Details
2024-04-25 18:11:16 -05:00
Ladd Hoffman 9b44c5bf21 widgeting
Gitea Actions Demo / Explore-Gitea-Actions (push) Failing after 27s Details
2024-04-25 17:50:10 -05:00
Ladd Hoffman b7a880322f set parent
Gitea Actions Demo / Explore-Gitea-Actions (push) Failing after 32s Details
2024-04-25 17:46:35 -05:00
Ladd Hoffman d09a46c292 request send message capability
Gitea Actions Demo / Explore-Gitea-Actions (push) Failing after 39s Details
2024-04-25 17:39:46 -05:00
Ladd Hoffman 9403e817b0 hard-code roomId
Gitea Actions Demo / Explore-Gitea-Actions (push) Failing after 33s Details
2024-04-25 17:29:02 -05:00
Ladd Hoffman 31fc599ce8 hard-code widgetId
Gitea Actions Demo / Explore-Gitea-Actions (push) Failing after 32s Details
2024-04-25 17:25:19 -05:00
Ladd Hoffman 80cd3439d1 log _events
Gitea Actions Demo / Explore-Gitea-Actions (push) Failing after 31s Details
2024-04-25 16:57:51 -05:00
Ladd Hoffman eb54ff4805 call updateRequestedCapabilities
Gitea Actions Demo / Explore-Gitea-Actions (push) Failing after 27s Details
2024-04-25 16:50:04 -05:00
Ladd Hoffman 1eacf3c9ab log widget api
Gitea Actions Demo / Explore-Gitea-Actions (push) Failing after 35s Details
2024-04-25 15:53:11 -05:00
Ladd Hoffman bc4b9f6a5b request a capability
Gitea Actions Demo / Explore-Gitea-Actions (push) Failing after 38s Details
2024-04-25 15:41:46 -05:00
Ladd Hoffman 8cc14bc7d5 call widget api start
Gitea Actions Demo / Explore-Gitea-Actions (push) Failing after 50s Details
2024-04-25 15:36:33 -05:00
Ladd Hoffman 27d0c853b2 fixup
Gitea Actions Demo / Explore-Gitea-Actions (push) Failing after 44s Details
2024-04-25 15:22:44 -05:00
Ladd Hoffman b713c77f10 try to instantiate widget api
Gitea Actions Demo / Explore-Gitea-Actions (push) Failing after 35s Details
2024-04-25 15:20:37 -05:00
Ladd Hoffman 466be6dacd simplify...
Gitea Actions Demo / Explore-Gitea-Actions (push) Failing after 26s Details
2024-04-25 15:05:19 -05:00
9 changed files with 119 additions and 49 deletions

View File

@ -1,9 +1,9 @@
{
"localhost": {
"DAO": "0x8d914D38dD301FC4606f5aa9fEcF8A76389020d3",
"Work1": "0xfe58B9EB03F75A603de1B286584f5E9532ab8fB5",
"Onboarding": "0x1d63FDe5B461106729fE1e5e38A02fc68C518Af5",
"Proposals": "0x050C420Cc4995B41217Eba1B54B82Fd5687e9139"
"DAO": "0x57BDFFf79108E5198dec6268A6BFFD8B62ECfA38",
"Work1": "0xB8f0cd092979F273b752FDa060F82BF2745f192e",
"Onboarding": "0x8F00038542C87A5eAf18d5938B7723bF2A04A4e4",
"Proposals": "0x6c18eb38b7450F8DaE5A5928A40fcA3952493Ee4"
},
"sepolia": {
"DAO": "0x8e5bd58B2ca8910C5F9be8de847d6883B15c60d2",

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,
@ -67,7 +73,7 @@ const start = async () => {
// Leave targetRoomId uninitialized for now
}
async function handleCommand(roomId, event) {
const handleCommand = async (roomId, event) => {
// Don't handle unhelpful events (ones that aren't text messages, are redacted, or sent by us)
if (event.content?.msgtype !== 'm.text') return;
if (event.sender === await client.getUserId()) return;
@ -96,16 +102,52 @@ const start = async () => {
try {
const proposalEventId = await proposalEventIds.get(proposalIndex);
const proposalEventUri = `https://matrix.to/#/${roomId}/${proposalEventId}`;
await client.sendText(roomId, `Proposal ${proposalIndex}: ${proposalEventUri}`);
const content = {
body: `Proposal ${proposalIndex}: ${proposalEventUri}`,
msgtype: 'm.text',
};
if (event.content['m.relates_to']?.rel_type === 'm.thread') {
content['m.relates_to'] = event.content['m.relates_to'];
}
await client.sendEvent(roomId, 'm.room.message', content);
} catch (e) {
// Not found
}
}
}
};
const handleRegisterIdentity = async (roomId, event) => {
const { message, signature } = event.content;
console.log('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
client.on('room.message', handleCommand);
// Handler for custom events
client.on('room.event', (roomId, event) => {
// Note that state events can also be sent down this listener too
if (event.state_key !== undefined) return; // state event
switch (event.type) {
case 'io.dgov.identity.register':
handleRegisterIdentity(roomId, event);
break;
default:
}
});
client.start().then(() => {
console.log('Bot started!');
outboundQueue.resume();

View File

@ -1,9 +1,9 @@
{
"localhost": {
"DAO": "0x8d914D38dD301FC4606f5aa9fEcF8A76389020d3",
"Work1": "0xfe58B9EB03F75A603de1B286584f5E9532ab8fB5",
"Onboarding": "0x1d63FDe5B461106729fE1e5e38A02fc68C518Af5",
"Proposals": "0x050C420Cc4995B41217Eba1B54B82Fd5687e9139"
"DAO": "0x57BDFFf79108E5198dec6268A6BFFD8B62ECfA38",
"Work1": "0xB8f0cd092979F273b752FDa060F82BF2745f192e",
"Onboarding": "0x8F00038542C87A5eAf18d5938B7723bF2A04A4e4",
"Proposals": "0x6c18eb38b7450F8DaE5A5928A40fcA3952493Ee4"
},
"sepolia": {
"DAO": "0x8e5bd58B2ca8910C5F9be8de847d6883B15c60d2",

View File

@ -1,9 +1,9 @@
{
"localhost": {
"DAO": "0x8d914D38dD301FC4606f5aa9fEcF8A76389020d3",
"Work1": "0xfe58B9EB03F75A603de1B286584f5E9532ab8fB5",
"Onboarding": "0x1d63FDe5B461106729fE1e5e38A02fc68C518Af5",
"Proposals": "0x050C420Cc4995B41217Eba1B54B82Fd5687e9139"
"DAO": "0x57BDFFf79108E5198dec6268A6BFFD8B62ECfA38",
"Work1": "0xB8f0cd092979F273b752FDa060F82BF2745f192e",
"Onboarding": "0x8F00038542C87A5eAf18d5938B7723bF2A04A4e4",
"Proposals": "0x6c18eb38b7450F8DaE5A5928A40fcA3952493Ee4"
},
"sepolia": {
"DAO": "0x8e5bd58B2ca8910C5F9be8de847d6883B15c60d2",

View File

@ -5,19 +5,9 @@
<link rel="icon" type="image/svg+xml" href="/dgf.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>DGF Prototype</title>
<script blocking="render">
console.log('adding window message event listener');
window.addEventListener(
'message',
(event) => {
if (event.data?.target?.startsWith('metamask')) return;
console.log('window message', event);
},
);
</script>
</head>
<body>
<div id="root"></div>
<script async type="module" src="/src/main.jsx"></script>
<script type="module" src="/src/main.jsx"></script>
</body>
</html>

View File

@ -229,7 +229,7 @@ function WebApp() {
Work1Contract.events.AvailabilityStaked().off();
OnboardingContract.events.AvailabilityStaked().off();
};
}, [provider, account, chainId, balance, dispatchValidationPool, dispatchPost, reputation,
}, [provider, account, chainId, balance, dispatchValidationPool, dispatchPost,
DAORef, workRef, onboardingRef,
fetchPost, fetchPosts, fetchReputation, fetchValidationPool, fetchValidationPools, fetchMembers,
]);

View File

@ -10,7 +10,9 @@ import Container from 'react-bootstrap/Container';
import Row from 'react-bootstrap/Row';
import Col from 'react-bootstrap/Col';
import Stack from 'react-bootstrap/Stack';
import { EventDirection, WidgetEventCapability } from 'matrix-widget-api';
import {
WidgetApi, EventDirection, WidgetEventCapability, /* MatrixCapabilities, */
} from 'matrix-widget-api';
// import { MuiCapabilitiesGuard } from '@matrix-widget-toolkit/mui';
// import { useWidgetApi } from '@matrix-widget-toolkit/react';
@ -233,7 +235,7 @@ function Widget() {
Work1Contract.events.AvailabilityStaked().off();
OnboardingContract.events.AvailabilityStaked().off();
};
}, [provider, account, chainId, balance, dispatchValidationPool, dispatchPost, reputation,
}, [provider, account, chainId, balance, dispatchValidationPool, dispatchPost,
DAORef, workRef, onboardingRef,
fetchPost, fetchPosts, fetchReputation, fetchValidationPool, fetchValidationPools, fetchMembers,
]);
@ -252,11 +254,41 @@ function Widget() {
useEffect(() => {
console.log('window.location', window.location);
const { searchParams } = new URL(window.location.href);
const widgetId = searchParams.get('widgetId');
window.widgetApiPromise.then((api) => {
console.log('widgetApi promise resolved', api);
widgetApi.current = api;
widgetApi.current = widgetApi.current ?? new WidgetApi(widgetId, 'https://chat.dgov.io');
console.log('widget api', widgetApi.current);
// widgetApi.current.requestCapability(MatrixCapabilities.AlwaysOnScreen);
// widgetApi.current.requestCapabilities([
// WidgetEventCapability.forRoomEvent(
// EventDirection.Send,
// 'm.message',
// ),
// ]);
// widgetApi.current.updateRequestedCapabilities();
widgetApi.current.on('ready', (e) => {
console.log('WIDGET READY', e);
const sendMessageCapability = WidgetEventCapability.forRoomEvent(
EventDirection.Send,
'm.room.message',
);
const sendRegisterIdentityCapability = WidgetEventCapability.forRoomEvent(
EventDirection.Send,
'io.dgov.identity.register',
);
widgetApi.current.requestCapability(sendMessageCapability.raw);
widgetApi.current.requestCapability(sendRegisterIdentityCapability.raw);
widgetApi.current.updateRequestedCapabilities();
});
widgetApi.current.start();
}, []);
/* -------------------------------------------------------------------------------- */
@ -341,16 +373,20 @@ function Widget() {
setShowViewPost(true);
}, [setViewPost, setShowViewPost]);
// TODO: Sign and send a message to the forum-api bot / to a room in matrix
const registerMatrixIdentity = async () => {
await widgetApi.current.requestCapabilities([
WidgetEventCapability.forRoomEvent(
EventDirection.Send,
'm.message',
),
]);
widgetApi.current.sendRoomEvent('m.message', 'test message');
};
// Sign and send a message
const registerMatrixIdentity = useCallback(async () => {
const message = new Date().toISOString();
const signature = await provider.request({
method: 'personal_sign',
params: [message, account],
});
await widgetApi.current.sendRoomEvent('io.dgov.identity.register', {
message,
signature,
});
}, [provider, account]);
/* -------------------------------------------------------------------------------- */
/* --------------------------- END UI ACTIONS ------------------------------------- */

View File

@ -7,12 +7,12 @@ import {
createBrowserRouter,
RouterProvider,
} from 'react-router-dom';
import { WidgetApiImpl } from '@matrix-widget-toolkit/api';
// import { WidgetApiImpl } from '@matrix-widget-toolkit/api';
import WebApp from './WebApp';
import Widget from './Widget';
window.widgetApiPromise = WidgetApiImpl.create({});
// window.widgetApiPromise = WidgetApiImpl.create({});
const router = createBrowserRouter([
{