Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mackuba/didkit
A library for handling DID identifiers used in Bluesky AT Protocol
https://github.com/mackuba/didkit
atproto atprotocol bluesky bluesky-api did identity
Last synced: 2 months ago
JSON representation
A library for handling DID identifiers used in Bluesky AT Protocol
- Host: GitHub
- URL: https://github.com/mackuba/didkit
- Owner: mackuba
- License: zlib
- Created: 2023-11-14T16:16:38.000Z (about 1 year ago)
- Default Branch: master
- Last Pushed: 2024-08-19T01:49:41.000Z (5 months ago)
- Last Synced: 2024-10-15T07:24:09.660Z (3 months ago)
- Topics: atproto, atprotocol, bluesky, bluesky-api, did, identity
- Language: Ruby
- Homepage: https://blue.mackuba.eu
- Size: 66.4 KB
- Stars: 6
- Watchers: 2
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# DIDKit 🪪
A small Ruby gem for handling Distributed Identifiers (DIDs) in Bluesky / AT Protocol.
> [!NOTE]
> ATProto Ruby gems collection: [skyfall](https://github.com/mackuba/skyfall) | [blue_factory](https://github.com/mackuba/blue_factory) | [minisky](https://github.com/mackuba/minisky) | [didkit](https://github.com/mackuba/didkit)## What does it do
Accounts on Bluesky use identifiers like [did:plc:oio4hkxaop4ao4wz2pp3f4cr](https://plc.directory/did:plc:oio4hkxaop4ao4wz2pp3f4cr) as unique IDs, and they also have assigned human-readable handles like [@mackuba.eu](https://bsky.app/profile/mackuba.eu), which are verified either through a DNS TXT entry or a `/.well-known/atproto-did` file. This library allows you to look up any account's assigned handle using a DID string or vice versa, load the account's DID JSON document that specifies the handles and the PDS server hosting user's repo, and check if the assigned handle verifies correctly.
## Installation
gem install didkit
## Usage
Use the `DIDKit::Resolver` class to look up DIDs and handles.
To look up a handle:
```rb
resolver = DIDKit::Resolver.new
resolver.resolve_handle('nytimes.com')
# => #
```This returns an object of `DIDKit::DID` class (aliased as just `DID`), which tells you:
- the DID as a string (`#to_s` or `#did`)
- the DID type (`#type`, `:plc` or `:web`)
- if the handle was resolved via a DNS entry or a `.well-known` file (`#resolved_by`, `:dns` or `:http`)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):
```rb
resolver.get_validated_handle('did:plc:ewvi7nxzyoun6zhxrhs64oiz')
# => "atproto.com"
```You can also load the DID document using `resolve_did`:
```rb
doc = resolver.resolve_did('did:plc:ragtjsm2j2vknwkz3zp4oxrd')
# => #, @json={...}>doc.handles
# => ["pfrazee.com"]doc.pds_endpoint
# => "https://morel.us-east.host.bsky.network"
```There are also some helper methods in the `DID` class that create a `Resolver` for you to save you some typing:
```rb
did = DID.resolve_handle('jay.bsky.team')
# => #did.to_s
# => "did:plc:oky5czdrnfjpqslsw2a5iclo"did.get_document
# => #, @json={...}>did.get_validated_handle
# => "jay.bsky.team"
```### Configuration
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:
```
resolver.nameserver = '8.8.8.8'
```## Credits
Copyright © 2024 Kuba Suder ([@mackuba.eu](https://bsky.app/profile/mackuba.eu)).
The code is available under the terms of the [zlib license](https://choosealicense.com/licenses/zlib/) (permissive, similar to MIT).