Skip to content
Snippets Groups Projects
Unverified Commit 59e4340d authored by Zdravko Iliev's avatar Zdravko Iliev
Browse files

wip: sending proof request on connection and listening and getting email on...

wip: sending proof request on connection and listening and getting email on accepting this proof request
parent d61eba35
No related branches found
No related tags found
1 merge request!38feat: rest agent support for connection and proof change state events
Pipeline #65341 failed with stage
in 16 seconds
LEDGERS="BCOVRIN_TEST"
IDUNION_KEY=#add if you are using IDUNION as a ledger
IDUNION_BASIC_USER=#add if you are using IDUNION as a ledger
IDUNION_BASIC_PASS=#add if you are using IDUNION as a ledger
AGENT_PEER_URL="http://localhost:8001"
AGENT_NAME=EXAMPTTLE_AGENT_45
......
version: '3.8'
services:
builder:
privileged: true
image: node:18.16.0-buster-slim
volumes:
- ./../yarn.lock:/app/yarn.lock
- ./../package.json:/app/package.json
- ./../apps:/app/apps
- ./../libs:/app/libs
- ./../nx.json:/app/nx.json
- ./../tsconfig.base.json:/app/tsconfig.base.json
- ./data/node_modules:/app/node_modules
- ./data/dist:/app/dist
working_dir: /app
command:
- sh
- -c
- |
whoami
apt update -y && apt install python3 git make build-essential -y
yarn install
yarn build:agent
exit 0
pg_db:
image: 'postgres:latest'
ports:
......@@ -12,10 +36,13 @@ services:
- ./data/db-simple/:/var/lib/postgresql/data/
agent-issuer-simple:
image: node:18.16.0
volumes:
- ./data/node_modules:/app/node_modules
- ./data/dist/apps/agent:/app/
working_dir: /app
command: node main.js
container_name: agent-issuer-simple
build:
context: "../"
dockerfile: "./apps/agent/deployment/local/Dockerfile"
env_file:
- ./env/issuer.simple.env
ports:
......@@ -24,12 +51,17 @@ services:
depends_on:
pg_db:
condition: service_started
builder:
condition: service_completed_successfully
agent-holder-simple:
container_name: agent-holder-simple
build:
context: "../"
dockerfile: "./apps/agent/deployment/local/Dockerfile"
image: node:18.16.0
volumes:
- ./data/node_modules:/app/node_modules
- ./data/dist/apps/agent:/app/
working_dir: /app
command: node main.js
env_file:
- ./env/holder.simple.env
ports:
......@@ -38,3 +70,6 @@ services:
depends_on:
pg_db:
condition: service_started
builder:
condition: service_completed_successfully
LEDGERS="BCOVRIN_TEST"
IDUNION_KEY=
AGENT_PEER_URL="http://agent-holder:6001"
AGENT_NAME=DEV_SIMPLE_AGENT_HOLDER_OCM # this should be changed to company name
AGENT_KEY=DEV_SIMPLE_AGENT_HOLDER_OCM #example random string
AGENT_DID_SEED=200000000000000000000000TCuste21xh #did private key seed min lenght 32
IDUNION_KEY=6eb8859f-dd7f-445a-bc37-ba986145d3b6
IDUNION_BASIC_USER=idunion4ssi
IDUNION_BASIC_PASS=7eDZ+LrUbV5bCRwe6Ki0Gw==
AGENT_PEER_URL=http://agent-holder-simple:6001
AGENT_PEER_PORT=6001
AGENT_NAME=DEV_SIMPLE_AGENT_HOLDER_OCM_3919 # this should be changed to company name
AGENT_KEY=DEV_SIMPLE_AGENT_HOLDER_OCM_3818 #example random string
AGENT_DID_SEED=jhPctchKaUfyZ1ioz6Fjypoasdhjahjsiscdkd23ozxflxkaKD0RR4TICwx
AGENT_DB_HOST=pg_db:5432
AGENT_DB_USER=postgres
AGENT_DB_PASS=postgres
AGENT_PORT=8081
AGENT_PORT=8080
AGENT_CONSUMER_NAME=agent_1
AGENT_IS_REST=true
AGENT_MAX_MESSAGES=10
......
LEDGERS="BCOVRIN_TEST"
IDUNION_KEY=
AGENT_PEER_URL="http://agent-issuer:8001"
AGENT_NAME=DEV_SIMPLE_AGENT_ISSUER_OCM # this should be changed to company name
AGENT_KEY=DEV_SIMPLE_AGENT_ISSUER_OCM #example random string
AGENT_DID_SEED=200000000000000000000000TCuste21js #did private key seed min lenght 32
IDUNION_KEY=6eb8859f-dd7f-445a-bc37-ba986145d3b6
IDUNION_BASIC_USER=idunion4ssi
IDUNION_BASIC_PASS=7eDZ+LrUbV5bCRwe6Ki0Gw==
AGENT_PEER_URL=http://agent-issuer-simple:8001
AGENT_PEER_PORT=8001
AGENT_NAME=DEV_SIMPLE_AGENT_ISSUER_OCM_45 # this should be changed to company name
AGENT_KEY=DEV_SIMPLE_AGENT_ISSUER_OCM_45 #example random string
AGENT_DID_SEED=Cd0VanW68R3HCaskjdakjsNpiuadscmsBBPP3DV6pMdwDFdHvPasdasdas
AGENT_DB_HOST=pg_db:5432
AGENT_DB_USER=postgres
AGENT_DB_PASS=postgres
AGENT_PORT=8081
AGENT_PORT=8080
AGENT_CONSUMER_NAME=agent_1
AGENT_IS_REST=true
AGENT_MAX_MESSAGES=10
......
......@@ -6,7 +6,9 @@ import {
CredentialsModule,
DidsModule,
Key,
KeyDidResolver,
KeyType,
PeerDidResolver,
ProofsModule,
TypedArrayEncoder,
V2CredentialProtocol,
......@@ -126,7 +128,11 @@ export const getAskarAnonCredsIndyModules = (networks: any) => {
}),
dids: new DidsModule({
registrars: [new IndyVdrIndyDidRegistrar()],
resolvers: [new IndyVdrIndyDidResolver()],
resolvers: [
new IndyVdrIndyDidResolver(),
new KeyDidResolver(),
new PeerDidResolver(),
],
}),
askar: new AskarModule({
ariesAskar,
......
......@@ -5,6 +5,12 @@ import {
BasicMessageEventTypes,
BasicMessageRole,
BasicMessageStateChangedEvent,
ConnectionEventTypes,
ConnectionStateChangedEvent,
DidExchangeRole,
ProofEventTypes,
ProofState,
ProofStateChangedEvent,
} from "@aries-framework/core";
import {
MakeBasicMessageResponseDto,
......@@ -30,6 +36,118 @@ export class AgentEventListenerServce implements OnModuleInit {
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
this.agentConfig = this.configService.get<IConfAgent>("agent")!;
console.log(this.agentConfig.agentIsSVDX);
console.log(this.agentConfig.agentIsRest);
if (this.agentConfig.agentIsSVDX && this.agentConfig.agentIsRest) {
//listen to when someone accepts a connection only when HIN webhook is set up and agent is in rest mode
//Extract to separate methods
this.askar.agent.events.on(
ConnectionEventTypes.ConnectionStateChanged,
async (ev: ConnectionStateChangedEvent) => {
console.log("role", ev.payload.connectionRecord.role);
console.log("state", ev.payload.connectionRecord.state);
if (
ev.payload.connectionRecord.role === DidExchangeRole.Responder &&
ev.payload.connectionRecord.state !== "completed"
) {
console.log("izlizam");
return;
}
console.log("connection accepted", JSON.stringify(ev, null, 2));
//I should have early return and only send proof request once the connection is accepted
const connectionDid = ev.payload.connectionRecord.theirDid; //?
const connections = await this.askar.agent.connections.findAllByQuery(
{
did: connectionDid,
},
);
console.log(JSON.stringify(connections, null, 2));
//delete everything without the current connection
//I should delete every connection besides the one that issued the proof ?
//can this happen with oob proof request
// when the request is accepted get the theirDid and search in connections ??
try {
await this.askar.agent.proofs.requestProof({
protocolVersion: "v2",
connectionId: ev.payload.connectionRecord.id,
proofFormats: {
anoncreds: {
name: "proof-request",
version: "1.0",
requested_attributes: {
email: {
name: "email",
restrictions: [
{
schema_id:
"did:indy:bcovrin:test:JpJEjf2LfretHgfQjMZnsi/anoncreds/v0/SCHEMA/hin-mail-demo/0.0.1",
cred_def_id:
"did:indy:bcovrin:test:uyuegPSRmfqy6RUdgwJ5y/anoncreds/v0/CLAIM_DEF/50002/hin-demo-cred-def",
},
],
},
},
},
},
});
} catch (e) {
console.log(JSON.stringify(e, null, 2));
console.log("failed to issue credential");
}
},
);
this.askar.agent.events.on(
ProofEventTypes.ProofStateChanged,
async (ev: ProofStateChangedEvent) => {
console.log(
"proof event accepted",
JSON.stringify(ev.payload.proofRecord, null, 2),
);
//is this the correct state ??
if (
ProofState.Done !== ev.payload.proofRecord.state
) {
return;
}
const result = await this.askar.agent.proofs.findPresentationMessage(
ev.payload.proofRecord.id,
);
console.log(JSON.stringify(result));
if (!result) return;
const t = await result.formats[0].attachmentId;
const d = await result.getPresentationAttachmentById(t);
if (!d) return;
console.log(ev.payload.proofRecord.connectionId);
console.log(
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
d.getDataAsJson()?.requested_proof.revealed_attrs.email.raw,
);
},
);
}
this.askar.agent.events.on(
BasicMessageEventTypes.BasicMessageStateChanged,
async (ev: BasicMessageStateChangedEvent) => {
......
......@@ -18,5 +18,6 @@ export const agentConfig = registerAs(
agentConsumerMaxMessagess: parseInt(process.env["AGENT_MAX_MESSAGES"]!),
agentConsumerRateLimit: parseInt(process.env["AGENT_RETE_LIMIT"]!),
agentPort: parseInt(process.env["AGENT_PORT"]!),
agentIsSVDX: process.env["AGENT_IS_SVDX"] === "true",
}),
);
......@@ -12,4 +12,5 @@ export interface IConfAgent {
agentConsumerMaxMessagess: number;
agentConsumerRateLimit: number;
agentPort: number;
agentIsSVDX: boolean;
}
......@@ -9,8 +9,9 @@ export const agentSchema = Joi.object({
AGENT_DB_USER: Joi.string().required(),
AGENT_DB_PASS: Joi.string().required(),
AGENT_CONSUMER_NAME: Joi.string(),
AGENT_IS_REST: Joi.string().required(),
AGENT_IS_REST: Joi.string().optional(),
AGENT_MAX_MESSAGES: Joi.string().required(),
AGENT_RETE_LIMIT: Joi.string().required(),
AGENT_PORT: Joi.string().required(),
AGENT_IS_SVDX: Joi.string().optional(),
});
......@@ -4,6 +4,7 @@ import { IdunionProvider } from "./idunion/idunion.provider";
import { BcovrinTestProvider } from "./bcovrin-test/bcovrin-test.provider";
import { ConfigModule } from "@nestjs/config";
import { DidgramTestProvider } from "./didgram-test/didgram-test.provider";
import { IndicioDemonetProvider } from "./indicio-demonet/indicio-demonet.provider";
@Module({
imports: [ConfigModule],
......@@ -13,6 +14,7 @@ import { DidgramTestProvider } from "./didgram-test/didgram-test.provider";
IdunionProvider,
BcovrinTestProvider,
DidgramTestProvider,
IndicioDemonetProvider,
],
exports: [LedgersService],
})
......
......@@ -6,6 +6,7 @@ import { IndyVdrPoolConfig } from "@aries-framework/indy-vdr";
import { ConfigService } from "@nestjs/config";
import { ILedgers } from "@ocm-engine/config";
import { DidgramTestProvider } from "./didgram-test/didgram-test.provider";
import { IndicioDemonetProvider } from "./indicio-demonet/indicio-demonet.provider";
@Injectable()
export class LedgersService {
......@@ -17,9 +18,11 @@ export class LedgersService {
private bcovrin: BcovrinTestProvider,
private idUnion: IdunionProvider,
private didGram: DidgramTestProvider,
private indicio: IndicioDemonetProvider,
private configService: ConfigService,
) {
this.providers = [bcovrin, idUnion, didGram];
this.providers = [bcovrin, idUnion, didGram, indicio];
//FIXME: properly check for null
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment