Skip to content

Commit

Permalink
feat: Default IdentityProvider
Browse files Browse the repository at this point in the history
  • Loading branch information
simonas-notcat committed Apr 10, 2020
1 parent 9faf707 commit 3334f6e
Show file tree
Hide file tree
Showing 7 changed files with 77 additions and 69 deletions.
3 changes: 1 addition & 2 deletions examples/expressjs-ethr/src/identity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ export const getIdentity = async () => {
if (identities.length > 0) {
identity = identities[0]
} else {
const identityProviders = await agent.identityManager.getIdentityProviders()
identity = await agent.identityManager.createIdentity(identityProviders[0].type)
identity = await agent.identityManager.createIdentity()
}

return identity
Expand Down
50 changes: 25 additions & 25 deletions examples/expressjs-ethr/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -613,65 +613,65 @@ cross-fetch@^3.0.4:
node-fetch "2.6.0"
whatwg-fetch "3.0.0"

daf-core@../../packages/daf-core, daf-core@^4.0.0-beta.39+63dd12d:
version "4.0.0-beta.39"
daf-core@../../packages/daf-core, daf-core@^4.0.0-beta.42:
version "4.0.0-beta.42"
dependencies:
blakejs "^1.1.0"
debug "^4.1.1"
events "^3.0.0"
typeorm "^0.2.24"

daf-data-store@../../packages/daf-data-store, daf-data-store@^4.0.0-beta.39+63dd12d:
version "4.0.0-beta.39"
daf-data-store@../../packages/daf-data-store, daf-data-store@^4.0.0-beta.42:
version "4.0.0-beta.42"
dependencies:
blakejs "^1.1.0"
daf-core "^4.0.0-beta.39+63dd12d"
daf-core "^4.0.0-beta.42"
debug "^4.1.1"
sql-bricks-sqlite "^0.1.0"

daf-did-comm@../../packages/daf-did-comm:
version "4.0.0-beta.39"
version "4.0.0-beta.42"
dependencies:
daf-core "^4.0.0-beta.39+63dd12d"
daf-core "^4.0.0-beta.42"
debug "^4.1.1"
uuid "^3.3.3"

daf-did-jwt@../../packages/daf-did-jwt, daf-did-jwt@^4.0.0-beta.39+63dd12d:
version "4.0.0-beta.39"
daf-did-jwt@../../packages/daf-did-jwt, daf-did-jwt@^4.0.0-beta.42:
version "4.0.0-beta.42"
dependencies:
daf-core "^4.0.0-beta.39+63dd12d"
daf-core "^4.0.0-beta.42"
debug "^4.1.1"
did-jwt "^4.0.0"
did-resolver "^1.1.0"

daf-ethr-did@../../packages/daf-ethr-did:
version "4.0.0-beta.39"
version "4.0.0-beta.42"
dependencies:
daf-core "^4.0.0-beta.39+63dd12d"
daf-core "^4.0.0-beta.42"
debug "^4.1.1"
ethjs-provider-signer "^0.1.4"
ethr-did "^1.1.0"
js-sha3 "^0.8.0"

daf-libsodium@../../packages/daf-libsodium:
version "4.0.0-beta.39"
version "4.0.0-beta.42"
dependencies:
base-58 "^0.0.1"
daf-core "^4.0.0-beta.39+63dd12d"
daf-core "^4.0.0-beta.42"
debug "^4.1.1"
did-jwt "^4.0.0"
elliptic "^6.5.2"
ethjs-signer "^0.1.1"
libsodium-wrappers "^0.7.6"

daf-resolver-universal@../../packages/daf-resolver-universal:
version "3.0.1"
version "4.0.0-beta.42"
dependencies:
cross-fetch "^3.0.4"
debug "^4.1.1"

daf-resolver@../../packages/daf-resolver:
version "3.0.1"
version "4.0.0-beta.42"
dependencies:
debug "^4.1.1"
did-resolver "^1.1.0"
Expand All @@ -680,29 +680,29 @@ daf-resolver@../../packages/daf-resolver:
web-did-resolver "^1.2.0"

daf-selective-disclosure@../../packages/daf-selective-disclosure:
version "4.0.0-beta.41"
version "4.0.0-beta.42"
dependencies:
blakejs "^1.1.0"
daf-core "^4.0.0-beta.39+63dd12d"
daf-data-store "^4.0.0-beta.39+63dd12d"
daf-did-jwt "^4.0.0-beta.39+63dd12d"
daf-core "^4.0.0-beta.42"
daf-data-store "^4.0.0-beta.42"
daf-did-jwt "^4.0.0-beta.42"
debug "^4.1.1"
did-jwt "^4.0.0"
typeorm "^0.2.24"

daf-url@../../packages/daf-url:
version "4.0.0-beta.39"
version "4.0.0-beta.42"
dependencies:
daf-core "^4.0.0-beta.39+63dd12d"
daf-core "^4.0.0-beta.42"
debug "^4.1.1"
url-parse "^1.4.7"

daf-w3c@../../packages/daf-w3c:
version "4.0.0-beta.39"
version "4.0.0-beta.42"
dependencies:
blakejs "^1.1.0"
daf-core "^4.0.0-beta.39+63dd12d"
daf-did-jwt "^4.0.0-beta.39+63dd12d"
daf-core "^4.0.0-beta.42"
daf-did-jwt "^4.0.0-beta.42"
debug "^4.1.1"
did-jwt-vc "^0.1.3"
did-resolver "^1.1.0"
Expand Down
3 changes: 1 addition & 2 deletions examples/send-vc/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ async function main() {
if (identities.length > 0) {
identity = identities[0]
} else {
const identityProviders = await agent.identityManager.getIdentityProviders()
identity = await agent.identityManager.createIdentity(identityProviders[0].type)
identity = await agent.identityManager.createIdentity()
}

// Sign verifiable credential
Expand Down
38 changes: 19 additions & 19 deletions examples/send-vc/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -479,57 +479,57 @@ cross-fetch@^3.0.4:
node-fetch "2.6.0"
whatwg-fetch "3.0.0"

daf-core@../../packages/daf-core, daf-core@^4.0.0-beta.39+63dd12d:
version "4.0.0-beta.39"
daf-core@../../packages/daf-core, daf-core@^4.0.0-beta.42:
version "4.0.0-beta.42"
dependencies:
blakejs "^1.1.0"
debug "^4.1.1"
events "^3.0.0"
typeorm "^0.2.24"

daf-did-comm@../../packages/daf-did-comm:
version "4.0.0-beta.39"
version "4.0.0-beta.42"
dependencies:
daf-core "^4.0.0-beta.39+63dd12d"
daf-core "^4.0.0-beta.42"
debug "^4.1.1"
uuid "^3.3.3"

daf-did-jwt@../../packages/daf-did-jwt, daf-did-jwt@^4.0.0-beta.39+63dd12d:
version "4.0.0-beta.39"
daf-did-jwt@../../packages/daf-did-jwt, daf-did-jwt@^4.0.0-beta.42:
version "4.0.0-beta.42"
dependencies:
daf-core "^4.0.0-beta.39+63dd12d"
daf-core "^4.0.0-beta.42"
debug "^4.1.1"
did-jwt "^4.0.0"
did-resolver "^1.1.0"

daf-ethr-did@../../packages/daf-ethr-did:
version "4.0.0-beta.39"
version "4.0.0-beta.42"
dependencies:
daf-core "^4.0.0-beta.39+63dd12d"
daf-core "^4.0.0-beta.42"
debug "^4.1.1"
ethjs-provider-signer "^0.1.4"
ethr-did "^1.1.0"
js-sha3 "^0.8.0"

daf-fs@../../packages/daf-fs:
version "4.0.0-beta.39"
version "4.0.0-beta.42"
dependencies:
daf-core "^4.0.0-beta.39+63dd12d"
daf-core "^4.0.0-beta.42"
debug "^4.1.1"

daf-libsodium@../../packages/daf-libsodium:
version "4.0.0-beta.39"
version "4.0.0-beta.42"
dependencies:
base-58 "^0.0.1"
daf-core "^4.0.0-beta.39+63dd12d"
daf-core "^4.0.0-beta.42"
debug "^4.1.1"
did-jwt "^4.0.0"
elliptic "^6.5.2"
ethjs-signer "^0.1.1"
libsodium-wrappers "^0.7.6"

daf-resolver@../../packages/daf-resolver:
version "3.0.1"
version "4.0.0-beta.42"
dependencies:
debug "^4.1.1"
did-resolver "^1.1.0"
Expand All @@ -538,7 +538,7 @@ daf-resolver@../../packages/daf-resolver:
web-did-resolver "^1.2.0"

daf-trust-graph@../../packages/daf-trust-graph:
version "4.0.0-beta.39"
version "4.0.0-beta.42"
dependencies:
apollo-cache-inmemory "^1.6.3"
apollo-client "^2.6.4"
Expand All @@ -547,19 +547,19 @@ daf-trust-graph@../../packages/daf-trust-graph:
apollo-link-ws "^1.0.19"
apollo-utilities "^1.3.2"
cross-fetch "^3.0.4"
daf-core "^4.0.0-beta.39+63dd12d"
daf-core "^4.0.0-beta.42"
debug "^4.1.1"
did-jwt "^4.0.0"
graphql "^14.0.0"
graphql-tag "^2.10.1"
subscriptions-transport-ws "^0.9.0"

daf-w3c@../../packages/daf-w3c:
version "4.0.0-beta.39"
version "4.0.0-beta.42"
dependencies:
blakejs "^1.1.0"
daf-core "^4.0.0-beta.39+63dd12d"
daf-did-jwt "^4.0.0-beta.39+63dd12d"
daf-core "^4.0.0-beta.42"
daf-did-jwt "^4.0.0-beta.42"
debug "^4.1.1"
did-jwt-vc "^0.1.3"
did-resolver "^1.1.0"
Expand Down
28 changes: 16 additions & 12 deletions packages/daf-cli/src/identity-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,19 +45,23 @@ program
if (cmd.create) {
try {
const providers = await agent.identityManager.getIdentityProviders()
let type
if (providers.length > 1) {
const answers = await inquirer.prompt([
{
type: 'list',
name: 'type',
choices: providers.map(provider => ({
name: `${provider.type} - ${provider.description}`,
value: provider.type,
})),
message: 'Select identity provider',
},
])

const answers = await inquirer.prompt([
{
type: 'list',
name: 'type',
choices: providers.map(provider => ({
name: `${provider.type} - ${provider.description}`,
value: provider.type,
})),
message: 'Select identity provider',
},
])
const identity = await agent.identityManager.createIdentity(answers.type)
type = answers.type
}
const identity = await agent.identityManager.createIdentity(type)
printTable([{ type: identity.identityProviderType, did: identity.did }])
} catch (e) {
console.error(e)
Expand Down
2 changes: 1 addition & 1 deletion packages/daf-core/src/graphql/graphql-identity-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export interface Context {
}

const identityProviders = async (_: any, args: any, ctx: Context) => {
return await ctx.agent.identityManager.getIdentityProviders()
return ctx.agent.identityManager.getIdentityProviders()
}

const managedIdentities = async (_: any, args: any, ctx: Context) => {
Expand Down
22 changes: 14 additions & 8 deletions packages/daf-core/src/identity/identity-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,18 @@ export class IdentityManager {
this.identityProviders = options.identityProviders
}

async getIdentityProviders(): Promise<AbstractIdentityProvider[]> {
getIdentityProviders(): AbstractIdentityProvider[] {
return this.identityProviders
}

async getIdentityProvider(type: string): Promise<AbstractIdentityProvider> {
getIdentityProvider(type: string): AbstractIdentityProvider {
for (const identityProvider of this.identityProviders) {
if (identityProvider.type === type) {
return identityProvider
}
}

return Promise.reject('IdentityProvider not found for type: ' + type)
throw Error('IdentityProvider not found for type: ' + type)
}

async getIdentities(): Promise<AbstractIdentity[]> {
Expand All @@ -45,23 +45,29 @@ export class IdentityManager {
}
}

async createIdentity(identityProviderType: string): Promise<AbstractIdentity> {
const identityProvider = await this.getIdentityProvider(identityProviderType)
async createIdentity(identityProviderType?: string): Promise<AbstractIdentity> {
const identityProvider = identityProviderType
? this.getIdentityProvider(identityProviderType)
: this.getDefaultIdentityProvider()
return identityProvider.createIdentity()
}

async importIdentity(identityProviderType: string, secret: string): Promise<AbstractIdentity> {
const identityProvider = await this.getIdentityProvider(identityProviderType)
const identityProvider = this.getIdentityProvider(identityProviderType)
return identityProvider.importIdentity(secret)
}

async exportIdentity(identityProviderType: string, did: string): Promise<string> {
const identityProvider = await this.getIdentityProvider(identityProviderType)
const identityProvider = this.getIdentityProvider(identityProviderType)
return identityProvider.exportIdentity(did)
}

async deleteIdentity(identityProviderType: string, did: string): Promise<boolean> {
const identityProvider = await this.getIdentityProvider(identityProviderType)
const identityProvider = this.getIdentityProvider(identityProviderType)
return identityProvider.deleteIdentity(did)
}

private getDefaultIdentityProvider(): AbstractIdentityProvider {
return this.identityProviders[0]
}
}

0 comments on commit 3334f6e

Please sign in to comment.