Skip to content

Commit

Permalink
feat: Adding ethr-did gas and ttl config
Browse files Browse the repository at this point in the history
  • Loading branch information
simonas-notcat committed May 6, 2020
1 parent 6f5385a commit d910b14
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
2 changes: 2 additions & 0 deletions packages/daf-cli/src/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ const setupAgent = async (): Promise<Daf.Agent> => {
kms: new KeyManagementSystem(new Daf.KeyStore(dbConnection, new SecretBox(process.env.DAF_SECRET_KEY))),
network: 'rinkeby',
rpcUrl: 'https://rinkeby.infura.io/v3/' + infuraProjectId,
gas: 10001,
ttl: 60 * 60 * 24 * 30 * 12 + 1,
}),
]
const serviceControllers = [TrustGraphServiceController]
Expand Down
15 changes: 11 additions & 4 deletions packages/daf-ethr-did/src/identity-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,35 +3,43 @@ const EthrDID = require('ethr-did')
import Debug from 'debug'
const debug = Debug('daf:ethr-did:identity-controller')

const DEFAULT_TTL = 60 * 60 * 24 * 30 * 12
const DEFAULT_GAS = 100000

export class IdentityController extends AbstractIdentityController {
private did: string
private kms: AbstractKeyManagementSystem
private identityStore: AbstractIdentityStore
private web3Provider: any
private address: string
private gas?: number
private ttl?: number

constructor(options: {
did: string
kms: AbstractKeyManagementSystem
identityStore: AbstractIdentityStore
web3Provider: any
address: string
ttl?: number
gas?: number
}) {
super()
this.did = options.did
this.kms = options.kms
this.identityStore = options.identityStore
this.web3Provider = options.web3Provider
this.address = options.address
this.ttl = options.ttl || DEFAULT_TTL
this.gas = options.gas || DEFAULT_GAS
}

async addService(service: { id: string; type: string; serviceEndpoint: string }): Promise<any> {
const ethrDid = new EthrDID({ address: this.address, provider: this.web3Provider })

const attribute = 'did/svc/' + service.type
const value = service.serviceEndpoint
const ttl = 60 * 60 * 24 * 30 * 12
const gas = 100000
const { ttl, gas } = this
debug('ethrDid.setAttribute', { attribute, value, ttl, gas })
try {
const txHash = await ethrDid.setAttribute(attribute, value, ttl, gas)
Expand All @@ -52,8 +60,7 @@ export class IdentityController extends AbstractIdentityController {
const usg = 'veriKey'
const attribute = 'did/pub/' + type + '/' + usg + '/hex'
const value = '0x' + key.serialized.publicKeyHex
const ttl = 60 * 60 * 24 * 30 * 12
const gas = 100000
const { ttl, gas } = this
debug('ethrDid.setAttribute', { attribute, value, ttl, gas })

try {
Expand Down
8 changes: 8 additions & 0 deletions packages/daf-ethr-did/src/identity-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,17 @@ export class IdentityProvider extends AbstractIdentityProvider {
private rpcUrl?: string
private kms: AbstractKeyManagementSystem
private identityStore: AbstractIdentityStore
private gas?: number
private ttl?: number

constructor(options: {
kms: AbstractKeyManagementSystem
identityStore: AbstractIdentityStore
network: string
rpcUrl?: string
web3Provider?: object
ttl?: number
gas?: number
}) {
super()
this.kms = options.kms
Expand All @@ -43,6 +47,8 @@ export class IdentityProvider extends AbstractIdentityProvider {
this.web3Provider = options.web3Provider
this.type = options.network + '-' + this.type
this.description = 'did:ethr ' + options.network + ' ' + this.description
this.ttl = options.ttl
this.gas = options.gas
}

private async identityFromSerialized(serializedIdentity: SerializedIdentity): Promise<AbstractIdentity> {
Expand All @@ -62,6 +68,8 @@ export class IdentityProvider extends AbstractIdentityProvider {
kms: this.kms,
identityStore: this.identityStore,
address: toEthereumAddress(key.serialized.publicKeyHex),
gas: this.gas,
ttl: this.ttl,
})

return new Identity({
Expand Down

0 comments on commit d910b14

Please sign in to comment.