|
| 1 | +# Communicating with the Signer Module |
| 2 | +The core of any commitment module is its interaction with the signer API. |
| 3 | +Note: Below examples will show snippets in Rust, however any language that allows for instantiation of an http client will work. |
| 4 | +Note: A more complete example of the Signer Module usage can be found here |
| 5 | +## Authentication |
| 6 | +Communication between the proposer commitment module and Commit-Boost is authenticated with a JWT token. This token will be provided as `CB_JWT_<MODULE_NAME>` by the Commit-Boost launcher at initialization time. |
| 7 | +To discover which pubkeys a commitment can be made for call `/signer/v1/get_pubkeys`: |
| 8 | +```use serde::Deserialize; |
| 9 | +
|
| 10 | +#[derive(Deserialize)] |
| 11 | +pub struct GetPubkeysResponse { |
| 12 | + pub consensus: Vec<BlsPublicKey>, |
| 13 | + pub proxy: Vec<BlsPublicKey>, |
| 14 | +} |
| 15 | +
|
| 16 | +let url = format!("{}/signer/v1/get_pubkeys", COMMIT_BOOST_HOST); |
| 17 | +
|
| 18 | +let pubkeys = reqwest::get(url) |
| 19 | + .await |
| 20 | + .unwrap() |
| 21 | + .json::<GetPubkeysResponse>() |
| 22 | + .unwrap() |
| 23 | + .consensus;``` |
| 24 | +Once you'd like to receive a signature to create a commitment, you'd create the request like so: |
| 25 | +```use serde_json::json; |
| 26 | +use alloy_rpc_types_beacon::BlsSignature |
| 27 | +
|
| 28 | +#[derive(Debug, Clone, Serialize, Deserialize)] |
| 29 | +pub struct SignRequest { |
| 30 | + pub id: String, |
| 31 | + pub pubkey: BlsPublicKey, |
| 32 | + pub is_proxy: bool, |
| 33 | + pub object_root: [u8; 32], |
| 34 | +} |
| 35 | +
|
| 36 | +let sign_request_body = json!({ |
| 37 | + "id": "0", |
| 38 | + "pubkey": "0xa02ccf2b03d2ec87f4b2b2d0335cf010bf41b1be29ee1659e0f0aca4d167db7e2ca1bf1d15ce12c1fac5a60901fd41db", |
| 39 | + "is_proxy": false, |
| 40 | + "object_root": "your32commitmentbyteshere0000000" |
| 41 | + }); |
| 42 | +
|
| 43 | +let url = format!("{}/signer/v1/request_signature", COMMIT_BOOST_HOST); |
| 44 | +let client = reqwest::Client::new(); |
| 45 | +let res = client |
| 46 | + .post(url) |
| 47 | + .json(sign_request_body) |
| 48 | + .send() |
| 49 | + .await |
| 50 | + .unwrap(); |
| 51 | + |
| 52 | +let signature_bytes = res.bytes().await.unwrap(); |
| 53 | +let signature = BlsSignature::from_slice(&signature_bytes);``` |
0 commit comments