[][src]Struct caelum_diddoc::DidDoc

pub struct DidDoc { /* fields omitted */ }

Methods

impl DidDoc[src]

pub fn new(context: String, id: String) -> DidDoc[src]

Web assembly Constructor

DidDoc's constructor will create an empty DidDoc object. An empty object is not a valid DidDoc.

import { DidDoc } from 'caelum_diddoc';
let d = new DidDoc("my_context", "my_id");

pub fn default() -> DidDoc[src]

Web assembly Constructor

DidDoc's constructor will create an empty DidDoc object. An empty object is not a valid DidDoc.

import { DidDoc } from 'caelum_diddoc';
let d = DidDoc.default();

pub fn from_json(json: JsValue) -> DidDoc[src]

WebAssembly Constructor formJSON

DidDoc's constructor will create a DidDoc object from input. Input must be a JSON object with all properties defined. If no value is wanted for certain property, must be empty. This is also true for sub properties (properties of properties).

import { DidDoc } from 'caelum_diddoc';
let myDidDoc_json = {
   "@context": [
       "https://www.w3.org/2018/credentials/v1",
       "https://www.w3.org/2018/credentials/examples/v1"
   ],
   "id": "http://example.com/credentials/4643",
   "authentication": [
        {
           "id": "did:example:ebfeb1276e12ec21f712ebc6f1c",
           "type": "OpenIdConnectVersion1.0Service",
           "owner": "OWNER!",
           "PublicKeyBase58": "H3C2AVvLMv6gmMNam3uVAjZpfkcJCwDwnZn6z3wXmqPV"
        },
        "did:lrn:123412341234#my_id"
    ],
   "publicKey": [{
        "id": "did:example:ebfeb1276e12ec21f712ebc6f1c",
        "type": "OpenIdConnectVersion1.0Service",
        "owner": "OWNER!",
        "PublicKeyBase58": "H3C2AVvLMv6gmMNam3uVAjZpfkcJCwDwnZn6z3wXmqPV"
    }],
   "service": [{
        "id": "id",
        "type": "type",
        "serviceEndpoint": "serviceEndpoint"
    }],
   "updated": "1982-02-02-00T00:00Z",
   "created": "1982-02-02-00T00:00Z",
   "proof": {
       "type": "RsaSignature2018",
       "created": "2018-06-17T10:03:48Z",
       "verificationMethod": "did:example:ebfeb1276e12ec21f712ebc6f1c#k1",
       "signatureValue": "pY9...Cky6Ed = "
   }
};
let myDidDoc = DidDoc.fromJSON(myDidDoc_json);

pub fn set_context(self, c: String) -> DidDoc[src]

Set context

Specifications describe a @context as a mandatory field that:

one or more URIs (An identifier as defined by RFC3986.) where the value of the first URI is https://www.w3.org/2019/did/v1. If more than one URI is provided, the URIs MUST be interpreted as an ordered set. It is RECOMMENDED that dereferencing the URIs results in a document containing machine-readable information about the context.

And must follow the following rules:

  1. A DID Document MUST have exactly one top-level context statement.
  2. The key for this property MUST be @context.
  3. The value of this key MUST be the URL for the generic DID context: https://w3id.org/did/v1.

By default context will be set to

{
    @context: [
        "https://www.w3.org/2018/credentials/v1",
        "https://www.w3.org/2018/credentials/examples/v1"
    ]
}

To overwrite default contexts use method setContext() can be used.

import { DidDoc } from 'caelum_diddoc';
let vc = new DidDoc("my_id")
    .setContext("new_context");

pub fn set_id(self, id: String) -> DidDoc[src]

Set Id (Did Subject)

A DID subject goes by the following rules:

  1. A DID Document MUST have exactly one DID subject.
  2. The key for this property MUST be id.
  3. The value of this key MUST be a valid DID.
  4. When this DID Document is registered with the target Decentralized Identifier Registry, the registered DID MUST match this DID subject value.

Similarly to @context, in caelum_diddoc, ids are created in the DidDoc constructor. Users can add an id subject using method add_id(), and can overwrite them using setter set_id(). ids are not array so no adder is implemented, only a setter and a getter.

By default id will be set by the constructor. To overwrite default id use method setId() can be used.

import { DidDoc } from 'caelum_diddoc';
let vc = new DidDoc("my_id")
    .setId("_id");

pub fn set_authentication(self, a: JsValue) -> DidDoc[src]

Set DID Authentication

Following w3's documentation:

Authentication is the mechanism by which a DID subject can cryptographically prove that they are associated with a DID.

The rules for Authentication are:

  1. A DID Document MAY include an authentication property.
  2. The value of the authentication property should be an array of verification methods.
  3. Each verification method MAY be embedded or referenced. An example of a verification method is a public key.

By default authentication is set to an empty object with empty properties (type and publicKey).

