From e368782b4c4de238e4994fc2346a2a1870ed5e61 Mon Sep 17 00:00:00 2001 From: Toporin Date: Thu, 30 Nov 2023 21:25:01 +0100 Subject: [PATCH] Satochip: Patch error 0x9C01 in cardBip32GetExtendedKey() This error occurs when the cache memory in the card is full. We need to flush the cache by sending the same command with the p2 flag set to 0x80. --- .../sparrow/io/satochip/SatochipCommandSet.java | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/sparrowwallet/sparrow/io/satochip/SatochipCommandSet.java b/src/main/java/com/sparrowwallet/sparrow/io/satochip/SatochipCommandSet.java index 32ba3464..de71b210 100644 --- a/src/main/java/com/sparrowwallet/sparrow/io/satochip/SatochipCommandSet.java +++ b/src/main/java/com/sparrowwallet/sparrow/io/satochip/SatochipCommandSet.java @@ -347,8 +347,14 @@ public class SatochipCommandSet { public APDUResponse cardBip32GetExtendedKey(byte[] bytePath) { byte p1 = (byte) (bytePath.length / 4); - APDUCommand plainApdu = new APDUCommand(0xB0, INS_BIP32_GET_EXTENDED_KEY, p1, 0x40, bytePath); - return this.cardTransmit(plainApdu); + APDUCommand capdu = new APDUCommand(0xB0, INS_BIP32_GET_EXTENDED_KEY, p1, 0x40, bytePath); + APDUResponse rapdu = this.cardTransmit(capdu); + if(rapdu.getSw() == 0x9C01) { + // error 0X9C01: no memory available for key derivation => flush memory cache in card + capdu = new APDUCommand(0xB0, INS_BIP32_GET_EXTENDED_KEY, p1, 0x80, bytePath); + rapdu = this.cardTransmit(capdu); + } + return rapdu; } /*