-
Notifications
You must be signed in to change notification settings - Fork 0
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 #1 from decentraland/feat/initial-client-implement…
…ation feat: Initial client implementation
- Loading branch information
Showing
21 changed files
with
12,834 additions
and
0 deletions.
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,29 @@ | ||
{ | ||
"extends": ["@dcl/eslint-config/dapps"], | ||
"parserOptions": { | ||
"project": ["tsconfig.json", "tests/tsconfig.json"] | ||
}, | ||
"rules": { | ||
"@typescript-eslint/no-non-null-assertion": "error" | ||
}, | ||
"ignorePatterns": ["src/protobuff-types"], | ||
"overrides": [ | ||
{ | ||
"files": ["*.ts"], | ||
"rules": { | ||
"@typescript-eslint/naming-convention": [ | ||
"error", | ||
{ "selector": "enumMember", "format": ["UPPER_CASE"] }, | ||
{ | ||
"selector": "objectLiteralProperty", | ||
"format": ["snake_case", "camelCase", "UPPER_CASE"], | ||
"filter": { | ||
"regex": "^.+-.+$", | ||
"match": false | ||
} | ||
} | ||
] | ||
} | ||
} | ||
] | ||
} |
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,43 @@ | ||
on: | ||
push: | ||
branches: | ||
- main | ||
pull_request: | ||
branches: | ||
- '*' | ||
release: | ||
types: | ||
- created | ||
|
||
name: Package CI | ||
jobs: | ||
install: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@master | ||
- name: Use Node.js 18.x | ||
uses: actions/setup-node@v3.7.0 | ||
with: | ||
cache: 'npm' | ||
node-version: 18.x | ||
- name: Install protoc | ||
run: sudo apt install -y protobuf-compiler | ||
- name: Install dependencies | ||
run: npm install | ||
- name: Build package | ||
run: npm run build | ||
- name: Run tests | ||
run: npm run test:coverage | ||
- name: Run linter | ||
run: npm run check:code | ||
- name: Report Coverage | ||
uses: coverallsapp/github-action@master | ||
with: | ||
github-token: ${{ secrets.GITHUB_TOKEN }} | ||
- name: Publish | ||
uses: menduz/oddish-action@master | ||
with: | ||
access: public | ||
provenance: true | ||
env: | ||
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} |
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,66 @@ | ||
node_modules/ | ||
.node_modules/ | ||
built/* | ||
tests/cases/rwc/* | ||
tests/cases/perf/* | ||
!tests/cases/webharness/compilerToString.js | ||
test-args.txt | ||
~*.docx | ||
\#*\# | ||
.\#* | ||
tests/baselines/local/* | ||
tests/baselines/local.old/* | ||
tests/services/baselines/local/* | ||
tests/baselines/prototyping/local/* | ||
tests/baselines/rwc/* | ||
tests/baselines/reference/projectOutput/* | ||
tests/baselines/local/projectOutput/* | ||
tests/baselines/reference/testresults.tap | ||
tests/services/baselines/prototyping/local/* | ||
tests/services/browser/typescriptServices.js | ||
src/harness/*.js | ||
src/compiler/diagnosticInformationMap.generated.ts | ||
src/compiler/diagnosticMessages.generated.json | ||
src/parser/diagnosticInformationMap.generated.ts | ||
src/parser/diagnosticMessages.generated.json | ||
rwc-report.html | ||
*.swp | ||
build.json | ||
*.actual | ||
tests/webTestServer.js | ||
tests/webTestServer.js.map | ||
tests/webhost/*.d.ts | ||
tests/webhost/webtsc.js | ||
tests/cases/**/*.js | ||
tests/cases/**/*.js.map | ||
*.config | ||
scripts/eslint/built/ | ||
scripts/debug.bat | ||
scripts/run.bat | ||
scripts/**/*.js | ||
scripts/**/*.js.map | ||
coverage/ | ||
internal/ | ||
**/.DS_Store | ||
.settings | ||
**/.vs | ||
**/.vscode/* | ||
!**/.vscode/tasks.json | ||
!**/.vscode/settings.template.json | ||
!**/.vscode/launch.template.json | ||
!**/.vscode/extensions.json | ||
!tests/cases/projects/projectOption/**/node_modules | ||
!tests/cases/projects/NodeModulesSearch/**/* | ||
!tests/baselines/reference/project/nodeModules*/**/* | ||
.idea | ||
yarn.lock | ||
yarn-error.log | ||
.parallelperf.* | ||
tests/baselines/reference/dt | ||
.failed-tests | ||
TEST-results.xml | ||
.eslintcache | ||
*v8.log | ||
/lib/ | ||
dist | ||
src/protobuff-types |
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,8 @@ | ||
{ | ||
"semi": false, | ||
"singleQuote": true, | ||
"printWidth": 140, | ||
"tabWidth": 2, | ||
"trailingComma": "none", | ||
"arrowParens": "avoid" | ||
} |
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,121 @@ | ||
<p align="center"> | ||
<a href="https://decentraland.org"> | ||
<img alt="Decentraland" src="https://decentraland.org/images/logo.png" width="60" /> | ||
</a> | ||
</p> | ||
<h1 align="center"> | ||
Decentraland Social Service JS Client | ||
</h1> | ||
|
||
The Decentraland Social Service JS Client is a Websocket client which uses the [DCL RPC protocol](https://github.com/decentraland/rpc) to communicate with the [Decentraland Social Service](https://github.com/decentraland/social-service). | ||
|
||
## Collaboration | ||
|
||
### Setting up the development environment | ||
|
||
In order to build the client, you'll need to have [Node.js](https://nodejs.org/en/) and [Protocol Buffers](https://grpc.io/docs/protoc-installation/) installed. | ||
|
||
### Installing the dependencies | ||
|
||
Run the NPM install command to install all the dependencies needed to run the project. | ||
|
||
```bash | ||
npm install | ||
``` | ||
|
||
### Building the client | ||
|
||
Run the NPM build command to build the client. | ||
|
||
```bash | ||
npm build | ||
``` | ||
|
||
This command will: | ||
1. Compile the protocol buffer's definitions for the RPC protocol of the Social Service, generating the corresponding TypeScript definitions. | ||
2. Compile the TypeScript code of the client. | ||
|
||
A distributable will be generated in the `dist` folder, containing all the client's code and types. | ||
|
||
## Using the client | ||
|
||
### Basic setup and usage | ||
|
||
To use the client, install the package in your NPM project: | ||
|
||
```bash | ||
npm install -S @dcl/social-rpc-client | ||
``` | ||
|
||
Import the client creator function from the installed package: | ||
|
||
```typescript | ||
import { createSocialClient } from "@dcl/social-client"; | ||
``` | ||
|
||
Create a new client instance by providing the client with: | ||
1. A URL to the Social Service's REST API | ||
2. A URL to the Social Service's Websocket endpoint | ||
3. The user's address (the same as the one used to sign the identity) | ||
4. An identity, signed with the user's wallet. | ||
|
||
```typescript | ||
import { createSocialClient } from "@dcl/social-client"; | ||
import { Wallet } from 'ethers' | ||
|
||
// Generate a random wallet for testing purposes or use the user's one in production environments. | ||
const wallet = Wallet.createRandom() | ||
const identity = await createIdentity(wallet, expiration) | ||
|
||
const socialClient = await createSocialClient( | ||
"https://social.decentraland.org", | ||
"wss://social-service.decentraland.org", | ||
wallet.address, | ||
identity | ||
); | ||
``` | ||
|
||
The `createSocialClient` will connect perform the required operations to connect to the Social Service and will return the connected client. | ||
|
||
|
||
Use the client to interact with the Social Service: | ||
|
||
```typescript | ||
import { createSocialClient } from "@dcl/social-client"; | ||
|
||
const socialClient = await createSocialClient( | ||
"https://social.decentraland.org", | ||
"wss://social-service.decentraland.org", | ||
wallet.address, | ||
identity | ||
); | ||
|
||
const friends = socialClient.getFriends() | ||
for await (const friend of friends) { | ||
console.log(friend) | ||
} | ||
``` | ||
|
||
The client exposes the methods available through the [social protobuff](https://github.com/decentraland/protocol/blob/main/public/social.proto) and a disconnect method which disconnects the client from the Social Service. | ||
|
||
|
||
### Generating an identity | ||
|
||
To authenticate users with the Social Service, you'll need to generate an identity for them. To do so, the `@dcl/crypto` library provides the `Authenticator.initializeAuthChain` method. Use it to generate an identity for your users: | ||
|
||
```typescript | ||
import { Wallet } from 'ethers' | ||
import { Authenticator } from '@dcl/crypto' | ||
// Generate a random wallet for testing purposes or use the user's one in production environments. | ||
const userWallet = Wallet.createRandom() | ||
|
||
// Generate an identity for the user. | ||
const address = await userWallet.getAddress() | ||
const ephemeralWallet = Wallet.createRandom() | ||
const payload = { | ||
address: ephemeralWallet.address, | ||
privateKey: ephemeralWallet.privateKey, | ||
publicKey: ephemeralWallet.publicKey | ||
} | ||
const identity = await Authenticator.initializeAuthChain(address, payload, expiration, (message: string) => signer.signMessage(message)) | ||
``` |
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,12 @@ | ||
{ | ||
"moduleFileExtensions": ["ts", "js"], | ||
"transform": { | ||
"^.+\\.(ts|tsx)$": "ts-jest" | ||
}, | ||
"coverageDirectory": "coverage", | ||
"collectCoverageFrom": ["src/**/*.ts"], | ||
"coveragePathIgnorePatterns": ["/node_modules/", "src/protobuff-types"], | ||
"testMatch": ["**/tests/*.spec.(ts)"], | ||
"testEnvironment": "node", | ||
"resetMocks": true | ||
} |
Oops, something went wrong.