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

Promote develop to master #120

Merged
merged 34 commits into from
Sep 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
ce15ab8
Add speculos container script
shanejearley Aug 11, 2022
48f19f3
Add ledger-app-builder
shanejearley Aug 15, 2022
06a5a8e
Add ledger apps and speculos submodules
shanejearley Aug 18, 2022
3680334
Add m1 speculos builder
shanejearley Aug 18, 2022
c952ac8
Add bitcoin and remove cosmos and iotex apps
shanejearley Aug 18, 2022
b3ee7c3
Update README.md with supported ledger apps
shanejearley Aug 18, 2022
5c00ca9
Add ledger test seed
shanejearley Aug 21, 2022
3cebfdc
Add browser compatible hardware transport for ledger emulator
shanejearley Sep 6, 2022
74e577e
Add ledger flag and launch to dev script
shanejearley Sep 6, 2022
ff373d5
Add proxy port to public env variables
shanejearley Sep 6, 2022
c5baaa9
Fix ledger transport package
shanejearley Sep 6, 2022
6c91d49
Fix merge conflicts
shanejearley Sep 6, 2022
331a964
Merge develop
shanejearley Sep 6, 2022
d6d37bb
Add ledger account to hardhat localnet
shanejearley Sep 6, 2022
7320576
Change --ledger to --speculos
shanejearley Sep 7, 2022
71c8700
Remove extra PUBLIC_SPECULOS env variable
shanejearley Sep 7, 2022
e252670
Fix merge conflicts
shanejearley Sep 9, 2022
1941633
Add docker to prerequisites
shanejearley Sep 9, 2022
24aaf8f
Add submodules update to ledger emulator
shanejearley Sep 9, 2022
ba6faf4
Add submodules pull to ledger emulator
shanejearley Sep 9, 2022
636e4ca
Fix ledger scripts
shanejearley Sep 9, 2022
6e27ef8
Fix push workflow
shanejearley Sep 9, 2022
c7f7d2c
Complete retrieveLastBlock
hawyar Sep 9, 2022
1a51261
Add more graceful shutdown of dev script subprocesses
shanejearley Sep 11, 2022
f8bb823
Fix proxy command in speculos script handler
shanejearley Sep 12, 2022
cf33c49
Switch pwd command with realpath
shanejearley Sep 12, 2022
0ea6cd0
Add GitHub ssh note to prerequesites
shanejearley Sep 12, 2022
f4fae62
Remove extra whitespace in README.md
shanejearley Sep 12, 2022
3578539
Update schema, change amount from integer to string
hawyar Sep 12, 2022
6917c1a
Catch all amount keys
hawyar Sep 12, 2022
9c5c5bd
Merge pull request #115 from consensusnetworks/feature/ledger-emulator
shanejearley Sep 12, 2022
2566f37
Merge pull request #119 from consensusnetworks/feature/iotex-etl
hawyar Sep 13, 2022
75ee400
Remove diagrams notebook
shanejearley Sep 13, 2022
6488a07
Merge pull request #121 from consensusnetworks/enhancement/migrate-di…
shanejearley Sep 13, 2022
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
3 changes: 1 addition & 2 deletions .github/workflows/push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@ jobs:
run: npm ci

- name: Build helpers
run: npm run build
working-directory: common/helpers
run: npm run build --workspace @casimir/helpers

- name: Build landing app
run: npm run build --workspace @casimir/landing
Expand Down
12 changes: 12 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[submodule "scripts/ledger/resources/app-bitcoin"]
path = scripts/ledger/resources/app-bitcoin
url = https://github.com/LedgerHQ/app-bitcoin-new.git
[submodule "scripts/ledger/resources/app-ethereum"]
path = scripts/ledger/resources/app-ethereum
url = https://github.com/LedgerHQ/app-ethereum.git
[submodule "scripts/ledger/resources/app-solana"]
path = scripts/ledger/resources/app-solana
url = https://github.com/LedgerHQ/app-solana.git
[submodule "scripts/ledger/resources/speculos"]
path = scripts/ledger/resources/speculos
url = https://github.com/LedgerHQ/speculos.git
29 changes: 22 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,13 @@ Make sure your development environment has these prerequisites.

