@twin.org/identity-connector-entity-storage 0.0.1-next.10
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 +21 -0
- package/dist/cjs/index.cjs +1191 -0
- package/dist/esm/index.mjs +1187 -0
- package/dist/types/entities/identityDocument.d.ts +22 -0
- package/dist/types/entities/identityProfile.d.ts +17 -0
- package/dist/types/entityStorageIdentityConnector.d.ts +163 -0
- package/dist/types/entityStorageIdentityProfileConnector.d.ts +86 -0
- package/dist/types/index.d.ts +5 -0
- package/dist/types/schema.d.ts +10 -0
- package/docs/changelog.md +5 -0
- package/docs/examples.md +1 -0
- package/docs/reference/classes/EntityStorageIdentityConnector.md +597 -0
- package/docs/reference/classes/EntityStorageIdentityProfileConnector.md +239 -0
- package/docs/reference/classes/IdentityDocument.md +45 -0
- package/docs/reference/classes/IdentityProfile.md +37 -0
- package/docs/reference/functions/initSchema.md +23 -0
- package/docs/reference/index.md +12 -0
- package/locales/en.json +41 -0
- package/package.json +46 -0
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { IDidDocument } from "@twin.org/standards-w3c-did";
|
|
2
|
+
/**
|
|
3
|
+
* Class describing the identity document.
|
|
4
|
+
*/
|
|
5
|
+
export declare class IdentityDocument {
|
|
6
|
+
/**
|
|
7
|
+
* The identity of the document.
|
|
8
|
+
*/
|
|
9
|
+
id: string;
|
|
10
|
+
/**
|
|
11
|
+
* The DID document.
|
|
12
|
+
*/
|
|
13
|
+
document: IDidDocument;
|
|
14
|
+
/**
|
|
15
|
+
* The signature of the document.
|
|
16
|
+
*/
|
|
17
|
+
signature: string;
|
|
18
|
+
/**
|
|
19
|
+
* The controller of the document.
|
|
20
|
+
*/
|
|
21
|
+
controller: string;
|
|
22
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Class representing profile details for the identity.
|
|
3
|
+
*/
|
|
4
|
+
export declare class IdentityProfile {
|
|
5
|
+
/**
|
|
6
|
+
* The id for the identity.
|
|
7
|
+
*/
|
|
8
|
+
identity: string;
|
|
9
|
+
/**
|
|
10
|
+
* The public profile data.
|
|
11
|
+
*/
|
|
12
|
+
publicProfile?: unknown;
|
|
13
|
+
/**
|
|
14
|
+
* The private profile data.
|
|
15
|
+
*/
|
|
16
|
+
privateProfile?: unknown;
|
|
17
|
+
}
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
import { type IJsonLdObject, type IJsonLdContextDefinitionRoot } from "@twin.org/data-json-ld";
|
|
2
|
+
import { type IIdentityConnector } from "@twin.org/identity-models";
|
|
3
|
+
import { DidVerificationMethodType, type IDidDocument, type IDidDocumentVerificationMethod, type IDidService, type IDidVerifiableCredential, type IDidVerifiablePresentation } from "@twin.org/standards-w3c-did";
|
|
4
|
+
/**
|
|
5
|
+
* Class for performing identity operations using entity storage.
|
|
6
|
+
*/
|
|
7
|
+
export declare class EntityStorageIdentityConnector implements IIdentityConnector {
|
|
8
|
+
/**
|
|
9
|
+
* The namespace supported by the identity connector.
|
|
10
|
+
*/
|
|
11
|
+
static readonly NAMESPACE: string;
|
|
12
|
+
/**
|
|
13
|
+
* Runtime name for the class.
|
|
14
|
+
*/
|
|
15
|
+
readonly CLASS_NAME: string;
|
|
16
|
+
/**
|
|
17
|
+
* Create a new instance of EntityStorageIdentityConnector.
|
|
18
|
+
* @param options The dependencies for the identity connector.
|
|
19
|
+
* @param options.didDocumentEntityStorageType The entity storage for the did documents, defaults to "identity-document".
|
|
20
|
+
* @param options.vaultConnectorType The vault for the private keys, defaults to "vault".
|
|
21
|
+
*/
|
|
22
|
+
constructor(options?: {
|
|
23
|
+
didDocumentEntityStorageType?: string;
|
|
24
|
+
vaultConnectorType?: string;
|
|
25
|
+
});
|
|
26
|
+
/**
|
|
27
|
+
* Create a new document.
|
|
28
|
+
* @param controller The controller of the identity who can make changes.
|
|
29
|
+
* @returns The created document.
|
|
30
|
+
*/
|
|
31
|
+
createDocument(controller: string): Promise<IDidDocument>;
|
|
32
|
+
/**
|
|
33
|
+
* Resolve a document from its id.
|
|
34
|
+
* @param documentId The id of the document to resolve.
|
|
35
|
+
* @returns The resolved document.
|
|
36
|
+
* @throws NotFoundError if the id can not be resolved.
|
|
37
|
+
*/
|
|
38
|
+
resolveDocument(documentId: string): Promise<IDidDocument>;
|
|
39
|
+
/**
|
|
40
|
+
* Add a verification method to the document in JSON Web key Format.
|
|
41
|
+
* @param controller The controller of the identity who can make changes.
|
|
42
|
+
* @param documentId The id of the document to add the verification method to.
|
|
43
|
+
* @param verificationMethodType The type of the verification method to add.
|
|
44
|
+
* @param verificationMethodId The id of the verification method, if undefined uses the kid of the generated JWK.
|
|
45
|
+
* @returns The verification method.
|
|
46
|
+
* @throws NotFoundError if the id can not be resolved.
|
|
47
|
+
* @throws NotSupportedError if the platform does not support multiple keys.
|
|
48
|
+
*/
|
|
49
|
+
addVerificationMethod(controller: string, documentId: string, verificationMethodType: DidVerificationMethodType, verificationMethodId?: string): Promise<IDidDocumentVerificationMethod>;
|
|
50
|
+
/**
|
|
51
|
+
* Remove a verification method from the document.
|
|
52
|
+
* @param controller The controller of the identity who can make changes.
|
|
53
|
+
* @param verificationMethodId The id of the verification method.
|
|
54
|
+
* @returns Nothing.
|
|
55
|
+
* @throws NotFoundError if the id can not be resolved.
|
|
56
|
+
* @throws NotSupportedError if the platform does not support multiple revocable keys.
|
|
57
|
+
*/
|
|
58
|
+
removeVerificationMethod(controller: string, verificationMethodId: string): Promise<void>;
|
|
59
|
+
/**
|
|
60
|
+
* Add a service to the document.
|
|
61
|
+
* @param controller The controller of the identity who can make changes.
|
|
62
|
+
* @param documentId The id of the document to add the service to.
|
|
63
|
+
* @param serviceId The id of the service.
|
|
64
|
+
* @param serviceType The type of the service.
|
|
65
|
+
* @param serviceEndpoint The endpoint for the service.
|
|
66
|
+
* @returns The service.
|
|
67
|
+
* @throws NotFoundError if the id can not be resolved.
|
|
68
|
+
*/
|
|
69
|
+
addService(controller: string, documentId: string, serviceId: string, serviceType: string, serviceEndpoint: string): Promise<IDidService>;
|
|
70
|
+
/**
|
|
71
|
+
* Remove a service from the document.
|
|
72
|
+
* @param controller The controller of the identity who can make changes.
|
|
73
|
+
* @param serviceId The id of the service.
|
|
74
|
+
* @returns Nothing.
|
|
75
|
+
* @throws NotFoundError if the id can not be resolved.
|
|
76
|
+
*/
|
|
77
|
+
removeService(controller: string, serviceId: string): Promise<void>;
|
|
78
|
+
/**
|
|
79
|
+
* Create a verifiable credential for a verification method.
|
|
80
|
+
* @param controller The controller of the identity who can make changes.
|
|
81
|
+
* @param verificationMethodId The verification method id to use.
|
|
82
|
+
* @param id The id of the credential.
|
|
83
|
+
* @param credential The credential to store in the verifiable credential.
|
|
84
|
+
* @param revocationIndex The bitmap revocation index of the credential, if undefined will not have revocation status.
|
|
85
|
+
* @returns The created verifiable credential and its token.
|
|
86
|
+
* @throws NotFoundError if the id can not be resolved.
|
|
87
|
+
*/
|
|
88
|
+
createVerifiableCredential<T extends IJsonLdObject = IJsonLdObject>(controller: string, verificationMethodId: string, id: string | undefined, credential: T, revocationIndex?: number): Promise<{
|
|
89
|
+
verifiableCredential: IDidVerifiableCredential<T>;
|
|
90
|
+
jwt: string;
|
|
91
|
+
}>;
|
|
92
|
+
/**
|
|
93
|
+
* Check a verifiable credential is valid.
|
|
94
|
+
* @param credentialJwt The credential to verify.
|
|
95
|
+
* @returns The credential stored in the jwt and the revocation status.
|
|
96
|
+
*/
|
|
97
|
+
checkVerifiableCredential<T extends IJsonLdObject = IJsonLdObject>(credentialJwt: string): Promise<{
|
|
98
|
+
revoked: boolean;
|
|
99
|
+
verifiableCredential?: IDidVerifiableCredential<T>;
|
|
100
|
+
}>;
|
|
101
|
+
/**
|
|
102
|
+
* Revoke verifiable credential(s).
|
|
103
|
+
* @param controller The controller of the identity who can make changes.
|
|
104
|
+
* @param issuerDocumentId The id of the document to update the revocation list for.
|
|
105
|
+
* @param credentialIndices The revocation bitmap index or indices to revoke.
|
|
106
|
+
* @returns Nothing.
|
|
107
|
+
*/
|
|
108
|
+
revokeVerifiableCredentials(controller: string, issuerDocumentId: string, credentialIndices: number[]): Promise<void>;
|
|
109
|
+
/**
|
|
110
|
+
* Unrevoke verifiable credential(s).
|
|
111
|
+
* @param controller The controller of the identity who can make changes.
|
|
112
|
+
* @param issuerDocumentId The id of the document to update the revocation list for.
|
|
113
|
+
* @param credentialIndices The revocation bitmap index or indices to un revoke.
|
|
114
|
+
* @returns Nothing.
|
|
115
|
+
*/
|
|
116
|
+
unrevokeVerifiableCredentials(controller: string, issuerDocumentId: string, credentialIndices: number[]): Promise<void>;
|
|
117
|
+
/**
|
|
118
|
+
* Create a verifiable presentation from the supplied verifiable credentials.
|
|
119
|
+
* @param controller The controller of the identity who can make changes.
|
|
120
|
+
* @param presentationMethodId The method to associate with the presentation.
|
|
121
|
+
* @param presentationId The id of the presentation.
|
|
122
|
+
* @param contexts The contexts for the data stored in the verifiable credential.
|
|
123
|
+
* @param types The types for the data stored in the verifiable credential.
|
|
124
|
+
* @param verifiableCredentials The credentials to use for creating the presentation in jwt format.
|
|
125
|
+
* @param expiresInMinutes The time in minutes for the presentation to expire.
|
|
126
|
+
* @returns The created verifiable presentation and its token.
|
|
127
|
+
* @throws NotFoundError if the id can not be resolved.
|
|
128
|
+
*/
|
|
129
|
+
createVerifiablePresentation<T extends IJsonLdObject = IJsonLdObject>(controller: string, presentationMethodId: string, presentationId: string | undefined, contexts: IJsonLdContextDefinitionRoot | undefined, types: string | string[] | undefined, verifiableCredentials: (string | IDidVerifiableCredential<T>)[], expiresInMinutes?: number): Promise<{
|
|
130
|
+
verifiablePresentation: IDidVerifiablePresentation<T>;
|
|
131
|
+
jwt: string;
|
|
132
|
+
}>;
|
|
133
|
+
/**
|
|
134
|
+
* Check a verifiable presentation is valid.
|
|
135
|
+
* @param presentationJwt The presentation to verify.
|
|
136
|
+
* @returns The presentation stored in the jwt and the revocation status.
|
|
137
|
+
*/
|
|
138
|
+
checkVerifiablePresentation<T extends IJsonLdObject = IJsonLdObject>(presentationJwt: string): Promise<{
|
|
139
|
+
revoked: boolean;
|
|
140
|
+
verifiablePresentation?: IDidVerifiablePresentation<T>;
|
|
141
|
+
issuers?: IDidDocument[];
|
|
142
|
+
}>;
|
|
143
|
+
/**
|
|
144
|
+
* Create a proof for arbitrary data with the specified verification method.
|
|
145
|
+
* @param controller The controller of the identity who can make changes.
|
|
146
|
+
* @param verificationMethodId The verification method id to use.
|
|
147
|
+
* @param bytes The data bytes to sign.
|
|
148
|
+
* @returns The proof signature type and value.
|
|
149
|
+
*/
|
|
150
|
+
createProof(controller: string, verificationMethodId: string, bytes: Uint8Array): Promise<{
|
|
151
|
+
type: string;
|
|
152
|
+
value: Uint8Array;
|
|
153
|
+
}>;
|
|
154
|
+
/**
|
|
155
|
+
* Verify proof for arbitrary data with the specified verification method.
|
|
156
|
+
* @param verificationMethodId The verification method id to use.
|
|
157
|
+
* @param bytes The data bytes to verify.
|
|
158
|
+
* @param signatureType The type of the signature for the proof.
|
|
159
|
+
* @param signatureValue The value of the signature for the proof.
|
|
160
|
+
* @returns True if the signature is valid.
|
|
161
|
+
*/
|
|
162
|
+
verifyProof(verificationMethodId: string, bytes: Uint8Array, signatureType: string, signatureValue: Uint8Array): Promise<boolean>;
|
|
163
|
+
}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import type { IJsonLdDocument } from "@twin.org/data-json-ld";
|
|
2
|
+
import type { IIdentityProfileConnector } from "@twin.org/identity-models";
|
|
3
|
+
/**
|
|
4
|
+
* Class which implements the identity profile connector contract.
|
|
5
|
+
*/
|
|
6
|
+
export declare class EntityStorageIdentityProfileConnector<T extends IJsonLdDocument = IJsonLdDocument, U extends IJsonLdDocument = IJsonLdDocument> implements IIdentityProfileConnector<T, U> {
|
|
7
|
+
/**
|
|
8
|
+
* The namespace supported by the identity profile connector.
|
|
9
|
+
*/
|
|
10
|
+
static readonly NAMESPACE: string;
|
|
11
|
+
/**
|
|
12
|
+
* Runtime name for the class.
|
|
13
|
+
*/
|
|
14
|
+
readonly CLASS_NAME: string;
|
|
15
|
+
/**
|
|
16
|
+
* Create a new instance of Identity.
|
|
17
|
+
* @param options The dependencies for the identity service.
|
|
18
|
+
* @param options.profileEntityStorageType The storage connector for the profiles, default to "identity-profile".
|
|
19
|
+
*/
|
|
20
|
+
constructor(options?: {
|
|
21
|
+
profileEntityStorageType?: string;
|
|
22
|
+
});
|
|
23
|
+
/**
|
|
24
|
+
* Create the profile properties for an identity.
|
|
25
|
+
* @param identity The identity of the profile to create.
|
|
26
|
+
* @param publicProfile The public profile data.
|
|
27
|
+
* @param privateProfile The private profile data.
|
|
28
|
+
* @returns Nothing.
|
|
29
|
+
*/
|
|
30
|
+
create(identity: string, publicProfile?: T, privateProfile?: U): Promise<void>;
|
|
31
|
+
/**
|
|
32
|
+
* Get the profile properties for an identity.
|
|
33
|
+
* @param identity The identity of the item to get.
|
|
34
|
+
* @param publicPropertyNames The public properties to get for the profile, defaults to all.
|
|
35
|
+
* @param privatePropertyNames The private properties to get for the profile, defaults to all.
|
|
36
|
+
* @returns The items properties.
|
|
37
|
+
*/
|
|
38
|
+
get(identity: string, publicPropertyNames?: (keyof T)[], privatePropertyNames?: (keyof U)[]): Promise<{
|
|
39
|
+
publicProfile: Partial<T>;
|
|
40
|
+
privateProfile: Partial<U>;
|
|
41
|
+
}>;
|
|
42
|
+
/**
|
|
43
|
+
* Update the profile properties of an identity.
|
|
44
|
+
* @param identity The identity to update.
|
|
45
|
+
* @param publicProfile The public profile data.
|
|
46
|
+
* @param privateProfile The private profile data.
|
|
47
|
+
* @returns Nothing.
|
|
48
|
+
*/
|
|
49
|
+
update(identity: string, publicProfile?: T, privateProfile?: U): Promise<void>;
|
|
50
|
+
/**
|
|
51
|
+
* Delete the profile for an identity.
|
|
52
|
+
* @param identity The identity to delete.
|
|
53
|
+
* @returns Nothing.
|
|
54
|
+
*/
|
|
55
|
+
remove(identity: string): Promise<void>;
|
|
56
|
+
/**
|
|
57
|
+
* Get a list of the requested types.
|
|
58
|
+
* @param publicFilters The filters to apply to the identities public profiles.
|
|
59
|
+
* @param privateFilters The filters to apply to the identities private profiles.
|
|
60
|
+
* @param publicPropertyNames The public properties to get for the profile, defaults to all.
|
|
61
|
+
* @param privatePropertyNames The private properties to get for the profile, defaults to all.
|
|
62
|
+
* @param cursor The cursor for paged requests.
|
|
63
|
+
* @param pageSize The maximum number of items in a page.
|
|
64
|
+
* @returns The list of items and cursor for paging.
|
|
65
|
+
*/
|
|
66
|
+
list(publicFilters?: {
|
|
67
|
+
propertyName: string;
|
|
68
|
+
propertyValue: unknown;
|
|
69
|
+
}[], privateFilters?: {
|
|
70
|
+
propertyName: string;
|
|
71
|
+
propertyValue: unknown;
|
|
72
|
+
}[], publicPropertyNames?: (keyof T)[], privatePropertyNames?: (keyof U)[], cursor?: string, pageSize?: number): Promise<{
|
|
73
|
+
/**
|
|
74
|
+
* The identities.
|
|
75
|
+
*/
|
|
76
|
+
items: {
|
|
77
|
+
identity: string;
|
|
78
|
+
publicProfile?: Partial<T>;
|
|
79
|
+
privateProfile?: Partial<U>;
|
|
80
|
+
}[];
|
|
81
|
+
/**
|
|
82
|
+
* An optional cursor, when defined can be used to call find to get more entities.
|
|
83
|
+
*/
|
|
84
|
+
cursor?: string;
|
|
85
|
+
}>;
|
|
86
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Initialize the schema for the identity entity storage connector.
|
|
3
|
+
* @param options Options for which entities to register.
|
|
4
|
+
* @param options.includeDocument Whether to include the document entity, defaults to true.
|
|
5
|
+
* @param options.includeProfile Whether to include the profile entity, defaults to true.
|
|
6
|
+
*/
|
|
7
|
+
export declare function initSchema(options?: {
|
|
8
|
+
includeDocument?: boolean;
|
|
9
|
+
includeProfile?: boolean;
|
|
10
|
+
}): void;
|
package/docs/examples.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
# @twin.org/identity-connector-entity-storage - Examples
|