WO2020103573A1 - Block chain-based network transaction signature method and device, and terminal equipment - Google Patents

Block chain-based network transaction signature method and device, and terminal equipment

Info

Publication number
WO2020103573A1
WO2020103573A1 PCT/CN2019/108540 CN2019108540W WO2020103573A1 WO 2020103573 A1 WO2020103573 A1 WO 2020103573A1 CN 2019108540 W CN2019108540 W CN 2019108540W WO 2020103573 A1 WO2020103573 A1 WO 2020103573A1
Authority
WO
WIPO (PCT)
Prior art keywords
input
transaction
value
transaction message
output
Prior art date
Application number
PCT/CN2019/108540
Other languages
French (fr)
Chinese (zh)
Inventor
陈柳章
Original Assignee
深圳市文鼎创数据科技有限公司
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by 深圳市文鼎创数据科技有限公司 filed Critical 深圳市文鼎创数据科技有限公司
Publication of WO2020103573A1 publication Critical patent/WO2020103573A1/en

Links

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06QINFORMATION AND COMMUNICATION TECHNOLOGY [ICT] SPECIALLY ADAPTED FOR ADMINISTRATIVE, COMMERCIAL, FINANCIAL, MANAGERIAL OR SUPERVISORY PURPOSES; SYSTEMS OR METHODS SPECIALLY ADAPTED FOR ADMINISTRATIVE, COMMERCIAL, FINANCIAL, MANAGERIAL OR SUPERVISORY PURPOSES, NOT OTHERWISE PROVIDED FOR
    • G06Q40/00Finance; Insurance; Tax strategies; Processing of corporate or income taxes
    • G06Q40/04Trading; Exchange, e.g. stocks, commodities, derivatives or currency exchange
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06QINFORMATION AND COMMUNICATION TECHNOLOGY [ICT] SPECIALLY ADAPTED FOR ADMINISTRATIVE, COMMERCIAL, FINANCIAL, MANAGERIAL OR SUPERVISORY PURPOSES; SYSTEMS OR METHODS SPECIALLY ADAPTED FOR ADMINISTRATIVE, COMMERCIAL, FINANCIAL, MANAGERIAL OR SUPERVISORY PURPOSES, NOT OTHERWISE PROVIDED FOR
    • G06Q20/00Payment architectures, schemes or protocols
    • G06Q20/38Payment protocols; Details thereof
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06QINFORMATION AND COMMUNICATION TECHNOLOGY [ICT] SPECIALLY ADAPTED FOR ADMINISTRATIVE, COMMERCIAL, FINANCIAL, MANAGERIAL OR SUPERVISORY PURPOSES; SYSTEMS OR METHODS SPECIALLY ADAPTED FOR ADMINISTRATIVE, COMMERCIAL, FINANCIAL, MANAGERIAL OR SUPERVISORY PURPOSES, NOT OTHERWISE PROVIDED FOR
    • G06Q20/00Payment architectures, schemes or protocols
    • G06Q20/38Payment protocols; Details thereof
    • G06Q20/382Payment protocols; Details thereof insuring higher security of transaction
    • G06Q20/3825Use of electronic signatures

