didkit 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CHANGELOG.md +2 -0
- data/LICENSE.txt +22 -0
- data/README.md +31 -0
- data/lib/didkit/did.rb +91 -0
- data/lib/didkit/document.rb +14 -0
- data/lib/didkit/errors.rb +4 -0
- data/lib/didkit/version.rb +5 -0
- data/lib/didkit.rb +10 -0
- data/sig/didkit.rbs +4 -0
- metadata +56 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 84c36ec4b90b5e5bd3513619f4866b13f4e97edd0fad2fda96cbb5a411638975
|
4
|
+
data.tar.gz: 90b272850cb3537672cb401e9fe1ff0c2b40fc505c927271d1ce51886926b356
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: a3ef3e167f721e91d0c251f8003d8450d115ba77c7f5282cb59680ea8ae94ff848e340e117ba28ed2d666e04a90df7a1f65b14a73086c54304917b76a97b8cc0
|
7
|
+
data.tar.gz: 0cf47614fad40c7de161a75cfc1d6bc2fca6f83afef2b7364b43453cc3af3c2ef5c08611b82ea10dc5fbced08ed7b820caf122c95c1975e1ccaadba70fb6aece
|
data/CHANGELOG.md
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
The zlib License
|
2
|
+
|
3
|
+
Copyright (c) 2023 Jakub Suder
|
4
|
+
|
5
|
+
This software is provided 'as-is', without any express or implied
|
6
|
+
warranty. In no event will the authors be held liable for any damages
|
7
|
+
arising from the use of this software.
|
8
|
+
|
9
|
+
Permission is granted to anyone to use this software for any purpose,
|
10
|
+
including commercial applications, and to alter it and redistribute it
|
11
|
+
freely, subject to the following restrictions:
|
12
|
+
|
13
|
+
1. The origin of this software must not be misrepresented; you must not
|
14
|
+
claim that you wrote the original software. If you use this software
|
15
|
+
in a product, an acknowledgment in the product documentation would be
|
16
|
+
appreciated but is not required.
|
17
|
+
|
18
|
+
2. Altered source versions must be plainly marked as such, and must not be
|
19
|
+
misrepresented as being the original software.
|
20
|
+
|
21
|
+
3. This notice may not be removed or altered from any source distribution.
|
22
|
+
|
data/README.md
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
# Didkit
|
2
|
+
|
3
|
+
TODO: Delete this and the text below, and describe your gem
|
4
|
+
|
5
|
+
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/didkit`. To experiment with that code, run `bin/console` for an interactive prompt.
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
TODO: Replace `UPDATE_WITH_YOUR_GEM_NAME_PRIOR_TO_RELEASE_TO_RUBYGEMS_ORG` with your gem name right after releasing it to RubyGems.org. Please do not do it earlier due to security reasons. Alternatively, replace this section with instructions to install your gem from git if you don't plan to release to RubyGems.org.
|
10
|
+
|
11
|
+
Install the gem and add to the application's Gemfile by executing:
|
12
|
+
|
13
|
+
$ bundle add UPDATE_WITH_YOUR_GEM_NAME_PRIOR_TO_RELEASE_TO_RUBYGEMS_ORG
|
14
|
+
|
15
|
+
If bundler is not being used to manage dependencies, install the gem by executing:
|
16
|
+
|
17
|
+
$ gem install UPDATE_WITH_YOUR_GEM_NAME_PRIOR_TO_RELEASE_TO_RUBYGEMS_ORG
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
TODO: Write usage instructions here
|
22
|
+
|
23
|
+
## Development
|
24
|
+
|
25
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
26
|
+
|
27
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
28
|
+
|
29
|
+
## Contributing
|
30
|
+
|
31
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/didkit.
|
data/lib/didkit/did.rb
ADDED
@@ -0,0 +1,91 @@
|
|
1
|
+
require 'json'
|
2
|
+
require 'open-uri'
|
3
|
+
require 'resolv'
|
4
|
+
|
5
|
+
require_relative 'document'
|
6
|
+
require_relative 'errors'
|
7
|
+
|
8
|
+
module DIDKit
|
9
|
+
class DID
|
10
|
+
def self.resolve_handle(handle)
|
11
|
+
domain = handle.gsub(/^@/, '')
|
12
|
+
|
13
|
+
if dns_did = resolve_handle_by_dns(domain)
|
14
|
+
DID.new(dns_did)
|
15
|
+
elsif http_did = resolve_handle_by_well_known(domain)
|
16
|
+
DID.new(http_did)
|
17
|
+
else
|
18
|
+
nil
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.resolve_handle_by_dns(domain)
|
23
|
+
dns_records = Resolv::DNS.open { |d| d.getresources("_atproto.#{domain}", Resolv::DNS::Resource::IN::TXT) }
|
24
|
+
|
25
|
+
if record = dns_records.first
|
26
|
+
if string = record.strings.first
|
27
|
+
if string =~ /^did\=(did\:\w+\:.*)$/
|
28
|
+
return $1
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
nil
|
34
|
+
end
|
35
|
+
|
36
|
+
def self.resolve_handle_by_well_known(domain)
|
37
|
+
url = URI("https://#{domain}/.well-known/atproto-did")
|
38
|
+
response = Net::HTTP.get_response(url)
|
39
|
+
|
40
|
+
if response.is_a?(Net::HTTPSuccess)
|
41
|
+
if text = response.body
|
42
|
+
if text.lines.length == 1 && text.start_with?('did:')
|
43
|
+
return text
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
nil
|
49
|
+
end
|
50
|
+
|
51
|
+
attr_reader :type
|
52
|
+
|
53
|
+
def initialize(did)
|
54
|
+
if did =~ /^did\:(\w+)\:/
|
55
|
+
@did = did
|
56
|
+
@type = $1
|
57
|
+
else
|
58
|
+
raise DIDError.new("Invalid DID format")
|
59
|
+
end
|
60
|
+
|
61
|
+
if @type != 'plc' && @type != 'web'
|
62
|
+
raise DIDError.new("Unrecognized DID type: #{@type}")
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
def to_s
|
67
|
+
@did
|
68
|
+
end
|
69
|
+
|
70
|
+
def get_document
|
71
|
+
if @type == 'plc'
|
72
|
+
resolve_did_plc(@did)
|
73
|
+
elsif @type == 'web'
|
74
|
+
resolve_did_web(@did)
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
def resolve_did_plc(did)
|
79
|
+
url = "https://plc.directory/#{did}"
|
80
|
+
json = JSON.parse(URI.open(url).read)
|
81
|
+
Document.new(json)
|
82
|
+
end
|
83
|
+
|
84
|
+
def resolve_did_web(did)
|
85
|
+
host = did.gsub(/^did\:web\:/, '')
|
86
|
+
url = "https://#{host}/.well-known/did.json"
|
87
|
+
json = JSON.parse(URI.open(url).read)
|
88
|
+
Document.new(json)
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module DIDKit
|
2
|
+
class Document
|
3
|
+
attr_reader :json
|
4
|
+
|
5
|
+
def initialize(json)
|
6
|
+
@json = json
|
7
|
+
end
|
8
|
+
|
9
|
+
def pds_endpoint
|
10
|
+
service = (@json['service'] || []).detect { |s| s['id'] == '#atproto_pds' }
|
11
|
+
service && service['serviceEndpoint']
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
data/lib/didkit.rb
ADDED
data/sig/didkit.rbs
ADDED
metadata
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: didkit
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Kuba Suder
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2023-11-14 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description:
|
14
|
+
email:
|
15
|
+
- jakub.suder@gmail.com
|
16
|
+
executables: []
|
17
|
+
extensions: []
|
18
|
+
extra_rdoc_files: []
|
19
|
+
files:
|
20
|
+
- CHANGELOG.md
|
21
|
+
- LICENSE.txt
|
22
|
+
- README.md
|
23
|
+
- lib/didkit.rb
|
24
|
+
- lib/didkit/did.rb
|
25
|
+
- lib/didkit/document.rb
|
26
|
+
- lib/didkit/errors.rb
|
27
|
+
- lib/didkit/version.rb
|
28
|
+
- sig/didkit.rbs
|
29
|
+
homepage: https://github.com/mackuba/didkit
|
30
|
+
licenses:
|
31
|
+
- Zlib
|
32
|
+
metadata:
|
33
|
+
bug_tracker_uri: https://github.com/mackuba/didkit/issues
|
34
|
+
changelog_uri: https://github.com/mackuba/didkit/blob/master/CHANGELOG.md
|
35
|
+
source_code_uri: https://github.com/mackuba/didkit
|
36
|
+
post_install_message:
|
37
|
+
rdoc_options: []
|
38
|
+
require_paths:
|
39
|
+
- lib
|
40
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
41
|
+
requirements:
|
42
|
+
- - ">="
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
version: 2.6.0
|
45
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
46
|
+
requirements:
|
47
|
+
- - ">="
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: '0'
|
50
|
+
requirements: []
|
51
|
+
rubygems_version: 3.4.10
|
52
|
+
signing_key:
|
53
|
+
specification_version: 4
|
54
|
+
summary: A library for handling Distributed ID (DID) identifiers used in Bluesky AT
|
55
|
+
Protocol
|
56
|
+
test_files: []
|