Skip to content

Commit

Permalink
[WIP] openwallet-foundation#883: Supporting simplified VTP state types
Browse files Browse the repository at this point in the history
  • Loading branch information
spivachuk committed Jun 21, 2022
1 parent 088b0df commit 6cef16a
Show file tree
Hide file tree
Showing 20 changed files with 44 additions and 166 deletions.
6 changes: 3 additions & 3 deletions demo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
"refresh": "rm -rf ./node_modules ./yarn.lock && yarn"
},
"devDependencies": {
"@aries-framework/core": "npm:@sicpa-dlab/aries-framework-core",
"@aries-framework/node": "npm:@sicpa-dlab/aries-framework-node",
"@sicpa-dlab/value-transfer-protocol-ts": "^0.0.8",
"@aries-framework/core": "file:../packages/core",
"@aries-framework/node": "file:../packages/node",
"@sicpa-dlab/value-transfer-protocol-ts": "file:../../value-transfer-protocol-ts",
"@types/figlet": "^1.5.4",
"@types/inquirer": "^8.1.3",
"clear": "^0.1.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
},
"dependencies": {
"@multiformats/base-x": "^4.0.1",
"@sicpa-dlab/value-transfer-protocol-ts": "0.0.11",
"@sicpa-dlab/value-transfer-protocol-ts": "file:../../../value-transfer-protocol-ts",
"@stablelib/aes": "^1.0.1",
"@stablelib/ed25519": "^1.0.2",
"@stablelib/sha256": "^1.0.1",
Expand Down
37 changes: 6 additions & 31 deletions packages/core/src/modules/value-transfer/ValueTransferModule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,7 @@ import type { ValueTransferRecord, ValueTransferTags } from './repository'

import { Lifecycle, scoped } from 'tsyringe'

import { AgentConfig } from '../../agent/AgentConfig'
import { Dispatcher } from '../../agent/Dispatcher'
import { MessageSender } from '../../agent/MessageSender'
import { ConnectionService } from '../connections'
import { DidResolverService } from '../dids'

import { ValueTransferResponseCoordinator } from './ValueTransferResponseCoordinator'
import { RequestHandler } from './handlers'
Expand All @@ -27,10 +23,6 @@ import { ValueTransferWitnessService } from './services/ValueTransferWitnessServ

@scoped(Lifecycle.ContainerScoped)
export class ValueTransferModule {
private config: AgentConfig
private messageSender: MessageSender
private connectionService: ConnectionService
private resolverService: DidResolverService
private valueTransferService: ValueTransferService
private valueTransferGetterService: ValueTransferGetterService
private valueTransferGiverService: ValueTransferGiverService
Expand All @@ -39,20 +31,12 @@ export class ValueTransferModule {

public constructor(
dispatcher: Dispatcher,
config: AgentConfig,
messageSender: MessageSender,
connectionService: ConnectionService,
resolverService: DidResolverService,
valueTransferService: ValueTransferService,
valueTransferGetterService: ValueTransferGetterService,
valueTransferGiverService: ValueTransferGiverService,
valueTransferWitnessService: ValueTransferWitnessService,
valueTransferResponseCoordinator: ValueTransferResponseCoordinator
) {
this.config = config
this.messageSender = messageSender
this.connectionService = connectionService
this.resolverService = resolverService
this.valueTransferService = valueTransferService
this.valueTransferGetterService = valueTransferGetterService
this.valueTransferGiverService = valueTransferGiverService
Expand Down Expand Up @@ -167,32 +151,23 @@ export class ValueTransferModule {
}

private registerHandlers(dispatcher: Dispatcher) {
dispatcher.registerHandler(
new RequestHandler(this.config, this.valueTransferService, this.valueTransferWitnessService)
)
dispatcher.registerHandler(new RequestHandler(this.valueTransferService, this.valueTransferWitnessService))
dispatcher.registerHandler(
new RequestWitnessedHandler(
this.config,
this.valueTransferService,
this.valueTransferGiverService,
this.valueTransferResponseCoordinator
)
)
dispatcher.registerHandler(new RequestAcceptedHandler(this.valueTransferService, this.valueTransferWitnessService))
dispatcher.registerHandler(
new RequestAcceptedHandler(this.config, this.valueTransferService, this.valueTransferWitnessService)
)
dispatcher.registerHandler(
new RequestAcceptedWitnessedHandler(this.config, this.valueTransferService, this.valueTransferGetterService)
)
dispatcher.registerHandler(
new CashAcceptedHandler(this.config, this.valueTransferService, this.valueTransferWitnessService)
)
dispatcher.registerHandler(
new CashAcceptedWitnessedHandler(this.config, this.valueTransferService, this.valueTransferGiverService)
new RequestAcceptedWitnessedHandler(this.valueTransferService, this.valueTransferGetterService)
)
dispatcher.registerHandler(new CashAcceptedHandler(this.valueTransferService, this.valueTransferWitnessService))
dispatcher.registerHandler(
new CashRemovedHandler(this.config, this.valueTransferService, this.valueTransferWitnessService)
new CashAcceptedWitnessedHandler(this.valueTransferService, this.valueTransferGiverService)
)
dispatcher.registerHandler(new CashRemovedHandler(this.valueTransferService, this.valueTransferWitnessService))
dispatcher.registerHandler(new GetterReceiptHandler(this.valueTransferGetterService))
dispatcher.registerHandler(new GiverReceiptHandler(this.valueTransferGiverService))
dispatcher.registerHandler(new ProblemReportHandler(this.valueTransferService))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import type { AgentConfig } from '../../../agent/AgentConfig'
import type { Handler, HandlerInboundMessage } from '../../../agent/Handler'
import type { DIDCommV2Message } from '../../../agent/didcomm'
import type { ValueTransferService } from '../services'
Expand All @@ -7,18 +6,15 @@ import type { ValueTransferWitnessService } from '../services/ValueTransferWitne
import { CashAcceptedMessage, ProblemReportMessage } from '../messages'

export class CashAcceptedHandler implements Handler<typeof DIDCommV2Message> {
private agentConfig: AgentConfig
private valueTransferService: ValueTransferService
private valueTransferWitnessService: ValueTransferWitnessService

public readonly supportedMessages = [CashAcceptedMessage]

public constructor(
agentConfig: AgentConfig,
valueTransferService: ValueTransferService,
valueTransferWitnessService: ValueTransferWitnessService
) {
this.agentConfig = agentConfig
this.valueTransferService = valueTransferService
this.valueTransferWitnessService = valueTransferWitnessService
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import type { AgentConfig } from '../../../agent/AgentConfig'
import type { HandlerInboundMessage, Handler } from '../../../agent/Handler'
import type { DIDCommV2Message } from '../../../agent/didcomm'
import type { ValueTransferService } from '../services'
Expand All @@ -7,18 +6,15 @@ import type { ValueTransferGiverService } from '../services/ValueTransferGiverSe
import { CashAcceptedWitnessedMessage } from '../messages'

export class CashAcceptedWitnessedHandler implements Handler<typeof DIDCommV2Message> {
private agentConfig: AgentConfig
private valueTransferService: ValueTransferService
private valueTransferGiverService: ValueTransferGiverService

public readonly supportedMessages = [CashAcceptedWitnessedMessage]

public constructor(
agentConfig: AgentConfig,
valueTransferService: ValueTransferService,
valueTransferGiverService: ValueTransferGiverService
) {
this.agentConfig = agentConfig
this.valueTransferService = valueTransferService
this.valueTransferGiverService = valueTransferGiverService
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import type { AgentConfig } from '../../../agent/AgentConfig'
import type { Handler, HandlerInboundMessage } from '../../../agent/Handler'
import type { DIDCommV2Message } from '../../../agent/didcomm'
import type { ValueTransferService } from '../services'
Expand All @@ -7,18 +6,15 @@ import type { ValueTransferWitnessService } from '../services/ValueTransferWitne
import { CashRemovedMessage } from '../messages'

export class CashRemovedHandler implements Handler<typeof DIDCommV2Message> {
private agentConfig: AgentConfig
private valueTransferService: ValueTransferService
private valueTransferWitnessService: ValueTransferWitnessService

public readonly supportedMessages = [CashRemovedMessage]

public constructor(
agentConfig: AgentConfig,
valueTransferService: ValueTransferService,
valueTransferWitnessService: ValueTransferWitnessService
) {
this.agentConfig = agentConfig
this.valueTransferService = valueTransferService
this.valueTransferWitnessService = valueTransferWitnessService
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import type { AgentConfig } from '../../../agent/AgentConfig'
import type { Handler, HandlerInboundMessage } from '../../../agent/Handler'
import type { DIDCommV2Message } from '../../../agent/didcomm'
import type { ValueTransferService } from '../services'
Expand All @@ -7,18 +6,15 @@ import type { ValueTransferWitnessService } from '../services/ValueTransferWitne
import { ProblemReportMessage, RequestAcceptedMessage } from '../messages'

export class RequestAcceptedHandler implements Handler<typeof DIDCommV2Message> {
private agentConfig: AgentConfig
private valueTransferService: ValueTransferService
private valueTransferWitnessService: ValueTransferWitnessService

public readonly supportedMessages = [RequestAcceptedMessage]

public constructor(
agentConfig: AgentConfig,
valueTransferService: ValueTransferService,
valueTransferWitnessService: ValueTransferWitnessService
) {
this.agentConfig = agentConfig
this.valueTransferService = valueTransferService
this.valueTransferWitnessService = valueTransferWitnessService
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import type { AgentConfig } from '../../../agent/AgentConfig'
import type { Handler, HandlerInboundMessage } from '../../../agent/Handler'
import type { DIDCommV2Message } from '../../../agent/didcomm'
import type { ValueTransferService } from '../services'
Expand All @@ -7,18 +6,15 @@ import type { ValueTransferGetterService } from '../services/ValueTransferGetter
import { RequestAcceptedWitnessedMessage } from '../messages'

export class RequestAcceptedWitnessedHandler implements Handler<typeof DIDCommV2Message> {
private agentConfig: AgentConfig
private valueTransferService: ValueTransferService
private valueTransferGetterService: ValueTransferGetterService

public readonly supportedMessages = [RequestAcceptedWitnessedMessage]

public constructor(
agentConfig: AgentConfig,
valueTransferService: ValueTransferService,
valueTransferGetterService: ValueTransferGetterService
) {
this.agentConfig = agentConfig
this.valueTransferService = valueTransferService
this.valueTransferGetterService = valueTransferGetterService
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import type { AgentConfig } from '../../../agent/AgentConfig'
import type { Handler, HandlerInboundMessage } from '../../../agent/Handler'
import type { DIDCommV2Message } from '../../../agent/didcomm'
import type { ValueTransferService } from '../services'
Expand All @@ -7,18 +6,15 @@ import type { ValueTransferWitnessService } from '../services/ValueTransferWitne
import { ProblemReportMessage, RequestMessage } from '../messages'

export class RequestHandler implements Handler<typeof DIDCommV2Message> {
private agentConfig: AgentConfig
private valueTransferService: ValueTransferService
private valueTransferWitnessService: ValueTransferWitnessService

public readonly supportedMessages = [RequestMessage]

public constructor(
agentConfig: AgentConfig,
valueTransferService: ValueTransferService,
valueTransferWitnessService: ValueTransferWitnessService
) {
this.agentConfig = agentConfig
this.valueTransferService = valueTransferService
this.valueTransferWitnessService = valueTransferWitnessService
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import type { AgentConfig } from '../../../agent/AgentConfig'
import type { Handler, HandlerInboundMessage } from '../../../agent/Handler'
import type { DIDCommV2Message } from '../../../agent/didcomm'
import type { ValueTransferResponseCoordinator } from '../ValueTransferResponseCoordinator'
Expand All @@ -9,20 +8,17 @@ import { ProblemReportMessage } from '../../problem-reports'
import { RequestWitnessedMessage } from '../messages/RequestWitnessedMessage'

export class RequestWitnessedHandler implements Handler<typeof DIDCommV2Message> {
private agentConfig: AgentConfig
private valueTransferService: ValueTransferService
private valueTransferGiverService: ValueTransferGiverService
private valueTransferResponseCoordinator: ValueTransferResponseCoordinator

public readonly supportedMessages = [RequestWitnessedMessage]

public constructor(
agentConfig: AgentConfig,
valueTransferService: ValueTransferService,
valueTransferGiverService: ValueTransferGiverService,
valueTransferResponseCoordinator: ValueTransferResponseCoordinator
) {
this.agentConfig = agentConfig
this.valueTransferService = valueTransferService
this.valueTransferGiverService = valueTransferGiverService
this.valueTransferResponseCoordinator = valueTransferResponseCoordinator
Expand Down
Original file line number Diff line number Diff line change
@@ -1,40 +1,25 @@
import type { RecordTags, TagsBase } from '../../../storage/BaseRecord'

import { Wallet } from '@sicpa-dlab/value-transfer-protocol-ts'
import { PartyState } from '@sicpa-dlab/value-transfer-protocol-ts'
import { Type } from 'class-transformer'
import { IsInstance, ValidateNested } from 'class-validator'

import type { RecordTags, TagsBase } from '../../../storage/BaseRecord'
import { BaseRecord } from '../../../storage/BaseRecord'
import { uuid } from '../../../utils/uuid'

export type CustomValueTransferStateTags = TagsBase
export type DefaultValueTransferStateTags = TagsBase

export type ValueTransferStateTags = RecordTags<ValueTransferStateRecord>

export interface ValueTransferStateProps {
id?: string
publicDid?: string
previousHash: string
wallet: Wallet
proposedNextWallet?: Wallet
partyState: PartyState
}

export class ValueTransferStateRecord extends BaseRecord<DefaultValueTransferStateTags, CustomValueTransferStateTags> {
public previousHash!: string

@Type(() => Wallet)
@ValidateNested()
@IsInstance(Wallet)
public wallet!: Wallet

@Type(() => Wallet)
@ValidateNested()
@IsInstance(Wallet)
public proposedNextWallet?: Wallet

public publicDid?: string

@Type(() => PartyState)
public partyState!: PartyState

public static readonly type = 'ValueTransferState'
public readonly type = ValueTransferStateRecord.type

Expand All @@ -44,9 +29,7 @@ export class ValueTransferStateRecord extends BaseRecord<DefaultValueTransferSta
if (props) {
this.id = props.id ?? uuid()
this.publicDid = props.publicDid
this.previousHash = props.previousHash
this.wallet = props.wallet
this.proposedNextWallet = props.proposedNextWallet
this.partyState = props.partyState
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,24 @@
import { WitnessState } from '@sicpa-dlab/value-transfer-protocol-ts'
import { Type } from 'class-transformer'
import type { RecordTags, TagsBase } from '../../../storage/BaseRecord'

import { BaseRecord } from '../../../storage/BaseRecord'
import { uuid } from '../../../utils/uuid'

export type CustomWitnessStateTags = TagsBase
export type DefaultWitnessStateTags = TagsBase

export type WitnessStateTags = RecordTags<WitnessStateRecord>

export interface WitnessStateProps {
id?: string
publicDid: string
stateAccumulator: string
witnessState: WitnessState
}

export class WitnessStateRecord extends BaseRecord<DefaultWitnessStateTags, CustomWitnessStateTags> {
public publicDid!: string
public stateAccumulator!: string

@Type(() => WitnessState)
public witnessState!: WitnessState

public static readonly type = 'WitnessState'
public readonly type = WitnessStateRecord.type
Expand All @@ -27,7 +29,7 @@ export class WitnessStateRecord extends BaseRecord<DefaultWitnessStateTags, Cust
if (props) {
this.id = props.id ?? uuid()
this.publicDid = props.publicDid
this.stateAccumulator = props.stateAccumulator
this.witnessState = props.witnessState
}
}

Expand Down
Loading

0 comments on commit 6cef16a

Please sign in to comment.