didkit 0.3.0 → 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7f394023d5e7e3f864041dc39e81d1e2730972b6bfe8f3c0a0d0178e27e6557e
4
- data.tar.gz: e622af3eea9c05a7831c7b4630e16e0a879faede2a38b6605bb622d0ebb2eaf6
3
+ metadata.gz: b81757b37a0aa45a3ccefe6e8ebac777a283a6f8d3b827308f1f029b30abe0c8
4
+ data.tar.gz: beef9f4a9cc71c9edc46fce5e95df2b1c6a442c223826054eafed721d744b8ad
5
5
  SHA512:
6
- metadata.gz: 1dd40553f1f96d93bb746d1cfc628d3f4a2a34df99634a88775c3673f4ef721c2e13f85110e7a3a0b2880f29ffcbe7da21838378cdd04a3ea346a7ab2ccb2bfc
7
- data.tar.gz: f32fc83842dcd9a1bf88817aa8a286f5a1bdf42004416f74ec2450104388426456c2d16b598ba4439d9cb6c13f5035d800df2abada369656ac0c883797f05d1d
6
+ metadata.gz: 24c046d3566c3816c700e60936f9313b837df8403dc0435e67c317eabaf4e554c29357573a825d72a4795185d942c67c0fc408457a2f3c72e8569c1fc9c718ab
7
+ data.tar.gz: d0e4bb8224a6a0c5b6d62edfee27869fc7227229d3d95f482beb2c917ac0ea99c45fed7e8993299c8a2b69ef0a9d5f58e1d610e108f0f15aac50ffebb7599dfe
data/CHANGELOG.md CHANGED
@@ -1,3 +1,11 @@
1
+ ## [0.3.1] - 2025-12-19
2
+
3
+ - allow passing a DID string or object to `#resolve_handle` and just return that DID – so you can have a script that accepts either a handle or a DID, and passes the input to `DID.resolve_handle` without checking which one it is
4
+ - allow passing another DID object to `DID.new` and return a copy of that DID
5
+ - parse `seq` field in `PLCOperation` if included and expose it as a property
6
+ - fixed some errors on Rubies older than 3.2 due to missing `filter_map` and `URI#origin`
7
+ - `PLCOperation` verifies if the argument is a `Hash`
8
+
1
9
  ## [0.3.0] - 2025-12-15
2
10
 
3
11
  Breaking changes:
data/lib/didkit/did.rb CHANGED
@@ -7,6 +7,8 @@ require_relative 'resolver'
7
7
 
8
8
  module DIDKit
9
9
  class DID
10
+ GENERIC_REGEXP = /\Adid\:\w+\:.+\z/
11
+
10
12
  include Requests
11
13
 
12
14
  def self.resolve_handle(handle)
@@ -16,9 +18,13 @@ module DIDKit
16
18
  attr_reader :type, :did, :resolved_by
17
19
 
18
20
  def initialize(did, resolved_by = nil)
19
- if did =~ /^did\:(\w+)\:/
21
+ if did.is_a?(DID)
22
+ did = did.to_s
23
+ end
24
+
25
+ if did =~ GENERIC_REGEXP
20
26
  @did = did
21
- @type = $1.to_sym
27
+ @type = did.split(':')[1].to_sym
22
28
  else
23
29
  raise DIDError.new("Invalid DID format")
24
30
  end
@@ -60,7 +66,7 @@ module DIDKit
60
66
  doc = self.document
61
67
  return nil if doc.pds_endpoint.nil?
62
68
 
63
- pds_host = URI(doc.pds_endpoint).origin
69
+ pds_host = uri_origin(doc.pds_endpoint)
64
70
  url = URI("#{pds_host}/xrpc/com.atproto.sync.getRepoStatus")
65
71
  url.query = URI.encode_www_form(:did => @did)
66
72
 
@@ -21,24 +21,30 @@ module DIDKit
21
21
  @did = did
22
22
  @json = json
23
23
 
24
- if service = json['service']
25
- raise FormatError, "Invalid service data" unless service.is_a?(Array) && service.all? { |x| x.is_a?(Hash) }
26
-
27
- @services = service.filter_map { |x|
28
- id, type, endpoint = x.values_at('id', 'type', 'serviceEndpoint')
29
- next unless id.is_a?(String) && id.start_with?('#') && type.is_a?(String) && endpoint.is_a?(String)
30
-
31
- ServiceRecord.new(id.gsub(/^#/, ''), type, endpoint)
32
- }
33
- else
34
- @services = []
35
- end
36
-
24
+ @services = parse_services(json['service'] || [])
37
25
  @handles = parse_also_known_as(json['alsoKnownAs'] || [])
38
26
  end
39
27
 
40
28
  def get_verified_handle
41
29
  Resolver.new.get_verified_handle(self)
42
30
  end
31
+
32
+ private
33
+
34
+ def parse_services(service_data)
35
+ raise FormatError, "Invalid service data" unless service_data.is_a?(Array) && service_data.all? { |x| x.is_a?(Hash) }
36
+
37
+ services = []
38
+
39
+ service_data.each do |x|
40
+ id, type, endpoint = x.values_at('id', 'type', 'serviceEndpoint')
41
+
42
+ if id.is_a?(String) && id.start_with?('#') && type.is_a?(String) && endpoint.is_a?(String)
43
+ services << ServiceRecord.new(id.gsub(/^#/, ''), type, endpoint)
44
+ end
45
+ end
46
+
47
+ services
48
+ end
43
49
  end
44
50
  end
@@ -12,13 +12,16 @@ module DIDKit
12
12
  include AtHandles
13
13
  include Services
14
14
 
15
- attr_reader :json, :did, :cid, :created_at, :type, :handles, :services
15
+ attr_reader :json, :did, :cid, :seq, :created_at, :type, :handles, :services
16
16
 
17
17
  def initialize(json)
18
18
  @json = json
19
+ raise FormatError, "Expected argument to be a Hash, got a #{json.class}" unless @json.is_a?(Hash)
20
+
21
+ @seq = json['seq']
19
22
  @did = json['did']
20
23
  raise FormatError, "Missing DID: #{json}" if @did.nil?
21
- raise FormatError, "Invalid DID: #{@did}" unless @did.is_a?(String) && @did.start_with?('did:')
24
+ raise FormatError, "Invalid DID: #{@did.inspect}" unless @did.is_a?(String) && @did.start_with?('did:')
22
25
 
23
26
  @cid = json['cid']
24
27
  raise FormatError, "Missing CID: #{json}" if @cid.nil?
@@ -30,7 +30,7 @@ module DIDKit
30
30
  end
31
31
 
32
32
  if response.is_a?(Net::HTTPRedirection) && redirects < max_redirects && (location = response['Location'])
33
- url = URI(location.include?('://') ? location : (url.origin + location))
33
+ url = URI(location.include?('://') ? location : (uri_origin(url) + location))
34
34
 
35
35
  if visited_urls.include?(url)
36
36
  return response
@@ -74,5 +74,13 @@ module DIDKit
74
74
  raise ArgumentError, "Invalid expected_type: #{expected_type.inspect}"
75
75
  end
76
76
  end
77
+
78
+ # backported from https://github.com/ruby/uri/pull/30/files for older Rubies
79
+ def uri_origin(uri)
80
+ uri = uri.is_a?(URI) ? uri : URI(uri)
81
+ authority = (uri.port == uri.default_port) ? uri.host : "#{uri.host}:#{uri.port}"
82
+
83
+ "#{uri.scheme}://#{authority}"
84
+ end
77
85
  end
78
86
  end
@@ -19,6 +19,10 @@ module DIDKit
19
19
  end
20
20
 
21
21
  def resolve_handle(handle)
22
+ if handle.is_a?(DID) || handle =~ DID::GENERIC_REGEXP
23
+ return DID.new(handle)
24
+ end
25
+
22
26
  domain = handle.gsub(/^@/, '')
23
27
 
24
28
  return nil if RESERVED_DOMAINS.include?(domain.split('.').last)
@@ -71,7 +75,7 @@ module DIDKit
71
75
 
72
76
  def parse_did_from_well_known(text)
73
77
  text = text.strip
74
- text.lines.length == 1 && text =~ /\Adid\:\w+\:.*\z/ ? text : nil
78
+ text.lines.length == 1 && text =~ DID::GENERIC_REGEXP ? text : nil
75
79
  end
76
80
 
77
81
  def resolve_did(did)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module DIDKit
4
- VERSION = "0.3.0"
4
+ VERSION = "0.3.1"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: didkit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kuba Suder
@@ -31,13 +31,13 @@ files:
31
31
  - lib/didkit/services.rb
32
32
  - lib/didkit/version.rb
33
33
  - sig/didkit.rbs
34
- homepage: https://github.com/mackuba/didkit
34
+ homepage: https://ruby.sdk.blue
35
35
  licenses:
36
36
  - Zlib
37
37
  metadata:
38
- bug_tracker_uri: https://github.com/mackuba/didkit/issues
39
- changelog_uri: https://github.com/mackuba/didkit/blob/master/CHANGELOG.md
40
- source_code_uri: https://github.com/mackuba/didkit
38
+ bug_tracker_uri: https://tangled.org/mackuba.eu/didkit/issues
39
+ changelog_uri: https://tangled.org/mackuba.eu/didkit/blob/master/CHANGELOG.md
40
+ source_code_uri: https://tangled.org/mackuba.eu/didkit
41
41
  rdoc_options: []
42
42
  require_paths:
43
43
  - lib
@@ -52,7 +52,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
52
52
  - !ruby/object:Gem::Version
53
53
  version: '0'
54
54
  requirements: []
55
- rubygems_version: 3.6.9
55
+ rubygems_version: 4.0.1
56
56
  specification_version: 4
57
57
  summary: A library for handling Distributed ID (DID) identifiers used in Bluesky AT
58
58
  Protocol