1. [Node.js (v16.x)](https://nodejs.org/en/download/) – we use [nvm](https://github.com/nvm-sh/nvm) to manage Node.js versions.

2. [AWS CLI (v2.x)](https://aws.amazon.com/cli/) – create an [AWS profile](https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-profiles.html) named `consensus-networks-dev`.
2. [Docker (v4.x)](https://docs.docker.com/engine/install/) - make sure your Docker runs on startup.

3. [SAM CLI (v1.x)](https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-sam-cli-install-mac.html) - tool for mocking backend services locally.
3. [AWS CLI (v2.x)](https://aws.amazon.com/cli/) – create an [AWS profile](https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-profiles.html) named `consensus-networks-dev`.

4. [SAM CLI (v1.x)](https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-sam-cli-install-mac.html) - tool for mocking backend services locally.

> 🚩 You also need to make sure to have at least one SSH authentication key on your GitHub account (for the git cloning of submodules in various scripts). See [Adding a new SSH key to your GitHub account](https://docs.github.com/en/authentication/connecting-to-github-with-ssh/adding-a-new-ssh-key-to-your-github-account).

### Scripts and Dependencies

Expand Down Expand Up @@ -70,7 +74,15 @@ You can get up and running without configuration. You can also mock local backen

> 🚩 You will need the [SAM CLI](https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-sam-cli-install-mac.html) for local mocking.

3. The commands and flags above apply to any package in the [apps](apps/) directory. While the default app is [@casimir/web](apps/web/), you can specify others by passing a subcommand to `npm run dev`.
3. Emulate a Ledger hardware wallet with [Speculos](#speculos). The default application is ethereum, and we also currently have support for the bitcoin and solana applications.

```zsh
npm run dev --speculos # or specify --speculos=ethereum, --speculos=bitcoin, or --speculos=solana
```

> 🚩 On MacOS, if you get an error because port 5000 is in use, go to  > System Preferences... > Sharing and uncheck Airplay Receiver.

4. The commands and flags above apply to any package in the [apps](apps/) directory. While the default app is [@casimir/web](apps/web/), you can specify others by passing a subcommand to `npm run dev`.

```zsh
# @casimir/web
Expand Down Expand Up @@ -109,14 +121,17 @@ EVM contract development is serviced through [Hardhat](https://hardhat.io/). The
npm run task:accounts
```

*Todo finish sample flow (show usage of compiled contract ABI in app)*
6. Use a contract in a Casimir app...
6. Use a contract in a Casimir app.

7. Clean [contracts/evm/build/artifacts](contracts/evm/build/artifacts) and [contracts/evm/build/cache](contracts/evm/build/cache)).
```typescript
// Todo add Casimir Typescript usage
```

7. Clean [contracts/evm/build/artifacts](contracts/evm/build/artifacts) and [contracts/evm/build/cache](contracts/evm/build/cache)).

```zsh
npm run task:clean
```
```

> 🚩 Note, this is required if you change the Hardhat configuration.

Expand Down
2 changes: 1 addition & 1 deletion apps/landing/src/composables/users.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export default function useUsers() {
* @returns {string} The base URL for the users API
*/
function getUsersBaseUrl(): string {
if (import.meta.env.PUBLIC_MOCK_ENABLED) {
if (import.meta.env.PUBLIC_MOCK) {
return `http://localhost:${import.meta.env.PUBLIC_USERS_PORT}`
} else {
return `https://users.${import.meta.env.PUBLIC_STAGE || 'dev'}.casimir.co`
Expand Down
3 changes: 2 additions & 1 deletion apps/landing/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import { createRouter, createWebHistory } from 'vue-router'
import routes from '~pages'

console.log('Creating app...', import.meta.env)
console.log('Local mocking is', import.meta.env.PUBLIC_MOCK_ENABLED ? 'enabled' : 'disabled')
console.log('Local mocking is', import.meta.env.PUBLIC_MOCK ? 'enabled' : 'disabled')
console.log('Ledger emulator is', import.meta.env.PUBLIC_SPECULOS_PORT ? 'enabled' : 'disabled')

const app = createApp(App)
const router = createRouter({
Expand Down
4 changes: 4 additions & 0 deletions apps/web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
},
"dependencies": {
"@heroicons/vue": "^1.0.6",
"@ledgerhq/hw-app-eth": "^6.29.4",
"@ledgerhq/hw-transport-webhid": "^6.27.2",
"buffer": "^6.0.3",
"ethers": "^5.6.9",
"iotex-antenna": "^0.31.3",
"vue": "^3.2.25",
Expand All @@ -18,6 +21,7 @@
"devDependencies": {
"@esbuild-plugins/node-globals-polyfill": "^0.1.1",
"@esbuild-plugins/node-modules-polyfill": "^0.1.4",
"@rollup/plugin-inject": "^4.0.4",
"@vitejs/plugin-vue": "^2.3.3",
"autoprefixer": "^10.4.7",
"postcss": "^8.4.14",
Expand Down
38 changes: 32 additions & 6 deletions apps/web/src/components/Wallet.vue
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@
</p>
</div>
<div class="coinbase-div">
<button class="coinbase-btn" @click="connectWallet('CoinbaseWallet')">
<button
class="coinbase-btn"
@click="connectWallet('CoinbaseWallet')"
>
{{ coinbaseButtonText }}
</button>
<p>
Expand All @@ -20,23 +23,42 @@
</p>
</div>
<div class="ioPay-div">
<button class="iopay-btn" @click="connectWallet('IoPay')">
<button
class="iopay-btn"
@click="connectWallet('IoPay')"
>
{{ ioPayButtonText }}
</button>
<p>
Connected ioPay Account:
<span> {{ ioPayAccountsResult }} </span>
</p>
</div>
<button
class="ledger-btn"
@click="connectWallet('Ledger')"
>
Connect Ledger
</button>
</div>
<div class="form-container">
<form @submit.prevent="sendTransaction(selectedProvider)">
<label for="address">Address</label>
<input v-model="toAddress" type="text" placeholder="To Address" />
<br />
<input
v-model="toAddress"
type="text"
placeholder="To Address"
>
<br>
<label for="amount">Amount</label>
<input v-model="amount" type="text" placeholder="Amount Ether" />
<button type="submit">Send Transaction</button>
<input
v-model="amount"
type="text"
placeholder="Amount Ether"
>
<button type="submit">
Send Transaction
</button>
</form>
</div>
</div>
Expand Down Expand Up @@ -127,6 +149,10 @@ button {
background-color: rgb(0, 218, 180);
}

.ledger-btn {
background-color: rgb(0, 0, 0);
}

.connect-wallet-container {
display: flex;
flex-direction: column;
Expand Down
26 changes: 26 additions & 0 deletions apps/web/src/composables/ledger.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import SpeculosHttpTransport from '@casimir/hw-transport-speculos'
import TransportWebHID from '@ledgerhq/hw-transport-webhid'
import Eth from '@ledgerhq/hw-app-eth'

export default function useLedger() {

const bip32Path = '44\'/60\'/0\'/0/0'

async function getLedgerEthSigner() {
const transport = await _getLedgerTransport()
return new Eth(transport)
}

async function _getLedgerTransport() {
if (import.meta.env.PUBLIC_SPECULOS_PORT) {
return await SpeculosHttpTransport.open(`http://127.0.0.1:${import.meta.env.PUBLIC_SPECULOS_PORT}`)
} else {
return await TransportWebHID.create()
}
}

return {
bip32Path,
getLedgerEthSigner
}
}
16 changes: 16 additions & 0 deletions apps/web/src/composables/wallet.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { ref } from 'vue'
import { ethers } from 'ethers'
import useIoPay from '@/composables/iopay'
import useLedger from '@/composables/ledger'
import useEthers from '@/composables/ethers'
import { BrowserProviders } from '@/interfaces/BrowserProviders'
import { EthersProvider } from '@/interfaces/EthersProvider'
Expand All @@ -21,6 +22,7 @@ const ethersProviderList = ['MetaMask', 'CoinbaseWallet']

export default function useWallet() {
const { getIoPayAccounts, sendIoPayTransaction } = useIoPay()
const { bip32Path, getLedgerEthSigner } = useLedger()
const ethereum: any = window.ethereum
const availableProviders = ref<BrowserProviders>(
getBrowserProviders(ethereum)
Expand Down Expand Up @@ -50,6 +52,11 @@ export default function useWallet() {
const accounts = await getIoPayAccounts()
const { address } = accounts[0]
setSelectedAccount(address)
} else if (provider === 'Ledger') {
const ledgerEth = await getLedgerEthSigner()
const { address } = await ledgerEth.getAddress(bip32Path)
console.log(address)
setSelectedAccount(address)
} else {
throw new Error('No provider selected')
}
Expand All @@ -76,6 +83,15 @@ export default function useWallet() {
})
} else if (selectedProvider.value === 'IoPay') {
await sendIoPayTransaction(toAddress.value, amount.value)
} else if (selectedProvider.value === 'Ledger') {

// npm run dev:ethereum in another process
// const ledgerEth = await getLedgerEthSigner()
// Create - { to: ... }
// Serialize - ethers.utils.serializeTransaction
// Sign - ledgerEth.signTransaction
// Send - (new ethers.providers.JsonRpcProvider("http://127.0.0.1:8545")).sendTransaction

} else {
throw new Error('Provider selected not yet supported')
}
Expand Down
2 changes: 1 addition & 1 deletion apps/web/src/types/ProviderString.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
import { BrowserProviders } from '@/interfaces/BrowserProviders'
export type ProviderString = keyof BrowserProviders | 'IoPay' | ''
export type ProviderString = keyof BrowserProviders | 'IoPay' | 'Ledger' |''
16 changes: 8 additions & 8 deletions apps/web/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@ import { UserConfig } from 'vite'
import { fileURLToPath } from 'url'
import * as path from 'path'
import pages from 'vite-plugin-pages'

import NodeModulesPolyfills from '@esbuild-plugins/node-modules-polyfill'
import NodeGlobalsPolyfillPlugin from '@esbuild-plugins/node-globals-polyfill'
import inject from '@rollup/plugin-inject'

const config: UserConfig = {
plugins: [
Expand All @@ -14,20 +13,21 @@ const config: UserConfig = {
dirs: [{ dir: 'src/pages', baseRoute: '' }],
extensions: ['vue'],
}),
inject({
Buffer: ['buffer', 'Buffer']
}) as Plugin // https://github.com/rollup/plugins/issues/1243
],
define: {
'window.global': 'globalThis'
'global': 'globalThis'
},
optimizeDeps: {
include: ['iotex-antenna'],
esbuildOptions: {
plugins: [
NodeModulesPolyfills(),
NodeGlobalsPolyfillPlugin({
process: true,
buffer: true,
define: true,
}),
buffer: true
})
],
},
},
Expand All @@ -39,7 +39,7 @@ const config: UserConfig = {
resolve: {
alias: {
'@': path.resolve(path.dirname(fileURLToPath(import.meta.url)), 'src'),
'./runtimeConfig': './runtimeConfig.browser',
'./runtimeConfig': './runtimeConfig.browser'
},
extensions: [
'.js',
Expand Down
54 changes: 30 additions & 24 deletions common/data/notebooks/athena/main.ipynb

Large diffs are not rendered by default.

Binary file removed common/data/notebooks/diagrams/_etl.png
Binary file not shown.
Binary file removed common/data/notebooks/diagrams/_ssv.png
Binary file not shown.
239 changes: 0 additions & 239 deletions common/data/notebooks/diagrams/main.ipynb

This file was deleted.

Binary file removed common/data/notebooks/diagrams/resources/casimir.png
Binary file not shown.
Binary file not shown.
Binary file removed common/data/notebooks/diagrams/resources/cosmos.png
Binary file not shown.
Binary file not shown.
Binary file removed common/data/notebooks/diagrams/resources/iotex.png
Binary file not shown.
Binary file removed common/data/notebooks/diagrams/resources/ssv.png
Binary file not shown.
1 change: 0 additions & 1 deletion common/data/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ python-dotenv = "^0.20.0"
s3fs = "^2022.7.1"
matplotlib = "^3.5.2"
pandas = "^1.4.3"
diagrams = "^0.21.1"

[tool.poetry.dev-dependencies]
jupyter = "^1.0.0"
Expand Down
5 changes: 4 additions & 1 deletion common/data/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,12 @@ export function schemaToGlueColumns(jsonSchema: JsonSchema): glue.Column[] {

let type: glue.Type = glue.Schema[typeKey]

if (name.endsWith('_at')) type = glue.Schema.DATE
if (name.endsWith('at')) type = glue.Schema.DATE

if (name === 'candidate_list') type = glue.Schema.array(glue.Schema.STRING)

if (name.endsWith('amount')) type = glue.Schema.BIG_INT

const comment = property.description
return { name, type, comment }
})
Expand Down
2 changes: 1 addition & 1 deletion common/data/src/schemas/event.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
"description": "The list of candidates in a stake action"
},
"amount": {
"type": "integer",
"type": "string",
"description": "The amount of the currency in the event"
},
"duration":{
Expand Down
2 changes: 2 additions & 0 deletions common/hw-transport-speculos/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules/
dist/
13 changes: 13 additions & 0 deletions common/hw-transport-speculos/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"name": "@casimir/hw-transport-speculos",
"version": "0.0.1",
"main": "src/index.ts",
"dependencies": {
"@ledgerhq/hw-transport": "^6.27.2"
},
"scripts": {
"dev": "npx esno src/index.ts",
"build": "esbuild src/index.ts --bundle --minify --sourcemap --platform=node --target=esnext --outfile=dist/index.js",
"test": "echo \"Error: no test specified\" && exit 1"
}
}
Loading