Skip to content

Commit ec44c26

Browse files
authored
Extract process of signing into a trait (#3696)
## Motivation Currently client processes own a private key (`AccountSecretKey`) which is potentially insecure but also prevents implementation of external signers (wallet extensions, hardware wallets, etc.). This PR addresses that. ## Proposal We achieve that by the introduction of a new `Signer` trait that encapsulates the actions of signing and getting a public key for an `AccountOwner` instance. A couple of other changes were made/introduced to support that: - `Signer` is passed around as `Box<dyn Signer>` to hide the implementation details of the actual `Signer` instance. - `Signer::sign` signs a `CryptoHash` (rather than `T: BcsSignable`). - (required by the above ☝️ ) New `sign_prehash(self, CryptoHash)` methods added on all secret keys types in the `linera-crypto` - An `InMemSigner` was introduced for backwards-compatibility and intermediate usage in native and web clients. - Removed `assigned_keys` and `unassignd_keys` from the `Wallet`. Now the `Signer` is the source of truth about which keys are available. ## Test Plan All tests have been updated to pass. ## Release Plan - Nothing to do / These changes follow the usual release cycle. ## Links <!-- Optional section for related PRs, related issues, and other references. If needed, please create issues to track future improvements and link them here. --> - [reviewer checklist](https://github.com/linera-io/linera-protocol/blob/main/CONTRIBUTING.md#reviewer-checklist)
1 parent d91699f commit ec44c26

File tree

55 files changed

+1754
-816
lines changed

Some content is hidden

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

55 files changed

+1754
-816
lines changed

.github/workflows/docker-compose.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,4 +72,4 @@ jobs:
7272
max_attempts: 10
7373
timeout_minutes: 2
7474
retry_wait_seconds: 10
75-
command: linera --wallet docker/wallet.json --storage rocksdb:docker/linera.db sync-balance
75+
command: linera --wallet docker/wallet.json --keystore docker/keystore.json --storage rocksdb:docker/linera.db sync-balance

.github/workflows/rust.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ env:
3333
RUST_LOG_FORMAT: plain
3434
LINERA_STORAGE_SERVICE: 127.0.0.1:1235
3535
LINERA_WALLET: /tmp/local-linera-net/wallet_0.json
36+
LINERA_KEYSTORE: /tmp/local-linera-net/keystore_0.json
3637
LINERA_STORAGE: rocksdb:/tmp/local-linera-net/client_0.db
3738
LINERA_FAUCET_URL: http://localhost:8079
3839

CLI.md

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ This document contains the help content for the `linera` command-line program.
99
* [`linera open-chain`](#linera-open-chain)
1010
* [`linera open-multi-owner-chain`](#linera-open-multi-owner-chain)
1111
* [`linera change-ownership`](#linera-change-ownership)
12+
* [`linera set-preferred-owner`](#linera-set-preferred-owner)
1213
* [`linera change-application-permissions`](#linera-change-application-permissions)
1314
* [`linera close-chain`](#linera-close-chain)
1415
* [`linera local-balance`](#linera-local-balance)
@@ -71,6 +72,7 @@ A Byzantine-fault tolerant sidechain with low-latency finality and high throughp
7172
* `open-chain` — Open (i.e. activate) a new chain deriving the UID from an existing one
7273
* `open-multi-owner-chain` — Open (i.e. activate) a new multi-owner chain deriving the UID from an existing one
7374
* `change-ownership` — Change who owns the chain, and how the owners work together proposing blocks
75+
* `set-preferred-owner` — Change the preferred owner of a chain
7476
* `change-application-permissions` — Changes the application permissions configuration
7577
* `close-chain` — Close an existing chain
7678
* `local-balance` — Read the current native-token balance of the given account directly from the local state
@@ -95,7 +97,7 @@ A Byzantine-fault tolerant sidechain with low-latency finality and high throughp
9597
* `create-application` — Create an application
9698
* `publish-and-create` — Create an application, and publish the required module
9799
* `keygen` — Create an unassigned key pair
98-
* `assign` — Link an owner with a key pair in the wallet to a chain that was created for that owner
100+
* `assign` — Link the owner to the chain. Expects that the caller has a private key corresponding to the `public_key`, otherwise block proposals will fail when signing with it
99101
* `retry-pending-block` — Retry a block we unsuccessfully tried to propose earlier
100102
* `wallet` — Show the contents of the wallet
101103
* `project` — Manage Linera projects
@@ -106,6 +108,7 @@ A Byzantine-fault tolerant sidechain with low-latency finality and high throughp
106108

107109
* `--storage <STORAGE_CONFIG>` — Storage configuration for the blockchain history
108110
* `--wallet <WALLET_STATE_PATH>` — Sets the file storing the private state of user chains (an empty one will be created if missing)
111+
* `--keystore <KEYSTORE_PATH>` — Sets the file storing the keystore state
109112
* `-w`, `--with-wallet <WITH_WALLET>` — Given an ASCII alphanumeric parameter `X`, read the wallet state and the wallet storage config from the environment variables `LINERA_WALLET_{X}` and `LINERA_STORAGE_{X}` instead of `LINERA_WALLET` and `LINERA_STORAGE`
110113
* `--send-timeout-ms <SEND_TIMEOUT>` — Timeout for sending queries (milliseconds)
111114

@@ -267,6 +270,19 @@ Specify the complete set of new owners, by public key. Existing owners that are
267270

268271

269272

273+
## `linera set-preferred-owner`
274+
275+
Change the preferred owner of a chain
276+
277+
**Usage:** `linera set-preferred-owner [OPTIONS] --owner <OWNER>`
278+
279+
###### **Options:**
280+
281+
* `--chain-id <CHAIN_ID>` — The ID of the chain whose preferred owner will be changed
282+
* `--owner <OWNER>` — The new preferred owner
283+
284+
285+
270286
## `linera change-application-permissions`
271287

272288
Changes the application permissions configuration
@@ -718,7 +734,7 @@ Create an unassigned key pair
718734

719735
## `linera assign`
720736

721-
Link an owner with a key pair in the wallet to a chain that was created for that owner
737+
Link the owner to the chain. Expects that the caller has a private key corresponding to the `public_key`, otherwise block proposals will fail when signing with it
722738

723739
**Usage:** `linera assign --owner <OWNER> --chain-id <CHAIN_ID>`
724740

Cargo.lock

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ FAUCET_URL=http://localhost:8080
9090

9191
# Set the path of the future wallet.
9292
export LINERA_WALLET="$LINERA_TMP_DIR/wallet.json"
93+
export LINERA_KEYSTORE="$LINERA_TMP_DIR/keystore.json"
9394
export LINERA_STORAGE="rocksdb:$LINERA_TMP_DIR/client.db"
9495

9596
# Initialize a new user wallet.

docker/compose.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ cleanup() {
1717
rm -r linera.db
1818
rm server.json
1919
rm wallet.json
20+
rm keystore.json
2021
SCYLLA_VOLUME=docker_linera-scylla-data
2122
SHARED_VOLUME=docker_linera-shared
2223
docker rm -f $(docker ps -a -q --filter volume=$SCYLLA_VOLUME)
@@ -63,7 +64,7 @@ linera-server generate --validators "$CONF_DIR/validator.toml" --committee commi
6364
# * Private chain states are stored in one local wallet `wallet.json`.
6465
# * `genesis.json` will contain the initial balances of chains as well as the initial committee.
6566

66-
linera --wallet wallet.json --storage rocksdb:linera.db create-genesis-config 10 --genesis genesis.json --initial-funding 10 --committee committee.json --testing-prng-seed 2
67+
linera --wallet wallet.json --keystore keystore.json --storage rocksdb:linera.db create-genesis-config 10 --genesis genesis.json --initial-funding 10 --committee committee.json --testing-prng-seed 2
6768

6869
if [ "${DOCKER_COMPOSE_WAIT:-false}" = "true" ]; then
6970
docker compose up --wait

examples/amm/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ Create the user wallet and add chains to it:
5454

5555
```bash
5656
export LINERA_WALLET="$LINERA_TMP_DIR/wallet.json"
57+
export LINERA_KEYSTORE="$LINERA_TMP_DIR/keystore.json"
5758
export LINERA_STORAGE="rocksdb:$LINERA_TMP_DIR/client.db"
5859

5960
linera wallet init --faucet $FAUCET_URL

examples/counter/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ Create the user wallet and add chains to it:
4343

4444
```bash
4545
export LINERA_WALLET="$LINERA_TMP_DIR/wallet.json"
46+
export LINERA_KEYSTORE="$LINERA_TMP_DIR/keystore.json"
4647
export LINERA_STORAGE="rocksdb:$LINERA_TMP_DIR/client.db"
4748

4849
linera wallet init --faucet $FAUCET_URL

examples/crowd-funding/README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,10 @@ Create the user wallets and add chains to them:
6666

6767
```bash
6868
export LINERA_WALLET_1="$LINERA_TMP_DIR/wallet_1.json"
69+
export LINERA_KEYSTORE_1="$LINERA_TMP_DIR/keystore_1.json"
6970
export LINERA_STORAGE_1="rocksdb:$LINERA_TMP_DIR/client_1.db"
7071
export LINERA_WALLET_2="$LINERA_TMP_DIR/wallet_2.json"
72+
export LINERA_KEYSTORE_2="$LINERA_TMP_DIR/keystore_2.json"
7173
export LINERA_STORAGE_2="rocksdb:$LINERA_TMP_DIR/client_2.db"
7274

7375
linera --with-wallet 1 wallet init --faucet $FAUCET_URL
@@ -81,7 +83,7 @@ OWNER_1="${INFO_1[2]}"
8183
OWNER_2="${INFO_2[2]}"
8284
```
8385

84-
Note that `linera --with-wallet 1` is equivalent to `linera --wallet "$LINERA_WALLET_1"
86+
Note that `linera --with-wallet 1` is equivalent to `linera --wallet "$LINERA_WALLET_1" --keystore "$LINERA_KEYSTORE_1"
8587
--storage "$LINERA_STORAGE_1"`.
8688

8789
The command below can be used to list the chains created for the test as known by each

examples/fungible/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ Create the user wallet and add chains to it:
5858

5959
```bash
6060
export LINERA_WALLET="$LINERA_TMP_DIR/wallet.json"
61+
export LINERA_KEYSTORE="$LINERA_TMP_DIR/keystore.json"
6162
export LINERA_STORAGE="rocksdb:$LINERA_TMP_DIR/client.db"
6263

6364
linera wallet init --faucet $FAUCET_URL

0 commit comments

Comments
 (0)