···13131414## Installation
15151616+From the command line:
1717+1618 gem install didkit
1919+2020+Or, add this to your `Gemfile`:
2121+2222+ gem 'didkit', '~> 0.3'
172318241925## Usage
20262121-Use the `DIDKit::Resolver` class to look up DIDs and handles.
2222-2323-To look up a handle:
2727+The simplest way to use the gem is through the `DIDKit::DID` class, aliased as just `DID`:
24282529```rb
2626-resolver = DIDKit::Resolver.new
2727-resolver.resolve_handle('nytimes.com')
2828- # => #<DIDKit::DID:0x00000001035956b0 @did="did:plc:eclio37ymobqex2ncko63h4r", @type=:plc, @resolved_by=:dns>
3030+did = DID.resolve_handle('jay.bsky.team')
3131+ # => #<DIDKit::DID:0x0... @did="did:plc:oky5czdrnfjpqslsw2a5iclo",
3232+ # @resolved_by=:dns, @type=:plc>
2933```
30343131-This returns an object of `DIDKit::DID` class (aliased as just `DID`), which tells you:
3535+This returns a `DID` object, which tells you:
32363337- the DID as a string (`#to_s` or `#did`)
3438- the DID type (`#type`, `:plc` or `:web`)
3539- if the handle was resolved via a DNS entry or a `.well-known` file (`#resolved_by`, `:dns` or `:http`)
36403737-To go in the other direction – to find an assigned and verified handle given a DID – use `get_validated_handle` (pass DID as a string or an object):
4141+To go in the other direction – to find an assigned and verified handle given a DID – create a `DID` from a DID string and call `get_verified_handle`:
38423943```rb
4040-resolver.get_validated_handle('did:plc:ewvi7nxzyoun6zhxrhs64oiz')
4141- # => "atproto.com"
4444+DID.new('did:plc:ewvi7nxzyoun6zhxrhs64oiz').get_verified_handle
4545+ # => "atproto.com"
4246```
43474444-You can also load the DID document using `resolve_did`:
4848+You can also load the DID JSON document using `#document`, which returns a `DIDKit::Document` (`DID` caches the document, so don't worry about calling this method multiple times):
45494650```rb
4747-doc = resolver.resolve_did('did:plc:ragtjsm2j2vknwkz3zp4oxrd')
4848- # => #<DIDKit::Document:0x0000000105d751f8 @did=#<DIDKit::DID:...>, @json={...}>
5151+did = DID.new('did:plc:ragtjsm2j2vknwkz3zp4oxrd')
49525050-doc.handles
5151- # => ["pfrazee.com"]
5353+did.document.handles
5454+ # => ["pfrazee.com"]
52555353-doc.pds_endpoint
5454- # => "https://morel.us-east.host.bsky.network"
5656+did.document.pds_host
5757+ # => "morel.us-east.host.bsky.network"
5558```
56595757-There are also some helper methods in the `DID` class that create a `Resolver` for you to save you some typing:
58605959-```rb
6060-did = DID.resolve_handle('jay.bsky.team')
6161- # => #<DIDKit::DID:0x000000010615ed28 @did="did:plc:oky5czdrnfjpqslsw2a5iclo", @type=:plc, @resolved_by=:dns>
6161+### Checking account status
62626363-did.to_s
6464- # => "did:plc:oky5czdrnfjpqslsw2a5iclo"
6363+`DIDKit::DID` also includes a few methods for checking the status of a given account (repo), which call the `com.atproto.sync.getRepoStatus` endpoint on the account's assigned PDS:
65646666-did.get_document
6767- # => #<DIDKit::Document:0x00000001066d4898 @did=#<DIDKit::DID:...>, @json={...}>
6565+```rb
6666+did = DID.new('did:plc:ch7azdejgddtlijyzurfdihn')
6767+did.account_status
6868+ # => :takendown
6969+did.account_active?
7070+ # => false
7171+did.account_exists?
7272+ # => true
68736969-did.get_validated_handle
7070- # => "jay.bsky.team"
7474+did = DID.new('did:plc:44ybard66vv44zksje25o7dz')
7575+did.account_status
7676+ # => :active
7777+did.account_active?
7878+ # => true
7179```
7272-73807481### Configuration
75827676-You can override the nameserver used for DNS lookups by setting the `nameserver` property in `Resolver`, e.g. to use Google's or CloudFlare's global DNS:
8383+You can customize some things about the DID/handle lookups by using the `DIDKit::Resolver` class, which the methods in `DID` use behind the scenes.
77847878-```
7979-resolver.nameserver = '8.8.8.8'
8080-```
8585+Currently available options include:
8686+8787+- `:nameserver` - override the nameserver used for DNS lookups, e.g. to use Google's or CloudFlare's DNS
8888+- `:timeout` - change the connection/response timeout for HTTP requests (default: 15 s)
8989+- `:max_redirects` - change allowed maximum number of redirects (default: 5)
9090+9191+Example:
81929393+```rb
9494+resolver = DIDKit::Resolver.new(nameserver: '8.8.8.8', timeout: 30)
9595+9696+did = resolver.resolve_handle('nytimes.com')
9797+ # => #<DIDKit::DID:0x0... @did="did:plc:eclio37ymobqex2ncko63h4r",
9898+ # @resolved_by=:dns, @type=:plc>
9999+100100+resolver.resolve_did(did)
101101+ # => #<DIDKit::Document:0x0... @did=#<DIDKit::DID:...>, @json={...}>
102102+103103+resolver.get_verified_handle(did)
104104+ # => 'nytimes.com'
105105+```
8210683107## Credits
84108