[][src]Struct caelum_vcdm::VPresentation

pub struct VPresentation { /* fields omitted */ }

Methods

impl VPresentation[src]

pub fn new(id: String) -> Self[src]

Web assembly Constructor

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

import { VPresentation } from 'caelum_vcdm';
let vp = new VPresentation("my_id");

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

WebAssembly Constructor formJSON

VPresentation's constructor will create a VPresentation 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 { VPresentation } from 'caelum_vcdm';
let vp_json = {
   "@context": [
       "https://www.w3.org/2018/credentials/v1",
       "https://www.w3.org/2018/credentials/examples/v1"
   ],
   "id": "did:example:ebfeb1276e12ec21f712ebc6f1c",
   "type": [
       "VerifiableCredential",
       "PersonalInformation"
   ],
   "verifiableCredential": [
       {
           "@context": [
               "https://www.w3.org/2018/credentials/v1",
               "https://www.w3.org/2018/credentials/examples/v1"
           ],
           "id": "http://example.com/credentials/4643",
           "type": [
               "VerifiableCredential",
               "PersonalInformation"
           ],
           "issuer": "did:example:ebfeb1276e12ec21f712ebc6f1c",
           "issuanceDate": "2010-01-01T19:73:24Z",
           "credentialStatus": {
               "id": "StatusID",
               "type": "available"
           },
           "credentialSubject": [{
               "type": "did:example:abfab3f512ebc6c1c22de17ec77",
               "name": "Mr John Doe",
               "mnumber": "77373737373A",
               "address": "10 Some Street, Anytown, ThisLocal, Country X",
               "birthDate": "1982-02-02-00T00:00Z"
           }],
           "proof": {
               "type": "RsaSignature2018",
               "created": "2018-06-17T10:03:48Z",
               "verificationMethod": "did:example:ebfeb1276e12ec21f712ebc6f1c#k1",
               "signatureValue": "pY9...Cky6Ed = "
           }
       }
   ],
   "proof": {
       "type": "RsaSignature2018",
       "created": "2018-06-17T10:03:48Z",
       "verificationMethod": "did:example:ebfeb1276e12ec21f712ebc6f1c#k1",
       "signatureValue": "pY9...Cky6Ed = "
   }
};
let ver_pres = VPresentation.fromJSON(vp_json);

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

Set context

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 { VPresentation } from 'caelum_vcdm';
let vp = new VPresentation("my_id")
    .setContext("new_context");

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

Set Id

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

import { VPresentation } from 'caelum_vcdm';
let vp = new VPresentation("my_id")
    .setId("my_id");

pub fn set_type(self, t: String) -> Self[src]

Set Type

By default type will be set to

{
    type: [
        "VerifiableCredential",
        "PersonalInformation"
    ]
}

To overwrite default types use method setType() can be used.

import { VPresentation } from 'caelum_vcdm';
let vp = new VPresentation("my_id")
    .setType("new_type");

pub fn set_verifiable_credential(self, json: JsValue) -> Self[src]

Set Verifiable Credential

