verifyaname


Nameverifyaname JSON
Version 0.2.1 PyPI version JSON
download
home_page
SummaryAname verification library
upload_time2023-10-18 10:53:10
maintainer
docs_urlNone
authorFetch.AI Limited
requires_python>=3.8,<3.12
licenseApache 2.0
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            ## Token generation
Below is the example how to generate verification token for your domain:

```python
from verifyaname.verification_token import VerificationTokenData

domain = 'fetch-ai.com'
owner_wallet_address = 'fetch176kwvxr6u9v4axkfe2pzzzn87p4qssu9rn09kn'

vtd = VerificationTokenData(domain=domain, owner_address=owner_wallet_address)

# *Raw* Value of the verification token is `vtd.token`:
print(f'Raw token value: {vtd.token_raw}')

# *DNS TXT* value of the verification token is `vtd.token_b64` (it is URL-Safe-Base64 encoded raw value):
print(f'DNS TXT token value: "{vtd.token}"')
```

Execution of the code examples above gives the following output:
```text
Raw token value: b'j7\xe5\xb4\x88T\x97\xde7\x98-\xde\x1b\x90n\n\x08\xe2\xdf=\x03S\x7f\x1f\x1f%n\xf7S?|\xe4'
DNS TXT token value: "ajfltIhUl943mC3eG5BuCgji3z0DU38fHyVu91M_fOQ"
```

