Skip to content

Commit

Permalink
improve keystore keys network spec by allowing to specify custom key …
Browse files Browse the repository at this point in the history
…types and their schemas
  • Loading branch information
klbrvik committed Sep 25, 2023
1 parent 4709732 commit 0c752a9
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 4 deletions.
24 changes: 24 additions & 0 deletions docs/src/network-definition-spec.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ The network config can be provided both in `json` or `toml` format and each sect
- `rpc_port`: (number) RPC port to use;
- `prometheus_port`: (number) Prometheus port to use;
- `prometheus_prefix`: A parameter for customizing the metric's prefix for the specific node. Will apply only to this node; Defaults to 'substrate'.
- `keystore_key_types`: Defines which keystore keys should be created, for more details checkout details below.
- `node_groups`:
- `*name`: (String) Group name, used for naming the nodes (e.g name-1)
- `*count` (Number), Number of `nodes` to launch for this group.
Expand Down Expand Up @@ -94,6 +95,7 @@ The network config can be provided both in `json` or `toml` format and each sect
- `env`: Array of env vars Object to set in the container.
- name: (String) name of the `env` var.
- value: (String| number) Value of the env var.
- `keystore_key_types`: Defines which keystore keys should be created, for more details checkout details below.

- `collator_groups`:

Expand Down Expand Up @@ -121,3 +123,25 @@ The network config can be provided both in `json` or `toml` format and each sect
## `types`

- Object to use as `user defined types` with the js api.

## `keystore_key_types`

- There are 2 ways to specify key, values that don't respect below format will be ignored:
- short: `audi` - creates `audi` key type that defaults to predefined schema, it predefined schema for given key type doesn't exist it is ignored
- long: `audi_sr` - creates `audi` key type with `sr` schema

- Schemas: `ed`, `ec`, `sr`

- Predefined key type schemas:
- `aura` - `sr` if statemint or asset hub polkadot parachain, otherwise `ed`
- `babe` - `sr`
- `imon` - `sr`
- `gran` - `ed`
- `audi` - `sr`
- `asgn` - `sr`
- `para` - `sr`
- `beef` - `ec`
- `nmbs` - `sr`
- `rand` - `sr`
- `rate` - `ed`
- `acco` - `sr`
25 changes: 21 additions & 4 deletions javascript/packages/orchestrator/src/keys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import {
} from "@polkadot/util-crypto";
import { makeDir } from "@zombienet/utils";
import fs from "fs";
import { DEFAULT_KEYSTORE_KEY_TYPES } from "./constants";
import { Node } from "./sharedTypes";

function nameCase(string: string) {
Expand Down Expand Up @@ -92,9 +91,27 @@ export async function generateKeystoreFiles(
rate: node.accounts.ed_account.publicKey, // Equilibrium rate module
};

node.keystoreKeyTypes?.forEach((key_type: string) => {
if (DEFAULT_KEYSTORE_KEY_TYPES.includes(key_type))
keystore_key_types[key_type] = default_keystore_key_types[key_type];
// 2 ways keys can be defined:
node.keystoreKeyTypes?.forEach((key_spec) => {
// short: by only 4 letter key type with defaulted scheme e.g. "audi", if default scheme doesn't exist it is "ed"
if (key_spec.length === 4) {
keystore_key_types[key_spec] =
default_keystore_key_types[key_spec] ||
node.accounts.ed_account.publicKey;
}

// long: 4 letter key type with scheme separated by underscore e.g. "audi_sr"
const [key_type, key_scheme] = key_spec.split("_");
if (key_type.length === 4) {
if (key_scheme === "ed") {
keystore_key_types[key_type] = node.accounts.ed_account.publicKey;
} else if (key_scheme === "ec") {
keystore_key_types[key_type] = node.accounts.ec_account.publicKey;
}
if (key_scheme === "sr") {
keystore_key_types[key_type] = node.accounts.sr_account.publicKey;
}
}
});

if (Object.keys(keystore_key_types).length === 0)
Expand Down

0 comments on commit 0c752a9

Please sign in to comment.