-
Notifications
You must be signed in to change notification settings - Fork 145
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
XMTP Frame Post Validation #123
Merged
Merged
Changes from 2 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
b2180fa
Just add an XMTP validator
neekolas 45b3b2e
Add named type
neekolas 02102ce
Clean up XMTP validation
neekolas 62f7b8c
Merge remote-tracking branch 'upstream/main' into nm/xmtp-specific-va…
neekolas c656ae2
Update yarn.lock
neekolas 73a6d4d
Rename function
neekolas d497193
Add README
neekolas cf622f1
Merge remote-tracking branch 'upstream/main' into nm/xmtp-specific-va…
neekolas a13a95c
Move docs
neekolas 753a302
Return undefined
neekolas 60a86eb
Update lock files
neekolas 47d61b8
Add to index.mdx
neekolas 87a6ef3
Add to README
neekolas File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -79,5 +79,8 @@ | |
}, | ||
"default": "./lib/index.js" | ||
} | ||
}, | ||
"dependencies": { | ||
"@xmtp/frames-validator": "^0.4.0" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,10 @@ | ||
import { FrameRequest, FrameValidationResponse } from './types'; | ||
import { FrameRequest, FrameValidationResponse, XmtpFrameValidationResponse } from './types'; | ||
import { | ||
NEYNAR_DEFAULT_API_KEY, | ||
neynarFrameValidation, | ||
} from '../utils/neynar/frame/neynarFrameFunctions'; | ||
import { xmtpFrameValidation } from '../utils/xmtp/validateRequest'; | ||
import { XmtpOpenFramesRequest } from '@xmtp/frames-validator'; | ||
|
||
type FrameMessageOptions = | ||
| { | ||
|
@@ -44,4 +46,8 @@ async function getFrameMessage( | |
} | ||
} | ||
|
||
export { getFrameMessage }; | ||
function getXmtpFrameMessage(body: XmtpOpenFramesRequest): XmtpFrameValidationResponse { | ||
return xmtpFrameValidation(body); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's have his one file for |
||
} | ||
|
||
export { getFrameMessage, getXmtpFrameMessage }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { validateFramesPost, XmtpOpenFramesRequest } from '@xmtp/frames-validator'; | ||
|
||
export async function xmtpFrameValidation(payload: XmtpOpenFramesRequest) { | ||
if (!payload.clientProtocol || !payload.clientProtocol.startsWith('xmtp@')) { | ||
return { | ||
isValid: false, | ||
message: undefined, | ||
}; | ||
} | ||
|
||
try { | ||
const { actionBody, verifiedWalletAddress } = await validateFramesPost(payload); | ||
return { | ||
isValid: true, | ||
message: { | ||
...actionBody, | ||
verifiedWalletAddress, | ||
}, | ||
}; | ||
} catch (e) { | ||
console.error(`Error validating frames post: ${e}`); | ||
return { | ||
isValid: false, | ||
message: undefined, | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where can I read this code?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also not sure if this should be a
dependencies
orpeerDependencies
🤔Our leaning is to be the second
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://github.com/xmtp/xmtp-node-js-tools/tree/main/packages/frames-validator
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If it's a
peerDependency
then we're closer to the approach in #116 where we would want the caller to pass in some instance of the validatorThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The developer experience is a little smoother if you only need to depend on
onchainkit
, but both are fineThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think is about choice, on what API to use.
OnchainKit contains some code might need React, and other it doesn't. Some code it needs Viem, and other it doesn't.
That's why we referred that as peerDependency.
In the documentation we will create a section called XMTP, where we will write that all those function need
to be used.
And then after that folks can do
What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Our goal is to make sure that folks will need the PROTO dependencies https://bundlephobia.com/package/@xmtp/frames-validator@0.4.0 only when using XMTP.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK. You've sold me on a peer dependency approach. That seems fine as long as it's well documented.
Then we can add something like
import { getOpenFramesMessage } from '@coinbase/onchainkit/open-frames'
as soon as there is a 1.0 version of that spec. It can call into this code for the XMTP implementation of the spec. But no need to wait on that.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Love that