let d = new DidDoc("my_context", "my_id")
    .setAuthentication({
           "id": "did:example:ebfeb1276e12ec21f712ebc6f1c",
           "type": "OpenIdConnectVersion1.0Service",
           "owner": "OWNER!",
           "PublicKeyBase58": "H3C2AVvLMv6gmMNam3uVAjZpfkcJCwDwnZn6z3wXmqPV"
    });

pub fn set_public_key(self, p: JsValue) -> DidDoc[src]

Set Public Key

Public keys are used for digital signatures, encryption and other cryptographic operations, which in turn are the basis for purposes such as authentication or establishing secure communication with service endpoints. In addition, public keys may play a role in authorization mechanisms of DID CRUD operations

The rules for public keys are:

  1. A DID Document MAY include a publicKey property.
  2. The value of the publicKey property MUST be an array of public keys, and every public key property MUST be in the Linked Data Cryptographic Suite Registry.
  3. Each public key MUST include id and type properties, and exactly one value property. The array of public keys SHOULD NOT contain duplicate entries with the same id and different value properties with different formats.
  4. Each public key MUST include a controller property, which identifies the controller of the corresponding private key.
  5. A registry of key types and formats is available in Registries .

When creating a publicKey the following fields must be included (empty if not needed):

  1. id
  2. owner
  3. type
  4. A valid key-value (exactly one) encryption method as the key, and the public key corresponding to that encrpytion method, as the value.
let d = new DidDoc("my_context", "my_id")
    .setPublicKey({
        "id": "did:sov:WRfXPg8dantKVubE3HX8pw#key-1",
        "type": "Ed25519VerificationKey2018",
        "owner": "NEW_OWNER",
        "publicKeyBase58": "~P7F3BNs5VmQ6eVpwkNKJ5D"
    });

pub fn set_service(self, s: JsValue) -> DidDoc[src]

Set Service

As w3's documentation explains:

A service endpoint may represent any type of service the subject wishes to advertise, including decentralized identity management services for further discovery, authentication, authorization, or interaction.

The rules for service endpoints are:

  1. A DID Document MAY include a service property.
  2. The value of the service property should be an array of service endpoints.
  3. Each service endpoint must include id, type, and serviceEndpoint properties, and MAY include additional properties.
  4. The service endpoint protocol SHOULD be published in an open standard specification.
  5. The value of the serviceEndpoint property MUST be a JSON-LD object or a valid URI conforming to RFC3986 and normalized according to the rules in section 6 of RFC3986 and to any normalization rules in its applicable URI scheme specification.
let d = new DidDoc("my_context", "my_id")
    .setService({
        "id": "did:ser:18y34b91c612c4123gwrh45y",
        "type": "agent",
        "serviceEndpoint": "https://agents.danubeclouds.com/agent/WRfXPg8dantKVubE3HX8pw"
    });

pub fn set_proof(self, proof: JsValue) -> DidDoc[src]

Set Proof

A proof on a DID Document is cryptographic proof of the integrity of the DID Document according to either:

  1. The subject as defined as a service endpoint, or if not present:
  2. The delegate as a generic DID parameter.

This proof is NOT proof of the binding between a DID and a DID Document.

The rules for a proof are:

  1. A DID Document MAY have exactly one property representing a proof.
  2. The key for this property MUST be proof.
  3. The value of this key MUST be a valid JSON-LD proof as defined by Linked Data Proofs.
let d = new DidDoc("my_context", "my_id")
    .setProof({
        "type": "RsaSignature2018",
        "created": "2018-06-17T10:03:48Z",
        "verificationMethod": "did:example:ebfeb1276e12ec21f712ebc6f1c#k1",
        "signatureValue": "pY9...Cky6Ed = "
    });

pub fn set_created(self, c: String) -> DidDoc[src]

Set Created

Standard metadata for identifier records includes a timestamp of the original creation. The rules for including a creation timestamp are:

  1. A DID Document MUST have zero or one property representing a creation timestamp. It is RECOMMENDED to include this property.
  2. The key for this property MUST be created.
  3. The value of this key MUST be a valid XML datetime value as defined in section 3.3.7 of W3C XML Schema Definition Language (XSD) 1.1 Part 2: Datatypes [XMLSCHEMA11-2].
  4. This datetime value MUST be normalized to UTC 00:00 as indicated by the trailing "Z".
  5. Method specifications that rely on DLTs SHOULD require time values that are after the known "median time past" (defined in Bitcoin BIP 113), when the DLT supports such a notion.
let d = new DidDoc("my_context", "my_id")
    .setCreated("2002-10-10T17:00:00Z");

pub fn set_updated(self, u: String) -> DidDoc[src]

Set Updated

