forked from iotaledger/identity.rs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
create_vp.js
39 lines (29 loc) · 1.52 KB
/
create_vp.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
// Copyright 2020-2021 IOTA Stiftung
// SPDX-License-Identifier: Apache-2.0
import { Client, Config, VerifiablePresentation } from '@iota/identity-wasm';
import { createVC } from './create_vc';
/**
This example shows how to create a Verifiable Presentation and validate it.
A Verifiable Presentation is the format in which a (collection of) Verifiable Credential(s) gets shared.
It is signed by the subject, to prove control over the Verifiable Credential with a nonce or timestamp.
@param {{defaultNodeURL: string, explorerURL: string, network: Network}} clientConfig
**/
async function createVP(clientConfig) {
// Create a default client configuration from the parent config network.
const config = Config.fromNetwork(clientConfig.network);
// Create a client instance to publish messages to the Tangle.
const client = Client.fromConfig(config);
// Creates new identities (See "createVC" example)
const {alice, signedVc} = await createVC(clientConfig);
// Create a Verifiable Presentation from the Credential - signed by Alice's key
// TODO: Sign with a challenge
const unsignedVp = new VerifiablePresentation(alice.doc, signedVc.toJSON())
const signedVp = alice.doc.signPresentation(unsignedVp, {
method: "#key",
private: alice.key.private,
})
// Check the validation status of the Verifiable Presentation
const result = await client.checkPresentation(signedVp.toString());
console.log(`VP verification result: ${result.verified}`);
}
export {createVP};