Skip to content
This repository has been archived by the owner on Jul 3, 2022. It is now read-only.

Commit

Permalink
add url verification proposal
Browse files Browse the repository at this point in the history
  • Loading branch information
hclivess committed Feb 17, 2018
1 parent cf20f1d commit 7db0c82
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 1 deletion.
35 changes: 35 additions & 0 deletions bisurl.py
@@ -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"))
1 change: 1 addition & 0 deletions suggested_peers.txt
Expand Up @@ -73,3 +73,4 @@
('91.92.136.121', '5658')
('78.46.74.182', '5658')
('127.0.0.1', '5658')
('146.199.65.231', '5658')
8 changes: 7 additions & 1 deletion wallet.py
Expand Up @@ -3,6 +3,7 @@
import PIL.Image, PIL.ImageTk, pyqrcode, os, hashlib, time, base64, connections, icons, log, socks, ast, options, tarfile, glob, essentials, re
from tokens import *
from decimal import *
from bisurl import *

getcontext().prec = 8 # decimal places
print(getcontext())
Expand Down Expand Up @@ -45,7 +46,6 @@
s = socks.socksocket()
s.settimeout(3)


def node_connect():
while True:
try:
Expand Down Expand Up @@ -1083,6 +1083,12 @@ def hello():
tokens_b = Button(f5, text="Tokens", command=tokens, height=1, width=10, font=("Tahoma", 8))
tokens_b.grid(row=button_row_zero+7, column=0, sticky=W + E + S, pady=0, padx=15)

create_url_b = Button(f5, text="Create URL", command=lambda: create_url("pay",myaddress,recipient.get(),amount.get(),openfield.get("1.0", END).strip()), height=1, width=10, font=("Tahoma", 8))
create_url_b.grid(row=button_row_zero+8, column=0, sticky=W + E + S, pady=0, padx=15)

read_url_b = Button(f5, text="Read URL", command=lambda: read_url(url.get()), height=1, width=10, font=("Tahoma", 8))
read_url_b.grid(row=button_row_zero+9, column=0, sticky=W + E + S, pady=0, padx=15)

#quit_b = Button(f5, text="Quit", command=app_quit, height=1, width=10, font=("Tahoma", 8))
#quit_b.grid(row=16, column=0, sticky=W + E + S, pady=0, padx=15)

Expand Down

6 comments on commit 7db0c82

@EggPool
Copy link
Contributor

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.

@hclivess
Copy link
Owner Author

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

@EggPool
Copy link
Contributor

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.

@EggPool
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@EggPool
Copy link
Contributor

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.

@hclivess
Copy link
Owner Author

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

Please sign in to comment.