UNPKG

@ew-did-registry/did-ethr-resolver

Version:

The package resolve CRUD operations on DID Documents

178 lines (177 loc) 6.42 kB
import { BigNumber } from 'ethers'; import { DIDAttribute, IAuthentication, IOperator, IPublicKey, IServiceEndpoint, IUpdateData, PubKeyType, RegistrySettings, IUpdateAttributeData } from '@ew-did-registry/did-resolver-interface'; import Resolver from './resolver'; import { EwSigner } from './ewSigner'; /** * To support/extend this Class, one just has to work with this file. * All the supporting functions are stored as private methods (i.e. with the '_' symbol) * One can easily extend the methods available by researching the smart contract functionality, * as well as by understanding how the read is performed. */ export declare class Operator extends Resolver implements IOperator { /** * ERC-1056 compliant ethereum smart-contract */ private _didRegistry; private _owner; private readonly _keys; private address?; /** * @param owner - Entity which controls document * @param settings - Settings to connect to Ethr registry */ constructor(owner: EwSigner, settings: RegistrySettings); protected getAddress(): Promise<string>; private did; getPublicKey(): string; /** * Relevant did should have positive cryptocurrency balance to perform * the transaction. Create method saves the public key in smart contract's * event, which can be qualified as document creation * * @param did * @param context * @returns Promise<boolean> */ create(): Promise<boolean>; /** * Sets attribute value in DID document identified by the did * * @example *```typescript * import { * Operator, DIDAttribute, Algorithms, PubKeyType, Encoding * } from '@ew-did-registry/did-resolver'; * import { Keys } from '@ew-did-registry/keys'; * const providerSettings = { * type: ProviderTypes.HTTP, * uriOrInfo: 'https://volta-rpc.energyweb.org', * } * const ownerKeys = new Keys(); * const owner = EwSigner.fromPrivateKey(ownerKeys.privateKey, providerSettings); * const operator = new Operator( * owner, * resolverSettings, * ); * const pKey = DIDAttribute.PublicKey; * const updateData = { * algo: Algorithms.ED25519, * type: PubKeyType.VerificationKey2018, * encoding: Encoding.HEX, * value: new Keys().publicKey, * }; * const validity = 10 * 60 * 1000; * const updated = await operator.update(did, pKey, updateData, validity); * ``` * * @param { string } did - did associated with DID document * @param { DIDAttribute } didAttribute - specifies updated section in DID document. Must be 31 * bytes or shorter * @param { IUpdateData } updateData * @param { number } validity - time in milliseconds during which * attribute will be valid * @returns Promise<number> */ update(did: string, didAttribute: DIDAttribute, updateData: IUpdateData, validity?: number): Promise<BigNumber>; /** * Revokes the delegate from DID Document * Returns true on success * * @param { string } did - did of identity of interest * @param { PubKeyType } delegateType - type of delegate of interest * @param { string } delegate - did of delegate of interest * @returns Promise<boolean> */ revokeDelegate(did: string, delegateType: PubKeyType, delegateDID: string): Promise<boolean>; /** * Revokes attribute from DID Document * Returns true on success * * @param { string } did - did of identity of interest * @param { DIDAttribute } attributeType - type of attribute to revoke * @param { IUpdateData } updateData - data required to identify the correct attribute to revoke * @returns Promise<boolean> */ revokeAttribute(did: string, attributeType: DIDAttribute, updateData: IUpdateAttributeData): Promise<boolean>; /** * Changes the owner of particular decentralised identity * Returns true on success * * @param { string } did - did of current identity owner * @param { string } newOwner - did of new owner that will be set on success * @returns Promise<boolean> */ changeOwner(did: string, newOwner: string): Promise<boolean>; /** * Revokes authentication methods, public keys and delegates from DID document * * @example * ```typescript *import { Operator } from '@ew-did-registry/did-resolver'; *import { Keys } from '@ew-did-registry/keys'; * * const providerSettings = { * type: ProviderTypes.HTTP, * uriOrInfo: 'https://volta-rpc.energyweb.org', * } * const ownerKeys = new Keys(); * const owner = EwSigner.fromPrivateKey(ownerKeys.privateKey, providerSettings); * const operator = new Operator( * owner, * resolverSettings, * ); * const updated = await operator.deactivate(did); * ``` * * @param did * @returns Promise<boolean> */ deactivate(did: string): Promise<void>; /** * Revokes authentication attributes * * @param did * @param auths * @param publicKeys * @private */ protected _revokeAuthentications(did: string, auths: IAuthentication[], publicKeys: IPublicKey[]): Promise<void>; /** * Revokes Public key attribute * * @param did * @param publicKeys * @private */ protected _revokePublicKeys(did: string, publicKeys: IPublicKey[]): Promise<void>; /** * Revokes service attributes * * @param did * @param services * @private */ protected _revokeServices(did: string, services: IServiceEndpoint[]): Promise<void>; /** * Private function to send transactions * * @param method * @param did * @param didAttribute * @param updateData * @param validity * @param overrides * @private */ protected _sendTransaction(method: string, did: string, didAttribute: DIDAttribute, updateData: IUpdateData, validity?: number, overrides?: { nonce?: number; }): Promise<BigNumber>; /** * Util functions to create attribute name, supported by read method * * @param attribute * @param updateData * @private */ protected _composeAttributeName(attribute: DIDAttribute, updateData: IUpdateData): string; }