Skip to content

feat: did rpc#348

Merged
weichweich merged 38 commits intodevelopfrom
aw-did-rpc
Jun 28, 2022
Merged

feat: did rpc#348
weichweich merged 38 commits intodevelopfrom
aw-did-rpc

Conversation

@weichweich
Copy link
Contributor

@weichweich weichweich commented Apr 1, 2022

fixes #2016

  • add rpc endpoints to query DID information

todo:

  • RPC methods not decorated
  • service endpoints
  • query by did

Examples

query using did

❯ curl -s -H "Content-Type: application/json" -d '{"id":1, "jsonrpc":"2.0", "method": "did_query", "params":["5FKxrLQM24ZhLxcaQfJR3uMxMZh5gU6E4CP3yghPJLzCDnHN"]}' http://127.0.0.1:19933/ | jq
Response
{
  "jsonrpc": "2.0",
  "result": {
    "accounts": [
      "5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY"
    ],
    "details": {
      "attestation_key": null,
      "authentication_key": "0x15ba41bf8842ae185ae06110a63e6cc7ac36d8a8ea217746231bef46c1379ab1",
      "delegation_key": null,
      "deposit": {
        "amount": "2007900000000000",
        "owner": "5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY"
      },
      "key_agreement_keys": [],
      "last_tx_counter": 3,
      "public_keys": {
        "0x15ba41bf8842ae185ae06110a63e6cc7ac36d8a8ea217746231bef46c1379ab1": {
          "block_number": 120,
          "key": {
            "PublicVerificationKey": {
              "Sr25519": "5FKxrLQM24ZhLxcaQfJR3uMxMZh5gU6E4CP3yghPJLzCDnHN"
            }
          }
        }
      }
    },
    "identifier": "5FKxrLQM24ZhLxcaQfJR3uMxMZh5gU6E4CP3yghPJLzCDnHN",
    "service_endpoints": [
      {
        "id": "123",
        "service_types": [
          "twitter"
        ],
        "urls": [
          "example.com"
        ]
      }
    ],
    "w3n": "alice-0"
  },
  "id": 1
}

query using w3n

❯ curl -s -H "Content-Type: application/json" -d '{"id":1, "jsonrpc":"2.0", "method": "did_queryByWeb3Name", "params":["alice-0"]}' http://127.0.0.1:19933/ | jq
Response
{
  "jsonrpc": "2.0",
  "result": {
    "accounts": [
      "5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY"
    ],
    "details": {
      "attestation_key": null,
      "authentication_key": "0x15ba41bf8842ae185ae06110a63e6cc7ac36d8a8ea217746231bef46c1379ab1",
      "delegation_key": null,
      "deposit": {
        "amount": "2007900000000000",
        "owner": "5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY"
      },
      "key_agreement_keys": [],
      "last_tx_counter": 3,
      "public_keys": {
        "0x15ba41bf8842ae185ae06110a63e6cc7ac36d8a8ea217746231bef46c1379ab1": {
          "block_number": 120,
          "key": {
            "PublicVerificationKey": {
              "Sr25519": "5FKxrLQM24ZhLxcaQfJR3uMxMZh5gU6E4CP3yghPJLzCDnHN"
            }
          }
        }
      }
    },
    "identifier": "5FKxrLQM24ZhLxcaQfJR3uMxMZh5gU6E4CP3yghPJLzCDnHN",
    "service_endpoints": [
      {
        "id": "123",
        "service_types": [
          "twitter"
        ],
        "urls": [
          "example.com"
        ]
      }
    ],
    "w3n": "alice-0"
  },
  "id": 1
}

query using linked account

