Comments
This commit is contained in:
151
src/cc/musig.cpp
151
src/cc/musig.cpp
@@ -217,6 +217,37 @@ UniValue musig_session(uint64_t txfee,struct CCcontract_info *cp,cJSON *params)
|
|||||||
{
|
{
|
||||||
UniValue result(UniValue::VOBJ);
|
UniValue result(UniValue::VOBJ);
|
||||||
result.push_back(Pair("result","success"));
|
result.push_back(Pair("result","success"));
|
||||||
|
/** Initializes a signing session for a signer
|
||||||
|
*
|
||||||
|
* Returns: 1: session is successfully initialized
|
||||||
|
* 0: session could not be initialized: secret key or secret nonce overflow
|
||||||
|
* Args: ctx: pointer to a context object, initialized for signing (cannot
|
||||||
|
* be NULL)
|
||||||
|
* Out: session: the session structure to initialize (cannot be NULL)
|
||||||
|
* signers: an array of signers' data to be initialized. Array length must
|
||||||
|
* equal to `n_signers` (cannot be NULL)
|
||||||
|
* nonce_commitment32: filled with a 32-byte commitment to the generated nonce
|
||||||
|
* (cannot be NULL)
|
||||||
|
* In: session_id32: a *unique* 32-byte ID to assign to this session (cannot be
|
||||||
|
* NULL). If a non-unique session_id32 was given then a partial
|
||||||
|
* signature will LEAK THE SECRET KEY.
|
||||||
|
* msg32: the 32-byte message to be signed. Shouldn't be NULL unless you
|
||||||
|
* require sharing public nonces before the message is known
|
||||||
|
* because it reduces nonce misuse resistance. If NULL, must be
|
||||||
|
* set with `musig_session_set_msg` before signing and verifying.
|
||||||
|
* combined_pk: the combined public key of all signers (cannot be NULL)
|
||||||
|
* pk_hash32: the 32-byte hash of the signers' individual keys (cannot be
|
||||||
|
* NULL)
|
||||||
|
* n_signers: length of signers array. Number of signers participating in
|
||||||
|
* the MuSig. Must be greater than 0 and at most 2^32 - 1.
|
||||||
|
* my_index: index of this signer in the signers array
|
||||||
|
* seckey: the signer's 32-byte secret key (cannot be NULL)
|
||||||
|
*/
|
||||||
|
//if (!secp256k1_musig_session_initialize(ctx, &musig_session[i], signer_data[i], nonce_commitment[i], session_id32, msg32, &combined_pk, pk_hash, N_SIGNERS, i, seckeys[i]))
|
||||||
|
//return 0;
|
||||||
|
// randombytes_buf(buf, num);
|
||||||
|
|
||||||
|
//nonce_commitment_ptr[i] = &nonce_commitment[i][0];
|
||||||
return(result);
|
return(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -224,6 +255,25 @@ UniValue musig_commit(uint64_t txfee,struct CCcontract_info *cp,cJSON *params)
|
|||||||
{
|
{
|
||||||
UniValue result(UniValue::VOBJ);
|
UniValue result(UniValue::VOBJ);
|
||||||
result.push_back(Pair("result","success"));
|
result.push_back(Pair("result","success"));
|
||||||
|
/** Gets the signer's public nonce given a list of all signers' data with commitments
|
||||||
|
*
|
||||||
|
* Returns: 1: public nonce is written in nonce
|
||||||
|
* 0: signer data is missing commitments or session isn't initialized
|
||||||
|
* for signing
|
||||||
|
* Args: ctx: pointer to a context object (cannot be NULL)
|
||||||
|
* session: the signing session to get the nonce from (cannot be NULL)
|
||||||
|
* signers: an array of signers' data initialized with
|
||||||
|
* `musig_session_initialize`. Array length must equal to
|
||||||
|
* `n_commitments` (cannot be NULL)
|
||||||
|
* Out: nonce: the nonce (cannot be NULL)
|
||||||
|
* In: commitments: array of 32-byte nonce commitments (cannot be NULL)
|
||||||
|
* n_commitments: the length of commitments and signers array. Must be the total
|
||||||
|
* number of signers participating in the MuSig.
|
||||||
|
*/
|
||||||
|
// Set nonce commitments in the signer data and get the own public nonce
|
||||||
|
//if (!secp256k1_musig_session_get_public_nonce(ctx, &musig_session[i], signer_data[i], &nonce[i], nonce_commitment_ptr, N_SIGNERS))
|
||||||
|
// return 0;
|
||||||
|
|
||||||
return(result);
|
return(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -231,13 +281,69 @@ UniValue musig_nonce(uint64_t txfee,struct CCcontract_info *cp,cJSON *params)
|
|||||||
{
|
{
|
||||||
UniValue result(UniValue::VOBJ);
|
UniValue result(UniValue::VOBJ);
|
||||||
result.push_back(Pair("result","success"));
|
result.push_back(Pair("result","success"));
|
||||||
return(result);
|
/** Checks a signer's public nonce against a commitment to said nonce, and update
|
||||||
|
* data structure if they match
|
||||||
|
*
|
||||||
|
* Returns: 1: commitment was valid, data structure updated
|
||||||
|
* 0: commitment was invalid, nothing happened
|
||||||
|
* Args: ctx: pointer to a context object (cannot be NULL)
|
||||||
|
* signer: pointer to the signer data to update (cannot be NULL). Must have
|
||||||
|
* been used with `musig_session_get_public_nonce` or initialized
|
||||||
|
* with `musig_session_initialize_verifier`.
|
||||||
|
* In: nonce: signer's alleged public nonce (cannot be NULL)
|
||||||
|
*/
|
||||||
|
//if (!secp256k1_musig_set_nonce(ctx, &signer_data[i][j], &nonce[j])) {
|
||||||
|
|
||||||
|
|
||||||
|
/** Updates a session with the combined public nonce of all signers. The combined
|
||||||
|
* public nonce is the sum of every signer's public nonce.
|
||||||
|
*
|
||||||
|
* Returns: 1: nonces are successfully combined
|
||||||
|
* 0: a signer's nonce is missing
|
||||||
|
* Args: ctx: pointer to a context object (cannot be NULL)
|
||||||
|
* session: session to update with the combined public nonce (cannot be
|
||||||
|
* NULL)
|
||||||
|
* signers: an array of signers' data, which must have had public nonces
|
||||||
|
* set with `musig_set_nonce`. Array length must equal to `n_signers`
|
||||||
|
* (cannot be NULL)
|
||||||
|
* n_signers: the length of the signers array. Must be the total number of
|
||||||
|
* signers participating in the MuSig.
|
||||||
|
* Out: nonce_is_negated: a pointer to an integer that indicates if the combined
|
||||||
|
* public nonce had to be negated.
|
||||||
|
* adaptor: point to add to the combined public nonce. If NULL, nothing is
|
||||||
|
* added to the combined nonce.
|
||||||
|
*/
|
||||||
|
// after all nonces: if (!secp256k1_musig_session_combine_nonces(ctx, &musig_session[i], signer_data[i], N_SIGNERS, NULL, NULL)) {
|
||||||
|
return(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
UniValue musig_partialsign(uint64_t txfee,struct CCcontract_info *cp,cJSON *params)
|
UniValue musig_partialsign(uint64_t txfee,struct CCcontract_info *cp,cJSON *params)
|
||||||
{
|
{
|
||||||
UniValue result(UniValue::VOBJ);
|
UniValue result(UniValue::VOBJ);
|
||||||
result.push_back(Pair("result","success"));
|
result.push_back(Pair("result","success"));
|
||||||
|
/** Produces a partial signature
|
||||||
|
*
|
||||||
|
* Returns: 1: partial signature constructed
|
||||||
|
* 0: session in incorrect or inconsistent state
|
||||||
|
* Args: ctx: pointer to a context object (cannot be NULL)
|
||||||
|
* session: active signing session for which the combined nonce has been
|
||||||
|
* computed (cannot be NULL)
|
||||||
|
* Out: partial_sig: partial signature (cannot be NULL)
|
||||||
|
*/
|
||||||
|
//if (!secp256k1_musig_partial_sign(ctx, &musig_session[i], &partial_sig[i])) {
|
||||||
|
/** Parse and verify a MuSig partial signature.
|
||||||
|
*
|
||||||
|
* Returns: 1 when the signature could be parsed, 0 otherwise.
|
||||||
|
* Args: ctx: a secp256k1 context object
|
||||||
|
* Out: sig: pointer to a signature object
|
||||||
|
* In: in32: pointer to the 32-byte signature to be parsed
|
||||||
|
*
|
||||||
|
* After the call, sig will always be initialized. If parsing failed or the
|
||||||
|
* encoded numbers are out of range, signature verification with it is
|
||||||
|
* guaranteed to fail for every message and public key.
|
||||||
|
*/
|
||||||
|
//SECP256K1_API int secp256k1_musig_partial_signature_parse(
|
||||||
|
|
||||||
return(result);
|
return(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -245,13 +351,54 @@ UniValue musig_sigcombine(uint64_t txfee,struct CCcontract_info *cp,cJSON *param
|
|||||||
{
|
{
|
||||||
UniValue result(UniValue::VOBJ);
|
UniValue result(UniValue::VOBJ);
|
||||||
result.push_back(Pair("result","success"));
|
result.push_back(Pair("result","success"));
|
||||||
return(result);
|
/** Checks that an individual partial signature verifies
|
||||||
|
*
|
||||||
|
* This function is essential when using protocols with adaptor signatures.
|
||||||
|
* However, it is not essential for regular MuSig's, in the sense that if any
|
||||||
|
* partial signatures does not verify, the full signature will also not verify, so the
|
||||||
|
* problem will be caught. But this function allows determining the specific party
|
||||||
|
* who produced an invalid signature, so that signing can be restarted without them.
|
||||||
|
*
|
||||||
|
* Returns: 1: partial signature verifies
|
||||||
|
* 0: invalid signature or bad data
|
||||||
|
* Args: ctx: pointer to a context object (cannot be NULL)
|
||||||
|
* session: active session for which the combined nonce has been computed
|
||||||
|
* (cannot be NULL)
|
||||||
|
* signer: data for the signer who produced this signature (cannot be NULL)
|
||||||
|
* In: partial_sig: signature to verify (cannot be NULL)
|
||||||
|
* pubkey: public key of the signer who produced the signature (cannot be NULL)
|
||||||
|
*/
|
||||||
|
//if (!secp256k1_musig_partial_sig_verify(ctx, &musig_session[i], &signer_data[i][j], &partial_sig[j], &pubkeys[j])) {
|
||||||
|
return 0;
|
||||||
|
/** Combines partial signatures
|
||||||
|
*
|
||||||
|
* Returns: 1: all partial signatures have values in range. Does NOT mean the
|
||||||
|
* resulting signature verifies.
|
||||||
|
* 0: some partial signature had s/r out of range
|
||||||
|
* Args: ctx: pointer to a context object (cannot be NULL)
|
||||||
|
* session: initialized session for which the combined nonce has been
|
||||||
|
* computed (cannot be NULL)
|
||||||
|
* Out: sig: complete signature (cannot be NULL)
|
||||||
|
* In: partial_sigs: array of partial signatures to combine (cannot be NULL)
|
||||||
|
* n_sigs: number of signatures in the partial_sigs array
|
||||||
|
*/
|
||||||
|
// after all partials: return secp256k1_musig_partial_sig_combine(ctx, &musig_session[0], sig, partial_sig, N_SIGNERS return(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
UniValue musig_verify(uint64_t txfee,struct CCcontract_info *cp,cJSON *params)
|
UniValue musig_verify(uint64_t txfee,struct CCcontract_info *cp,cJSON *params)
|
||||||
{
|
{
|
||||||
UniValue result(UniValue::VOBJ);
|
UniValue result(UniValue::VOBJ);
|
||||||
result.push_back(Pair("result","success"));
|
result.push_back(Pair("result","success"));
|
||||||
|
/** Verify a Schnorr signature.
|
||||||
|
*
|
||||||
|
* Returns: 1: correct signature
|
||||||
|
* 0: incorrect or unparseable signature
|
||||||
|
* Args: ctx: a secp256k1 context object, initialized for verification.
|
||||||
|
* In: sig: the signature being verified (cannot be NULL)
|
||||||
|
* msg32: the 32-byte message hash being verified (cannot be NULL)
|
||||||
|
* pubkey: pointer to a public key to verify with (cannot be NULL)
|
||||||
|
*/
|
||||||
|
// if (!secp256k1_schnorrsig_verify(ctx, &sig, msg, &combined_pk)) {
|
||||||
return(result);
|
return(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user