forked from klever-io/trx-ledger
-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
231a712
commit a642082
Showing
59 changed files
with
1,107 additions
and
449 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,43 @@ | ||
import struct | ||
|
||
|
||
def parse_bip32_path(path): | ||
if len(path) == 0: | ||
return "" | ||
result = "" | ||
elements = path.split('/') | ||
for pathElement in elements: | ||
element = pathElement.split('\'') | ||
if len(element) == 1: | ||
result = result + struct.pack(">I", int(element[0])).hex() | ||
else: | ||
result = result + struct.pack(">I", 0x80000000 | int(element[0])).hex() | ||
return result | ||
if len(path) == 0: | ||
return "" | ||
result = "" | ||
elements = path.split('/') | ||
for pathElement in elements: | ||
element = pathElement.split('\'') | ||
if len(element) == 1: | ||
result = result + struct.pack(">I", int(element[0])).hex() | ||
else: | ||
result = result + struct.pack(">I", | ||
0x80000000 | int(element[0])).hex() | ||
return result | ||
|
||
|
||
def parse_bip32_path_to_bytes(path): | ||
if len(path) == 0: | ||
return b"" | ||
result = b"" | ||
elements = path.split('/') | ||
for pathElement in elements: | ||
element = pathElement.split('\'') | ||
if len(element) == 1: | ||
result = result + struct.pack(">I", int(element[0])) | ||
else: | ||
result = result + struct.pack(">I", 0x80000000 | int(element[0])) | ||
return result | ||
|
||
|
||
def apduMessage(INS, P1, P2, PATH, MESSAGE): | ||
hexString = "" | ||
if PATH: | ||
hexString = "E0{:02x}{:02x}{:02x}{:02x}{:02x}{}".format( | ||
INS, P1, P2, (len(PATH) + len(MESSAGE)) // 2 + 1, | ||
len(PATH) // 4 // 2, PATH + MESSAGE) | ||
else: | ||
hexString = "E0{:02x}{:02x}{:02x}{:02x}{}".format( | ||
INS, P1, P2, | ||
len(MESSAGE) // 2, MESSAGE) | ||
return bytearray.fromhex(hexString) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.