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.
For generating keys and signing messages, you'll use the CLIChain (clichain
) tool.
Learn more:
- For a list of CLIChain commands, see Implementation: CLIChain.
- To learn more about key and signature requests, see Request flow.
Prerequisites
Before you start, complete the following prerequisites:
- Run a local chain or Join Buenavista. Make sure the node is running.
- Make sure you can request a new key – for example, from SpaceWard.
- Create a Keychain.
1. Install CLIChain
To install CLIChain, navigate to the wardenprotocol
directory and run this:
go install ./cmd/clichain
2. Export variables
In the next steps, you'll use the following values:
- Your chain ID you used when running a node.
- Your Keychain ID obtained when registering a Keychain.
- Your Keychain Writer name you specified when adding a Keychain Writer.
Export them as environment variables:
export CHAIN_ID=chain_123-1
export KEYCHAIN_ID=1
export KEYCHAIN_WRITER_NAME=my-keychain-writer-name
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.
-
Use SpaceWard or the command line to create a new Space and request a new key.
-
Get all key requests:
wardend query warden key-requests --keychain-id $KEYCHAIN_ID
Your key request ID will be returned in the
id
field of the output:id=1
-
Export the request ID:
export KEY_REQUEST_ID=1 # replace with the actual key request ID
-
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 key request by submitting a transaction from the Keychain Writer account:
wardend tx warden fulfill-key-request $KEY_REQUEST_ID $PUBLIC_KEY /
--from $KEYCHAIN_WRITER_NAME --chain-id $CHAIN_ID
4. Fulfill a signature request
When a user requests a new key, the Keychain signs a message with the private key and submits the signature to the chain.
-
Use SpaceWard or the command line to create a new signature request.
-
Get all signature requests:
wardend query warden sign-requests --keychain-id $KEYCHAIN_ID
Your signature request ID and data for signing will be returned in the
id
anddata_for_signing
fields of the output:id: 1
data_for_signing: rx3uiUeGwwRgSgObBBRjyauN77OTQD6gPPLIWx64y/0= -
Export your signature request data:
export DATA=rx3uiUeGwwRgSgObBBRjyauN77OTQD6gPPLIWx64y/0= # replace with the actual data
export SIGN_REQUEST_ID=1 # replace with the actual signature request ID -
Use the CLIChain
sign
command to sign the message with the key generated in Step 3 and export the signature:export SIGNATURE=$(echo -n $DATA | base64 -d | clichain sign -k /tmp/key -o base64)
-
Fulfill the signature request by submitting a transaction from the Keychain Writer account:
wardend tx warden fulfill-sign-request $SIGNATURE_REQUEST_ID $SIGNATURE \
--from $KEYCHAIN_WRITER_NAME --chain-id $CHAIN_ID