Skip to content

Commit

Permalink
Merge pull request #684 from xmtp/rygine/merge-web-packages
Browse files Browse the repository at this point in the history
Merge `consent-proof-signature` and `frames-client` from web repo
  • Loading branch information
rygine authored Oct 17, 2024
2 parents 12486c1 + 92bc000 commit f20d30e
Show file tree
Hide file tree
Showing 42 changed files with 1,579 additions and 229 deletions.
76 changes: 76 additions & 0 deletions .github/workflows/packages.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
name: Packages

on:
push:
branches:
- main

pull_request:
paths:
- "packages/**"
- ".github/workflows/packages.yml"
- "dev/**"
- ".node-version"
- ".nvmrc"
- ".yarnrc.yml"
- "turbo.json"
- "yarn.lock"

jobs:
typecheck:
name: Typecheck
runs-on: warp-ubuntu-latest-x64-8x
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version-file: ".nvmrc"
cache: "yarn"
env:
SKIP_YARN_COREPACK_CHECK: "1"
- name: Enable corepack
run: corepack enable
- name: Install dependencies
run: yarn
- name: Typecheck
run: yarn turbo run typecheck --filter='./packages/*'

test:
name: Test
runs-on: warp-ubuntu-latest-x64-8x
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version-file: ".nvmrc"
cache: "yarn"
env:
SKIP_YARN_COREPACK_CHECK: "1"
- name: Enable corepack
run: corepack enable
- name: Install dependencies
run: yarn
- name: Start dev environment
run: ./dev/up
- name: Sleep for 5 seconds
run: sleep 5s
- name: Run tests
run: yarn turbo run test --filter='./packages/*'

build:
name: Build
runs-on: warp-ubuntu-latest-x64-8x
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version-file: ".nvmrc"
cache: "yarn"
env:
SKIP_YARN_COREPACK_CHECK: "1"
- name: Enable corepack
run: corepack enable
- name: Install dependencies
run: yarn
- name: Build
run: yarn turbo run build --filter='./packages/*'
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ To learn more about the contents of this repository, see this README and the REA
- [`content-type-text`](content-types/content-type-text): Content type for plain text messages
- [`content-type-transaction-reference`](content-types/content-type-transaction-reference): Content type for on-chain transaction references

### Packages

