Skip to content

Commit fedd203

Browse files
committed
init
0 parents  commit fedd203

File tree

7 files changed

+317
-0
lines changed

7 files changed

+317
-0
lines changed

.gitignore

Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
# Byte-compiled / optimized / DLL files
2+
__pycache__/
3+
*.py[cod]
4+
*$py.class
5+
6+
# C extensions
7+
*.so
8+
9+
# Distribution / packaging
10+
.Python
11+
.idea
12+
build/
13+
develop-eggs/
14+
dist/
15+
downloads/
16+
eggs/
17+
.eggs/
18+
lib/
19+
lib64/
20+
parts/
21+
sdist/
22+
var/
23+
wheels/
24+
pip-wheel-metadata/
25+
share/python-wheels/
26+
*.egg-info/
27+
.installed.cfg
28+
*.egg
29+
MANIFEST
30+
31+
# PyInstaller
32+
# Usually these files are written by a python script from a template
33+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
34+
*.manifest
35+
*.spec
36+
37+
# Installer logs
38+
pip-log.txt
39+
pip-delete-this-directory.txt
40+
41+
# Unit test / coverage reports
42+
htmlcov/
43+
.tox/
44+
.nox/
45+
.coverage
46+
.coverage.*
47+
.cache
48+
nosetests.xml
49+
coverage.xml
50+
*.cover
51+
*.py,cover
52+
.hypothesis/
53+
.pytest_cache/
54+
55+
# Translations
56+
*.mo
57+
*.pot
58+
59+
# Django stuff:
60+
*.log
61+
local_settings.py
62+
db.sqlite3
63+
db.sqlite3-journal
64+
65+
# Flask stuff:
66+
instance/
67+
.webassets-cache
68+
69+
# Scrapy stuff:
70+
.scrapy
71+
72+
# Sphinx documentation
73+
docs/_build/
74+
75+
# PyBuilder
76+
target/
77+
78+
# Jupyter Notebook
79+
.ipynb_checkpoints
80+
81+
# IPython
82+
profile_default/
83+
ipython_config.py
84+
85+
# pyenv
86+
.python-version
87+
88+
# pipenv
89+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
90+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
91+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
92+
# install all needed dependencies.
93+
#Pipfile.lock
94+
95+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow
96+
__pypackages__/
97+
98+
# Celery stuff
99+
celerybeat-schedule
100+
celerybeat.pid
101+
102+
# SageMath parsed files
103+
*.sage.py
104+
105+
# Environments
106+
.env
107+
.venv
108+
env/
109+
venv/
110+
ENV/
111+
env.bak/
112+
venv.bak/
113+
114+
# Spyder project settings
115+
.spyderproject
116+
.spyproject
117+
118+
# Rope project settings
119+
.ropeproject
120+
121+
# mkdocs documentation
122+
/site
123+
124+
# mypy
125+
.mypy_cache/
126+
.dmypy.json
127+
dmypy.json
128+
129+
# Pyre type checker
130+
.pyre/
131+
132+
#venv
133+
134+
ar_wallet.json
135+
*.pdf
136+
137+
everpay_venv

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2021 everFinance
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# everpay.py
2+
3+
Python sdk for [arseeding] (https://github.com/everFinance/arseeding).
4+
5+
Install with
6+
7+
```
8+
pip install arseeding
9+
```
10+
11+
12+
- Quick start
13+
14+
upload python.pdf to arweave using arseeding
15+
16+
```python
17+
18+
import arseeding, everpay
19+
# ar account
20+
signer = everpay.ARSigner('ar_wallet.json')
21+
data = open('game.py', 'rb').read()
22+
o = arseeding.send_and_pay(signer, 'usdc', data)
23+
print(o)
24+
25+
```

arseeding/__init__.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import requests, json
2+
import everpay
3+
from .bundleitem import BundleItem
4+
5+
arseed_url = 'https://arseed.web3infura.io'
6+
pay_url = 'https://api.everpay.io'
7+
def send_and_pay(signer, currency, data, target='', anchor='', tags=[], arseed_url=arseed_url):
8+
if data == type(''):
9+
data = data.encode()
10+
11+
b = BundleItem(signer, target, anchor, tags, data)
12+
url = "%s/bundle/tx/%s"%(arseed_url, currency)
13+
res = requests.post(url=url,
14+
data=b.binary,
15+
headers={'Content-Type': 'application/octet-stream'}
16+
)
17+
18+
if res.status_code == 200:
19+
order = res.json()
20+
21+
account = everpay.Account(pay_url, signer)
22+
account.transfer(currency, order['bundler'], int(order['fee']), data=json.dumps(order))
23+
24+
return order
25+

arseeding/bundleitem.py

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
import hashlib
2+
from arweave import deep_hash
3+
from jose.utils import base64url_decode, base64url_encode
4+
from .tags import serialize_tags
5+
6+
sig_conf = {
7+
'ar': {
8+
'signature_type': 1,
9+
'sig_length': 512,
10+
'pub_length': 512,
11+
'sig_name': 'arweave'
12+
}
13+
}
14+
15+
class BundleItem:
16+
def __init__(self, signer, target, anchor, tags, data):
17+
self.signer = signer
18+
self.signature_type = sig_conf[signer.type.lower()]['signature_type']
19+
self.owner = signer.owner
20+
self.target = target
21+
self.anchor = anchor
22+
self.tags = tags
23+
self.data = data
24+
self.sign()
25+
self.binary = self.get_item_binary()
26+
27+
def get_data_to_sign(self):
28+
datalist = [
29+
b'dataitem',
30+
b'1',
31+
str(self.signature_type).encode(),
32+
base64url_decode(self.signer.owner.encode()),
33+
#self.target.encode(),
34+
#self.anchor.encode(),
35+
#serialize_tags(self.tags),
36+
b'',
37+
b'',
38+
b'',
39+
self.data
40+
]
41+
return deep_hash.deep_hash(datalist)
42+
43+
def sign(self):
44+
data = self.get_data_to_sign()
45+
if self.signer.type == 'AR':
46+
sig = self.signer.wallet.sign(data)
47+
self.id = base64url_encode(hashlib.sha256(sig).digest()).decode()
48+
self.signature = base64url_encode(sig).decode()
49+
50+
def get_item_binary(self):
51+
if not self.id or not self.signature:
52+
raise ValueError("no signature")
53+
st = self.signature_type.to_bytes(2, byteorder='little')
54+
sig = base64url_decode(self.signature.encode())
55+
owner = base64url_decode(self.signer.owner.encode())
56+
data = self.data
57+
return st+sig+owner+b"\x00\x00"+(0).to_bytes(8, byteorder='little') +(0).to_bytes(8, byteorder='little')+data

arseeding/tags.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import io
2+
from fastavro import schemaless_writer, schemaless_reader, parse_schema
3+
4+
schema = {
5+
"type": "array",
6+
"items": {
7+
"type": "record",
8+
"name": "Tag",
9+
"fields": [
10+
{"name": "name", "type": "string"},
11+
{"name": "value", "type": "string"}
12+
]
13+
}
14+
}
15+
16+
parsed_schema = parse_schema(schema)
17+
18+
def serialize_tags(tags):
19+
if len(tags) == 0:
20+
return
21+
fo = io.BytesIO()
22+
schemaless_writer(fo, parsed_schema, tags)
23+
return fo.getvalue()
24+
25+
def deserialize_tags(tags_serialized):
26+
tags = []
27+
fo = io.BytesIO(tags_serialized)
28+
for tag in schemaless_reader(fo, parsed_schema):
29+
tags.append(tag)
30+
return tags

setup.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import setuptools
2+
3+
setuptools.setup(
4+
name='arseeding',
5+
version='0.0.1',
6+
packages=['arseeding',],
7+
license='MIT',
8+
description = 'Python sdk for arseeding',
9+
long_description=open('README.md').read(),
10+
long_description_content_type="text/markdown",
11+
author = 'xiaojay',
12+
author_email = '[email protected]',
13+
install_requires=['everpay', 'requests', 'web3', 'python-jose', 'arweave-python-client', 'eth_account', 'fastavro'],
14+
url = 'https://github.com/everFinance/arseeding.py',
15+
download_url = 'https://github.com/everFinance/arseeding.py/archive/refs/tags/v0.0.1.tar.gz',
16+
classifiers=[
17+
"Programming Language :: Python :: 3",
18+
"Programming Language :: Python :: 2",
19+
"License :: OSI Approved :: MIT License",
20+
"Operating System :: OS Independent",
21+
],
22+
)

0 commit comments

Comments
 (0)