Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 1 addition & 21 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@ If you have any trouble with the installation, see [the troubleshooting guide](/
```python
from blockstack_profiles import (
sign_token, wrap_token, sign_token_records,
validate_token_record, get_profile_from_tokens,
make_zone_file_for_hosted_data,
resolve_zone_file_to_profile
validate_token_record, get_profile_from_tokens
)
```

Expand Down Expand Up @@ -70,21 +68,3 @@ profile = get_profile_from_tokens(profile_tokens, "02f1fd79dcd51bd017f71546ddc0f
"birthDate": "1980-01-01"
}
```

### Creating Zone Files

```python
zone_file = make_zone_file_for_hosted_data("naval.id", "https://mq9.s3.amazonaws.com/naval.id/profile.json")
```

```
$ORIGIN naval.id
$TTL 3600
@ IN URI "https://mq9.s3.amazonaws.com/naval.id/profile.json"
```

### Resolving Zone Files to Profiles

```python
profile = resolve_zone_file_to_profile(zone_file)
```
4 changes: 1 addition & 3 deletions blockstack_profiles/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,8 @@
)

from zone_file_format import (
make_zone_file_for_hosted_data,
get_token_file_url_from_zone_file,
zone_file_has_a_valid_uri_record,
resolve_zone_file_to_profile
zone_file_has_a_valid_uri_record
)

from legacy_format import (
Expand Down
35 changes: 0 additions & 35 deletions blockstack_profiles/zone_file_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,6 @@
from .token_verifying import get_profile_from_tokens


def make_zone_file_for_hosted_data(origin, token_file_url, ttl=3600):
if "://" not in token_file_url:
raise ValueError("Invalid token file URL")
json_zone_file = {
"$ttl": ttl,
"$origin": origin,
"uri": [{
"name": "_http._tcp",
"priority": 10,
"weight": 1,
"target": token_file_url
}]
}
zone_file = make_zone_file(json_zone_file)
return zone_file


def get_token_file_url_from_zone_file(zone_file):
token_file_url = None

Expand All @@ -47,21 +30,3 @@ def get_token_file_url_from_zone_file(zone_file):
def zone_file_has_a_valid_uri_record(data):
return get_token_file_url_from_zone_file(data) is not None


def resolve_zone_file_to_profile(zone_file, address_or_public_key):
if is_profile_in_legacy_format(zone_file):
return zone_file

token_file_url = get_token_file_url_from_zone_file(zone_file)

try:
r = requests.get(token_file_url)
except:
return None

try:
profile_token_records = json.loads(r.text)
except ValueError:
return None

return get_profile_from_tokens(profile_token_records, address_or_public_key)
18 changes: 1 addition & 17 deletions unit_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,10 @@
from blockstack_profiles import (
sign_token, wrap_token, sign_token_records,
verify_token, verify_token_record, get_profile_from_tokens,
make_zone_file_for_hosted_data,
get_person_from_legacy_format,
convert_profile_to_legacy_format,
get_token_file_url_from_zone_file,
zone_file_has_a_valid_uri_record,
resolve_zone_file_to_profile
zone_file_has_a_valid_uri_record
)
from test_data import reference_profiles

Expand Down Expand Up @@ -92,16 +90,6 @@ def setUp(self):
def tearDown(self):
pass

def test_zone_file_creation(self):
origin = "naval.id"
token_file_url = "https://mq9.s3.amazonaws.com/naval.id/profile.json"
zone_file = make_zone_file_for_hosted_data(origin, token_file_url)
# print zone_file
self.assertTrue(isinstance(zone_file, (unicode, str)))
self.assertTrue("$ORIGIN" in zone_file)
self.assertTrue("$TTL" in zone_file)
self.assertTrue("_http._tcp URI" in zone_file)

def test_token_file_url_recovery_from_zone_file(self):
token_file_url = get_token_file_url_from_zone_file(self.zone_file)
self.assertEqual(token_file_url, "https://mq9.s3.amazonaws.com/naval.id/profile.json")
Expand All @@ -110,10 +98,6 @@ def test_zone_file_has_a_valid_uri_record(self):
is_valid = zone_file_has_a_valid_uri_record(self.zone_file)
self.assertTrue(is_valid)

def test_resolve_zone_file_to_profile(self):
profile = resolve_zone_file_to_profile(self.zone_file_2, self.public_key_2)
self.assertTrue("name" in profile)


class LegacyFormatTests(unittest.TestCase):
def setUp(self):
Expand Down