Example #1
0
def test_generic_verification_method_has_props():
    vmethod = VerificationMethod(
        id="did:example:123#test",
        type="MyVerificationMethod",
        controller="did:example:123",
        publicKeyExample="test",
    )
    assert hasattr(vmethod, "publicKeyExample")
    assert "publicKeyExample" in vmethod.serialize()
Example #2
0
def test_deserialize_x_multiple_material_properties():
    with pytest.raises(ValueError):
        VerificationMethod.deserialize(
            {
                "id": "did:example:123#vm-3",
                "controller": "did:example:123",
                "type": "EcdsaSecp256k1RecoveryMethod2020",
                "blockchainAccountId": (
                    "0xab16a96d359ec26a11e2c2b3d8f8b8942d5bfcdb@eip155:1"
                ),
                "publicKeyBase58": "abc123",
            }
        )
Example #3
0
def test_validator_allow_missing_controller():
    vmethod = VerificationMethod.deserialize(
        {
            "id": "did:example:123#keys-1",
            "type": "Ed25519Signature2018",
            "publicKeyBase58": "12345",
        },
    )
    assert vmethod.controller == "did:example:123"
    with pytest.raises(ValueError):
        vmethod = VerificationMethod.deserialize(
            {
                "type": "Ed25519Signature2018",
                "publicKeyBase58": "12345",
            },
        )
Example #4
0
def test_infer_material():
    vmethod_raw = {
        "id": "did:example:123#vm-3",
        "controller": "did:example:123",
        "type": "EcdsaSecp256k1RecoveryMethod2020",
        "blockchainAccountId": "0xab16a96d359ec26a11e2c2b3d8f8b8942d5bfcdb@eip155:1",
    }
    vmethod = VerificationMethod.deserialize(vmethod_raw)
    assert vmethod.material == vmethod_raw["blockchainAccountId"]
Example #5
0
def test_validator_allow_controller_list():
    vmethod = VerificationMethod.deserialize(
        {
            "id": "did:example:123#keys-1",
            "type": "Ed25519Signature2018",
            "controller": ["did:example:123"],
            "publicKeyBase58": "12345",
        },
    )
    assert vmethod.controller == "did:example:123"
Example #6
0
def test_suite_creation():
    MyVerificationMethod = VerificationMethod.suite(
        "MyVerificationMethod", "publicKeyExample", str
    )
    vmethod = MyVerificationMethod(
        id="did:example:123#test",
        type="MyVerificationMethod",
        controller="did:example:123",
        public_key_example="test",
    )
    assert vmethod.material == "test"
Example #7
0
def test_unknown_material():
    vmethod = VerificationMethod.deserialize(
        {
            "id": "did:example:123#vm-3",
            "controller": "did:example:123",
            "type": "EcdsaSecp256k1RecoveryMethod2020",
            "unknownMaterial": "0xab16a96d359ec26a11e2c2b3d8f8b8942d5bfcdb@eip155:1",
        }
    )
    with pytest.raises(VerificationMaterialUnknown):
        vmethod.material
Example #8
0
def test_make():
    did = DID("did:example:123")
    kwargs = {"id": did.ref("1"), "controller": did, "public_key_base58": "test"}
    vmethod = Ed25519VerificationKey2018.make(**kwargs)
    assert "publicKeyBase58" in vmethod.serialize()

    class ExampleVerificationMethod(VerificationMethod):
        type: Literal["Example"]
        public_key_base58: str

    vmethod = ExampleVerificationMethod.make(**kwargs)
    assert "publicKeyBase58" in vmethod.serialize()

    ExampleVerificationMethod = VerificationMethod.suite(
        "Example", "publicKeyBase58", str
    )

    vmethod = ExampleVerificationMethod.make(**kwargs)
    assert "publicKeyBase58" in vmethod.serialize()
Example #9
0
def test_deserialized_member_types():
    vmethod = VerificationMethod.deserialize(VMETHOD0)
    assert isinstance(vmethod.id, DIDUrl)
    assert isinstance(vmethod.controller, DID)
Example #10
0
def test_serialization_x(invalid_vmethod_raw):
    with pytest.raises(ValueError):
        VerificationMethod.deserialize(invalid_vmethod_raw)
Example #11
0
def test_serialization(vmethod_raw):
    vmethod = VerificationMethod.deserialize(vmethod_raw)
    assert vmethod.id == DIDUrl.parse(vmethod_raw["id"])
    assert vmethod.type == vmethod_raw["type"]
    assert vmethod.controller == DID(vmethod_raw["controller"])
    assert vmethod.serialize() == vmethod_raw