Skip to content

Commit

Permalink
fix: Examples
Browse files Browse the repository at this point in the history
  • Loading branch information
simonas-notcat committed Mar 11, 2020
1 parent 5234c54 commit e4581e1
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 7 deletions.
2 changes: 1 addition & 1 deletion examples/react-graphql/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ let didResolver = new DafResolver({ infuraProjectId })
const identityProviders = [
new DafEthrDid.IdentityProvider({
kms: new DafLibSodium.KeyManagementSystem(new Daf.KeyStore()),
identityStore: new Daf.IdentityStore(),
identityStore: new Daf.IdentityStore('rinkeby-ethr'),
network: 'rinkeby',
rpcUrl: 'https://rinkeby.infura.io/v3/' + infuraProjectId,
}),
Expand Down
20 changes: 16 additions & 4 deletions packages/daf-core/src/__tests__/entities.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { createConnection, Connection } from 'typeorm'
import { createConnection, Connection, In } from 'typeorm'
import { Identity, Key, Message, Credential, Presentation, Claim, MessageMetaData } from '../index'
import { Entities } from '../index'

Expand Down Expand Up @@ -105,9 +105,21 @@ describe('daf-core', () => {
relations: ['credentials', 'credentials.issuer', 'credentials.subject'],
})

console.log(message)

expect(message.credentials.length).toEqual(1)
// TODO
expect(message.credentials[0].claims.length).toEqual(3)

let where = {}

where['issuer'] = In([id1.did])
where['subject'] = In([id2.did])
where['type'] = 'name'

const claims = await Claim.find({
relations: ['credential', 'credential.issuer', 'credential.subject'],
where,
})

expect(claims[0].type).toEqual('name')
expect(claims[0].value).toEqual('Alice')
})
})
3 changes: 3 additions & 0 deletions packages/daf-core/src/entities/identity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ export class Identity extends BaseEntity {
@PrimaryColumn()
did: string

@Column({ nullable: true })
provider: string

@Column({ nullable: true })
controllerKeyId: string

Expand Down
7 changes: 6 additions & 1 deletion packages/daf-core/src/identity/identity-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ import Debug from 'debug'
const debug = Debug('daf:identity-store')

export class IdentityStore extends AbstractIdentityStore {
constructor(private provider: string) {
super()
}

async get(did: string) {
const identity = await Identity.findOne(did, { relations: ['keys'] })
if (!identity) throw Error('Identity not found')
Expand All @@ -25,6 +29,7 @@ export class IdentityStore extends AbstractIdentityStore {
identity.did = serializedIdentity.did
identity.controllerKeyId = serializedIdentity.controllerKeyId
identity.keys = []
identity.provider = this.provider

for (const sKey of serializedIdentity.keys) {
const key = new Key()
Expand All @@ -38,7 +43,7 @@ export class IdentityStore extends AbstractIdentityStore {
}

async listDids() {
const identities = await Identity.find()
const identities = await Identity.find({ where: { provider: this.provider } })
return identities.map(identity => identity.did)
}
}
6 changes: 5 additions & 1 deletion packages/daf-data-store/src/data-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,11 @@ export class DataStore {
where.push({ to: receiver })
}

const messages = await Message.find({ where, relations: ['from', 'to'] })
const messages = await Message.find({
where,
order: { saveDate: 'DESC' },
relations: ['from', 'to'],
})

return messages.map(this.messageToLegacyFormat)
}
Expand Down

0 comments on commit e4581e1

Please sign in to comment.