oydid 0.6.7 → 0.7.0

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: e8b1fc642be72b8b9a92b137f995360b5d4e68742b5a9744b59b3e88649976bb
4
- data.tar.gz: 291e766737dec1b5756de3408097f5f243b02d3119ab3be2a29444957e82e9af
3
+ metadata.gz: dc7743afc702237fde6c94c6b4deb6dfd667ec8e0671952dbc0262414b67f2ea
4
+ data.tar.gz: a51344bf8e704bbe23a5e8c5f8a663000e701ce55803a171ff5b6f994a8089c2
5
5
  SHA512:
6
- metadata.gz: 04bf2f70fcfe5200ed15417dbcd57734b3fe33603bb36eb4dc5007821d6c27af135a3b37552fd75c42a9a1feb02453411a47106340b9abb836496df679ec7b99
7
- data.tar.gz: fd8d594757ecf3119c409b0d6169e607a823b1a575fcb1b5599625c2f305f580e51dee886a3112217272695b69e1da9ca65d1b3b1599a5908f916bce12aaacc1
6
+ metadata.gz: 1d2696a20122730603f44cad828e602f59791fad06a3f93fa70aca358445e35ac1af7cf38951cd3a4d0179dfdb47f2d38770d29c0cec162129f2730849431e46
7
+ data.tar.gz: b3c13897c837fb7be6ede4b4ce2e12251c0e9ff1546bde6123b8437f179d6d758e57ee5939931da1f3a08278d60c74d55e326d5f26b9ec05a4e22847e1530dfa
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.6.7
1
+ 0.7.0
data/lib/oydid/basic.rb CHANGED
@@ -35,6 +35,9 @@ class Oydid
35
35
 
36
36
  def self.multi_hash(message, options)
37
37
  method = options[:digest] || DEFAULT_DIGEST
38
+ # only set within the case statement for digests that are not looked up
39
+ # in the multicodec registry (see BLAKE2B_EXTRA_CODES)
40
+ code = nil
38
41
  case method.to_s
39
42
  when "sha2-256"
40
43
  digest = RbNaCl::Hash.sha256(message)
@@ -44,6 +47,11 @@ class Oydid
44
47
  digest = OpenSSL::Digest.digest(method, message)
45
48
  when "blake2b-16"
46
49
  digest = RbNaCl::Hash.blake2b(message, {digest_size: 16})
50
+ when "blake2b-17", "blake2b-18", "blake2b-19", "blake2b-20",
51
+ "blake2b-21", "blake2b-22", "blake2b-23"
52
+ digest_size = method.to_s.split("-").last.to_i
53
+ digest = RbNaCl::Hash.blake2b(message, {digest_size: digest_size})
54
+ code = BLAKE2B_EXTRA_CODES[digest_size]
47
55
  when "blake2b-32"
48
56
  digest = RbNaCl::Hash.blake2b(message, {digest_size: 32})
49
57
  when "blake2b-64"
@@ -51,7 +59,7 @@ class Oydid
51
59
  else
52
60
  return [nil, "unsupported digest: '" + method.to_s + "'"]
53
61
  end
54
- code = Multicodecs[method].code
62
+ code = Multicodecs[method].code if code.nil?
55
63
  length = digest.bytesize
56
64
  encoded = multi_encode([code, length, digest].pack("CCa#{length}"), options)
57
65
  # encoded = multi_encode(Multihashes.encode(digest, method.to_s), options)
@@ -80,6 +88,13 @@ class Oydid
80
88
  return ["blake2b-64", ""]
81
89
  else
82
90
  code, length, digest = decoded_message.unpack('CCa*')
91
+ # intermediate BLAKE2b sizes carry a code outside the multicodec
92
+ # registry; require the length byte to match so a stray code
93
+ # cannot be mistaken for one of them
94
+ blake2b_size = BLAKE2B_EXTRA_CODES.key(code)
95
+ if !blake2b_size.nil? && length == blake2b_size
96
+ return ["blake2b-" + blake2b_size.to_s, ""]
97
+ end
83
98
  retVal = Multicodecs[code].name rescue nil
84
99
  if !retVal.nil?
85
100
  return [retVal, ""]
data/lib/oydid.rb CHANGED
@@ -26,7 +26,12 @@ class Oydid
26
26
  LOCATION_PREFIX = "@"
27
27
  DEFAULT_LOCATION = "https://oydid.ownyourdata.eu"
28
28
  DEFAULT_DIGEST = "sha2-256"
29
- SUPPORTED_DIGESTS = ["sha2-256", "sha2-512", "sha3-224", "sha3-256", "sha3-384", "sha3-512", "blake2b-16", "blake2b-32", "blake2b-64"]
29
+ # BLAKE2b digests are named by digest size in BYTES here (house convention,
30
+ # e.g. "blake2b-16" is a 16 byte / 128 bit digest). This deliberately
31
+ # deviates from the multicodec registry, where blake2b-N counts bits.
32
+ SUPPORTED_DIGESTS = ["sha2-256", "sha2-512", "sha3-224", "sha3-256", "sha3-384", "sha3-512",
33
+ "blake2b-16", "blake2b-17", "blake2b-18", "blake2b-19", "blake2b-20",
34
+ "blake2b-21", "blake2b-22", "blake2b-23", "blake2b-32", "blake2b-64"]
30
35
  DEFAULT_ENCODING = "base58btc"
31
36
  SUPPORTED_ENCODINGS = ["base16", "base32", "base58btc", "base64"]
32
37
  LOG_HASH_OPTIONS = {:digest => "sha2-256", :encode => "base58btc"}
@@ -34,6 +39,24 @@ class Oydid
34
39
  JWS_SECURITY_SUITE = "https://w3id.org/security/suites/jws-2020/v1"
35
40
  DEFAULT_PUBLIC_RESOLVER = "https://dev.uniresolver.io/1.0/identifiers/"
36
41
 
42
+ # Single-byte multicodec codes for the intermediate BLAKE2b digest sizes
43
+ # (17-23 bytes), needed to keep a did:oyd identifier short enough for the
44
+ # 50 character URL limit of the EU Digital Product Passport registry.
45
+ #
46
+ # These sizes cannot take their code from Multicodecs[]: multi_hash packs
47
+ # the code into a single byte, which effectively truncates the registry's
48
+ # two-byte blake2b codes to their low byte - and those collide with the SHA
49
+ # codes already in use (0xb212 -> 0x12 = sha2-256, 0xb214 -> 0x14 =
50
+ # sha3-512, 0xb216 -> 0x16 = sha3-256, 0xb217 -> 0x17 = sha3-224).
51
+ #
52
+ # Instead the free, contiguous range 0x0B-0x11 is used (code = size - 6).
53
+ # Codes are kept low and single-byte on purpose: the value of the leading
54
+ # byte feeds into the base58btc length, and a low code saves a character.
55
+ BLAKE2B_EXTRA_CODES = {
56
+ 17 => 0x0B, 18 => 0x0C, 19 => 0x0D, 20 => 0x0E,
57
+ 21 => 0x0F, 22 => 0x10, 23 => 0x11
58
+ }.freeze
59
+
37
60
  # full Multicodecs table: https://github.com/multiformats/multicodec/blob/master/table.csv
38
61
  # Multicodecs.register(code: 0x1305, name: 'rsa-priv', tag: 'key')
39
62
  # Multicodecs.register(code: 0x1205, name: 'rsa-pub', tag: 'key')