Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

E2ee #168

Draft
wants to merge 6 commits into
base: main
Choose a base branch
from
Draft

E2ee #168

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

A set of tools for AI developers to build on top of [XMTP](https://xmtp.org)

## What's inside?

### MessageKit

- [`message-kit`](/packages/message-kit): A kit for quickly building messaging apps
Expand Down
13 changes: 9 additions & 4 deletions packages/client/src/components/Chat.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -169,16 +169,13 @@
}

.urlContainer {
margin: 8px 0;
display: flex;
flex-direction: column;
gap: 8px;
border-radius: 8px 8px 0 0;
max-width: 300px;
background: #e0e0e0;
}

.urlPreview {
border-radius: 8px 8px 0 0;
overflow: hidden;
background: #ffffff;
border: 1px solid #b0b0b0;
Expand Down Expand Up @@ -231,3 +228,11 @@
color: var(--accent);
font-size: 0.9rem;
}
.encryptionInfo {
text-align: center !important;
width: 100%;
font-size: 0.7rem;
padding: 0rem;
padding-top: 0.4rem;
display: block !important;
}
17 changes: 9 additions & 8 deletions packages/client/src/components/Chat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@ function Chat({ user }: { user: UserInfo }) {
const [processedMessageIds] = useState(new Set<string>());

useEffect(() => {
console.log("useEffect triggered with user:", user);

const init = async () => {
try {
setRecipientInfo(user);
Expand All @@ -64,7 +62,6 @@ function Chat({ user }: { user: UserInfo }) {

const onMessage = async (message: Message | undefined) => {
if (message) {
console.log("onMessage", message);
setMessages((prevMessages) => [...prevMessages, message]);
}
};
Expand All @@ -88,7 +85,6 @@ function Chat({ user }: { user: UserInfo }) {
receivers: [recipientInfo.address],
originalMessage: undefined,
})) as Message;
console.log("message", message);

setMessages((prevMessages) => [...prevMessages, message]);
setNewMessage("");
Expand Down Expand Up @@ -144,17 +140,19 @@ function Chat({ user }: { user: UserInfo }) {
if (urlRegex.test(part)) {
try {
const urlType = getUrlType(part);
const isMessageKitUrl = part.includes("message-kit.org");

const isMessageKitUrl =
part.includes("message-kit.org") ||
part.includes("baselinks.vercel.app");
const isMobile = window.innerWidth < 768;
return (
<div key={index} className={styles.urlContainer}>
{isMessageKitUrl && <UrlPreview url={part} urlType={urlType} />}
{isMessageKitUrl && <UrlPreview url={part} />}
<div className={styles.buttonContainer}>
{urlType === "payment" && (
<button
onClick={() => {
const ethUrl = ethereumURL(part);
openUrl(ethUrl);
isMobile ? openUrl(ethUrl) : alert("Not on mobile");
}}
className={styles.urlButton}>
Pay in USDC
Expand Down Expand Up @@ -248,6 +246,9 @@ function Chat({ user }: { user: UserInfo }) {
Send
</button>
</div>
<div className={styles.encryptionInfo}>
End-to-end encrypted powered by XMTP
</div>
</form>
</div>
);
Expand Down
8 changes: 1 addition & 7 deletions packages/client/src/components/UrlPreview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,7 @@ interface OgData {
url?: string;
}

export const UrlPreview = ({
url,
urlType,
}: {
url: string;
urlType?: string;
}) => {
export const UrlPreview = ({ url }: { url: string; urlType?: string }) => {
const [ogData, setOgData] = useState<OgData | null>(null);
const [loading, setLoading] = useState(true);

Expand Down
2 changes: 1 addition & 1 deletion packages/create-message-kit/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,4 @@
"access": "public",
"registry": "https://registry.npmjs.org/"
}
}
}
2 changes: 1 addition & 1 deletion packages/docs/pages/concepts/xmtp.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

[XMTP](https://xmtp.org/) is the protocol that MessageKit uses to send and receive messages.

> Check out the [XMTP AI](/plugins/xmtp) plugins for more information.
> Check out the [xmtp e2ee](/plugins/xmtp) plugins for more information.

## Context

Expand Down
8 changes: 6 additions & 2 deletions packages/docs/pages/plugins/xmtp.mdx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# End-to-end encrypted messaging
# Secure agent messaging

AI is transforming consumer tech, with messaging becoming the main channel for interacting with agent services. This shift will scale message traffic astronomically, analogous to the web’s rise in the 2000s. Just as Cloud-flare secured web traffic, messaging will need robust scalable end-to-end encrypted messages to protect sensitive information.

Expand Down Expand Up @@ -108,7 +108,11 @@ const onMessage = async (message, user) => {

### React example

This is how you can use the `xmtp-e2ee` package to create a client and handle messages.
xmtp-e2ee is a light wrapper around the xmtp package to make it easier to use in react and web. Doesnt support groups yet.

```bash [cmd]
bun install xmtp-e2ee
```

```tsx
import { XMTP, Message } from "xmtp-e2ee";
Expand Down
2 changes: 1 addition & 1 deletion packages/xmtp-e2ee/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# XMTP

> See [XMTP AI](https://message-kit.org/plugins/xmtp) plugin
> See [xmtp e2ee](https://message-kit.org/plugins/xmtp) plugin

### Installation

Expand Down
4 changes: 2 additions & 2 deletions packages/xmtp-e2ee/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "xmtp-e2ee",
"version": "0.0.8",
"version": "0.0.9",
"license": "MIT",
"type": "module",
"exports": {
Expand Down Expand Up @@ -61,4 +61,4 @@
"access": "public",
"registry": "https://registry.npmjs.org/"
}
}
}
3 changes: 2 additions & 1 deletion packages/xmtp-e2ee/src/lib/xmtp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,8 @@ async function streamMessages(
while (true) {
try {
const stream = await client.conversations.streamAllMessages();
console.log(`Stream started`);
console.log(`XMTP: [v2] Stream started`);

for await (const message of stream) {
if (message) {
try {
Expand Down
2 changes: 1 addition & 1 deletion packages/xmtp/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# XMTP

> See [XMTP AI](https://message-kit.org/plugins/xmtp) plugin
> See [xmtp e2ee](https://message-kit.org/plugins/xmtp) plugin

### Installation

Expand Down
4 changes: 2 additions & 2 deletions packages/xmtp/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "xmtp",
"version": "0.0.8",
"version": "0.0.9",
"license": "MIT",
"type": "module",
"exports": {
Expand Down Expand Up @@ -59,4 +59,4 @@
"access": "public",
"registry": "https://registry.npmjs.org/"
}
}
}
7 changes: 2 additions & 5 deletions packages/xmtp/src/lib/xmtp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,6 @@ export class XMTP {
contentType = ContentTypeAgentMessage;
}

console.log(`message`, message);
if (userMessage.originalMessage?.version == "v2") {
let v2Conversation = await this.getV2ConversationByAddress(
userMessage.originalMessage.client?.address,
Expand Down Expand Up @@ -359,7 +358,7 @@ async function streamMessages(
await v3client.conversations.sync();
await v3client.conversations.list();
const stream = await v3client.conversations.streamAllMessages();
console.warn(`XMTP: [v3] Stream started`);
console.log(`XMTP: [v3] Stream started`);
for await (const message of stream) {
let conversation = await xmtp.getConversationFromMessage(message);
if (message && conversation) {
Expand All @@ -378,7 +377,6 @@ async function streamMessages(
conversation,
client,
);
console.log(`parsedMessage`, parsedMessage);
await onMessage(parsedMessage as Message);
} catch (e) {
console.log(`error`, e);
Expand All @@ -390,7 +388,7 @@ async function streamMessages(
typeof v2client.conversations.streamAllMessages === "function"
) {
const stream = await v2client.conversations.streamAllMessages();
console.warn(`XMTP: [v2] Stream started`);
console.log(`XMTP: [v2] Stream started`);
for await (const message of stream) {
let conversation = await xmtp.getConversationFromMessage(message);
if (message && conversation) {
Expand All @@ -408,7 +406,6 @@ async function streamMessages(
conversation,
client,
);
console.log(`parsedMessage`, parsedMessage);
await onMessage(parsedMessage as Message);
} catch (e) {
console.log(`error`, e);
Expand Down
Loading