This repository has been archived by the owner on Jul 3, 2022. It is now read-only.
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
Showing
3 changed files
with
43 additions
and
1 deletion.
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 |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import hashlib,base64 | ||
|
||
def checksum(string): | ||
#return base64.urlsafe_b64encode(string.encode("utf-8")).decode("utf-8")[:8] | ||
m = hashlib.md5() | ||
m.update(string.encode("utf-8")) | ||
return m.hexdigest()[:8] | ||
|
||
|
||
def create_url(command, address, recipient, amount, openfield): | ||
if command == "pay": | ||
openfield_b64_encode = (base64.urlsafe_b64encode(openfield.encode("utf-8"))).decode("utf-8") | ||
print (openfield_b64_encode) | ||
|
||
url_output = "bis://{}/{}/{}/{}/{}/".format(command,address,recipient,amount,openfield_b64_encode) | ||
return url_output+checksum(url_output) | ||
|
||
|
||
def read_url(url): | ||
url_split = url.split("/") | ||
#print(url_split) | ||
|
||
|
||
reconstruct = "bis://{}/{}/{}/{}/{}/".format(url_split[2],url_split[3],url_split[4],url_split[5],url_split[6]) | ||
openfield_b64_decode = base64.urlsafe_b64decode(url_split[6]).decode("utf-8") | ||
|
||
if checksum(reconstruct) == url_split[7]: | ||
print ("Checksum match") | ||
return url_split[2],url_split[3],url_split[4],url_split[5],openfield_b64_decode | ||
else: | ||
print ("Checksum mismatch",checksum(reconstruct),url_split[7]) | ||
return | ||
|
||
print ("create_url", create_url ("pay", "address", "recipient", "10", "eeeeeeeeeasdasdasdasdasdeeeeeeeeeeee")) | ||
print ("read_url", read_url("bis://pay/address/recipient/10/ZWVlZWVlZWVlYXNkYXNkYXNkYXNkYXNkZWVlZWVlZWVlZWVl/7bfd1630")) |
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 |
---|---|---|
|
@@ -73,3 +73,4 @@ | |
('91.92.136.121', '5658') | ||
('78.46.74.182', '5658') | ||
('127.0.0.1', '5658') | ||
('146.199.65.231', '5658') |
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
7db0c82
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See Ascii85 instead of b64 safe url encode and checksum encode. Less size for the same bin counterpart.
z85 is great but includes the "/" char
https://en.wikipedia.org/wiki/Ascii85
rfc1924 version excludes / " and ' , it's safe for url and json.
Conversion from/to ascii85 variants fit in a few python lines.
7db0c82
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you have the library? https://docs.python.org/3/library/base64.html#base64.a85encode produces quite url-unfriendly results
7db0c82
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, will check tomorrow. There are several variations on ascii85, only the rfc1924 one is url/json safe.
7db0c82
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here is a gist with a custom alphabet:
https://gist.github.com/EggPool/98ffb4db24c3b8b3309f71ad99fe4782
7db0c82
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
btw, the url would be
bis://pay/recipient/10/ZWVlZWVlZWVlYXNkYXNkYXNkYXNkYXNkZWVlZWVlZWVlZWVl/7bfd1630
rather than
bis://pay/address/recipient/10/ZWVlZWVlZWVlYXNkYXNkYXNkYXNkYXNkZWVlZWVlZWVlZWVl/7bfd1630
It's to be used in the wallet, and will use the wallet address as source, not a fixed one.
So the same "link" can be used as a static payment/donation link posted anywhere.
including the source address in it makes it too specific.
7db0c82
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, I will limit it. Added some comments to https://gist.github.com/EggPool/98ffb4db24c3b8b3309f71ad99fe4782