generated from PolymeshAssociation/typescript-boilerplate
-
Notifications
You must be signed in to change notification settings - Fork 11
/
Identities.ts
136 lines (122 loc) · 5.16 KB
/
Identities.ts
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
132
133
134
135
136
import { createPortfolioTransformer } from '~/api/entities/Venue';
import {
attestPrimaryKeyRotation,
AuthorizationRequest,
Context,
createPortfolios,
Identity,
NumberedPortfolio,
registerIdentity,
rotatePrimaryKey,
} from '~/internal';
import {
AttestPrimaryKeyRotationParams,
ProcedureMethod,
RegisterIdentityParams,
RotatePrimaryKeyParams,
} from '~/types';
import { asIdentity, createProcedureMethod } from '~/utils/internal';
/**
* Handles all Identity related functionality
*/
export class Identities {
private context: Context;
/**
* @hidden
*/
constructor(context: Context) {
this.context = context;
this.registerIdentity = createProcedureMethod(
{ getProcedureAndArgs: args => [registerIdentity, args] },
context
);
this.attestPrimaryKeyRotation = createProcedureMethod(
{ getProcedureAndArgs: args => [attestPrimaryKeyRotation, args] },
context
);
this.rotatePrimaryKey = createProcedureMethod(
{ getProcedureAndArgs: args => [rotatePrimaryKey, args] },
context
);
this.createPortfolio = createProcedureMethod<
{ name: string },
{ names: string[] },
NumberedPortfolio[],
NumberedPortfolio
>(
{
getProcedureAndArgs: args => [
createPortfolios,
{
names: [args.name],
},
],
transformer: createPortfolioTransformer,
},
context
);
this.createPortfolios = createProcedureMethod(
{
getProcedureAndArgs: args => [createPortfolios, args],
},
context
);
}
/**
* Register an Identity, possibly with a CDD claim
*
* @note the transaction signer must be a CDD provider
* @note this may create {@link api/entities/AuthorizationRequest!AuthorizationRequest | Authorization Requests} which have to be accepted by the `targetAccount`.
* An {@link api/entities/Account!Account} or {@link api/entities/Identity!Identity} can fetch its pending Authorization Requests by calling {@link api/entities/common/namespaces/Authorizations!Authorizations.getReceived | authorizations.getReceived}.
* Also, an Account or Identity can directly fetch the details of an Authorization Request by calling {@link api/entities/common/namespaces/Authorizations!Authorizations.getOne | authorizations.getOne}
*
* @note required role:
* - Customer Due Diligence Provider
*/
public registerIdentity: ProcedureMethod<RegisterIdentityParams, Identity>;
/**
* Get CDD Provider's attestation to change primary key
*
* @note the transaction signer must be a CDD provider
* @note this creates an {@link api/entities/AuthorizationRequest!AuthorizationRequest | Authorization Requests} which have to be accepted by the `targetAccount` along with the authorization for `RotatingPrimaryKey`.
* An {@link api/entities/Account!Account} or {@link api/entities/Identity!Identity} can fetch its pending Authorization Requests by calling {@link api/entities/common/namespaces/Authorizations!Authorizations.getReceived | authorizations.getReceived}.
* Also, an Account or Identity can directly fetch the details of an Authorization Request by calling {@link api/entities/common/namespaces/Authorizations!Authorizations.getOne | authorizations.getOne}
*
* @note required role:
* - Customer Due Diligence Provider
*/
public attestPrimaryKeyRotation: ProcedureMethod<
AttestPrimaryKeyRotationParams,
AuthorizationRequest
>;
/**
* Creates an Authorization to rotate primary key of the signing Identity by the `targetAccount`
*
* @note this creates an {@link api/entities/AuthorizationRequest!AuthorizationRequest | Authorization Requests} which have to be accepted by the `targetAccount` along with the optional CDD authorization generated by CDD provider attesting the rotation of primary key
* An {@link api/entities/Account!Account} or {@link api/entities/Identity!Identity} can fetch its pending Authorization Requests by calling {@link api/entities/common/namespaces/Authorizations!Authorizations.getReceived | authorizations.getReceived}.
* Also, an Account or Identity can directly fetch the details of an Authorization Request by calling {@link api/entities/common/namespaces/Authorizations!Authorizations.getOne | authorizations.getOne}
*/
public rotatePrimaryKey: ProcedureMethod<RotatePrimaryKeyParams, AuthorizationRequest>;
/**
* Create a new Portfolio under the ownership of the signing Identity
*/
public createPortfolio: ProcedureMethod<{ name: string }, NumberedPortfolio[], NumberedPortfolio>;
/**
* Creates a set of new Portfolios under the ownership of the signing Identity
*/
public createPortfolios: ProcedureMethod<{ names: string[] }, NumberedPortfolio[]>;
/**
* Create an Identity instance from a DID
*
* @throws if there is no Identity with the passed DID
*/
public getIdentity(args: { did: string }): Promise<Identity> {
return this.context.getIdentity(args.did);
}
/**
* Return whether the supplied Identity/DID exists
*/
public isIdentityValid(args: { identity: Identity | string }): Promise<boolean> {
return asIdentity(args.identity, this.context).exists();
}
}