3id-resolver 中文文档教程

发布于 3年前 浏览 26 项目主页 更新于 3年前

3ID Resolver

该库旨在解析 3ID DID 文档。 3ID 是一种瘦身份协议,它使用 ipfs 和以太坊来发布和轮换身份使用的加密密钥。

它支持来自 Decentralized Identifiers 规范的提议.io">W3C 凭证社区组。

它需要 did-resolver 库,这是解析 DID 的主要接口。

Resolving a DID document

通过将 IPFS 实例传递给 getResolver() 函数来创建 3ID 解析器。 要使用返回的解析器,它必须在实例化期间传递给 did-resolver 实例,例如:

import { Resolver } from 'did-resolver'
import { getResolver } from '3id-resolver'

const threeIdResolver = getResolver(ipfs)
const resolver = new Resolver(threeIdResolver)

resolver.resolve('did:3:QmRhjfL4HLdB8LovGf1o43NJ8QnbfqmpdnTuBvZTewnuBV').then(doc => console.log)

// You can also use ES7 async/await syntax
const doc = await resolver.resolve('did:muport:zdpuAt4qH8ur3vHpVrP1xb7rtJuyVUVbRiGatkkVcJZRgAXDf')

参见 did-resolver docs 获取有关 DID 解析器的更多一般使用信息。

结果:

{
  '@context': 'https://w3id.org/did/v1',
  id: 'did:3:zdpuAt4qH8ur3vHpVrP1xb7rtJuyVUVbRiGatkkVcJZRgAXDf',
  publicKeys: [ {
    id: 'did:3:zdpuAt4qH8ur3vHpVrP1xb7rtJuyVUVbRiGatkkVcJZRgAXDf#signingKey',
    type: 'Secp256k1VerificationKey2018',
    publicKeyHex: '03fdd57adec3d438ea237fe46b33ee1e016eda6b585c3e27ea66686c2ea5358479'
  }, {
    id: 'did:3:zdpuAt4qH8ur3vHpVrP1xb7rtJuyVUVbRiGatkkVcJZRgAXDf#encryptionKey',
    type: 'Curve25519EncryptionPublicKey',
    publicKeyBase64: 'fake encryptionKey'
  }, {
    id: 'did:3:zdpuAt4qH8ur3vHpVrP1xb7rtJuyVUVbRiGatkkVcJZRgAXDf#managementKey',
    type: 'Secp256k1VerificationKey2018',
    ethereumAddress: 'fake eth addr'
  }],
  authentication: [{
    type: 'Secp256k1SignatureAuthentication2018',
    publicKey: 'did:3:zdpuAt4qH8ur3vHpVrP1xb7rtJuyVUVbRiGatkkVcJZRgAXDf#signingKey'
  }]
}

Maintainers

@oed

3ID Resolver

This library is intended to resolve 3ID DID documents. 3ID is a thin identity protocol that uses ipfs and ethereum to publish and rotate the cryptographic keys used by an identity.

It supports the proposed Decentralized Identifiers spec from the W3C Credentials Community Group.

It requires the did-resolver library, which is the primary interface for resolving DIDs.

Resolving a DID document

A 3ID resolver is created by passing an IPFS instance to the getResolver() function. To use the resolver returned, it must be passed to a did-resolver instance during instantiation, for example:

import { Resolver } from 'did-resolver'
import { getResolver } from '3id-resolver'

const threeIdResolver = getResolver(ipfs)
const resolver = new Resolver(threeIdResolver)

resolver.resolve('did:3:QmRhjfL4HLdB8LovGf1o43NJ8QnbfqmpdnTuBvZTewnuBV').then(doc => console.log)

// You can also use ES7 async/await syntax
const doc = await resolver.resolve('did:muport:zdpuAt4qH8ur3vHpVrP1xb7rtJuyVUVbRiGatkkVcJZRgAXDf')

See the did-resolver docs for more general usage information on DID resolvers.

Result:

{
  '@context': 'https://w3id.org/did/v1',
  id: 'did:3:zdpuAt4qH8ur3vHpVrP1xb7rtJuyVUVbRiGatkkVcJZRgAXDf',
  publicKeys: [ {
    id: 'did:3:zdpuAt4qH8ur3vHpVrP1xb7rtJuyVUVbRiGatkkVcJZRgAXDf#signingKey',
    type: 'Secp256k1VerificationKey2018',
    publicKeyHex: '03fdd57adec3d438ea237fe46b33ee1e016eda6b585c3e27ea66686c2ea5358479'
  }, {
    id: 'did:3:zdpuAt4qH8ur3vHpVrP1xb7rtJuyVUVbRiGatkkVcJZRgAXDf#encryptionKey',
    type: 'Curve25519EncryptionPublicKey',
    publicKeyBase64: 'fake encryptionKey'
  }, {
    id: 'did:3:zdpuAt4qH8ur3vHpVrP1xb7rtJuyVUVbRiGatkkVcJZRgAXDf#managementKey',
    type: 'Secp256k1VerificationKey2018',
    ethereumAddress: 'fake eth addr'
  }],
  authentication: [{
    type: 'Secp256k1SignatureAuthentication2018',
    publicKey: 'did:3:zdpuAt4qH8ur3vHpVrP1xb7rtJuyVUVbRiGatkkVcJZRgAXDf#signingKey'
  }]
}

Maintainers

@oed

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文