Tools to prove ownership of content
Project description
owner
Tools to prove ownership of content
To install: pip install owner
Essentially
from owner import weave, unweave
assert unweave(weave(b'bob and alice')) == b'bob and alice'
What's happening?
Well, here's what's happening by default.
First, a weaver is made...
from owner import HeadWeaver
weaver = HeadWeaver()
weave
When we weave, we get the same original content, but with a bunch of "other junk"...
content = b'--this is where content goes--'
extra_info = b'**optional free-from "extra info goes here: It is meant for ownership and dating info.**'
w = weaver.weave(content, extra_info)
w
b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xb8\xe8gU\xcc\xc1\n)\xd1\xb0\x1dd\x07\xa4\x90\xbd\xfe\x0f7\xe9\xb5\xcd\xf8\xd7[z\xc5\xeao\xac\x03|8**optional free-from "extra info goes here: It is meant for ownership and dating info.**--this is where content goes--'
unweave
No fret though, we can unjunk the weave.
unwoven_content = weaver.unweave(w)
assert unwoven_content == content # see that the unwoven content is the same as the original content
unwoven_content
b'--this is where content goes--'
What does weaving and unweaving do for you?
Well, that's up to you. It's just a means to add some information to some content, within the bytes of the content itself, and be able to still access the original content.
What you put in the extra_info
depends on you and your use case.
The use case we have in mind here is: I want to prove that some content is mine by posting a hash of it on a block-chain.
But if I just hash the content, only the content is represented, not any other information (such as my name etc.).
Simple solution to that: Just prepend my name (or any other information) to the raw content.
That's what extra_info
is.
Ah... but then I need to know where the original content starts.
That's what offset
is.
And then we added a content_hash
to add extra error-correcting abilities.
Let's now have a look at how the woven bytes are parsed.
inspecting the parts of the woven
parts = weaver.unweave_parts(w)
parts
UnWovenBaseHeaderWeave(offset=b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xb8', content_hash=b'\xe8gU\xcc\xc1\n)\xd1\xb0\x1dd\x07\xa4\x90\xbd\xfe\x0f7\xe9\xb5\xcd\xf8\xd7[z\xc5\xeao\xac\x03|8', extra_info=b'**optional free-from "extra info goes here: It is meant for ownership and dating info.**', content=b'--this is where content goes--')
parts._fields
('offset', 'content_hash', 'extra_info', 'content')
As you see in the print out above, the parts are all given in raw bytes format.
If you need them to be interpreted you can do so like this:
parts = weaver.unweave_parts(w, interpret_bytes=True)
parts
UnWovenBaseHeaderWeave(offset=184, content_hash='e86755ccc10a29d1b01d6407a490bdfe0f37e9b5cdf8d75b7ac5ea6fac037c38', extra_info=b'**optional free-from "extra info goes here: It is meant for ownership and dating info.**', content=b'--this is where content goes--')
The offset tells us where the content actually starts. Here, we know it starts at the 184th byte.
parts.offset
184
The content_hash
is the sha256 of the original contents, here presented in hex form.
parts.content_hash
'e86755ccc10a29d1b01d6407a490bdfe0f37e9b5cdf8d75b7ac5ea6fac037c38'
parts.extra_info
b'**optional free-from "extra info goes here: It is meant for ownership and dating info.**'
parts.content
b'--this is where content goes--'
a bit more control on how you get your woven parts
import json
weaver = HeadWeaver()
content = 'This is some text'
extra_info = {"name": "Thor Whalen",
"date": "2013-12-11"}
w = weaver.weave(content.encode(), json.dumps(extra_info).encode())
parts = weaver.unweave_parts(w, interpret_bytes=True, decode_content=True, decode_extra_info=json.loads)
parts
UnWovenBaseHeaderWeave(offset=141, content_hash='2263d8dd95ccfe1ad45d732c6eaaf59b3345e6647331605cb15aae52002dff75', extra_info={'name': 'Thor Whalen', 'date': '2013-12-11'}, content='This is some text')
assert isinstance(parts.extra_info, dict) # I'm now getting extra_info in the form of a dict
parts.extra_info
{'name': 'Thor Whalen', 'date': '2013-12-11'}
assert isinstance(parts.content, str) # content is as a str
parts.content
'This is some text'
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file owner-0.0.10.tar.gz
.
File metadata
- Download URL: owner-0.0.10.tar.gz
- Upload date:
- Size: 6.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.24.0 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.51.0 CPython/3.8.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 24e45af7e9657febb77c157f88339e57f1cdb34d7feef32ce1f98d945627f138 |
|
MD5 | 491fd086148392d8ca66eefd14f2fd8f |
|
BLAKE2b-256 | 85a124552b7754540bf8ddeade1d0a10f362c47adc448ab445249da0922acb87 |
File details
Details for the file owner-0.0.10-py3-none-any.whl
.
File metadata
- Download URL: owner-0.0.10-py3-none-any.whl
- Upload date:
- Size: 6.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.24.0 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.51.0 CPython/3.8.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | d194043dc6cc76d839dd40c478d748f07b3d1db40b64987b7ff070b40aca7da1 |
|
MD5 | ac09a04f2d9e49afe0ef49022e5697a5 |
|
BLAKE2b-256 | 58624759fee78076bde1d8d509267e75cb11dc368d804cc4600ed982913999c3 |