@3sixty/identity-rest-client 0.0.0-stage → 0.20.0-next.0
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/LICENSE +201 -0
- package/README.md +24 -2
- package/dist/es/identityProfileRestClient.js +192 -0
- package/dist/es/identityProfileRestClient.js.map +1 -0
- package/dist/es/identityResolverRestClient.js +43 -0
- package/dist/es/identityResolverRestClient.js.map +1 -0
- package/dist/es/identityRestClient.js +388 -0
- package/dist/es/identityRestClient.js.map +1 -0
- package/dist/es/index.js +6 -0
- package/dist/es/index.js.map +1 -0
- package/dist/types/identityProfileRestClient.d.ts +111 -0
- package/dist/types/identityResolverRestClient.d.ts +29 -0
- package/dist/types/identityRestClient.d.ts +202 -0
- package/dist/types/index.d.ts +3 -0
- package/docs/changelog.md +0 -0
- package/docs/examples.md +175 -0
- package/docs/reference/classes/IdentityProfileRestClient.md +337 -0
- package/docs/reference/classes/IdentityResolverRestClient.md +87 -0
- package/docs/reference/classes/IdentityRestClient.md +717 -0
- package/docs/reference/index.md +7 -0
- package/locales/en.json +1 -0
- package/package.json +58 -5
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
import { BaseRestClient } from "@3sixty/api-core";
|
|
2
|
+
import type { IBaseRestClientConfig } from "@3sixty/api-models";
|
|
3
|
+
import type { IJsonLdContextDefinitionRoot, IJsonLdNodeObject } from "@3sixty/data-json-ld";
|
|
4
|
+
import { type IIdentityComponent } from "@3sixty/identity-models";
|
|
5
|
+
import { DidVerificationMethodType, type IDidDocument, type IDidDocumentVerificationMethod, type IDidService, type IDidVerifiableCredential, type IDidVerifiablePresentation, type IProof, ProofTypes } from "@3sixty/standards-w3c-did";
|
|
6
|
+
/**
|
|
7
|
+
* Client for performing identity through to REST endpoints.
|
|
8
|
+
*/
|
|
9
|
+
export declare class IdentityRestClient extends BaseRestClient implements IIdentityComponent {
|
|
10
|
+
/**
|
|
11
|
+
* Runtime name for the class.
|
|
12
|
+
*/
|
|
13
|
+
static readonly CLASS_NAME: string;
|
|
14
|
+
/**
|
|
15
|
+
* Create a new instance of IdentityRestClient.
|
|
16
|
+
* @param config The configuration for the client.
|
|
17
|
+
*/
|
|
18
|
+
constructor(config: IBaseRestClientConfig);
|
|
19
|
+
/**
|
|
20
|
+
* Returns the class name of the component.
|
|
21
|
+
* @returns The class name of the component.
|
|
22
|
+
*/
|
|
23
|
+
className(): string;
|
|
24
|
+
/**
|
|
25
|
+
* Create a new identity.
|
|
26
|
+
* @param namespace The namespace of the connector to use for the identity, defaults to service configured namespace.
|
|
27
|
+
* @returns The created identity document.
|
|
28
|
+
*/
|
|
29
|
+
identityCreate(namespace?: string): Promise<IDidDocument>;
|
|
30
|
+
/**
|
|
31
|
+
* Remove an identity.
|
|
32
|
+
* @param identity The id of the document to remove.
|
|
33
|
+
* @param options Optional settings.
|
|
34
|
+
* @param options.removeKeys Also remove any associated private keys from the vault.
|
|
35
|
+
* @param options.removeDocumentKey Also remove the document key from the vault.
|
|
36
|
+
* @returns A promise that resolves when the identity has been removed.
|
|
37
|
+
*/
|
|
38
|
+
identityRemove(identity: string, options?: {
|
|
39
|
+
removeKeys?: boolean;
|
|
40
|
+
removeDocumentKey?: boolean;
|
|
41
|
+
}): Promise<void>;
|
|
42
|
+
/**
|
|
43
|
+
* Add a verification method to the document in JSON Web key Format.
|
|
44
|
+
* @param identity The id of the document to add the verification method to.
|
|
45
|
+
* @param verificationMethodType The type of the verification method to add.
|
|
46
|
+
* @param verificationMethodId The id of the verification method, if undefined uses the kid of the generated JWK.
|
|
47
|
+
* @returns The verification method.
|
|
48
|
+
* @throws NotFoundError if the id can not be resolved.
|
|
49
|
+
* @throws NotSupportedError if the platform does not support multiple keys.
|
|
50
|
+
*/
|
|
51
|
+
verificationMethodCreate(identity: string, verificationMethodType: DidVerificationMethodType, verificationMethodId?: string): Promise<IDidDocumentVerificationMethod>;
|
|
52
|
+
/**
|
|
53
|
+
* Remove a verification method from the document.
|
|
54
|
+
* @param verificationMethodId The id of the verification method.
|
|
55
|
+
* @param options Optional settings.
|
|
56
|
+
* @param options.removeKeys Also remove any associated private key from the vault.
|
|
57
|
+
* @param controller Unused by the REST client; the controller is resolved server-side from the session context.
|
|
58
|
+
* @returns A promise that resolves when the verification method has been removed.
|
|
59
|
+
* @throws NotFoundError if the id can not be resolved.
|
|
60
|
+
* @throws NotSupportedError if the platform does not support multiple revocable keys.
|
|
61
|
+
*/
|
|
62
|
+
verificationMethodRemove(verificationMethodId: string, options?: {
|
|
63
|
+
removeKeys?: boolean;
|
|
64
|
+
}, controller?: string): Promise<void>;
|
|
65
|
+
/**
|
|
66
|
+
* Add a service to the document.
|
|
67
|
+
* @param identity The id of the document to add the service to.
|
|
68
|
+
* @param serviceId The id of the service.
|
|
69
|
+
* @param serviceType The type of the service.
|
|
70
|
+
* @param serviceEndpoint The endpoint for the service.
|
|
71
|
+
* @returns The service.
|
|
72
|
+
* @throws NotFoundError if the id can not be resolved.
|
|
73
|
+
*/
|
|
74
|
+
serviceCreate(identity: string, serviceId: string, serviceType: string | string[], serviceEndpoint: string | string[]): Promise<IDidService>;
|
|
75
|
+
/**
|
|
76
|
+
* Remove a service from the document.
|
|
77
|
+
* @param serviceId The id of the service.
|
|
78
|
+
* @returns A promise that resolves when the service has been removed.
|
|
79
|
+
* @throws NotFoundError if the id can not be resolved.
|
|
80
|
+
*/
|
|
81
|
+
serviceRemove(serviceId: string): Promise<void>;
|
|
82
|
+
/**
|
|
83
|
+
* Add an alias to the alsoKnownAs property on the document.
|
|
84
|
+
* If the alias is already present the operation is a no-op.
|
|
85
|
+
* @param documentId The id of the document to update.
|
|
86
|
+
* @param alias The alias to add. Must be a Url or Urn (typically another DID).
|
|
87
|
+
* @returns A promise that resolves when the alias has been added.
|
|
88
|
+
* @throws GeneralError if the alias is not a Url or Urn.
|
|
89
|
+
* @throws NotFoundError if the id can not be resolved.
|
|
90
|
+
*/
|
|
91
|
+
alsoKnownAsAdd(documentId: string, alias: string): Promise<void>;
|
|
92
|
+
/**
|
|
93
|
+
* Remove an alias from the alsoKnownAs property on the document.
|
|
94
|
+
* If the alias is not present the operation is a no-op.
|
|
95
|
+
* @param documentId The id of the document to update.
|
|
96
|
+
* @param alias The alias to remove. Must be a Url or Urn.
|
|
97
|
+
* @returns A promise that resolves when the alias has been removed.
|
|
98
|
+
* @throws GeneralError if the alias is not a Url or Urn.
|
|
99
|
+
* @throws NotFoundError if the id can not be resolved.
|
|
100
|
+
*/
|
|
101
|
+
alsoKnownAsRemove(documentId: string, alias: string): Promise<void>;
|
|
102
|
+
/**
|
|
103
|
+
* Create a verifiable credential for a verification method.
|
|
104
|
+
* @param verificationMethodId The verification method id to use.
|
|
105
|
+
* @param id The id of the credential.
|
|
106
|
+
* @param subject The credential subject to store in the verifiable credential.
|
|
107
|
+
* @param options Additional options for creating the verifiable credential.
|
|
108
|
+
* @param options.revocationIndex The bitmap revocation index of the credential, if undefined will not have revocation status.
|
|
109
|
+
* @param options.expirationDate The date the verifiable credential is valid until.
|
|
110
|
+
* @param options.jwtHeaderFields Additional fields to include in the JWT header when creating the verifiable credential in jwt format.
|
|
111
|
+
* @param options.jwtPayloadFields Additional fields to include in the JWT payload when creating the verifiable credential in jwt format.
|
|
112
|
+
* @returns The created verifiable credential and its token.
|
|
113
|
+
* @throws NotFoundError if the id can not be resolved.
|
|
114
|
+
*/
|
|
115
|
+
verifiableCredentialCreate(verificationMethodId: string, id: string | undefined, subject: IJsonLdNodeObject, options?: {
|
|
116
|
+
revocationIndex?: number;
|
|
117
|
+
expirationDate?: Date;
|
|
118
|
+
jwtHeaderFields?: {
|
|
119
|
+
[id: string]: string;
|
|
120
|
+
};
|
|
121
|
+
jwtPayloadFields?: {
|
|
122
|
+
[id: string]: string;
|
|
123
|
+
};
|
|
124
|
+
}): Promise<{
|
|
125
|
+
verifiableCredential: IDidVerifiableCredential;
|
|
126
|
+
jwt: string;
|
|
127
|
+
}>;
|
|
128
|
+
/**
|
|
129
|
+
* Verify a verifiable credential is valid.
|
|
130
|
+
* @param credential The credential to verify.
|
|
131
|
+
* @returns The credential stored in the jwt and the revocation status.
|
|
132
|
+
*/
|
|
133
|
+
verifiableCredentialVerify(credential: string | IDidVerifiableCredential): Promise<{
|
|
134
|
+
revoked: boolean;
|
|
135
|
+
verifiableCredential?: IDidVerifiableCredential;
|
|
136
|
+
}>;
|
|
137
|
+
/**
|
|
138
|
+
* Revoke verifiable credential.
|
|
139
|
+
* @param issuerId The id of the document to update the revocation list for.
|
|
140
|
+
* @param credentialIndex The revocation bitmap index to revoke.
|
|
141
|
+
* @returns A promise that resolves when the credential has been revoked.
|
|
142
|
+
*/
|
|
143
|
+
verifiableCredentialRevoke(issuerId: string, credentialIndex: number): Promise<void>;
|
|
144
|
+
/**
|
|
145
|
+
* Unrevoke verifiable credential.
|
|
146
|
+
* @param issuerId The id of the document to update the revocation list for.
|
|
147
|
+
* @param credentialIndex The revocation bitmap index to unrevoke.
|
|
148
|
+
* @returns A promise that resolves when the credential has been unrevoked.
|
|
149
|
+
*/
|
|
150
|
+
verifiableCredentialUnrevoke(issuerId: string, credentialIndex: number): Promise<void>;
|
|
151
|
+
/**
|
|
152
|
+
* Create a verifiable presentation from the supplied verifiable credentials.
|
|
153
|
+
* @param verificationMethodId The method to associate with the presentation.
|
|
154
|
+
* @param presentationId The id of the presentation.
|
|
155
|
+
* @param contexts The contexts for the data stored in the verifiable credential.
|
|
156
|
+
* @param types The types for the data stored in the verifiable credential.
|
|
157
|
+
* @param verifiableCredentials The credentials to use for creating the presentation in jwt format.
|
|
158
|
+
* @param options Additional options for creating the verifiable presentation.
|
|
159
|
+
* @param options.expirationDate The date the verifiable presentation is valid until.
|
|
160
|
+
* @param options.jwtHeaderFields Additional fields to include in the JWT header when creating the verifiable presentation in jwt format.
|
|
161
|
+
* @param options.jwtPayloadFields Additional fields to include in the JWT payload when creating the verifiable presentation in jwt format.
|
|
162
|
+
* @returns The created verifiable presentation and its token.
|
|
163
|
+
* @throws NotFoundError if the id can not be resolved.
|
|
164
|
+
*/
|
|
165
|
+
verifiablePresentationCreate(verificationMethodId: string, presentationId: string | undefined, contexts: IJsonLdContextDefinitionRoot | undefined, types: string | string[] | undefined, verifiableCredentials: (string | IDidVerifiableCredential)[], options?: {
|
|
166
|
+
expirationDate?: Date;
|
|
167
|
+
jwtHeaderFields?: {
|
|
168
|
+
[id: string]: string;
|
|
169
|
+
};
|
|
170
|
+
jwtPayloadFields?: {
|
|
171
|
+
[id: string]: string;
|
|
172
|
+
};
|
|
173
|
+
}): Promise<{
|
|
174
|
+
verifiablePresentation: IDidVerifiablePresentation;
|
|
175
|
+
jwt: string;
|
|
176
|
+
}>;
|
|
177
|
+
/**
|
|
178
|
+
* Verify a verifiable presentation is valid.
|
|
179
|
+
* @param presentation The presentation to verify.
|
|
180
|
+
* @returns The presentation stored in the jwt and the revocation status.
|
|
181
|
+
*/
|
|
182
|
+
verifiablePresentationVerify(presentation: string | IDidVerifiablePresentation): Promise<{
|
|
183
|
+
revoked: boolean;
|
|
184
|
+
verifiablePresentation?: IDidVerifiablePresentation;
|
|
185
|
+
issuers?: IDidDocument[];
|
|
186
|
+
}>;
|
|
187
|
+
/**
|
|
188
|
+
* Create a proof for a document with the specified verification method.
|
|
189
|
+
* @param verificationMethodId The verification method id to use.
|
|
190
|
+
* @param proofType The type of proof to create.
|
|
191
|
+
* @param unsecureDocument The unsecure document to create the proof for.
|
|
192
|
+
* @returns The proof.
|
|
193
|
+
*/
|
|
194
|
+
proofCreate(verificationMethodId: string, proofType: ProofTypes, unsecureDocument: IJsonLdNodeObject): Promise<IProof>;
|
|
195
|
+
/**
|
|
196
|
+
* Verify proof for a document with the specified verification method.
|
|
197
|
+
* @param document The document to verify.
|
|
198
|
+
* @param proof The proof to verify.
|
|
199
|
+
* @returns True if the proof is verified.
|
|
200
|
+
*/
|
|
201
|
+
proofVerify(document: IJsonLdNodeObject, proof: IProof): Promise<boolean>;
|
|
202
|
+
}
|
|
File without changes
|
package/docs/examples.md
ADDED
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
# Identity REST Client Examples
|
|
2
|
+
|
|
3
|
+
Use these examples to call identity REST endpoints from applications that need document lifecycle, credential, and profile operations.
|
|
4
|
+
|
|
5
|
+
## IdentityRestClient
|
|
6
|
+
|
|
7
|
+
```typescript
|
|
8
|
+
import { IdentityRestClient } from '@3sixty/identity-rest-client';
|
|
9
|
+
|
|
10
|
+
const client = new IdentityRestClient({
|
|
11
|
+
endpoint: 'http://localhost:8080'
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
const className = client.className();
|
|
15
|
+
const createdDocument = await client.identityCreate('iota');
|
|
16
|
+
|
|
17
|
+
await client.identityRemove(createdDocument.id);
|
|
18
|
+
|
|
19
|
+
console.log(className); // IdentityRestClient
|
|
20
|
+
console.log(createdDocument.id); // did:iota:tst:0x...
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
```typescript
|
|
24
|
+
import { IdentityRestClient } from '@3sixty/identity-rest-client';
|
|
25
|
+
import { DidVerificationMethodType, ProofTypes } from '@3sixty/standards-w3c-did';
|
|
26
|
+
|
|
27
|
+
const client = new IdentityRestClient({
|
|
28
|
+
endpoint: 'http://localhost:8080'
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
const did = 'did:iota:tst:0x1234abcd';
|
|
32
|
+
|
|
33
|
+
const verificationMethod = await client.verificationMethodCreate(
|
|
34
|
+
did,
|
|
35
|
+
DidVerificationMethodType.VerificationMethod,
|
|
36
|
+
'signing-key'
|
|
37
|
+
);
|
|
38
|
+
|
|
39
|
+
await client.verificationMethodRemove(verificationMethod.id);
|
|
40
|
+
|
|
41
|
+
const service = await client.serviceCreate(
|
|
42
|
+
did,
|
|
43
|
+
'linked-domain',
|
|
44
|
+
'LinkedDomains',
|
|
45
|
+
'https://example.org'
|
|
46
|
+
);
|
|
47
|
+
|
|
48
|
+
await client.serviceRemove(service.id);
|
|
49
|
+
|
|
50
|
+
const credentialCreateResult = await client.verifiableCredentialCreate(
|
|
51
|
+
`${did}#signing-key`,
|
|
52
|
+
'urn:uuid:credential-001',
|
|
53
|
+
{
|
|
54
|
+
id: 'did:iota:tst:0x5678efab',
|
|
55
|
+
name: 'Alice'
|
|
56
|
+
},
|
|
57
|
+
{
|
|
58
|
+
revocationIndex: 2
|
|
59
|
+
}
|
|
60
|
+
);
|
|
61
|
+
|
|
62
|
+
const credentialVerificationResult = await client.verifiableCredentialVerify(
|
|
63
|
+
credentialCreateResult.jwt
|
|
64
|
+
);
|
|
65
|
+
|
|
66
|
+
await client.verifiableCredentialRevoke(did, 2);
|
|
67
|
+
await client.verifiableCredentialUnrevoke(did, 2);
|
|
68
|
+
|
|
69
|
+
const presentationCreateResult = await client.verifiablePresentationCreate(
|
|
70
|
+
`${did}#signing-key`,
|
|
71
|
+
'urn:uuid:presentation-001',
|
|
72
|
+
['https://www.w3.org/2018/credentials/v1'],
|
|
73
|
+
['VerifiablePresentation'],
|
|
74
|
+
[credentialCreateResult.jwt]
|
|
75
|
+
);
|
|
76
|
+
|
|
77
|
+
const presentationVerificationResult = await client.verifiablePresentationVerify(
|
|
78
|
+
presentationCreateResult.jwt
|
|
79
|
+
);
|
|
80
|
+
|
|
81
|
+
const proof = await client.proofCreate(`${did}#signing-key`, ProofTypes.DataIntegrityProof, {
|
|
82
|
+
id: 'urn:example:doc-1',
|
|
83
|
+
name: 'Sample'
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
const proofVerified = await client.proofVerify(
|
|
87
|
+
{
|
|
88
|
+
id: 'urn:example:doc-1',
|
|
89
|
+
name: 'Sample'
|
|
90
|
+
},
|
|
91
|
+
proof
|
|
92
|
+
);
|
|
93
|
+
|
|
94
|
+
console.log(credentialVerificationResult.revoked); // false
|
|
95
|
+
console.log(presentationVerificationResult.revoked); // false
|
|
96
|
+
console.log(proofVerified); // true
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
## IdentityProfileRestClient
|
|
100
|
+
|
|
101
|
+
```typescript
|
|
102
|
+
import { IdentityProfileRestClient } from '@3sixty/identity-rest-client';
|
|
103
|
+
|
|
104
|
+
interface PublicProfile {
|
|
105
|
+
displayName: string;
|
|
106
|
+
website: string;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
interface PrivateProfile {
|
|
110
|
+
contactEmail: string;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
const profileClient = new IdentityProfileRestClient<PublicProfile, PrivateProfile>({
|
|
114
|
+
endpoint: 'http://localhost:8080'
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
const className = profileClient.className();
|
|
118
|
+
|
|
119
|
+
await profileClient.create(
|
|
120
|
+
{
|
|
121
|
+
displayName: 'Alice',
|
|
122
|
+
website: 'https://example.org'
|
|
123
|
+
},
|
|
124
|
+
{
|
|
125
|
+
contactEmail: 'alice@example.org'
|
|
126
|
+
}
|
|
127
|
+
);
|
|
128
|
+
|
|
129
|
+
const profile = await profileClient.get(['displayName'], ['contactEmail']);
|
|
130
|
+
const publicProfile = await profileClient.getPublic(profile.identity, ['displayName']);
|
|
131
|
+
|
|
132
|
+
await profileClient.update(
|
|
133
|
+
{
|
|
134
|
+
displayName: 'Alice Doe',
|
|
135
|
+
website: 'https://example.org'
|
|
136
|
+
},
|
|
137
|
+
{
|
|
138
|
+
contactEmail: 'alice.doe@example.org'
|
|
139
|
+
}
|
|
140
|
+
);
|
|
141
|
+
|
|
142
|
+
const profileList = await profileClient.list(
|
|
143
|
+
[
|
|
144
|
+
{
|
|
145
|
+
propertyName: 'displayName',
|
|
146
|
+
propertyValue: 'Alice Doe'
|
|
147
|
+
}
|
|
148
|
+
],
|
|
149
|
+
['displayName'],
|
|
150
|
+
undefined,
|
|
151
|
+
10
|
|
152
|
+
);
|
|
153
|
+
|
|
154
|
+
await profileClient.remove();
|
|
155
|
+
|
|
156
|
+
console.log(className); // IdentityProfileRestClient
|
|
157
|
+
console.log(publicProfile.displayName); // Alice
|
|
158
|
+
console.log(profileList.items.length); // 1
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
## IdentityResolverRestClient
|
|
162
|
+
|
|
163
|
+
```typescript
|
|
164
|
+
import { IdentityResolverRestClient } from '@3sixty/identity-rest-client';
|
|
165
|
+
|
|
166
|
+
const resolverClient = new IdentityResolverRestClient({
|
|
167
|
+
endpoint: 'http://localhost:8080'
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
const className = resolverClient.className();
|
|
171
|
+
const didDocument = await resolverClient.identityResolve('did:iota:tst:0x1234abcd');
|
|
172
|
+
|
|
173
|
+
console.log(className); // IdentityResolverRestClient
|
|
174
|
+
console.log(didDocument.id); // did:iota:tst:0x1234abcd
|
|
175
|
+
```
|