> NOTE: Value returned by the `vtd.token` property (see the code above) needs to be stored in domain's
> DNS TXT configuration under the `fetch-aname-token=` key - see the [DNS TXT record](#dns-txt-record) below.

## DNS TXT record
The whole DNS TXT record can be simply generated by calling the `create_dns_txt_record()` method.

```python
from verifyaname.verification_token import VerificationTokenData

domain = 'fetch-ai.com'
owner_wallet_address = 'fetch176kwvxr6u9v4axkfe2pzzzn87p4qssu9rn09kn'

vtd = VerificationTokenData(domain=domain, owner_address=owner_wallet_address)

dns_record = vtd.create_dns_txt_record()
print("Below is the *whole* DNS TXT record:")
print(dns_record)
```

Execution of the code above gives the following output, please notice the very last line starting with
the `fetch-aname-token=` text - **WHOLE** that line represents the whole DNS TXT record line:
```text
Below is the *whole* DNS TXT record:
fetch-aname-token=ajfltIhUl943mC3eG5BuCgji3z0DU38fHyVu91M_fOQ
```
> NOTE: This dns txt record **MUST** be then added as the **whole** line to the DNS TXT configuration of the domain in
> question(the `fetch-ai.com` in this particular case).


# Verifying DNS TXT record

In order to verify validity of the DNS TXT record (queried from the DNS TXT configuration of the domain) use the
following static method:

```python
from verifyaname.verification_token import VerificationTokenData

# Value acquired from the DNS TXT domain configuration of the 'fetch-ai.com' domain:
dns_txt_record = 'fetch-aname-token=ajfltIhUl943mC3eG5BuCgji3z0DU38fHyVu91M_fOQ'

# We expect following domain & owner wallet address:
domain = 'fetch-ai.com'
expected_owner_wallet_address = 'fetch176kwvxr6u9v4axkfe2pzzzn87p4qssu9rn09kn'

expected_vtd = VerificationTokenData(domain=domain, owner_address=expected_owner_wallet_address)

print(f'Is token valid: {expected_vtd.verify_dns_txt_record(dns_txt_record)}')
```

Execution of the code examples above gives the following output:
```text
Is token valid: True
```

## Extracting token from a DNS TXT record

```python
from verifyaname.verification_token import VerificationTokenData

# Value acquired from the DNS TXT domain configuration of the 'fetch-ai.com' domain:
dns_txt_record = 'fetch-aname-token=ajfltIhUl943mC3eG5BuCgji3z0DU38fHyVu91M_fOQ'
token = VerificationTokenData.extract_token_from_dns_txt_record(dns_txt_record)
print(f'[Valid record]     Extracted token: {token}')

# Malformed DNS TXT record (the record does *NOT* start with expected `fetch-aname-token=` prefix,
# in which case, the `VerificationTokenData.extract_token_from_dns_txt_record(...)` returns `None`.
malformed_dns_txt_record = 'MAFLFORMED_PREFIX=ajfltIhUl943mC3eG5BuCgji3z0DU38fHyVu91M_fOQ'
token2 = VerificationTokenData.extract_token_from_dns_txt_record(malformed_dns_txt_record)
print(f'[Malformed record] Extracted token: {token2}')
```

Execution of the code examples above gives the following output:
```text
[Valid record]     Extracted token: ajfltIhUl943mC3eG5BuCgji3z0DU38fHyVu91M_fOQ
[Malformed record] Extracted token: None
```

### Retrospective postprocessing of *Multiple* DNS TXT records

Using this approach makes sense more-or-less only if there is necessary to do some post-processing
of **multiple** DNS TXT records - e.g. do their verification retrospectively for some reason.

HOWEVER, normally, there is no reason to do verification retrospectively, and it is better, and way more readable 
to perform verification in immediate fashion using the `VerificationTokenData.verify_dns_txt_record(...)` method.

```python
from verifyaname.verification_token import VerificationTokenData

# NOTE: In this example we are going to use just *single* domain in order to simplify.
# However, in general, the algorithm below can be extended to multiple domains if necessary. 
domain = 'fetch-ai.com'

# Values acquired from the DNS TXT configuration of the 'fetch-ai.com' domain:
dns_txt_records = [
    'fetch-aname-token=ajfltIhUl943mC3eG5BuCgji3z0DU38fHyVu91M_fOQ',
    'fetch-aname-token=0OSUJZkcHtGMzEYivudG2DtBIq0M7pC9rWS3WXRhUac',
    'fetch-aname-token=J7RRL7jHyZ0LqUsrtDEODWOAb54XUlHT3laCUG9di8k',
    'fetch-aname-token=Cb09i2l-_WDHrY5tjOhZzbNbAWGiPSijMdiRAWgywtA'
]

tokens = set()
for record in dns_txt_records:
    tokens.add(VerificationTokenData.extract_token_from_dns_txt_record(record))

# For the domain `fetch-ai.com` we are expecting 4 owners:

expected_owners = {
    'fetch176kwvxr6u9v4axkfe2pzzzn87p4qssu9rn09kn',
    'fetch1mlhdzzrmcrmmzfjg4tg8runfmu7d0nvlmmttdv',
    'fetch104376kh6sevxel6xy4qdragnyvvczcfqje5urg',
    'fetch1pws7ernn93pd8ht2w4zu08mqgznpz3qu7xs709',
}

# Verify all owners for the domain:
failed_owners = set()
for owner in expected_owners:
    vtd = VerificationTokenData(domain=domain, owner_address=owner)

    # Using the `vtd.token` property to verify the token:
    if vtd.token in tokens:
        print(f'SUCCESS: [{owner}] has been VERIFIED as owner of the "{domain}" domain')
    else:
        failed_owners.add(owner)
        print(f'FAILURE: [{owner}] failed to verify as an owner of the "{domain}" domain')

if len(failed_owners) > 0:
    print(
        f'Verification of ownership for the "{domain}" domain FAILED for {len(failed_owners)} from {len(expected_owners)} owner(s)')
else:
    print(f'ALL owners have been verified')
```

Execution of the code examples above gives the following output:
```text
SUCCESS: [fetch176kwvxr6u9v4axkfe2pzzzn87p4qssu9rn09kn] has been VERIFIED as owner of the "fetch-ai.com" domain
SUCCESS: [fetch1mlhdzzrmcrmmzfjg4tg8runfmu7d0nvlmmttdv] has been VERIFIED as owner of the "fetch-ai.com" domain
SUCCESS: [fetch104376kh6sevxel6xy4qdragnyvvczcfqje5urg] has been VERIFIED as owner of the "fetch-ai.com" domain
FAILURE: [fetch1pws7ernn93pd8ht2w4zu08mqgznpz3qu7xs709] failed to verify as an owner of the "fetch-ai.com" domain
Verification of ownership for the "fetch-ai.com" domain FAILED for 1 from 4 owner(s)
```


            

Raw data

            {
    "_id": null,
    "home_page": "",
    "name": "verifyaname",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.8,<3.12",
    "maintainer_email": "",
    "keywords": "",
    "author": "Fetch.AI Limited",
    "author_email": "",
    "download_url": "https://files.pythonhosted.org/packages/2d/62/5a730b882990c7f0dbf1b1295e68d06883492855f534a75796c327d02815/verifyaname-0.2.1.tar.gz",
    "platform": null,
    "description": "## Token generation\nBelow is the example how to generate verification token for your domain:\n\n```python\nfrom verifyaname.verification_token import VerificationTokenData\n\ndomain = 'fetch-ai.com'\nowner_wallet_address = 'fetch176kwvxr6u9v4axkfe2pzzzn87p4qssu9rn09kn'\n\nvtd = VerificationTokenData(domain=domain, owner_address=owner_wallet_address)\n\n# *Raw* Value of the verification token is `vtd.token`:\nprint(f'Raw token value: {vtd.token_raw}')\n\n# *DNS TXT* value of the verification token is `vtd.token_b64` (it is URL-Safe-Base64 encoded raw value):\nprint(f'DNS TXT token value: \"{vtd.token}\"')\n```\n\nExecution of the code examples above gives the following output:\n```text\nRaw token value: b'j7\\xe5\\xb4\\x88T\\x97\\xde7\\x98-\\xde\\x1b\\x90n\\n\\x08\\xe2\\xdf=\\x03S\\x7f\\x1f\\x1f%n\\xf7S?|\\xe4'\nDNS TXT token value: \"ajfltIhUl943mC3eG5BuCgji3z0DU38fHyVu91M_fOQ\"\n```\n\n> NOTE: Value returned by the `vtd.token` property (see the code above) needs to be stored in domain's\n> DNS TXT configuration under the `fetch-aname-token=` key - see the [DNS TXT record](#dns-txt-record) below.\n\n## DNS TXT record\nThe whole DNS TXT record can be simply generated by calling the `create_dns_txt_record()` method.\n\n```python\nfrom verifyaname.verification_token import VerificationTokenData\n\ndomain = 'fetch-ai.com'\nowner_wallet_address = 'fetch176kwvxr6u9v4axkfe2pzzzn87p4qssu9rn09kn'\n\nvtd = VerificationTokenData(domain=domain, owner_address=owner_wallet_address)\n\ndns_record = vtd.create_dns_txt_record()\nprint(\"Below is the *whole* DNS TXT record:\")\nprint(dns_record)\n```\n\nExecution of the code above gives the following output, please notice the very last line starting with\nthe `fetch-aname-token=` text - **WHOLE** that line represents the whole DNS TXT record line:\n```text\nBelow is the *whole* DNS TXT record:\nfetch-aname-token=ajfltIhUl943mC3eG5BuCgji3z0DU38fHyVu91M_fOQ\n```\n> NOTE: This dns txt record **MUST** be then added as the **whole** line to the DNS TXT configuration of the domain in\n> question(the `fetch-ai.com` in this particular case).\n\n\n# Verifying DNS TXT record\n\nIn order to verify validity of the DNS TXT record (queried from the DNS TXT configuration of the domain) use the\nfollowing static method:\n\n```python\nfrom verifyaname.verification_token import VerificationTokenData\n\n# Value acquired from the DNS TXT domain configuration of the 'fetch-ai.com' domain:\ndns_txt_record = 'fetch-aname-token=ajfltIhUl943mC3eG5BuCgji3z0DU38fHyVu91M_fOQ'\n\n# We expect following domain & owner wallet address:\ndomain = 'fetch-ai.com'\nexpected_owner_wallet_address = 'fetch176kwvxr6u9v4axkfe2pzzzn87p4qssu9rn09kn'\n\nexpected_vtd = VerificationTokenData(domain=domain, owner_address=expected_owner_wallet_address)\n\nprint(f'Is token valid: {expected_vtd.verify_dns_txt_record(dns_txt_record)}')\n```\n\nExecution of the code examples above gives the following output:\n```text\nIs token valid: True\n```\n\n## Extracting token from a DNS TXT record\n\n```python\nfrom verifyaname.verification_token import VerificationTokenData\n\n# Value acquired from the DNS TXT domain configuration of the 'fetch-ai.com' domain:\ndns_txt_record = 'fetch-aname-token=ajfltIhUl943mC3eG5BuCgji3z0DU38fHyVu91M_fOQ'\ntoken = VerificationTokenData.extract_token_from_dns_txt_record(dns_txt_record)\nprint(f'[Valid record]     Extracted token: {token}')\n\n# Malformed DNS TXT record (the record does *NOT* start with expected `fetch-aname-token=` prefix,\n# in which case, the `VerificationTokenData.extract_token_from_dns_txt_record(...)` returns `None`.\nmalformed_dns_txt_record = 'MAFLFORMED_PREFIX=ajfltIhUl943mC3eG5BuCgji3z0DU38fHyVu91M_fOQ'\ntoken2 = VerificationTokenData.extract_token_from_dns_txt_record(malformed_dns_txt_record)\nprint(f'[Malformed record] Extracted token: {token2}')\n```\n\nExecution of the code examples above gives the following output:\n```text\n[Valid record]     Extracted token: ajfltIhUl943mC3eG5BuCgji3z0DU38fHyVu91M_fOQ\n[Malformed record] Extracted token: None\n```\n\n### Retrospective postprocessing of *Multiple* DNS TXT records\n\nUsing this approach makes sense more-or-less only if there is necessary to do some post-processing\nof **multiple** DNS TXT records - e.g. do their verification retrospectively for some reason.\n\nHOWEVER, normally, there is no reason to do verification retrospectively, and it is better, and way more readable \nto perform verification in immediate fashion using the `VerificationTokenData.verify_dns_txt_record(...)` method.\n\n```python\nfrom verifyaname.verification_token import VerificationTokenData\n\n# NOTE: In this example we are going to use just *single* domain in order to simplify.\n# However, in general, the algorithm below can be extended to multiple domains if necessary. \ndomain = 'fetch-ai.com'\n\n# Values acquired from the DNS TXT configuration of the 'fetch-ai.com' domain:\ndns_txt_records = [\n    'fetch-aname-token=ajfltIhUl943mC3eG5BuCgji3z0DU38fHyVu91M_fOQ',\n    'fetch-aname-token=0OSUJZkcHtGMzEYivudG2DtBIq0M7pC9rWS3WXRhUac',\n    'fetch-aname-token=J7RRL7jHyZ0LqUsrtDEODWOAb54XUlHT3laCUG9di8k',\n    'fetch-aname-token=Cb09i2l-_WDHrY5tjOhZzbNbAWGiPSijMdiRAWgywtA'\n]\n\ntokens = set()\nfor record in dns_txt_records:\n    tokens.add(VerificationTokenData.extract_token_from_dns_txt_record(record))\n\n# For the domain `fetch-ai.com` we are expecting 4 owners:\n\nexpected_owners = {\n    'fetch176kwvxr6u9v4axkfe2pzzzn87p4qssu9rn09kn',\n    'fetch1mlhdzzrmcrmmzfjg4tg8runfmu7d0nvlmmttdv',\n    'fetch104376kh6sevxel6xy4qdragnyvvczcfqje5urg',\n    'fetch1pws7ernn93pd8ht2w4zu08mqgznpz3qu7xs709',\n}\n\n# Verify all owners for the domain:\nfailed_owners = set()\nfor owner in expected_owners:\n    vtd = VerificationTokenData(domain=domain, owner_address=owner)\n\n    # Using the `vtd.token` property to verify the token:\n    if vtd.token in tokens:\n        print(f'SUCCESS: [{owner}] has been VERIFIED as owner of the \"{domain}\" domain')\n    else:\n        failed_owners.add(owner)\n        print(f'FAILURE: [{owner}] failed to verify as an owner of the \"{domain}\" domain')\n\nif len(failed_owners) > 0:\n    print(\n        f'Verification of ownership for the \"{domain}\" domain FAILED for {len(failed_owners)} from {len(expected_owners)} owner(s)')\nelse:\n    print(f'ALL owners have been verified')\n```\n\nExecution of the code examples above gives the following output:\n```text\nSUCCESS: [fetch176kwvxr6u9v4axkfe2pzzzn87p4qssu9rn09kn] has been VERIFIED as owner of the \"fetch-ai.com\" domain\nSUCCESS: [fetch1mlhdzzrmcrmmzfjg4tg8runfmu7d0nvlmmttdv] has been VERIFIED as owner of the \"fetch-ai.com\" domain\nSUCCESS: [fetch104376kh6sevxel6xy4qdragnyvvczcfqje5urg] has been VERIFIED as owner of the \"fetch-ai.com\" domain\nFAILURE: [fetch1pws7ernn93pd8ht2w4zu08mqgznpz3qu7xs709] failed to verify as an owner of the \"fetch-ai.com\" domain\nVerification of ownership for the \"fetch-ai.com\" domain FAILED for 1 from 4 owner(s)\n```\n\n",
    "bugtrack_url": null,
    "license": "Apache 2.0",
    "summary": "Aname verification library",
    "version": "0.2.1",
    "project_urls": null,
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "e3d012a5f2f5105a3a63055fb117c01bdff7158d49c22f87f793b47405dc77ac",
                "md5": "e80b1fbacb98c00b0d9d404d892ef7d1",
                "sha256": "3b7f075bc02d24a933791ea286c8bf09c68f0ab8e63b5db8bf382017ee383db7"
            },
            "downloads": -1,
            "filename": "verifyaname-0.2.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "e80b1fbacb98c00b0d9d404d892ef7d1",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8,<3.12",
            "size": 8522,
            "upload_time": "2023-10-18T10:53:08",
            "upload_time_iso_8601": "2023-10-18T10:53:08.460264Z",
            "url": "https://files.pythonhosted.org/packages/e3/d0/12a5f2f5105a3a63055fb117c01bdff7158d49c22f87f793b47405dc77ac/verifyaname-0.2.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "2d625a730b882990c7f0dbf1b1295e68d06883492855f534a75796c327d02815",
                "md5": "939921e9977101ca916c72cfdeaa8d59",
                "sha256": "0aefec8765cf710318fb031435664a77d009cd811f9db3f8cd724f5151b6d624"
            },
            "downloads": -1,
            "filename": "verifyaname-0.2.1.tar.gz",
            "has_sig": false,
            "md5_digest": "939921e9977101ca916c72cfdeaa8d59",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8,<3.12",
            "size": 5191,
            "upload_time": "2023-10-18T10:53:10",
            "upload_time_iso_8601": "2023-10-18T10:53:10.318963Z",
            "url": "https://files.pythonhosted.org/packages/2d/62/5a730b882990c7f0dbf1b1295e68d06883492855f534a75796c327d02815/verifyaname-0.2.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-10-18 10:53:10",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "lcname": "verifyaname"
}
        
Elapsed time: 0.12665s