❯ curl -s -H "Content-Type: application/json" -d '{"id":1, "jsonrpc":"2.0", "method": "did_queryByAccount", "params":["5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY"]}' http://127.0.0.1:19933/ | jq
Response
{
  "jsonrpc": "2.0",
  "result": {
    "accounts": [
      "5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY"
    ],
    "details": {
      "attestation_key": null,
      "authentication_key": "0x15ba41bf8842ae185ae06110a63e6cc7ac36d8a8ea217746231bef46c1379ab1",
      "delegation_key": null,
      "deposit": {
        "amount": "2007900000000000",
        "owner": "5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY"
      },
      "key_agreement_keys": [],
      "last_tx_counter": 3,
      "public_keys": {
        "0x15ba41bf8842ae185ae06110a63e6cc7ac36d8a8ea217746231bef46c1379ab1": {
          "block_number": 120,
          "key": {
            "PublicVerificationKey": {
              "Sr25519": "5FKxrLQM24ZhLxcaQfJR3uMxMZh5gU6E4CP3yghPJLzCDnHN"
            }
          }
        }
      }
    },
    "identifier": "5FKxrLQM24ZhLxcaQfJR3uMxMZh5gU6E4CP3yghPJLzCDnHN",
    "service_endpoints": [
      {
        "id": "123",
        "service_types": [
          "twitter"
        ],
        "urls": [
          "example.com"
        ]
      }
    ],
    "w3n": "alice-0"
  },
  "id": 1
}

Checklist:

  • I have verified that the code works
    • No panics! (checked arithmetic ops, no indexing array[3] use get(3), ...)
  • I have verified that the code is easy to understand
    • If not, I have left a well-balanced amount of inline comments
  • I have left the code in a better state
  • I have documented the changes (where applicable)

@weichweich weichweich self-assigned this Apr 1, 2022
@weichweich weichweich changed the title Aw did rpc did rpc Apr 1, 2022
@weichweich weichweich changed the title did rpc feat: did rpc Apr 21, 2022
Copy link
Contributor Author

@weichweich weichweich left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Had to touch a lot of files unfortunately.

  • all fields in DidDetails should be public. How should dependent crates use this? Create getters for everything and clone each part!?
  • updated the dependencies
  • fixed some features

}
}

/// Verify that a given slice can be used as a web3 name.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reordered to keep the impl blocks together

sp-consensus-aura = {git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.19", default-features = false}
sp-core = {git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.19", default-features = false}
sp-io = {git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.19", default-features = false}
pallet-aura = {git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.19"}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

default-features = false is not needed and should not be used in dev-dependencies

}

#[cfg(feature = "std")]
impl<T, S> fmt::Debug for OrderedSet<T, S>
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can derive RuntimeDebug. No need to implement that our self

@weichweich weichweich marked this pull request as ready for review April 27, 2022 15:41
@weichweich weichweich requested review from ntn-x2, trusch and wischli and removed request for ntn-x2 and wischli April 28, 2022 15:34
@tjwelde
Copy link
Contributor

tjwelde commented Apr 28, 2022

Add an example please

Copy link
Contributor

@ntn-x2 ntn-x2 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Didn't look thoroughly into it. I just had few personal opinions.

}
}

impl did_rpc_runtime_api::DidApi<
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since it's used in all runtimes, why don't we move it into common? So far we have the same features deployed in all runtimes.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah it's a huge chunk of code. I would like to slim it down a bit but wasn't sure how.
The issue is, since it's implemented for the runtime you can't move it out there.
The impl also has to be in the impl_runtime_apis! block.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I could move the following to commons since it's shared between all queries.

let accounts = pallet_did_lookup::ConnectedAccounts::<Runtime>::iter_key_prefix(&owner_info.owner).collect();
let service_endpoints = did::ServiceEndpoints::<Runtime>::iter_prefix(&owner_info.owner).map(|e|From::from(e.1)).collect();
did_rpc_runtime_api::RawDidDocument {
  identifier: owner_info.owner,
  w3n: Some(name.into()),
  accounts,
  service_endpoints,
  details: details.into(),
}

@weichweich weichweich mentioned this pull request Apr 29, 2022
5 tasks
Copy link
Contributor

@wischli wischli left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apart from the renaming of DidDocument, for which I don't have a strong opinion, and moving some code to common, it LGTM!

weichweich and others added 2 commits May 2, 2022 08:07
Co-authored-by: William Freudenberger <william@kilt.io>
DidDocument is overloaded
@wischli wischli added the next release This PR is required for the next release. label May 30, 2022
Copy link
Contributor

@ntn-x2 ntn-x2 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Amazingly written code... especially from a certain point on..... 🙏

@weichweich weichweich enabled auto-merge (squash) June 28, 2022 12:04
@weichweich weichweich merged commit 2964f6c into develop Jun 28, 2022
@weichweich weichweich deleted the aw-did-rpc branch June 28, 2022 12:48
@wischli wischli removed the next release This PR is required for the next release. label Sep 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants