Skip to main content

Token generation

Below is the example how to generate verification token for your domain:

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:

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 below.

DNS TXT record

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

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:

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:

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:

Is token valid: True

Extracting token from a DNS TXT record

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:

[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.

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:

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)

Metadata

Release files for verifyaname 0.2.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for verifyaname 0.2.1
File Size Uploaded
verifyaname-0.2.1.tar.gz 5.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for verifyaname 0.2.1
File Interpreter ABI Platform
verifyaname-0.2.1-py3-none-any.whl Python 3 none any Details

Total release size: 13.7 kB

Release files / verifyaname-0.2.1.tar.gz

Download URL verifyaname-0.2.1.tar.gz
Size 5.2 kB
Tags Source
SHA-256 checksum
How to use checksums
0aefec8765cf710318fb031435664a77d009cd811f9db3f8cd724f5151b6d624
BLAKE2b-256 checksum
How to use checksums
2d625a730b882990c7f0dbf1b1295e68d06883492855f534a75796c327d02815
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.8.0 colorama/0.4.4 importlib-metadata/6.7.0 keyring/23.13.1 pkginfo/1.9.6 readme-renderer/34.0 requests-toolbelt/1.0.0 requests/2.31.0 rfc3986/1.5.0 tqdm/4.65.0 urllib3/1.26.5 CPython/3.10.12

Release files / verifyaname-0.2.1-py3-none-any.whl

Download URL verifyaname-0.2.1-py3-none-any.whl
Size 8.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
3b7f075bc02d24a933791ea286c8bf09c68f0ab8e63b5db8bf382017ee383db7
BLAKE2b-256 checksum
How to use checksums
e3d012a5f2f5105a3a63055fb117c01bdff7158d49c22f87f793b47405dc77ac
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.8.0 colorama/0.4.4 importlib-metadata/6.7.0 keyring/23.13.1 pkginfo/1.9.6 readme-renderer/34.0 requests-toolbelt/1.0.0 requests/2.31.0 rfc3986/1.5.0 tqdm/4.65.0 urllib3/1.26.5 CPython/3.10.12

Release history Release notifications | RSS feed

This release

0.2.1 This release

2 release files

0.2.0

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page