From 7f69fdbb69b0380a4d9bfa41d76613b1c0b1dc51 Mon Sep 17 00:00:00 2001 From: JGiter Date: Tue, 9 Nov 2021 18:10:51 +0200 Subject: [PATCH] fix(didRegistry): update owned document --- ...egistry_didRegistry_service.DidRegistry.md | 16 +++---- package-lock.json | 2 +- .../didRegistry/didRegistry.service.ts | 43 +++++++++++-------- 3 files changed, 35 insertions(+), 26 deletions(-) diff --git a/docs/api/classes/modules_didRegistry_didRegistry_service.DidRegistry.md b/docs/api/classes/modules_didRegistry_didRegistry_service.DidRegistry.md index 29e34795..a23e6818 100644 --- a/docs/api/classes/modules_didRegistry_didRegistry_service.DidRegistry.md +++ b/docs/api/classes/modules_didRegistry_didRegistry_service.DidRegistry.md @@ -171,19 +171,19 @@ ___ ### updateDocument -▸ **updateDocument**(`options`): `Promise`<`boolean`\> +▸ **updateDocument**(`__namedParameters`): `Promise`<`boolean`\> **`description`** updates did document based on data provided #### Parameters -| Name | Type | Description | -| :------ | :------ | :------ | -| `options` | `Object` | Options to connect with blockchain | -| `options.data` | `IUpdateData` | New attribute value | -| `options.did?` | `string` | Asset did to be updated | -| `options.didAttribute` | `DIDAttribute` | Type of document to be updated | -| `options.validity?` | `number` | Time (s) for the attribute to expire | +| Name | Type | +| :------ | :------ | +| `__namedParameters` | `Object` | +| `__namedParameters.data` | `IUpdateData` | +| `__namedParameters.did?` | `string` | +| `__namedParameters.didAttribute` | `DIDAttribute` | +| `__namedParameters.validity?` | `number` | #### Returns diff --git a/package-lock.json b/package-lock.json index 27526f92..354136b5 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "iam-client-lib", - "version": "3.3.0-alpha.8", + "version": "3.3.0-alpha.9", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/src/modules/didRegistry/didRegistry.service.ts b/src/modules/didRegistry/didRegistry.service.ts index c11a012e..46be9bf4 100644 --- a/src/modules/didRegistry/didRegistry.service.ts +++ b/src/modules/didRegistry/didRegistry.service.ts @@ -157,32 +157,41 @@ export class DidRegistry { * @returns true if document is updated successfuly * */ - async updateDocument(options: { + async updateDocument({ + didAttribute, + data, + validity, + did = this._signerService.did, + }: { didAttribute: DIDAttribute; data: IUpdateData; did?: string; validity?: number; }): Promise { - const { didAttribute, data, validity, did } = options; - - if (!did) { + if (did === this._signerService.did) { const updated = await this._document.update(didAttribute, data, validity); return Boolean(updated); - } else if (!(await this._assetsService.getOwnedAssets()).find((a) => a.document.id === did)) { - throw new Error(ERROR_MESSAGES.CAN_NOT_UPDATE_NOT_CONTROLLED_DOCUMENT); - } - - const updateData: IUpdateData = { - algo: KeyType.Secp256k1, - encoding: Encoding.HEX, - ...data, - }; + } else { + const assetDID = (await this._assetsService.getOwnedAssets()).find((a) => a.document.id === did)?.id; + if (!assetDID) { + throw new Error(ERROR_MESSAGES.CAN_NOT_UPDATE_NOT_CONTROLLED_DOCUMENT); + } + const updateData: IUpdateData = { + algo: KeyType.Secp256k1, + encoding: Encoding.HEX, + ...data, + }; - const { didRegistryAddress: didContractAddress } = chainConfigs()[this._signerService.chainId]; - const operator = new ProxyOperator(this._identityOwner, { address: didContractAddress }, addressOf(did)); - const update = await operator.update(did, didAttribute, updateData); + const { didRegistryAddress: didContractAddress } = chainConfigs()[this._signerService.chainId]; + const operator = new ProxyOperator( + this._identityOwner, + { address: didContractAddress }, + addressOf(assetDID), + ); + const update = await operator.update(did, didAttribute, updateData); - return Boolean(update); + return Boolean(update); + } } /**