Fulfill requests from CLI
Overview
This is a step-by-step guide explaining how to fulfill key and signature requests with your Keychain from the command line.
You'll interact with the node through node commands. For generating keys and signing messages, you'll use CLIChain – a command-line tool for managing cryptographic keys and operations.
You can either run a local chain to test your configuration or interact with Chiado testnet. In the provided code snippets, you'll find tabs with different versions of node commands.
Learn more:
- For a list of CLIChain commands, see Implementation: CLIChain.
- To learn more about key and signature requests, see Request flow.
Prerequisites
If you wish to operate a Keychain locally, complete the following prerequisites:
-
Run a local chain. If you used manual configuration, make sure you created a Space.
-
Create a Keychain. You can skip it if you used our
just
script to run the node with default settings.
To operate a Keychain on Chiado, complete these prerequisites:
-
Create a Keychain. These steps involve creating an account (key) on Chiado.
-
Use your key to create a Space:
wardend tx warden new-space \
--from my-key-name \
--fees 400000000award \
--chain-id chiado_1001-1 \
--node https://rpc.chiado.wardenprotocol.org:443 -
Query Spaces. The list will contain Space IDs and account addresses. You should note down the Space ID associated with your address.
wardend query warden spaces \
--node https://rpc.chiado.wardenprotocol.org:443
1. Install CLIChain
To install CLIChain, navigate to the wardenprotocol
directory and run this:
go install ./cmd/clichain
2. Export variables
The next steps require that you export your node and Keychain settings as environment variables. If you used our just
script to run the node, you can export the predefined settings. Otherwise, use custom values.
- Local node: default settings
- Local node: custom settings
- Chiado
export CHAIN_ID=warden_1337-1
export KEY_NAME=shulgin
export SPACE_ID=1
export KEYCHAIN_ID=1
export KEYCHAIN_WRITER_NAME=shulgin
export CHAIN_ID=chain_123-1
export KEY_NAME=my-key-name
export SPACE_ID=1
export KEYCHAIN_ID=1
export KEYCHAIN_WRITER_NAME=my-keychain-writer-name
export CHAIN_ID=chiado_10010-1
export KEY_NAME=my-key-name
export SPACE_ID=1
export KEYCHAIN_ID=1
export KEYCHAIN_WRITER_NAME=my-keychain-writer-name
export RPC_URL=https://rpc.chiado.wardenprotocol.org:443
CHAIN_ID
: The chain ID you used when running a node.
Returned bywardend status
in thenetwork
field.KEY_NAME
: Your local account name, or key name.
Returned bywardend keys list
.SPACE_ID
: Your Space ID.
Returned bywardend query warden spaces
.KEYCHAIN_ID
: Your Keychain ID obtained when registering a Keychain.
Returned bywardend query warden keychains
in theid
field.KEYCHAIN_WRITER_NAME
: Your Keychain Writer name specified when adding a Keychain Writer.
Returned bywardend keys list
.RPC_URL
: The RPC URL for interacting with Chiado.
3. Fulfill a key request
When a user requests a new key, the Keychain generates a new private key, stores it securely, and submits the public key to the chain. To test this flow, take the steps below.
-
Request a new key:
- Local node
- Chiado
wardend tx warden new-action new-key-request \
--from $KEY_NAME \
--space-id $SPACE_ID \
--keychain-id $KEYCHAIN_ID \
--key-type KEY_TYPE_ECDSA_SECP256K1 \
-y \
--chain-id $CHAIN_ID \
| wardend query wait-txwardend tx warden new-action new-key-request \
--from $KEY_NAME \
--space-id $SPACE_ID \
--keychain-id $KEYCHAIN_ID \
--key-type KEY_TYPE_ECDSA_SECP256K1 \
--fees 400000000award \
-y \
--chain-id $CHAIN_ID \
--node $RPC_URL -
Get all key requests:
- Local node
- Chiado
wardend query warden key-requests --keychain-id $KEYCHAIN_ID
wardend query warden key-requests --keychain-id $KEYCHAIN_ID --node $RPC_URL
Your request ID will be returned in the
id
field of the output:key_requests:
- creator: warden1d652c9nngq5cneak2whyaqa4g9ehr8pstxj0r5
deducted_keychain_fees: []
id: "1"
key_type: KEY_TYPE_ECDSA_SECP256K1
keychain_id: "1"
space_id: "1"
status: KEY_REQUEST_STATUS_PENDING
pagination:
total: "1" -
Export the request ID using the command below. Replace
1
with the actual ID you obtained.export KEY_REQUEST_ID=1
-
Use the CLIChain
generate
command to generate the key:clichain generate -o private_$KEY_REQUEST_ID.key
-
Export the public key, derived with the CLIChain
public-key
command:export PUBLIC_KEY=$(go run ./cmd/clichain public-key -k private_$KEY_REQUEST_ID.key -o base64)
-
Fulfill the request by submitting a transaction from the Keychain Writer account:
- Local node
- Chiado
wardend tx warden fulfill-key-request $KEY_REQUEST_ID $PUBLIC_KEY \
--from $KEYCHAIN_WRITER_NAME \
--chain-id $CHAIN_IDwardend tx warden fulfill-key-request $KEY_REQUEST_ID $PUBLIC_KEY \
--from $KEYCHAIN_WRITER_NAME \
--fees 400000000award \
--chain-id $CHAIN_ID \
--node $RPC_URL -
Check the request status to make sure it was fulfilled:
- Local node
- Chiado
wardend query warden key-request-by-id --id=$KEY_REQUEST_ID
wardend query warden key-request-by-id --id=$KEY_REQUEST_ID --node $RPC_URL
Your request status will be returned in the
status
field of the output:key_request:
creator: warden1d652c9nngq5cneak2whyaqa4g9ehr8pstxj0r5
deducted_keychain_fees: []
id: "1"
key_type: KEY_TYPE_ECDSA_SECP256K1
keychain_id: "1"
space_id: "1"
status: KEY_REQUEST_STATUS_FULFILLED
4. Fulfill a signature request
When a user requests a signature, the Keychain signs a message with the private key and submits the signature to the chain. To test this flow, take the steps below. We'll create a signature using the key generated in the previous step.
-
Create a signature request:
- Local node
- Chiado
wardend tx warden new-action new-sign-request \
--from $KEY_NAME \
--input "MrT1dvxgez7QoVFudyVn5S8xCTJjxUi5xxZyWHcji5Q=" \
--key-id $KEY_REQUEST_ID \
-y \
--chain-id $CHAIN_ID \
| wardend query wait-txwardend tx warden new-action new-sign-request \
--from $KEY_NAME \
--input "MrT1dvxgez7QoVFudyVn5S8xCTJjxUi5xxZyWHcji5Q=" \
--key-id $KEY_REQUEST_ID \
--fees 400000000award \
-y \
--chain-id $CHAIN_ID \
--node $RPC_URLtipIn the
--input
flag, you should provide a Base64-encoded hash. For testing purposes, you can use the hash from the example above. Alternatively, you can create one yourself – run the following command, replacing00112233
with arbitrary raw data:RAW_DATA="00112233"
HASH=$(echo -n $RAW_DATA | sha256sum | awk '{print $1}')
BASE64_HASH=$(echo -n $HASH | xxd -r -p | base64)Then create a signature request. In the
--input
flag, specify$BASE64_HASH
. -
Get all signature requests:
- Local node
- Chiado
wardend query warden sign-requests --keychain-id $KEYCHAIN_ID
wardend query warden sign-requests --keychain-id $KEYCHAIN_ID --node $RPC_URL
Your request ID and data for signing will be returned in the
id
anddata_for_signing
fields of the output:pagination:
total: "1"
- Result: null
creator: warden1d652c9nngq5cneak2whyaqa4g9ehr8pstxj0r5
data_for_signing: MrT1dvxgez7QoVFudyVn5S8xCTJjxUi5xxZyWHcji5Q=
deducted_keychain_fees: []
id: "1"
key_id: "1"
status: SIGN_REQUEST_STATUS_PENDING -
Export the request details using the command below. Specify the actual request ID and data you obtained.
export DATA=MrT1dvxgez7QoVFudyVn5S8xCTJjxUi5xxZyWHcji5Q=
export SIGN_REQUEST_ID=1 -
Use the CLIChain
sign
command to sign the message with the key generated in the previous step. Export the signature.export SIGNATURE=$(echo -n $DATA | base64 -d | clichain sign -k private_$KEY_REQUEST_ID.key -o base64)
-
Fulfill the signature request by submitting a transaction from the Keychain Writer account:
- Local node
- Chiado
wardend tx warden fulfill-sign-request $SIGN_REQUEST_ID $SIGNATURE \
--from $KEYCHAIN_WRITER_NAME \
--chain-id $CHAIN_IDwardend tx warden fulfill-sign-request $SIGN_REQUEST_ID $SIGNATURE \
--from $KEYCHAIN_WRITER_NAME \
--fees 400000000award \
--chain-id $CHAIN_ID \
--node $RPC_URL -
Check the request status to make sure it was fulfilled:
- Local node
- Chiado
wardend query warden sign-request-by-id --id=$SIGN_REQUEST_ID
wardend query warden sign-request-by-id --id=$SIGN_REQUEST_ID --node $RPC_URL
Your request status will be returned in the
status
field of the output:sign_request:
Result:
type: SignedData
value:
signed_data: a0OHXtOgLHHP6qXxehlkImIjefA9fWZyuaD8hwzj4aMPiDkjvPLstu2I0+Ntcjz6wa1bh3+NGpqNKmWpqOlyiQE=
creator: warden1d652c9nngq5cneak2whyaqa4g9ehr8pstxj0r5
data_for_signing: MrT1dvxgez7QoVFudyVn5S8xCTJjxUi5xxZyWHcji5Q=
deducted_keychain_fees: []
id: "1"
key_id: "1"
status: SIGN_REQUEST_STATUS_FULFILLED
Next steps
To start building a Keychain service, follow Build a Keychain app.