Skip to content
This repository has been archived by the owner on Jan 16, 2025. It is now read-only.

Commit

Permalink
Merge pull request #143 from xmtp/nm/allow-require
Browse files Browse the repository at this point in the history
Allow require
  • Loading branch information
neekolas authored Feb 7, 2024
2 parents be33368 + 12af7ee commit 9d486ea
Show file tree
Hide file tree
Showing 7 changed files with 310 additions and 7 deletions.
5 changes: 5 additions & 0 deletions .changeset/thick-bears-drum.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@xmtp/frames-validator": minor
---

Configure to export for both Node.js and ESM
20 changes: 20 additions & 0 deletions packages/frames-validator/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Frames Validator

A set of tools for validating POST payloads from XMTP Frames

## Usage

```ts
import { validateFramesPost } from "@xmtp/frames-validator"

export function handler(requestBody: any) {
// This is an XMTP payload
if (requestBody.untrustedData?.clientType === "xmtp") {
const { verifiedWalletAddress } = await validateFramesPost(requestBody)
return doSomethingWithWalletAddress(verifiedWalletAddress)
} else {
// This is a Farcaster POST payload
return doSomethingWithFarcasterPayload(requestBody)
}
}
```
16 changes: 14 additions & 2 deletions packages/frames-validator/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,17 @@
"name": "@xmtp/frames-validator",
"version": "0.2.0",
"description": "A validator for XMTP frames requests",
"main": "dist/src/index.js",
"type": "module",
"main": "dist/index.cjs",
"module": "dist/index.js",
"types": "dist/index.d.ts",
"exports": {
".": {
"types": "./dist/index.d.ts",
"import": "./dist/index.js",
"require": "./dist/index.cjs"
}
},
"engines": {
"node": ">=18"
},
Expand All @@ -20,7 +29,7 @@
},
"scripts": {
"clean": "rm -rf dist",
"build": "yarn clean && tsc",
"build": "yarn clean && rollup -c",
"prepublishOnly": "yarn build",
"test": "vitest run ./src"
},
Expand All @@ -32,8 +41,11 @@
"homepage": "https://github.com/xmtp/xmtp-node-js-tools#readme",
"packageManager": "[email protected]",
"devDependencies": {
"@rollup/plugin-typescript": "^11.1.6",
"@xmtp/frames-client": "^0.2.0",
"ethers": "^6.10.0",
"rollup": "^4.9.6",
"rollup-plugin-dts": "^6.1.0",
"typescript": "^5.3.3",
"vitest": "^1.0.1"
}
Expand Down
43 changes: 43 additions & 0 deletions packages/frames-validator/rollup.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import typescript from "@rollup/plugin-typescript"
import { defineConfig } from "rollup"
import { dts } from "rollup-plugin-dts"

const external = ["@xmtp/proto", "node:crypto", "@xmtp/xmtp-js", "long"]

const plugins = [
typescript({
declaration: false,
declarationMap: false,
}),
]

export default defineConfig([
{
input: "src/index.ts",
output: {
file: "dist/index.js",
format: "es",
sourcemap: true,
},
plugins,
external,
},
{
input: "src/index.ts",
output: {
file: "dist/index.cjs",
format: "cjs",
sourcemap: true,
},
plugins,
external,
},
{
input: "src/index.ts",
output: {
file: "dist/index.d.ts",
format: "es",
},
plugins: [dts()],
},
])
2 changes: 1 addition & 1 deletion packages/frames-validator/src/crypto.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { webcrypto } from "crypto"
import { webcrypto } from "node:crypto"

export async function sha256(data: Uint8Array): Promise<Uint8Array> {
const hash = await webcrypto.subtle.digest("SHA-256", data)
Expand Down
5 changes: 3 additions & 2 deletions packages/frames-validator/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"outDir": "dist"
"outDir": "dist/esm",
"composite": false
},
"includes": ["src"]
"includes": ["src/**/*"]
}
Loading

0 comments on commit 9d486ea

Please sign in to comment.