Approve a request
Once you created your request, you need to approve the challenge as the request creator before other users are notified to approve. To approve a request, you'll need to follow these steps:
Get the challenge
Given a request_id
, first need to fetch the HSM challenge:
curl --request GET \
--url https://api.vault.ledger.com/requests/{{request_id}}/challenge \
--header 'authorization: Bearer {{access_token}}' \
--header 'content-type: application/json' \
--header 'x-ledger-workspace: minivault'
Decode the challenge
Decode the challenge to validate that the instructions HSM received is the same as the one you passed in your request:
import jwt
// decode the challenge
challenge_data_bytes = jwt.utils.base64url_decode(challenge)
Review the instructions closely to ensure they align with your initial intention before signing. This challenge involves trusted data signed by your API user, allowing the HSM to sign the actual transaction. For instance, if the recipient address differs from your request, it might indicate a potential man-in-the-middle attack. Regardless of the request, the true signed transaction will be sent to the recipient specified in this challenge. Don't trust, verify.
Sign the challenge
Sign the challenge with your user private key.
import jwt
def sign_challenge(challenge: bytes, private_key_hex: str) -> str:
private_key_bytes = bytes.fromhex(private_key_hex)
challenge_data_bytes = jwt.utils.base64url_decode(challenge)
jws = jwt.PyJWS()
jws: str = jws.encode(challenge_data_bytes, private_key_bytes, algorithm="ES256")
return jws
With privatekeybytes the PEM format bytes of the private key.
-----BEGIN EC PRIVATE KEY-----
MHcCAQEEIDN4pKvYZtwGLC/XiUKdUjPJJGTRd1MQxVKsiaWEAY1OoAoGCCqGSM49
AwEHoUQDQgAEdcIngZ7X7X5sipnIuP3rt1w6mg3V9LQE4txm5cx0tvaDxon+W6Kx
CBtTMvPCR5D9a9Nab2cNEjvKePWyzOHqMg==
-----END EC PRIVATE KEY-----
JSON Web Signature details
And jws
the signed challenge / jws object. The resulting jws
consists of three parts: the JWS Header, the JWS Payload, and the JWS Signature. The three parts are base64url-encoded and concatenated in that order being separated by period ('.') characters.
Approve the request
Once you signed the challenge use it to post your approval on the approve request endpoint:
curl --request POST \
--url https://api.vault.ledger.com/requests/{{request_id}}/approve \
--header 'authorization: Bearer {{access_token}}' \
--header 'content-type: application/json' \
--header 'x-ledger-workspace: <workspace name>' \
--data '{
"jws": "{{jws}}"
}'
If the response status is 200, the response payload will be the request with its new status, in our case we are still waiting for another approval from a second user so the status stays in PENDING_APPROVAL
.
Last updated