Skip to content

Commit

Permalink
feat: feature registry preliminary implementation
Browse files Browse the repository at this point in the history
Signed-off-by: Ariel Gentile <gentilester@gmail.com>

fix: expose oob domain (#990)

fix: some changes based on feedback

Signed-off-by: Ariel Gentile <gentilester@gmail.com>

docs: a few clarifications and TODOs

Signed-off-by: Ariel Gentile <gentilester@gmail.com>

feat: combine features

Signed-off-by: Ariel Gentile <gentilester@gmail.com>

test(credentials): fix flaky tests with events (#966)

Signed-off-by: 2byrds <2byrds@gmail.com>

feat: OOB public did (#930)

Signed-off-by: Pavel Zarecky <zarecky@procivis.ch>

feat(routing): manual mediator pickup lifecycle management (#989)

Signed-off-by: Ariel Gentile <gentilester@gmail.com>

docs(demo): faber creates invitation (#995)

Signed-off-by: conanoc <conanoc@gmail.com>

chore(release): v0.2.3 (#999)

Signed-off-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

Signed-off-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

fix: disclosures message fields and optional thid

Signed-off-by: Ariel Gentile <gentilester@gmail.com>

fix(question-answer): question answer protocol state/role check (#1001)

Signed-off-by: Ariel Gentile <gentilester@gmail.com>

refactor: move feature registration to module

Signed-off-by: Ariel Gentile <gentilester@gmail.com>

fix: dependency manager test

Signed-off-by: Ariel Gentile <gentilester@gmail.com>

fix: feature registry instance

Signed-off-by: Ariel Gentile <gentilester@gmail.com>
  • Loading branch information
genaris committed Sep 2, 2022
1 parent b699977 commit 7337b00
Show file tree
Hide file tree
Showing 101 changed files with 2,132 additions and 613 deletions.
19 changes: 19 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,25 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.

## [0.2.3](https://github.com/hyperledger/aries-framework-javascript/compare/v0.2.2...v0.2.3) (2022-08-30)

### Bug Fixes

- export the KeyDerivationMethod ([#958](https://github.com/hyperledger/aries-framework-javascript/issues/958)) ([04ab1cc](https://github.com/hyperledger/aries-framework-javascript/commit/04ab1cca853284d144fd64d35e26e9dfe77d4a1b))
- expose oob domain ([#990](https://github.com/hyperledger/aries-framework-javascript/issues/990)) ([dad975d](https://github.com/hyperledger/aries-framework-javascript/commit/dad975d9d9b658c6b37749ece2a91381e2a314c9))
- **generic-records:** support custom id property ([#964](https://github.com/hyperledger/aries-framework-javascript/issues/964)) ([0f690a0](https://github.com/hyperledger/aries-framework-javascript/commit/0f690a0564a25204cacfae7cd958f660f777567e))

### Features

- always initialize mediator ([#985](https://github.com/hyperledger/aries-framework-javascript/issues/985)) ([b699977](https://github.com/hyperledger/aries-framework-javascript/commit/b69997744ac9e30ffba22daac7789216d2683e36))
- delete by record id ([#983](https://github.com/hyperledger/aries-framework-javascript/issues/983)) ([d8a30d9](https://github.com/hyperledger/aries-framework-javascript/commit/d8a30d94d336cf3417c2cd00a8110185dde6a106))
- **ledger:** handle REQNACK response for write request ([#967](https://github.com/hyperledger/aries-framework-javascript/issues/967)) ([6468a93](https://github.com/hyperledger/aries-framework-javascript/commit/6468a9311c8458615871e1e85ba3f3b560453715))
- OOB public did ([#930](https://github.com/hyperledger/aries-framework-javascript/issues/930)) ([c99f3c9](https://github.com/hyperledger/aries-framework-javascript/commit/c99f3c9152a79ca6a0a24fdc93e7f3bebbb9d084))
- **proofs:** present proof as nested protocol ([#972](https://github.com/hyperledger/aries-framework-javascript/issues/972)) ([52247d9](https://github.com/hyperledger/aries-framework-javascript/commit/52247d997c5910924d3099c736dd2e20ec86a214))
- **routing:** manual mediator pickup lifecycle management ([#989](https://github.com/hyperledger/aries-framework-javascript/issues/989)) ([69d4906](https://github.com/hyperledger/aries-framework-javascript/commit/69d4906a0ceb8a311ca6bdad5ed6d2048335109a))
- **routing:** pickup v2 mediator role basic implementation ([#975](https://github.com/hyperledger/aries-framework-javascript/issues/975)) ([a989556](https://github.com/hyperledger/aries-framework-javascript/commit/a98955666853471d504f8a5c8c4623e18ba8c8ed))
- **routing:** support promise in message repo ([#959](https://github.com/hyperledger/aries-framework-javascript/issues/959)) ([79c5d8d](https://github.com/hyperledger/aries-framework-javascript/commit/79c5d8d76512b641167bce46e82f34cf22bc285e))

## [0.2.2](https://github.com/hyperledger/aries-framework-javascript/compare/v0.2.1...v0.2.2) (2022-07-15)

### Bug Fixes
Expand Down
85 changes: 17 additions & 68 deletions demo/src/Alice.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,11 @@
import type {
ConnectionRecord,
ConnectionStateChangedEvent,
CredentialExchangeRecord,
ProofRecord,
} from '@aries-framework/core'

import { ConnectionEventTypes } from '@aries-framework/core'
import type { ConnectionRecord, CredentialExchangeRecord, ProofRecord } from '@aries-framework/core'

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

export class Alice extends BaseAgent {
public outOfBandId?: string
public connected: boolean
public connectionRecordFaberId?: string

public constructor(port: number, name: string) {
super(port, name)
Expand All @@ -26,74 +19,30 @@ export class Alice extends BaseAgent {
}

private async getConnectionRecord() {
if (!this.outOfBandId) {
throw Error(redText(Output.MissingConnectionRecord))
}

const [connection] = await this.agent.connections.findAllByOutOfBandId(this.outOfBandId)

if (!connection) {
if (!this.connectionRecordFaberId) {
throw Error(redText(Output.MissingConnectionRecord))
}

return connection
return await this.agent.connections.getById(this.connectionRecordFaberId)
}

private async printConnectionInvite() {
const outOfBand = await this.agent.oob.createInvitation()
this.outOfBandId = outOfBand.id

console.log(
Output.ConnectionLink,
outOfBand.outOfBandInvitation.toUrl({ domain: `http://localhost:${this.port}` }),
'\n'
)
}

private async waitForConnection() {
if (!this.outOfBandId) {
throw new Error(redText(Output.MissingConnectionRecord))
private async receiveConnectionRequest(invitationUrl: string) {
const { connectionRecord } = await this.agent.oob.receiveInvitationFromUrl(invitationUrl)
if (!connectionRecord) {
throw new Error(redText(Output.NoConnectionRecordFromOutOfBand))
}
return connectionRecord
}

console.log('Waiting for Faber to finish connection...')

const getConnectionRecord = (outOfBandId: string) =>
new Promise<ConnectionRecord>((resolve, reject) => {
// Timeout of 20 seconds
const timeoutId = setTimeout(() => reject(new Error(redText(Output.MissingConnectionRecord))), 20000)

// Start listener
this.agent.events.on<ConnectionStateChangedEvent>(ConnectionEventTypes.ConnectionStateChanged, (e) => {
if (e.payload.connectionRecord.outOfBandId !== outOfBandId) return

clearTimeout(timeoutId)
resolve(e.payload.connectionRecord)
})

// Also retrieve the connection record by invitation if the event has already fired
void this.agent.connections.findAllByOutOfBandId(outOfBandId).then(([connectionRecord]) => {
if (connectionRecord) {
clearTimeout(timeoutId)
resolve(connectionRecord)
}
})
})

const connectionRecord = await getConnectionRecord(this.outOfBandId)

try {
await this.agent.connections.returnWhenIsConnected(connectionRecord.id)
} catch (e) {
console.log(redText(`\nTimeout of 20 seconds reached.. Returning to home screen.\n`))
return
}
console.log(greenText(Output.ConnectionEstablished))
private async waitForConnection(connectionRecord: ConnectionRecord) {
connectionRecord = await this.agent.connections.returnWhenIsConnected(connectionRecord.id)
this.connected = true
console.log(greenText(Output.ConnectionEstablished))
return connectionRecord.id
}

public async setupConnection() {
await this.printConnectionInvite()
await this.waitForConnection()
public async acceptConnection(invitation_url: string) {
const connectionRecord = await this.receiveConnectionRequest(invitation_url)
this.connectionRecordFaberId = await this.waitForConnection(connectionRecord)
}

public async acceptCredentialOffer(credentialRecord: CredentialExchangeRecord) {
Expand Down
12 changes: 7 additions & 5 deletions demo/src/AliceInquirer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export const runAlice = async () => {
}

enum PromptOptions {
CreateConnection = 'Create connection invitation',
ReceiveConnectionUrl = 'Receive connection invitation',
SendMessage = 'Send message',
Exit = 'Exit',
Restart = 'Restart',
Expand All @@ -42,9 +42,9 @@ export class AliceInquirer extends BaseInquirer {
}

private async getPromptChoice() {
if (this.alice.outOfBandId) return inquirer.prompt([this.inquireOptions(this.promptOptionsString)])
if (this.alice.connectionRecordFaberId) return inquirer.prompt([this.inquireOptions(this.promptOptionsString)])

const reducedOption = [PromptOptions.CreateConnection, PromptOptions.Exit, PromptOptions.Restart]
const reducedOption = [PromptOptions.ReceiveConnectionUrl, PromptOptions.Exit, PromptOptions.Restart]
return inquirer.prompt([this.inquireOptions(reducedOption)])
}

Expand All @@ -53,7 +53,7 @@ export class AliceInquirer extends BaseInquirer {
if (this.listener.on) return

switch (choice.options) {
case PromptOptions.CreateConnection:
case PromptOptions.ReceiveConnectionUrl:
await this.connection()
break
case PromptOptions.SendMessage:
Expand Down Expand Up @@ -88,7 +88,9 @@ export class AliceInquirer extends BaseInquirer {
}

public async connection() {
await this.alice.setupConnection()
const title = Title.InvitationTitle
const getUrl = await inquirer.prompt([this.inquireInput(title)])
await this.alice.acceptConnection(getUrl.input)
if (!this.alice.connected) return

this.listener.credentialOfferListener(this.alice, this)
Expand Down
84 changes: 67 additions & 17 deletions demo/src/Faber.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
import type { ConnectionRecord } from '@aries-framework/core'
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 { V1CredentialPreview, AttributeFilter, ProofAttributeInfo, utils } from '@aries-framework/core'
import {
V1CredentialPreview,
AttributeFilter,
ProofAttributeInfo,
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 connectionRecordAliceId?: string
public outOfBandId?: string
public credentialDefinition?: CredDef
public ui: BottomBar

Expand All @@ -25,29 +31,73 @@ export class Faber extends BaseAgent {
}

private async getConnectionRecord() {
if (!this.connectionRecordAliceId) {
if (!this.outOfBandId) {
throw Error(redText(Output.MissingConnectionRecord))
}
return await this.agent.connections.getById(this.connectionRecordAliceId)
}

private async receiveConnectionRequest(invitationUrl: string) {
const { connectionRecord } = await this.agent.oob.receiveInvitationFromUrl(invitationUrl)
if (!connectionRecord) {
throw new Error(redText(Output.NoConnectionRecordFromOutOfBand))
const [connection] = await this.agent.connections.findAllByOutOfBandId(this.outOfBandId)

if (!connection) {
throw Error(redText(Output.MissingConnectionRecord))
}
return connectionRecord

return connection
}

private async waitForConnection(connectionRecord: ConnectionRecord) {
connectionRecord = await this.agent.connections.returnWhenIsConnected(connectionRecord.id)
private async printConnectionInvite() {
const outOfBand = await this.agent.oob.createInvitation()
this.outOfBandId = outOfBand.id

console.log(
Output.ConnectionLink,
outOfBand.outOfBandInvitation.toUrl({ domain: `http://localhost:${this.port}` }),
'\n'
)
}

private async waitForConnection() {
if (!this.outOfBandId) {
throw new Error(redText(Output.MissingConnectionRecord))
}

console.log('Waiting for Alice to finish connection...')

const getConnectionRecord = (outOfBandId: string) =>
new Promise<ConnectionRecord>((resolve, reject) => {
// Timeout of 20 seconds
const timeoutId = setTimeout(() => reject(new Error(redText(Output.MissingConnectionRecord))), 20000)

// Start listener
this.agent.events.on<ConnectionStateChangedEvent>(ConnectionEventTypes.ConnectionStateChanged, (e) => {
if (e.payload.connectionRecord.outOfBandId !== outOfBandId) return

clearTimeout(timeoutId)
resolve(e.payload.connectionRecord)
})

// Also retrieve the connection record by invitation if the event has already fired
void this.agent.connections.findAllByOutOfBandId(outOfBandId).then(([connectionRecord]) => {
if (connectionRecord) {
clearTimeout(timeoutId)
resolve(connectionRecord)
}
})
})

const connectionRecord = await getConnectionRecord(this.outOfBandId)

try {
await this.agent.connections.returnWhenIsConnected(connectionRecord.id)
} catch (e) {
console.log(redText(`\nTimeout of 20 seconds reached.. Returning to home screen.\n`))
return
}
console.log(greenText(Output.ConnectionEstablished))
return connectionRecord.id
}

public async acceptConnection(invitation_url: string) {
const connectionRecord = await this.receiveConnectionRequest(invitation_url)
this.connectionRecordAliceId = await this.waitForConnection(connectionRecord)
public async setupConnection() {
await this.printConnectionInvite()
await this.waitForConnection()
}

private printSchema(name: string, version: string, attributes: string[]) {
Expand Down
14 changes: 6 additions & 8 deletions demo/src/FaberInquirer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export const runFaber = async () => {
}

enum PromptOptions {
ReceiveConnectionUrl = 'Receive connection invitation',
CreateConnection = 'Create connection invitation',
OfferCredential = 'Offer credential',
RequestProof = 'Request proof',
SendMessage = 'Send message',
Expand All @@ -42,9 +42,9 @@ export class FaberInquirer extends BaseInquirer {
}

private async getPromptChoice() {
if (this.faber.connectionRecordAliceId) return inquirer.prompt([this.inquireOptions(this.promptOptionsString)])
if (this.faber.outOfBandId) return inquirer.prompt([this.inquireOptions(this.promptOptionsString)])

const reducedOption = [PromptOptions.ReceiveConnectionUrl, PromptOptions.Exit, PromptOptions.Restart]
const reducedOption = [PromptOptions.CreateConnection, PromptOptions.Exit, PromptOptions.Restart]
return inquirer.prompt([this.inquireOptions(reducedOption)])
}

Expand All @@ -53,7 +53,7 @@ export class FaberInquirer extends BaseInquirer {
if (this.listener.on) return

switch (choice.options) {
case PromptOptions.ReceiveConnectionUrl:
case PromptOptions.CreateConnection:
await this.connection()
break
case PromptOptions.OfferCredential:
Expand All @@ -76,9 +76,7 @@ export class FaberInquirer extends BaseInquirer {
}

public async connection() {
const title = Title.InvitationTitle
const getUrl = await inquirer.prompt([this.inquireInput(title)])
await this.faber.acceptConnection(getUrl.input)
await this.faber.setupConnection()
}

public async exitUseCase(title: string) {
Expand All @@ -104,7 +102,7 @@ export class FaberInquirer extends BaseInquirer {

public async message() {
const message = await this.inquireMessage()
if (message) return
if (!message) return

await this.faber.sendMessage(message)
}
Expand Down
2 changes: 1 addition & 1 deletion demo/src/OutputClass.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export enum Output {
NoConnectionRecordFromOutOfBand = `\nNo connectionRecord has been created from invitation\n`,
ConnectionEstablished = `\nConnection established!`,
MissingConnectionRecord = `\nNo connectionRecord ID has been set yet\n`,
ConnectionLink = `\nRun 'Receive connection invitation' in Faber and paste this invitation link:\n\n`,
ConnectionLink = `\nRun 'Receive connection invitation' in Alice and paste this invitation link:\n\n`,
Exit = 'Shutting down agent...\nExiting...',
}

Expand Down
2 changes: 1 addition & 1 deletion lerna.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"packages": ["packages/*"],
"version": "0.2.2",
"version": "0.2.3",
"useWorkspaces": true,
"npmClient": "yarn",
"command": {
Expand Down
19 changes: 19 additions & 0 deletions packages/core/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,25 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.

## [0.2.3](https://github.com/hyperledger/aries-framework-javascript/compare/v0.2.2...v0.2.3) (2022-08-30)

### Bug Fixes

- export the KeyDerivationMethod ([#958](https://github.com/hyperledger/aries-framework-javascript/issues/958)) ([04ab1cc](https://github.com/hyperledger/aries-framework-javascript/commit/04ab1cca853284d144fd64d35e26e9dfe77d4a1b))
- expose oob domain ([#990](https://github.com/hyperledger/aries-framework-javascript/issues/990)) ([dad975d](https://github.com/hyperledger/aries-framework-javascript/commit/dad975d9d9b658c6b37749ece2a91381e2a314c9))
- **generic-records:** support custom id property ([#964](https://github.com/hyperledger/aries-framework-javascript/issues/964)) ([0f690a0](https://github.com/hyperledger/aries-framework-javascript/commit/0f690a0564a25204cacfae7cd958f660f777567e))

### Features

- always initialize mediator ([#985](https://github.com/hyperledger/aries-framework-javascript/issues/985)) ([b699977](https://github.com/hyperledger/aries-framework-javascript/commit/b69997744ac9e30ffba22daac7789216d2683e36))
- delete by record id ([#983](https://github.com/hyperledger/aries-framework-javascript/issues/983)) ([d8a30d9](https://github.com/hyperledger/aries-framework-javascript/commit/d8a30d94d336cf3417c2cd00a8110185dde6a106))
- **ledger:** handle REQNACK response for write request ([#967](https://github.com/hyperledger/aries-framework-javascript/issues/967)) ([6468a93](https://github.com/hyperledger/aries-framework-javascript/commit/6468a9311c8458615871e1e85ba3f3b560453715))
- OOB public did ([#930](https://github.com/hyperledger/aries-framework-javascript/issues/930)) ([c99f3c9](https://github.com/hyperledger/aries-framework-javascript/commit/c99f3c9152a79ca6a0a24fdc93e7f3bebbb9d084))
- **proofs:** present proof as nested protocol ([#972](https://github.com/hyperledger/aries-framework-javascript/issues/972)) ([52247d9](https://github.com/hyperledger/aries-framework-javascript/commit/52247d997c5910924d3099c736dd2e20ec86a214))
- **routing:** manual mediator pickup lifecycle management ([#989](https://github.com/hyperledger/aries-framework-javascript/issues/989)) ([69d4906](https://github.com/hyperledger/aries-framework-javascript/commit/69d4906a0ceb8a311ca6bdad5ed6d2048335109a))
- **routing:** pickup v2 mediator role basic implementation ([#975](https://github.com/hyperledger/aries-framework-javascript/issues/975)) ([a989556](https://github.com/hyperledger/aries-framework-javascript/commit/a98955666853471d504f8a5c8c4623e18ba8c8ed))
- **routing:** support promise in message repo ([#959](https://github.com/hyperledger/aries-framework-javascript/issues/959)) ([79c5d8d](https://github.com/hyperledger/aries-framework-javascript/commit/79c5d8d76512b641167bce46e82f34cf22bc285e))

## [0.2.2](https://github.com/hyperledger/aries-framework-javascript/compare/v0.2.1...v0.2.2) (2022-07-15)

### Bug Fixes
Expand Down
2 changes: 1 addition & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "@aries-framework/core",
"main": "build/index",
"types": "build/index",
"version": "0.2.2",
"version": "0.2.3",
"files": [
"build"
],
Expand Down
Loading

0 comments on commit 7337b00

Please sign in to comment.