Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/connect rtc #8

Merged
merged 24 commits into from
Apr 24, 2024
Merged
Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
f0293a4
docs: add webrtc decision
PhearZero Feb 15, 2024
0c7a935
feat: session status and webvitals performance increase
PhearZero Feb 15, 2024
77353cd
feat: WebRTC with websocket signaling
PhearZero Mar 25, 2024
9683478
fix: session adapter
PhearZero Apr 9, 2024
6396c36
wip: adds basic message passing demo
PhearZero Apr 10, 2024
785b999
Merge branch 'refs/heads/develop' into feat/connect-rtc
PhearZero Apr 10, 2024
da647ae
fix: test stubs
PhearZero Apr 10, 2024
fb021a4
test: add signals unit tests
PhearZero Apr 10, 2024
1d88a24
refactor: add core module and enforce style guides
PhearZero Apr 11, 2024
d1a61e0
chore: cleanup docker files
PhearZero Apr 11, 2024
1515c14
Merge branch 'refs/heads/feat/rekeyed-account-support' into feat/conn…
PhearZero Apr 11, 2024
9203910
chore: cleanup demo application
PhearZero Apr 12, 2024
102a55c
test: enforce linters and tests
PhearZero Apr 15, 2024
9ce32c4
Merge remote-tracking branch 'refs/remotes/origin/develop' into feat/…
PhearZero Apr 15, 2024
8d2f3f3
build: remove preinstall hooks
PhearZero Apr 15, 2024
6c6a257
refactor: change call to offer
PhearZero Apr 17, 2024
68e6cab
test: add signaling fixture for session
PhearZero Apr 18, 2024
af6b7e7
feat: js signaling client
PhearZero Apr 18, 2024
e98cedd
chore: lint fixes
PhearZero Apr 18, 2024
d59ff07
docs: update contrib and top level compose
PhearZero Apr 22, 2024
6cc3eef
fix: patch service for docker
PhearZero Apr 22, 2024
325edae
build: add ngrok to docker
PhearZero Apr 22, 2024
3e34494
docs: cleanup config docs
PhearZero Apr 22, 2024
ce75747
chore: cleanup files and update README
PhearZero Apr 22, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 60 additions & 0 deletions .decisions/3-Peer-to-Peer-Signaling.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# Overview

Communicating across platforms in a decentralized manner

## Decisions

- Limit dependency on WebSockets to signaling
- Allow bidirectional communication between peers
- Enforce locality of device?
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we enforce it?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could if we remove the STUN/TURN servers but we would lose a decent percentage of devices behind symmetric NAT

Copy link
Collaborator

@kylebeee kylebeee Apr 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is enforced locality even possible if apple / chrome sync passkeys across devices?

Not sure about chrome but apple really doesn't adhere to the standard well

https://www.slashid.dev/blog/passkeys-deepdive/#:~:text=Passkeys%20and%20traditional%20platform%20authenticator,event%20of%20a%20device%20compromise.

"impossible to verify the device type used to generate a key, and hence the trustworthiness of the key and its metadata. In fact, the lack of an attestation statement means that you can’t prove the key has been stored, or even generated, safely because you can’t infer properties/provenance of the authenticator."

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kylebeee Enforcing locality of the WebRTC peer channel, limiting discovery to only local addresses (no STUN/TURN)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if the decision is no enforcing locality we should remove this bullet IMO


## Implementation

A WebSocket Service should establish the SDP handshake and emit ICE candidates for WebRTC clients.

This implementation should replace Wallet Connect with the following sequence
```mermaid
sequenceDiagram
participant Website
participant Server
participant Wallet
Note over Website, Wallet: Link devices
Website->>Server: GET Challenge Message
Server->>Website: Send Challenge Message

Website-->>Website: Display QR Connect Nonce
Website->>Server: Subscribe to 'wss:link'
Wallet->>Website: Scan QR Code
Wallet->>Server: POST Nonce + Signature + Answer
Server-->>Server: Validate Signature
Server-->>Website: HTTPOnly Session
Server->>Wallet: Ok Response + HTTPOnly Session
Server->>Website: Emit to `wss:link` client
Note over Website, Wallet: Passkeys/FIDO2
Website-->>Website: Continue FIDO2 Flow
Wallet-->>Wallet: Continue FIDO2 Flow
Note over Website, Wallet: Signaling Peer Offer/Answer
Website-->>Server: Subscribe to 'wss:answer-${address}'
Wallet-->>Server: Subscribe to 'wss:offer-${address}'

Website-->>Website: Create Peer Offer & DataChannel
Website-->>Server: POST Offer
Server-->>Wallet: Emit Offer

Wallet-->>Wallet: Create Peer Answer with Offer & DataChannel

Wallet-->>Server: POST Answer
Server-->>Website: Emit Answer
Website-->>Website: Set Remote SDP
Website-->>Website: Discover ICE Candidates
Website->>Server: Emit candidates to `wss:offer-${address}`
Server->>Wallet: Emit candidates to `wss:offer-${address}`
Wallet-->>Wallet: Set Candidates
Wallet-->>Wallet: Discover ICE Candidates
Wallet->>Server: Emit candidates to `wss:answer-${address}`
Server->>Website: Emit to `wss:answer`
Website->>Website: Set Candidates

```

