@twin.org/identity-service 0.0.3-next.2 → 0.0.3-next.21

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/docs/examples.md CHANGED
@@ -1 +1,196 @@
1
- # @twin.org/identity-service - Examples
1
+ # Identity Service Examples
2
+
3
+ These examples show how to orchestrate identity operations through service-level abstractions for connectors, resolvers, and profile storage.
4
+
5
+ ## IdentityService
6
+
7
+ ```typescript
8
+ import { IdentityService } from '@twin.org/identity-service';
9
+
10
+ const identityService = new IdentityService({
11
+ config: {
12
+ defaultNamespace: 'iota'
13
+ }
14
+ });
15
+
16
+ const className = identityService.className();
17
+ const didDocument = await identityService.identityCreate('iota', 'controller-1');
18
+
19
+ await identityService.identityRemove(didDocument.id, 'controller-1');
20
+
21
+ console.log(className); // IdentityService
22
+ console.log(didDocument.id); // did:iota:tst:0x...
23
+ ```
24
+
25
+ ```typescript
26
+ import { IdentityService } from '@twin.org/identity-service';
27
+ import { DidVerificationMethodType, ProofTypes } from '@twin.org/standards-w3c-did';
28
+
29
+ const identityService = new IdentityService({
30
+ config: {
31
+ defaultNamespace: 'iota'
32
+ }
33
+ });
34
+
35
+ const identity = 'did:iota:tst:0x1234abcd';
36
+
37
+ const verificationMethod = await identityService.verificationMethodCreate(
38
+ identity,
39
+ DidVerificationMethodType.VerificationMethod,
40
+ 'signing-key',
41
+ 'controller-1'
42
+ );
43
+
44
+ await identityService.verificationMethodRemove(verificationMethod.id, 'controller-1');
45
+
46
+ const service = await identityService.serviceCreate(
47
+ identity,
48
+ 'linked-domain',
49
+ 'LinkedDomains',
50
+ 'https://example.org',
51
+ 'controller-1'
52
+ );
53
+
54
+ await identityService.serviceRemove(service.id, 'controller-1');
55
+
56
+ const createdCredential = await identityService.verifiableCredentialCreate(
57
+ `${identity}#signing-key`,
58
+ 'urn:uuid:credential-001',
59
+ {
60
+ id: 'did:iota:tst:0x5678efab',
61
+ role: 'Engineer'
62
+ },
63
+ {
64
+ revocationIndex: 7
65
+ },
66
+ 'controller-1'
67
+ );
68
+
69
+ const verifiedCredential = await identityService.verifiableCredentialVerify(createdCredential.jwt);
70
+
71
+ await identityService.verifiableCredentialRevoke(identity, 7, 'controller-1');
72
+ await identityService.verifiableCredentialUnrevoke(identity, 7, 'controller-1');
73
+
74
+ const createdPresentation = await identityService.verifiablePresentationCreate(
75
+ `${identity}#signing-key`,
76
+ 'urn:uuid:presentation-001',
77
+ ['https://www.w3.org/2018/credentials/v1'],
78
+ ['VerifiablePresentation'],
79
+ [createdCredential.jwt],
80
+ {
81
+ expirationDate: new Date('2027-01-01T00:00:00.000Z')
82
+ },
83
+ 'controller-1'
84
+ );
85
+
86
+ const verifiedPresentation = await identityService.verifiablePresentationVerify(
87
+ createdPresentation.jwt
88
+ );
89
+
90
+ const proof = await identityService.proofCreate(
91
+ `${identity}#signing-key`,
92
+ ProofTypes.DataIntegrityProof,
93
+ {
94
+ id: 'urn:example:document-1',
95
+ value: 'hello'
96
+ },
97
+ 'controller-1'
98
+ );
99
+
100
+ const proofIsValid = await identityService.proofVerify(
101
+ {
102
+ id: 'urn:example:document-1',
103
+ value: 'hello'
104
+ },
105
+ proof
106
+ );
107
+
108
+ console.log(verifiedCredential.revoked); // false
109
+ console.log(verifiedPresentation.revoked); // false
110
+ console.log(proofIsValid); // true
111
+ ```
112
+
113
+ ## IdentityProfileService
114
+
115
+ ```typescript
116
+ import { IdentityProfileService } from '@twin.org/identity-service';
117
+
118
+ interface PublicProfile {
119
+ displayName: string;
120
+ location: string;
121
+ }
122
+
123
+ interface PrivateProfile {
124
+ email: string;
125
+ }
126
+
127
+ const profileService = new IdentityProfileService<PublicProfile, PrivateProfile>({
128
+ profileEntityConnectorType: 'identity-profile'
129
+ });
130
+
131
+ const className = profileService.className();
132
+ const identity = 'did:iota:tst:0x1234abcd';
133
+
134
+ await profileService.create(
135
+ {
136
+ displayName: 'Alice',
137
+ location: 'London'
138
+ },
139
+ {
140
+ email: 'alice@example.org'
141
+ },
142
+ identity
143
+ );
144
+
145
+ const profile = await profileService.get(['displayName'], ['email'], identity);
146
+ const publicProfile = await profileService.getPublic(identity, ['displayName']);
147
+
148
+ await profileService.update(
149
+ {
150
+ displayName: 'Alice Doe',
151
+ location: 'London'
152
+ },
153
+ {
154
+ email: 'alice.doe@example.org'
155
+ },
156
+ identity
157
+ );
158
+
159
+ const profiles = await profileService.list(
160
+ [
161
+ {
162
+ propertyName: 'displayName',
163
+ propertyValue: 'Alice Doe'
164
+ }
165
+ ],
166
+ ['displayName'],
167
+ undefined,
168
+ 10
169
+ );
170
+
171
+ await profileService.remove(identity);
172
+
173
+ console.log(className); // IdentityService
174
+ console.log(profile.identity); // did:iota:tst:0x1234abcd
175
+ console.log(publicProfile.displayName); // Alice
176
+ console.log(profiles.items.length); // 1
177
+ ```
178
+
179
+ ## IdentityResolverService
180
+
181
+ ```typescript
182
+ import { IdentityResolverService } from '@twin.org/identity-service';
183
+
184
+ const resolverService = new IdentityResolverService({
185
+ config: {
186
+ defaultNamespace: 'iota'
187
+ },
188
+ fallbackResolverConnectorType: 'universal'
189
+ });
190
+
191
+ const className = resolverService.className();
192
+ const didDocument = await resolverService.identityResolve('did:iota:tst:0x1234abcd');
193
+
194
+ console.log(className); // IdentityService
195
+ console.log(didDocument.id); // did:iota:tst:0x1234abcd
196
+ ```