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

Add a new ECDSA session key for PoI signing #16

Open pacokleitz opened 1 year ago

pacokleitz commented 1 year ago

An ECDSA key is needed for PoI signing. The correct way to implement it is as a new Session key like the one used by authority-discovery. Look at the authority-discovery frame pallet as an example of how to add it.

Look at primitives/authority-discovery and frame/authority-discovery in https://github.com/paritytech/substrate/blob/polkadot-v0.9.40 as example

Read https://develop--substrate-docs.netlify.app/v3/concepts/session-keys/ (might be a bit outdated)

I think that it should be added to the same custom pallet as for the signing rpc handler.

pacokleitz commented 1 year ago

Can't complete this task because there is an error while compiling the runtime.

The error is related to Webassembly and a library needed for random operations (getrandom) which doesn't seem to work in wasm. When I fix the error by adding the "js" feature of the getrandom library, I get another error "mod sys doesn't have the errno function", also related to the module sys not available in wasm.

It is weird because I copied how session keys are added in the substrate library official pallets, and copied all the dependencies they are using without adding new ones.

I added a primitives module for our new pallet which creates the types needed for our new session key:

Our primitives for our "pallet-template": https://github.com/ambula-labs/ambula/tree/feat/add-poi-session-key/pallets/template/src/primitives Example primitives from substrate "authority-discovery" official pallet: https://github.com/paritytech/substrate/tree/polkadot-v0.9.40/primitives/authority-discovery

Our pallet "pallet-template" that imports the primitives: https://github.com/ambula-labs/ambula/tree/feat/add-poi-session-key/pallets/template Example "authority-discovery" official pallet that imports the primitives in the same way: https://github.com/paritytech/substrate/tree/polkadot-v0.9.40/frame/authority-discovery