Disclosure of Invention
The present application provides a prepaid card management method and apparatus based on a block chain technology, a block chain node, and a prepaid card management system based on a block chain technology, so as to solve the problem that the current prepaid card management scheme cannot guarantee the rights and benefits of consumers and cannot meet the privacy requirements of consumers. The specific scheme is as follows:
in a first aspect, the present application provides a prepaid card management method based on a block chain technology, applied to a block chain node deployed with a prepaid contract, the method including;
transferring the target amount to a prepaid contract account of the consumer according to an amount transfer request sent by the consumer;
according to a locking request sent by the consumer, locking a prepaid contract account of the consumer to a blockchain account of a merchant, and setting a locking period as a target locking period;
receiving a transaction request sent by the merchant, wherein the transaction request is a request initiated by the consumer and signed by a private key of a blockchain account of the merchant, and the transaction request comprises a prepaid contract account of the consumer as an transferred-out account, a prepaid contract account of the merchant as an transferred-in account, the consumption amount and zero knowledge proof;
performing signature verification on the transaction request; verifying a locked relationship between the consumer's prepaid contract account and the merchant's blockchain account; verifying the zero knowledge proof;
if the three items of verification are passed, transferring the consumption amount of the time from the prepaid contract account of the consumer to the prepaid contract account of the merchant;
releasing the locking relationship between the consumer's prepaid contract account and the merchant's blockchain account when the actual locking period reaches the target locking period;
wherein the amount of the prepaid contract account is in encrypted form in the blockchain node.
Preferably, the transferring the target amount to the prepaid contract account of the consumer according to the amount transfer request sent by the consumer includes:
transferring an external recharging amount from an external asset contract account of a consumer to a pre-paid contract account of the consumer according to an external recharging request sent by the consumer;
and/or the presence of a gas in the gas,
transferring an internal transfer amount from a first prepaid contract account of a consumer to a second prepaid contract account of the consumer according to an internal transfer request sent by the consumer.
Preferably, the method further comprises the following steps:
judging whether a prepaid contract account of a consumer to be charged is locked or not according to an external charging request sent by the consumer;
if yes, rejecting the external recharging request;
if not, transferring the external recharging amount from the external asset contract account of the consumer to the pre-paid contract account of the consumer.
Preferably, the transferring the target amount to the prepaid contract account of the consumer according to the amount transfer request sent by the consumer includes:
determining a prepaid contract account of the consumer to be transferred with the amount according to the amount transfer request sent by the consumer;
determining whether the consumer's prepaid contract account is a registered account;
if yes, judging whether the sum of all the accounts of the prepaid contract exceeds the maximum sum after the sum is transferred;
if not, the target amount is transferred to the consumer's prepaid contract account.
Preferably, the transferring the target amount to the prepaid contract account of the consumer according to the amount transfer request sent by the consumer includes:
extracting a target amount as an in-transit fund of a pre-paid contract account of a consumer according to an amount transfer request sent by the consumer;
transferring the in-transit funds to the consumer's pre-paid contract account at the end of the current operational period.
Preferably, the method further comprises the following steps:
receiving an account registration request sent by a consumer or a merchant, wherein the account registration request comprises a public key and a signature;
judging whether the public key is registered to a prepaid contract account;
if not, verifying the signature;
and if the verification is passed, determining that the registration of the account of the prepaid contract is successful, and feeding back a registration success message to the consumer or the merchant.
Preferably, the method further comprises the following steps:
and when the actual locking period does not reach the target locking period, if an unlocking request sent by the merchant is received, releasing the locking relationship between the prepaid contract account of the consumer and the blockchain account of the merchant.
In a second aspect, the present application provides a prepaid card management apparatus based on a block chain technology, applied to a block chain node where prepaid contracts are deployed, the apparatus including;
the amount transfer module is used for transferring the target amount to the prepaid contract account of the consumer according to the amount transfer request sent by the consumer;
the locking module is used for locking the prepaid contract account of the consumer to the block chain account of the merchant according to the locking request sent by the consumer and setting the locking term as a target locking term;
the transaction request receiving module is used for receiving a transaction request sent by the merchant, wherein the transaction request is a request initiated by the consumer and signed by a private key of a blockchain account of the merchant, and the transaction request comprises a prepaid contract account of the consumer as an roll-out account, a prepaid contract account of the merchant as a roll-in account, the consumption amount and zero knowledge proof;
the verification module is used for performing signature verification on the transaction request; verifying a locked relationship between the consumer's prepaid contract account and the merchant's blockchain account; verifying the zero knowledge proof;
the consumption module is used for transferring the consumption amount to the pre-paid contract account of the merchant from the pre-paid contract account of the consumer if the three items of verification are passed;
an unlocking module for unlocking the locking relationship between the consumer's prepaid contract account and the merchant's blockchain account when the actual locking period reaches the target locking period;
wherein the amount of the prepaid contract account is in encrypted form in the blockchain node.
In a third aspect, the present application provides a block-link point deployed with pre-paid contracts, the block-link point comprising:
a memory for storing a computer program;
a processor for executing the computer program to implement the prepaid card management method based on the block chain technology as described above.
In a fourth aspect, the present application provides a prepaid card management system based on a block chain technology, comprising: a consumer, a merchant, and a blockchain node deployed with a prepaid contract;
the consumer is used for sending a money transfer request and a locking request to the block chain node;
the blockchain node is used for transferring a target amount to the prepaid contract account of the consumer according to the amount transfer request, locking the prepaid contract account of the consumer to the blockchain account of the merchant, and setting a locking period as a target locking period;
the merchant is used for sending a transaction request to the blockchain node, wherein the transaction request is a request initiated by the consumer and signed by a private key of a blockchain account of the merchant, and comprises a prepaid contract account of the consumer as a roll-out account, a prepaid contract account of the merchant as a roll-in account, the consumption amount and zero knowledge proof;
the block chain node is used for performing signature verification on the transaction request; verifying a locking relationship between the consumer's prepaid contract account and the merchant's blockchain account; verifying the zero knowledge proof; if the three items of verification are passed, transferring the consumption amount of the time from the prepaid contract account of the consumer to the prepaid contract account of the merchant;
the blockchain node is further used for unlocking the locking relation between the prepaid contract account of the consumer and the blockchain account of the merchant when the actual locking period reaches the target locking period;
wherein the amount of the prepaid contract account is in encrypted form in the blockchain node.
In summary, the present application provides a prepaid card management method based on a blockchain technology, which is applied to a blockchain node where prepaid contracts are deployed, wherein specific amounts of prepaid contract accounts of consumers and merchants are in an encrypted form in the blockchain node, and the method comprises the following steps: transferring the target amount to a prepaid contract account of the consumer according to the amount transfer request sent by the consumer; according to a locking request sent by a consumer, locking a prepaid contract account of the consumer to a blockchain account of a merchant, and setting a locking period as a target locking period; receiving a transaction request sent by a merchant, wherein the transaction request is a request initiated by a consumer and signed by a private key of a blockchain account of the merchant, and the transaction request comprises a prepaid contract account of the consumer as an export account, a prepaid contract account of the merchant as an import account, the consumption amount of the time and a zero knowledge proof; performing signature verification on the transaction request; verifying a locking relationship between a consumer's prepaid contract account and a merchant's blockchain account; verifying the zero knowledge proof; if the three items of verification are passed, transferring the consumption amount from the prepaid contract account of the consumer to the prepaid contract account of the merchant; and releasing the locking relation between the pre-paid contract account of the consumer and the block chain account of the merchant when the actual locking period reaches the target locking period.
Therefore, the method takes the block chain nodes as a trusted third party, and realizes a prepaid card mechanism on the premise of ensuring the anonymity and privacy of consumers. Based on the blockchain technology, a consumer's prepaid contract account can be locked to a merchant's blockchain account for a period of time, after which all authorized transactions for the prepaid contract account are performed by the locked merchant blockchain account, which is automatically unlocked after expiration of the lock. Thus, the prepaid contract account is not directly associated with the consumer, and the consumer authorizes the transaction, and the real transaction operation is handed to the blockchain account for execution, which ensures the anonymity of the consumer. Moreover, the amount of the prepaid contract account is in an encrypted form in the block link points and is completely hidden, and only a controller of the prepaid contract account can read the account amount, so that the privacy of a consumer is guaranteed.
In addition, the method can ensure various consumption rights and interests of the consumer, and is particularly shown in the following steps that on one hand, each transaction needs the authorization of the consumer, a merchant only can passively accept the transaction, and the account amount of the consumer cannot be actively deducted; on the other hand, after a certain time limit is exceeded, the locking relationship is automatically released, and the consumer can retrieve the account balance.
The application also provides a prepaid card management device based on the block chain technology, a block chain node and a prepaid card management system based on the block chain technology, and the technical effects correspond to those of the method, and are not described again here.
Detailed Description
In order that those skilled in the art will better understand the disclosure, the following detailed description is given with reference to the accompanying drawings. It is to be understood that the embodiments described are only a few embodiments of the present application and not all embodiments. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present application.
The application aims to provide a prepaid card management method and device based on a block chain technology, a block chain node and a prepaid card management system based on the block chain technology. On the basis, the anonymity and the privacy of the consumers are guaranteed.
Example one
The prepaid card management method based on the block chain technology provided by the present application is described below. The method is applied to a blockchain node deployed with prepaid contracts, as shown in fig. 1 and 2, and comprises the following steps;
s11, transferring the target amount to a prepaid contract account of the consumer according to the amount transfer request sent by the consumer;
s12, locking the prepaid contract account of the consumer to the block chain account of the merchant according to the locking request sent by the consumer, and setting the locking term as a target locking term;
s13, receiving a transaction request sent by a merchant, wherein the transaction request is a request initiated by a consumer and signed by a private key of a block chain account of the merchant, and the transaction request comprises a prepaid contract account of the consumer as an export account, a prepaid contract account of the merchant as an import account, the current consumption amount and zero knowledge proof;
s14, signature verification is carried out on the transaction request; verifying a locking relationship between a consumer's prepaid contract account and a merchant's blockchain account; verifying the zero knowledge proof;
s15, if the three items of verification are passed, transferring the consumption amount from the prepaid contract account of the consumer to the prepaid contract account of the merchant;
and S16, when the actual locking period reaches the target locking period, releasing the locking relation between the prepaid contract account of the consumer and the block chain account of the merchant.
First, a Pre-paid Contract (PPC) is deployed on a block link point, similar to an issuer, for managing and holding all Pre-paid Contract accounts. Both the merchant and the consumer register an account in the prepaid contract.
Accounts in the block chain can be divided into two types, one type is an external account controlled by a private key, and a controller of the private key is a controller of the external account; the other type is a contract account controlled by logic, the contract account can only be executed according to the logic of the intelligent contract, the contracts can be mutually called, but the execution must be triggered by an external account initially. The pre-paid contract account is distinguished from the blockchain account and is controlled by an independent pre-paid contract account private key, and the controller of the pre-paid contract account private key is the controller of the pre-paid contract account. The operations of prepaid contract account money transfer, account locking and the like all need to be authorized by a controller in a signature mode.
The consumer's prepaid contract account may be locked to the merchant-controlled blockchain account for a period of time. Locking means that the current account can only pay for a specific account, which is equivalent to the consumer's prepaid contract account signing up with the merchant's blockchain account, targeting the consumer's blockchain account for consumption. After locking, all authorized transactions for the prepaid contract account can only be executed via the locked merchant blockchain account. And automatically unlocking after the locking is finished.
The prepaid contract account is not directly related to the actual user, and after the consumer authorizes the transactions such as transfer and account locking, the real transactions are handed to the actually executed blockchain account in an offline mode, so that the anonymity and privacy of the consumer are guaranteed. Moreover, in the block chain node, the amount of the prepaid contract account is in an encrypted form, whether the consumer or the merchant, and particularly can be realized in an encrypted manner through an ElGamal algorithm, and only the controller of the prepaid contract account can read the amount of the prepaid contract account.
Locking achieves the effect of prepayment, that is, locking ensures that the consumer's prepaid contract account only transacts with the locked merchant blockchain account, and no other action is available. Moreover, the specific service is determined by the locked blockchain account, and the separation of transfer authorization and service logic is realized, wherein the service logic refers to preset transaction rules, such as 20 benefits per consumption 100, and the transfer authorization and the service logic are separated in the embodiment. Meanwhile, the consumer can keep the authorization of each transaction, namely that the account holder of the prepaid contract needs to initiate each transaction actively, and the merchant can only accept passively but cannot deduct the amount of the prepaid contract actively. Finally, the lock is automatically unlocked after the lock is finished by a certain period of time, so that the consumer can finally take out the balance of the prepaid card.
It should be noted that, the consumers and the merchants mentioned in this embodiment refer to not only the user or the organization but also the computer products such as the client and the computer device.
According to the prepaid card management method based on the blockchain technology, the blockchain is used for replacing a trusted third party, and on the premise that the anonymity and privacy of the consumer are guaranteed, various consumption rights and interests of the consumer are fully guaranteed. In addition, the separation of transfer authorization and business logic is realized. In theory, any business logic can be designed to meet various consumption needs.
Example two
Another method for managing prepaid cards based on block chain technology provided in the present application is described in detail below.
The prepaid contract is first deployed and instantiated, and the subsequent operations of this embodiment are all implemented in the prepaid contract. One possible block chain technology-based prepaid card management process is as follows: both the consumer and the merchant register a prepaid contract account in the prepaid contract; the consumer transfers a sum of money to the pre-paid contract account controlled by the consumer, locks the sum of money to the blockchain account controlled by the merchant, and sets a locking term; during each transaction, the consumer generates a zero knowledge certificate for the account balance of the pre-paid contract and the consumption amount of the consumer, signs the certificate and sends the certificate to the merchant; signing the private key of the local blockchain account of the merchant, generating a transaction request and submitting blockchain nodes; verifying the transaction request by the block chain link points, verifying the locking relation between the merchant block chain account and the consumer pre-paid contract account, and verifying zero knowledge proof; and completing transfer consumption after the three verification items are passed, and transferring the consumption amount from the prepaid contract account of the consumer to the prepaid contract account of the merchant. After the locking period expires, the locking relationship is released and the consumer is free to control the balance therein.
In this embodiment, the consumer and the merchant both interact with the prepaid contracts on the block link points through the client, and the functions of the client mainly include:
1. a user's blockchain account private key is generated and managed, and transactions are signed with the blockchain account private key when needed, such as when a blockchain transaction is to be initiated.
2. The user's private key of the prepaid contract account is generated and managed, and if necessary, a proof is generated and signed with the private key of the prepaid contract account, for example, the balance of the prepaid contract account is proved, and a transaction with a variable amount is initiated.
3. Interacting with block link points;
4. and interacting with other clients.
The algorithms involved in the client and prepaid contracts are described below. In the description of the embodiments below, Z represents a set of non-negative integers; zp represents a set of non-negative integers less than p; zp denotes a set of positive integers smaller than p; g represents a group formed by midpoints of elliptic curves on a finite field Zp, G represents a generator in G, the points in G support addition and quantity multiplication operations (x · G, namely x G additions), and a unit cell 0 in G is 0 · G; address represents a block chain Address type; x represents that X is an element in the set X or an element of X type; = denotes assigned value, = = denotes equal.
The process of transferring the sum of money to the pre-paid contract account controlled by the consumer can be specifically transferring the sum of money from an external asset contract account to the pre-paid contract account or transferring the sum of money from one pre-paid contract account to another pre-paid contract account. In this embodiment, the external asset contract Mint is a conventional ERC20 contract, and two functions are mainly used for it:
transfer from (from Address: address, toAddress: address, b: Z): in the external property contract Mint, the property is transferred from fromAddr to toAddr with the quota b.
transfer (toAddr: address, b: Z): in Mint, the asset is transferred out of the external asset contract account to toAddr with a quota of b.
In the embodiment, the proof is generated by the save function in a zero knowledge proof mode and is verified by verifyprofo; the Sign function generates a signature by means of zero knowledge proof and is verified by a VerifySign function.
In the implementation process, the present embodiment mainly involves seven processes: contract deployment, account registration, recharging, extraction, locking, transfer and unlocking, and the implementation processes and the adopted algorithms of the processes are respectively described below.
Contract deployment:
the prepaid contract includes global variables that are determined at deployment and cannot be changed thereafter, and instance variables that can be modified after deployment. The prepaid contract is described in detail as follows:
global variables:
z represents the cycle length, and the same account can only execute one operation in the same cycle;
z, which represents the maximum value of the sum of all account balances.
Example variables:
coin, the address of an external asset contract;
mapping (G = > [ G, G ]), account balance, initially empty;
mapping (G = > [ G, G ]), fund in transit, and is empty initially;
mapping (G = > Z), cycle number of last rolover operation, initially empty;
mapping (G = > [ Address, Z ]), the locked blockchain Address and expiration time (in block height), initially empty;
mapping (G = > Z), account operation count, initially empty;
z, the sum of the balances of all accounts is initially 0 and does not exceed MAX at most.
The prepaid contracts are deployed on the blockchain nodes, the contractor method is run to initialize the prepaid contracts, and the subsequent operations are performed based on the prepaid contracts previously deployed. The account assets in the prepaid contract are mutually redeemable with account assets of other asset contracts, including but not limited to the external asset contracts described above.
The constractor method is as follows:
inputting: the coin _ Address is Address;
and (3) outputting: air conditioner
The method comprises the following steps:
1. coin = Mint (coin _ addr)// import and save external asset contract addresses in the coin variable, followed by both the in and out transfer of assets, is the interaction with the contract
After deployment, the system architecture of the blockchain is shown in fig. 3.
And (3) account registration:
the client runs the register method to create a public-private key pair and registers the account in the prepaid contract using the public key as an address. And then, the account registration result is confirmed by inquiring the block chain node.
The client-side register method is as follows:
inputting: adress is the Address of the prepaid contract
And (3) outputting: g, public key, signature sig
The method comprises the following steps: generating a public and private key pair (x, y), randomly selecting a private key x from Zp, and calculating a public key y = x · g; generating a signature sig = Sign (x, (addr, y)); the client encrypts the management private key x and returns (y, sig).
The client then sends the public key y G and signature sig to the blockchain node. On the block link point side, the register method for the prepaid contract is as follows:
1. require (| registered (y), "" registered |)// determine whether public key y has registered an account, if yes, directly stop registering and prompt registered, otherwise continue the subsequent steps
2. require (VerifySign (y, (addr, y), sig), "invalid signature!.)// determine if the signature is valid
3. acc [ y ] = [0,0]// initializing account balance
4. pending [ y ] = [ y, g ]// initializing funds in transit
5. lock y = null// initializing lock state
6. ctr [ y ] =0// initialize counter
In summary, the account registration process is shown in FIG. 4.
Recharging:
assets are transferred from the external asset contract account to the prepaid contract account. Specifically, the user calls a fund method of the prepaid contract through the client to charge the account of the prepaid contract. The client can then query the blockchain system to confirm the recharge results.
The fund method is as follows:
inputting: public key y: G, transferred amount b: Z
And (3) outputting: is free of
The method comprises the following steps:
1. required (y), "unregistered!.// determining whether prepaid contract account y is a registered account, it is guaranteed that it is a registered account
2. Acquire (y, msg. Sender), "no operation authority |)// determine whether prepaid contract account y is locked, only unlocked account has authority to recharge
3. require (btotal + b < = MAX, "Total overrun!")// determine whether the asset is redeemed for excess
4、rollOver(y)
5. pending [ y ] = pending [ y ] [0] + b · g// increase in funds in transit b
6. requirement (core. Transfer from (msg. Sender, address, b), "asset transfer error!")// deduction of b from an external asset contract account
7. btotal = btotal + b// prepaid contract account increase b
As shown in fig. 5, when transferring the amount from account a to account B, the actual implementation process is: first, the amount of money is extracted from account A and used as the in-transit fund of account B; when a certain condition is reached, for example, when the operation cycle is ended, a rolover operation is executed, and the funds in transit are transferred into the account B. The rolover method will be described in detail below and will not be expanded here.
Extraction:
transferring assets from the prepaid contract account to the external asset contract account. The client runs a burn method to request that its own controlled prepaid contract account be transferred out of assets to an external asset contract account. And the block chain node runs a burn method to execute real asset transferring operation.
The burn method at the client side is as follows:
inputting: private key x Zp
And (3) outputting: signature sig
1. let b = readBalance (x)// determine transfer amount
2. let y = x · g// calculating public key
3. let [ CL, CR ] = acc [ y ]// get account balance
4. let proof = pro (st _ burn [ y, CL, CR, b, g ], (x))// proof of generation
5. let sig = Sign (x, (b, proof, ctr [ y ]))// generate signature and return
When generating proof, st _ burn [ y, CL, CR, b, g ] is public parameter, (x) is private parameter, proof proposition: { y = = x · g and CL = = g · b + x · CR }.
Accordingly, on the block link point side, the burn method of the advance contract is as follows:
inputting: g is the public key, b is the transfer amount, Z is the proof, sig is signed
And (3) outputting: is composed of
1. required (y), "unregistered!.// determine whether account y is a registered account
2. Acquire (checkLock (y, msg. Sender), "No operation Authority!")// determine if account y is locked and locked account cannot transfer money
3、rollOver(y)
4. require (st _ burn [ y, CL, CR, b, g ], proof of invalidity!)/proof of verification
5. require (VerifySign (y, (b, proof, ctr [ y ]), sig), "invalid signature!.)// verify signature
6. acc [ y ] = [ acc [ y ] [0] -CL, acc [ y ] [1] -CR ]// deduct account balance
7. ctr [ y ] = ctr [ y ] +1// counter plus one
8. require (core. Transfer (msg. Sender, b), "asset transfer error |)// transfer balance out to external asset contract
9. btotal = btotal-b// prepaid contract overall balance reduction
Locking:
the consumer requests the prepaid contract account to be locked to the blockchain account using the lock method while setting a lock period, and the blockchain linked point executes the lock method to perform a true locking operation when the prepaid contract account is identical in form to the prepaid card.
The customer-side lock method is as follows:
inputting: the private key x is Zp, the block chain Address is addr and Address, and the height n of the unlocked block chain is Z
And (3) outputting: signature sig
The method comprises the following steps:
1. let y = x · g// calculating public key
2. let sig = Sign (x, (addr, n, ctr [ y ]))// generate signature and return sig
The client may then invoke the lock method of the prepaid contract directly, or the signature may be handed over to a lock method that is authorized by other clients to invoke the prepaid contract.
On one side of the block chain link points, the lock method of the prepay contract is as follows:
inputting: g is a public key, the Address is a block chain account, Z is an unlocking block height, and sig is a signature
And (3) outputting: is free of
The method comprises the following steps:
1. required (y), "unregistered |)// determining whether account y is a registered account
2. Acquire (checkLock (y, msg. Sender), "No operation Authority!")// determine whether Account y is locked
3、rollOver(y)
4. require (VerifySign (y, (addr, n, ctr [ y ]), sig), "invalid signature!.)// verify signature
5. lock [ y ] = [ addr, n ]// locked account y
6. ctr [ y ] = ctr [ y ] +1// counter plus one
Transferring accounts:
a user (typically a consumer) transfers assets from his prepaid contract account to another prepaid contract account (typically a merchant) using the transfer method.
The user can generate the transfer certificate through a transfer method of the client side, wherein the transfer method of the client side comprises the following steps:
inputting: private key of transfer-out party x: zp, public key of transfer-in party y _ to: G, transfer amount b: Z (requirement is greater than zero, with upper limit)
And (3) outputting: returning (y _ from: G, y _ to: G, C _ from: G, C _ to: G, D: G, proof, sig), if the input is invalid, returning an error
The method comprises the following steps:
1. let bal = readBalance (x)// read roll-out account balance
2. If (b > bal) returns an error// transfer amount b cannot be greater than the account balance
3. let y _ from = x · g// calculate the roll-out account public key y
4. Simulating rolover (y _ from); let [ CL, CR ] = acc [ y _ from ]// simulate transfer operation, read transfer account balance after transfer
5. Randomly selecting r in Zp
6、let C_from=b·g+r·y_from
7、let C_to=b·g+r·y_to
8. let D = r.g// (C _ from, D) is an encrypted form of the amount transferred from the account, and (C _ to, D) is an encrypted form of the amount transferred from the account
9. proof of production = pro (st _ transfer [ y _ to, y _ from, CL, CR, C _ from, C _ to, D, g ], (x, b, bal, r))// proof of generation
10. sig = Sign (x, (y _ to, C _ from, C _ to, D, proof, ctr [ y ]))// generating signature
11. (y _ from, y _ to, C _ from, C _ to, D, proof, sig)// return transfer voucher
And the return value of the transfer method at the client side is the transfer certificate. If the prepaid contract account is locked to a blockchain account, the transfer credentials may be delivered to the client controlling the private key of the blockchain account, authorizing it to invoke the transfer. If the prepaid contract account is not locked, the transfer credentials may be delivered to any client (including itself) authorizing it to perform the transfer. The transfer is executed by calling a transfer method of the prepaid contract, and the parameters are transfer certificates generated by the transfer method of the client.
In generating the proof, st _ transfer [ y _ to, y _ from, CL, CR, C _ from, C _ to, D, g ] is a public parameter, (x, b, bal, r) is a private parameter, proof proposition: { C _ from = = b · g + r · y _ from and C _ to = = b · g + r · y _ to and D = = r · g and CL-C = = (bal-b) · g + x · g (CR-D) and y = = x · g and b and bal-b are between [0, max }.
On the block link point side, the transfer method of the prepaid contract is as follows:
inputting: y _ from: G, y _ to: G, C _ from: G, C _ to: G, D: G, proof, sig
And (3) outputting: is composed of
1. required (y _ from), "transfer out account unregistered |)// whether transfer out account is registered
2. required (y _ to), "transfer account unregistered |)// whether the transfer account is registered
3. Acquire (checkLock (y _ from, msg. Sender), "No operation Authority!")// check Lock relationship
4、rollOver(y_from);rollOver(y_to)
5. require (st _ transfer [ y _ to, y _ from, CL, CR, C _ from, C _ to, D, g ], proof of invalidity!)/proof of verification
6. require (VerifySign (y _ from, (y _ to, C _ from, C _ to, D, proof, ctr [ y _ from ]), sig), "invalid signature!")// verify signature
7. acc [ y _ from ] = [ acc [ y _ from ] [0] -C _ from, acc [ y _ from ] [1] -D ]// extract amount from roll-out account
8. pending [ y _ to ] = [ pending [ y _ to ] [0] + C _ to, pending [ y _ to ] [1] + D ]// pick-up amount as the funds in transit to the account
9. ctr [ y _ from ] = ctr [ y _ from ] +1// roll-out account counter plus one
Unlocking:
after the locking is finished, the locking relation is automatically released, and no additional operation is needed. Specifically, the user can directly call the unlock method of the prepaid contract through the client to unlock the prepaid contract account, provided that the client possesses the private key of the blockchain account to which the prepaid contract account is locked. In addition, if the consumer wishes to unlock in advance, the locked blockchain account can be actively unlocked.
The Unlock method is as follows:
inputting: public key y G
And (3) outputting: is free of
1. required (y), "unregistered!.// check if the account is a registered account
2. Acquire (checkLock (y, msg. Sender), "No operation Authority!")// check the locked status of the account
3、rollOver(y)
4. lock [ y ] = empty/unlocked
The above procedure also calls four methods: the rolOver method, the checkLock method, the registered method, and the readBalance method, which are described below.
rollOver method:
the function is as follows: the balance is transferred from the in-transit funds to the actual account.
Inputting: g is the public key y.
And (3) outputting: none.
The method comprises the following steps:
1. the current block height is divided by the cycle length and then rounded down to obtain the current cycle number E, i.e. E = rounded down (block.
2. If the y account does not have a roll over during this period, the balance of the in-transit account is transferred to the real account. That is, if (lastrolover [ y ] < e), the following update operation is performed:
acc[y]=[acc[y][0]+pending[y][0],acc[y][1]+pending[y][1]]
pending[y]=[0,0]
lastRollOver[y]=e
the checkLock method:
the function is as follows: check if the account is locked, where 1 indicates true and 0 indicates not true.
Inputting: g is the public key, and the Address of the block chain is the Address.
And (3) outputting: if addr has operation authority to y, 1 is output, otherwise 0 is output.
The method comprises the following steps:
1. if (lock [ y ] = = null), return 1// if there is no lock, return 1
2. let [ locker, ts ] = lock [ y ]// get locked account locker and unlock block number ts
3. If (addr = = lock or ts < block.number), return 1, otherwise return 0// if locked account lock equals input account number addr, or unlock block number ts exceeds lock block number (equivalent to reaching target lock deadline), return 1, otherwise return 0
registered method:
the function is as follows: it is checked whether the account is already registered.
Inputting: g is the public key.
And (3) outputting: if the public key is registered, 1 is output, otherwise 0 is output.
The method comprises the following steps:
1. if (acc [ y ] [0] = =0 and acc [ y ] [1] = =0 and pending [ y ] [0] = =0 and pending [ y ] [1] = = 0), return 0, otherwise return 1// user use tool to generate a new account, then register in the prepaid contract. Here it is checked whether it is already registered. If a return 1 is registered, otherwise a return 0 is returned.
The readBalance method comprises the following steps:
the function is as follows: reading balance of corresponding account
Inputting: private key x Zp
And (3) outputting: account balance
The method comprises the following steps:
1、let y=x·g
2. simulating rolOver (y); let [ CL, CR ] = acc [ y ]
3. Find b by cycling from 0 to MAX such that b · g = = CL-x · CR, return b · g =
EXAMPLE III
The prepaid card management apparatus based on the blockchain technology provided in the present application is described below, and the prepaid card management apparatus based on the blockchain technology described below and the prepaid card management method based on the blockchain technology described above may be referred to in correspondence.
As shown in fig. 6, the prepaid card management apparatus based on the block chain technology is applied to a block chain node where prepaid contracts are deployed, including;
the amount transfer module 61 is used for transferring the target amount to the prepaid contract account of the consumer according to the amount transfer request sent by the consumer;
a locking module 62, configured to lock the prepaid contract account of the consumer to the blockchain account of the merchant according to the locking request sent by the consumer, and set the locking term as a target locking term;
the transaction request receiving module 63 is configured to receive a transaction request sent by a merchant, where the transaction request is a request initiated by a consumer and signed by a private key of a blockchain account of the merchant, and the transaction request includes a prepaid contract account of the consumer as an account transferred out, a prepaid contract account of the merchant as an account transferred in, the current consumption amount, and a zero knowledge proof;
a verification module 64 for performing signature verification on the transaction request; verifying a locking relationship between a consumer's prepaid contract account and a merchant's blockchain account; verifying the zero knowledge proof;
the consumption module 65 is used for transferring the consumption amount to the pre-paid contract account of the merchant from the pre-paid contract account of the consumer if the three items of verification are passed;
an unlocking module 66, configured to unlock the locking relationship between the consumer's prepaid contract account and the merchant's blockchain account when the actual locking period reaches the target locking period;
wherein the amount of the pre-paid contract account is in encrypted form in the block link points.
The prepaid card management apparatus based on the blockchain technology of the present embodiment is used to implement the aforementioned prepaid card management method based on the blockchain technology, and therefore, the specific implementation of the apparatus can be seen in the foregoing parts of the embodiment of the prepaid card management method based on the blockchain technology, for example, the money transfer module 61, the locking module 62, the transaction request receiving module 63, the verification module 64, the consumption module 65, and the unlocking module 66 are respectively used to implement steps S11, S12, S13, S14, S15, and S16 in the aforementioned prepaid card management method based on the blockchain technology. Therefore, specific embodiments thereof may be referred to in the description of the corresponding respective partial embodiments, and will not be described herein.
In addition, since the prepaid card management apparatus based on the blockchain technology of the present embodiment is used for implementing the foregoing prepaid card management method based on the blockchain technology, the role thereof corresponds to the role of the method described above, and details thereof are omitted here.
Example four
Further, the present application provides a block link point deployed with a prepaid contract, as shown in fig. 7, the block link point including:
a memory 100 for storing a computer program;
a processor 200 for executing the computer program to implement the prepaid card management method based on block chain technology as described above.
EXAMPLE five
The present application also provides a prepaid card management system based on the block chain technology, as shown in fig. 8, including: a consumer, a merchant, and a blockchain node deployed with a prepaid contract;
the consumer is used for sending a money transfer request and a locking request to the block chain nodes;
the block chain node is used for transferring the target amount to the prepaid contract account of the consumer according to the amount transfer request, locking the prepaid contract account of the consumer to the block chain account of the merchant, and setting the locking period as a target locking period;
the merchant is used for sending a transaction request to the blockchain nodes, the transaction request is a request which is initiated by a consumer and is signed by a private key of a blockchain account of the merchant, and the transaction request comprises a prepaid contract account of the consumer as an export account, a prepaid contract account of the merchant as an import account, the current consumption amount and zero knowledge proof;
the block chain nodes are used for signature verification of the transaction request; verifying a locking relationship between a consumer's prepaid contract account and a merchant's blockchain account; verifying the zero knowledge proof; if the three items of verification are passed, transferring the consumption amount from the prepaid contract account of the consumer to the prepaid contract account of the merchant;
the blockchain node is also used for releasing the locking relation between the prepaid contract account of the consumer and the blockchain account of the merchant when the actual locking period reaches the target locking period;
wherein the amount of the prepaid contract account is in encrypted form in the block link point.
The embodiments are described in a progressive manner, each embodiment focuses on differences from other embodiments, and the same or similar parts among the embodiments are referred to each other. The device disclosed by the embodiment corresponds to the method disclosed by the embodiment, so that the description is simple, and the relevant points can be referred to the method part for description.
The steps of a method or algorithm described in connection with the embodiments disclosed herein may be embodied directly in hardware, in a software module executed by a processor, or in a combination of the two. A software module may reside in Random Access Memory (RAM), memory, read Only Memory (ROM), electrically programmable ROM, electrically erasable programmable ROM, registers, hard disk, a removable disk, a CD-ROM, or any other form of storage medium known in the art.
The above detailed descriptions of the solutions provided in the present application, and the specific examples applied herein are set forth to explain the principles and implementations of the present application, and the above descriptions of the examples are only used to help understand the method and its core ideas of the present application; meanwhile, for a person skilled in the art, according to the idea of the present application, there may be variations in the specific embodiments and the application scope, and in summary, the content of the present specification should not be construed as a limitation to the present application.