Disclosure of Invention
In view of the above, a method, apparatus, device and storage medium for implementing multiple signatures are provided to solve the problems of complex operation, unsafe and slow operation in multiple signatures in the prior art.
The application adopts the following technical scheme:
in a first aspect, an embodiment of the present application provides a multiple signature implementation method, where the method includes:
generating a key pair for participating in the transaction;
creating a multi-signature template and returning to the address of the multi-signature template;
transferring the certificate to the multi-signature module;
creating a transaction according to the multi-signature template and returning data to be signed;
signing the data to be signed, and returning signed signature data and a Boolean value;
if the Boolean value does not meet the weight condition, the signed signature data is used as a new signature object, and the signature is continued by using other private keys corresponding to the public keys participating in the establishment of the multi-signature template so as to continue the judgment until the Boolean value meets the weight condition, so that the multi-signature is realized.
Optionally, the weight condition includes that the sum of signed key weights is equal to or greater than the sum of minimum weights participating in the multi-sign template.
Optionally, before signing the data to be signed, at least one key in the key pair participating in the transaction exists in the current wallet.
Optionally, the multi-signature template includes a sum of minimum weights of the participating multi-signatures, a number of private keys defined in the multi-signature template, and weights of the public keys of the participating multi-signatures.
Optionally, the signature includes a bitmap, wherein the bitmap includes a private key participating in the multiple signature, and a location of the private key participating in the signature.
In a second aspect, an embodiment of the present application provides a multiple signature implementation apparatus, including:
the key pair generation module is used for generating a key pair participating in a transaction;
the multi-signature template creation module is used for creating a multi-signature template and returning the address of the multi-signature template;
the transfer certificate module is used for transferring the transfer certificate to the multi-sign module;
the transaction creation module is used for creating a transaction according to the multi-signature template and returning data to be signed;
the signature module is used for signing the data to be signed and returning signed signature data and Boolean values;
and the multiple signature realization module is used for taking the signed signature data as a new signature object when the Boolean value does not meet the weight condition, and continuing to sign by using other private keys corresponding to the public keys participating in the establishment of the multiple signature templates until the Boolean value meets the weight condition so as to realize multiple signatures.
Optionally, the weight condition includes that the sum of signed key weights is equal to or greater than the sum of minimum weights participating in the multi-sign template.
Optionally, the method further comprises a determining module, configured to determine that at least one key in the key pair participating in the transaction exists in the wallet before signing the data to be signed.
Optionally, the multi-signature template includes a sum of minimum weights of the participating multi-signatures, a number of private keys defined in the multi-signature template, and weights of the public keys of the participating multi-signatures.
Optionally, the signature includes a bitmap, wherein the bitmap includes a private key participating in the multiple signature, and a location of the private key participating in the signature.
In a third aspect, an embodiment of the present application provides an apparatus, including:
a processor, and a memory coupled to the processor;
the memory is used for storing a computer program, and the computer program is at least used for executing the multi-signature implementation method according to the first aspect of the embodiment of the application;
the processor is configured to invoke and execute the computer program in the memory.
In a fourth aspect, an embodiment of the present application provides a storage medium storing a computer program, where the computer program implements the steps of the multiple signature implementation method according to the first aspect when the computer program is executed by a processor.
Therefore, in the embodiment of the application, a scheme of realizing multiple signatures by using a template running in a block chain public chain is adopted, whether a transaction is triggered or not is judged through weight, and a weight parameter is added for the multiple signatures. The following effects are achieved: the operation is simple, and the work can be started only by adding a plurality of templates to initiate a plurality of transactions; encryption and decryption are convenient; adding a weight parameter, and judging whether a transaction is triggered or not through the weight; the operation is performed on the template written in the public chain core code, and the operation is safe and rapid.
Detailed Description
In order to make the objects, technical solutions and advantages of the present application more apparent, the technical solutions of the present application will be described in detail below. It will be apparent that the described embodiments are only some, but not all, embodiments of the application. All other embodiments, based on the examples herein, which are within the scope of the application as defined by the claims, will be within the scope of the application as defined by the claims.
First, a common signature and multiple signatures will be described, and the common signature can be understood as follows: a puts money into a cipher box, then locks the cipher box by using the public key of B, and only B can unlock by using the private key of B to take out money. In the multi-signed transaction, it can be understood that after the money is put into the password box by the A, the password box is locked by the public key of the B, the locking operation is performed by the public key of the B, and even the public key of the third party C can be used for locking. At this time, if B wants to withdraw money from the inside of the cryptographic box, he needs to perform not only decryption operation using his own private key, but also unlocking operation of the cryptographic box by another person.
In the embodiment of the application, in the BigBang public chain, the consensus task is realized by writing the realization of the consensus mechanism into the code and executing the consensus task by creating a template. The multi-signature template is designed for realizing multiple signatures, and has the characteristics of simple operation, safe execution and high execution speed.
Examples
Fig. 1 is a flowchart of a multiple signature implementation method according to an embodiment of the present application, where the method may be performed by a multiple signature implementation device according to an embodiment of the present application, and the device may be implemented in software and/or hardware. Referring to fig. 1, the method may specifically include the steps of:
s101, generating a key pair participating in a transaction.
In particular, suppose that three pairs of keys can be generated, which can be implemented by bigbang makekeypair command. In one specific example, the implementation is as follows.
privkey1=″f1547396c4ec9f50a646b6ac791ee11fe493adc04940289752c2dc0494e040f5″
pubkey1=″579792c544d6a6c198498250c1fa1467a5e5eeb59435a6cdeb06085fb8c7b091″
privkey2=″43368761015b9de09dce66826188a22d1cb9d98a2b6e599c56bc384f839d67ff″
pubkey2=″6d95657d15cb91e074f98fdcbbcf311325beb1d8c2c0f6d65d8362c15c213a2f1″
privkey3=″be590f4db119efcff0247e5e08c7e840454b948e7a5c2993f84c12db9770fd8a″
pubkey3=″efd6b29ad69ea477c4f0ac859cdd00039b83c5b074c8b2f4f9038a781b9d63d5″
S102, creating a multi-signature template, and returning the address of the multi-signature template.
Specifically, the method can be realized by bigbang addnewtemplate multisig "{ \" required\ "2 \" pubkeys \ "[ \" $pubkey1\ "," "$pubkey2\", "" $pubkey3\ "]", wherein the required parameter means that the specified number of signatures are needed in the multi-signature template to confirm, and the above command indicates that more than two signatures are needed in the three keys.
S103, turning through the certificate to the multi-sign module.
Specifically, like a common transaction, the conversion of the multi-label template into the token can be realized by bigbangsendfrom $boss_addr $addr $amountof, wherein $boss_addr can be any address with the token, $addr is the multi-label template address returned in the last step, and $amountof is the number of the tokens.
S104, creating a transaction according to the multi-signature template and returning data to be signed.
Specifically, by creating a transaction via the createtraction method, transaction raw data, i.e., the data to be signed $tx_hex, will be returned. In a specific example, when the multi-sign template address is to initiate a transfer to $any_addr, a multi-person signature is required to be valid, which may be accomplished by the bigbang createtransaction $addr $any_addr $amountcommand. Wherein, $addr is a multi-signature template address.
S105, signing the data to be signed, and returning signed data and Boolean values.
Specifically, the returned data to be signed $tx_hex is signed by signing, which returns signed signature data signed transaction raw data and boolean value completed, where txdata= transaction raw data. In one specific example, a boolean value is used to determine whether the multiple signature minimum weight requirement is met.
And S106, if the Boolean value does not meet the weight condition, taking the signed signature data as a new signature object, and continuing to sign by using other private keys corresponding to the public keys participating in the establishment of the multi-signature template to continue judgment until the Boolean value meets the weight condition so as to realize multiple signatures.
Specifically, if the completed is false, that is, the weight condition is not satisfied, the raw data signed in the previous step is used as a new signature object, and the private key corresponding to the public key participating in the establishment of the multi-signature template is used to repeat the operation in the previous step. If the result of the completed is true, the transaction is sent through sendtransaction (txdata= signed transaction raw data). In addition, the signature result $sg1_hex in the above-described signature result $sg1_data is obtained, and $sg1_hex is signed with another private key. Specifically, the method can be realized by a command bigbang signtransaction $g1_hex, and returns the sg2_data, wherein the command includes a signature result sg2_hex and a variable completed whether the multi-signature requirement is met. If the completed is true, that is, the weight condition is satisfied, the required weight requirement is satisfied, at this time, the transaction is broadcast to the chain through the sendtransaction method, and the token receiving object $any_addr when the transaction is created previously can receive the corresponding token, which can be specifically realized through the command bigbang sendtransaction $sg2_hex. If the completed parameter is false, indicating that the multi-sign requirement is not satisfied, repeating the above operation until the completed parameter is true.
Optionally, the weight condition includes that the sum of signed key weights is equal to or greater than the sum of minimum weights of the participating multi-signatures in the multi-signature template. Wherein the value of completed is used to determine that the sum of signed key weights is equal to or greater than the sum of required templates.
Optionally, prior to signing the data to be signed, there is at least one key in the key pair participating in the transaction in the current wallet. At least one of the current wallets is in an unlocking state, and the wallet can be specifically realized through a bigbang signtransaction $tx_hex command and returns a sg1_data, wherein the current wallet comprises a signature result sg1_hex and a variable completed whether the requirement of multiple signing is met.
Optionally, the multi-signature template includes a sum of minimum weights of the participating multi-signatures, a number of private keys defined in the multi-signature template, and weights of public keys of the participating multi-signatures. Multiple signatures are used to initiate a transaction from a multiple signature template address, which becomes a multiple signature transaction. In one specific example, in a multi-sign transaction, vchSig contains two parts: one is the content of the multi-signature template, and the other is the multiple signature, as shown below.
The template content is a binary string whose length depends on the number of keys defined in the template. Up to 255 keys are expressed as follows.
Wherein required is the sum of the minimum weights of the participating multi-labels; key-length is the number of keys and nth-public-key is the n-th participating public key; the weight of nth-key-weight being the nth public key can be regarded as a uint256 since the public key is 32 bytes; the order of the public keys is determined by the small-end uint256 size.
Optionally, the signature comprises a bitmap, wherein the bitmap comprises a private key participating in the multiple signature, and a location of the private key participating in the signature. The signature includes three parts, represented as follows.
Where index is a bitmap, i.e., a bitmap, that indicates which keys are involved in the multiple signature, the position of which is related to the order of the keys. If index is considered as a uint8 array idx [ ], then the method of setting the public key with sequence number n: idx [ n/8] & (1 < < < (n% 8)); (Ri, si) is the same as the libsodium crypt_sign_ed25519_decoded () algorithm; s=si+ & gt Sj; all parameters of SHA512 are calculated in binary; ri=ri×b, B being the base point of ed 25519; si=ri+sha 512 (Ri, pi, M) ×si is scalar addition scale+scale (mod L) and multiplication scale (mod L) of ed 25519; ri=sha512 (sha512 (ki) [32, 64), M); ki is the private key; pi is the public key; si=clamp (SHA 512 (ki) [0, 32)), ki being a private key; there is equation pi=si×b.
In addition, in one specific example, M is content to be signed, which is Hash (IOStream (version, type, timestamp, lockuntil, anchor, input, sendto, amount, txfee, d ata)) in a multi-sign transaction. Further, verification can also be performed by si×b= (ri+sha512 (Ri, pi, M) ×si) ×b=ri+sha512 (Ri, pi, M) ×pi.
Therefore, in the embodiment of the application, a scheme of realizing multiple signatures by using a template running in a block chain public chain is adopted, whether a transaction is triggered or not is judged through weight, and a weight parameter is added for the multiple signatures. The following effects are achieved: the operation is simple, and the work can be started only by adding a plurality of templates to initiate a plurality of transactions; encryption and decryption are convenient; adding a weight parameter, and judging whether a transaction is triggered or not through the weight; the operation is performed on the template written in the public chain core code, and the operation is safe and rapid.
Fig. 2 is a schematic structural diagram of a multiple signature implementation device according to an embodiment of the present application, where the device is adapted to perform a multiple signature implementation method according to an embodiment of the present application. As shown in fig. 2, the apparatus may specifically include a key pair generation module 201, a multi-signature template creation module 202, a turn-through certificate module 203, a transaction creation module 204, a signature module 205, and a multi-signature implementation module 206.
Wherein, the key pair generating module 201 is configured to generate a key pair for participating in a transaction; the multi-signature template creation module 202 is configured to create a multi-signature template and return an address of the multi-signature template; the transfer certificate module 203 is configured to transfer certificates to the multi-sign module; the transaction creation module 204 is configured to create a transaction according to the multi-signature template and return data to be signed; the signature module 205 is configured to sign the data to be signed and return signed data and boolean values; and the multiple signature implementation module 206 is configured to take the signed signature data as a new signature object when the boolean value does not satisfy the weight condition, and continue to sign with other private keys corresponding to the public keys participating in the establishment of the multiple signature templates to continue the judgment until the boolean value satisfies the weight condition to implement the multiple signature.
Therefore, in the embodiment of the application, a scheme of realizing multiple signatures by using a template running in a block chain public chain is adopted, whether a transaction is triggered or not is judged through weight, and a weight parameter is added for the multiple signatures. The following effects are achieved: the operation is simple, and the work can be started only by adding a plurality of templates to initiate a plurality of transactions; encryption and decryption are convenient; adding a weight parameter, and judging whether a transaction is triggered or not through the weight; the operation is performed on the template written in the public chain core code, and the operation is safe and rapid.
Optionally, the weight condition includes that the sum of signed key weights is equal to or greater than the sum of minimum weights of the participating multi-signatures in the multi-signature template.
Optionally, the method further comprises a determining module for determining that at least one key in the key pair participating in the transaction exists in the wallet before signing the data to be signed.
Optionally, the multi-signature template includes a sum of minimum weights of the participating multi-signatures, a number of private keys defined in the multi-signature template, and weights of public keys of the participating multi-signatures.
Optionally, the signature comprises a bitmap, wherein the bitmap comprises a private key participating in the multiple signature, and a location of the private key participating in the signature.
The multi-signature realizing device provided by the embodiment of the application can execute the multi-signature realizing device method provided by any embodiment of the application, and has the corresponding functional modules and beneficial effects of the executing method.
An embodiment of the present application further provides an apparatus, referring to fig. 3, fig. 3 is a schematic structural diagram of an apparatus, as shown in fig. 3, where the apparatus includes: a processor 310 and a memory 320 connected to the processor 310; the memory 320 is used for storing a computer program, and the computer program is at least used for executing the multiple signature implementation method in the embodiment of the present application; the processor 310 is used to invoke and execute the computer program in memory; the method for realizing the multiple signatures at least comprises the following steps: generating a key pair for participating in the transaction; creating a multi-signature template and returning to the address of the multi-signature template; transferring the certificate to the multi-signature module; creating a transaction according to the multi-signature template and returning data to be signed; signing the data to be signed, and returning signed signature data and a Boolean value; if the Boolean value does not meet the weight condition, the signed signature data is used as a new signature object, and the signature is continued by using other private keys corresponding to the public keys participating in the establishment of the multi-signature template so as to continue the judgment until the Boolean value meets the weight condition, so that the multi-signature is realized.
The embodiment of the application also provides a storage medium, and the storage medium stores a computer program which, when executed by a processor, realizes the steps in the multi-signature realization method as in the embodiment of the application: generating a key pair for participating in the transaction; creating a multi-signature template and returning to the address of the multi-signature template; transferring the certificate to the multi-signature module; creating a transaction according to the multi-signature template and returning data to be signed; signing the data to be signed, and returning signed signature data and a Boolean value; if the Boolean value does not meet the weight condition, the signed signature data is used as a new signature object, and the signature is continued by using other private keys corresponding to the public keys participating in the establishment of the multi-signature template so as to continue the judgment until the Boolean value meets the weight condition, so that the multi-signature is realized.
It should be noted that in the description of the present application, the terms "first," "second," and the like are used for descriptive purposes only and are not to be construed as indicating or implying relative importance. Furthermore, in the description of the present application, unless otherwise indicated, the meaning of "plurality" means at least two.
Any process or method descriptions in flow charts or otherwise described herein may be understood as representing modules, segments, or portions of code which include one or more executable instructions for implementing specific logical functions or steps of the process, and further implementations are included within the scope of the preferred embodiment of the present application in which functions may be executed out of order from that shown or discussed, including substantially concurrently or in reverse order, depending on the functionality involved, as would be understood by those reasonably skilled in the art of the present application.
It is to be understood that portions of the present application may be implemented in hardware, software, firmware, or a combination thereof. In the above-described embodiments, the various steps or methods may be implemented in software or firmware stored in a memory and executed by a suitable instruction execution system. For example, if implemented in hardware, as in another embodiment, may be implemented using any one or combination of the following techniques, as is well known in the art: discrete logic circuits having logic gates for implementing logic functions on data signals, application specific integrated circuits having suitable combinational logic gates, programmable Gate Arrays (PGAs), field Programmable Gate Arrays (FPGAs), and the like.
Those of ordinary skill in the art will appreciate that all or part of the steps carried out in the method of the above-described embodiments may be implemented by a program to instruct related hardware, and the program may be stored in a computer readable storage medium, where the program when executed includes one or a combination of the steps of the method embodiments.
In addition, each functional unit in the embodiments of the present application may be integrated in one processing module, or each unit may exist alone physically, or two or more units may be integrated in one module. The integrated modules may be implemented in hardware or in software functional modules. The integrated modules may also be stored in a computer readable storage medium if implemented as software functional modules and sold or used as a stand-alone product.
The above-mentioned storage medium may be a read-only memory, a magnetic disk or an optical disk, or the like.
In the description of the present specification, a description referring to terms "one embodiment," "some embodiments," "examples," "specific examples," or "some examples," etc., means that a particular feature, structure, material, or characteristic described in connection with the embodiment or example is included in at least one embodiment or example of the present application. In this specification, schematic representations of the above terms do not necessarily refer to the same embodiments or examples. Furthermore, the particular features, structures, materials, or characteristics described may be combined in any suitable manner in any one or more embodiments or examples.
While embodiments of the present application have been shown and described above, it will be understood that the above embodiments are illustrative and not to be construed as limiting the application, and that variations, modifications, alternatives and variations may be made to the above embodiments by one of ordinary skill in the art within the scope of the application.