Newer
Older
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
import { makeAutoObservable, runInAction } from "mobx";
import api, { W3cCredentialDto } from "@dashboard/engine-api";
import { toast } from "react-toastify";
import displayError from "@dashboard/utils/displayError";
import {
FormType,
LegalParticipantFormData,
PrivatePersonFormData,
} from "./interfaces";
class OfferJsonLdCredentialDialogStore {
public formType: FormType | null = null;
public connectionId: string | undefined;
public signing = false;
public offerSending = false;
constructor(connectionId: string | undefined) {
this.connectionId = connectionId;
makeAutoObservable(this);
}
private buildPrivatePersonJsonLd(data: PrivatePersonFormData) {
return {
"@context": [
"https://www.w3.org/2018/credentials/v1",
"https://w3id.org/security/suites/jws-2020/v1",
"https://www.vereign.com/.well-known/vereign-schema",
],
type: ["VerifiableCredential"],
id: "",
issuer: "",
issuanceDate: "",
credentialSubject: {
type: "vereign:PrivatePerson",
"vereign:name": data.name,
"vereign:dateOfBirth": data.dateOfBirth,
"vereign:address": {
"vereign:street": data.street,
"vereign:building": data.building,
"vereign:city": data.city,
"vereign:country": data.country,
},
},
};
}
private buildLegalParticipantJsonLd(data: LegalParticipantFormData) {
return {
"@context": [
"https://www.w3.org/2018/credentials/v1",
"https://w3id.org/security/suites/jws-2020/v1",
"https://www.vereign.com/.well-known/vereign-schema",
],
type: ["VerifiableCredential"],
id: "",
issuer: "",
issuanceDate: "",
credentialSubject: {
type: "vereign:LegalParticipant",
"vereign:companyName": data.companyName,
"vereign:taxID": data.taxID,
"vereign:gleiCode": data.gleiCode,
"vereign:address": {
"vereign:street": data.street,
"vereign:building": data.building,
"vereign:city": data.city,
"vereign:country": data.country,
},
},
};
}
public offerPrivatePersonCreds = async (data: PrivatePersonFormData) => {
return this.offerCredential(this.buildPrivatePersonJsonLd(data));
};
public offerLegalParticipantCreds = async (
data: LegalParticipantFormData,
) => {
return this.offerCredential(this.buildLegalParticipantJsonLd(data));
};
public offerCustomJsonLdCreds = async (doc: unknown) => {
return this.offerCredential(doc);
};
private offerCredential = async (doc: unknown) => {
runInAction(() => (this.offerSending = true));
try {
const cred = await api.offerJsonLdCredential({
connectionId: this.connectionId,
doc: doc as W3cCredentialDto,
});
toast("Credential offer sent");
runInAction(() => {
this.offerSending = false;
});
return cred;
} catch (e: unknown) {
displayError(e);
runInAction(() => {
this.offerSending = false;
});
}
return null;
};
public signJsonLd = async (doc: unknown) => {
runInAction(() => (this.signing = true));
try {
const cred = await api.signJsonLdCredential({
doc: doc as W3cCredentialDto,
});
toast("Credential signed");
runInAction(() => {
this.signing = false;
});
return cred;
} catch (e: unknown) {
displayError(e);
runInAction(() => {
this.signing = false;
});
}
return null;
};
}
export type { OfferJsonLdCredentialDialogStore };
export default OfferJsonLdCredentialDialogStore;