*Note: This process may be deprecated in the future in favor of `libp2p` which allows for an agnostic discovery layer and also supports the WebRTC transport
23 changes: 23 additions & 0 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: CI
on: [pull_request]
jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [ 18.x, 20.x ]
steps:
- name: Checkout
uses: actions/checkout@master
- name: Use Node.js
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- name: Install Dependencies
run: npm install
- name: Run Build
run: npm run build
- name: Lint Codebase
run: npm run lint
- name: Unit Tests with Coverage
run: npm run test:cov
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
swagger-codegen-cli.jar

.data
.idea

Expand Down
12 changes: 12 additions & 0 deletions client-gen.sh
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

couldn't find any mention of this in the readme

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is mostly in the docs branch to limit merge conflicts with the unit tests

Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@


CODEGEN=swagger-codegen-cli.jar
if [ -f $CODEGEN ]; then
echo "Codegen already exists"
else
echo "Downloading codegen"
wget https://repo1.maven.org/maven2/io/swagger/codegen/v3/swagger-codegen-cli/3.0.52/swagger-codegen-cli-3.0.52.jar -O swagger-codegen-cli.jar
fi

java -jar swagger-codegen-cli.jar generate -i http://localhost:3000/api-json -l typescript-fetch -o clients/liquid-auth-client-js/src/client
java -jar swagger-codegen-cli.jar generate -i http://localhost:3000/api-json -l kotlin-client -o clients/liquid-auth-client-kotlin
59 changes: 59 additions & 0 deletions clients/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# Overview

Client JSON-RPC interfaces are generated from OpenAPI 3.0 specifications.
All clients should mirror the same interfaces and include the same parameters (as much as possible).

```typescript
interface SignalClient {
readonly url: string; // Origin of the service
type: "offer" | "answer" // Type of client
peerClient: RTCPeerConnection | PeerClient // Native WebRTC Wrapper/Interface
socket: Socket // The socket to the service

readonly authenticated: boolean; // State of authentication
readonly requestId?: string; // The current request being signaled

/**
* Generate a Request ID
*/
generateRequestId(): any;

/**
* Top level Friendly interface for signaling
* @param args
*/
peer(requestId: any, type: 'offer' | 'answer', config?: RTCConfiguration): Promise<void>;

/**
* Link a Request ID to this client
* @param args
*/
link(...args: any[]): Promise<LinkMessage>;

/**
* Wait for a desciption signal
* @param args
*/
signal(...args: any[]): Promise<string>;

/**
* Terminate the signaling session
*/
close(): void


/**
* Listen to Interface events
* @param args
*/
on(...args: any[]): void;

/**
* Emit an event to the interface
* @param channel
* @param callback
*/
emit(channel: string, callback: (...args: any[])=>void)

}
```
22 changes: 22 additions & 0 deletions clients/liquid-auth-client-js/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"env": {
"browser": true,
"es2021": true,
"node": true
},
"parserOptions": {
"project": "tsconfig.json",
"sourceType": "module"
},
"plugins": [
"@typescript-eslint/eslint-plugin",
"eslint-plugin-tsdoc"
],
"extends": [
"plugin:@typescript-eslint/recommended",
"plugin:prettier/recommended"
],
"rules": {
"@typescript-eslint/no-explicit-any": "warn"
}
}
1 change: 1 addition & 0 deletions clients/liquid-auth-client-js/.gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
lib
docs

# Logs
logs
Expand Down
4 changes: 4 additions & 0 deletions clients/liquid-auth-client-js/.prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"singleQuote": true,
"trailingComma": "all"
}
34 changes: 24 additions & 10 deletions clients/liquid-auth-client-js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,29 +21,43 @@
"default": "./lib/connect.js",
"types": "./lib/connect.d.ts"
},
"./encoding": {
"default": "./lib/encoding.js",
"types": "./lib/encoding.d.ts"
"./signal": {
"default": "./lib/signal.js",
"types": "./lib/signal.d.ts"
},
"./errors": {
"default": "./lib/errors.js",
"types": "./lib/errors.d.ts"
}
},
"scripts": {
"dev": "tsc --watch",
"build": "tsc",
"preinstall": "npm run build",
"test": "tsc && c8 node --test ./tests/*.test.js"
"build:docs": "typedoc --plugin typedoc-plugin-markdown --out docs src",
"lint": "eslint --fix src",
"test": "tsc && node --test ./tests/*.spec.js",
"test:cov": "tsc && c8 node --test ./tests/*.spec.js"
},
"author": "",
"license": "MIT",
"devDependencies": {
"@types/qrcode": "^1.5.5",
"@typescript-eslint/eslint-plugin": "^6.21.0",
"@typescript-eslint/parser": "^7.6.0",
"algosdk": "^2.7.0",
"c8": "^9.1.0",
"typescript": "^5.3.3"
"eslint": "^8.57.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-prettier": "^5.1.3",
"eslint-plugin-tsdoc": "^0.2.17",
"typedoc": "^0.25.13",
"typedoc-plugin-markdown": "^4.0.0-next.55",
"typescript": "^5.4.5"
},
"dependencies": {
"qr-code-styling": "^1.6.0-rc.1"
},
"peerDependencies": {
"algosdk": "^2.7.0",
"@liquid/core": "^1.0.0",
"eventemitter3": "^5.0.1",
"qr-code-styling": "^1.6.0-rc.1",
"tweetnacl": "^1.0.3"
}
}
1 change: 1 addition & 0 deletions clients/liquid-auth-client-js/public/favicon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Loading