From acd4791355b622f17a348b2301250e75a17975b4 Mon Sep 17 00:00:00 2001 From: Prathamesh Musale Date: Wed, 14 Aug 2024 05:32:08 +0000 Subject: [PATCH] Accept keys with or without hex prefix (#75) Part of [laconicd testnet validator enrollment](https://www.notion.so/laconicd-testnet-validator-enrollment-6fc1d3cafcc64fef8c5ed3affa27c675) Reviewed-on: https://git.vdb.to/cerc-io/laconic-registry-cli/pulls/75 Co-authored-by: Prathamesh Musale Co-committed-by: Prathamesh Musale --- README.md | 10 +++++++++- package.json | 2 +- src/util/common.ts | 7 ++++++- 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index a5c6825..9179151 100644 --- a/README.md +++ b/README.md @@ -54,7 +54,15 @@ Registering records in registry requires an account. To get account private key laconicd keys export alice --keyring-backend test --unarmored-hex --unsafe ``` -In `config.yml` file assign the account private key to `userKey`. +In `config.yml` file assign the account private key to `userKey`: + +```yml +services: + registry: + .. + userKey: "" + .. +``` ## Gas and Fees diff --git a/package.json b/package.json index 10d149d..5a6e29c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@cerc-io/laconic-registry-cli", - "version": "0.2.3", + "version": "0.2.4", "main": "index.js", "repository": "git@github.com:cerc-io/laconic-registry-cli.git", "author": "", diff --git a/src/util/common.ts b/src/util/common.ts index 0c1923b..cc0bdd6 100644 --- a/src/util/common.ts +++ b/src/util/common.ts @@ -6,11 +6,16 @@ export const getConnectionInfo = (argv: Arguments, config: any) => { const result = { ...config, + userKey: stripHexPrefix(config.userKey), ...clean({ server, userKey, bondId, txKey, chainId }), - privateKey: txKey || userKey || config.userKey, + privateKey: stripHexPrefix(txKey || userKey || config.userKey), gas: String(gas || config.gas), fees: String(fees || config.fees) }; return result; }; + +function stripHexPrefix (hex: string): string { + return hex && hex.startsWith('0x') ? hex.slice(2) : hex; +}