webb-tools / dkg-substrate

Multy-party threshold ECDSA (GG20) Substrate node
https://tangle.webb.tools/
GNU General Public License v3.0
59 stars 15 forks source link

[TASK] Pass compressed public key in `nextPublicKeySignatureSumbitted` and `publicKeySignatureChanged` events #703

Closed devpavan04 closed 1 year ago

devpavan04 commented 1 year ago

Overview

In the individual key details page of stats-dapp, we display a Timeline component that illustrates the status of 3 key events at various timestamps:

  1. Generated
  2. Signed
  3. Rotated

However, stats-dapp currently, can only show the generated and rotated status. This limitation is due to the absence of the compressed public key in the following DKG events:

Most notably, the limitation is with the event - nextPublicKeySignatureSubmitted.

CleanShot 2023-08-31 at 11 18 44

Whenever a public key is submitted or a next public key is generated, we create a new Public Key GraphQL item, assigning its ID to the compressed key. Yet, when a public key signature is submitted, we only have the Uncompressed Public Key at our disposal, and not the Compressed Key. This discrepancy hinders the update of that specific public key's status from generated to rotated.

The solution requires us to utilize the compressed public key across all events, rather than the uncompressed key.

CleanShot 2023-08-31 at 08 04 13

Note:

Tried to make use of the following function to convert uncompressed to compressed key:

import { ECPairFactory } from 'ecpair';
import * as tinysecp from 'tiny-secp256k1';

export function compressPublicKey(uncompressed: `0x${string}`): `0x${string}` {
  const ECPair = ECPairFactory(tinysecp);
  const dkgPubKey = ECPair.fromPublicKey(Buffer.from(uncompressed.slice(2), 'hex'), {
    compressed: true,
  }).publicKey.toString('hex');
  // now we remove the `04` prefix byte and return it.
  return `0x${dkgPubKey.slice(2)}`;
}

Due to the limitation of subquery's sandbox environment, there was error importing tiny-secp256k1 and ecpair library.

drewstone commented 1 year ago

Can we not compress it outside of the graphql work and on the Ui?

devpavan04 commented 1 year ago

Can we not compress it outside of the graphql work and on the Ui?

We're compressing/uncompressing as needed in the UI without any problem. But this update is required since we're using compressed key as the ID when creating public keys in subquery. We need to use either compressed or uncompressed key in all events. Not both as marked in the screenshot above.