j"19HxigV4QyBv3tHpQVcUEQyq1pzZVdoAutMQ# KaChing APDU Transaction Protocol Explained
[Source(Permalink)](https://kaching.cards/explained/ )
![](https://kaching.cards/browsing-katp.jpg)
# KaChing APDU Transaction Protocol Explained 解é KaChing APDU 交æåè®®
#### The reader of this article is expected to have a fairly good knowledge about bitcoin at a technical level. æ¬æç读è
åºè¯¥å¨ææ¯å±é¢ä¸å¯¹æ¯ç¹å¸æç¸å½å¥½çäºè§£
#### **Protocol specification: åè®®è§æ ¼:** <http://kaching.cards/katp.pdf>
The KaChing APDU Transaction Protocol (KATP) is a protocol allowing two entities to perform peer-to-peer bitcoin transactions. Itâs primarily designed for local communication, where the wallet and terminal are physically close.
Kaching APDU 交æåè®®(KATP)æ¯ä¸ä¸ªå
许两个å®ä½æ§è¡å¯¹çæ¯ç¹å¸äº¤æçåè®®ã å®ä¸»è¦æ¯ä¸ºæ¬å°éä¿¡è设计çï¼é±å
åç»ç«¯å¨ç©çä¸ä¿æè¿è·ç¦»ã
During a transaction session one peer acts as the terminal while the other acts as the wallet. Some devices such as an app on a smartphone will have the ability to act both as terminal and wallet.
å¨äº¤æä¼è¯ä¸ï¼ä¸ä¸ªå¯¹çç¹å
å½ç»ç«¯ï¼èå¦ä¸ä¸ªå
å½é±å
ã æäºè®¾å¤ï¼æ¯å¦æºè½ææºä¸çåºç¨ç¨åºï¼å¯ä»¥åæ¶å
å½ç»ç«¯åé±å
çè§è²ã
Both the terminal and wallet are able to add as many inputs and outputs to the transaction as they wish. This allows both the wallet and terminal to consolidate their UTXOs as part of normal use.
ç»ç«¯åé±å
é½è½å¤æç
§èªå·±çææ¿å交ææ·»å ä»»æå¤çè¾å
¥åè¾åºã è¿ä½¿å¾é±å
åç»ç«¯é½å¯ä»¥å并å®ä»¬ç UTXOs (æªè±è´¹ç交æè¾åº)ä½ä¸ºæ£å¸¸ä½¿ç¨çä¸é¨åã
Metadata may be added in the form of OP\_RETURN outputs by both terminal and wallet.
å
æ°æ®å¯ä»¥éè¿ç»ç«¯åé±å
以OP\_RETURN è¾åºçå½¢å¼æ·»å ã
## Terminal role ç»ç«¯è§è²
The terminal is the host of the communication session. It is responsible for determining the correct fee and publishing the completed transaction to the blockchain.
ç»ç«¯æ¯éä¿¡ä¼è¯ç主æºã å®è´è´£ç¡®å®æ£ç¡®çè´¹ç¨ï¼å¹¶å°å®æç交æåå¸å°åºåé¾ã
## Wallet role é±å
è§è²
The wallet is responsible for keeping track of itâs own UTXOs. A wallet doesnât need any internet connectivity. Such a wallet can only receive (and spend) funds when communicating with a terminal.
é±å
è´è´£è·è¸ªå®èªå·±ç UTXOsã é±å
ä¸éè¦ä»»ä½ç½ç»è¿æ¥ã è¿ç§é±å
åªæå¨ä¸ç»ç«¯éä¿¡æ¶æè½æ¥æ¶(å使ç¨)èµéã
## Card pairing and management protocol å¡çé
对å管çåè®®
KATP defines only the public protocol of a KaChing wallet implemented in a smart card. A smartcard wallet will also need to support some protocol for managing the card, such initializing the master key, setting PIN and spend limits. Since that protocol typically will only be used between the card holder and their own phone, standardizing that protocol is of less concern.
KATP ä»
å®ä¹äºå¨æºè½å¡ä¸æ¤å
¥ç KaChing é±å
çå
Œ
±åè®®ã æºè½å¡é±å
è¿éè¦æ¯æä¸äºç®¡çå¡çåè®®ï¼æ¯å¦åå§å主å¯é¥ã设置 PIN åè±è´¹éå¶ã ç±äºè¯¥åè®®é常åªå¨å¡ææè
åä»ä»¬èªå·±çææºä¹é´ä½¿ç¨ï¼å æ¤å¯¹è¯¥åè®®è¿è¡æ ååå°±ä¸é£ä¹éè¦äºã
## Physical communication ç©çéä¿¡
KATP doesnât dictate any specific physical communication protocol. Any protocol that allows for the transmission of APDU packets can be used. For interoperability contactless communication using ISO/IEC 14443 A/B is recommended.
KATP ä¸è§å®ä»»ä½ç¹å®çç©çéä¿¡åè®®ã å¯ä»¥ä½¿ç¨ä»»ä½å
è®¸ä¼ è¾ APDU æ°æ®å
çåè®®ã å»ºè®®ä½¿ç¨ ISO/IEC 14443 A/B è¿è¡äºç¨æ§éæ¥è§¦éä¿¡ã
## NFC: Near-field communication NFC è¿åºéä¿¡
NFC is a set of protocols managed by the NFC Forum for contactless communication. KaChing APDU Transaction Protocol is not built on top of the NFC protocols, but a contactless wallet will make use of the same underlying protocols such as APDU and ISO/IEC 14443. A smart card implementing KATP might also implement an NFC tag to enhance the user experience.
NFCæ¯ä¸å¥ç± NFC 论å管ççéæ¥è§¦å¼éä¿¡åè®®ã Kaching APDU 交æå议并ä¸å»ºç«å¨ NFC åè®®ä¹ä¸ï¼ä½éæ¥è§¦å¼é±å
å°ä½¿ç¨ç¸åçåºå±åè®®ï¼å¦ APDU å ISO/IEC 14443 ã å®ç° KATP çæºè½å¡è¿å¯ä»¥æ¤å
¥ NFC æ ç¾ï¼ä»¥å¢å¼ºç¨æ·ä½éªã
## Android devices å®å设å¤
Android devices can be programmed to both operate as a KaChing terminal and as a wallet. An Android device with NFC support can communicate with wallets supporting ISO/IEC 14443 A or B. The communication is done using the [IsoDep interface](https://developer.android.com/reference/android/nfc/tech/IsoDep). This interface allows the transmission of APDU packages directly bypassing the NFC higher level protocols.
å®å设å¤å¯ä»¥è¢«ç¼ç¨ä¸ºæ¢æ¯ä¸ä¸ª KaChing ç»ç«¯åæ¯ä¸ä¸ªé±å
ã æ¯æ NFC ç Android 设å¤å¯ä»¥ä¸æ¯æ ISO/IEC 14443 A æ B çé±å
éä¿¡ã éä¿¡æ¯ä½¿ç¨[IsoDep æ¥å£](https://developer.android.com/reference/android/nfc/tech/IsoDep)å®æçã è¿ä¸ªæ¥å£å
许ç´æ¥ä¼ è¾ APDU å
并ç»è¿ NFC ä¸çé«çº§åè®®ã
In order to implement a wallet, [host-based card emulation is used](https://developer.android.com/guide/topics/connectivity/nfc/hce).
为äºå®ç°ä¸ä¸ªé±å
ï¼ä½¿ç¨äº[HCE: åºäºä¸»æºçå¡æ¨¡æ](https://developer.android.com/guide/topics/connectivity/nfc/hce).
The KaChing protocol can be used for phone to phone payments. This requires one of the phones to act as the terminal and the other to act as the wallet. The phone acting as terminal must have internet connection.
Kaching åè®®å¯ä»¥ç¨äºææºå¯¹ææºçæ¯ä»ã è¿éè¦ä¸é¨ææºå
å½ç»ç«¯ï¼å¦ä¸é¨å
å½é±å
ã ä½ä¸ºç»ç«¯çææºå¿
é¡»æäºèç½è¿æ¥ã
## iOS devices iOS 设å¤
As of today, third party apps are not given sufficient access to the built-in NFC of iOS devices required to implement the KaChing protocol. In order to implement a KaChing terminal on an iOS device, external hardware is required.
å°ç®å为æ¢ï¼ç¬¬ä¸æ¹åºç¨ç¨åºè¿æ²¡æè·å¾è¶³å¤çæé访é®å
ç½®ç iOS 设å¤ç NFCï¼èè¿äºè®¾å¤éè¦å®ç° KaChing åè®®ã 为äºå¨ iOS 设å¤ä¸å®ç°ä¸ä¸ª KaChing ç»ç«¯ï¼éè¦å¤é¨ç¡¬ä»¶ã
## APDU
The APDU protocol is specified in ISO/IEC 7816-4. KaChing APDU Transaction Protocol uses only a subset of this protocol. Communication is performed in command-response pairs. The command APDU is sent by the terminal. The wallet sends a response APDU back.
APDU åè®®ç± ISO/IEC 7816-4 è§å®ã Kaching APDU 交æåè®®ä»
使ç¨è¯¥åè®®çä¸ä¸ªåéã éä¿¡æ¯å¨å½ä»¤-ååºæ¶æ¯å¯¹ä¸æ§è¡çã ç»ç«¯åéå½ä»¤ APDUã é±å
ååä¸ä¸ªååº APDU ã
Note that in order to parse APDUs the length must be known.
请注æï¼ä¸ºäºè§£æ APDUsï¼å¿
é¡»ç¥éé¿åº¦ã
## Command APDU å½ä»¤APDU
The CLA bytes must always be â80â. Logical channels, command chaining and secure messaging are not used.
CLA åèå¿
é¡»å§ç»ä¸º"80"ã ä¸ä½¿ç¨é»è¾ééãå½ä»¤é¾æ¥åå®å
¨æ¶æ¯ä¼ éã
The parameter bytes P1-P2 must always be â00â.
åæ°åè P1-P2å¿
é¡»å§ç»ä¸º'00'ã
Nc is a number denoting the length of the data field in the command APDU. It is encoded in the command APDU as the field Lc.
Nc æ¯å½ä»¤ APDU ä¸è¡¨ç¤ºæ°æ®å段é¿åº¦çæ°åã å®å¨ APDU å½ä»¤ä¸è¢«ç¼ç 为å段 Lcã
Ne is a number denoting the expected maximum length of the data field in the response APDU. It is encoded in the command APDU as the field Le.
Ne æ¯ä¸ä¸ªæ°åï¼è¡¨ç¤ºååº APDU ä¸æ°æ®å段çé¢ææ大é¿åº¦ã å®å¨ APDU å½ä»¤ä¸è¢«ç¼ç 为å段 Leã
When the value of both Nc and Ne is equal to or less than 255, the encoding is simple. If the value is zero, the corresponding field is omitted in the command APDU. Any other value is encoded as a single byte.
å½ Nc å Ne çå¼é½çäºæå°äº255æ¶ï¼ç¼ç å¾ç®åã å¦æ该å¼ä¸ºé¶ï¼åå¨å½ä»¤ APDU ä¸çç¥å¯¹åºçå段ã ä»»ä½å
¶ä»å¼é½è¢«ç¼ç 为å个åèã
Itâs highly recommended to keep the value of Nc and Ne within the range 0-255. The encoding of extended length is a bit complicated and support is still missing in some libraries and smart cards.
强çå»ºè®®å° Nc å Ne çå¼ä¿æå¨0-255ä¹é´ã æ©å±é¿åº¦çç¼ç æç¹å¤æï¼å¨ä¸äºåºåæºè½å¡ä¸ä»ç¶ç¼ºä¹æ¯æã
## Response APDU ååº APDU
The response APDU consist of up to Ne bytes data followed by two status bytes denoted SW1-SW2. Status bytes â9000â indicates success.
ååº APDU ç±å¤è¾¾ Ne 个åèçæ°æ®å两个æ è¯ä¸º SW1-SW2çç¶æåèç»æã ç¶æåè"9000"表示æåã
## Limitations éå¶
KATP puts no limits on the size of transactions, the number of inputs and outputs nor the size of each input and output.
KATP 没æéå¶äº¤æç大å°ãè¾å
¥åè¾åºçæ°éï¼ä¹æ²¡æéå¶æ¯ä¸ªè¾å
¥åè¾åºç大å°ã
In practice there will be limits. It can be expected that wallets implemented as smart cards can handle transactions of at least 2000 bytes.
å®é
ä¸æ¯æé度çã å¯ä»¥é¢æï¼é±å
å®ç°ä¸ºæºè½å¡å¯ä»¥å¤çè³å°2000åèç交æã
## Transaction Session 交æä¼è¯
Before the transaction session can start the terminal must wait for:
å¨äº¤æä¼è¯å¯ä»¥å¯å¨ä¹åï¼ç»ç«¯å¿
é¡»çå¾
:
* Transfer amount 转å¸éé¢
* The wallet to be presented to the terminal å°è¢«æ交ç»ç»ç«¯çé±å
For best user experience a terminal should be prepared for these events to happen in any order.
为äºè·å¾æä½³çç¨æ·ä½éªï¼ç»ç«¯åºè¯¥ä¸ºè¿äºäºä»¶ä»¥ä»»ä½é¡ºåºåçå好åå¤ã
The session is successfully completed with the transaction being committed to the wallet and published to the blockchain. The wallet must be programmed to be fail safe in case of aborted sessions.
å½äº¤æ被æ交ç»é±å
并åå¸å°åºåé¾æ¶ï¼ä¼è¯æåå°å®æã é±å
å¿
须被设å®ä¸ºå¨ä¸æ¢ä¼è¯çæ
åµä¸æ¯æ
éå®å
¨çã
The wallet doesnât have to be aware of any dust limit policy in output amounts. If the wallet produces an output with value below dust limit, the terminal can resolve this either by retrying the transaction session with a slightly different transfer amount or by removing the problematic output. A wallet that has been programmed to be aware of current dust limits, might refuse to sign the transaction if itâs output has been modified by the terminal.
é±å
ä¸å¿
ç¥éä»»ä½ç°å°éå¶æ¿çç产éã å¦æé±å
产ççè¾åºå¼ä½äºå°åéå¶ï¼ç»ç«¯å¯ä»¥éè¿ä»¥ç¨å¾®ä¸åçä¼ è¾ééè¯äº¤æä¼è¯æ移é¤æé®é¢çè¾åºæ¥è§£å³è¿ä¸ªé®é¢ã å¦æä¸ä¸ªé±å
çè¾åºè¢«ç»ç«¯ä¿®æ¹äºï¼å®å¯è½ä¼æç»å¨äº¤æä¸ç¾åï¼å 为è¿ä¸ªé±å
å·²ç»è¢«è®¾å®ä¸ºç¥éå½åçç°å°éå¶ã
There is no support for retrying individual commands in the protocol.
ä¸æ¯æå¨åè®®ä¸éè¯å个å½ä»¤ã
## 0 Select KaChing éç¨ KaChing
Before sending any of the KATP commands the terminal should issue the SELECT command as defined in ISO/IEC 7816-4. This command has many options. In order to reduce the burden on wallet implementers it is highly recommended to only use the following options:
å¨åéä»»ä½ KATP å½ä»¤ä¹åï¼ç»ç«¯åºè¯¥ååº iso / iec 7816-4ä¸å®ä¹ç SELECT å½ä»¤ã è¿ä¸ªå½ä»¤æå¾å¤é项ã 为äºåè½»é±å
å®ç°è
çè´æ
ï¼å¼ºç建议åªä½¿ç¨ä»¥ä¸é项:
* CLA = â00â
* INS = âA4â
* P1 = â04â
* P2 = â00â
* Lc = â0Aâ
* Command data = âA0000008194B43E282BFâ
* Le = omitted (Ne = 0, no response expected)
The command data is the international AID for KATP. It consist of a two parts
å½ä»¤æ°æ®æ¯ KATP çå½é
AIDã å®ç±ä¸¤é¨åç»æï¼
* International RID = âA000000819â
* PIX = â4B43E282BFâ
Usage of this AID is subject to the conditions found in the standard document. The RID is assigned to Bitcoin.no AS by ISO.
è¿ä¸ª AID ç使ç¨åå°æ åææ¡£ä¸çæ¡ä»¶çå¶çº¦ã å½é
æ ååç»ç» ISO å°è¿ä¸ª RID åé
ç»Bitcoin.no ASã
## 1 Get Transaction Template from Wallet ä»é±å
ä¸è·å交æ模æ¿
The transaction template is in bitcoin format including version number and nLockTime.
交æ模æ¿æ¯æ¯ç¹å¸æ ¼å¼ï¼å
æ¬çæ¬å·å nLockTimeã
### Transfer amount examples 转账éé¢ç¤ºä¾
Payment of 1000 satoshis including any transaction fees. Transfer amount is 1000.
æ¯ä»1000èªï¼å
æ¬ä»»ä½äº¤æè´¹ç¨ã 转账éé¢ä¸º 1000ã
Payment of 1000 satoshis excluding any transaction fees. Transfer amount is 1000 + estimated fee.
æ¯ä»1000èªï¼ä¸å
æ¬ä»»ä½äº¤æè´¹ç¨ã 转账éé¢ä¸º 1000 + 估计æç»è´¹ã
Request to send 1000 satoshis to wallet. Transaction fee is paid by the sender. Transfer amount is -1000.
请æ±åé1000èªå°é±å
ã 交æè´¹ç±åé人æ¯ä»ã 转账éé¢ä¸º -1000ã
Request to send 1000 satoshis to wallet. Transaction fee is paid by the receiver. Transfer amount is -(1000 - estimated fee).
请æ±åé1000èªå°é±å
ã 交æè´¹ç±æ¶æ¬¾äººæ¯ä»ã 转账éé¢ä¸º -(1000-估计æç»è´¹)ã
### Fee estimation æç»è´¹ä¼°ç®
Fee estimation must be done by the terminal before any transaction data is received from the wallet. If the estimate is way off, the terminal can either try to adjust the amount in some of the outputs or retry the session with a better estimate.
å¨ä»é±å
æ¥æ¶ä»»ä½äº¤ææ°æ®ä¹åï¼æç»è´¹ç估计å¿
é¡»ç±ç»ç«¯å®æã å¦æ估计é误ï¼ç»ç«¯å¯ä»¥å°è¯è°æ´æäºè¾åºä¸çæ°éï¼æè
ç¨æ´å¥½ç估计éè¯ä¼è¯ã
### PIN å£ä»¤å¯ç
PIN is optional. Some cards might require PIN only after a certain amount has been spent. When one of the PIN required status bytes is returned, the terminal must prompt the user for the PIN and retry the session. The PIN code can be any Unicode string, but a terminal will typically only allow entry of the digits 0-9.
PINç æ¯å¯éçã æäºå¡å¯è½éè¦å¯ç åï¼ææä¸å®çéé¢å·²è±è´¹ã å½è¿åä¸ä¸ªæéç PIN ç¶æåèæ¶ï¼ç»ç«¯å¿
é¡»æ示ç¨æ·è¾å
¥ PIN 并éè¯ä¼è¯ã Pin ç å¯ä»¥æ¯ä»»ä½ Unicode å符串ï¼ä½ç»ç«¯é常åªå
许è¾å
¥æ°å0-9ã
When using contactless cards, the card holder might have to tap the card twice. Once to get prompted for the PIN entry and once more to complete the transaction.
å½ä½¿ç¨éæ¥è§¦å¼å¡çæ¶ï¼å¡çææè
å¯è½éè¦ç¹å»å¡ç两次ã ä¸æ¬¡è·å¾æ示è¾å
¥ PINï¼åä¸æ¬¡å®æ交æã
### Chunked Response ååååº
If the transaction template returned from the wallet doesnât fit into a single response, it will be split into chunks. The terminal retrieves more data by reissuing the command with empty command data. The terminal must support basic transaction parsing in order to determine if the complete transaction has been received.
å¦æé±å
ä¸è¿åç交æ模æ¿ä¸éåå个ååºï¼é£ä¹å®å°è¢«æå为å¤ä¸ªåã ç»ç«¯éè¿ä½¿ç¨ç©ºå½ä»¤æ°æ®éæ°ååºå½ä»¤æ¥æ£ç´¢æ´å¤çæ°æ®ã ç»ç«¯å¿
é¡»æ¯æåºæ¬äº¤æ解æï¼ä»¥ç¡®å®æ¯å¦å·²ç»æ¥æ¶å°å®æ´ç交æã
## 2 Get Public Meta-Key from Wallet ä»é±å
è·åå
Œ
±å
å¯é¥
One intended usage of the public meta-key is for the terminal to embed a receipt into the transaction. The receipt is encrypted using the public meta-key and embedded in an OP\_RETURN out of the transaction. If a receipt is too big to fit into the current transaction, an encrypted link can be embedded instead, e.g. using [b://](https://b.bitdb.network/) or [c://](https://c.bitdb.network/) protocols.
å
Œ
±å
å¯é¥çä¸ä¸ªé¢æç¨éæ¯ç¨äºç»ç«¯å°æ¶æ®åµå
¥å°äº¤æä¸ã æ¶æ®ä½¿ç¨å
Œ
±å
å¯é¥è¿è¡å å¯ï¼å¹¶åµå
¥å°äº¤æä¹å¤ç OP\_RETURNä¸ã å¦ææ¶æ®å¤ªå¤§èæ æ³æ¾å
¥å½å交æï¼åå¯ä»¥åµå
¥å å¯åçæ¶æ®é¾æ¥ï¼ä¾å¦ä½¿ç¨ b: // æ c: // åè®®ã
The rationale for this is to allow the user of a smart card, with limited storage, to get a receipt for all purchases. The card holder has paired the card with an app on their smartphone. The app watches the blockchain for transactions signed by the card. The app also has the master key used by the card to derive the public meta-keys. This allows the app to show the purchase including receipt immediately after the card has been used.
è¿æ ·åçåºæ¬åçæ¯å
许æºè½å¡çç¨æ·å¨æéçåå¨ç©ºé´å
è·å¾ææè´ä¹°çæ¶æ®ã æå¡äººå·²ç»å°å¡çä¸æºè½ææºä¸çåºç¨ç¨åºé
对ã 该åºç¨ç¨åºçè§åºåé¾ä¸ç±å¡çç¾ç½²ç交æã 该åºç¨ç¨åºè¿æå¡ç使ç¨ç主å¯é¥ï¼ä»¥æ¨å¯¼å
Œ
±å
å¯é¥ã è¿ä½¿å¾å¡ç被使ç¨ä¹åï¼åºç¨ç¨åºç«å³æ¾ç¤ºè´ä¹°è®°å½åæ¶æ®ã
## 3 Write Transaction to Wallet å°äº¤æåå
¥é±å
The terminal completes the transaction by adding its own inputs and outputs to the template retrieved from the wallet. The terminal is encouraged to shuffle the order of inputs and outputs to enhance privacy.
ç»ç«¯éè¿å°èªå·±çè¾å
¥åè¾åºæ·»å å°ä»é±å
æ£ç´¢ç模æ¿ä¸æ¥å®æ交æã 该ç»ç«¯æ¯é¼å±éæºå交æè¾å
¥åè¾åºç顺åºï¼ä»¥æé«éç§ã
## 4 Get Signatures from Wallet ä»é±å
ä¸è·åç¾å
The terminal might have modified the outputs of the transaction template returned by the wallet. Any spend limit checks must be redone, potentially triggering PIN requirement at this stage.
ç»ç«¯å¯è½å·²ç»ä¿®æ¹äºé±å
è¿åç交æ模æ¿çè¾åºã ä»»ä½è±è´¹éå¶æ£æ¥å¿
é¡»éåï¼å¨è¿ä¸ªé¶æ®µå¯è½è§¦å PIN è¦æ±ã
## 5 Get Transaction Hash from Wallet ä»é±å
ä¸è·å交æåå¸å¼
At this stage both the terminal and wallet has a copy of the complete transaction. The terminal should compare the hash calculated by the wallet with its own.
å¨è¿ä¸ªé¶æ®µï¼ç»ç«¯åé±å
é½æå®æ´äº¤æçä¸ä»½å¯æ¬ã ç»ç«¯åºè¯¥å°é±å
计ç®çåå¸æ£åå¼ä¸å®èªå·±çæ£åå¼è¿è¡æ¯è¾ã
A wallet implemented in a smart card should do any time consuming housekeeping at this stage.
å¨æºè½å¡ä¸å®ç°çé±å
åºè¯¥å¨è¿ä¸ªé¶æ®µåä»»ä½æ¶èæ¶é´çæ´çå·¥ä½ã
## 6 Commit Transaction to Wallet å°äº¤ææ交ç»é±å
The commit step is the only command where communication failure can result in the wallet becoming out of sync with the blockchain.
æ交æ¥éª¤æ¯å¯ä¸ä¸ä¸ªå¯å éä¿¡æ
éï¼å¯¼è´é±å
ä¸åºåé¾å¤±å»åæ¥çæ¥éª¤ã
When processing the commit command, the wallet must do as little processing as possible. In practice this means that the next wallet state must be fully prepared and saved into persisted memory during the processing of the previous command. The terminal must never issue the commit command more than once. Adding checks in the wallet to protect against a misbehaving terminal is likely to be counterproductive. It adds complexity to the wallet, with more things that can go wrong.
å¨å¤çæ交å½ä»¤æ¶ï¼é±å
å¿
须尽å¯è½å°è¿è¡å¤çã å¨å®è·µä¸ï¼è¿æå³çä¸ä¸ä¸ªé±å
ç¶æå¿
须被å®å
¨åå¤å¥½ï¼å¹¶å¨å¤çåä¸ä¸ªå½ä»¤æé´ä¿åå°æä¹
å
åä¸ã ç»ç«¯ç»ä¸è½å¤æ¬¡ååºæ交å½ä»¤ã å¨é±å
ä¸æ·»å æ£æ¥ä»¥é²æ¢ç»ç«¯è¡ä¸ºä¸å½å¯è½ä¼éå¾å
¶åãè¿ä¼å¢å é±å
çå¤ææ§ï¼å¹¶ä¸ä¼ææ´å¤çäºæ
å¯è½åºéã
Only the terminal should publish the transaction. If the terminal doesnât receive a successful response from the wallet it assumes the transaction failed. No payment has been made, the customer will not receive any goods or services.
åªæç»ç«¯åºè¯¥åå¸äº¤æã å¦æç»ç«¯æ²¡æä»é±å
æ¶å°æåçååºï¼é£ä¹å®å°±è®¤ä¸ºäº¤æ失败äºã ä»æ¬¾æ²¡æåçï¼å®¢æ·å°ä¸ä¼æ¶å°ä»»ä½è´§ç©ææå¡ã
In the worst case the wallet can end up with some transaction in its UTXO set thatâs never been published to the blockchain. An online wallet can resolve this by timing out the missing transaction. How fast the transaction is timed out should depend on how confident the wallet is that the transaction hasnât been published. A highly confident wallet can time out the transaction within a few seconds.
å¨æåçæ
åµä¸ï¼é±å
çUTXOéåä¸ä¼å©ä¸ä¸äºä»æªè¢«åå¸å°åºåé¾ç交æã ä¸ä¸ªå¨çº¿é±å
å¯ä»¥éè¿è¶
æ¶ä¸¢å¤±ç交ææ¥è§£å³è¿ä¸ªé®é¢ã 交æè¶
æ¶çé度åºè¯¥åå³äºé±å
对交ææªè¢«å
¬å¸çä¿¡å¿ç¨åº¦ã ä¸ä¸ªé«åº¦èªä¿¡çé±å
å¯ä»¥å¨å ç§éå
å°äº¤æ设为è¶
æ¶ã
è¯è
ï¼wer5lcy
text/markdownUTF-8LMKaChing APDU Transaction Protocol Explained (Simplified Chinese Translation) | Çã$&zرÌ?èÚlØQ:ó-Æò[@â´9·ðbitpastembtip462 prerender
https://whatsonchain.com/tx/82a2522c836a9acd84953f8b3cfca279fa943ed407c2162c46c77938f70a03d7