Taproot_example.dart

With the recent release of the ROAST coordinator project, I wanted to try my hand at going through a Dart example and explaining each block of code. As a disclaimer, I did not write this code and have no experience working with it, but I still thought maybe I could do an alright job commenting on it anyway. However, it has since been amended by MattLM, who did write the code.

This section imports the relevant packages. dart:async and dart:io are general dart packages for the server stdin, while grpc is use for remote protocol calls used by FROST. coinlib.dart is the Peercoin package that was developed last year (coinlib | Dart package). Frost_noosphere.dart is the FROST implementation most recently developed.

These take in command line prompts as either string or int. This will be called anytime inputs are needed from the user.

These are listeners, which wait for an event to be completed, such as signature requests or signature completion.

These are important constants, including server port and participant maximum. keyName is the name associated with a signature key, and is just hardcoded as “example_key” in this example.

This is the main asynchronous function, where first we load up Frosty. We declare the number of participants and the threshold by asking the user for them with inputs. Then, we generate id’s for each participant and their associated private keys. We configure each participant with an ID and a compressed public key.

Start the server, wait for it to serve the port

log in each client, opening a client channel and passing their private key along. Completers will wait (or “listen”) for an event, in this case the client log-in event.

Start distributed key generation and requesting them from clients.

Wait for clients to receive the key generation then accept it, posting to the user to wait up to 20 minutes. Wait for the key, or null out after 20 minutes with a key generation failure.

Build the key information for the group, including the pubkey resulting from the distributed key generation. Print the keys and the time it took then use the keys to create an address, specifically a key-path P2TR (or pay-to-taproot) address. Ask the user to deposit coin at the address and what the transaction id for that is. In this final line, we are treating the P2TR program as a kind of encapsulation for the taproot information for use in an output, i.e. scriptPubKey.

Asks for unsigned inputs at the taproot address, then build the unsigned transaction. Here, the transaction has a 9.99 PPC hardcoded output, but encapsulates the program into the taproot transaction. Hash the unsigned transaction into a taproot signature hash using the default Schnorr algorithm that can be readily signed.

Require the group to sign in a small timeframe of 3 minutes.

Wait for responses and signatures, building the final transaction and adding the taproot signature to the input.

Print it out and shut it down.

3 Likes