Skip to content

Commit b27a36a

Browse files
piyalbasuvcarl
andauthored
organizing based on Chrome's naming convention and ease of sharing code between components (#10)
* content script update * whitelist PR preview env * adding UI work for mnemonic phrase screen plus some url whitelisting improvemnents * rm debugger * implement UX fixes and design for mnemonic phrase views * PR comments * organizing based on Chrome's naming convention and ease of sharing code between components * remove session timer for rn * adding lyra status method placeholder * removing demo code * README update * README update * create an api/internal folder and add a sketch * Update README.md Co-authored-by: Carl Vitullo <vcarl@users.noreply.github.com> Co-authored-by: Carl Vitullo <vcarl@users.noreply.github.com>
1 parent f2d6ee2 commit b27a36a

File tree

49 files changed

+464
-407
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+464
-407
lines changed

README.md

Lines changed: 46 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,6 @@ This project builds a Chrome extension that handles authentication as well as a
77
playground calls the Lyra API exactly how a client site like
88
accountviewer.stellar.org would call it
99

10-
### Prerequesites
11-
12-
This project requires nodeJS https://nodejs.org/en/download/
13-
14-
After that, we will need Yarn to install our dependencies.
15-
16-
In Terminal, run
17-
18-
```
19-
brew install yarn
20-
```
21-
2210
### Install project dependencies
2311

2412
Navigate to this project folder in Terminal and run
@@ -70,3 +58,49 @@ yarn start
7058

7159
Done! You should be able to access the Playground by going to
7260
`http://lyraclient.com:9000/playground.html` in your browser
61+
62+
### Project Setup
63+
64+
This app has 3 main components that are named using Chrome extension
65+
nomenclature. All of these are located in the `src/` folder:
66+
67+
1. The UI that appears when you click on the Chrome extension in your browser.
68+
This code also controls the fullscreen authentiction flow and any popups
69+
triggered by the extension. This is all controlled by one React app. In
70+
Chrome parlance, this is called the `popup` and is therefore located in
71+
`src/popup`
72+
73+
2. The API that is exposed to client websites. This API is automatically
74+
injected into ANY website a user visits while they have Lyra installed. For
75+
security purposes, we whitelist specific domains that can _successfully_
76+
called API methods. Example: `laboratory.stellar.org` wants to interact with
77+
Lyra, perhaps to request a user's public key from the extension. A dev for
78+
`laboratory.stellar.org` would call this API to get that data from Lyra. In
79+
Chrome parlance, this is known as a `content script`. It is instantiated on a
80+
client website by `public/contentScript.js`. For clarity, and ease of sharing
81+
code, the API methods are defined in `src/lyraApi`.
82+
83+
3. The "backend" service. We want to do things like account creation and store
84+
sensitive data, like public keys, in a secure place away from the `popup` and
85+
away from the `content script`. We want this service to be a standalone
86+
entity that these other 2 can make requests to and receive only what the
87+
backend sees fit. In Chrome terms, this is known as the `background` script
88+
and is instantiated by `public/background`. The code is located in
89+
`src/background`.
90+
91+
This script is run by the Chrome extension on browser starts and continues
92+
running, storing data and listening/responding to messages from the other
93+
`popup` and `content script`, and only terminates on browser close (or extension
94+
uninstall/reload). It is run in a headless browser, so it has access to all Web
95+
APIs and Chrome APIs. It also has accessible dev tools, which can be reached by
96+
going to `chrome://extensions/` and clicking `inspect views: background page`
97+
98+
## Other parts of the codebase
99+
100+
All helpers, statics, etc. that are shared by the 3 components are located in
101+
the top level of `src`. This includes the `api` folder, which sends messages to
102+
the `background`. Both `popup` and `content script` can send to and receive from
103+
`background`.
104+
105+
The `public` folder contains all extension specific instantiation and assets. It
106+
also contains the code for the aforementioned `Playground`.

README.png

158 KB
Loading

background/backgroundComponents/messageListener.ts

Lines changed: 0 additions & 311 deletions
This file was deleted.

public/background.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import initMessageListener from "../background/backgroundComponents/messageListener";
1+
import initMessageListener from "../src/background";
22

33
chrome.runtime.onInstalled.addListener(() => {
44
chrome.declarativeContent.onPageChanged.removeRules(undefined, () => {

public/playground/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
</head>
1818
<body>
1919
<h1>Connect to Lyra and get user's public key</h1>
20-
<button id="lyra-connect">Lyra.connect()</button>
20+
<button id="lyra-connect">Lyra.getPublicKey()</button>
2121
<input type="text" readonly id="publicKey" />
2222
<br />
2323
<h1>Send funds from user's account to another account</h1>

0 commit comments

Comments
 (0)