Skip to content

Commit

Permalink
Feature/ver 172 (#38)
Browse files Browse the repository at this point in the history
* added implicit invite endpoint & version bump
  • Loading branch information
Ellenn-A authored Jan 15, 2024
1 parent 64f2f15 commit 715295b
Show file tree
Hide file tree
Showing 6 changed files with 86 additions and 7 deletions.
6 changes: 3 additions & 3 deletions docker-compose-testnet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ services:
#- '5003:5003'
- '3000:3000'
# or via command line arguments
command: --endpoint "http://alice:5002", "ws://alice:5003" --ipfs-origin http://ipfs0:5001 --config /config.json --persona-title "TA" --persona-color "#eddedf"
command: --endpoint "http://alice:5002" "ws://alice:5003" --ipfs-origin http://ipfs0:5001 --config /config.json --persona-title "TA" --persona-color "#eddedf"
networks:
- testnet

Expand All @@ -62,7 +62,7 @@ services:
#- '5102:5002'
#- '5103:5003'
- '3001:3000'
command: --endpoint "http://bob:5002", "ws://bob:5003" --ipfs-origin http://ipfs1:5001 --config /config.json --persona-title "OEM" --persona-color "#dfedde"
command: --endpoint "http://bob:5002" "ws://bob:5003" --ipfs-origin http://ipfs1:5001 --config /config.json --persona-title "OEM" --persona-color "#dfedde"
networks:
- testnet

Expand All @@ -86,7 +86,7 @@ services:
#- '5202:5002'
#- '5203:5003'
- '3002:3000'
command: --endpoint "http://charlie:5002", "ws://charlie:5003" --ipfs-origin http://ipfs2:5001 --config /config.json --persona-title "Supplier" --persona-color "#dedfed"
command: --endpoint "http://charlie:5002" "ws://charlie:5003" --ipfs-origin http://ipfs2:5001 --config /config.json --persona-title "Supplier" --persona-color "#dedfed"
networks:
- testnet

Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@digicatapult/veritable-cloudagent",
"version": "0.4.11",
"version": "0.4.12",
"main": "build/index",
"types": "build/index",
"files": [
Expand Down
2 changes: 1 addition & 1 deletion src/controllers/did/DidController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export class DidController extends Controller {
...rest,
privateKeys: privateKeys?.map(({ keyType, privateKey }) => ({
keyType,
privateKey: TypedArrayEncoder.fromString(privateKey),
privateKey: TypedArrayEncoder.fromBase64(privateKey),
})),
})
return this.getDidRecordByDid(options.did)
Expand Down
24 changes: 24 additions & 0 deletions src/controllers/outofband/OutOfBandController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import type {
ConnectionRecordProps,
CreateOutOfBandInvitationConfig,
CreateLegacyInvitationConfig,
ReceiveOutOfBandImplicitInvitationConfig,
} from '@aries-framework/core'

import { AgentMessage, JsonTransformer, OutOfBandInvitation, Agent, RecordNotFoundError } from '@aries-framework/core'
Expand Down Expand Up @@ -180,6 +181,29 @@ export class OutOfBandController extends Controller {
connectionRecord: connectionRecord?.toJSON(),
}
}
/**
* Creates inbound out-of-band record from an implicit invitation, given as public DID the agent should be able to resolve
* It automatically passes out-of-band invitation for further
* processing to `acceptInvitation` method. If you don't want to do that you can set
* `autoAcceptInvitation` attribute in `config` parameter to `false` and accept the message later by
* calling `acceptInvitation`.
*
* @param config config for creating and handling invitation
* @returns out-of-band record and connection record if one has been created.
*/
@Example<{ outOfBandRecord: OutOfBandRecordWithInvitationProps; connectionRecord: ConnectionRecordProps }>({
outOfBandRecord: outOfBandRecordExample,
connectionRecord: ConnectionRecordExample,
})
@Post('/receive-implicit-invitation')
@Response<HttpResponse>(500)
public async receiveImplicitInvitation(@Body() config: ReceiveOutOfBandImplicitInvitationConfig) {
const { outOfBandRecord, connectionRecord } = await this.agent.oob.receiveImplicitInvitation(config)
return {
outOfBandRecord: outOfBandRecord.toJSON(),
connectionRecord: connectionRecord?.toJSON(),
}
}

/**
* Creates inbound out-of-band record and assigns out-of-band invitation message to it if the
Expand Down
55 changes: 55 additions & 0 deletions tests/unit/outofband.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import type {
ConnectionRecord,
OutOfBandInvitation,
ConnectionInvitationMessage,
ReceiveOutOfBandImplicitInvitationConfig,
} from '@aries-framework/core'
import type { Express } from 'express'

Expand Down Expand Up @@ -285,6 +286,60 @@ describe('OutOfBandController', () => {
).equals(true)
})
})
describe('Receive out of band implicit invitation', () => {
const config: ReceiveOutOfBandImplicitInvitationConfig = {
did: 'z6Mkk7yqnGF3YwTrLpqrW6PGsKci7dNqh1CjnvMbzrMerSeL',
}
test('should return out of band invitation', async () => {
const receiveImplicitInvitationStub = stub(bobAgent.oob, 'receiveImplicitInvitation')
receiveImplicitInvitationStub.resolves({
outOfBandRecord: outOfBandRecord,
connectionRecord: connectionRecord,
})
const getResult = () => receiveImplicitInvitationStub.firstCall.returnValue

const response = await request(app).post('/oob/receive-implicit-invitation').send(config) //use barebones config

expect(response.statusCode).to.be.equal(200)
expect(response.body).to.deep.equal(objectToJson(await getResult()))
})
test('should use parameters', async () => {
const receiveImplicitInvitationStub = stub(bobAgent.oob, 'receiveImplicitInvitation')
receiveImplicitInvitationStub.resolves({
outOfBandRecord: outOfBandRecord,
connectionRecord: connectionRecord,
})

// todo: add tests for routing param
const params = {
label: 'test',
alias: 'test',
imageUrl: 'test',
autoAcceptInvitation: false,
autoAcceptConnection: false,
}

const response = await request(app)
.post('/oob/receive-implicit-invitation')
.send({
...config, //send config only containing did
...params,
})

expect(response.statusCode).to.be.equal(200)
expect(
receiveImplicitInvitationStub.calledWith(
match({
label: params.label,
alias: params.alias,
imageUrl: params.imageUrl,
autoAcceptInvitation: params.autoAcceptInvitation,
autoAcceptConnection: params.autoAcceptConnection,
})
)
).equals(true)
})
})

describe('Receive out of band invitation by url', () => {
test('should return out of band invitation', async () => {
Expand Down

0 comments on commit 715295b

Please sign in to comment.