2019-06-20 00:20:09 +02:00
|
|
|
import Web3Provider from '../Web3Provider'
|
|
|
|
import ContractBase from './ContractBase'
|
|
|
|
import { zeroX, didPrefixed } from '../../utils'
|
|
|
|
import { InstantiableConfig } from '../../Instantiable.abstract'
|
2018-10-29 10:53:22 +01:00
|
|
|
|
|
|
|
export default class DIDRegistry extends ContractBase {
|
2019-06-20 00:20:09 +02:00
|
|
|
public static async getInstance(
|
|
|
|
config: InstantiableConfig
|
|
|
|
): Promise<DIDRegistry> {
|
|
|
|
const didRegistry: DIDRegistry = new DIDRegistry('DIDRegistry')
|
2019-03-21 02:56:58 +01:00
|
|
|
await didRegistry.init(config)
|
2018-10-29 10:53:22 +01:00
|
|
|
return didRegistry
|
|
|
|
}
|
|
|
|
|
2019-06-20 00:20:09 +02:00
|
|
|
public async registerAttribute(
|
|
|
|
did: string,
|
|
|
|
checksum: string,
|
|
|
|
providers: string[],
|
|
|
|
value: string,
|
|
|
|
ownerAddress: string
|
|
|
|
) {
|
|
|
|
return this.send('registerAttribute', ownerAddress, [
|
|
|
|
zeroX(did),
|
|
|
|
zeroX(checksum),
|
|
|
|
providers.map(zeroX),
|
|
|
|
value
|
|
|
|
])
|
2018-10-29 10:53:22 +01:00
|
|
|
}
|
|
|
|
|
2019-03-04 13:05:27 +01:00
|
|
|
public async getDIDOwner(did: string): Promise<string> {
|
2019-06-20 00:20:09 +02:00
|
|
|
return this.call('getDIDOwner', [zeroX(did)])
|
2018-10-29 10:53:22 +01:00
|
|
|
}
|
|
|
|
|
2019-03-04 13:05:27 +01:00
|
|
|
public async getBlockNumberUpdated(did: string): Promise<number> {
|
2019-06-20 00:20:09 +02:00
|
|
|
return +(await this.call('getBlockNumberUpdated', [zeroX(did)]))
|
2018-10-29 10:53:22 +01:00
|
|
|
}
|
2019-04-16 13:27:37 +02:00
|
|
|
|
|
|
|
public async getAttributesByOwner(owner: string): Promise<string[]> {
|
2019-06-20 00:20:09 +02:00
|
|
|
return (await this.getPastEvents('DIDAttributeRegistered', {
|
|
|
|
_owner: zeroX(owner)
|
|
|
|
}))
|
|
|
|
.map(({ returnValues }) => returnValues._did)
|
2019-04-16 13:27:37 +02:00
|
|
|
.map(didPrefixed)
|
|
|
|
}
|
2018-10-29 10:53:22 +01:00
|
|
|
}
|