-
Notifications
You must be signed in to change notification settings - Fork 40
feat: add rofl key genearation use case #1478
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
base: main
Are you sure you want to change the base?
Conversation
✅ Deploy Preview for oasisprotocol-docs ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
44e18a5
to
cef9dea
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
First pass
@@ -0,0 +1,576 @@ | |||
--- | |||
description: Generate an EVM key inside ROFL via appd and use it to sign and send transactions on Base. | |||
tags: [ROFL, appd, keys, EVM] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think KMS
became a standard term now for managing the keys.
tags: [ROFL, appd, keys, EVM] | |
tags: [ROFL, appd, KMS, EVM] |
```shell | ||
oasis rofl init rofl-keygen | ||
cd rofl-keygen | ||
```` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
```` | |
``` |
src/ | ||
appd.ts # talks to appd over /run/rofl-appd.sock | ||
evm.ts # ethers helpers (provider, wallet, tx) | ||
keys.ts # tiny helpers (checksum) | ||
server.ts # HTTP API to drive the demo | ||
contracts/ | ||
Counter.sol # optional sample contract |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's us the standard tree
command-like project structure style.
src/ | |
appd.ts # talks to appd over /run/rofl-appd.sock | |
evm.ts # ethers helpers (provider, wallet, tx) | |
keys.ts # tiny helpers (checksum) | |
server.ts # HTTP API to drive the demo | |
contracts/ | |
Counter.sol # optional sample contract | |
src/ | |
├── appd.ts # talks to appd over /run/rofl-appd.sock | |
├── evm.ts # ethers helpers (provider, wallet, tx) | |
├── keys.ts # tiny helpers (checksum) | |
└── server.ts # HTTP API to drive the demo | |
contracts/ | |
└── Counter.sol # optional sample contract |
npm init -y | ||
npm i express ethers zod dotenv | ||
npm i -D typescript tsx @types/node @types/express hardhat | ||
npx tsc --init --rootDir src --outDir dist --module NodeNext --target ES2022 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd just use hardhat init
and select typescript. Then install any extra deps. See how we did it for Sapphire: https://github.com/oasisprotocol/sapphire-paratime/blob/main/docs/quickstart.mdx#init-a-new-hardhat-project
@@ -0,0 +1,576 @@ | |||
--- | |||
description: Generate an EVM key inside ROFL via appd and use it to sign and send transactions on Base. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For those who don't know what EVM stands for.
description: Generate an EVM key inside ROFL via appd and use it to sign and send transactions on Base. | |
description: Generate an Ethereum-compatible key inside ROFL via appd and use it to sign and send transactions on Base. |
}); | ||
} | ||
|
||
export async function getEvmPrivateKey(keyId: string): Promise<string> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Follow best security practices and use SecretKey
instead of PrivateKey
.
export async function getEvmPrivateKey(keyId: string): Promise<string> { | |
export async function getEvmSecretKey(keyId: string): Promise<string> { |
export function privateKeyToWallet(pkHex: string): Wallet { | ||
return new Wallet(pkHex); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
export function privateKeyToWallet(pkHex: string): Wallet { | |
return new Wallet(pkHex); | |
} | |
export function secretKeyToWallet(skHex: string): Wallet { | |
return new Wallet(skHex); | |
} |
|
||
</details> | ||
|
||
### `src/server.ts` — minimal HTTP API |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think running another HTTP API is not a good idea. There is a REST server already running and accessible at /run/rofl/appd.sock
for this purpose.
Users that want to have EVM-signing capability would need to integrate your HTTP API anyway, so why not connecting to appd directly? Instead of server.ts I'd write a simple test that uses appd, get the key, sign an EVM transaction and submit it to Base.
1. **Get App ID** | ||
|
||
```shell | ||
curl -s https://YOUR-PROXY/app-id | jq |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
YOUR_PROXY
is the machine name defined in compose.yaml. Also, https won't work out of the box since the domain is not managed by CA and self-signed certs are not allowed.
Closes oasisprotocol/oasis-sdk#2298
This PR:
appd
RESTThe example repo can be found here: https://github.com/uniyalabhishek/demo-rofl-keygen