- [`frames-client`](https://github.com/xmtp/xmtp-js/blob/main/packages/frames-client): XMTP Open Frames client
- [`consent-proof-signature`](https://github.com/xmtp/xmtp-js/blob/main/packages/consent-proof-signature): Lightweight package for creating consent proofs

## Contributing

See our [contribution guide](./CONTRIBUTING.md) to learn more about contributing to this project.
2 changes: 1 addition & 1 deletion content-types/content-type-primitives/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
},
"devDependencies": {
"@rollup/plugin-terser": "^0.4.4",
"@rollup/plugin-typescript": "^12.1.0",
"@rollup/plugin-typescript": "^12.1.1",
"@types/node": "^20.16.11",
"happy-dom": "^15.7.4",
"rimraf": "^6.0.1",
Expand Down
2 changes: 1 addition & 1 deletion content-types/content-type-reaction/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
},
"devDependencies": {
"@rollup/plugin-terser": "^0.4.4",
"@rollup/plugin-typescript": "^12.1.0",
"@rollup/plugin-typescript": "^12.1.1",
"@types/node": "^20.16.11",
"@xmtp/xmtp-js": "^11.6.3",
"buffer": "^6.0.3",
Expand Down
2 changes: 1 addition & 1 deletion content-types/content-type-read-receipt/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
},
"devDependencies": {
"@rollup/plugin-terser": "^0.4.4",
"@rollup/plugin-typescript": "^12.1.0",
"@rollup/plugin-typescript": "^12.1.1",
"@types/node": "^20.16.11",
"@xmtp/xmtp-js": "^11.6.3",
"buffer": "^6.0.3",
Expand Down
2 changes: 1 addition & 1 deletion content-types/content-type-remote-attachment/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
"devDependencies": {
"@rollup/plugin-node-resolve": "^15.3.0",
"@rollup/plugin-terser": "^0.4.4",
"@rollup/plugin-typescript": "^12.1.0",
"@rollup/plugin-typescript": "^12.1.1",
"@types/node": "^20.16.11",
"@xmtp/rollup-plugin-resolve-extensions": "^1.0.1",
"@xmtp/xmtp-js": "^11.6.3",
Expand Down
2 changes: 1 addition & 1 deletion content-types/content-type-reply/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
},
"devDependencies": {
"@rollup/plugin-terser": "^0.4.4",
"@rollup/plugin-typescript": "^12.1.0",
"@rollup/plugin-typescript": "^12.1.1",
"@types/node": "^20.16.11",
"@xmtp/content-type-remote-attachment": "workspace:*",
"@xmtp/xmtp-js": "^11.6.3",
Expand Down
2 changes: 1 addition & 1 deletion content-types/content-type-text/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
},
"devDependencies": {
"@rollup/plugin-terser": "^0.4.4",
"@rollup/plugin-typescript": "^12.1.0",
"@rollup/plugin-typescript": "^12.1.1",
"@types/node": "^20.16.11",
"@xmtp/xmtp-js": "^11.6.3",
"buffer": "^6.0.3",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
},
"devDependencies": {
"@rollup/plugin-terser": "^0.4.4",
"@rollup/plugin-typescript": "^12.1.0",
"@rollup/plugin-typescript": "^12.1.1",
"@types/node": "^20.16.11",
"@xmtp/xmtp-js": "^11.6.3",
"buffer": "^6.0.3",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
"rimraf": "^6.0.1",
"turbo": "^2.1.3",
"typescript": "^5.6.3",
"typescript-eslint": "^8.9.0"
"typescript-eslint": "^8.10.0"
},
"packageManager": "[email protected]",
"engines": {
Expand Down
13 changes: 13 additions & 0 deletions packages/consent-proof-signature/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# @xmtp/consent-proof-signature

## 0.1.3

### Patch Changes

- 8adc23f: Add CommonJS export to `consent-proof-signature` package

## 0.1.1

### Patch Changes

- 6fbe931: Created package
24 changes: 24 additions & 0 deletions packages/consent-proof-signature/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Consent Proof Signature

## Usage

```ts
// Sign the message for example with Viem
import { createWalletClient, custom } from "viem";

const timestamp = Date.now();
const message = createConsentMessage(broadcastAddress, timestamp);

const walletClient = createWalletClient({
chain: mainnet,
transport: custom((window as any).ethereum!),
});
const [account] = await walletClient.getAddresses();
const signature = await walletClient.signMessage({
account,
message,
});
const consentProofBytes = createConsentProofPayload(signature, timestamp);
```

Now the `consentProofBytes` can be encoded and sent to a service to decode and add in a new conversation invitation
88 changes: 88 additions & 0 deletions packages/consent-proof-signature/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
{
"name": "@xmtp/consent-proof-signature",
"version": "0.1.3",
"keywords": [
"xmtp",
"messaging",
"web3",
"sdk",
"js",
"ts",
"javascript",
"typescript"
],
"homepage": "https://github.com/xmtp/xmtp-js",
"bugs": {
"url": "https://github.com/xmtp/xmtp-js/issues"
},
"repository": {
"type": "git",
"url": "[email protected]:xmtp/xmtp-js.git",
"directory": "packages/consent-proof-signature"
},
"license": "MIT",
"author": "XMTP Labs <[email protected]>",
"sideEffects": false,
"type": "module",
"exports": {
".": {
"types": "./dist/index.d.ts",
"require": "./dist/index.cjs",
"import": "./dist/index.js"
}
},
"main": "dist/index.cjs",
"module": "dist/index.js",
"browser": "dist/index.js",
"types": "dist/index.d.ts",
"files": [
"dist",
"src",
"!src/**/*.test.*",
"tsconfig.json"
],
"scripts": {
"build": "yarn clean:dist && yarn rollup -c",
"clean": "rm -rf .turbo && rm -rf node_modules && yarn clean:dist",
"clean:dist": "rm -rf dist",
"dev": "yarn clean:dist && yarn rollup -c --watch",
"test": "vitest run --passWithNoTests",
"typecheck": "tsc",
"typedoc": "typedoc"
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 3 chrome versions",
"last 3 firefox versions",
"last 3 safari versions"
]
},
"dependencies": {
"@xmtp/proto": "3.62.1",
"long": "^5.2.3"
},
"devDependencies": {
"@rollup/plugin-terser": "^0.4.4",
"@rollup/plugin-typescript": "^12.1.1",
"ethers": "^6.13.1",
"rollup": "^4.24.0",
"rollup-plugin-dts": "^6.1.1",
"rollup-plugin-filesize": "^10.0.0",
"tsconfig": "workspace:*",
"typedoc": "^0.26.4",
"typescript": "^5.6.3",
"vite": "^5.4.9",
"vitest": "^2.1.3"
},
"packageManager": "[email protected]",
"publishConfig": {
"access": "public",
"provenance": true,
"registry": "https://registry.npmjs.org/"
}
}
58 changes: 58 additions & 0 deletions packages/consent-proof-signature/rollup.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import terser from "@rollup/plugin-terser";
import typescript from "@rollup/plugin-typescript";
import { defineConfig } from "rollup";
import { dts } from "rollup-plugin-dts";
import filesize from "rollup-plugin-filesize";

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

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

export default defineConfig([
{
input: "src/index.ts",
output: {
file: "dist/index.js",
format: "es",
sourcemap: true,
},
external,
plugins,
},
{
input: "src/index.ts",
output: {
file: "dist/index.cjs",
format: "cjs",
sourcemap: true,
},
external,
plugins,
},
{
input: "src/index.ts",
output: {
file: "dist/browser/index.js",
format: "es",
sourcemap: true,
},
external,
plugins: [terser(), ...plugins],
},
{
input: "src/index.ts",
output: {
file: "dist/index.d.ts",
format: "es",
},
plugins: [dts()],
},
]);
30 changes: 30 additions & 0 deletions packages/consent-proof-signature/src/index.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { describe, expect, it } from "vitest";
import { createConsentMessage, createConsentProofPayload } from ".";

describe("createConsentMessage", () => {
it("should return a signature", () => {
const timestampMs = 1581663600000;
const exampleAddress = "0x1234567890abcdef";
const signatureMessage = createConsentMessage(exampleAddress, timestampMs);
expect(signatureMessage).toEqual(
"XMTP : Grant inbox consent to sender\n\nCurrent Time: Fri, 14 Feb 2020 07:00:00 GMT\nFrom Address: 0x1234567890abcdef\n\nFor more info: https://xmtp.org/signatures/",
);
});
});

describe("createConsentProofPayload", () => {
it("should return data of consent proof", () => {
const timestampMs = 1581663600000;
const exampleSignature = "0x1234567890abcdef";
const signatureMessage = createConsentProofPayload(
exampleSignature,
timestampMs,
);
expect(signatureMessage).toEqual(
Buffer.from([
10, 18, 48, 120, 49, 50, 51, 52, 53, 54, 55, 56, 57, 48, 97, 98, 99,
100, 101, 102, 16, 128, 251, 252, 147, 132, 46, 24, 1,
]),
);
});
});
Loading

0 comments on commit f20d30e

Please sign in to comment.