Skip to content
This repository was archived by the owner on Oct 16, 2024. It is now read-only.

Commit 84578ea

Browse files
committed
Support stream output logic
1 parent 66e0945 commit 84578ea

File tree

2 files changed

+25
-8
lines changed

2 files changed

+25
-8
lines changed

btchip/btchip.py

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,15 @@ def __init__(self, dongle):
7979
self.dongle = dongle
8080
self.needKeyCache = False
8181
try:
82+
firmware = self.getFirmwareVersion()['version'].split(".")
83+
self.multiOutputSupported = int(firmware[0]) >= 1 and int(firmware[1]) >= 1 and int(firmware[2]) >= 4
84+
if self.multiOutputSupported:
85+
self.scriptBlockLength = 50
86+
else:
87+
self.scriptBlockLength = 255
88+
except:
89+
pass
90+
try:
8291
result = self.getJCExtendedFeatures()
8392
self.needKeyCache = (result['proprietaryApi'] == False)
8493
except:
@@ -264,12 +273,20 @@ def finalizeInput(self, outputAddress, amount, fees, changePath, rawTx=None):
264273
apdu.append(len(params))
265274
apdu.extend(params)
266275
response = self.dongle.exchange(bytearray(apdu))
267-
apdu = [ self.BTCHIP_CLA, self.BTCHIP_INS_HASH_INPUT_FINALIZE_FULL, 0x80, 0x00 ]
268-
params = []
269-
params.extend(outputs)
270-
apdu.append(len(params))
271-
apdu.extend(params)
272-
response = self.dongle.exchange(bytearray(apdu))
276+
offset = 0
277+
while (offset < len(outputs)):
278+
blockLength = self.scriptBlockLength
279+
if ((offset + blockLength) < len(outputs)):
280+
dataLength = blockLength
281+
p1 = 0x00
282+
else:
283+
dataLength = len(outputs) - offset
284+
p1 = 0x80
285+
apdu = [ self.BTCHIP_CLA, self.BTCHIP_INS_HASH_INPUT_FINALIZE_FULL, \
286+
p1, 0x00, dataLength ]
287+
apdu.extend(outputs[offset : offset + dataLength])
288+
response = self.dongle.exchange(bytearray(apdu))
289+
offset += dataLength
273290
alternateEncoding = True
274291
except:
275292
pass
@@ -310,7 +327,7 @@ def finalizeInputFull(self, outputData):
310327
offset = 0
311328
encryptedOutputData = ""
312329
while (offset < len(outputData)):
313-
blockLength = 255
330+
blockLength = self.scriptBlockLength
314331
if ((offset + blockLength) < len(outputData)):
315332
dataLength = blockLength
316333
p1 = 0x00

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
here = dirname(__file__)
88
setup(
99
name='btchip-python',
10-
version='0.1.18',
10+
version='0.1.19',
1111
author='BTChip',
1212
author_email='[email protected]',
1313
description='Python library to communicate with Ledger Nano dongle',

0 commit comments

Comments
 (0)