-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #231 from xmtp/ar/consent-proof-signature-package
Add consent proof message package
- Loading branch information
Showing
13 changed files
with
314 additions
and
1 deletion.
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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@xmtp/consent-proof-signature": patch | ||
--- | ||
|
||
Created package |
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,7 @@ | ||
module.exports = { | ||
root: true, | ||
extends: ["xmtp-web"], | ||
parserOptions: { | ||
project: "./tsconfig.eslint.json", | ||
}, | ||
}; |
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,23 @@ | ||
# Consent Proof Signature | ||
|
||
## Usage | ||
|
||
```ts | ||
const timestamp = Date.now(); | ||
const message = createConsentMessage(broadcastAddress, timestamp); | ||
// Sign the message for example with Viem | ||
import { createWalletClient, custom } from "viem"; | ||
|
||
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 |
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,97 @@ | ||
{ | ||
"name": "@xmtp/consent-proof-signature", | ||
"version": "0.1.0", | ||
"keywords": [ | ||
"xmtp", | ||
"messaging", | ||
"web3", | ||
"sdk", | ||
"js", | ||
"ts", | ||
"javascript", | ||
"typescript" | ||
], | ||
"homepage": "https://github.com/xmtp/xmtp-web", | ||
"bugs": { | ||
"url": "https://github.com/xmtp/xmtp-web/issues" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "[email protected]:xmtp/xmtp-web.git", | ||
"directory": "packages/consent-proof-signature" | ||
}, | ||
"license": "MIT", | ||
"author": "XMTP Labs <[email protected]>", | ||
"sideEffects": false, | ||
"type": "module", | ||
"exports": { | ||
".": { | ||
"types": "./lib/index.d.ts", | ||
"default": "./lib/index.js" | ||
} | ||
}, | ||
"main": "index.js", | ||
"module": "lib/index.js", | ||
"browser": "lib/index.js", | ||
"types": "lib/index.d.ts", | ||
"files": [ | ||
"lib", | ||
"src", | ||
"!src/**/*.test.*", | ||
"tsconfig.json" | ||
], | ||
"scripts": { | ||
"build": "yarn clean:lib && yarn rollup -c", | ||
"clean": "rm -rf .turbo && rm -rf node_modules && yarn clean:lib", | ||
"clean:lib": "rm -rf lib", | ||
"dev": "yarn clean:lib && yarn rollup -c --watch", | ||
"format": "yarn format:base -w .", | ||
"format:base": "prettier --ignore-path ../../.gitignore", | ||
"format:check": "yarn format:base -c .", | ||
"lint": "eslint . --ignore-path ../../.gitignore", | ||
"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.56.0", | ||
"long": "^5.2.3" | ||
}, | ||
"devDependencies": { | ||
"@rollup/plugin-terser": "^0.4.4", | ||
"@rollup/plugin-typescript": "^11.1.6", | ||
"@xmtp/tsconfig": "workspace:*", | ||
"eslint": "^8.57.0", | ||
"eslint-config-xmtp-web": "workspace:*", | ||
"ethers": "^6.11.1", | ||
"prettier": "^3.2.5", | ||
"prettier-plugin-packagejson": "^2.4.12", | ||
"rollup": "^4.13.0", | ||
"rollup-plugin-dts": "^6.1.0", | ||
"rollup-plugin-filesize": "^10.0.0", | ||
"rollup-plugin-tsconfig-paths": "^1.5.2", | ||
"typedoc": "^0.25.12", | ||
"typescript": "^5.4.2", | ||
"vite": "^5.1.6", | ||
"vite-tsconfig-paths": "^4.3.1", | ||
"vitest": "^1.3.1" | ||
}, | ||
"packageManager": "[email protected]", | ||
"publishConfig": { | ||
"access": "public", | ||
"provenance": true, | ||
"registry": "https://registry.npmjs.org/" | ||
} | ||
} |
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,50 @@ | ||
import { defineConfig } from "rollup"; | ||
import typescript from "@rollup/plugin-typescript"; | ||
import { dts } from "rollup-plugin-dts"; | ||
import tsConfigPaths from "rollup-plugin-tsconfig-paths"; | ||
import terser from "@rollup/plugin-terser"; | ||
import filesize from "rollup-plugin-filesize"; | ||
|
||
const plugins = [ | ||
tsConfigPaths(), | ||
typescript({ | ||
declaration: false, | ||
declarationMap: false, | ||
}), | ||
filesize({ | ||
showMinifiedSize: false, | ||
}), | ||
]; | ||
|
||
const external = ["@xmtp/proto", "node:crypto"]; | ||
|
||
export default defineConfig([ | ||
{ | ||
input: "src/index.ts", | ||
output: { | ||
file: "lib/index.js", | ||
format: "es", | ||
sourcemap: true, | ||
}, | ||
external, | ||
plugins, | ||
}, | ||
{ | ||
input: "src/index.ts", | ||
output: { | ||
file: "lib/browser/index.js", | ||
format: "es", | ||
sourcemap: true, | ||
}, | ||
external, | ||
plugins: [terser(), ...plugins], | ||
}, | ||
{ | ||
input: "src/index.ts", | ||
output: { | ||
file: "lib/index.d.ts", | ||
format: "es", | ||
}, | ||
plugins: [tsConfigPaths(), dts()], | ||
}, | ||
]); |
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,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, | ||
]), | ||
); | ||
}); | ||
}); |
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,35 @@ | ||
import Long from "long"; | ||
import { invitation } from "@xmtp/proto"; | ||
/** | ||
* | ||
* @param peerAddress - Ethereum address of the broadcaster | ||
* @param timestampMs - Timestamp in milliseconds used in the signature | ||
* @returns | ||
*/ | ||
export const createConsentMessage = ( | ||
peerAddress: string, | ||
timestampMs: number, | ||
): string => | ||
"XMTP : Grant inbox consent to sender\n" + | ||
"\n" + | ||
`Current Time: ${new Date(timestampMs).toUTCString()}\n` + | ||
`From Address: ${peerAddress}\n` + | ||
"\n" + | ||
"For more info: https://xmtp.org/signatures/"; | ||
|
||
/** | ||
* | ||
* @param signature hex string of the signature | ||
* @param timestampMs timestamp in milliseconds used in the signature | ||
* @returns Uint8Array of the consent proof payload | ||
*/ | ||
export const createConsentProofPayload = ( | ||
signature: string, | ||
timestampMs: number, | ||
): Uint8Array => | ||
invitation.ConsentProofPayload.encode({ | ||
signature, | ||
timestamp: Long.fromNumber(timestampMs), | ||
payloadVersion: | ||
invitation.ConsentProofPayloadVersion.CONSENT_PROOF_PAYLOAD_VERSION_1, | ||
}).finish(); |
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,5 @@ | ||
{ | ||
"extends": "./tsconfig.json", | ||
"include": [".", ".eslintrc.cjs", "rollup.config.js"], | ||
"exclude": ["lib", "node_modules"] | ||
} |
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,4 @@ | ||
{ | ||
"extends": "@xmtp/tsconfig/react-sdk.json", | ||
"include": ["src", ".eslintrc.cjs", "vitest.config.ts", "vitest.setup.ts"] | ||
} |
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,17 @@ | ||
import { defineConfig, mergeConfig } from "vite"; | ||
import { defineConfig as defineVitestConfig } from "vitest/config"; | ||
import tsconfigPaths from "vite-tsconfig-paths"; | ||
|
||
// https://vitejs.dev/config/ | ||
const viteConfig = defineConfig({ | ||
plugins: [tsconfigPaths()], | ||
}); | ||
|
||
const vitestConfig = defineVitestConfig({ | ||
test: { | ||
globals: true, | ||
environment: "happy-dom", | ||
}, | ||
}); | ||
|
||
export default mergeConfig(viteConfig, vitestConfig); |
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 |
---|---|---|
|
@@ -18,7 +18,7 @@ | |
"repository": { | ||
"type": "git", | ||
"url": "[email protected]:xmtp/xmtp-web.git", | ||
"directory": "packages/react-sdk" | ||
"directory": "packages/frames-client" | ||
}, | ||
"license": "MIT", | ||
"author": "XMTP Labs <[email protected]>", | ||
|
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