ambula-labs / ambula

A fork from the substrate node template, implementing the Proof of Interaction consensus algorithm.
The Unlicense
1 stars 0 forks source link

Implement the signing/verification mecanisms inside the PoI code #28

Open 0xA1337 opened 1 year ago

0xA1337 commented 1 year ago

Checkout the code :

        // Get node authority-discovery public session key from keystore
        let authority_discovery_pubkey: Vec<sr25519::Public> = SyncCryptoStore::sr25519_public_keys(
            &*keystore_container.sync_keystore(),
            AUTHORITY_DISCOVERY_KEY_TYPE,
        )
        .iter()
        .map(|k| sr25519::Public::from(k.clone()))
        .collect();

        // Use authority-discovery session key to sign a message (should use a different ECDSA session key KEY_TYPE instead)
        let signature = SyncCryptoStore::sign_with(
            &*keystore_container.sync_keystore(),
            AUTHORITY_DISCOVERY_KEY_TYPE,
            &authority_discovery_pubkey[0].into(),
            "My Signed Message".as_bytes()
        ).unwrap();

        match signature {
            Some(sig) => println!("Signature: {:?}", H512::from_slice(&sig)),
            _ => {},
        };

and a similar method, SyncCryptoStore::verify should be available. Use it to implement signature production & verification in the poi "module".