Standard metadata for identifier records includes a timestamp of the most recent change. The rules for including an updated timestamp are:

  1. A DID Document MUST have zero or one property representing an updated timestamp. It is RECOMMENDED to include this property.
  2. The key for this property MUST be updated.
  3. The value of this key MUST be a valid XML datetime value as defined in section 3.3.7 of W3C XML Schema Definition Language (XSD) 1.1 Part 2: Datatypes [XMLSCHEMA11-2].
  4. This datetime value MUST be normalized to UTC 00:00 as indicated by the trailing "Z".
  5. Method specifications that rely on DLTs SHOULD require time values that are after the known "median time past" (defined in Bitcoin BIP 113), when the DLT supports such a notion.
let d = new DidDoc("my_context", "my_id")
    .setUpdated("2016-10-17T02:41:00Z");

pub fn get_context(&self) -> JsValue[src]

Get Context

let dContext = dd.getContext();

pub fn get_id(&self) -> JsValue[src]

Get DID Identification

let dId = dd.getId();

pub fn get_authentication(&self) -> JsValue[src]

Get DID Authentication

let dAuthentication = dd.getAuthentication();

pub fn get_public_key(&self) -> JsValue[src]

Get Public Key

let dPublicKey = dd.getPublicKey();

pub fn get_service(&self) -> JsValue[src]

Get Services

let dServices = dd.getService();

pub fn get_proof(&self) -> JsValue[src]

Get Proof

let dProof = dd.getProof();

pub fn get_created(&self) -> JsValue[src]

Get DID Creation (Created)

let dCreated = dd.getCreated();

pub fn get_updated(&self) -> JsValue[src]

Get DID last update (Updated)

let dUpdated = dd.getUpdated();

pub fn add_context(self, c: String) -> DidDoc[src]

Add Context

let d = new DidDoc("my_context", "my_id")
    .addContext("my_second_context");

pub fn add_authentication(self, json_auth: JsValue) -> DidDoc[src]

Add Authentication

let d = new DidDoc("my_context", "my_id")
    .addAuthentication({
           "id": "did:example:ebfeb1276e12ec21f712ebc6f1c",
           "type": "OpenIdConnectVersion1.0Service",
           "owner": "OWNER!",
           "PublicKeyBase58": "H3C2AVvLMv6gmMNam3uVAjZpfkcJCwDwnZn6z3wXmqPV"
    });

pub fn add_public_key(self, json_publickey: JsValue) -> DidDoc[src]

Add Public Key

let d = new DidDoc("my_context", "my_id")
    .addPublicKey({
        "id": "did:sov:WRfXPg8dantKVubE3HX8pw#key-1",
        "type": "Ed25519VerificationKey2018",
        "owner": "", // empty `owner`
        "publicKeyBase58": "~P7F3BNs5VmQ6eVpwkNKJ5D"
    });

pub fn add_service(self, json_service: JsValue) -> DidDoc[src]

Add Service

let d = new DidDoc("my_context", "my_id")
    .addService({
        "id": "did:ser:18y34b91c612c4123gwrh45y",
        "type": "agent",
        "serviceEndpoint": "https://agents.danubeclouds.com/agent/WRfXPg8dantKVubE3HX8pw"
    })
    .setService({
        "id": "did:ser:18y34b91c612c4123gwrh45y",
        "type": "agent",
        "serviceEndpoint": "https://agents.danubeclouds.com/agent/WRfXPg8dantKVubE3HX8pw"
    });

pub fn to_json(&self) -> JsValue[src]

Generate JSON from Did Document

let my_json = dd.toJSON();

Trait Implementations

impl From<DidDoc> for JsValue[src]

impl FromWasmAbi for DidDoc[src]

type Abi = u32

The wasm ABI type that this converts from when coming back out from the ABI boundary. Read more

impl IntoWasmAbi for DidDoc[src]

type Abi = u32

The wasm ABI type that this converts into when crossing the ABI boundary. Read more

impl OptionFromWasmAbi for DidDoc[src]

impl OptionIntoWasmAbi for DidDoc[src]

impl RefFromWasmAbi for DidDoc[src]

type Abi = u32

The wasm ABI type references to Self are recovered from.

type Anchor = Ref<'static, DidDoc>

The type that holds the reference to Self for the duration of the invocation of the function that has an &Self parameter. This is required to ensure that the lifetimes don't persist beyond one function call, and so that they remain anonymous. Read more

impl RefMutFromWasmAbi for DidDoc[src]

type Abi = u32

Same as RefFromWasmAbi::Abi

type Anchor = RefMut<'static, DidDoc>

Same as RefFromWasmAbi::Anchor

impl WasmDescribe for DidDoc[src]

Auto Trait Implementations

impl RefUnwindSafe for DidDoc

impl !Send for DidDoc

impl !Sync for DidDoc

impl Unpin for DidDoc

impl UnwindSafe for DidDoc

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ReturnWasmAbi for T where
    T: IntoWasmAbi
[src]

type Abi = <T as IntoWasmAbi>::Abi

Same as IntoWasmAbi::Abi

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.