{"id":13454080,"url":"https://github.com/dialectlabs/protocol","last_synced_at":"2025-06-25T10:36:08.925Z","repository":{"id":38191238,"uuid":"403125917","full_name":"dialectlabs/protocol","owner":"dialectlabs","description":null,"archived":false,"fork":false,"pushed_at":"2022-11-23T09:33:40.000Z","size":933,"stargazers_count":77,"open_issues_count":8,"forks_count":12,"subscribers_count":6,"default_branch":"master","last_synced_at":"2025-06-17T03:43:26.147Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dialectlabs.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-09-04T18:11:16.000Z","updated_at":"2024-11-05T12:03:47.000Z","dependencies_parsed_at":"2023-01-21T14:04:32.781Z","dependency_job_id":null,"html_url":"https://github.com/dialectlabs/protocol","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"purl":"pkg:github/dialectlabs/protocol","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dialectlabs%2Fprotocol","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dialectlabs%2Fprotocol/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dialectlabs%2Fprotocol/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dialectlabs%2Fprotocol/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dialectlabs","download_url":"https://codeload.github.com/dialectlabs/protocol/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dialectlabs%2Fprotocol/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":261853168,"owners_count":23219816,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-07-31T08:00:50.760Z","updated_at":"2025-06-25T10:36:08.901Z","avatar_url":"https://github.com/dialectlabs.png","language":"TypeScript","funding_links":[],"categories":["TypeScript"],"sub_categories":[],"readme":"# Protocol \u0026 web3\n\n## Summary\n\nDialect is a smart messaging protocol for dapp notifications and wallet-to-wallet messaging on the Solana Blockchain.\n\nDialect works by decorating on-chain resources, or sets of resources, with publish-subscribe (pub-sub) messaging capabilities. This is accomplished by creating a PDA whose seeds are the (lexically sorted) resources' public keys. Each pub-sub messaging PDA is called a _dialect_.\n\nDialect `v0` currently supports one-to-one messaging between wallets, which powers both dapp notifications as well as user-to-user chat. Future versions of Dialect will also support one-to-many and many-to-many messaging.\n\nThis repository contains both the Dialect rust programs (protocol), in Anchor, as well as a typescript client, published to npm as `@dialectlabs/web3`.\n\nCurrently, the dialect account rent cost is `~0.059 SOL`.\n\n## Table of Contents\n\n1. Installation\n2. Usage\n3. Local Development\n4. Docker\n5. Anchor Tests\n6. Examples\n7. Message Encryption\n\n## Installation\n\n**npm:**\n\n```shell\nnpm install @dialectlabs/protocol --save\n```\n\n**yarn:**\n\n```shell\nyarn add @dialectlabs/protocol\n```\n\n## Usage\n\nThis section describes how to use Dialect protocol in your app by showing you examples in the`examples/` directory of this repository. Follow along in this section, \u0026 refer to the code in those examples.\n\n### Create your first dialect, send and receive message\n\nThe example in `examples/hello-world.ts` demonstrates how to create a new dialect, send and receive message.\n\n```typescript\nimport {\n  createDialect,\n  getDialectForMembers,\n  sendMessage,\n  Member,\n} from '@dialectlabs/protocol';\n\nconst program = // ... initialize dialect program\n\nconst [user1, user2] = [Keypair.generate(), Keypair.generate()];\n// ... fund keypairs\nconst dialectMembers: Member[] = [\n  {\n    publicKey: user1.publicKey,\n    scopes: [true, true],\n  },\n  {\n    publicKey: user2.publicKey,\n    scopes: [false, true],\n  },\n];\nconst user1Dialect = await createDialect(\n  program,\n  user1,\n  dialectMembers,\n  false,\n); // crate dialect on behalf of 1st user\nawait sendMessage(program, user1Dialect, user1, 'Hello dialect!'); // send message\nconst { dialect: user2Dialect } = await getDialectForMembers(\n  program,\n  dialectMembers,\n  user2,\n); // get dialect on behalf of 2nd user\nconsole.log(JSON.stringify(user2Dialect.messages));\n// Will print [{\"text\":\"Hello dialect!\", ...}]\n```\n\nRun the example above\n\n```shell\nts-node examples/hello-world.ts\n```\n\n## Local Development\n\nNote: If you just need a local running instance of the Dialect program, it is easiest to simply run Dialect in a docker container. See the [Docker](###docker) section below.\n\nDialect is built with Solana and Anchor. Install both dependencies first following their respective documentation\n\n- [Solana](https://docs.solana.com/cli/install-solana-cli-tools)\n- [Anchor](https://book.anchor-lang.com) v0.18.0\n\nWe recommend installing anchor with [avm](https://book.anchor-lang.com/getting_started/installation.html#installing-using-anchor-version-manager-avm-recommended) and using the `\"@project-serum/anchor\"` version that's specified in our [package.json](https://github.com/dialectlabs/protocol/blob/master/package.json) file.\n\nBe sure you are targeting a Solana `localnet` instance:\n\n```shell\nsolana config set --url localhost\n```\n\nNext run the tests to verify everything is setup correctly:\n\nFirst ensure you have ts-mocha installed globally:\n\n```shell\nnpm install -g ts-mocha\n```\n\nRun the tests with:\n\n```shell\nanchor test\n```\n\nRun a local validator:\n\n```shell\nsolana-test-validator --rpc-port 8899\n```\n\nBuild the Dialect Solana program:\n\n```shell\nanchor build\n```\n\nIf you haven't deployed this program to localnet before, `anchor build` produces a program-id. To get this program-id use the command:\n\n```bash\nsolana address -k target/deploy/dialect-keypair.json\n```\n\nAdd this program id in the following additional places before proceeding:\n\n1. In the `dialect = \"\u003cprogram-id\u003e\"` in `Anchor.toml`\n2. In the `declare_id!(\"\u003cprogram-id\u003e\")` in `programs/dialect/src/lib.rs`\n3. In the `localnet` key in `src/utils/program.json` (redundant, to be retired)\n\nBefore deploying make sure you fund your Solana wallet:\n\nYou can fund your wallet with:\n\n```shell\nsolana airdrop 2\n```\n\nYou can verify your token balance with:\n\n```shell\nsolana balance\n```\n\nDeploy the Dialect Solana program with:\n\n```shell\nanchor deploy\n```\n\nFinally, install the `js`/`ts` `npm` dependencies with\n\n```shell\nnpm i\n```\n\n### Docker\n\nThe Dialect docker image will get you a deployed Dialect program running on a Solana validator. This is ideal if you're building off of `@dialectlabs/protocol`, rather than actively developing on it.\n\n```bash\n# build\ndocker build -f docker/Dockerfile . -t dialect/protocol:latest\n\n# run\ndocker run -i --rm -p 8899:8899 -p 8900:8900 -p 9900:9900 --name protocol dialect/protocol:latest\n```\n\n## Tests\n\nFirst ensure you have ts-mocha install globally:\n\n```shell\nnpm install -g ts-mocha\n```\n\nRun the tests with:\n\n```shell\nanchor test\n```\n\n## Examples\n\nRun the example with:\n\n```bash\nDIALECT_PUBLIC_KEY=\u003cdialect-public-key\u003e ts-node examples/hello-world.ts\n```\n\nIt is fine to omit the `DIALECT_PUBLIC_KEY` environment variable, the example will generate one on the fly. However, if you're using this example as an integration test with other services, such as the monitoring service, you'll need to set it to the public key corresponding to the private key in the monitoring service.\n\n## Message Encryption\n\nA note about the encryption nonce.\n\nhttps://pynacl.readthedocs.io/en/v0.2.1/secret/\n\n### Nonce\n\nThe 24 bytes nonce (Number used once) given to encrypt() and decrypt() must **_NEVER_** be reused for a particular key.\nReusing the nonce means an attacker will have enough information to recover your secret key and encrypt or decrypt arbitrary messages.\nA nonce is not considered secret and may be freely transmitted or stored in plaintext alongside the ciphertext.\n\nA nonce does not need to be random, nor does the method of generating them need to be secret.\nA nonce could simply be a counter incremented with each message encrypted.\n\nBoth the sender and the receiver should record every nonce both that they’ve used and they’ve received from the other.\nThey should reject any message which reuses a nonce and they should make absolutely sure never to reuse a nonce.\nIt is not enough to simply use a random value and hope that it’s not being reused (simply generating random values would open up the system to a Birthday Attack).\n\nOne good method of generating nonces is for each person to pick a unique prefix, for example b\"p1\" and b\"p2\". When each person generates a nonce they prefix it, so instead of nacl.utils.random(24) you’d do b\"p1\" + nacl.utils.random(22). This prefix serves as a guarantee that no two messages from different people will inadvertently overlap nonces while in transit. They should still record every nonce they’ve personally used and every nonce they’ve received to prevent reuse or replays.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdialectlabs%2Fprotocol","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdialectlabs%2Fprotocol","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdialectlabs%2Fprotocol/lists"}