实现一套 DID 之总体设计 | Move dApp 极速入门(五)

  • 李大狗
  • 更新于 2023-08-21 16:06
  • 阅读 601

从本篇开始,我们将通过一个实战案例更深入的讲解 MOVE 语言以及 MOVE dApp 的开发 ——这也是 MOVE 生态上的首个 DID 的实现。

前文链接:

合约数据类型综述 | Move dApp 极速入门(四)

操作资源 | Move dApp极速入门(三)

第一个 Move dApp | Move dApp极速入门(二)

Hello Move | Move dApp极速入门(一)

在之前的文章里,我们通过精简的方式对 MOVE 语言以及 Starcoin dApp 开发进行了快速入门。

从本篇开始,我们将通过一个实战案例更深入的讲解 MOVE 语言以及 MOVE dApp 的开发 ——这也是 MOVE 生态上的首个 DID 的实现。

0x01 DID & Verifiable Credential 科普

DID 是由 w3c 推出的数字身份协议。

Decentralized identifiers (DIDs) are a new type of identifier that enables verifiable, decentralized digital identity. A DID refers to any subject (e.g., a person, organization, thing, data model, abstract entity, etc.) as determined by the controller of the DID.

Verifiable Credential 是由 w3c 推出的可验证凭证协议。

Credentials are a part of our daily lives; driver's licenses are used to assert that we are capable of operating a motor vehicle, university degrees can be used to assert our level of education, and government-issued passports enable us to travel between countries. This specification provides a mechanism to express these sorts of credentials on the Web in a way that is cryptographically secure, privacy respecting, and machine-verifiable.

在现有的实践中,二者经常被一同实践。但实际上,这两套协议也并非绑定的,我们完全可以用 DID + SBT来替代DID + VC

0x02 设计思路

像羽毛一样轻。

一个MVP(最小可用版本)的 DID 至少包含如下几个组成部分:

  • DID Syntax(DID 标识符)

    https\://www.w3.org/TR/did-core/#did-syntax

  • DID Document in JSON(JSON 格式的 DID 描述文档)

    • Address Aggregator 地址聚合器
    • Endpoint Aggregator 终端服务聚合器

在进行任意的 dApp 实践的时候,设计者都首先要问自己一个问题:

把哪些部分放到链上?把哪些部分放到链下?

这个问题遵循一个即可:

让链上设计尽可能的轻

以 DID 为例,我们可以看到很多 DID 的实现都会把链上搞得过重。事实上,对于 MVP 版本来说,我们在链上实现如下两个模块即可:

  • Addr Aggregator:地址的增删改查
  • Endpoint Addrgator:终端服务的增删改查

然后我们会在链下实现一个 did_sdk,里面包含如下模块:

  • Contract Interactor:和链上合约进行交互
  • DID Handler:将链上数据转化为符合 w3c 标准的格式

0x03 系统架构

DID & VC based SBT 

包含如下三个层级:

  • dApp 层:一个简单的对 DID 应用的 dApp 的实现
  • VC 层:基于 SBT 的可验证凭证的实现
  • 通用 DID 层:通用 DID 的实现

0x04 文件结构

本项目持续 buidl 中,完全开源:

https://github.com/WeLightProject/DID-Solution-In-Move

文件结构如下

.
├── README.md
├── did
│   ├── Move.toml
│   ├── README.md
│   ├── build
│   ├── dapp
│   ├── release
│   └── sources
├── sbt-as-vc
│   ├── Move.toml
│   ├── README.md
│   ├── build
│   ├── dapp
│   ├── release
│   └── sources
└── did_handler
    ├── README.md
    ├── _build
    ├── deps
    ├── lib
    ├── mix.exs
    ├── mix.lock
    └── test

其中,didsbt-as-vc包含 MOVE 合约及纯前端 dApp,did_handler 是使用 elixir 语言实现的 SDK。

点赞 0
收藏 0
分享
本文参与登链社区写作激励计划 ,好文好收益,欢迎正在阅读的你也加入。

0 条评论

请先 登录 后评论
李大狗
李大狗
0x73c7...6A1d
面向炫酷编程