By default verifiableCredential will be an empty vector Vec::new() representing Vec<VerifiableCredential>. A array of json objects representing a VCredential`.

import { VPresentation } from 'caelum_vcdm';
let vp = new VPresentation("my_id")
    // Variable `vc` represents a `VCredential` object
    .addVerifiableCredential(vp.toJSON())

Equivalent to

import { VPresentation } from 'caelum_vcdm';
let vp = new VPresentation("my_id")
    .addVerifiableCredential({
        "@context": [
            "https://www.w3.org/2018/credentials/v1",
            "https://www.w3.org/2018/credentials/examples/v1"
        ],
        "id": "http://example.com/credentials/4643",
        "type": [
            "VerifiableCredential",
            "PersonalInformation"
        ],
        "issuer": "did:example:ebfeb1276e12ec21f712ebc6f1c",
        "issuanceDate": "2010-01-01T19:73:24Z",
        "credentialStatus": {
            "id": "StatusID",
            "type": "available"
        },
        "credentialSubject": [{
            "type": "did:example:abfab3f512ebc6c1c22de17ec77",
            "name": "Mr John Doe",
            "mnumber": "77373737373A",
            "address": "10 Some Street, Anytown, ThisLocal, Country X",
            "birthDate": "1982-02-02-00T00:00Z"
        }],
        "proof": {
            "type": "RsaSignature2018",
            "created": "2018-06-17T10:03:48Z",
            "verificationMethod": "did:example:ebfeb1276e12ec21f712ebc6f1c#k1",
            "signatureValue": "pY9...Cky6Ed = "
        }
    });

pub fn set_proof(self, p: JsValue) -> Self[src]

Set Proof

/// By default proof will be set to empty. To overwrite default proof use method setProof() can be used.

import { VPresentation } from 'caelum_vcdm';
let vp = new VPresentation("my_id")
    .setProof({
        "type": "RsaSignature2018",
        "created": "2018-06-17T10:03:48Z",
        "verificationMethod": "did:example:ebfeb1276e12ec21f712ebc6f1c#k1",
        "signatureValue": "pY9...Cky6Ed = "
    });

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

Add context

By default context will be set to

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

To add to the default context array use method addContext() can be used.

import { VPresentation } from 'caelum_vcdm';
let vp = new VPresentation("my_id")
    .addContext("another_context");

pub fn add_type(self, t: String) -> Self[src]

Add Type

By default type will be set to:

{
    type: [
        "VerifiableCredential",
        "PersonalInformation"
    ]
}

Once a property type is set, one may want to add to the array. To do so use method addType().

import { VPresentation } from 'caelum_vcdm';
let vp = new VPresentation("my_id")
    .addType("new_type");

pub fn add_verifiable_credential(self, vc: JsValue) -> Self[src]

Add Verifiable Credential

By default verifiableCredential create an empty vector. In order to add/push more verifiableCredentials to the array use method addVerifiableCredential().

import { VPresentation } from 'caelum_vcdm';
let vp = new VPresentation("my_id")
    .addVerifiableCredential({
        "@context": [
            "https://www.w3.org/2018/credentials/v1",
            "https://www.w3.org/2018/credentials/examples/v1"
        ],
        "id": "http://example.com/credentials/4643",
        "type": [
            "VerifiableCredential",
            "PersonalInformation"
        ],
        "issuer": "did:example:ebfeb1276e12ec21f712ebc6f1c",
        "issuanceDate": "2010-01-01T19:73:24Z",
        "credentialStatus": {
            "id": "StatusID",
            "type": "available"
        },
        "credentialSubject": [{
            "type": "did:example:abfab3f512ebc6c1c22de17ec77",
            "name": "Mr John Doe",
            "mnumber": "77373737373A",
            "address": "10 Some Street, Anytown, ThisLocal, Country X",
            "birthDate": "1982-02-02-00T00:00Z"
        }],
        "proof": {
            "type": "RsaSignature2018",
            "created": "2018-06-17T10:03:48Z",
            "verificationMethod": "did:example:ebfeb1276e12ec21f712ebc6f1c#k1",
            "signatureValue": "pY9...Cky6Ed = "
        }
    });

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

Get Context

import { VPresentation } from 'caelum_vcdm';
let vp = new VPresentation("my_id")
console.log(vp.getContext())

The code above will print in console the following:

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

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

Get Verifiable Credential

import { VPresentation } from 'caelum_vcdm';
let vp = new VPresentation("my_id")
    addVerifiableCredential(serde_json::from_str(r#"{
        "@context": [
            "https://www.w3.org/2018/credentials/v1",
            "https://www.w3.org/2018/credentials/examples/v1"
        ],
        "id": "http://example.com/credentials/4643",
        "type": [
            "VerifiableCredential",
            "PersonalInformation"
        ],
        "issuer": "did:example:ebfeb1276e12ec21f712ebc6f1c",
        "issuanceDate": "2010-01-01T19:73:24Z",
        "credentialStatus": {
            "id": "StatusID",
            "type": "available"
        },
        "credentialSubject": [{
            "type": "did:example:abfab3f512ebc6c1c22de17ec77",
            "name": "Mr John Doe",
            "mnumber": "77373737373A",
            "address": "10 Some Street, Anytown, ThisLocal, Country X",
            "birthDate": "1982-02-02-00T00:00Z"
        }],
        "proof": [{
            "type": "RsaSignature2018",
            "created": "2018-06-17T10:03:48Z",
            "verificationMethod": "did:example:ebfeb1276e12ec21f712ebc6f1c#k1",
            "signatureValue": "pY9...Cky6Ed = "
        }]
    }"#).unwrap());
console.log(vp.getVerifialbleCredential());

The code above will print in console the following:

{
        "@context": [
            "https://www.w3.org/2018/credentials/v1",
            "https://www.w3.org/2018/credentials/examples/v1"
        ],
        "id": "http://example.com/credentials/4643",
        "type": [
            "VerifiableCredential",
            "PersonalInformation"
        ],
        "issuer": "did:example:ebfeb1276e12ec21f712ebc6f1c",
        "issuanceDate": "2010-01-01T19:73:24Z",
        "credentialStatus": {
            "id": "StatusID",
            "type": "available"
        },
        "credentialSubject": [{
            "type": "did:example:abfab3f512ebc6c1c22de17ec77",
            "name": "Mr John Doe",
            "mnumber": "77373737373A",
            "address": "10 Some Street, Anytown, ThisLocal, Country X",
            "birthDate": "1982-02-02-00T00:00Z"
        }],
        "proof": {
            "type": "RsaSignature2018",
            "created": "2018-06-17T10:03:48Z",
            "verificationMethod": "did:example:ebfeb1276e12ec21f712ebc6f1c#k1",
            "signatureValue": "pY9...Cky6Ed = "
        }
    }
}

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

Get Type

import { VPresentation } from 'caelum_vcdm';
let vp = new VPresentation("my_id")
    .setType("my_type")
    .addType("my_type2")
console.log(vp.getType())

The code above will print in console the following:

["my_type", "my_type2"]

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

Get Id

import { VPresentation } from 'caelum_vcdm';
let vp = new VPresentation("my_id");
console.log(vp.getId())

The code above will print in console the following:

id: "my_id"

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

Get Proof

import { VPresentation } from 'caelum_vcdm';
let vp = new VPresentation("my_id")
    .setProof({
       "type": "RsaSignature2018",
       "created": "2018-06-17T10:03:48Z",
       "verificationMethod": "did:example:ebfeb1276e12ec21f712ebc6f1c#k1",
       "signatureValue": "pY9...Cky6Ed = "
    })
console.log(vp.getProof())

The code above will print in console the following:

{
    "type": "RsaSignature2018",
    "created": "2018-06-17T10:03:48Z",
    "verificationMethod": "did:example:ebfeb1276e12ec21f712ebc6f1c#k1",
    "signatureValue": "pY9...Cky6Ed = "
}

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

Jsonify Verifiable Presentation

toJSON method will output the current VPresentation as a JsValue (json object).

Trait Implementations

impl From<VPresentation> for JsValue[src]

impl RefFromWasmAbi for VPresentation[src]

type Abi = u32

The wasm ABI type references to Self are recovered from.

type Anchor = Ref<'static, VPresentation>

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 FromWasmAbi for VPresentation[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 VPresentation[src]

type Abi = u32

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

impl WasmDescribe for VPresentation[src]

impl OptionFromWasmAbi for VPresentation[src]

impl OptionIntoWasmAbi for VPresentation[src]

impl RefMutFromWasmAbi for VPresentation[src]

type Abi = u32

Same as RefFromWasmAbi::Abi

type Anchor = RefMut<'static, VPresentation>

Same as RefFromWasmAbi::Anchor

Auto Trait Implementations

Blanket Implementations

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

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

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.

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

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

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

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

type Abi = <T as IntoWasmAbi>::Abi

Same as IntoWasmAbi::Abi

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.

impl<T> Same<T> for T

type Output = T

Should always be Self