webb-tools / gadget

A framework for building modular AVS and Tangle Blueprints: https://docs.tangle.tools/developers/blueprints.
https://tangle.tools
MIT License
5 stars 1 forks source link

Gadget SDK - proc-macro for generating blueprint.json #160

Open shekohex opened 1 month ago

shekohex commented 1 month ago

Goal

We need a macro that essentially generates a metadata file of the blueprint and export it as json. This would be used by other tools, like the gadget CLI, which then could convert this JSON into an extrinsic to create the blueprint on-chain.

Example Blueprint

/// Generates a key with a specified threshold.
#[job(params(t))]
fn keygen(t: u8, ..) -> Result<Vec<u8>> {
    // ...
} 

/// Signs a message using the generated key.
#[job(params(keygen_id, message_hash))]
#[verifier(Evm("0x4838B106FCe9647Bdf1E7877BF73cE8B0BAD5f97")]
fn sign(keygen_id: u64, message_hash: [u8; 32], ..) -> Result<Vec<u8>> {
    // ...
} 
//! A service for CGGMP21 key generation and signing operations.

mod keygen;
mod signing;

sdk::blueprint! {
    registration_hook: None,
    registration_params: [],
    request_hook: Evm("0x4838B106FCe9647Bdf1E7877BF73cE8B0BAD5f97"),
    request_params: [],
    jobs: [keygen::KeygenJob, signing::SignJob],
    gadget: Wasm {
        runtime: Wasmtime,
        soruces: [
            Ipfs("QmExampleIpfsHash"),
            Github {
                owner: "dfns",
                repo: "cggmp21",
                tag: "v1.0.0",
                binaries: [{
                    arch: Wasm32,
                    os: Unknown,
                    name: "cggmp21.wasm",
                    sha256: "0xabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdef",
                }],
            }
        ],
    },
};

fn main() {
    // ...
}

blueprint.json specification

{
  "metadata": {
    "name": "dnfs-cggmp21-blueprint",
    "description": "A service for CGGMP21 key generation and signing operations.",
    "author": "Example Author",
    "category": "Cryptographic Services",
    "code_repository": "https://github.com/dfns/cggmp21",
    "logo": "https://example.com/logo.png",
    "website": "https://example.com",
    "license": "Apache-2.0"
  },
  "jobs": [
    {
      "metadata": {
        "name": "keygen",
        "description": "Generates a key with a specified threshold."
      },
      "params": ["Uint8"],
      "result": ["Bytes"],
      "verifier": "None"
    },
    {
      "metadata": {
        "name": "sign",
        "description": "Signs a message using the generated key."
      },
      "params": ["Uint64", "Bytes"],
      "result": ["Bytes"],
      "verifier": { "Evm": "0x4838B106FCe9647Bdf1E7877BF73cE8B0BAD5f97" }
    }
  ],
  "registration_hook": "None",
  "registration_params": [],
  "request_hook": {
    "Evm": "0x4838B106FCe9647Bdf1E7877BF73cE8B0BAD5f97"
  },
  "request_params": [],
  "gadget": {
    "Wasm": {
      "runtime": "Wasmtime",
      "soruces": [
        {
          "fetcher": {
            "IPFS": "QmExampleIpfsHash"
          }
        },
        {
          "fetcher": {
            "Github": {
              "owner": "dfns",
              "repo": "cggmp21",
              "tag": "v1.0.0",
              "binaries": [
                {
                  "arch": "Wasm32",
                  "os": "Unknown",
                  "name": "cggmp21.wasm",
                  "sha256": "abcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdef"
                }
              ]
            }
          }
        }
      ]
    }
  }
}