How to use the ledgerblue.ledgerWrapper.wrapCommandAPDU function in ledgerblue

To help you get started, we’ve selected a few ledgerblue examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github LedgerHQ / blue-loader-python / ledgerblue / comm.py View on Github external
def exchange(self, apdu, timeout=TIMEOUT):
		if APDUGEN:
			print("%s" % hexstr(apdu))
			return

		if self.debug:
			print("HID => %s" % hexstr(apdu))
		if self.ledger:
			apdu = wrapCommandAPDU(0x0101, apdu, 64)		
		padSize = len(apdu) % 64
		tmp = apdu
		if padSize != 0:
			tmp.extend([0] * (64 - padSize))
		offset = 0
		while(offset != len(tmp)):
			data = tmp[offset:offset + 64]
			data = bytearray([0]) + data
			if self.device.write(data) < 0:
				raise BaseException("Error while writing")
			offset += 64
		dataLength = 0
		dataStart = 2		
		result = self.waitImpl.waitFirstResponse(timeout)
		if not self.ledger:
			if result[0] == 0x61: # 61xx : data available
github LedgerHQ / blue-loader-python / experimental / bluepy / commBLE.py View on Github external
def exchange(self, apdu, timeout=20000):
		if self.debug:
			print("=> %s" % hexlify(apdu))
		apdu = wrapCommandAPDU(0, apdu, DEFAULT_BLE_CHUNK, True)		
		offset = 0
		while(offset < len(apdu)):			
			data = apdu[offset:offset + DEFAULT_BLE_CHUNK]
			self.writeCharacteristic.write(data, withResponse=True)
			offset += DEFAULT_BLE_CHUNK
			self.result = ""
		while True:
			if not self.device.waitForNotifications(BLE_NOTIFICATION_TIMEOUT):
				raise CommException("Timeout")
			response = unwrapResponseAPDU(0, self.result, DEFAULT_BLE_CHUNK, True)
			if response is not None:
				result = response
				dataStart = 0
				swOffset = len(response) - 2
				dataLength = len(response) - 2
				break