Definitions

  • the present application belongs to the field of network transaction technology, and particularly relates to a signature method, signature device, terminal device and computer-readable storage medium based on a blockchain network transaction.
  • the calculation formula for the handling fee is: the sum of the amount of each transaction input-the output of each transaction The sum of the amounts.
  • the amount of each transaction input used by user A is 2 Bitcoin and 5 bitcoin, and user A 1 Bitcoin was transferred to user B, and the blockchain network changed 5.5 Bitcoins to user A (although the 5.5 Bitcoin was returned to user A, but still counted as the transaction output of this transaction), then in this transaction , User A needs to pay a handling fee of 0.5 Bitcoin.
  • the first aspect of the present application provides a signature method based on a blockchain network transaction.
  • the above-mentioned blockchain network transaction message includes an input field corresponding to each transaction input and an output field corresponding to each transaction output.
  • Each input field includes the TxOutHash value of the output hash
  • each legal input corresponds to the previous transaction message
  • the previous transaction message corresponding to each legal input is that there is an output field
  • the output The output corresponding to the field is the legal input
  • the TxOutHash value corresponding to each legal input is the same as the hash hash value of the previous transaction message corresponding to the legal input;
  • the above signature methods include:
  • the second aspect of the present application provides a signature device based on a blockchain network transaction.
  • the above-mentioned blockchain network transaction message includes an input field corresponding to each transaction input and an output field corresponding to each transaction output.
  • Each input field includes the TxOutHash value of the output hash
  • each legal input corresponds to the previous transaction message
  • the previous transaction message corresponding to each legal input is that there is an output field
  • the output The output corresponding to the field is the legal input
  • the TxOutHash value corresponding to each legal input is the same as the hash hash value of the previous transaction message corresponding to the legal input;
  • the above signature device includes:
  • the TxOutHash acquisition module is used to obtain the TxOutHash value under the input field corresponding to each input required for this transaction in this transaction message.
  • the above transaction message is the transaction message of this transaction;
  • the previous message acquisition module is used to obtain the previous transaction message corresponding to each input required for this transaction;
  • the hash value calculation module is used to calculate the hash value of each previous transaction message to obtain the hash value corresponding to each input;
  • the judgment module is used to judge whether the calculated Hash value corresponding to each input is consistent with the TxOutHash value under the input field corresponding to the input;
  • the signature module is used to sign the above transaction message if the calculated Hash value corresponding to each input is consistent with the TxOutHash value under the input field corresponding to the input.
  • a third aspect of the present application provides a terminal device, including a memory, a processor, and a computer program stored in the memory and executable on the processor.
  • the processor executes the computer program to implement the method of the first aspect. A step of.
  • a fourth aspect of the present application provides a computer-readable storage medium.
  • the computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the steps of the method of the first aspect described above are implemented.
  • a fifth aspect of the present application provides a computer program product.
  • the computer program product includes a computer program.
  • the computer program is executed by one or more processors, the steps of the method of the first aspect described above are implemented.
  • this application provides a signature method based on the blockchain network transaction.
  • each legal input corresponds to the previous transaction message, and each legal input
  • the Hash value of the corresponding previous transaction message is the same as the TxOutHash value corresponding to the input.
  • the signature method provided in this application calculates the TxOutHash value corresponding to an input in the transaction message and the previous transaction report corresponding to the input. Whether the hash value of the text is the same to determine whether the input is legal and traverse all inputs of the transaction message. Only sign the transaction message when it is judged that all inputs of the transaction message are legal .
  • the blockchain node where the user is located needs to send a signed transaction message to the blockchain transaction platform.
  • the signature operation is used to indicate that the transaction message is legal
  • the blockchain trading platform will only perform transfer operations when it receives legitimate messages. Therefore, the technical solution provided in this application can determine whether each transaction input of this transaction is legal, and can check the illegal transaction input embedded in the transaction message to a certain extent, only when it is determined that all transaction inputs are legal Only when the signature operation is executed, that is, the transaction message is determined to be legal, which makes the blockchain transaction platform perform the transfer operation, to a certain extent, it can avoid the illegal embedding of the transaction message when the user transfers the account. Multiple transaction inputs cause the user to pay more processing fees. Therefore, the signature method provided in this application can better protect the user's funds to a certain extent.
  • FIG. 1 is a schematic diagram of an application scenario of a signature method based on a blockchain network transaction provided by this application;
  • Figure 2 is a schematic diagram of the common transaction message format when conducting transactions based on the blockchain network
  • FIG. 3 is a schematic diagram of an implementation process of a signature method based on a blockchain network transaction provided by Embodiment 1 of the present application;
  • Embodiment 4 is a schematic diagram of judging whether each transaction input is legal provided by Embodiment 1 of the present application;
  • FIG. 5 is a schematic diagram of an implementation process of another signature method based on a blockchain network transaction provided by Embodiment 2 of the present application;
  • FIG. 6 is a schematic diagram of a calculation process of a handling fee provided in Example 2 of the present application.
  • FIG. 7 is a schematic structural diagram of a signature device based on a blockchain network transaction provided by Embodiment 3 of the present application.
  • FIG. 8 is a schematic structural diagram of a terminal device according to Embodiment 4 of the present application.
  • FIG. 1 is a schematic diagram of an application scenario of a signature method based on a blockchain network transaction provided by this application.
  • the application scenario includes a blockchain node 1 and a blockchain transaction platform 2.
  • a transaction message 3 will be generated first.
  • the transaction message 3 includes the accounts of each payee and the size of the transfer amount to each account of the payee.
  • the transaction message 3 includes the account x of the blockchain node X, the amount transferred to the account x, the account y of the blockchain node Y, and the transfer amount.
  • the blockchain node 1 sends the transaction message 3 to the blockchain transaction platform 2.
  • the blockchain transaction platform 2 judges that the transaction message 3 is legal, it will assist the blockchain node 1 to complete the transfer transaction.
  • the format of the transaction message is usually different.
  • the following uses Figure 2 to illustrate a more commonly used transaction message format.
  • the blockchain network that uses Bitcoin as the transaction currency adopts the transaction message format shown in FIG. 2.
  • the transaction message includes the input field corresponding to each transaction input input and the output field corresponding to each transaction output output.
  • the transaction message also includes the Input-Counter field and the Output-Counter field, Input -The size of the Counter field is used to indicate the number of input fields in the current transaction message, and the size of the Output-Counter field is used to indicate the number of output fields in the current transaction message.
  • Input -The size of Counter and Output-Counter should be 2.
  • the TxOutHash value is the hash hash value of the previous transaction message of the input corresponding to the input field, as shown in FIG.
  • the TxOutHash value in the first input field should be the transaction input input1
  • the Hash value of the corresponding previous transaction message I where the previous transaction message corresponding to each input has an output field, and the output corresponding to the output field is the input transaction message (for example, for transactions Input input1, if the previous transaction message corresponding to input1 is the previous transaction message I, then the previous transaction message I includes an output field, and the transaction output corresponding to the output field is the input1);
  • the TxOutIndex value under an input field is used to indicate which output field in the previous transaction message the corresponding input corresponds to, for example, the previous transaction message corresponding to the transaction input input1 in FIG.
  • the previous transaction message I is the previous transaction message I, assuming that the previous transaction message I includes two output fields, namely outputA field and outputB field, if the transaction output corresponding to the outputA field is input1, then the output of the previous transaction message I corresponding to the input1
  • the field is specifically the outputA field.
  • the TxOutIndex value in the input field corresponding to the input1 can be used to obtain the outputA field corresponding to the previous transaction message I; the ScriptLen under each input field The value is used to indicate the field length of the Sign & PubKey value in the input field; the Sign & Pubkey under each input field is the transaction signature and transaction public key of this transaction.
  • each output field it includes the amount Value value, script length ScriptLen value, and PKScript value.
  • the Value value under each output field is used to indicate the amount of the corresponding output; the ScriptLen value under each output field is used to indicate the field length of the PKScript value in the output field; the PKScript value under each output field is used to indicate Payee's account public key or account address (the account address is the payee account). If the PKScript under the output field is used to indicate the account public key of the beneficiary, the blockchain trading platform can calculate the account address of the beneficiary from the account public key, so as to conduct the transfer transaction.
  • the signature method based on the blockchain network transaction provided by this application can be applied to the blockchain network using the transaction message format as shown in FIG. 2, such as the blockchain network with Bitcoin as the currency in.
  • the signature method based on the blockchain network transaction provided by this application does not have to be applied to the blockchain network using the transaction message format as shown in FIG. 2.
  • FIG. 2 For details, please refer to this application The description of Embodiment 1 and Embodiment 2.
  • the following describes a signature method based on blockchain network transactions provided in Embodiment 1 of the present application.
  • the signature method is applied to the following blockchain network:
  • the transaction message of the blockchain network includes an input field corresponding to each transaction input input and an output field corresponding to each transaction output output.
  • Each input field includes a TxOutHash value
  • each legal input corresponds to Last transaction message
  • the output corresponding to the output field is the legal input
  • the TxOutHash value corresponding to each legal input is the The corresponding hash value of the previous transaction message is the same (the main reason why the input is limited to "legal" here is: when the input field corresponding to the illegal input is embedded in the transaction message, the illegal input is not necessarily Corresponding to the previous transaction message, even if there is a previous transaction message, the TxOutHash value corresponding to the illegal input is not necessarily the same as the Hash value of the previous transaction message).
  • the packet format of the blockchain network to which the signature method provided in Embodiment 1 of the present application does not necessarily include the Input-Counter field, Output-Counter field, nor under the input field. It must contain the ScriptLen value, and the Value and ScriptLen values may not necessarily be under the output field.
  • the signature method provided in the first embodiment of the present application needs to sign the transaction message, it can be the same as FIG. 2, and the Sign & PubKey can be included under each input field in the transaction message, but please ask a person skilled in the art Note that the field corresponding to the signature of the transaction message in the embodiment of the present application is not necessarily the same as that in FIG. 2.
  • the signature method provided in Embodiment 1 of this application is shown in FIG. 3 and includes:
  • step S101 in this transaction message, the TxOutHash value under the input field corresponding to each input required for this transaction is obtained.
  • the above transaction message is the transaction message of this transaction;
  • the transaction message includes three input fields, namely input field 1, input field 2, and input field 3, in step S101, the input field is read from the transaction message The TxOutHash value in 1, the TxOutHash value in the input field 2, and the TxOutHash value in the input field 3.
  • the step S101 may include: determining whether the above-mentioned transaction message conforms to a preset message format, and if it matches, then in the transaction message, obtain the transaction request The TxOutHash value under the input field corresponding to each input of. That is, first check whether the transaction message conforms to the preset message format. For example, check whether the transaction message includes the preset fields and whether the length of each field matches the preset length. After the secondary transaction message conforms to the preset message format, let's read the TxOutHash value under each input field.
  • step S102 obtain the previous transaction message corresponding to each input required for this transaction
  • the previous transaction message may be obtained by communicating with a preset server, and this step S102 may include the following steps S1021-S1022:
  • step S1021 the identification information of each input required for this transaction is acquired, and the identification information of each input is sent to the preset server to instruct the preset server to perform an operation of searching for the previous transaction message corresponding to each input;
  • the identification information of each input may be the input time, the amount of the input, the account number and / or the payment account of the input, etc.
  • the input information of the inputX may include: 2018 10 At 5:10 pm on the 30th of the month, 5 bitcoin, the deposit account is X, and the payment account is Y.
  • the above preset server After receiving the identification information of each input, the above preset server searches for the previous transaction message corresponding to each input according to the identification information of each input.
  • the preset server searches for a transaction corresponding to Output outputX transaction message, the outputX is the transaction output at 5:10 pm on October 30, 2018, the amount is 5 bitcoin, the receiving account is X and the sending account is Y, corresponding to the transaction with the outputX
  • the message is the last transaction message of inputX.
  • step S1022 receive the previous transaction message corresponding to each input sent by the preset server respectively;
  • this step S1022 may include: after sending the identification information of each input to the preset server, determining whether a previous transaction message corresponding to each input returned by the preset server is received within a preset time period; If the previous transaction message corresponding to each input is received, the subsequent step S103 is performed; if the previous transaction message corresponding to each input is not received, it is considered that there is an illegal input in this transaction.
  • the previous transaction message corresponding to input1 of this transaction message is the previous transaction message A
  • the previous transaction message corresponding to input2 is the previous transaction message B
  • the previous transaction corresponding to input3 The message is the last transaction message C.
  • step S103 calculate the hash value of each previous transaction message to obtain the hash value corresponding to each input;
  • the method for calculating the hash value of the message may use a currently commonly used method, such as the SHA256 algorithm, etc.
  • the present application does not limit the method for calculating the hash value.
  • this step S103 may further include a step of determining whether a previous transaction message corresponding to each input required for this transaction is obtained.
  • a prompt for notifying the user that the transaction is illegal may be output Information to remind the user whether to sign the transaction message; or, can output a prompt message to remind the user that the transaction is illegal, and terminate the signing operation of the transaction message; or, you can directly terminate the transaction message Signature; or, you can directly terminate the transaction, that is, do not send the transaction message to the blockchain trading platform.
  • this step S103 is specifically: if the previous transaction message corresponding to each input required for this transaction is obtained, then the hash hash value of each previous transaction message is calculated to obtain the hash corresponding to each input value.
  • this step S103 may also include:
  • the hash hash value of each previous transaction message is calculated to obtain the hash value corresponding to each input.
  • the transaction message may include the Sign & PubKey shown in FIG. 2 in this case.
  • the step S103 may also include: After the previous transaction message, determine whether each previous transaction message is a legal message based on the signature value and public key (can be Sign & PubKey) in each previous transaction message; when judging each previous transaction message When the messages are all legitimate messages, calculate the hash value of each previous transaction message to obtain the hash value corresponding to each input.
  • a previous transaction message is illegal (does not conform to the preset message format, or based on the signature value and public key to determine that it is not a legal message)
  • step S104 it is determined whether the calculated Hash value corresponding to each input is consistent with the TxOutHash value under the input field corresponding to the input;
  • each input in the transaction message can be considered legal, otherwise, if it is in each input required for this transaction ,
  • the Hash value corresponding to one or more inputs is inconsistent with the TxOutHash value under the corresponding input field (for example, the TxOutHash under input field 2 is not the same as the Hash value of the previous transaction message B), then it can be output for Prompt information to remind the user that the transaction is illegal, to remind the user whether to sign the transaction message; or, you can output a prompt message to remind the user that the transaction is illegal, and terminate the signature of the transaction message Operation; or, you can directly terminate this signature, or you can directly terminate this transaction, that is, do not send this transaction message to the blockchain transaction review.
  • step S105 if the calculated Hash value corresponding to each input is consistent with the TxOutHash value under the input field corresponding to the input, the transaction message is signed;
  • TxOutHash under input field 1 is consistent with the hash value of the previous transaction message A
  • TxOutHash under input field 2 is consistent with the hash value of the previous transaction message B
  • TxOutHash under input field 3 is consistent
  • the hash value of the previous transaction message C is the same, it is considered that all inputs of the transaction message are legal, and then sign the transaction message (if the input field of the transaction message as defined in this application example includes Sign & PubKey, you can write the transaction signature and transaction public key of this transaction into the Sign & PubKey in the input field of the transaction message), so that the blockchain trading platform can help complete the transaction.
  • Example 1 of this application can determine whether each transaction input of this transaction is legal, and can check the illegal transaction input embedded in this transaction message to a certain extent, only when judged Only when all transaction inputs are legal, will the signature operation be performed, that is, the transaction message will be deemed legal, which will enable the blockchain transaction platform to perform this transfer operation, which can avoid the user's transfer due to the transaction report to a certain extent.
  • Multiple transaction inputs are illegally embedded in the article, which causes the user to pay more processing fees. Therefore, the signature method provided by this application can better protect the user's funds to a certain extent.
  • Embodiment 2 of this application describes another signature method based on blockchain network transactions provided in Embodiment 2 of this application.
  • the signature method described in Embodiment 2 of this application is applied to the following blockchain network:
  • the transaction message of the blockchain network includes each input field and each output field, each input field includes a TxOutHash value, and each output field includes an amount Value, which is used to indicate the amount of the corresponding output
  • the TxOutIndex value under each input field is also included under each input field.
  • the TxOutIndex value under each input field is used to indicate the position of the output field corresponding to the corresponding input in the corresponding previous transaction message.
  • FIG. 2 For the format of the transaction message of the blockchain network defined in the first embodiment of the application, please refer to FIG. 2 and the corresponding text description part.
  • the signature method provided in the second embodiment of the present application needs to sign the transaction message, it can be the same as in FIG. 2, and the transaction message can include Sign & PubKey under each input field.
  • the field corresponding to the signature of the transaction message in the embodiment of the present application is not necessarily the same as FIG. 2.
  • the signature method described in Embodiment 2 of this application is shown in FIG. 5 and includes:
  • step S201 in this transaction message, the TxOutHash value under the input field corresponding to each input required for this transaction is obtained.
  • the above transaction message is the transaction message of this transaction;
  • step S202 obtain the previous transaction message corresponding to each input required for this transaction
  • step S203 calculate the hash value of each previous transaction message to obtain the hash value corresponding to each input;
  • step S204 it is determined whether the calculated Hash value corresponding to each input is consistent with the TxOutHash value under the input field corresponding to the input;
  • step S205 if the calculated Hash value corresponding to each input is consistent with the TxOutHash value under the input field corresponding to the input, then according to the above transaction message, each output field of the above transaction message is obtained Under the Value value, get the amount corresponding to each output in this transaction;
  • the transaction fee to be paid for this transaction can be further calculated and displayed to facilitate the user Know the transaction fee of this transaction, and enable users to determine whether to continue the transaction based on the transaction fee of this transaction.
  • the value of each transaction output is determined by reading the Value value under each output field in the transaction message, for example, the Value value under output field 1 is used to indicate the transaction The amount of output1 is output, and the Value value under output field 2 is used to indicate the amount of output2 of the transaction.
  • step S206 among each input required for the transaction, an input is selected as the target input;
  • this transaction requires three inputs, namely input1, input2, and input3. You can select any input from input1, input2, and input3 as the target input, for example, select input1 as the target input.
  • step S207 according to the TxOutIndex value under the input field corresponding to the target input, in the previous transaction message corresponding to the target input, search for the target output field, and the output corresponding to the target output field is the target input;
  • step S206 If in step S206, input1 is selected as the target input, in this transaction message, the TxOutIndex value in input field 1 corresponding to input1 is obtained, and the TxOutIndex value in input field 1 is used to indicate that input1 corresponds to the previous time
  • the TxOutIndex value in input field 1 is used to indicate that input1 corresponds to the previous time
  • step S208 obtain the Value value under the target output field to obtain the amount of the target input
  • the value of the value in the output field A1 in the previous transaction message A is used as the amount of input1.
  • step S209 it is determined whether the selected input has traversed all the inputs required for the transaction, if not, step S210 is executed, and if so, step S211 is executed;
  • step S210 remove the selected input, and in each input of this transaction, select an input as the target input, and return to step S207;
  • step S209 it is determined whether the amount of each input of the transaction message is obtained, if not, then select an input as the target input, and return to step S207;
  • step S211 according to the amount of money corresponding to each input in this transaction and the amount of money corresponding to each output in this transaction, the transaction fee for this transaction is determined;
  • the method for calculating the handling fee can use the existing technology to calculate the sum of the amount of each input and the sum of the amount of each output, minus the sum of the amount of each input minus the amount of each output The sum of the size and the transaction fee for this transaction.
  • step S212 the user is shown the above handling fee so that the user can confirm whether they are willing to continue the transaction;
  • step S213 if an instruction indicating that the user is willing to continue the transaction is received, the transaction message of this time is signed.
  • the user is shown the size of the handling fee, and when receiving the instruction of the user willing to continue the transaction, the transaction message is signed; when the instruction of the user refusing to continue the transaction is received, it can be Terminate this signature.
  • the second embodiment of the present application can further inform the user of the transaction fee of the transaction. Therefore, compared with the first embodiment, the second embodiment of the present application can make the user know the size of the transaction fee for each transaction. Can guarantee the user's right to know, and further improve the user experience.
  • the second embodiment of the present application is the same as the first embodiment, which can check the illegal transaction input embedded in the transaction message to a certain extent, so as to avoid that when the user transfers money, because the transaction message is illegally embedded Input of a transaction, causing the user to pay more processing fees.
  • Embodiment 3 of the present application provides a signature device based on a blockchain network transaction.
  • the above-mentioned blockchain network transaction message includes an input field corresponding to each transaction input and an output field corresponding to each transaction output.
  • Each input field includes the TxOutHash value of the output hash
  • each legal input corresponds to the previous transaction message
  • the previous transaction message corresponding to each legal input is that there is an output field.
  • the output corresponding to the field is the legal input
  • the TxOutHash value corresponding to each legal input is the same as the hash hash value of the previous transaction message corresponding to the legal input;
  • the signature device 300 includes:
  • the TxOutHash obtaining module 301 is used to obtain the TxOutHash value under the input field corresponding to each input required for this transaction in this transaction message.
  • the above transaction message is the transaction message of this transaction;
  • the previous message acquisition module 302 is used to obtain the previous transaction message corresponding to each input required for this transaction;
  • the hash value calculation module 303 is used to calculate the hash value of each previous transaction message to obtain the hash value corresponding to each input;
  • the judgment module 304 is used to judge whether the calculated Hash value corresponding to each input is consistent with the TxOutHash value under the input field corresponding to the input;
  • the signature module 305 is configured to sign the transaction message if the calculated Hash value corresponding to each input is consistent with the TxOutHash value under the input field corresponding to the input.
  • each output field in the transaction message of the above-mentioned blockchain network includes an amount Value value, the above Value value is used to indicate the amount of the corresponding output amount, and each input field also includes a send output index TxOutIndex value , The TxOutIndex value under each input field is used to indicate the position of the output field corresponding to the corresponding input in the corresponding previous transaction message;
  • the above-mentioned signature module 305 includes:
  • the output amount determination unit is used to obtain each of the above transaction messages according to the above transaction message if the calculated Hash value corresponding to each input is consistent with the TxOutHash value under the input field corresponding to the input Value value under the output field to get the amount of money corresponding to each output in this transaction;
  • Target input selection unit used to select any input as the target input among each input required for this transaction
  • the target output determining unit is used to search for the target output field in the previous transaction message corresponding to the target input according to the TxOutIndex value under the input field corresponding to the target input, wherein the output corresponding to the target output field is the target input;
  • the target input amount determination unit is used to obtain the Value value under the target output field to obtain the amount of the target input amount
  • the traversal judgment unit is used to judge whether the selected input traverses all inputs required for this transaction
  • the target input reselection unit is used to remove the selected input if the selected input has not traversed all the inputs required for this transaction, and select another input as the target input among each input of this transaction;
  • the handling fee determination unit is used to determine the cost of the selected input according to the amount of each input in this transaction and the amount of each output in this transaction if the selected input traverses all the inputs required for this transaction. Handling fee for each transaction;
  • the handling fee display unit is used to display the above handling fee to the user so that the user can confirm whether they are willing to continue the transaction;
  • the signature unit is used to sign the transaction message if an instruction indicating that the user is willing to continue the transaction is received.
  • the above TxOutHash acquisition module 301 includes:
  • the first format judgment unit is used to judge whether the message format of the above transaction message conforms to the preset message format
  • the TxOutHash obtaining unit is used to obtain the TxOutHash value under the input field corresponding to each input required for this transaction in this transaction message if it conforms to the above-mentioned preset message format.
  • the above-mentioned signature device 300 further includes:
  • the previous message judgment module is used to judge whether the previous transaction message corresponding to each input required for this transaction is obtained;
  • the above-mentioned hash value calculation module 303 is specifically used for:
  • the hash hash value of each previous transaction message is calculated to obtain the hash value corresponding to each input.
  • the above hash value calculation module 303 includes:
  • the second format judgment unit is used to judge whether the message format of each previous transaction message conforms to the preset message format
  • the hash value calculation unit is configured to calculate a hash hash value of each previous transaction message if it conforms to the above-mentioned preset message format to obtain a hash value corresponding to each input.
  • the foregoing previous message acquisition module 302 includes:
  • the communication sending unit is used to obtain the identification information of each input required for this transaction, and send the identification information of each input to the preset server to instruct the preset server to perform the operation of searching for the previous transaction message corresponding to each input ;
  • the communication receiving unit is configured to receive the previous transaction message corresponding to each input sent by the preset server.
  • the above-mentioned signature device 300 further includes:
  • the signature termination module is used to terminate the signature if the Hash value corresponding to one or more inputs is inconsistent with the TxOutHash value under the corresponding input field in each input required for this transaction.
  • FIG. 8 is a schematic diagram of a terminal device provided in Embodiment 4 of the present application.
  • the terminal device is a blockchain node applied in a blockchain network, where the transaction message of the blockchain network includes various transaction inputs
  • each legal input corresponds to the previous transaction message
  • each legal The previous transaction message corresponding to input has an output field
  • the output corresponding to the output field is the legal input.
  • the TxOutHash value corresponding to each legal input and the hash of the previous transaction message corresponding to the legal input Hash value is the same.
  • the terminal device 4 of this embodiment includes: a processor 40, a memory 41, and a computer program 42 stored in the memory 41 and executable on the processor 40.
  • the steps in the above method embodiment are implemented, for example, steps S101 to S105 shown in FIG. 1.
  • the processor 40 executes the computer program 42, the functions of each module / unit in the above-described device embodiment are realized, for example, the functions of the modules 301 to 305 shown in FIG. 7.
  • the computer program 42 may be divided into one or more modules / units.
  • the one or more modules / units are stored in the memory 41 and executed by the processor 40 to complete the application.
  • the one or more modules / units may be a series of computer program instruction segments capable of performing specific functions, and the instruction segments are used to describe the execution process of the computer program 42 in the terminal device 4.
  • the above computer program 42 can be divided into a TxOutHash acquisition module, a previous message acquisition module, a hash value calculation module, a judgment module, and a signature module.
  • the specific functions of each module are as follows:
  • the terminal device 4 may be a computing device such as a desktop computer, a notebook, a palmtop computer and a cloud server.
  • the above terminal device may include, but is not limited to, the processor 40 and the memory 41.
  • FIG. 8 is only an example of the terminal device 4 and does not constitute a limitation on the terminal device 4, and may include more or less components than those illustrated, or a combination of certain components, or different components.
  • the above terminal device may further include an input and output device, a network access device, a bus, and the like.
  • the so-called processor 40 may be a central processing unit (Central Processing Unit (CPU), can also be other general-purpose processors, digital signal processors (Digital Signal Processor, DSP), application-specific integrated circuits (Application Specific Integrated Circuit (ASIC), Field-Programmable Gate Array (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc.
  • the general-purpose processor may be a microprocessor or the processor may be any conventional processor or the like.
  • the above-mentioned memory 41 may be an internal storage unit of the above-mentioned terminal device 4, such as a hard disk or a memory of the terminal device 4.
  • the memory 41 may also be an external storage device of the terminal device 4, such as a plug-in hard disk, a Smart Media Card (SMC), a Secure Digital (SD) card, and a flash memory provided on the terminal device 4 Card (Flash Card) etc.
  • the memory 41 may include both the internal storage unit of the terminal device 4 and the external storage device.
  • the memory 41 is used to store the computer program and other programs and data required by the terminal device.
  • the above-mentioned memory 41 may also be used to temporarily store data that has been output or will be output.
  • each functional unit and module is used as an example for illustration.
  • the above-mentioned functions may be allocated by different functional units
  • Module completion means that the internal structure of the above device is divided into different functional units or modules to complete all or part of the functions described above.
  • the functional units and modules in the embodiments may be integrated into one processing unit, or each unit may exist alone physically, or two or more units may be integrated into one unit.
  • the above integrated unit may use hardware It can also be implemented in the form of software functional units.
  • the specific names of each functional unit and module are only for the purpose of distinguishing each other, and are not used to limit the protection scope of the present application.
  • the disclosed device / terminal device and method may be implemented in other ways.
  • the device / terminal device embodiments described above are only schematic.
  • the above-mentioned division of modules or units is only a division of logical functions.
  • the displayed or discussed mutual coupling or direct coupling or communication connection may be indirect coupling or communication connection through some interfaces, devices or units, and may be in electrical, mechanical or other forms.
  • the units described as separate components may or may not be physically separated, and the components displayed as units may or may not be physical units, that is, they may be located in one place or may be distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
  • each functional unit in each embodiment of the present application may be integrated into one processing unit, or each unit may exist alone physically, or two or more units may be integrated into one unit.
  • the above integrated unit may be implemented in the form of hardware or software functional unit.
  • the above integrated module / unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium.
  • the present application can implement all or part of the processes in the methods of the above embodiments, and can also be completed by instructing relevant hardware through a computer program.
  • the above computer program can be stored in a computer-readable storage medium, and the computer program When executed by the processor, the steps of the foregoing method embodiments may be implemented.
  • the above-mentioned computer program includes computer program code, and the above-mentioned computer program code may be in the form of source code, object code, executable file or some intermediate form.
  • the above computer readable medium may include: any entity or device capable of carrying the above computer program code, recording medium, U disk, removable hard disk, magnetic disk, optical disk, computer memory, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), electrical carrier signals, telecommunication signals, and software distribution media.
  • ROM Read-Only Memory
  • RAM Random Access Memory
  • electrical carrier signals telecommunication signals
  • software distribution media any entity or device capable of carrying the above computer program code
  • recording medium U disk, removable hard disk, magnetic disk, optical disk
  • computer memory read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), electrical carrier signals, telecommunication signals, and software distribution media.
  • ROM Read-Only Memory
  • RAM Random Access Memory
  • electrical carrier signals telecommunication signals
  • software distribution media software distribution media.

Abstract

A block chain-based network transaction signature method and device, and a terminal equipment, the signature method comprises: in a current transaction message, acquiring a TxOut Hash value under an input field respectively corresponding to each input required for acquiring the current transaction, and the current transaction message is the transaction message of the current transaction (S101); acquiring a previous transaction message respectively corresponding to each input required for acquiring the current transaction (S102); calculating the Hash value of each previous transaction message to obtain the Hash value corresponding to each input (S103); determining whether the calculated Hash value corresponding to each input is consistent with the TxOut Hash value under the input field corresponding to the input (S104); if the calculated Hash value corresponding to each input is consistent with the TxOut Hash value under the input field corresponding to the input, signing the current transaction message (S105). The signature method can better ensure users' fund safety to some extent.

Description

一种基于区块链网络交易的签名方法、装置及终端设备Signature method, device and terminal equipment based on blockchain network transaction
本申请申明享有2018年11月21日递交的申请号为CN201811390264.7、发明名称为“一种基于区块链网络交易的签名方法、装置及终端设备”中国专利申请的优先权,该中国专利申请的整体内容以参考的方式结合在本申请中。This application declares to enjoy the priority of the Chinese patent application with the application number CN201811390264.7 and the invention titled "A signature method, device and terminal equipment based on blockchain network transactions" submitted on November 21, 2018 The entire content of the application is incorporated in this application by reference.
技术领域Technical field
本申请属于网络交易技术领域,尤其涉及一种基于区块链网络交易的签名方法、签名装置、终端设备及计算机可读存储介质。The present application belongs to the field of network transaction technology, and particularly relates to a signature method, signature device, terminal device and computer-readable storage medium based on a blockchain network transaction.
背景技术Background technique
随着区块链技术的发展,各种电子货币(比如比特币、莱特币、以太币等)在区块链网络中大量流通。With the development of blockchain technology, various electronic currencies (such as Bitcoin, Litecoin, Ether, etc.) circulate in large quantities in the blockchain network.
对于目前的区块链网络来说,当用户在区块链网络中执行转账操作时,需要缴纳一定的手续费,手续费的计算公式为:各个交易输入的金额大小之和-各个交易输出的金额大小之和。例如,对于以比特币为交易币种的区块链网络来说,当用户A向用户B转账时,用户A使用到的各个交易输入的金额大小分别为2比特币和5比特币,用户A向用户B转出了1比特币,区块链网络找零5.5比特币至用户A(虽然该5.5比特币返回至用户A,但依然算本次交易的交易输出),则在本次交易中,用户A需要支付的手续费为0.5比特币。For the current blockchain network, when users perform transfer operations in the blockchain network, they need to pay a certain handling fee. The calculation formula for the handling fee is: the sum of the amount of each transaction input-the output of each transaction The sum of the amounts. For example, for a blockchain network that uses Bitcoin as the transaction currency, when user A transfers money to user B, the amount of each transaction input used by user A is 2 bitcoin and 5 bitcoin, and user A 1 bitcoin was transferred to user B, and the blockchain network changed 5.5 bitcoins to user A (although the 5.5 bitcoin was returned to user A, but still counted as the transaction output of this transaction), then in this transaction , User A needs to pay a handling fee of 0.5 Bitcoin.
技术问题technical problem
由此可见,当用户在转账时,若被非法提供多个交易输入,则会造成用户需缴纳更多的手续费,因此,当用户在区块链网络中执行转账操作时,如何更好的保障用户的资金安全是目前亟待解决的技术问题。It can be seen that when a user is illegally providing multiple transaction inputs when transferring money, it will cause the user to pay more processing fees. Therefore, when the user performs a transfer operation in the blockchain network, how to better Ensuring the safety of users' funds is a technical problem that needs to be solved urgently.
技术解决方案Technical solution
本申请第一方面提供了一种基于区块链网络交易的签名方法,上述区块链网络的交易报文中包括有各个交易输入input分别对应的input字段以及各个交易输出output分别对应的output字段,每个input字段中均包括有发送输出哈希TxOutHash值,每个合法的input均对应有前次交易报文,每个合法的input对应的前次交易报文为存在有一output字段,该output字段对应的output为该合法的input,每个合法的input对应的TxOutHash值与该合法的input对应的前次交易报文的哈希Hash值相同;The first aspect of the present application provides a signature method based on a blockchain network transaction. The above-mentioned blockchain network transaction message includes an input field corresponding to each transaction input and an output field corresponding to each transaction output. , Each input field includes the TxOutHash value of the output hash, each legal input corresponds to the previous transaction message, and the previous transaction message corresponding to each legal input is that there is an output field, the output The output corresponding to the field is the legal input, and the TxOutHash value corresponding to each legal input is the same as the hash hash value of the previous transaction message corresponding to the legal input;
上述签名方法包括:The above signature methods include:
在本次交易报文中,获取本次交易所需的各个input分别对应的input字段下的TxOutHash值,上述本次交易报文为本次交易的交易报文;In this transaction message, obtain the TxOutHash value under the input field corresponding to each input required for this transaction. The above transaction message is the transaction message of this transaction;
获取本次交易所需的各个input分别对应的前次交易报文;Get the previous transaction message corresponding to each input required for this transaction;
计算每个前次交易报文的哈希Hash值,得到每个input对应的Hash值;Calculate the hash hash value of each previous transaction message to get the hash value corresponding to each input;
判断计算得到的每个input对应的Hash值与该input对应的input字段下的TxOutHash值是否一致;Determine whether the calculated Hash value corresponding to each input is consistent with the TxOutHash value under the input field corresponding to the input;
若计算得到的每个input对应的Hash值与该input对应的input字段下的TxOutHash值均一致,则对上述本次交易报文进行签名。If the calculated Hash value corresponding to each input is consistent with the TxOutHash value under the input field corresponding to the input, the above transaction message is signed.
本申请第二方面提供了一种基于区块链网络交易的签名装置,上述区块链网络的交易报文中包括有各个交易输入input分别对应的input字段以及各个交易输出output分别对应的output字段,每个input字段中均包括有发送输出哈希TxOutHash值,每个合法的input均对应有前次交易报文,每个合法的input对应的前次交易报文为存在有一output字段,该output字段对应的output为该合法的input,每个合法的input对应的TxOutHash值与该合法的input对应的前次交易报文的哈希Hash值相同;The second aspect of the present application provides a signature device based on a blockchain network transaction. The above-mentioned blockchain network transaction message includes an input field corresponding to each transaction input and an output field corresponding to each transaction output. , Each input field includes the TxOutHash value of the output hash, each legal input corresponds to the previous transaction message, and the previous transaction message corresponding to each legal input is that there is an output field, the output The output corresponding to the field is the legal input, and the TxOutHash value corresponding to each legal input is the same as the hash hash value of the previous transaction message corresponding to the legal input;
上述签名装置包括:The above signature device includes:
TxOutHash获取模块,用于在本次交易报文中,获取本次交易所需的各个input分别对应的input字段下的TxOutHash值,上述本次交易报文为本次交易的交易报文;The TxOutHash acquisition module is used to obtain the TxOutHash value under the input field corresponding to each input required for this transaction in this transaction message. The above transaction message is the transaction message of this transaction;
前次报文获取模块,用于获取本次交易所需的各个input分别对应的前次交易报文;The previous message acquisition module is used to obtain the previous transaction message corresponding to each input required for this transaction;
哈希值计算模块,用于计算每个前次交易报文的哈希Hash值,得到每个input对应的Hash值;The hash value calculation module is used to calculate the hash value of each previous transaction message to obtain the hash value corresponding to each input;
判断模块,用于判断计算得到的每个input对应的Hash值与该input对应的input字段下的TxOutHash值是否一致;The judgment module is used to judge whether the calculated Hash value corresponding to each input is consistent with the TxOutHash value under the input field corresponding to the input;
签名模块,用于若计算得到的每个input对应的Hash值与该input对应的input字段下的TxOutHash值均一致,则对上述本次交易报文进行签名。The signature module is used to sign the above transaction message if the calculated Hash value corresponding to each input is consistent with the TxOutHash value under the input field corresponding to the input.
本申请第三方面提供了一种终端设备,包括存储器、处理器以及存储在上述存储器中并可在上述处理器上运行的计算机程序,上述处理器执行上述计算机程序时实现如上述第一方面方法的步骤。A third aspect of the present application provides a terminal device, including a memory, a processor, and a computer program stored in the memory and executable on the processor. The processor executes the computer program to implement the method of the first aspect. A step of.
本申请第四方面提供了一种计算机可读存储介质,上述计算机可读存储介质存储有计算机程序,上述计算机程序被处理器执行时实现如上述第一方面方法的步骤。A fourth aspect of the present application provides a computer-readable storage medium. The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the steps of the method of the first aspect described above are implemented.
本申请第五方面提供了一种计算机程序产品,上述计算机程序产品包括计算机程序,上述计算机程序被一个或多个处理器执行时实现如上述第一方面方法的步骤。A fifth aspect of the present application provides a computer program product. The computer program product includes a computer program. When the computer program is executed by one or more processors, the steps of the method of the first aspect described above are implemented.
有益效果Beneficial effect
由上可见,本申请提供了一种基于区块链网络交易的签名方法,该区块链网络的交易报文中,每个合法的input均对应有前次交易报文,每个合法的input对应的前次交易报文的Hash值与该input对应的TxOutHash值相同,本申请所提供的签名方法通过计算本次交易报文中某个input对应的TxOutHash值与该input对应的前次交易报文的Hash值是否相同,来确定该input是否合法,并遍历本次交易报文的所有input,只有当判断出本次交易报文的所有input均合法时,才对本次交易报文进行签名。众所周知,当用户需要在区块链网络中进行转账操作时,该用户所在的区块链节点需要发送签名后的交易报文至区块链交易平台,签名操作用于指示该交易报文为合法报文,区块链交易平台只有在接收到合法报文时,才会执行转账操作。因此,本申请所提供的技术方案可以判断本次交易的各个交易输入是否合法,能够在一定程度上检查出本次交易报文中所嵌入的非法交易输入,只有当判断出所有交易输入均合法时,才会执行签名操作,即才认定本次交易报文合法,进而使得区块链交易平台执行本次转账操作,能够在一定程度上避免在用户转账时,由于交易报文中被非法嵌入多个交易输入,而造成用户需缴纳更多手续费的问题,因此,本申请所提供的签名方法能够在一定程度更好的保障用户的资金安全。As can be seen from the above, this application provides a signature method based on the blockchain network transaction. In the blockchain network transaction message, each legal input corresponds to the previous transaction message, and each legal input The Hash value of the corresponding previous transaction message is the same as the TxOutHash value corresponding to the input. The signature method provided in this application calculates the TxOutHash value corresponding to an input in the transaction message and the previous transaction report corresponding to the input. Whether the hash value of the text is the same to determine whether the input is legal and traverse all inputs of the transaction message. Only sign the transaction message when it is judged that all inputs of the transaction message are legal . As we all know, when a user needs to perform a transfer operation in the blockchain network, the blockchain node where the user is located needs to send a signed transaction message to the blockchain transaction platform. The signature operation is used to indicate that the transaction message is legal For messages, the blockchain trading platform will only perform transfer operations when it receives legitimate messages. Therefore, the technical solution provided in this application can determine whether each transaction input of this transaction is legal, and can check the illegal transaction input embedded in the transaction message to a certain extent, only when it is determined that all transaction inputs are legal Only when the signature operation is executed, that is, the transaction message is determined to be legal, which makes the blockchain transaction platform perform the transfer operation, to a certain extent, it can avoid the illegal embedding of the transaction message when the user transfers the account. Multiple transaction inputs cause the user to pay more processing fees. Therefore, the signature method provided in this application can better protect the user's funds to a certain extent.
附图说明BRIEF DESCRIPTION
为了更清楚地说明本申请实施例中的技术方案,下面将对实施例或现有技术描述中所需要使用的附图作简单地介绍,显而易见地,下面描述中的附图仅仅是本申请的一些实施例,对于本领域普通技术人员来讲,在不付出创造性劳动性的前提下,还可以根据这些附图获得其它的附图。In order to more clearly explain the technical solutions in the embodiments of the present application, the following will briefly introduce the drawings required in the embodiments or the description of the prior art. Obviously, the drawings in the following description are only for the application For some embodiments, for those of ordinary skill in the art, without paying creative labor, other drawings may be obtained based on these drawings.
图1是本申请提供的基于区块链网络交易的签名方法的应用场景示意图;1 is a schematic diagram of an application scenario of a signature method based on a blockchain network transaction provided by this application;
图2是基于区块链网络进行交易时的常用交易报文格式的示意图;Figure 2 is a schematic diagram of the common transaction message format when conducting transactions based on the blockchain network;
图3是本申请实施例一提供的一种基于区块链网络交易的签名方法的实现流程示意图;3 is a schematic diagram of an implementation process of a signature method based on a blockchain network transaction provided by Embodiment 1 of the present application;
图4是本申请实施例一提供的判断各个交易输入是否合法的示意图;4 is a schematic diagram of judging whether each transaction input is legal provided by Embodiment 1 of the present application;
图5是本申请实施例二提供的另一种基于区块链网络交易的签名方法的实现流程示意图;5 is a schematic diagram of an implementation process of another signature method based on a blockchain network transaction provided by Embodiment 2 of the present application;
图6是本申请实施例二提供的手续费计算过程示意图;FIG. 6 is a schematic diagram of a calculation process of a handling fee provided in Example 2 of the present application;
图7是本申请实施例三提供的一种基于区块链网络交易的签名装置的结构示意图;7 is a schematic structural diagram of a signature device based on a blockchain network transaction provided by Embodiment 3 of the present application;
图8是本申请实施例四提供的终端设备的结构示意图。8 is a schematic structural diagram of a terminal device according to Embodiment 4 of the present application.
本发明的实施方式Embodiments of the invention
以下描述中,为了说明而不是为了限定,提出了诸如特定系统结构、技术之类的具体细节,以便透彻理解本申请实施例。然而,本领域的技术人员应当清楚,在没有这些具体细节的其它实施例中也可以实现本申请。在其它情况中,省略对众所周知的系统、装置、电路以及方法的详细说明,以免不必要的细节妨碍本申请的描述。In the following description, for the purpose of illustration rather than limitation, specific details such as specific system structure and technology are proposed to thoroughly understand the embodiments of the present application. However, those skilled in the art should understand that the present application can also be implemented in other embodiments without these specific details. In other cases, detailed descriptions of well-known systems, devices, circuits, and methods are omitted to avoid unnecessary details hindering the description of the present application.
本申请所提供的基于区块链网络交易的签名方法应用于区块链网络中的区块链节点。附图1为本申请提供的基于区块链网络交易的签名方法的应用场景示意图,该应用场景中包括区块链节点1以及区块链交易平台2,当区块链节点1要发起转账交易时,会首先生成一交易报文3,通常情况下,该交易报文3中包括各个收款方的账号以及向各个收款方的账号的转账金额大小,比如,若区块链节点1向区块链节点X以及区块链节点Y转账时,该交易报文3中包括区块链节点X的账号x、向账号x的转账金额、区块链节点Y的账号y以及向账号y的转账金额。区块链节点1将该交易报文3发送至区块链交易平台2,区块链交易平台2在判断出该交易报文3合法时,会协助区块链节点1完成转账交易。The signature method based on the blockchain network transaction provided in this application is applied to the blockchain nodes in the blockchain network. Figure 1 is a schematic diagram of an application scenario of a signature method based on a blockchain network transaction provided by this application. The application scenario includes a blockchain node 1 and a blockchain transaction platform 2. When the blockchain node 1 initiates a transfer transaction Time, a transaction message 3 will be generated first. Normally, the transaction message 3 includes the accounts of each payee and the size of the transfer amount to each account of the payee. For example, if the blockchain node 1 When transferring money from blockchain node X and blockchain node Y, the transaction message 3 includes the account x of the blockchain node X, the amount transferred to the account x, the account y of the blockchain node Y, and the transfer amount. The blockchain node 1 sends the transaction message 3 to the blockchain transaction platform 2. When the blockchain transaction platform 2 judges that the transaction message 3 is legal, it will assist the blockchain node 1 to complete the transfer transaction.
此外,对于目前的区块链网络,当用户在区块链网络中执行转账操作时,通常需要缴纳一定的手续费。如图1所示,位于区块链节点1处的用户A发起转账操作时,通常是需要缴纳一定的手续费的,该手续费的金额大小与该区块链节点1在转账时所使用的各个交易输入input的金额大小以及各个交易输出output的金额大小有关,上述区块链交易平台2在接收到交易报文3,并判断出该交易报文3合法之后,会收取一定的手续费,对于以比特币为交易币种的区块链网络来说,该手续费会奖励给矿工。In addition, for the current blockchain network, when users perform transfer operations in the blockchain network, they usually need to pay a certain processing fee. As shown in Fig. 1, when user A located at blockchain node 1 initiates a transfer operation, it is usually necessary to pay a certain handling fee. The amount of the handling fee is the same as that used by the blockchain node 1 when transferring money. The amount of input of each transaction is related to the amount of output of each transaction. After receiving the transaction message 3 and determining that the transaction message 3 is legal, the above-mentioned blockchain transaction platform 2 will charge a certain fee. For the blockchain network that uses Bitcoin as the transaction currency, this fee will be rewarded to the miners.
对于不同类型的区块链网络来说(比如,以比特币为交易币种的区块链网络、以以太币为交易币种的区块链网络、以莱特币为交易币种的区块链网络等等),交易报文的格式通常也不同。下面利用附图2,来阐述一种较为常用的交易报文格式,以比特币为交易币种的区块链网络就采用如图2所示的交易报文格式。For different types of blockchain networks (for example, a blockchain network with Bitcoin as a transaction currency, a blockchain network with Ethereum as a transaction currency, and a blockchain with Litecoin as a transaction currency Internet, etc.), the format of the transaction message is usually different. The following uses Figure 2 to illustrate a more commonly used transaction message format. The blockchain network that uses Bitcoin as the transaction currency adopts the transaction message format shown in FIG. 2.
如图2所示,交易报文中包括有各个交易输入input所对应的input字段以及各个交易输出output所对应的output字段,该交易报文中还包括Input-Counter字段和Output-Counter字段,Input-Counter字段的大小用于指示当前交易报文中input字段的个数,Output-Counter字段的大小用于指示当前交易报文中output字段的个数,在附图2所示的例子中,Input-Counter和Output-Counter的大小应均为2。As shown in Figure 2, the transaction message includes the input field corresponding to each transaction input input and the output field corresponding to each transaction output output. The transaction message also includes the Input-Counter field and the Output-Counter field, Input -The size of the Counter field is used to indicate the number of input fields in the current transaction message, and the size of the Output-Counter field is used to indicate the number of output fields in the current transaction message. In the example shown in FIG. 2, Input -The size of Counter and Output-Counter should be 2.
如图2所示,对于每个input字段,均包括有发送输出哈希TxOutHash值、发送输出索引TxOutIndex值、脚本长度ScriptLen值以及签名公钥Sign&PubKey值。其中,对于每个input字段下的TxOutHash值为该input字段对应的input的前次交易报文的哈希Hash值,如图2所示,第一个input字段中的TxOutHash值应为交易输入input1对应的前次交易报文I的Hash值,其中,每个input对应的前次交易报文为存在有一output字段,该output字段对应的output为该input的交易报文(举例来说,对于交易输入input1,若该input1所对应的前次交易报文为前次交易报文I,则该前次交易报文I中包括有一output字段,该output字段对应的交易输出即为该input1);每个input字段下的TxOutIndex值用于指示对应的input具体对应前次交易报文中的哪一个output字段,比如,附图2中的交易输入input1对应的前次交易报文为前次交易报文I,假设该前次交易报文I中包括两个output字段,分别为outputA字段和outputB字段,若该outputA字段对应的交易输出为input1,则该input1所对应的前次交易报文I的output字段具体为outputA字段,则在本次交易报文中,可通过该input1对应的input字段中的TxOutIndex值,得到该input1具体对应前次交易报文I 的outputA字段;每个input字段下的ScriptLen值用于指示该input字段中Sign&PubKey值的字段长度;每个input字段下的Sign&Pubkey为本次交易的交易签名和交易公钥。As shown in FIG. 2, for each input field, there are a send output hash TxOutHash value, a send output index TxOutIndex value, a script length ScriptLen value, and a signature public key Sign & PubKey value. Among them, for each input field, the TxOutHash value is the hash hash value of the previous transaction message of the input corresponding to the input field, as shown in FIG. 2, the TxOutHash value in the first input field should be the transaction input input1 The Hash value of the corresponding previous transaction message I, where the previous transaction message corresponding to each input has an output field, and the output corresponding to the output field is the input transaction message (for example, for transactions Input input1, if the previous transaction message corresponding to input1 is the previous transaction message I, then the previous transaction message I includes an output field, and the transaction output corresponding to the output field is the input1); The TxOutIndex value under an input field is used to indicate which output field in the previous transaction message the corresponding input corresponds to, for example, the previous transaction message corresponding to the transaction input input1 in FIG. 2 is the previous transaction message I, assuming that the previous transaction message I includes two output fields, namely outputA field and outputB field, if the transaction output corresponding to the outputA field is input1, then the output of the previous transaction message I corresponding to the input1 The field is specifically the outputA field. In this transaction message, the TxOutIndex value in the input field corresponding to the input1 can be used to obtain the outputA field corresponding to the previous transaction message I; the ScriptLen under each input field The value is used to indicate the field length of the Sign & PubKey value in the input field; the Sign & Pubkey under each input field is the transaction signature and transaction public key of this transaction.
如图2所示,对于每个output字段,均包括有金额Value值、脚本长度ScriptLen值以及PKScript值。每个output字段下的Value值用于指示对应的output的金额大小;每个output字段下的ScriptLen值用于指示该output字段中PKScript值的字段长度;每个output字段下的PKScript值用于指示收款方的账户公钥或账户地址(该账号地址即为收款方账号)。若output字段下的PKScript用于指示收款方的账户公钥,则区块链交易平台可通过该账户公钥计算出收款方的账户地址,从而进行转账交易。As shown in Figure 2, for each output field, it includes the amount Value value, script length ScriptLen value, and PKScript value. The Value value under each output field is used to indicate the amount of the corresponding output; the ScriptLen value under each output field is used to indicate the field length of the PKScript value in the output field; the PKScript value under each output field is used to indicate Payee's account public key or account address (the account address is the payee account). If the PKScript under the output field is used to indicate the account public key of the beneficiary, the blockchain trading platform can calculate the account address of the beneficiary from the account public key, so as to conduct the transfer transaction.
本申请所提供的基于区块链网络交易的签名方法可以应用在使用如图2所示的交易报文格式的区块链网络中,比如可以应用在以比特币为币种的区块链网络中。但是,请本领域技术人员注意,本申请所提供的基于区块链网络交易的签名方法并非必须应用在使用如图2所示的交易报文格式的区块链网络中,具体可参见本申请实施例一以及实施例二的描述。The signature method based on the blockchain network transaction provided by this application can be applied to the blockchain network using the transaction message format as shown in FIG. 2, such as the blockchain network with Bitcoin as the currency in. However, those skilled in the art should note that the signature method based on the blockchain network transaction provided by this application does not have to be applied to the blockchain network using the transaction message format as shown in FIG. 2. For details, please refer to this application The description of Embodiment 1 and Embodiment 2.
实施例一Example one
下面对本申请实施例一提供的一种基于区块链网络交易的签名方法进行描述,该签名方法应用在如下区块链网络中:The following describes a signature method based on blockchain network transactions provided in Embodiment 1 of the present application. The signature method is applied to the following blockchain network:
该区块链网络的交易报文中包括有各个交易输入input分别对应的input字段以及各个交易输出output分别对应的output字段,每个input字段中均包括TxOutHash值,每个合法的input均对应有前次交易报文,每个合法的input对应的前次交易报文为存在有一output字段,该output字段对应的output为该合法的input,每个合法的input对应的TxOutHash值与该合法的input对应的前次交易报文的哈希Hash值相同(这里之所以将input限定为“合法”的主要原因是:当交易报文中嵌入非法的input对应的input字段时,该非法的input不一定对应有前次交易报文,即便对应有前次交易报文,该非法的input对应的TxOutHash值也与其前次交易报文的Hash值不一定相同)。The transaction message of the blockchain network includes an input field corresponding to each transaction input input and an output field corresponding to each transaction output output. Each input field includes a TxOutHash value, and each legal input corresponds to Last transaction message, there is an output field corresponding to the previous transaction message corresponding to each legal input, the output corresponding to the output field is the legal input, and the TxOutHash value corresponding to each legal input is the The corresponding hash value of the previous transaction message is the same (the main reason why the input is limited to "legal" here is: when the input field corresponding to the illegal input is embedded in the transaction message, the illegal input is not necessarily Corresponding to the previous transaction message, even if there is a previous transaction message, the TxOutHash value corresponding to the illegal input is not necessarily the same as the Hash value of the previous transaction message).
申请实施例一所限定的区块链网络的交易报文格式具体可参见附图2以及相应的文字描述部分。但是,请本领域技术人员注意,本申请实施例一提供的签名方法所应用的区块链网络的报文格式中,不一定包含有Input-Counter字段、Output-Counter字段、input字段下也不一定包含ScriptLen值、output字段下也不一定有Value值以及ScriptLen值等。此外,由于本申请实施例一所提供的签名方法需要对本次交易报文进行签名,因此,可以与图2相同,交易报文中每个input字段下可以包括Sign&PubKey,但是请本领域技术人员注意,本申请实施例中对本次交易报文进行签名所对应的字段并不一定与图2完全相同。For the format of the transaction message of the blockchain network defined in the first embodiment of the application, please refer to FIG. 2 and the corresponding text description part. However, those skilled in the art should note that the packet format of the blockchain network to which the signature method provided in Embodiment 1 of the present application does not necessarily include the Input-Counter field, Output-Counter field, nor under the input field. It must contain the ScriptLen value, and the Value and ScriptLen values may not necessarily be under the output field. In addition, since the signature method provided in the first embodiment of the present application needs to sign the transaction message, it can be the same as FIG. 2, and the Sign & PubKey can be included under each input field in the transaction message, but please ask a person skilled in the art Note that the field corresponding to the signature of the transaction message in the embodiment of the present application is not necessarily the same as that in FIG. 2.
本申请实施例一提供的签名方法如图3所示,包括:The signature method provided in Embodiment 1 of this application is shown in FIG. 3 and includes:
在步骤S101中,在本次交易报文中,获取本次交易所需的各个input分别对应的input字段下的TxOutHash值,上述本次交易报文为本次交易的交易报文;In step S101, in this transaction message, the TxOutHash value under the input field corresponding to each input required for this transaction is obtained. The above transaction message is the transaction message of this transaction;
在本次交易中,为了避免本次交易报文中非法插入多个input而导致用户需支付较多的手续费,需要首先执行本申请所提供的步骤S101-S105,在判断出本次交易报文中所需的各个input均合法时,才对本次交易报文进行签名。In this transaction, in order to avoid illegal insertion of multiple inputs in the transaction message and cause the user to pay more processing fees, it is necessary to first perform the steps S101-S105 provided in this application to determine the transaction report Only when all the inputs required in the text are legal, the transaction message is signed.
为了详细描述本申请实施例一所述的技术方案,下面利用附图4来说明。In order to describe the technical solution described in the first embodiment of the present application in detail, the following description will be made with reference to FIG. 4.
如图4所示,本次交易报文中包括3个input字段,分别为input字段1、input字段2以及input字段3,则在该步骤S101中,从本次交易报文中读取input字段1中的TxOutHash值、input字段2中的TxOutHash值以及input字段3中的TxOutHash值。As shown in FIG. 4, the transaction message includes three input fields, namely input field 1, input field 2, and input field 3, in step S101, the input field is read from the transaction message The TxOutHash value in 1, the TxOutHash value in the input field 2, and the TxOutHash value in the input field 3.
此外,在本申请实施例中,该步骤S101可以包括:判断上述本次交易报文是否符合预设报文格式,若符合,则再在该本次交易报文中,获取本次交易所需的各个input分别对应的input字段下的TxOutHash值。也即是,首先检查本次交易报文是否符合预设报文格式,比如,查看本次交易报文是否包括预设的各个字段,以及各个字段的长度是否符合预设长度等,只有在本次交易报文符合预设报文格式后,再来读取各个input字段下的TxOutHash值。In addition, in the embodiment of the present application, the step S101 may include: determining whether the above-mentioned transaction message conforms to a preset message format, and if it matches, then in the transaction message, obtain the transaction request The TxOutHash value under the input field corresponding to each input of. That is, first check whether the transaction message conforms to the preset message format. For example, check whether the transaction message includes the preset fields and whether the length of each field matches the preset length. After the secondary transaction message conforms to the preset message format, let's read the TxOutHash value under each input field.
在步骤S102中,获取本次交易所需的各个input分别对应的前次交易报文;In step S102, obtain the previous transaction message corresponding to each input required for this transaction;
在本申请实施例中,前次交易报文可以通过与预设服务器通信获得,该步骤S102可以包括以下步骤S1021-S1022:In the embodiment of the present application, the previous transaction message may be obtained by communicating with a preset server, and this step S102 may include the following steps S1021-S1022:
在步骤S1021中,获取本次交易所需的各个input的标识信息,将各个input的标识信息发送至预设服务器,以指示该预设服务器执行查找各个input对应的前次交易报文的操作;In step S1021, the identification information of each input required for this transaction is acquired, and the identification information of each input is sent to the preset server to instruct the preset server to perform an operation of searching for the previous transaction message corresponding to each input;
其中,每个input的标识信息可以为该input的入账时间、入账金额、入账账号和/或发款账号等等,比如,对于某一inputX来说,该inputX的标识信息可以包括:2018年10月30日下午5:10入账、5比特币、入款账号为X、发款账号为Y。上述预设服务器在接收到各个input的标识信息之后,就根据各个input的标识信息,查找各个input对应的前次交易报文,比如,对于上述inputX来说,该预设服务器就查找对应有一交易输出outputX的交易报文,该outputX为2018年10月30日下午5:10转出、金额大小5比特币、收款账号为X且发款账号为Y的交易输出,对应有该outputX的交易报文即为inputX的前次交易报文。Among them, the identification information of each input may be the input time, the amount of the input, the account number and / or the payment account of the input, etc. For example, for an inputX, the input information of the inputX may include: 2018 10 At 5:10 pm on the 30th of the month, 5 bitcoin, the deposit account is X, and the payment account is Y. After receiving the identification information of each input, the above preset server searches for the previous transaction message corresponding to each input according to the identification information of each input. For example, for the above inputX, the preset server searches for a transaction corresponding to Output outputX transaction message, the outputX is the transaction output at 5:10 pm on October 30, 2018, the amount is 5 bitcoin, the receiving account is X and the sending account is Y, corresponding to the transaction with the outputX The message is the last transaction message of inputX.
在步骤S1022中,接收上述预设服务器发送的各个input分别对应的前次交易报文;In step S1022, receive the previous transaction message corresponding to each input sent by the preset server respectively;
此外,该步骤S1022可以包括:在将各个input的标识信息发送至上述预设服务器之后,判断在预设时间段内是否接收到上述预设服务器返回的各个input分别对应的前次交易报文;若接收到各个input分别对应的前次交易报文,则执行后续步骤S103;若未接收到各个input分别对应的前次交易报文,则认为本次交易中存在非法的input,此时,可以输出用于提示用户本次交易不合法的提示信息,提醒用户是否对本次交易报文进行签名;或者,可以输出用于提示用户本次交易不合法的提示信息,并终止对本次交易报文的签名操作;或者,可以直接终止本次签名,或者,还可以直接终止本次交易,即不将本次交易报文发送至区块链交易平台。In addition, this step S1022 may include: after sending the identification information of each input to the preset server, determining whether a previous transaction message corresponding to each input returned by the preset server is received within a preset time period; If the previous transaction message corresponding to each input is received, the subsequent step S103 is performed; if the previous transaction message corresponding to each input is not received, it is considered that there is an illegal input in this transaction. Output a reminder message to remind the user that the transaction is illegal, to remind the user whether to sign the transaction message; or, you can output a reminder message to remind the user that the transaction is illegal, and terminate the transaction report The signature operation of the document; or, you can directly terminate the signature, or you can directly terminate the transaction, that is, do not send the transaction message to the blockchain trading platform.
如图4所示,本次交易报文的input1对应的前次交易报文为前次交易报文A,input2对应的前次交易报文为前次交易报文B,input3对应的前次交易报文为前次交易报文C。As shown in Figure 4, the previous transaction message corresponding to input1 of this transaction message is the previous transaction message A, the previous transaction message corresponding to input2 is the previous transaction message B, and the previous transaction corresponding to input3 The message is the last transaction message C.
在步骤S103中,计算每个前次交易报文的Hash值,得到每个input对应的Hash值;In step S103, calculate the hash value of each previous transaction message to obtain the hash value corresponding to each input;
在本申请实施例中,对报文的哈希值计算方法可以采用目前常用的方法,比如SHA256算法等,本申请对哈希值计算方法不作限定。如图4所示,在该步骤S103中,需要计算前次交易报文A的Hash值(该前次交易报文A的Hash值即为input1对应的Hash值)、前次交易报文B的Hash值(该前次交易报文B的Hash值即为input2对应的Hash值)以及前次交易报文C的Hash值(该前次交易报文C的Hash值即为input3对应的Hash值)。In the embodiment of the present application, the method for calculating the hash value of the message may use a currently commonly used method, such as the SHA256 algorithm, etc. The present application does not limit the method for calculating the hash value. As shown in FIG. 4, in this step S103, it is necessary to calculate the Hash value of the previous transaction message A (the Hash value of the previous transaction message A is the Hash value corresponding to input1), and the value of the previous transaction message B Hash value (the hash value of the previous transaction message B is the hash value corresponding to input2) and the hash value of the previous transaction message C (the hash value of the previous transaction message C is the hash value corresponding to input3) .
此外,在该步骤S103之前,还可以包括步骤:判断是否获取到本次交易所需的各个input分别对应的前次交易报文。与步骤S102所述的相同,若未接收到各个input分别对应的前次交易报文,则认为本次交易中存在非法的input,此时,可以输出用于提示用户本次交易不合法的提示信息,提醒用户是否对本次交易报文进行签名;或者,可以输出用于提示用户本次交易不合法的提示信息,并终止对本次交易报文的签名操作;或者,可以直接终止本次签名;或者,还可以直接终止本次交易,即不将本次交易报文发送至区块链交易平台。相应地,该步骤S103具体为:若获取本次交易所需的各个input分别对应的前次交易报文,则计算每个前次交易报文的哈希Hash值,得到每个input对应的Hash值。In addition, before this step S103, it may further include a step of determining whether a previous transaction message corresponding to each input required for this transaction is obtained. As described in step S102, if the previous transaction message corresponding to each input is not received, it is considered that there is an illegal input in this transaction, and at this time, a prompt for notifying the user that the transaction is illegal may be output Information to remind the user whether to sign the transaction message; or, can output a prompt message to remind the user that the transaction is illegal, and terminate the signing operation of the transaction message; or, you can directly terminate the transaction message Signature; or, you can directly terminate the transaction, that is, do not send the transaction message to the blockchain trading platform. Correspondingly, this step S103 is specifically: if the previous transaction message corresponding to each input required for this transaction is obtained, then the hash hash value of each previous transaction message is calculated to obtain the hash corresponding to each input value.
此外,该步骤S103也可以包括:In addition, this step S103 may also include:
判断各个前次交易报文的报文格式是否符合预设报文格式;Determine whether the message format of each previous transaction message conforms to the preset message format;
若符合该预设报文格式,则计算每个前次交易报文的哈希Hash值,得到每个input对应的Hash值。If it conforms to the preset message format, the hash hash value of each previous transaction message is calculated to obtain the hash value corresponding to each input.
由于本申请实施例需要对本次交易报文进行签名,因此本次交易报文中可以包括如附图2所示的Sign&PubKey,在这种情况下,该步骤S103也可以包括:在获取到各个前次交易报文之后,根据每个前次交易报文中的签名值和公钥(可以为Sign&PubKey)来判断每个前次交易报文是否为合法报文;当判断出各个前次交易报文均为合法报文时,计算每个每个前次交易报文的哈希Hash值,得到每个input对应的Hash值。Since the embodiment of the present application needs to sign the transaction message, the transaction message may include the Sign & PubKey shown in FIG. 2 in this case. In this case, the step S103 may also include: After the previous transaction message, determine whether each previous transaction message is a legal message based on the signature value and public key (can be Sign & PubKey) in each previous transaction message; when judging each previous transaction message When the messages are all legitimate messages, calculate the hash value of each previous transaction message to obtain the hash value corresponding to each input.
若判断出某一前次交易报文不合法(不符合预设的报文格式,或者根据签名值以及公钥判断出不为合法报文)时,可以输出用于提示用户本次交易不合法的提示信息,提醒用户是否对本次交易报文进行签名;或者,可以输出用于提示用户本次交易不合法的提示信息,并终止对本次交易报文的签名操作;或者,可以直接终止本次签名,或者,还可以直接终止本次交易,即不将本次交易报文发送至区块链交易平台。If it is determined that a previous transaction message is illegal (does not conform to the preset message format, or based on the signature value and public key to determine that it is not a legal message), it can be output to prompt the user that the transaction is illegal Prompt message to remind the user whether to sign the transaction message; or, you can output a prompt message to remind the user that the transaction is illegal, and terminate the signature operation of the transaction message; or, you can directly terminate This signature, or, you can also directly terminate this transaction, that is, do not send this transaction message to the blockchain trading platform.
在步骤S104中,判断计算得到的每个input对应的Hash值与该input对应的input字段下的TxOutHash值是否一致;In step S104, it is determined whether the calculated Hash value corresponding to each input is consistent with the TxOutHash value under the input field corresponding to the input;
如图4所示,即是判断input字段1下的TxOutHash与前次交易报文A的Hash值是否一致、input字段2下的TxOutHash与前次交易报文B的Hash值是否一致以及input字段3下的TxOutHash与前次交易报文C的Hash值是否一致,若均一致,则可以认为本次交易报文中的各个input均是合法的,否则,若在本次交易所需的各个input中,存在有一个或多个input对应的Hash值与对应的input字段下的TxOutHash值不一致(比如,input字段2下的TxOutHash与前次交易报文B的Hash值不相同),则可以输出用于提示用户本次交易不合法的提示信息,提醒用户是否对本次交易报文进行签名;或者,可以输出用于提示用户本次交易不合法的提示信息,并终止对本次交易报文的签名操作;或者,可以直接终止本次签名,或者,还可以直接终止本次交易,即不将本次交易报文发送至区块链交易评。As shown in Figure 4, it is to determine whether the TxOutHash under input field 1 is consistent with the Hash value of the previous transaction message A, the TxOutHash under input field 2 is consistent with the Hash value of the previous transaction message B, and the input field 3 Whether the TxOutHash of the next transaction is the same as the Hash value of the previous transaction message C. If they are the same, each input in the transaction message can be considered legal, otherwise, if it is in each input required for this transaction , The Hash value corresponding to one or more inputs is inconsistent with the TxOutHash value under the corresponding input field (for example, the TxOutHash under input field 2 is not the same as the Hash value of the previous transaction message B), then it can be output for Prompt information to remind the user that the transaction is illegal, to remind the user whether to sign the transaction message; or, you can output a prompt message to remind the user that the transaction is illegal, and terminate the signature of the transaction message Operation; or, you can directly terminate this signature, or you can directly terminate this transaction, that is, do not send this transaction message to the blockchain transaction review.
在步骤S105中,若计算得到的每个input对应的Hash值与该input对应的input字段下的TxOutHash值均一致,则对本次交易报文进行签名;In step S105, if the calculated Hash value corresponding to each input is consistent with the TxOutHash value under the input field corresponding to the input, the transaction message is signed;
如图4所示,若input字段1下的TxOutHash与前次交易报文A的Hash值一致、input字段2下的TxOutHash与前次交易报文B的Hash值一致并且input字段3下的TxOutHash与前次交易报文C的Hash值一致,则认为本次交易报文的所有input均合法,则对本次交易报文进行签名(若本申请实施例所限定的交易报文的input字段下包括Sign&PubKey,则可以将本次交易的交易签名和交易公钥写入交易报文中input字段中的Sign&PubKey中),以使区块链交易平台协助完成本次交易。As shown in Figure 4, if TxOutHash under input field 1 is consistent with the hash value of the previous transaction message A, TxOutHash under input field 2 is consistent with the hash value of the previous transaction message B, and TxOutHash under input field 3 is consistent If the hash value of the previous transaction message C is the same, it is considered that all inputs of the transaction message are legal, and then sign the transaction message (if the input field of the transaction message as defined in this application example includes Sign & PubKey, you can write the transaction signature and transaction public key of this transaction into the Sign & PubKey in the input field of the transaction message), so that the blockchain trading platform can help complete the transaction.
由上可见,本申请实施例一所提供的技术方案可以判断本次交易的各个交易输入是否合法,能够在一定程度上检查出本次交易报文中所嵌入的非法交易输入,只有当判断出所有交易输入均合法时,才会执行签名操作,即才认定本次交易报文合法,进而使得区块链交易平台执行本次转账操作,能够在一定程度上避免在用户转账时,由于交易报文中被非法嵌入多个交易输入,而造成用户需缴纳更多手续费的问题,因此,本申请所提供的签名方法能够在一定程度更好的保障用户的资金安全。It can be seen from the above that the technical solution provided in Example 1 of this application can determine whether each transaction input of this transaction is legal, and can check the illegal transaction input embedded in this transaction message to a certain extent, only when judged Only when all transaction inputs are legal, will the signature operation be performed, that is, the transaction message will be deemed legal, which will enable the blockchain transaction platform to perform this transfer operation, which can avoid the user's transfer due to the transaction report to a certain extent. Multiple transaction inputs are illegally embedded in the article, which causes the user to pay more processing fees. Therefore, the signature method provided by this application can better protect the user's funds to a certain extent.
实施例二Example 2
下面对本申请实施例二提供的另一种基于区块链网络交易的签名方法进行描述,本申请实施例二所述的签名方法应用在如下区块链网络中:The following describes another signature method based on blockchain network transactions provided in Embodiment 2 of this application. The signature method described in Embodiment 2 of this application is applied to the following blockchain network:
该区块链网络的交易报文中包括各个input字段以及各个output字段,每个input字段中包括TxOutHash值,每个output字段中包括金额Value值,该Value值用于指示对应的output的金额大小,每个input字段下还包括发送输出索引TxOutIndex值,每个input字段下的TxOutIndex值用于指示对应的input所对应的output字段在对应的前次交易报文中的位置。申请实施例一所限定的区块链网络的交易报文格式具体可参见附图2以及相应的文字描述部分。此外,与实施例一相同,由于本申请实施例二所提供的签名方法需要对本次交易报文进行签名,因此,可以与图2相同,交易报文中每个input字段下可以包括Sign&PubKey,但是请本领域技术人员注意,本申请实施例中对本次交易报文进行签名所对应的字段并不一定与图2完全相同。The transaction message of the blockchain network includes each input field and each output field, each input field includes a TxOutHash value, and each output field includes an amount Value, which is used to indicate the amount of the corresponding output The TxOutIndex value under each input field is also included under each input field. The TxOutIndex value under each input field is used to indicate the position of the output field corresponding to the corresponding input in the corresponding previous transaction message. For the format of the transaction message of the blockchain network defined in the first embodiment of the application, please refer to FIG. 2 and the corresponding text description part. In addition, as in the first embodiment, since the signature method provided in the second embodiment of the present application needs to sign the transaction message, it can be the same as in FIG. 2, and the transaction message can include Sign & PubKey under each input field. However, those skilled in the art should note that the field corresponding to the signature of the transaction message in the embodiment of the present application is not necessarily the same as FIG. 2.
本申请实施例二所述的签名方法如图5所示,包括:The signature method described in Embodiment 2 of this application is shown in FIG. 5 and includes:
在步骤S201中,在本次交易报文中,获取本次交易所需的各个input分别对应的input字段下的TxOutHash值,上述本次交易报文为本次交易的交易报文;In step S201, in this transaction message, the TxOutHash value under the input field corresponding to each input required for this transaction is obtained. The above transaction message is the transaction message of this transaction;
在步骤S202中,获取本次交易所需的各个input分别对应的前次交易报文;In step S202, obtain the previous transaction message corresponding to each input required for this transaction;
在步骤S203中,计算每个前次交易报文的Hash值,得到每个input对应的Hash值;In step S203, calculate the hash value of each previous transaction message to obtain the hash value corresponding to each input;
在步骤S204中,判断计算得到的每个input对应的Hash值与该input对应的input字段下的TxOutHash值是否一致;In step S204, it is determined whether the calculated Hash value corresponding to each input is consistent with the TxOutHash value under the input field corresponding to the input;
在本申请实施例二中,上述步骤S201-S204与实施例一中的步骤S101-S104执行方式相同,具体可参见实施例一的描述,此处不再赘述。In the second embodiment of the present application, the above steps S201-S204 are executed in the same manner as the steps S101-S104 in the first embodiment. For details, please refer to the description of the first embodiment, which will not be repeated here.
在步骤S205中,若计算得到的每个input对应的Hash值与该input对应的input字段下的TxOutHash值均一致,则根据上述本次交易报文,获取上述本次交易报文的各个output字段下的Value值,得到本次交易中每个output对应的金额大小;In step S205, if the calculated Hash value corresponding to each input is consistent with the TxOutHash value under the input field corresponding to the input, then according to the above transaction message, each output field of the above transaction message is obtained Under the Value value, get the amount corresponding to each output in this transaction;
在本申请实施例二中,若通过步骤S201-S204,判断出本次交易报文的各个交易输入是合法的,则可以进一步将本次交易需要缴纳的手续费计算并显示出来,以便于用户知晓本次交易的手续费,并可以使用户根据本次交易的手续费来确定是否继续进行交易。In the second embodiment of the present application, if it is determined through steps S201-S204 that each transaction input of the transaction message is legal, the transaction fee to be paid for this transaction can be further calculated and displayed to facilitate the user Know the transaction fee of this transaction, and enable users to determine whether to continue the transaction based on the transaction fee of this transaction.
为了更清楚的描述本申请实施例二所述的技术方案,下面利用附图6进行说明。如图6所示,在该步骤S205中,通过读取本次交易报文中各个output字段下的Value值来确定各个交易输出的金额大小,比如,output字段1下的Value值用于指示交易输出output1的金额大小,output字段2下的Value值用于指示交易输出output2的金额大小。In order to more clearly describe the technical solution described in Embodiment 2 of the present application, the following uses FIG. 6 for illustration. As shown in FIG. 6, in this step S205, the value of each transaction output is determined by reading the Value value under each output field in the transaction message, for example, the Value value under output field 1 is used to indicate the transaction The amount of output1 is output, and the Value value under output field 2 is used to indicate the amount of output2 of the transaction.
在步骤S206中,在本次交易所需的各个input中,选取一input作为目标input;In step S206, among each input required for the transaction, an input is selected as the target input;
如图6所示,本次交易需要三个input,分别为input1、input2以及input3,可以从input1、input2以及input3中选取任意一input作为目标input,比如选取input1作为目标input。As shown in Figure 6, this transaction requires three inputs, namely input1, input2, and input3. You can select any input from input1, input2, and input3 as the target input, for example, select input1 as the target input.
在步骤S207中,根据上述目标input对应的input字段下TxOutIndex值,在该目标input对应的前次交易报文中,查找目标output字段,该目标output字段对应的output为该目标input;In step S207, according to the TxOutIndex value under the input field corresponding to the target input, in the previous transaction message corresponding to the target input, search for the target output field, and the output corresponding to the target output field is the target input;
若在步骤S206中,选取input1为目标input,则在本次交易报文中,获取该input1对应的input字段1中的TxOutIndex值,该input字段1中的TxOutIndex值用于指示该input1对应前次交易报文A中的哪一个output字段,如图6所示,可以得出,该input1对应前次交易报文A中的第一个output字段,即output字段A1,从而得到目标output字段即为output字段A1。If in step S206, input1 is selected as the target input, in this transaction message, the TxOutIndex value in input field 1 corresponding to input1 is obtained, and the TxOutIndex value in input field 1 is used to indicate that input1 corresponds to the previous time Which output field in the transaction message A, as shown in FIG. 6, can be drawn that the input1 corresponds to the first output field in the previous transaction message A, that is, the output field A1, so that the target output field is output field A1.
在步骤S208中,获取上述目标output字段下的Value值,得到该目标input的金额大小;In step S208, obtain the Value value under the target output field to obtain the amount of the target input;
如图6所示,将前次交易报文A中,output字段A1下的Value值作为input1的金额大小。As shown in Figure 6, the value of the value in the output field A1 in the previous transaction message A is used as the amount of input1.
在步骤S209中,判断所选取的input是否遍历完本次交易所需的所有input,若否,则执行步骤S210,若是,则执行步骤S211;In step S209, it is determined whether the selected input has traversed all the inputs required for the transaction, if not, step S210 is executed, and if so, step S211 is executed;
在步骤S210中,除去已选取的input,在本次交易的各个input中,在选取一input作为目标input,返回步骤S207;In step S210, remove the selected input, and in each input of this transaction, select an input as the target input, and return to step S207;
在上述步骤S209中,判断是否获取到本次交易报文的每一个input的金额大小,若没有,则再选取一input作为目标input,并返回执行步骤S207;In the above step S209, it is determined whether the amount of each input of the transaction message is obtained, if not, then select an input as the target input, and return to step S207;
在步骤S211中,根据本次交易中各个input对应的金额大小,以及本次交易中各个output对应的金额大小,确定本次交易的手续费;In step S211, according to the amount of money corresponding to each input in this transaction and the amount of money corresponding to each output in this transaction, the transaction fee for this transaction is determined;
在该步骤中,手续费的计算方式可以利用现有技术,可以计算各个input的金额大小之和,以及,各个output的金额大小之和,将各个input的金额大小之和减去各个output的金额大小之和,得到本次交易的手续费。In this step, the method for calculating the handling fee can use the existing technology to calculate the sum of the amount of each input and the sum of the amount of each output, minus the sum of the amount of each input minus the amount of each output The sum of the size and the transaction fee for this transaction.
在步骤S212中,向用户展示上述手续费,以便用户确认是否愿意继续交易;In step S212, the user is shown the above handling fee so that the user can confirm whether they are willing to continue the transaction;
在步骤S213中,若接收到用于指示用户愿意继续交易的指令,则对本次交易报文进行签名。In step S213, if an instruction indicating that the user is willing to continue the transaction is received, the transaction message of this time is signed.
在本申请实施例中,向用户展示该手续费的大小,当接收到用户愿意继续交易的指令时,则对本次交易报文进行签名;当接收到用户拒绝继续交易的指令时,则可以终止本次签名。In the embodiment of the present application, the user is shown the size of the handling fee, and when receiving the instruction of the user willing to continue the transaction, the transaction message is signed; when the instruction of the user refusing to continue the transaction is received, it can be Terminate this signature.
本申请实施例二相比于实施例一,可以进一步将本次交易的手续费告知用户,因此,相比于实施例一,本申请实施例二可以使用户知晓每次交易的手续费大小,能够保证用户的知情权,并进一步提高用户体验。此外,本申请实施例二与实施例一相同,能够在一定程度上检查出本次交易报文中所嵌入的非法交易输入,从而能够避免在用户转账时,由于交易报文中被非法嵌入多个交易输入,而造成用户需缴纳更多手续费的问题。Compared with the first embodiment, the second embodiment of the present application can further inform the user of the transaction fee of the transaction. Therefore, compared with the first embodiment, the second embodiment of the present application can make the user know the size of the transaction fee for each transaction. Can guarantee the user's right to know, and further improve the user experience. In addition, the second embodiment of the present application is the same as the first embodiment, which can check the illegal transaction input embedded in the transaction message to a certain extent, so as to avoid that when the user transfers money, because the transaction message is illegally embedded Input of a transaction, causing the user to pay more processing fees.
应理解,上述实施例中各步骤的序号的大小并不意味着执行顺序的先后,各过程的执行顺序应以其功能和内在逻辑确定,而不应对本申请实施例的实施过程构成任何限定。It should be understood that the size of the sequence numbers of the steps in the above embodiments does not mean the order of execution, and the execution order of each process should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiments of the present application.
实施例三Example Three
本申请实施例三提供了一种基于区块链网络交易的签名装置,上述区块链网络的交易报文中包括有各个交易输入input分别对应的input字段以及各个交易输出output分别对应的output字段,每个input字段中均包括有发送输出哈希TxOutHash值,每个合法的input均对应有前次交易报文,每个合法的input对应的前次交易报文为存在有一output字段,该output字段对应的output为该合法的input,每个合法的input对应的TxOutHash值与该合法的input对应的前次交易报文的哈希Hash值相同;Embodiment 3 of the present application provides a signature device based on a blockchain network transaction. The above-mentioned blockchain network transaction message includes an input field corresponding to each transaction input and an output field corresponding to each transaction output. , Each input field includes the TxOutHash value of the output hash, each legal input corresponds to the previous transaction message, and the previous transaction message corresponding to each legal input is that there is an output field. The output corresponding to the field is the legal input, and the TxOutHash value corresponding to each legal input is the same as the hash hash value of the previous transaction message corresponding to the legal input;
如图7所示,该签名装置300包括:As shown in FIG. 7, the signature device 300 includes:
TxOutHash获取模块301,用于在本次交易报文中,获取本次交易所需的各个input分别对应的input字段下的TxOutHash值,上述本次交易报文为本次交易的交易报文;The TxOutHash obtaining module 301 is used to obtain the TxOutHash value under the input field corresponding to each input required for this transaction in this transaction message. The above transaction message is the transaction message of this transaction;
前次报文获取模块302,用于获取本次交易所需的各个input分别对应的前次交易报文;The previous message acquisition module 302 is used to obtain the previous transaction message corresponding to each input required for this transaction;
哈希值计算模块303,用于计算每个前次交易报文的哈希Hash值,得到每个input对应的Hash值;The hash value calculation module 303 is used to calculate the hash value of each previous transaction message to obtain the hash value corresponding to each input;
判断模块304,用于判断计算得到的每个input对应的Hash值与该input对应的input字段下的TxOutHash值是否一致;The judgment module 304 is used to judge whether the calculated Hash value corresponding to each input is consistent with the TxOutHash value under the input field corresponding to the input;
签名模块305,用于若计算得到的每个input对应的Hash值与该input对应的input字段下的TxOutHash值均一致,则对本次交易报文进行签名。The signature module 305 is configured to sign the transaction message if the calculated Hash value corresponding to each input is consistent with the TxOutHash value under the input field corresponding to the input.
可选地,上述区块链网络的交易报文中每个output字段中均包括金额Value值,上述Value值用于指示对应的output的金额大小,每个input字段下还包括发送输出索引TxOutIndex值,每个input字段下的TxOutIndex值用于指示对应的input所对应的output字段在对应的前次交易报文中的位置;Optionally, each output field in the transaction message of the above-mentioned blockchain network includes an amount Value value, the above Value value is used to indicate the amount of the corresponding output amount, and each input field also includes a send output index TxOutIndex value , The TxOutIndex value under each input field is used to indicate the position of the output field corresponding to the corresponding input in the corresponding previous transaction message;
相应地,上述签名模块305包括:Accordingly, the above-mentioned signature module 305 includes:
输出金额确定单元,用于若计算得到的每个input对应的Hash值与该input对应的input字段下的TxOutHash值均一致,则根据上述本次交易报文,获取上述本次交易报文的各个output字段下的Value值,得到本次交易中每个output对应的金额大小;The output amount determination unit is used to obtain each of the above transaction messages according to the above transaction message if the calculated Hash value corresponding to each input is consistent with the TxOutHash value under the input field corresponding to the input Value value under the output field to get the amount of money corresponding to each output in this transaction;
目标输入选取单元,用于在本次交易所需的各个input中,选取任一input作为目标input;Target input selection unit, used to select any input as the target input among each input required for this transaction;
目标输出确定单元,用于根据上述目标input对应的input字段下的TxOutIndex值,在上述目标input对应的前次交易报文中,查找目标output字段,其中,上述目标output字段对应的output为上述目标input;The target output determining unit is used to search for the target output field in the previous transaction message corresponding to the target input according to the TxOutIndex value under the input field corresponding to the target input, wherein the output corresponding to the target output field is the target input;
目标输入金额确定单元,用于获取上述目标output字段下的Value值,得到上述目标input的金额大小;The target input amount determination unit is used to obtain the Value value under the target output field to obtain the amount of the target input amount;
遍历判断单元,用于判断所选取的input是否遍历完本次交易所需的所有input;The traversal judgment unit is used to judge whether the selected input traverses all inputs required for this transaction;
目标输入再选单元,用于若所选取的input没有遍历完本次交易所需的所有input,则除去已选取的input,在本次交易的各个input中,再选取一input作为目标input;The target input reselection unit is used to remove the selected input if the selected input has not traversed all the inputs required for this transaction, and select another input as the target input among each input of this transaction;
手续费确定单元,用于若所选取的input遍历完本次交易所需的所有input,则根据本次交易中各个input对应的金额大小,以及本次交易中各个output对应的金额大小,确定本次交易的手续费;The handling fee determination unit is used to determine the cost of the selected input according to the amount of each input in this transaction and the amount of each output in this transaction if the selected input traverses all the inputs required for this transaction. Handling fee for each transaction;
手续费展示单元,用于向用户展示上述手续费,以便用户确认是否愿意继续交易;The handling fee display unit is used to display the above handling fee to the user so that the user can confirm whether they are willing to continue the transaction;
签名单元,用于若接收到用于指示用户愿意继续交易的指令,则对本次交易报文进行签名。The signature unit is used to sign the transaction message if an instruction indicating that the user is willing to continue the transaction is received.
可选地,上述TxOutHash获取模块301包括:Optionally, the above TxOutHash acquisition module 301 includes:
第一格式判断单元,用于判断上述本次交易报文的报文格式是否符合预设报文格式;The first format judgment unit is used to judge whether the message format of the above transaction message conforms to the preset message format;
TxOutHash获取单元,用于若符合上述预设报文格式,则在本次交易报文中,获取本次交易所需的各个input分别对应的input字段下的TxOutHash值。The TxOutHash obtaining unit is used to obtain the TxOutHash value under the input field corresponding to each input required for this transaction in this transaction message if it conforms to the above-mentioned preset message format.
可选地,上述签名装置300还包括:Optionally, the above-mentioned signature device 300 further includes:
前次报文判断模块,用于判断是否获取到本次交易所需的各个input分别对应的前次交易报文;The previous message judgment module is used to judge whether the previous transaction message corresponding to each input required for this transaction is obtained;
相应地,上述哈希值计算模块303具体用于:Accordingly, the above-mentioned hash value calculation module 303 is specifically used for:
若获取本次交易所需的各个input分别对应的前次交易报文,则计算每个前次交易报文的哈希Hash值,得到每个input对应的Hash值。If the previous transaction message corresponding to each input required for this transaction is obtained, the hash hash value of each previous transaction message is calculated to obtain the hash value corresponding to each input.
可选地,上述哈希值计算模块303,包括:Optionally, the above hash value calculation module 303 includes:
第二格式判断单元,用于判断各个前次交易报文的报文格式是否符合预设报文格式;The second format judgment unit is used to judge whether the message format of each previous transaction message conforms to the preset message format;
哈希值计算单元,用于若符合上述预设报文格式,则计算每个前次交易报文的哈希Hash值,得到每个input对应的Hash值。The hash value calculation unit is configured to calculate a hash hash value of each previous transaction message if it conforms to the above-mentioned preset message format to obtain a hash value corresponding to each input.
可选地,上述前次报文获取模块302,包括:Optionally, the foregoing previous message acquisition module 302 includes:
通信发送单元,用于获取本次交易所需的各个input的标识信息,将各个input的标识信息发送至预设服务器,以指示上述预设服务器执行查找各个input对应的前次交易报文的操作;The communication sending unit is used to obtain the identification information of each input required for this transaction, and send the identification information of each input to the preset server to instruct the preset server to perform the operation of searching for the previous transaction message corresponding to each input ;
通信接收单元,用于接收上述预设服务器发送的各个input分别对应的前次交易报文。The communication receiving unit is configured to receive the previous transaction message corresponding to each input sent by the preset server.
可选地,上述签名装置300还包括:Optionally, the above-mentioned signature device 300 further includes:
签名终止模块,用于在本次交易所需的各个input中,若存在有一个或多个input对应的Hash值与对应的input字段下的TxOutHash值不一致,则终止本次签名。The signature termination module is used to terminate the signature if the Hash value corresponding to one or more inputs is inconsistent with the TxOutHash value under the corresponding input field in each input required for this transaction.
需要说明的是,上述装置/单元之间的信息交互、执行过程等内容,由于与本申请方法实施例基于同一构思,其具体功能及带来的技术效果,具体可参见方法实施例部分,此处不再赘述。It should be noted that the information interaction and execution process between the above devices / units are based on the same concept as the method embodiments of the present application, and their specific functions and technical effects are brought about. For details, please refer to the method embodiments section. I will not repeat them here.
实施例四Example 4
图8是本申请实施例四提供的终端设备的示意图,该终端设备为一应用在区块链网络中的区块链节点,其中,该区块链网络的交易报文中包括有各个交易输入input分别对应的input字段以及各个交易输出output分别对应的output字段,每个input字段中均包括有发送输出哈希TxOutHash值,每个合法的input均对应有前次交易报文,每个合法的input对应的前次交易报文为存在有一output字段,该output字段对应的output为该合法的input,每个合法的input对应的TxOutHash值与该合法的input对应的前次交易报文的哈希Hash值相同。FIG. 8 is a schematic diagram of a terminal device provided in Embodiment 4 of the present application. The terminal device is a blockchain node applied in a blockchain network, where the transaction message of the blockchain network includes various transaction inputs The input field corresponding to the input and the output field corresponding to the output of each transaction respectively, each input field includes the output output hash TxOutHash value, each legal input corresponds to the previous transaction message, each legal The previous transaction message corresponding to input has an output field, and the output corresponding to the output field is the legal input. The TxOutHash value corresponding to each legal input and the hash of the previous transaction message corresponding to the legal input Hash value is the same.
如图8所示,该实施例的终端设备4包括:处理器40、存储器41以及存储在上述存储器41中并可在上述处理器40上运行的计算机程序42。上述处理器40执行上述计算机程序42时实现上述方法实施例中的步骤,例如图1所示的步骤S101至S105。或者,上述处理器40执行上述计算机程序42时实现上述装置实施例中各模块/单元的功能,例如图7所示模块301至305的功能。As shown in FIG. 8, the terminal device 4 of this embodiment includes: a processor 40, a memory 41, and a computer program 42 stored in the memory 41 and executable on the processor 40. When the processor 40 executes the computer program 42, the steps in the above method embodiment are implemented, for example, steps S101 to S105 shown in FIG. 1. Alternatively, when the processor 40 executes the computer program 42, the functions of each module / unit in the above-described device embodiment are realized, for example, the functions of the modules 301 to 305 shown in FIG. 7.
示例性的,上述计算机程序42可以被分割成一个或多个模块/单元,上述一个或者多个模块/单元被存储在上述存储器41中,并由上述处理器40执行,以完成本申请。上述一个或多个模块/单元可以是能够完成特定功能的一系列计算机程序指令段,该指令段用于描述上述计算机程序42在上述终端设备4中的执行过程。例如,上述计算机程序42可以被分割成TxOutHash获取模块、前次报文获取模块、哈希值计算模块、判断模块以及签名模块,各模块具体功能如下:Exemplarily, the computer program 42 may be divided into one or more modules / units. The one or more modules / units are stored in the memory 41 and executed by the processor 40 to complete the application. The one or more modules / units may be a series of computer program instruction segments capable of performing specific functions, and the instruction segments are used to describe the execution process of the computer program 42 in the terminal device 4. For example, the above computer program 42 can be divided into a TxOutHash acquisition module, a previous message acquisition module, a hash value calculation module, a judgment module, and a signature module. The specific functions of each module are as follows:
在本次交易报文中,获取本次交易所需的各个input分别对应的input字段下的TxOutHash值,上述本次交易报文为本次交易的交易报文;In this transaction message, obtain the TxOutHash value under the input field corresponding to each input required for this transaction. The above transaction message is the transaction message of this transaction;
获取本次交易所需的各个input分别对应的前次交易报文;Get the previous transaction message corresponding to each input required for this transaction;
计算每个前次交易报文的哈希Hash值,得到每个input对应的Hash值;Calculate the hash hash value of each previous transaction message to get the hash value corresponding to each input;
判断计算得到的每个input对应的Hash值与该input对应的input字段下的TxOutHash值是否一致;Determine whether the calculated Hash value corresponding to each input is consistent with the TxOutHash value under the input field corresponding to the input;
若计算得到的每个input对应的Hash值与该input对应的input字段下的TxOutHash值均一致,则对上述本次交易报文进行签名。If the calculated Hash value corresponding to each input is consistent with the TxOutHash value under the input field corresponding to the input, the above transaction message is signed.
上述终端设备4可以是桌上型计算机、笔记本、掌上电脑及云端服务器等计算设备。上述终端设备可包括,但不仅限于,处理器40、存储器41。本领域技术人员可以理解,图8仅仅是终端设备4的示例,并不构成对终端设备4的限定,可以包括比图示更多或更少的部件,或者组合某些部件,或者不同的部件,例如上述终端设备还可以包括输入输出设备、网络接入设备、总线等。The terminal device 4 may be a computing device such as a desktop computer, a notebook, a palmtop computer and a cloud server. The above terminal device may include, but is not limited to, the processor 40 and the memory 41. A person skilled in the art may understand that FIG. 8 is only an example of the terminal device 4 and does not constitute a limitation on the terminal device 4, and may include more or less components than those illustrated, or a combination of certain components, or different components. For example, the above terminal device may further include an input and output device, a network access device, a bus, and the like.
所称处理器40可以是中央处理单元(Central Processing Unit,CPU),还可以是其它通用处理器、数字信号处理器 (Digital Signal Processor,DSP)、专用集成电路 (Application Specific Integrated Circuit,ASIC)、现场可编程门阵列 (Field-Programmable Gate Array,FPGA) 或者其它可编程逻辑器件、分立门或者晶体管逻辑器件、分立硬件组件等。通用处理器可以是微处理器或者该处理器也可以是任何常规的处理器等。The so-called processor 40 may be a central processing unit (Central Processing Unit (CPU), can also be other general-purpose processors, digital signal processors (Digital Signal Processor, DSP), application-specific integrated circuits (Application Specific Integrated Circuit (ASIC), Field-Programmable Gate Array (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. The general-purpose processor may be a microprocessor or the processor may be any conventional processor or the like.
上述存储器41可以是上述终端设备4的内部存储单元,例如终端设备4的硬盘或内存。上述存储器41也可以是上述终端设备4的外部存储设备,例如上述终端设备4上配备的插接式硬盘,智能存储卡(Smart Media Card, SMC),安全数字(Secure Digital, SD)卡,闪存卡(Flash Card)等。进一步地,上述存储器41还可以既包括上述终端设备4的内部存储单元也包括外部存储设备。上述存储器41用于存储上述计算机程序以及上述终端设备所需的其它程序和数据。上述存储器41还可以用于暂时地存储已经输出或者将要输出的数据。The above-mentioned memory 41 may be an internal storage unit of the above-mentioned terminal device 4, such as a hard disk or a memory of the terminal device 4. The memory 41 may also be an external storage device of the terminal device 4, such as a plug-in hard disk, a Smart Media Card (SMC), a Secure Digital (SD) card, and a flash memory provided on the terminal device 4 Card (Flash Card) etc. Further, the memory 41 may include both the internal storage unit of the terminal device 4 and the external storage device. The memory 41 is used to store the computer program and other programs and data required by the terminal device. The above-mentioned memory 41 may also be used to temporarily store data that has been output or will be output.
所属领域的技术人员可以清楚地了解到,为了描述的方便和简洁,仅以上述各功能单元、模块的划分进行举例说明,实际应用中,可以根据需要而将上述功能分配由不同的功能单元、模块完成,即将上述装置的内部结构划分成不同的功能单元或模块,以完成以上描述的全部或者部分功能。实施例中的各功能单元、模块可以集成在一个处理单元中,也可以是各个单元单独物理存在,也可以两个或两个以上单元集成在一个单元中,上述集成的单元既可以采用硬件的形式实现,也可以采用软件功能单元的形式实现。另外,各功能单元、模块的具体名称也只是为了便于相互区分,并不用于限制本申请的保护范围。上述系统中单元、模块的具体工作过程,可以参考前述方法实施例中的对应过程,在此不再赘述。Those skilled in the art can clearly understand that, for convenience and conciseness of description, only the above-mentioned division of each functional unit and module is used as an example for illustration. In practical applications, the above-mentioned functions may be allocated by different functional units, Module completion means that the internal structure of the above device is divided into different functional units or modules to complete all or part of the functions described above. The functional units and modules in the embodiments may be integrated into one processing unit, or each unit may exist alone physically, or two or more units may be integrated into one unit. The above integrated unit may use hardware It can also be implemented in the form of software functional units. In addition, the specific names of each functional unit and module are only for the purpose of distinguishing each other, and are not used to limit the protection scope of the present application. For the specific working processes of the units and modules in the above system, reference may be made to the corresponding processes in the foregoing method embodiments, which will not be repeated here.
在上述实施例中,对各个实施例的描述都各有侧重,某个实施例中没有详述或记载的部分,可以参见其它实施例的相关描述。In the above embodiments, the description of each embodiment has its own emphasis. For a part that is not detailed or recorded in an embodiment, you can refer to the related descriptions of other embodiments.
本领域普通技术人员可以意识到,结合本文中所公开的实施例描述的各示例的单元及算法步骤,能够以电子硬件、或者计算机软件和电子硬件的结合来实现。这些功能究竟以硬件还是软件方式来执行,取决于技术方案的特定应用和设计约束条件。专业技术人员可以对每个特定的应用来使用不同方法来实现所描述的功能,但是这种实现不应认为超出本申请的范围。Those of ordinary skill in the art may realize that the units and algorithm steps of the examples described in conjunction with the embodiments disclosed herein can be implemented by electronic hardware, or a combination of computer software and electronic hardware. Whether these functions are executed in hardware or software depends on the specific application of the technical solution and design constraints. Professional technicians can use different methods to implement the described functions for each specific application, but such implementation should not be considered beyond the scope of this application.
在本申请所提供的实施例中,应该理解到,所揭露的装置/终端设备和方法,可以通过其它的方式实现。例如,以上所描述的装置/终端设备实施例仅仅是示意性的,例如,上述模块或单元的划分,仅仅为一种逻辑功能划分,实际实现时可以有另外的划分方式,例如多个单元或组件可以结合或者可以集成到另一个系统,或一些特征可以忽略,或不执行。另一点,所显示或讨论的相互之间的耦合或直接耦合或通讯连接可以是通过一些接口,装置或单元的间接耦合或通讯连接,可以是电性,机械或其它的形式。In the embodiments provided in this application, it should be understood that the disclosed device / terminal device and method may be implemented in other ways. For example, the device / terminal device embodiments described above are only schematic. For example, the above-mentioned division of modules or units is only a division of logical functions. In actual implementation, there may be other divisions, such as multiple units or Components can be combined or integrated into another system, or some features can be ignored or not implemented. In addition, the displayed or discussed mutual coupling or direct coupling or communication connection may be indirect coupling or communication connection through some interfaces, devices or units, and may be in electrical, mechanical or other forms.
上述作为分离部件说明的单元可以是或者也可以不是物理上分开的,作为单元显示的部件可以是或者也可以不是物理单元,即可以位于一个地方,或者也可以分布到多个网络单元上。可以根据实际的需要选择其中的部分或者全部单元来实现本实施例方案的目的。The units described as separate components may or may not be physically separated, and the components displayed as units may or may not be physical units, that is, they may be located in one place or may be distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
另外,在本申请各个实施例中的各功能单元可以集成在一个处理单元中,也可以是各个单元单独物理存在,也可以两个或两个以上单元集成在一个单元中。上述集成的单元既可以采用硬件的形式实现,也可以采用软件功能单元的形式实现。In addition, each functional unit in each embodiment of the present application may be integrated into one processing unit, or each unit may exist alone physically, or two or more units may be integrated into one unit. The above integrated unit may be implemented in the form of hardware or software functional unit.
上述集成的模块/单元如果以软件功能单元的形式实现并作为独立的产品销售或使用时,可以存储在一个计算机可读取存储介质中。基于这样的理解,本申请实现上述实施例方法中的全部或部分流程,也可以通过计算机程序来指令相关的硬件来完成,上述的计算机程序可存储于一计算机可读存储介质中,该计算机程序在被处理器执行时,可实现上述各个方法实施例的步骤。其中,上述计算机程序包括计算机程序代码,上述计算机程序代码可以为源代码形式、对象代码形式、可执行文件或某些中间形式等。上述计算机可读介质可以包括:能够携带上述计算机程序代码的任何实体或装置、记录介质、U盘、移动硬盘、磁碟、光盘、计算机存储器、只读存储器(ROM,Read-Only Memory)、随机存取存储器(RAM,Random Access Memory)、电载波信号、电信信号以及软件分发介质等。需要说明的是,上述计算机可读介质包含的内容可以根据司法管辖区内立法和专利实践的要求进行适当的增减,例如在某些司法管辖区,根据立法和专利实践,计算机可读介质不包括电载波信号和电信信号。If the above integrated module / unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the present application can implement all or part of the processes in the methods of the above embodiments, and can also be completed by instructing relevant hardware through a computer program. The above computer program can be stored in a computer-readable storage medium, and the computer program When executed by the processor, the steps of the foregoing method embodiments may be implemented. Wherein, the above-mentioned computer program includes computer program code, and the above-mentioned computer program code may be in the form of source code, object code, executable file or some intermediate form. The above computer readable medium may include: any entity or device capable of carrying the above computer program code, recording medium, U disk, removable hard disk, magnetic disk, optical disk, computer memory, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), electrical carrier signals, telecommunication signals, and software distribution media. It should be noted that the content contained in the above computer-readable medium can be appropriately increased or decreased according to the requirements of legislation and patent practice in jurisdictions. For example, in some jurisdictions, according to legislation and patent practice, computer-readable media are not Including electrical carrier signals and telecommunications signals.
以上上述实施例仅用以说明本申请的技术方案,而非对其限制;尽管参照前述实施例对本申请进行了详细的说明,本领域的普通技术人员应当理解:其依然可以对前述各实施例所记载的技术方案进行修改,或者对其中部分技术特征进行等同替换;而这些修改或者替换,并不使相应技术方案的本质脱离本申请各实施例技术方案的精神和范围,均应包含在本申请的保护范围之内。The above-mentioned embodiments are only used to illustrate the technical solutions of the present application, not to limit them; although the present application has been described in detail with reference to the foregoing embodiments, persons of ordinary skill in the art should understand that they can still perform the foregoing embodiments The recorded technical solutions are modified, or some of the technical features are equivalently replaced; and these modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of this application, and should be included in this Within the scope of protection applied for.

Claims (20)

  1. 一种基于区块链网络交易的签名方法,其特征在于,所述区块链网络的交易报文中包括有各个交易输入input分别对应的input字段以及各个交易输出output分别对应的output字段,每个input字段中均包括有发送输出哈希TxOutHash值,每个合法的input均对应有前次交易报文,每个合法的input对应的前次交易报文为存在有一output字段,该output字段对应的output为该合法的input,每个合法的input对应的TxOutHash值与该合法的input对应的前次交易报文的哈希Hash值相同;A signature method based on a blockchain network transaction, characterized in that the transaction message of the blockchain network includes an input field corresponding to each transaction input input and an output field corresponding to each transaction output output, each Each input field includes the TxOutHash value of the sent output hash. Each legal input corresponds to the previous transaction message. Each legal input corresponds to the previous transaction message. There is an output field, which corresponds to the output field. Is the legal input, and the TxOutHash value corresponding to each legal input is the same as the hash hash value of the previous transaction message corresponding to the legal input;
    所述签名方法包括:The signature method includes:
    在本次交易报文中,获取本次交易所需的各个input分别对应的input字段下的TxOutHash值,所述本次交易报文为本次交易的交易报文;In this transaction message, obtain the TxOutHash value under the input field corresponding to each input required for this transaction, which is the transaction message of this transaction;
    获取本次交易所需的各个input分别对应的前次交易报文;Get the previous transaction message corresponding to each input required for this transaction;
    计算每个前次交易报文的哈希Hash值,得到每个input对应的Hash值;Calculate the hash hash value of each previous transaction message to get the hash value corresponding to each input;
    判断计算得到的每个input对应的Hash值与该input对应的input字段下的TxOutHash值是否一致;Determine whether the calculated Hash value corresponding to each input is consistent with the TxOutHash value under the input field corresponding to the input;
    若计算得到的每个input对应的Hash值与该input对应的input字段下的TxOutHash值均一致,则对所述本次交易报文进行签名。If the calculated Hash value corresponding to each input is consistent with the TxOutHash value under the input field corresponding to the input, the transaction message of this time is signed.
  2. 如权利要求1所述的签名方法,其特征在于,所述区块链网络的交易报文中每个output字段中均包括金额Value值,所述Value值用于指示对应的output的金额大小,每个input字段下还包括发送输出索引TxOutIndex值,每个input字段下的TxOutIndex值用于指示对应的input所对应的output字段在对应的前次交易报文中的位置;The signature method according to claim 1, wherein each output field in the transaction message of the blockchain network includes an amount Value value, and the Value value is used to indicate the amount of the corresponding output amount, Each input field also includes a send output index TxOutIndex value. The TxOutIndex value under each input field is used to indicate the position of the output field corresponding to the corresponding input in the corresponding previous transaction message;
    所述若计算得到的每个input对应的Hash值与该input对应的input字段下的TxOutHash值均一致,则对本次交易报文进行签名,包括:If the calculated Hash value corresponding to each input is consistent with the TxOutHash value under the input field corresponding to the input, the transaction message is signed, including:
    若计算得到的每个input对应的Hash值与该input对应的input字段下的TxOutHash值均一致,则:If the calculated Hash value corresponding to each input is consistent with the TxOutHash value under the input field corresponding to the input, then:
    根据所述本次交易报文,获取所述本次交易报文的各个output字段下的Value值,得到本次交易中每个output对应的金额大小;According to the transaction message, obtain the Value value under each output field of the transaction message to obtain the amount of money corresponding to each output in the transaction;
    在本次交易所需的各个input中,选取任一input作为目标input;In each input required for this transaction, select any input as the target input;
    根据所述目标input对应的input字段下的TxOutIndex值,在所述目标input对应的前次交易报文中,查找目标output字段,其中,所述目标output字段对应的output为所述目标input;According to the TxOutIndex value under the input field corresponding to the target input, search for the target output field in the previous transaction message corresponding to the target input, where the output corresponding to the target output field is the target input;
    获取所述目标output字段下的Value值,得到所述目标input的金额大小;Obtain the Value value under the target output field to obtain the amount of the target input amount;
    判断所选取的input是否遍历完本次交易所需的所有input;Determine whether the selected input traverses all the inputs required for this transaction;
    若所选取的input没有遍历完本次交易所需的所有input,则:If the selected input does not traverse all the inputs required for this transaction, then:
    除去已选取的input,在本次交易的各个input中,再选取一input作为目标input,并返回执行所述根据所述目标input对应的input字段下的TxOutIndex值,在所述目标input对应的前次交易报文中,查找目标output字段,其中,所述目标output字段对应的output为所述目标input的步骤以及后续步骤,从而得到本次交易中每个input对应的金额大小;Remove the selected input, in each input of this transaction, select another input as the target input, and return to execute the TxOutIndex value under the input field corresponding to the target input, in front of the corresponding target input In the transaction message, search for the target output field, where the output corresponding to the target output field is the step and subsequent steps of the target input, so as to obtain the amount of money corresponding to each input in this transaction;
    若所选取的input遍历完本次交易所需的所有input,则:If the selected input traverses all inputs required for this transaction, then:
    根据本次交易中各个input对应的金额大小,以及本次交易中各个output对应的金额大小,确定本次交易的手续费;Determine the transaction fee for this transaction based on the amount of money corresponding to each input in this transaction and the amount of money corresponding to each output in this transaction;
    向用户展示所述手续费,以便用户确认是否愿意继续交易;Show the user the handling fee so that the user can confirm whether they are willing to continue the transaction;
    若接收到用于指示用户愿意继续交易的指令,则对本次交易报文进行签名。If an instruction indicating that the user is willing to continue the transaction is received, the transaction message is signed.
  3. 如权利要求1所述的签名方法,其特征在于,所述在本次交易报文中,获取本次交易所需的各个input分别对应的input字段下的TxOutHash值,包括:The signature method according to claim 1, wherein, in the transaction message, obtaining the TxOutHash value under the input field corresponding to each input required for the transaction includes:
    判断所述本次交易报文的报文格式是否符合预设报文格式;Determine whether the message format of the transaction message conforms to the preset message format;
    若符合所述预设报文格式,则在本次交易报文中,获取本次交易所需的各个input分别对应的input字段下的TxOutHash值。If the preset message format is met, then in this transaction message, the TxOutHash value under the input field corresponding to each input required for this transaction is obtained.
  4. 如权利要求1所述的签名方法,其特征在于,在所述计算每个前次交易报文的哈希Hash值,得到每个input对应的Hash值的步骤之前,所述签名方法还包括:The signature method according to claim 1, wherein before the step of calculating the hash value of each previous transaction message to obtain a hash value corresponding to each input, the signature method further comprises:
    判断是否获取到本次交易所需的各个input分别对应的前次交易报文;Determine whether the previous transaction message corresponding to each input required for this transaction is obtained;
    相应地,所述计算每个前次交易报文的哈希Hash值,得到每个input对应的Hash值,包括:Correspondingly, the hash hash value of each previous transaction message is calculated to obtain a hash value corresponding to each input, including:
    若获取本次交易所需的各个input分别对应的前次交易报文,则计算每个前次交易报文的哈希Hash值,得到每个input对应的Hash值。If the previous transaction message corresponding to each input required for this transaction is obtained, the hash hash value of each previous transaction message is calculated to obtain the hash value corresponding to each input.
  5. 如权利要求1所述的签名方法,其特征在于,所述计算每个前次交易报文的哈希Hash值,得到每个input对应的Hash值,包括:The signature method according to claim 1, wherein the calculating a hash value of each previous transaction message to obtain a hash value corresponding to each input includes:
    判断各个前次交易报文的报文格式是否符合预设报文格式;Determine whether the message format of each previous transaction message conforms to the preset message format;
    若符合所述预设报文格式,则计算每个前次交易报文的哈希Hash值,得到每个input对应的Hash值。If the preset message format is met, then the hash hash value of each previous transaction message is calculated to obtain the hash value corresponding to each input.
  6. 如权利要求1所述的签名方法,其特征在于,所述获取本次交易所需的各个input分别对应的前次交易报文,包括:The signature method according to claim 1, wherein the previous transaction message corresponding to each input required to obtain the transaction includes:
    获取本次交易所需的各个input的标识信息,将各个input的标识信息发送至预设服务器,以指示所述预设服务器执行查找各个input对应的前次交易报文的操作;Obtain the identification information of each input required for this transaction, and send the identification information of each input to a preset server to instruct the preset server to perform the operation of searching for the previous transaction message corresponding to each input;
    接收所述预设服务器发送的各个input分别对应的前次交易报文。Receiving the previous transaction message corresponding to each input sent by the preset server respectively.
  7. 如权利要求1至6中任一项所述的签名方法,其特征在于,在所述判断计算得到的每个input对应的Hash值与该input对应的input字段下的TxOutHash值是否一致的步骤之后,还包括:The signature method according to any one of claims 1 to 6, wherein after the step of determining whether the calculated Hash value corresponding to each input is consistent with the TxOutHash value under the input field corresponding to the input ,Also includes:
    在本次交易所需的各个input中,若存在有一个或多个input对应的Hash值与对应的input字段下的TxOutHash值不一致,则终止本次签名。In each input required for this transaction, if there is a hash value corresponding to one or more inputs that is inconsistent with the TxOutHash value under the corresponding input field, the signature is terminated.
  8. 一种终端设备,包括存储器、处理器以及存储在所述存储器中并可在所述处理器上运行的计算机程序,其特征在于,所述处理器执行所述计算机程序时实现如下基于区块链网络交易的签名方法:A terminal device includes a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that, when the processor executes the computer program, it is implemented as follows based on a blockchain Network transaction signature method:
    其中,所述区块链网络的交易报文中包括有各个交易输入input分别对应的input字段以及各个交易输出output分别对应的output字段,每个input字段中均包括有发送输出哈希TxOutHash值,每个合法的input均对应有前次交易报文,每个合法的input对应的前次交易报文为存在有一output字段,该output字段对应的output为该合法的input,每个合法的input对应的TxOutHash值与该合法的input对应的前次交易报文的哈希Hash值相同;Among them, the transaction message of the blockchain network includes an input field corresponding to each transaction input input and an output field corresponding to each transaction output output, and each input field includes a send output hash TxOutHash value, Each legal input corresponds to a previous transaction message. The previous transaction message corresponding to each legal input has an output field. The output corresponding to the output field is the legal input, and each legal input corresponds to The TxOutHash value is the same as the hash hash value of the previous transaction message corresponding to the legal input;
    所述签名方法包括:The signature method includes:
    在本次交易报文中,获取本次交易所需的各个input分别对应的input字段下的TxOutHash值,所述本次交易报文为本次交易的交易报文;In this transaction message, obtain the TxOutHash value under the input field corresponding to each input required for this transaction, which is the transaction message of this transaction;
    获取本次交易所需的各个input分别对应的前次交易报文;Get the previous transaction message corresponding to each input required for this transaction;
    计算每个前次交易报文的哈希Hash值,得到每个input对应的Hash值;Calculate the hash hash value of each previous transaction message to get the hash value corresponding to each input;
    判断计算得到的每个input对应的Hash值与该input对应的input字段下的TxOutHash值是否一致;Determine whether the calculated Hash value corresponding to each input is consistent with the TxOutHash value under the input field corresponding to the input;
    若计算得到的每个input对应的Hash值与该input对应的input字段下的TxOutHash值均一致,则对所述本次交易报文进行签名。If the calculated Hash value corresponding to each input is consistent with the TxOutHash value under the input field corresponding to the input, the transaction message of this time is signed.
  9. 如权利要求8所述的终端设备,其特征在于,所述区块链网络的交易报文中每个output字段中均包括金额Value值,所述Value值用于指示对应的output的金额大小,每个input字段下还包括发送输出索引TxOutIndex值,每个input字段下的TxOutIndex值用于指示对应的input所对应的output字段在对应的前次交易报文中的位置;The terminal device according to claim 8, wherein each output field in the transaction message of the blockchain network includes an amount Value value, and the Value value is used to indicate the amount of the corresponding output amount, Each input field also includes a send output index TxOutIndex value. The TxOutIndex value under each input field is used to indicate the position of the output field corresponding to the corresponding input in the corresponding previous transaction message;
    所述若计算得到的每个input对应的Hash值与该input对应的input字段下的TxOutHash值均一致,则对本次交易报文进行签名,包括:If the calculated Hash value corresponding to each input is consistent with the TxOutHash value under the input field corresponding to the input, the transaction message is signed, including:
    若计算得到的每个input对应的Hash值与该input对应的input字段下的TxOutHash值均一致,则:If the calculated Hash value corresponding to each input is consistent with the TxOutHash value under the input field corresponding to the input, then:
    根据所述本次交易报文,获取所述本次交易报文的各个output字段下的Value值,得到本次交易中每个output对应的金额大小;According to the transaction message, obtain the Value value under each output field of the transaction message to obtain the amount of money corresponding to each output in the transaction;
    在本次交易所需的各个input中,选取任一input作为目标input;In each input required for this transaction, select any input as the target input;
    根据所述目标input对应的input字段下的TxOutIndex值,在所述目标input对应的前次交易报文中,查找目标output字段,其中,所述目标output字段对应的output为所述目标input;According to the TxOutIndex value under the input field corresponding to the target input, search for the target output field in the previous transaction message corresponding to the target input, where the output corresponding to the target output field is the target input;
    获取所述目标output字段下的Value值,得到所述目标input的金额大小;Obtain the Value value under the target output field to obtain the amount of the target input amount;
    判断所选取的input是否遍历完本次交易所需的所有input;Determine whether the selected input traverses all the inputs required for this transaction;
    若所选取的input没有遍历完本次交易所需的所有input,则:If the selected input does not traverse all the inputs required for this transaction, then:
    除去已选取的input,在本次交易的各个input中,再选取一input作为目标input,并返回执行所述根据所述目标input对应的input字段下的TxOutIndex值,在所述目标input对应的前次交易报文中,查找目标output字段,其中,所述目标output字段对应的output为所述目标input的步骤以及后续步骤,从而得到本次交易中每个input对应的金额大小;Remove the selected input, and in each input of this transaction, select another input as the target input, and return to execute the TxOutIndex value under the input field corresponding to the target input, before the target input In the transaction message, search for the target output field, where the output corresponding to the target output field is the step and subsequent steps of the target input, so as to obtain the amount of money corresponding to each input in this transaction;
    若所选取的input遍历完本次交易所需的所有input,则:If the selected input traverses all inputs required for this transaction, then:
    根据本次交易中各个input对应的金额大小,以及本次交易中各个output对应的金额大小,确定本次交易的手续费;Determine the transaction fee for this transaction based on the amount of money corresponding to each input in this transaction and the amount of money corresponding to each output in this transaction;
    向用户展示所述手续费,以便用户确认是否愿意继续交易;Show the user the handling fee so that the user can confirm whether they are willing to continue the transaction;
    若接收到用于指示用户愿意继续交易的指令,则对本次交易报文进行签名。If an instruction indicating that the user is willing to continue the transaction is received, the transaction message is signed.
  10. 如权利要求8所述的终端设备,其特征在于,所述在本次交易报文中,获取本次交易所需的各个input分别对应的input字段下的TxOutHash值,包括:The terminal device according to claim 8, wherein, in the transaction message, obtaining the TxOutHash value under the input field corresponding to each input required for the transaction includes:
    判断所述本次交易报文的报文格式是否符合预设报文格式;Determine whether the message format of the transaction message conforms to the preset message format;
    若符合所述预设报文格式,则在本次交易报文中,获取本次交易所需的各个input分别对应的input字段下的TxOutHash值。If the preset message format is met, then in this transaction message, the TxOutHash value under the input field corresponding to each input required for this transaction is obtained.
  11. 如权利要求8所述的终端设备,其特征在于,在所述计算每个前次交易报文的哈希Hash值,得到每个input对应的Hash值的步骤之前,所述处理器执行所述计算机程序时,还执行如下步骤:The terminal device according to claim 8, wherein before the step of calculating the hash value of each previous transaction message to obtain a hash value corresponding to each input, the processor executes When performing a computer program, the following steps are also performed:
    判断是否获取到本次交易所需的各个input分别对应的前次交易报文;Determine whether the previous transaction message corresponding to each input required for this transaction is obtained;
    相应地,所述计算每个前次交易报文的哈希Hash值,得到每个input对应的Hash值,包括:Correspondingly, the hash hash value of each previous transaction message is calculated to obtain a hash value corresponding to each input, including:
    若获取本次交易所需的各个input分别对应的前次交易报文,则计算每个前次交易报文的哈希Hash值,得到每个input对应的Hash值。If the previous transaction message corresponding to each input required for this transaction is obtained, the hash hash value of each previous transaction message is calculated to obtain the hash value corresponding to each input.
  12. 如权利要求8所述的终端设备,其特征在于,所述计算每个前次交易报文的哈希Hash值,得到每个input对应的Hash值,包括:The terminal device according to claim 8, wherein the calculating a hash value of each previous transaction message to obtain a hash value corresponding to each input includes:
    判断各个前次交易报文的报文格式是否符合预设报文格式;Determine whether the message format of each previous transaction message conforms to the preset message format;
    若符合所述预设报文格式,则计算每个前次交易报文的哈希Hash值,得到每个input对应的Hash值。If the preset message format is met, then the hash hash value of each previous transaction message is calculated to obtain the hash value corresponding to each input.
  13. 如权利要求8所述的终端设备,其特征在于,所述获取本次交易所需的各个input分别对应的前次交易报文,包括:The terminal device according to claim 8, wherein the previous transaction message corresponding to each input required to obtain the transaction includes:
    获取本次交易所需的各个input的标识信息,将各个input的标识信息发送至预设服务器,以指示所述预设服务器执行查找各个input对应的前次交易报文的操作;Obtain the identification information of each input required for this transaction, and send the identification information of each input to a preset server to instruct the preset server to perform the operation of searching for the previous transaction message corresponding to each input;
    接收所述预设服务器发送的各个input分别对应的前次交易报文。Receiving the previous transaction message corresponding to each input sent by the preset server respectively.
  14. 如权利要求8至13中任一项所述的终端设备,其特征在于,在所述判断计算得到的每个input对应的Hash值与该input对应的input字段下的TxOutHash值是否一致的步骤之后,所述处理器执行所述计算机程序时,还执行如下步骤:The terminal device according to any one of claims 8 to 13, wherein after the step of determining whether the calculated Hash value corresponding to each input is consistent with the TxOutHash value under the input field corresponding to the input When the processor executes the computer program, it also performs the following steps:
    在本次交易所需的各个input中,若存在有一个或多个input对应的Hash值与对应的input字段下的TxOutHash值不一致,则终止本次签名。In each input required for this transaction, if there is a hash value corresponding to one or more inputs that is inconsistent with the TxOutHash value under the corresponding input field, the signature is terminated.
  15. 一种基于区块链网络交易的签名装置,其特征在于,所述区块链网络的交易报文中包括有各个交易输入input分别对应的input字段以及各个交易输出output分别对应的output字段,每个input字段中均包括有发送输出哈希TxOutHash值,每个合法的input均对应有前次交易报文,每个合法的input对应的前次交易报文为存在有一output字段,该output字段对应的output为该合法的input,每个合法的input对应的TxOutHash值与该合法的input对应的前次交易报文的哈希Hash值相同;A signature device based on a blockchain network transaction, characterized in that the transaction message of the blockchain network includes an input field corresponding to each transaction input input and an output field corresponding to each transaction output output, each Each input field includes the TxOutHash value of the sent output hash. Each legal input corresponds to the previous transaction message. Each legal input corresponds to the previous transaction message. There is an output field, which corresponds to the output field. Is the legal input, and the TxOutHash value corresponding to each legal input is the same as the hash hash value of the previous transaction message corresponding to the legal input;
    所述签名装置包括:The signature device includes:
    TxOutHash获取模块,用于在本次交易报文中,获取本次交易所需的各个input分别对应的input字段下的TxOutHash值,所述本次交易报文为本次交易的交易报文;The TxOutHash acquisition module is used to obtain the TxOutHash value under the input field corresponding to each input required for this transaction in this transaction message, which is the transaction message of this transaction;
    前次报文获取模块,用于获取本次交易所需的各个input分别对应的前次交易报文;The previous message acquisition module is used to obtain the previous transaction message corresponding to each input required for this transaction;
    哈希值计算模块,用于计算每个前次交易报文的哈希Hash值,得到每个input对应的Hash值;The hash value calculation module is used to calculate the hash value of each previous transaction message to obtain the hash value corresponding to each input;
    判断模块,用于判断计算得到的每个input对应的Hash值与该input对应的input字段下的TxOutHash值是否一致;The judgment module is used to judge whether the calculated Hash value corresponding to each input is consistent with the TxOutHash value under the input field corresponding to the input;
    签名模块,用于若计算得到的每个input对应的Hash值与该input对应的input字段下的TxOutHash值均一致,则对所述本次交易报文进行签名。The signature module is used to sign the transaction message if the calculated Hash value corresponding to each input is consistent with the TxOutHash value under the input field corresponding to the input.
  16. 如权利要求15所述的签名装置,其特征在于,所述区块链网络的交易报文中每个output字段中均包括金额Value值,所述Value值用于指示对应的output的金额大小,每个input字段下还包括发送输出索引TxOutIndex值,每个input字段下的TxOutIndex值用于指示对应的input所对应的output字段在对应的前次交易报文中的位置;The signature device according to claim 15, wherein each output field in the transaction message of the blockchain network includes an amount Value value, and the Value value is used to indicate the amount of the corresponding output amount, Each input field also includes a send output index TxOutIndex value. The TxOutIndex value under each input field is used to indicate the position of the output field corresponding to the corresponding input in the corresponding previous transaction message;
    相应地,所述签名模块包括:Correspondingly, the signature module includes:
    输出金额确定单元,用于若计算得到的每个input对应的Hash值与该input对应的input字段下的TxOutHash值均一致,则:根据所述本次交易报文,获取所述本次交易报文的各个output字段下的Value值,得到本次交易中每个output对应的金额大小;The output amount determination unit is used to: if the calculated Hash value corresponding to each input is consistent with the TxOutHash value under the input field corresponding to the input, then: according to the transaction message, obtain the transaction report The Value value under each output field of the article can get the amount of money corresponding to each output in this transaction;
    目标输入选取单元,用于在本次交易所需的各个input中,选取任一input作为目标input;Target input selection unit, used to select any input as the target input among each input required for this transaction;
    目标输出确定单元,用于根据所述目标input对应的input字段下的TxOutIndex值,在所述目标input对应的前次交易报文中,查找目标output字段,其中,所述目标output字段对应的output为所述目标input;The target output determining unit is used to search for the target output field in the previous transaction message corresponding to the target input according to the TxOutIndex value under the input field corresponding to the target input, wherein the output corresponding to the target output field Input for the target;
    目标输入金额确定单元,用于获取所述目标output字段下的Value值,得到所述目标input的金额大小;A target input amount determining unit, used to obtain the Value value under the target output field to obtain the amount of the target input amount;
    遍历判断单元,用于判断所选取的input是否遍历完本次交易所需的所有input;The traversal judgment unit is used to judge whether the selected input traverses all inputs required for this transaction;
    目标输入再选单元,用于若所选取的input没有遍历完本次交易所需的所有input,则:除去已选取的input,在本次交易的各个input中,再选取一input作为目标input,并返回执行所述根据所述目标input对应的input字段下的TxOutIndex值,在所述目标input对应的前次交易报文中,查找目标output字段,其中,所述目标output字段对应的output为所述目标input的步骤以及后续步骤,从而得到本次交易中每个input对应的金额大小;The target input reselection unit is used to select all input required for this transaction if the selected input does not traverse all the inputs required for this transaction, and then select one input as the target input among each input of this transaction. And return to execute the TxOutIndex value under the input field corresponding to the target input, search for the target output field in the previous transaction message corresponding to the target input, wherein the output corresponding to the target output field is Describe the steps and subsequent steps of the target input to obtain the amount of money corresponding to each input in this transaction;
    手续费确定单元,用于若所选取的input遍历完本次交易所需的所有input,则:根据本次交易中各个input对应的金额大小,以及本次交易中各个output对应的金额大小,确定本次交易的手续费;The handling fee determination unit is used to determine if the selected input traverses all inputs required for this transaction: according to the amount of money corresponding to each input in this transaction and the amount of money corresponding to each output in this transaction Handling fee for this transaction;
    手续费展示单元,用于向用户展示所述手续费,以便用户确认是否愿意继续交易;The handling fee display unit is used to display the handling fee to the user so that the user can confirm whether they are willing to continue the transaction;
    签名单元,用于若接收到用于指示用户愿意继续交易的指令,则对本次交易报文进行签名。The signature unit is used to sign the transaction message if an instruction indicating that the user is willing to continue the transaction is received.
  17. 如权利要求15所述的签名装置,其特征在于,所述TxOutHash获取模块包括:The signature device according to claim 15, wherein the TxOutHash acquisition module includes:
    第一格式判断单元,用于判断所述本次交易报文的报文格式是否符合预设报文格式;A first format judgment unit, used for judging whether the message format of the transaction message conforms to the preset message format;
    TxOutHash获取单元,用于若符合所述预设报文格式,则在本次交易报文中,获取本次交易所需的各个input分别对应的input字段下的TxOutHash值。The TxOutHash obtaining unit is used to obtain the TxOutHash value under the input field corresponding to each input required for this transaction in this transaction message if it conforms to the preset message format.
  18. 一种计算机可读存储介质,所述计算机可读存储介质存储有计算机程序,其特征在于,所述计算机程序被处理器执行时实现如下基于区块链网络交易的签名方法:A computer-readable storage medium storing a computer program, characterized in that, when the computer program is executed by a processor, the following signature method based on a blockchain network transaction is implemented:
    其中,所述区块链网络的交易报文中包括有各个交易输入input分别对应的input字段以及各个交易输出output分别对应的output字段,每个input字段中均包括有发送输出哈希TxOutHash值,每个合法的input均对应有前次交易报文,每个合法的input对应的前次交易报文为存在有一output字段,该output字段对应的output为该合法的input,每个合法的input对应的TxOutHash值与该合法的input对应的前次交易报文的哈希Hash值相同;Among them, the transaction message of the blockchain network includes an input field corresponding to each transaction input input and an output field corresponding to each transaction output output, and each input field includes a send output hash TxOutHash value, Each legal input corresponds to a previous transaction message. The previous transaction message corresponding to each legal input has an output field. The output corresponding to the output field is the legal input, and each legal input corresponds to The TxOutHash value is the same as the hash hash value of the previous transaction message corresponding to the legal input;
    所述签名方法包括:The signature method includes:
    在本次交易报文中,获取本次交易所需的各个input分别对应的input字段下的TxOutHash值,所述本次交易报文为本次交易的交易报文;In this transaction message, obtain the TxOutHash value under the input field corresponding to each input required for this transaction, which is the transaction message of this transaction;
    获取本次交易所需的各个input分别对应的前次交易报文;Get the previous transaction message corresponding to each input required for this transaction;
    计算每个前次交易报文的哈希Hash值,得到每个input对应的Hash值;Calculate the hash hash value of each previous transaction message to get the hash value corresponding to each input;
    判断计算得到的每个input对应的Hash值与该input对应的input字段下的TxOutHash值是否一致;Determine whether the calculated Hash value corresponding to each input is consistent with the TxOutHash value under the input field corresponding to the input;
    若计算得到的每个input对应的Hash值与该input对应的input字段下的TxOutHash值均一致,则对所述本次交易报文进行签名。If the calculated Hash value corresponding to each input is consistent with the TxOutHash value under the input field corresponding to the input, the transaction message of this time is signed.
  19. 如权利要求18所述的计算机可读存储介质,其特征在于,所述区块链网络的交易报文中每个output字段中均包括金额Value值,所述Value值用于指示对应的output的金额大小,每个input字段下还包括发送输出索引TxOutIndex值,每个input字段下的TxOutIndex值用于指示对应的input所对应的output字段在对应的前次交易报文中的位置;The computer-readable storage medium of claim 18, wherein each output field in the transaction message of the blockchain network includes an amount Value value, and the Value value is used to indicate the corresponding output The amount of money, each input field also includes the sending output index TxOutIndex value, the TxOutIndex value under each input field is used to indicate the position of the corresponding input field in the corresponding previous transaction message;
    所述若计算得到的每个input对应的Hash值与该input对应的input字段下的TxOutHash值均一致,则对本次交易报文进行签名,包括:If the calculated Hash value corresponding to each input is consistent with the TxOutHash value under the input field corresponding to the input, the transaction message is signed, including:
    若计算得到的每个input对应的Hash值与该input对应的input字段下的TxOutHash值均一致,则:If the calculated Hash value corresponding to each input is consistent with the TxOutHash value under the input field corresponding to the input, then:
    根据所述本次交易报文,获取所述本次交易报文的各个output字段下的Value值,得到本次交易中每个output对应的金额大小;According to the transaction message, obtain the Value value under each output field of the transaction message to obtain the amount of money corresponding to each output in the transaction;
    在本次交易所需的各个input中,选取任一input作为目标input;In each input required for this transaction, select any input as the target input;
    根据所述目标input对应的input字段下的TxOutIndex值,在所述目标input对应的前次交易报文中,查找目标output字段,其中,所述目标output字段对应的output为所述目标input;According to the TxOutIndex value under the input field corresponding to the target input, search for the target output field in the previous transaction message corresponding to the target input, where the output corresponding to the target output field is the target input;
    获取所述目标output字段下的Value值,得到所述目标input的金额大小;Obtain the Value value under the target output field to obtain the amount of the target input amount;
    判断所选取的input是否遍历完本次交易所需的所有input;Determine whether the selected input traverses all the inputs required for this transaction;
    若所选取的input没有遍历完本次交易所需的所有input,则:If the selected input does not traverse all the inputs required for this transaction, then:
    除去已选取的input,在本次交易的各个input中,再选取一input作为目标input,并返回执行所述根据所述目标input对应的input字段下的TxOutIndex值,在所述目标input对应的前次交易报文中,查找目标output字段,其中,所述目标output字段对应的output为所述目标input的步骤以及后续步骤,从而得到本次交易中每个input对应的金额大小;Remove the selected input, in each input of this transaction, select another input as the target input, and return to execute the TxOutIndex value under the input field corresponding to the target input, in front of the corresponding target input In the transaction message, search for the target output field, where the output corresponding to the target output field is the step and subsequent steps of the target input, so as to obtain the amount of money corresponding to each input in this transaction;
    若所选取的input遍历完本次交易所需的所有input,则:If the selected input traverses all inputs required for this transaction, then:
    根据本次交易中各个input对应的金额大小,以及本次交易中各个output对应的金额大小,确定本次交易的手续费;Determine the transaction fee for this transaction based on the amount of money corresponding to each input in this transaction and the amount of money corresponding to each output in this transaction;
    向用户展示所述手续费,以便用户确认是否愿意继续交易;Show the user the handling fee so that the user can confirm whether they are willing to continue the transaction;
    若接收到用于指示用户愿意继续交易的指令,则对本次交易报文进行签名。If an instruction indicating that the user is willing to continue the transaction is received, the transaction message is signed.
  20. 如权利要求18所述的计算机可读存储介质,其特征在于,所述在本次交易报文中,获取本次交易所需的各个input分别对应的input字段下的TxOutHash值,包括:The computer-readable storage medium of claim 18, wherein, in the transaction message, obtaining the TxOutHash value under the input field corresponding to each input required for the transaction includes:
    判断所述本次交易报文的报文格式是否符合预设报文格式;Determine whether the message format of the transaction message conforms to the preset message format;
    若符合所述预设报文格式,则在本次交易报文中,获取本次交易所需的各个input分别对应的input字段下的TxOutHash值。If the preset message format is met, then in this transaction message, the TxOutHash value under the input field corresponding to each input required for this transaction is obtained.
PCT/CN2019/108540 2018-11-21 2019-09-27 Block chain-based network transaction signature method and device, and terminal equipment WO2020103573A1 (en)

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN201811390264.7 2018-11-21
CN201811390264.7A CN111210345B (en) 2018-11-21 2018-11-21 Signature method and device based on block chain network transaction and terminal equipment

Publications (1)

Publication Number Publication Date
WO2020103573A1 true WO2020103573A1 (en) 2020-05-28

Family

ID=70773071

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2019/108540 WO2020103573A1 (en) 2018-11-21 2019-09-27 Block chain-based network transaction signature method and device, and terminal equipment

Country Status (2)

Country Link
CN (1) CN111210345B (en)
WO (1) WO2020103573A1 (en)

Families Citing this family (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US11039317B2 (en) * 2018-12-31 2021-06-15 T-Mobile Usa, Inc. Using a blockchain to determine trustworthiness of messages within a telecommunications network for a smart city

Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN106385319A (en) * 2016-09-29 2017-02-08 江苏通付盾科技有限公司 Verification method for information in block chain network and verification system thereof
CN106789920A (en) * 2016-11-25 2017-05-31 深圳前海微众银行股份有限公司 The joint connecting method and device of block chain
CN107180353A (en) * 2017-06-29 2017-09-19 飞天诚信科技股份有限公司 The implementation method and device of a kind of revocable intelligent contract transaction
CN108712263A (en) * 2018-06-11 2018-10-26 北京京东尚科信息技术有限公司 Information Authentication method, apparatus, system and computer readable storage medium
CN108805571A (en) * 2018-06-11 2018-11-13 北京京东尚科信息技术有限公司 Data guard method, platform, block chain node, system and storage medium

Family Cites Families (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US7882036B1 (en) * 2006-05-01 2011-02-01 Data-Pac Mailing Systems Corp. System and method for postal indicia printing evidencing and accounting
CN104992329B (en) * 2015-05-14 2018-05-11 飞天诚信科技股份有限公司 A kind of method for safely issuing transaction message
CN105956923B (en) * 2016-04-20 2022-04-29 上海如鸽投资有限公司 Asset transaction system and digital authentication and transaction method of assets
CN107947935B (en) * 2017-11-09 2021-09-17 深圳市文鼎创数据科技有限公司 Message signature method, system and terminal equipment
CN107994995A (en) * 2017-11-29 2018-05-04 深圳市文鼎创数据科技有限公司 A kind of method of commerce, system and the terminal device of lower security medium
CN108009810A (en) * 2017-12-27 2018-05-08 光载无限(北京)科技有限公司 A kind of Trusted Digital transaction in assets method

Patent Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN106385319A (en) * 2016-09-29 2017-02-08 江苏通付盾科技有限公司 Verification method for information in block chain network and verification system thereof
CN106789920A (en) * 2016-11-25 2017-05-31 深圳前海微众银行股份有限公司 The joint connecting method and device of block chain
CN107180353A (en) * 2017-06-29 2017-09-19 飞天诚信科技股份有限公司 The implementation method and device of a kind of revocable intelligent contract transaction
CN108712263A (en) * 2018-06-11 2018-10-26 北京京东尚科信息技术有限公司 Information Authentication method, apparatus, system and computer readable storage medium
CN108805571A (en) * 2018-06-11 2018-11-13 北京京东尚科信息技术有限公司 Data guard method, platform, block chain node, system and storage medium

Also Published As

Publication number Publication date
CN111210345A (en) 2020-05-29
CN111210345B (en) 2023-02-17

Similar Documents

Publication Publication Date Title
CN109064334B (en) Intelligent contract accounting method, computer device and readable storage medium
EP3594884A1 (en) Electronic bill management method, device, and storage medium
JP2019523495A (en) Digital goods management in a distributed transaction consensus network
CN110517145B (en) Data transaction method based on multi-block chain and related equipment
CN114788222A (en) Method and system for secure and verifiable offline blockchain transactions
EP4358000A1 (en) Digital currency-based payment method, platform, terminal, and payment system
CN112116334A (en) Cross-block-chain third-party arbitration performance guarantee system and method thereof
WO2020220740A1 (en) Blockchain-based invoice creation method, apparatus and electronic device
TW202018655A (en) Blockchain-based property execution method and system
US20220036351A1 (en) Method and apparatus for resource exchange
CN111709777A (en) Payment mode recommendation method, system, terminal device and storage medium
CN112184240A (en) Refund request processing method and device
CN112132674A (en) Transaction processing method and device
CN113297594A (en) Cross-chain transaction method and device, electronic equipment and storage medium
WO2020103573A1 (en) Block chain-based network transaction signature method and device, and terminal equipment
CN112788555B (en) Cross-operator telephone charge transfer settlement method, device and computing equipment
CN116029825B (en) Block chain transaction method, device and system, electronic equipment and storage medium
CN111612616A (en) Block chain account evaluation method and device, terminal device and computer readable medium
CN111815444A (en) Block chain transaction method, electronic device and storage medium
CN111105238A (en) Transaction risk control method and device
WO2023154203A1 (en) Method and system for transfer of ownership of nft (non-fungible token) upon refund transaction in payment network
CN112712353B (en) Digital currency zero-payment method, system and terminal
CN109271564A (en) Declaration form querying method and equipment
CN112819464B (en) Intelligent contract processing method, processing device, terminal equipment and storage medium
CN112785299B (en) Method and device for roaming transaction based on blockchain

Legal Events

Date Code Title Description
121 Ep: the epo has been informed by wipo that ep was designated in this application

Ref document number: 19886111

Country of ref document: EP

Kind code of ref document: A1

NENP Non-entry into the national phase

Ref country code: DE

122 Ep: pct application non-entry in european phase

Ref document number: 19886111

Country of ref document: EP

Kind code of ref document: A1

32PN Ep: public notification in the ep bulletin as address of the adressee cannot be established

Free format text: NOTING OF LOSS OF RIGHTS PURSUANT TO RULE 112(1) EPC (EPO FORM 1205A DATED 29/09/2021)

122 Ep: pct application non-entry in european phase

Ref document number: 19886111

Country of ref document: EP

Kind code of ref document: A1