didkit 0.0.1 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +20 -1
- data/README.md +10 -19
- data/lib/didkit/did.rb +22 -20
- data/lib/didkit/document.rb +33 -6
- data/lib/didkit/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d974c618ebe4702ec35b8f4e1465b3cc0664d1cf932fd8739ac4371f7c20caa2
|
4
|
+
data.tar.gz: 66479727000f96ef26d09074bd97cd59d43f14388ea213f25deb846c6e75cb3d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b3b84e04e7be85c0af2a544173a14338870fc3163727dd9341a1c76d83ce6397c03f4f28284549c5c07c2c3625e018b81c7a4149c80dac8e817f01f7b724c042
|
7
|
+
data.tar.gz: e476000c6bbc05a3e5664e2fb44a8bb19e302c2b13d880bfc9d98a2144916b7982d914d41beea55e5775f55a1a3d01a9bd0854ff4cfa9274d86aba4a406441e1
|
data/CHANGELOG.md
CHANGED
@@ -1,2 +1,21 @@
|
|
1
|
-
## [
|
1
|
+
## [0.0.3] - 2024-03-06
|
2
2
|
|
3
|
+
- added `Document#handles` with handle info extracted from `alsoKnownAs` field
|
4
|
+
- added validation of various fields of the DID document
|
5
|
+
- added `DID#resolved_by` (`:dns` or `:http`)
|
6
|
+
- added `DID#did` which returns the DID in a string form like `to_s`
|
7
|
+
- added `DID#web_domain` which returns the domain part of a `did:web`
|
8
|
+
- changed `DID#type` to be stored as a symbol
|
9
|
+
|
10
|
+
## [0.0.2] - 2023-11-14
|
11
|
+
|
12
|
+
- fixed missing require
|
13
|
+
- fixed some connection error handling
|
14
|
+
|
15
|
+
## [0.0.1] - 2023-11-14
|
16
|
+
|
17
|
+
Initial release:
|
18
|
+
|
19
|
+
- resolving handle to DID via DNS or HTTP well-known
|
20
|
+
- loading DID document via PLC or did:web well-known
|
21
|
+
- extracting PDS endpoint field from the DID doc
|
data/README.md
CHANGED
@@ -1,31 +1,22 @@
|
|
1
|
-
#
|
1
|
+
# DidKit
|
2
2
|
|
3
|
-
|
3
|
+
A small Ruby gem for handling Distributed Identifiers (DIDs) in Bluesky / AT Protocol
|
4
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
5
|
|
7
|
-
##
|
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:
|
6
|
+
## What does it do
|
12
7
|
|
13
|
-
|
8
|
+
**TODO** - not much yet :)
|
14
9
|
|
15
|
-
|
10
|
+
See the [did.rb](https://github.com/mackuba/didkit/blob/master/lib/didkit/did.rb) file for now.
|
16
11
|
|
17
|
-
$ gem install UPDATE_WITH_YOUR_GEM_NAME_PRIOR_TO_RELEASE_TO_RUBYGEMS_ORG
|
18
12
|
|
19
|
-
##
|
20
|
-
|
21
|
-
TODO: Write usage instructions here
|
13
|
+
## Installation
|
22
14
|
|
23
|
-
|
15
|
+
gem install didkit
|
24
16
|
|
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
17
|
|
27
|
-
|
18
|
+
## Credits
|
28
19
|
|
29
|
-
|
20
|
+
Copyright © 2023 Kuba Suder ([@mackuba.eu](https://bsky.app/profile/mackuba.eu)).
|
30
21
|
|
31
|
-
|
22
|
+
The code is available under the terms of the [zlib license](https://choosealicense.com/licenses/zlib/) (permissive, similar to MIT).
|
data/lib/didkit/did.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'json'
|
2
|
+
require 'net/http'
|
2
3
|
require 'open-uri'
|
3
4
|
require 'resolv'
|
4
5
|
|
@@ -11,9 +12,9 @@ module DIDKit
|
|
11
12
|
domain = handle.gsub(/^@/, '')
|
12
13
|
|
13
14
|
if dns_did = resolve_handle_by_dns(domain)
|
14
|
-
DID.new(dns_did)
|
15
|
+
DID.new(dns_did, :dns)
|
15
16
|
elsif http_did = resolve_handle_by_well_known(domain)
|
16
|
-
DID.new(http_did)
|
17
|
+
DID.new(http_did, :http)
|
17
18
|
else
|
18
19
|
nil
|
19
20
|
end
|
@@ -45,47 +46,48 @@ module DIDKit
|
|
45
46
|
end
|
46
47
|
end
|
47
48
|
|
49
|
+
nil
|
50
|
+
rescue StandardError => e
|
48
51
|
nil
|
49
52
|
end
|
50
53
|
|
51
|
-
attr_reader :type
|
54
|
+
attr_reader :type, :did, :resolved_by
|
52
55
|
|
53
|
-
def initialize(did)
|
56
|
+
def initialize(did, resolved_by = nil)
|
54
57
|
if did =~ /^did\:(\w+)\:/
|
55
58
|
@did = did
|
56
|
-
@type = $1
|
59
|
+
@type = $1.to_sym
|
57
60
|
else
|
58
61
|
raise DIDError.new("Invalid DID format")
|
59
62
|
end
|
60
63
|
|
61
|
-
if @type !=
|
64
|
+
if @type != :plc && @type != :web
|
62
65
|
raise DIDError.new("Unrecognized DID type: #{@type}")
|
63
66
|
end
|
64
|
-
end
|
65
67
|
|
66
|
-
|
67
|
-
@did
|
68
|
+
@resolved_by = resolved_by
|
68
69
|
end
|
69
70
|
|
71
|
+
alias to_s did
|
72
|
+
|
70
73
|
def get_document
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
74
|
+
type == :plc ? resolve_did_plc : resolve_did_web
|
75
|
+
end
|
76
|
+
|
77
|
+
def web_domain
|
78
|
+
did.gsub(/^did\:web\:/, '') if type == :web
|
76
79
|
end
|
77
80
|
|
78
|
-
def resolve_did_plc
|
81
|
+
def resolve_did_plc
|
79
82
|
url = "https://plc.directory/#{did}"
|
80
83
|
json = JSON.parse(URI.open(url).read)
|
81
|
-
Document.new(json)
|
84
|
+
Document.new(self, json)
|
82
85
|
end
|
83
86
|
|
84
|
-
def resolve_did_web
|
85
|
-
|
86
|
-
url = "https://#{host}/.well-known/did.json"
|
87
|
+
def resolve_did_web
|
88
|
+
url = "https://#{web_domain}/.well-known/did.json"
|
87
89
|
json = JSON.parse(URI.open(url).read)
|
88
|
-
Document.new(json)
|
90
|
+
Document.new(self, json)
|
89
91
|
end
|
90
92
|
end
|
91
93
|
end
|
data/lib/didkit/document.rb
CHANGED
@@ -1,14 +1,41 @@
|
|
1
1
|
module DIDKit
|
2
2
|
class Document
|
3
|
-
|
3
|
+
class FormatError < StandardError
|
4
|
+
end
|
5
|
+
|
6
|
+
attr_reader :json, :did, :pds_endpoint, :handles
|
4
7
|
|
5
|
-
def initialize(json)
|
8
|
+
def initialize(did, json)
|
9
|
+
raise FormatError, "Missing id field" if json['id'].nil?
|
10
|
+
raise FormatError, "Invalid id field" unless json['id'].is_a?(String)
|
11
|
+
raise FormatError, "Id field doesn't match expected DID" unless json['id'] == did.to_s
|
12
|
+
|
13
|
+
@did = did
|
6
14
|
@json = json
|
7
|
-
end
|
8
15
|
|
9
|
-
|
10
|
-
|
11
|
-
service && service
|
16
|
+
service = json['service']
|
17
|
+
raise FormatError, "Missing service key" if service.nil?
|
18
|
+
raise FormatError, "Invalid service data" unless service.is_a?(Array) && service.all? { |x| x.is_a?(Hash) }
|
19
|
+
|
20
|
+
if pds = service.detect { |x| x['id'] == '#atproto_pds' }
|
21
|
+
raise FormatError, "Missing PDS type" unless pds['type']
|
22
|
+
raise FormatError, "Invalid PDS type" unless pds['type'] == 'AtprotoPersonalDataServer'
|
23
|
+
raise FormatError, "Missing PDS endpoint" unless pds['serviceEndpoint']
|
24
|
+
raise FormatError, "Invalid PDS endpoint" unless pds['serviceEndpoint'].is_a?(String)
|
25
|
+
raise FormatError, "Invalid PDS endpoint" unless pds['serviceEndpoint'] =~ %r(://)
|
26
|
+
|
27
|
+
@pds_endpoint = pds['serviceEndpoint']
|
28
|
+
end
|
29
|
+
|
30
|
+
if aka = json['alsoKnownAs']
|
31
|
+
raise FormatError, "Invalid alsoKnownAs" unless aka.is_a?(Array)
|
32
|
+
raise FormatError, "Invalid alsoKnownAs" unless aka.all? { |x| x.is_a?(String) }
|
33
|
+
raise FormatError, "Invalid alsoKnownAs" unless aka.all? { |x| x =~ %r(\Aat://[^/]+\z) }
|
34
|
+
|
35
|
+
@handles = aka.map { |x| x.gsub('at://', '') }
|
36
|
+
else
|
37
|
+
@handles = []
|
38
|
+
end
|
12
39
|
end
|
13
40
|
end
|
14
41
|
end
|
data/lib/didkit/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: didkit
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kuba Suder
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-03-06 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description:
|
14
14
|
email:
|