oydid 0.8.0 → 0.8.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 +4 -4
- data/VERSION +1 -1
- data/lib/oydid.rb +43 -27
- data/spec/oydid_spec.rb +56 -0
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 853f05f30010c3713c64d00caee53feccd969429af27ee4cbd0370c1de7d9891
|
|
4
|
+
data.tar.gz: f601867e31baedc4bba925d99039a184dabca9ac64de311b5171c30d84f5b100
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 78ce89d1e9fe4546852d6cb9ade32a8afbe0756ddf0af9253db328ade1d7d70fa60f1a1dc3ead15093713264954feae54bfb07f6d73ab41791e18758943b99d7
|
|
7
|
+
data.tar.gz: 01f895768ab0fcbc4f38c5e93e2ca0ab1bd82a5f25fe8092cf63ec32d4552e2f4a7a91292f55294bc9c3e40388b57809f92073199318142eb923c76703757289
|
data/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
0.8.
|
|
1
|
+
0.8.1
|
data/lib/oydid.rb
CHANGED
|
@@ -1367,6 +1367,44 @@ class Oydid
|
|
|
1367
1367
|
end
|
|
1368
1368
|
end
|
|
1369
1369
|
|
|
1370
|
+
# Verification relationships in the payload either name a key by fragment
|
|
1371
|
+
# ("#key-doc") or embed a whole verification method. Both need the DID
|
|
1372
|
+
# prefixed onto the identifier; an embedded method additionally needs a
|
|
1373
|
+
# controller, which the client cannot supply - the DID is the hash of the
|
|
1374
|
+
# document that would have to contain it, so it is not known while the
|
|
1375
|
+
# document is being written.
|
|
1376
|
+
def self.expand_verification_methods(payload, wd, did)
|
|
1377
|
+
return wd if !payload.is_a?(Hash)
|
|
1378
|
+
|
|
1379
|
+
[ "authentication",
|
|
1380
|
+
"assertionMethod",
|
|
1381
|
+
"keyAgreement",
|
|
1382
|
+
"capabilityInvocation",
|
|
1383
|
+
"capabilityDelegation" ].each do |vm|
|
|
1384
|
+
next if payload[vm].to_s == ""
|
|
1385
|
+
entries = payload[vm]
|
|
1386
|
+
entries = [entries] if entries.is_a?(Hash) || entries.is_a?(String)
|
|
1387
|
+
|
|
1388
|
+
new_entries = []
|
|
1389
|
+
entries.each do |el|
|
|
1390
|
+
if el.is_a?(String)
|
|
1391
|
+
new_entries << percent_encode(did) + el
|
|
1392
|
+
else
|
|
1393
|
+
new_el = el.transform_keys(&:to_s)
|
|
1394
|
+
new_el["id"] = percent_encode(did) + new_el["id"].to_s
|
|
1395
|
+
if new_el["controller"].to_s == ""
|
|
1396
|
+
new_el["controller"] = percent_encode(did)
|
|
1397
|
+
end
|
|
1398
|
+
new_entries << new_el
|
|
1399
|
+
end
|
|
1400
|
+
end
|
|
1401
|
+
|
|
1402
|
+
wd[vm] = new_entries.length > 0 ? new_entries : payload[vm]
|
|
1403
|
+
payload.delete(vm)
|
|
1404
|
+
end
|
|
1405
|
+
wd
|
|
1406
|
+
end
|
|
1407
|
+
|
|
1370
1408
|
def self.w3c(did_info, options)
|
|
1371
1409
|
# check if doc is already W3C DID
|
|
1372
1410
|
is_already_w3c_did = (did_info.transform_keys(&:to_s)["doc"]["doc"].has_key?("@context") &&
|
|
@@ -1527,6 +1565,10 @@ class Oydid
|
|
|
1527
1565
|
if location.nil?
|
|
1528
1566
|
location = get_location(did_info["did"].to_s)
|
|
1529
1567
|
end
|
|
1568
|
+
# a payload carrying a service used to skip the handling below
|
|
1569
|
+
# entirely and get merged verbatim, which left fragment identifiers
|
|
1570
|
+
# unresolved and embedded methods without a controller
|
|
1571
|
+
wd = expand_verification_methods(didDoc["doc"], wd, did)
|
|
1530
1572
|
wd = wd.merge(didDoc["doc"])
|
|
1531
1573
|
if wd["service"] != []
|
|
1532
1574
|
if wd["service"].is_a?(Array)
|
|
@@ -1547,33 +1589,7 @@ class Oydid
|
|
|
1547
1589
|
if didDoc["doc"].is_a?(Hash)
|
|
1548
1590
|
if didDoc["doc"] != {}
|
|
1549
1591
|
didDoc = didDoc["doc"]
|
|
1550
|
-
|
|
1551
|
-
vms = [ "authentication",
|
|
1552
|
-
"assertionMethod",
|
|
1553
|
-
"keyAgreement",
|
|
1554
|
-
"capabilityInvocation",
|
|
1555
|
-
"capabilityDelegation" ]
|
|
1556
|
-
|
|
1557
|
-
vms.each do |vm|
|
|
1558
|
-
if didDoc[vm].to_s != ""
|
|
1559
|
-
new_entries = []
|
|
1560
|
-
didDoc[vm].each do |el|
|
|
1561
|
-
if el.is_a?(String)
|
|
1562
|
-
new_entries << percent_encode(did) + el
|
|
1563
|
-
else
|
|
1564
|
-
new_el = el.transform_keys(&:to_s)
|
|
1565
|
-
new_el["id"] = percent_encode(did) + new_el["id"]
|
|
1566
|
-
new_entries << new_el
|
|
1567
|
-
end
|
|
1568
|
-
end unless didDoc[vm].nil?
|
|
1569
|
-
if new_entries.length > 0
|
|
1570
|
-
wd[vm] = new_entries
|
|
1571
|
-
else
|
|
1572
|
-
wd[vm] = didDoc[vm]
|
|
1573
|
-
end
|
|
1574
|
-
didDoc.delete(vm)
|
|
1575
|
-
end
|
|
1576
|
-
end
|
|
1592
|
+
wd = expand_verification_methods(didDoc, wd, did)
|
|
1577
1593
|
if didDoc["alsoKnownAs"].to_s != ""
|
|
1578
1594
|
if didDoc["alsoKnownAs"].is_a?(Array)
|
|
1579
1595
|
dda = didDoc["alsoKnownAs"]
|
data/spec/oydid_spec.rb
CHANGED
|
@@ -528,4 +528,60 @@ describe "OYDID handling" do
|
|
|
528
528
|
end
|
|
529
529
|
end
|
|
530
530
|
|
|
531
|
+
# W3C conversion of verification relationships carried in the payload
|
|
532
|
+
describe "verification relationships in the payload" do
|
|
533
|
+
let(:did) { "did:oyd:zQmaBZTghndXTgxNwfbdpVLWdFf6faYE4oeuN2zzXdQt1kh" }
|
|
534
|
+
let(:keys) do
|
|
535
|
+
"z6MktULudTtAsAhRegYPiZ6631RV3viv12qd4GQF8z1xB22S:" \
|
|
536
|
+
"z6MkqGC3nWZhYieEVTVDKW5v588CiGfsDSmRVG9ZwwWTvLSK"
|
|
537
|
+
end
|
|
538
|
+
let(:attestation) do
|
|
539
|
+
{ "id" => "#key-attest",
|
|
540
|
+
"type" => "Ed25519VerificationKey2020",
|
|
541
|
+
"publicKeyMultibase" => "z6Mkg49NtQR2LyYRDCQFK4w1VVHqhypZSSRo7HsyuN7SV7v5" }
|
|
542
|
+
end
|
|
543
|
+
|
|
544
|
+
def convert(payload)
|
|
545
|
+
Oydid.w3c({ "did" => did, "doc" => { "doc" => payload, "key" => keys } }, {})
|
|
546
|
+
end
|
|
547
|
+
|
|
548
|
+
it "prefixes the DID onto a key named by fragment" do
|
|
549
|
+
wd = convert({ "authentication" => ["#key-doc"] })
|
|
550
|
+
expect(wd["authentication"]).to eq ["#{did}#key-doc"]
|
|
551
|
+
end
|
|
552
|
+
|
|
553
|
+
it "prefixes the DID onto an embedded verification method" do
|
|
554
|
+
wd = convert({ "assertionMethod" => [attestation] })
|
|
555
|
+
expect(wd["assertionMethod"].first["id"]).to eq "#{did}#key-attest"
|
|
556
|
+
end
|
|
557
|
+
|
|
558
|
+
# a client cannot supply the controller: the DID is the hash of the
|
|
559
|
+
# document that would contain it
|
|
560
|
+
it "fills in the controller of an embedded verification method" do
|
|
561
|
+
wd = convert({ "assertionMethod" => [attestation] })
|
|
562
|
+
expect(wd["assertionMethod"].first["controller"]).to eq did
|
|
563
|
+
end
|
|
564
|
+
|
|
565
|
+
it "keeps a controller the payload already carries" do
|
|
566
|
+
own = attestation.merge("controller" => "did:oyd:zSomeoneElse")
|
|
567
|
+
wd = convert({ "assertionMethod" => [own] })
|
|
568
|
+
expect(wd["assertionMethod"].first["controller"]).to eq "did:oyd:zSomeoneElse"
|
|
569
|
+
end
|
|
570
|
+
|
|
571
|
+
# regression: a payload carrying a service took a different branch and was
|
|
572
|
+
# merged verbatim, leaving fragments unresolved
|
|
573
|
+
it "handles relationships next to a service entry" do
|
|
574
|
+
wd = convert({ "assertionMethod" => [attestation],
|
|
575
|
+
"service" => [{ "id" => "#payload", "type" => "Custom" }] })
|
|
576
|
+
expect(wd["assertionMethod"].first["id"]).to eq "#{did}#key-attest"
|
|
577
|
+
expect(wd["assertionMethod"].first["controller"]).to eq did
|
|
578
|
+
expect(wd["service"]).to be_an(Array)
|
|
579
|
+
end
|
|
580
|
+
|
|
581
|
+
it "accepts a single embedded method that is not wrapped in an array" do
|
|
582
|
+
wd = convert({ "assertionMethod" => attestation })
|
|
583
|
+
expect(wd["assertionMethod"].first["id"]).to eq "#{did}#key-attest"
|
|
584
|
+
end
|
|
585
|
+
end
|
|
586
|
+
|
|
531
587
|
end
|