Skip to content

Commit

Permalink
feat: polish xmtp (#161)
Browse files Browse the repository at this point in the history
  • Loading branch information
Zizzamia authored Feb 21, 2024
1 parent d99c916 commit 272082b
Show file tree
Hide file tree
Showing 15 changed files with 145 additions and 77 deletions.
5 changes: 5 additions & 0 deletions .changeset/silly-beans-visit.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@coinbase/onchainkit': patch
---

- **feat**: Added `getXmtpFrameMessage` and `isXmtpFrameRequest` so that Frames can receive interactions from apps outside of Farcaster, such as from XMTP conversations. By @neekolas #123
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,19 @@ OnchainKit offers three themes packed with React components and TypeScript utili
- Utilities:
- [`getFrameHtmlResponse`](https://onchainkit.xyz/framekit/get-frame-html-response)
- [`getFrameMessage`](https://onchainkit.xyz/framekit/get-frame-message)
- [`getXmtpFrameMessage`](https://onchainkit.xyz/framekit/get-xmtp-frame-message)
- [`getFrameMetadata`](https://onchainkit.xyz/framekit/get-frame-metadata)
- [Framegear](https://onchainkit.xyz/framekit/framegear)

- [Identity Kit](https://onchainkit.xyz/identitykit/introduction)

- Components:
- [`<Avatar />`](https://onchainkit.xyz/identitykit/avatar)
- [`<Name />`](https://onchainkit.xyz/identitykit/name)

- [XMTP Kit](https://onchainkit.xyz/xmtpkit/introduction)
- Utilities:
- [`getXmtpFrameMessage`](https://onchainkit.xyz/xmtpkit/get-xmtp-frame-message)

## Overview

To integrate OnchainKit into your project, begin by installing the necessary packages.
Expand Down
Binary file modified site/.yarn/install-state.gz
Binary file not shown.
1 change: 0 additions & 1 deletion site/docs/pages/framekit/introduction.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ To assist you in engaging with Frames, here is the Frame Kit which includes:
- Utilities:
- [`getFrameHtmlResponse`](/framekit/get-frame-html-response)
- [`getFrameMessage`](/framekit/get-frame-message)
- [`getXmtpFrameMessage`](/framekit/get-xmtp-frame-message)
- [`getFrameMetadata`](/framekit/get-frame-metadata)
- Emulator
- [`framegear`](/framekit/framegear)
6 changes: 5 additions & 1 deletion site/docs/pages/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -87,15 +87,19 @@ OnchainKit offers three themes packed with React components and TypeScript utili
- Utilities:
- [`getFrameHtmlResponse`](/framekit/get-frame-html-response)
- [`getFrameMessage`](/framekit/get-frame-message)
- [`getXmtpFrameMessage`](/framekit/get-xmtp-frame-message)
- [`getFrameMetadata`](/framekit/get-frame-metadata)
- [Framegear](/framekit/framegear)

- [Identity Kit](/identitykit/introduction)

- Components:
- [`<Avatar />`](/identitykit/avatar)
- [`<Name />`](/identitykit/name)

- [XMTP Kit](/xmtpkit/introduction)
- Utilities:
- [`getXmtpFrameMessage`](/xmtpkit/get-xmtp-frame-message)

# Community

Check out the following places for more OnchainKit-related content:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# getXmtpFrameMessage

Frames can receive interactions from apps outside of Farcaster, such as from XMTP conversations. When receiving these interactions you can expect a slightly different response format, since fields like `fid` or `castId` are not available.
Frames can receive interactions from apps outside of Farcaster, such as from XMTP conversations.
When receiving these interactions you can expect a slightly different response format,
since fields like `fid` or `castId` are not available.

You can also use `getXmtpFrameMessage` to access useful information such as:

Expand Down Expand Up @@ -42,7 +44,27 @@ export async function POST(req: NextRequest): Promise<Response> {
}
```

**@Param**
## Returns

```ts
type Promise<XmtpFrameValidationResponse>;

type XmtpFrameValidationResponse =
| { isValid: true; message: XmtpFrameValidationData }
| { isValid: false; message: undefined };

interface FrameValidationData {
frameUrl: string;
buttonIndex: number;
timestamp: number;
identifier: string;
verifiedWalletAddress: string;
// Same as verifiedWalletAddress
identifier: string;
}
```

## Param

```ts
export type UntrustedData = {
Expand All @@ -63,25 +85,3 @@ export type XmtpFramesRequest = {
};
};
```

**@Returns**

```ts
type Promise<XmtpFrameValidationResponse>;

type XmtpFrameValidationResponse =
| { isValid: true; message: XmtpFrameValidationData }
| { isValid: false; message: undefined };

interface FrameValidationData {
frameUrl: string;
buttonIndex: number;
timestamp: number;
identifier: string;
verifiedWalletAddress: string;
// Same as verifiedWalletAddress
identifier: string;
}
```

<br />
14 changes: 14 additions & 0 deletions site/docs/pages/xmtpkit/introduction.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
title: Introduction to XMTP Kit · OnchainKit
deescription: Introduction to XMTP Kit
---

# Introduction to XMTP Kit

XMTP Kit is designed to be modular and flexible, allowing developers to use only the parts of the protocol that they need.

To assist you in engaging with XMTP, here is the XMTP Kit which includes:

- [XMTP Kit](/xmtpkit/introduction)
- Utilities:
- [`getXmtpFrameMessage`](/xmtpkit/get-xmtp-frame-message)
3 changes: 3 additions & 0 deletions site/docs/pages/xmtpkit/is-xmtp-frame-request.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# isXmtpFrameRequest

isXmtpFrameRequest
19 changes: 19 additions & 0 deletions site/sidebar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,4 +90,23 @@ export const sidebar = [
},
],
},
{
text: 'XMTP Kit',
items: [
{ text: 'Introduction', link: '/xmtpkit/introduction' },
{
text: 'Utilities',
items: [
{
text: 'getXmtpFrameMessage',
link: '/xmtpkit/get-xmtp-frame-message',
},
{
text: 'isXmtpFrameRequest',
link: '/xmtpkit/is-xmtp-frame-request',
},
],
},
],
},
] as const satisfies Sidebar;
17 changes: 17 additions & 0 deletions src/core/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// 🌲☀️🌲
export { getEASAttestations } from './getEASAttestations';
export { getFrameHtmlResponse } from './getFrameHtmlResponse';
export { getFrameMetadata } from './getFrameMetadata';
export { getFrameMessage } from './getFrameMessage';
export { getMockFrameRequest } from './getMockFrameRequest';
export type {
FrameButtonMetadata,
FrameImageMetadata,
FrameInputMetadata,
FrameMetadataReact,
FrameMetadataType,
FrameRequest,
FrameValidationData,
MockFrameRequest,
MockFrameRequestOptions,
} from './types';
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { getXmtpFrameMessage, isXmtpFrameRequest } from './validation';
import { getXmtpFrameMessage } from './getXmtpFrameMessage';

const FIXTURES = {
valid: {
Expand Down Expand Up @@ -58,42 +58,3 @@ describe('xmtp validation', () => {
expect(invalidResult.message).toBeUndefined();
});
});

describe('isXmtpFrameRequest', () => {
it('should return true for requests with the correct client protocol', () => {
expect(
isXmtpFrameRequest({
clientProtocol: 'xmtp@2024-02-09',
untrustedData: {},
trustedData: {},
}),
).toBe(true);
});

it('should return false for farcaster requests', () => {
expect(
isXmtpFrameRequest({
untrustedData: {},
trustedData: {},
}),
).toBe(false);
});

it('should return false for other client protocols', () => {
expect(
isXmtpFrameRequest({
clientProtocol: 'lens@v1',
untrustedData: {},
trustedData: {},
}),
);
});

it('should return false for malformed requests', () => {
expect(
isXmtpFrameRequest({
clientProtocol: 'xmtp@2024-02-09',
}),
).toBe(false);
});
});
9 changes: 0 additions & 9 deletions src/xmtp/validation.ts → src/xmtp/getXmtpFrameMessage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,3 @@ export async function getXmtpFrameMessage(payload: XmtpOpenFramesRequest) {
};
}
}

export function isXmtpFrameRequest(payload: any): payload is XmtpOpenFramesRequest {
return (
!!payload &&
!!payload.untrustedData &&
!!payload.trustedData &&
!!payload.clientProtocol?.startsWith('xmtp@')
);
}
3 changes: 2 additions & 1 deletion src/xmtp/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export { getXmtpFrameMessage, isXmtpFrameRequest } from './validation';
export { getXmtpFrameMessage } from './getXmtpFrameMessage';
export { isXmtpFrameRequest } from './isXmtpFrameRequest';
40 changes: 40 additions & 0 deletions src/xmtp/isXmtpFrameRequest.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { isXmtpFrameRequest } from './isXmtpFrameRequest';

describe('isXmtpFrameRequest', () => {
it('should return true for requests with the correct client protocol', () => {
expect(
isXmtpFrameRequest({
clientProtocol: 'xmtp@2024-02-09',
untrustedData: {},
trustedData: {},
}),
).toBe(true);
});

it('should return false for farcaster requests', () => {
expect(
isXmtpFrameRequest({
untrustedData: {},
trustedData: {},
}),
).toBe(false);
});

it('should return false for other client protocols', () => {
expect(
isXmtpFrameRequest({
clientProtocol: 'lens@v1',
untrustedData: {},
trustedData: {},
}),
);
});

it('should return false for malformed requests', () => {
expect(
isXmtpFrameRequest({
clientProtocol: 'xmtp@2024-02-09',
}),
).toBe(false);
});
});
10 changes: 10 additions & 0 deletions src/xmtp/isXmtpFrameRequest.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { XmtpOpenFramesRequest } from '@xmtp/frames-validator';

export function isXmtpFrameRequest(payload: any): payload is XmtpOpenFramesRequest {
return (
!!payload &&
!!payload.untrustedData &&
!!payload.trustedData &&
!!payload.clientProtocol?.startsWith('xmtp@')
);
}

0 comments on commit 272082b

Please sign in to comment.