基于区块链的毕业设计ethr-status-registry – ethr状态注册表

本文提供基于区块链的毕业设计国外最新区块链项目源码下载,包括solidity,eth,fabric等blockchain区块链,基于区块链的毕业设计ethr-status-registry – ethr状态注册表 是一篇很好的国外资料

ethr-status-registry

Verifiable Credential status resolver using an ethereum contract as registry

This library can check the revocation status of a credential against a registry deployed as an ethereum smart contract. This library only supports credentials that embed a credentialStatus field.

Usage

Check credential status

Normally, this is used in conjunction with the credential-status library, so besides configuring it there’s not much else to do. If your use-case requires direct verification it can also be used independently:

const statusReg = new EthrStatusRegistry(config)  //... obtain issuer DID document either from `did-jwt`->`verifyJWT` or `did-resolver` -> `resolve()` const revocationStatus = await statusReg.checkStatus(token, didDocument) // {revoked : false}

Config

There is an easy way to use an infuraProjectId to quickly configure it for the popular public ethereum networks.

import { EthrStatusRegistry } from 'ethr-status-registry' import { Status } from 'credential-status'  const status = new Status({     ...new EthrStatusRegistry({infuraProjectId: 'YOUR Infura PROJECT ID HERE'}).asStatusMethod, })

You can also use your own web3 providers and can specify your own custom networks:

new EthrStatusRegistry({   networks: [     { name: 'mainnet', rpcUrl: 'http://127.0.0.1:8545' },     { name: 'rinkeby', rpcUrl: 'rinkeby.example.com' },     { name: 'customNetwork', provider: new JsonRpcProvider('http://custom.network:8545') }   ] })

Revoke a credential

A credential can be revoked by anyone, but the convention is that issuer controlled ethereumAddresses are considered valid revokers. An issuer controlled ethereumAddress appears as one of the PublicKey entries in the DID document of the issuer of the credential.

import { EthrCredentialRevoker } from 'ethr-status-registry' import { sign } from `ethjs-signer`  const privateKey = '0x<Issuer Private Key>' const ethSigner = (rawTx: any, cb: any) => cb(null, sign(rawTx, privateKey))  const credential = '<JWT token with credentialStatus>' const revoker = new EthrCredentialRevoker({ infuraProjectId: '<Your infura project ID>' }) const txHash = await revoker.revoke(credential, ethSigner)

after the transaction gets mined, the credential is considered revoked.

Example

An example JWT that includes a credentialStatus field:

eyJ0eXAiOiJKV1QiLCJhbGciOiJFUzI1NksifQ.eyJpYXQiOjE1ODg5MjIyMDEsImNyZWRlbnRpYWx TdGF0dXMiOnsidHlwZSI6IkV0aHJTdGF0dXNSZWdpc3RyeTIwMTkiLCJpZCI6InJpbmtlYnk6MHg5N2 ZkMjc4OTJjZGNEMDM1ZEFlMWZlNzEyMzVjNjM2MDQ0QjU5MzQ4In0sImlzcyI6ImRpZDpldGhyOjB4N TRkNTllM2ZmZDc2OTE3ZjYyZGI3MDJhYzM1NGIxN2YzODQyOTU1ZSJ9.0sLZupOnyrdZPQAhtfa2eP_ 2HN_FELJu_clbXBrk9SgaU_ZO0izjDLTnNkip9RVM6ED0nLznfT35XHk6_C9S_Q 

The payload of this token decodes like this:

{   "credentialStatus": {     "type": "EthrStatusRegistry2019",     "id": "rinkeby:0x97fd27892cdcD035dAe1fe71235c636044B59348"   },   "iss": "did:ethr:0x54d59e3ffd76917f62db702ac354b17f3842955e",   //... }

This is based on the credentialStatus proposal in the W3C spec.

The issuer of this credential (iss) has a DID document that contains a publicKey entry like so:

{   "type": "Secp256k1VerificationKey2018",   "ethereumAddress": "0x54d59e3ffd76917f62db702ac354b17f3842955e"   //... }

which is considered to be a valid revoker.

How this works

The credentialStatus entry embedded in the payload tells the credential-status library that this credential revocation status can be checked using the EthrStatusRegistry2019 implementation. This library provides such an implementation and maps it to the correct method (EthrStatusRegistry2019) through the asStatusMethod property.

Next, this library interprets the status field, extracting the registry address 0x97fd27892cdcD035dAe1fe71235c636044B59348 and the network name rinkeby where the contract should exist.

Next, it computes a keccak hash of the credential and gathers ethereumAddress entries from the issuer DID document It uses these params to call the revoked() method of the contract and obtain a revocation result.

Notes

Consider this a draft implementation since many of the standards are still in development.

Limitations

  • it supports only ethereumAddress entries from the provided DID document
  • the library returns a boolean result, so it’s not easy to learn the time of revocation. This will probably be fixed in a future version of the lib.

Potential improvements

  • use secp256k1 publicKey entries and automatically compute their corresponding ethereumAddress as valid revokers
  • provide a credentialStatus entry that can override or augment the entry embedded in credentials.
  • also, there may be default registries deployed so that credentials don’t have to specify their own.

Other improvement proposals are welcome.

We use optional third-party analytics cookies to understand how you use GitHub.com so we can build better products. Learn more.


ethr状态注册表

使用以太坊eth合约作为注册表的可验证凭证状态解析程序

此库可以对照部署为以太坊eth智能合约的注册表检查凭证的吊销状态。此库仅支持嵌入credentialStatus字段的凭据。

使用情况

检查凭据状态

通常,这是与凭证状态库一起使用的,因此除了配置它之外,没有太多其他事情要做。如果您的用例需要直接验证,也可以独立使用:

const statusReg = new EthrStatusRegistry(config)  //... obtain issuer DID document either from `did-jwt`->`verifyJWT` or `did-resolver` -> `resolve()` const revocationStatus = await statusReg.checkStatus(token, didDocument) // {revoked : false}

配置

有一种简单的方法可以使用infuraProjectId为流行的公共以太坊eth网络快速配置它。

import { EthrStatusRegistry } from 'ethr-status-registry' import { Status } from 'credential-status'  const status = new Status({     ...new EthrStatusRegistry({infuraProjectId: 'YOUR Infura PROJECT ID HERE'}).asStatusMethod, })

您还可以使用自己的web3提供程序,并可以指定自己的自定义网络:

new EthrStatusRegistry({   networks: [     { name: 'mainnet', rpcUrl: 'http://127.0.0.1:8545' },     { name: 'rinkeby', rpcUrl: 'rinkeby.example.com' },     { name: 'customNetwork', provider: new JsonRpcProvider('http://custom.network:8545') }   ] })

吊销凭据的示例

任何人都可以吊销凭据,但惯例是,颁发者控制的以太坊eth地址被视为有效的吊销者。颁发者控制的以太坊eth地址显示为凭证颁发者的DID文档中的公钥条目之一。

import { EthrCredentialRevoker } from 'ethr-status-registry' import { sign } from `ethjs-signer`  const privateKey = '0x<Issuer Private Key>' const ethSigner = (rawTx: any, cb: any) => cb(null, sign(rawTx, privateKey))  const credential = '<JWT token with credentialStatus>' const revoker = new EthrCredentialRevoker({ infuraProjectId: '<Your infura project ID>' }) const txHash = await revoker.revoke(credential, ethSigner)

在挖掘事务后,凭证被视为已吊销。

如何工作

一个包含credentialStatus字段的JWT示例:

eyJ0eXAiOiJKV1QiLCJhbGciOiJFUzI1NksifQ.eyJpYXQiOjE1ODg5MjIyMDEsImNyZWRlbnRpYWx TdGF0dXMiOnsidHlwZSI6IkV0aHJTdGF0dXNSZWdpc3RyeTIwMTkiLCJpZCI6InJpbmtlYnk6MHg5N2 ZkMjc4OTJjZGNEMDM1ZEFlMWZlNzEyMzVjNjM2MDQ0QjU5MzQ4In0sImlzcyI6ImRpZDpldGhyOjB4N TRkNTllM2ZmZDc2OTE3ZjYyZGI3MDJhYzM1NGIxN2YzODQyOTU1ZSJ9.0sLZupOnyrdZPQAhtfa2eP_ 2HN_FELJu_clbXBrk9SgaU_ZO0izjDLTnNkip9RVM6ED0nLznfT35XHk6_C9S_Q 

此令牌的有效负载按如下方式解码:

{   "credentialStatus": {     "type": "EthrStatusRegistry2019",     "id": "rinkeby:0x97fd27892cdcD035dAe1fe71235c636044B59348"   },   "iss": "did:ethr:0x54d59e3ffd76917f62db702ac354b17f3842955e",   //... }

这基于W3C规范中的credentialStatus建议。

此凭证(iss)的颁发者有一个DID文档,其中包含这样的公钥条目:

{   "type": "Secp256k1VerificationKey2018",   "ethereumAddress": "0x54d59e3ffd76917f62db702ac354b17f3842955e"   //... }

,该条目被认为是有效的撤销。

注意事项

负载中嵌入的credentialStatus条目告诉凭证状态库,可以使用EthrStatusRegistry2019实现检查此凭证吊销状态。这个库提供了这样一个实现,并通过asStatusMethod属性将其映射到正确的方法(EthrStatusRegistry2019)。

接下来,此库解释状态字段,提取注册地址0x97fd27892cdcD035dAe1fe71235c636044B59348和合同所在的网络名称rinkeby。

接下来,它计算凭证的keccak散列,并从颁发者DID文档收集以太坊eth地址条目。它使用这些参数调用契约的revoked()方法并获得吊销结果。

限制

由于许多标准仍在开发中,因此将其视为实施草案。

潜在改进

  • 它只支持所提供的DID文档中的以太坊eth地址条目
  • 库返回一个布尔结果,因此不容易了解撤销的时间。这可能会在lib的未来版本中修复。

基本cookies

  • 使用secp256k1 publicKey条目并自动将其对应的以太坊eth地址计算为有效的撤销符
  • 提供一个credentialStatus条目,该条目可以覆盖或扩充嵌入在凭证中的条目。
  • 此外,可能会部署默认注册表,这样凭证就不必指定自己的注册表。在

欢迎提出其他改进建议。

我们使用可选的第三方分析cookies来了解您如何使用GitHub.com网站所以我们可以制造更好的产品。了解更多。

部分转自网络,侵权联系删除区块链源码网

www.interchains.cc

https://www.interchains.cc/18033.html

区块链毕设网(www.interchains.cc)全网最靠谱的原创区块链毕设代做网站 部分资料来自网络,侵权联系删除! 最全最大的区块链源码站 !
区块链知识分享网, 以太坊dapp资源网, 区块链教程, fabric教程下载, 区块链书籍下载, 区块链资料下载, 区块链视频教程下载, 区块链基础教程, 区块链入门教程, 区块链资源 » 基于区块链的毕业设计ethr-status-registry – ethr状态注册表

提供最优质的资源集合

立即查看 了解详情