Skip to content

Commit

Permalink
refactor!: remove indy from core (openwallet-foundation#1286)
Browse files Browse the repository at this point in the history
Signed-off-by: Timo Glastra <timo@animo.id>
  • Loading branch information
TimoGlastra committed Feb 19, 2023
1 parent 616b908 commit b6d66b1
Show file tree
Hide file tree
Showing 348 changed files with 7,161 additions and 16,681 deletions.
6 changes: 6 additions & 0 deletions demo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,15 @@
"refresh": "rm -rf ./node_modules ./yarn.lock && yarn"
},
"devDependencies": {
"@aries-framework/anoncreds": "*",
"@aries-framework/anoncreds-rs": "*",
"@aries-framework/askar": "*",
"@aries-framework/core": "*",
"@aries-framework/indy-sdk": "*",
"@aries-framework/indy-vdr": "*",
"@aries-framework/node": "*",
"@types/figlet": "^1.5.4",
"@types/indy-sdk": "^1.16.26",
"@types/inquirer": "^8.1.3",
"clear": "^0.1.0",
"commander": "^8.3.0",
Expand Down
2 changes: 1 addition & 1 deletion demo/src/Alice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export class Alice extends BaseAgent {
public connectionRecordFaberId?: string

public constructor(port: number, name: string) {
super(port, name)
super({ port, name, useLegacyIndySdk: true })
this.connected = false
}

Expand Down
178 changes: 161 additions & 17 deletions demo/src/BaseAgent.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,34 @@
import type { IndySdkPoolConfig } from '../../packages/indy-sdk/src/ledger'
import type { IndyVdrPoolConfig } from '../../packages/indy-vdr/src/pool'
import type { InitConfig } from '@aries-framework/core'

import { Agent, AutoAcceptCredential, AutoAcceptProof, HttpOutboundTransport } from '@aries-framework/core'
import {
AnonCredsModule,
LegacyIndyCredentialFormatService,
LegacyIndyProofFormatService,
V1CredentialProtocol,
V1ProofProtocol,
} from '@aries-framework/anoncreds'
import { AnonCredsRsModule } from '@aries-framework/anoncreds-rs'
import { AskarModule } from '@aries-framework/askar'
import {
TypedArrayEncoder,
KeyType,
DidsModule,
V2ProofProtocol,
V2CredentialProtocol,
ProofsModule,
AutoAcceptProof,
AutoAcceptCredential,
CredentialsModule,
Agent,
HttpOutboundTransport,
} from '@aries-framework/core'
import { IndySdkAnonCredsRegistry, IndySdkModule, IndySdkSovDidResolver } from '@aries-framework/indy-sdk'
import { IndyVdrAnonCredsRegistry, IndyVdrModule, IndyVdrSovDidResolver } from '@aries-framework/indy-vdr'
import { agentDependencies, HttpInboundTransport } from '@aries-framework/node'
import { randomUUID } from 'crypto'
import indySdk from 'indy-sdk'

import { greenText } from './OutputClass'

Expand All @@ -10,46 +37,163 @@ const bcovrin = `{"reqSignature":{},"txn":{"data":{"data":{"alias":"Node1","blsk
{"reqSignature":{},"txn":{"data":{"data":{"alias":"Node3","blskey":"3WFpdbg7C5cnLYZwFZevJqhubkFALBfCBBok15GdrKMUhUjGsk3jV6QKj6MZgEubF7oqCafxNdkm7eswgA4sdKTRc82tLGzZBd6vNqU8dupzup6uYUf32KTHTPQbuUM8Yk4QFXjEf2Usu2TJcNkdgpyeUSX42u5LqdDDpNSWUK5deC5","blskey_pop":"QwDeb2CkNSx6r8QC8vGQK3GRv7Yndn84TGNijX8YXHPiagXajyfTjoR87rXUu4G4QLk2cF8NNyqWiYMus1623dELWwx57rLCFqGh7N4ZRbGDRP4fnVcaKg1BcUxQ866Ven4gw8y4N56S5HzxXNBZtLYmhGHvDtk6PFkFwCvxYrNYjh","client_ip":"138.197.138.255","client_port":9706,"node_ip":"138.197.138.255","node_port":9705,"services":["VALIDATOR"]},"dest":"DKVxG2fXXTU8yT5N7hGEbXB3dfdAnYv1JczDUHpmDxya"},"metadata":{"from":"4cU41vWW82ArfxJxHkzXPG"},"type":"0"},"txnMetadata":{"seqNo":3,"txnId":"7e9f355dffa78ed24668f0e0e369fd8c224076571c51e2ea8be5f26479edebe4"},"ver":"1"}
{"reqSignature":{},"txn":{"data":{"data":{"alias":"Node4","blskey":"2zN3bHM1m4rLz54MJHYSwvqzPchYp8jkHswveCLAEJVcX6Mm1wHQD1SkPYMzUDTZvWvhuE6VNAkK3KxVeEmsanSmvjVkReDeBEMxeDaayjcZjFGPydyey1qxBHmTvAnBKoPydvuTAqx5f7YNNRAdeLmUi99gERUU7TD8KfAa6MpQ9bw","blskey_pop":"RPLagxaR5xdimFzwmzYnz4ZhWtYQEj8iR5ZU53T2gitPCyCHQneUn2Huc4oeLd2B2HzkGnjAff4hWTJT6C7qHYB1Mv2wU5iHHGFWkhnTX9WsEAbunJCV2qcaXScKj4tTfvdDKfLiVuU2av6hbsMztirRze7LvYBkRHV3tGwyCptsrP","client_ip":"138.197.138.255","client_port":9708,"node_ip":"138.197.138.255","node_port":9707,"services":["VALIDATOR"]},"dest":"4PS3EDQ3dW1tci1Bp6543CfuuebjFrg36kLAUcskGfaA"},"metadata":{"from":"TWwCRQRZ2ZHMJFn9TzLp7W"},"type":"0"},"txnMetadata":{"seqNo":4,"txnId":"aa5e817d7cc626170eca175822029339a444eb0ee8f0bd20d3b0b76e566fb008"},"ver":"1"}`

const indyNetworkConfig = {
// Need unique network id as we will have multiple agent processes in the agent
id: randomUUID(),
genesisTransactions: bcovrin,
indyNamespace: 'bcovrin:test',
isProduction: false,
connectOnStartup: true,
} satisfies IndySdkPoolConfig | IndyVdrPoolConfig

type DemoAgent = Agent<ReturnType<typeof getLegacyIndySdkModules> | ReturnType<typeof getAskarAnonCredsIndyModules>>

export class BaseAgent {
public port: number
public name: string
public config: InitConfig
public agent: Agent
public agent: DemoAgent
public anonCredsIssuerId: string
public useLegacyIndySdk: boolean

public constructor(port: number, name: string) {
public constructor({
port,
name,
useLegacyIndySdk = false,
}: {
port: number
name: string
useLegacyIndySdk?: boolean
}) {
this.name = name
this.port = port

const config: InitConfig = {
const config = {
label: name,
walletConfig: {
id: name,
key: name,
},
publicDidSeed: '6b8b882e2618fa5d45ee7229ca880083',
indyLedgers: [
{
genesisTransactions: bcovrin,
id: 'greenlights' + name,
indyNamespace: 'greenlights' + name,
isProduction: false,
},
],
publicDidSeed: 'afjdemoverysercure00000000000000',
endpoints: [`http://localhost:${this.port}`],
autoAcceptConnections: true,
autoAcceptCredentials: AutoAcceptCredential.ContentApproved,
autoAcceptProofs: AutoAcceptProof.ContentApproved,
}
} satisfies InitConfig

this.config = config

this.agent = new Agent({ config, dependencies: agentDependencies })
// TODO: do not hardcode this
this.anonCredsIssuerId = '2jEvRuKmfBJTRa7QowDpNN'
this.useLegacyIndySdk = useLegacyIndySdk

this.agent = new Agent({
config,
dependencies: agentDependencies,
modules: useLegacyIndySdk ? getLegacyIndySdkModules() : getAskarAnonCredsIndyModules(),
})
this.agent.registerInboundTransport(new HttpInboundTransport({ port }))
this.agent.registerOutboundTransport(new HttpOutboundTransport())
}

public async initializeAgent() {
await this.agent.initialize()

// FIXME:
// We need to make sure the key to submit transactions is created. We should update this to use the dids module, and allow
// to add an existing did based on a seed/secretKey, and not register it on the the ledger. However for Indy SDK we currently
// use the deprecated publicDidSeed property (which will register the did in the wallet), and for Askar we manually create the key
// in the wallet.
if (!this.useLegacyIndySdk) {
try {
await this.agent.context.wallet.createKey({
keyType: KeyType.Ed25519,
privateKey: TypedArrayEncoder.fromString('afjdemoverysercure00000000000000'),
})
} catch (error) {
// We assume the key already exists, and that's why askar failed
}
}

console.log(greenText(`\nAgent ${this.name} created!\n`))
}
}

function getAskarAnonCredsIndyModules() {
const legacyIndyCredentialFormatService = new LegacyIndyCredentialFormatService()
const legacyIndyProofFormatService = new LegacyIndyProofFormatService()

return {
credentials: new CredentialsModule({
autoAcceptCredentials: AutoAcceptCredential.ContentApproved,
credentialProtocols: [
new V1CredentialProtocol({
indyCredentialFormat: legacyIndyCredentialFormatService,
}),
new V2CredentialProtocol({
credentialFormats: [legacyIndyCredentialFormatService],
}),
],
}),
proofs: new ProofsModule({
autoAcceptProofs: AutoAcceptProof.ContentApproved,
proofProtocols: [
new V1ProofProtocol({
indyProofFormat: legacyIndyProofFormatService,
}),
new V2ProofProtocol({
proofFormats: [legacyIndyProofFormatService],
}),
],
}),
anoncreds: new AnonCredsModule({
registries: [new IndyVdrAnonCredsRegistry()],
}),
anoncredsRs: new AnonCredsRsModule(),
indyVdr: new IndyVdrModule({
networks: [indyNetworkConfig],
}),
dids: new DidsModule({
resolvers: [new IndyVdrSovDidResolver()],
}),
askar: new AskarModule(),
} as const
}

function getLegacyIndySdkModules() {
const legacyIndyCredentialFormatService = new LegacyIndyCredentialFormatService()
const legacyIndyProofFormatService = new LegacyIndyProofFormatService()

return {
credentials: new CredentialsModule({
autoAcceptCredentials: AutoAcceptCredential.ContentApproved,
credentialProtocols: [
new V1CredentialProtocol({
indyCredentialFormat: legacyIndyCredentialFormatService,
}),
new V2CredentialProtocol({
credentialFormats: [legacyIndyCredentialFormatService],
}),
],
}),
proofs: new ProofsModule({
autoAcceptProofs: AutoAcceptProof.ContentApproved,
proofProtocols: [
new V1ProofProtocol({
indyProofFormat: legacyIndyProofFormatService,
}),
new V2ProofProtocol({
proofFormats: [legacyIndyProofFormatService],
}),
],
}),
anoncreds: new AnonCredsModule({
registries: [new IndySdkAnonCredsRegistry()],
}),
indySdk: new IndySdkModule({
indySdk,
networks: [indyNetworkConfig],
}),
dids: new DidsModule({
resolvers: [new IndySdkSovDidResolver()],
}),
} as const
}
87 changes: 59 additions & 28 deletions demo/src/Faber.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
import type { RegisterCredentialDefinitionReturnStateFinished } from '../../packages/anoncreds/src'
import type { ConnectionRecord, ConnectionStateChangedEvent } from '@aries-framework/core'
import type { CredDef, Schema } from 'indy-sdk'
import type BottomBar from 'inquirer/lib/ui/bottom-bar'

import { utils, V1CredentialPreview, ConnectionEventTypes } from '@aries-framework/core'
import { utils, ConnectionEventTypes } from '@aries-framework/core'
import { ui } from 'inquirer'

import { BaseAgent } from './BaseAgent'
import { Color, greenText, Output, purpleText, redText } from './OutputClass'

export class Faber extends BaseAgent {
public outOfBandId?: string
public credentialDefinition?: CredDef
public credentialDefinition?: RegisterCredentialDefinitionReturnStateFinished
public ui: BottomBar

public constructor(port: number, name: string) {
super(port, name)
super({ port, name })
this.ui = new ui.BottomBar()
}

Expand Down Expand Up @@ -105,39 +105,57 @@ export class Faber extends BaseAgent {
const schemaTemplate = {
name: 'Faber College' + utils.uuid(),
version: '1.0.0',
attributes: ['name', 'degree', 'date'],
attrNames: ['name', 'degree', 'date'],
issuerId: this.anonCredsIssuerId,
}
this.printSchema(schemaTemplate.name, schemaTemplate.version, schemaTemplate.attributes)
this.printSchema(schemaTemplate.name, schemaTemplate.version, schemaTemplate.attrNames)
this.ui.updateBottomBar(greenText('\nRegistering schema...\n', false))
const schema = await this.agent.ledger.registerSchema(schemaTemplate)

const { schemaState } = await this.agent.modules.anoncreds.registerSchema({
schema: schemaTemplate,
options: {
didIndyNamespace: 'bcovrin:test',
},
})

if (schemaState.state !== 'finished') {
throw new Error(
`Error registering schema: ${schemaState.state === 'failed' ? schemaState.reason : 'Not Finished'}}`
)
}
this.ui.updateBottomBar('\nSchema registered!\n')
return schema
return schemaState
}

private async registerCredentialDefinition(schema: Schema) {
private async registerCredentialDefinition(schemaId: string) {
this.ui.updateBottomBar('\nRegistering credential definition...\n')
this.credentialDefinition = await this.agent.ledger.registerCredentialDefinition({
schema,
tag: 'latest',
supportRevocation: false,
const { credentialDefinitionState } = await this.agent.modules.anoncreds.registerCredentialDefinition({
credentialDefinition: {
schemaId,
issuerId: this.anonCredsIssuerId,
tag: 'latest',
},
options: {
didIndyNamespace: 'bcovrin:test',
},
})

if (credentialDefinitionState.state !== 'finished') {
throw new Error(
`Error registering credential definition: ${
credentialDefinitionState.state === 'failed' ? credentialDefinitionState.reason : 'Not Finished'
}}`
)
}

this.credentialDefinition = credentialDefinitionState
this.ui.updateBottomBar('\nCredential definition registered!!\n')
return this.credentialDefinition
}

private getCredentialPreview() {
const credentialPreview = V1CredentialPreview.fromRecord({
name: 'Alice Smith',
degree: 'Computer Science',
date: '01/01/2022',
})
return credentialPreview
}

public async issueCredential() {
const schema = await this.registerSchema()
const credDef = await this.registerCredentialDefinition(schema)
const credentialPreview = this.getCredentialPreview()
const credentialDefinition = await this.registerCredentialDefinition(schema.schemaId)
const connectionRecord = await this.getConnectionRecord()

this.ui.updateBottomBar('\nSending credential offer...\n')
Expand All @@ -147,8 +165,21 @@ export class Faber extends BaseAgent {
protocolVersion: 'v1',
credentialFormats: {
indy: {
attributes: credentialPreview.attributes,
credentialDefinitionId: credDef.id,
attributes: [
{
name: 'name',
value: 'Alice Smith',
},
{
name: 'degree',
value: 'Computer Science',
},
{
name: 'date',
value: '01/01/2022',
},
],
credentialDefinitionId: credentialDefinition.credentialDefinitionId,
},
},
})
Expand All @@ -169,7 +200,7 @@ export class Faber extends BaseAgent {
name: 'name',
restrictions: [
{
credentialDefinitionId: this.credentialDefinition?.id,
cred_def_id: this.credentialDefinition?.credentialDefinitionId,
},
],
},
Expand All @@ -190,7 +221,7 @@ export class Faber extends BaseAgent {
indy: {
name: 'proof-request',
version: '1.0',
requestedAttributes: proofAttribute,
requested_attributes: proofAttribute,
},
},
})
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,11 @@
"eslint-plugin-import": "^2.23.4",
"eslint-plugin-prettier": "^3.4.0",
"express": "^4.17.1",
"indy-sdk": "^1.16.0-dev-1636",
"indy-sdk": "^1.16.0-dev-1655",
"jest": "^27.0.4",
"lerna": "^4.0.0",
"prettier": "^2.3.1",
"rxjs": "^7.2.0",
"rxjs": "^7.8.0",
"ts-jest": "^27.0.3",
"ts-node": "^10.0.0",
"tsconfig-paths": "^4.1.2",
Expand Down

0 comments on commit b6d66b1

Please sign in to comment.