Skip to content

Commit cdd3f1d

Browse files
committed
feat: 🎸 Identities:rotatePrimaryKeyToSecondary
1 parent 6f45230 commit cdd3f1d

File tree

6 files changed

+539
-0
lines changed

6 files changed

+539
-0
lines changed

src/api/client/Identities.ts

+23
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,15 @@ import {
1414
revokeIdentityToCreatePortfolios,
1515
RevokeIdentityToCreatePortfoliosParams,
1616
rotatePrimaryKey,
17+
rotatePrimaryKeyToSecondary,
1718
} from '~/internal';
1819
import {
1920
AttestPrimaryKeyRotationParams,
2021
CreateChildIdentityParams,
2122
ProcedureMethod,
2223
RegisterIdentityParams,
2324
RotatePrimaryKeyParams,
25+
RotatePrimaryKeyToSecondaryParams,
2426
} from '~/types';
2527
import { identityIdToString } from '~/utils/conversion';
2628
import { asIdentity, assertIdentityExists, createProcedureMethod } from '~/utils/internal';
@@ -52,6 +54,11 @@ export class Identities {
5254
context
5355
);
5456

57+
this.rotatePrimaryKeyToSecondary = createProcedureMethod(
58+
{ getProcedureAndArgs: args => [rotatePrimaryKeyToSecondary, args] },
59+
context
60+
);
61+
5562
this.createPortfolio = createProcedureMethod(
5663
{
5764
getProcedureAndArgs: args => [
@@ -131,6 +138,22 @@ export class Identities {
131138
*/
132139
public rotatePrimaryKey: ProcedureMethod<RotatePrimaryKeyParams, AuthorizationRequest>;
133140

141+
/**
142+
* Creates an Authorization to rotate primary key of the signing Identity to an existing secondary key identified by the `targetAccount`
143+
*
144+
* @note the given `targetAccount` must be an existing secondaryKey or unlinked to any other Identity
145+
* @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
146+
* 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}.
147+
* 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}
148+
* @throws if the given `targetAccount` is linked with another Identity
149+
* @throws if the given `targetAccount` is already the primary key of the signing Identity
150+
* @throws if the given `targetAccount` already has a pending invitation to become the primary key of the signing Identity
151+
*/
152+
public rotatePrimaryKeyToSecondary: ProcedureMethod<
153+
RotatePrimaryKeyToSecondaryParams,
154+
AuthorizationRequest
155+
>;
156+
134157
/**
135158
* Create a new Portfolio under the ownership of the signing Identity
136159
* @note the `ownerDid` is optional. If provided portfolios will be created as Custody Portfolios under the `ownerDid`

src/api/client/__tests__/Identities.ts

+26
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
} from '~/internal';
1212
import { dsMockUtils, entityMockUtils, procedureMockUtils } from '~/testUtils/mocks';
1313
import { Mocked } from '~/testUtils/types';
14+
import { RotatePrimaryKeyToSecondaryParams } from '~/types';
1415
import { tuple } from '~/types/utils';
1516
import * as utilsConversionModule from '~/utils/conversion';
1617

@@ -255,6 +256,31 @@ describe('Identities Class', () => {
255256
});
256257
});
257258

259+
describe('method: rotatePrimaryKeyToSecondary', () => {
260+
it('should prepare the procedure with the correct arguments and context, and return the resulting transaction', async () => {
261+
const args: RotatePrimaryKeyToSecondaryParams = {
262+
targetAccount: 'someAccount',
263+
expiry: new Date('01/01/2050'),
264+
permissions: {
265+
assets: null,
266+
transactions: null,
267+
transactionGroups: [],
268+
portfolios: null,
269+
},
270+
};
271+
272+
const expectedTransaction = 'someTransaction' as unknown as PolymeshTransaction<void>;
273+
274+
when(procedureMockUtils.getPrepareMock())
275+
.calledWith({ args, transformer: undefined }, context, {})
276+
.mockResolvedValue(expectedTransaction);
277+
278+
const tx = await identities.rotatePrimaryKeyToSecondary(args);
279+
280+
expect(tx).toBe(expectedTransaction);
281+
});
282+
});
283+
258284
describe('method: allowIdentityToCreatePortfolios', () => {
259285
it('should prepare the procedure with the correct arguments and context, and return the resulting transaction', async () => {
260286
const args = {

0 commit comments

Comments
 (0)