Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaojay committed Jul 20, 2022
0 parents commit fedd203
Show file tree
Hide file tree
Showing 7 changed files with 317 additions and 0 deletions.
137 changes: 137 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
.idea
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
pip-wheel-metadata/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
target/

# Jupyter Notebook
.ipynb_checkpoints

# IPython
profile_default/
ipython_config.py

# pyenv
.python-version

# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock

# PEP 582; used by e.g. github.com/David-OConnor/pyflow
__pypackages__/

# Celery stuff
celerybeat-schedule
celerybeat.pid

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
.dmypy.json
dmypy.json

# Pyre type checker
.pyre/

#venv

ar_wallet.json
*.pdf

everpay_venv
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2021 everFinance

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
25 changes: 25 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# everpay.py

Python sdk for [arseeding] (https://github.com/everFinance/arseeding).

Install with

```
pip install arseeding
```


- Quick start

upload python.pdf to arweave using arseeding

```python

import arseeding, everpay
# ar account
signer = everpay.ARSigner('ar_wallet.json')
data = open('game.py', 'rb').read()
o = arseeding.send_and_pay(signer, 'usdc', data)
print(o)

```
25 changes: 25 additions & 0 deletions arseeding/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import requests, json
import everpay
from .bundleitem import BundleItem

arseed_url = 'https://arseed.web3infura.io'
pay_url = 'https://api.everpay.io'
def send_and_pay(signer, currency, data, target='', anchor='', tags=[], arseed_url=arseed_url):
if data == type(''):
data = data.encode()

b = BundleItem(signer, target, anchor, tags, data)
url = "%s/bundle/tx/%s"%(arseed_url, currency)
res = requests.post(url=url,
data=b.binary,
headers={'Content-Type': 'application/octet-stream'}
)

if res.status_code == 200:
order = res.json()

account = everpay.Account(pay_url, signer)
account.transfer(currency, order['bundler'], int(order['fee']), data=json.dumps(order))

return order

57 changes: 57 additions & 0 deletions arseeding/bundleitem.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import hashlib
from arweave import deep_hash
from jose.utils import base64url_decode, base64url_encode
from .tags import serialize_tags

sig_conf = {
'ar': {
'signature_type': 1,
'sig_length': 512,
'pub_length': 512,
'sig_name': 'arweave'
}
}

class BundleItem:
def __init__(self, signer, target, anchor, tags, data):
self.signer = signer
self.signature_type = sig_conf[signer.type.lower()]['signature_type']
self.owner = signer.owner
self.target = target
self.anchor = anchor
self.tags = tags
self.data = data
self.sign()
self.binary = self.get_item_binary()

def get_data_to_sign(self):
datalist = [
b'dataitem',
b'1',
str(self.signature_type).encode(),
base64url_decode(self.signer.owner.encode()),
#self.target.encode(),
#self.anchor.encode(),
#serialize_tags(self.tags),
b'',
b'',
b'',
self.data
]
return deep_hash.deep_hash(datalist)

def sign(self):
data = self.get_data_to_sign()
if self.signer.type == 'AR':
sig = self.signer.wallet.sign(data)
self.id = base64url_encode(hashlib.sha256(sig).digest()).decode()
self.signature = base64url_encode(sig).decode()

def get_item_binary(self):
if not self.id or not self.signature:
raise ValueError("no signature")
st = self.signature_type.to_bytes(2, byteorder='little')
sig = base64url_decode(self.signature.encode())
owner = base64url_decode(self.signer.owner.encode())
data = self.data
return st+sig+owner+b"\x00\x00"+(0).to_bytes(8, byteorder='little') +(0).to_bytes(8, byteorder='little')+data
30 changes: 30 additions & 0 deletions arseeding/tags.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import io
from fastavro import schemaless_writer, schemaless_reader, parse_schema

schema = {
"type": "array",
"items": {
"type": "record",
"name": "Tag",
"fields": [
{"name": "name", "type": "string"},
{"name": "value", "type": "string"}
]
}
}

parsed_schema = parse_schema(schema)

def serialize_tags(tags):
if len(tags) == 0:
return
fo = io.BytesIO()
schemaless_writer(fo, parsed_schema, tags)
return fo.getvalue()

def deserialize_tags(tags_serialized):
tags = []
fo = io.BytesIO(tags_serialized)
for tag in schemaless_reader(fo, parsed_schema):
tags.append(tag)
return tags
22 changes: 22 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import setuptools

setuptools.setup(
name='arseeding',
version='0.0.1',
packages=['arseeding',],
license='MIT',
description = 'Python sdk for arseeding',
long_description=open('README.md').read(),
long_description_content_type="text/markdown",
author = 'xiaojay',
author_email = '[email protected]',
install_requires=['everpay', 'requests', 'web3', 'python-jose', 'arweave-python-client', 'eth_account', 'fastavro'],
url = 'https://github.com/everFinance/arseeding.py',
download_url = 'https://github.com/everFinance/arseeding.py/archive/refs/tags/v0.0.1.tar.gz',
classifiers=[
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 2",
"License :: OSI Approved :: MIT License",
"Operating System :: OS Independent",
],
)

0 comments on commit fedd203

Please sign in to comment.