Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ Some features are not yet supported, but are on our roadmap. Check [the roadmap]
Documentation on how to get started with Aries Framework JavaScript can be found at https://aries.js.org

## Publish new packages (SICPA's fork)

See docs [here](sicpa-docs/PUBLISH.md)

### Demo
Expand Down
2 changes: 1 addition & 1 deletion demo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"devDependencies": {
"@aries-framework/core": "file:../packages/core",
"@aries-framework/node": "file:../packages/node",
"@sicpa-dlab/value-transfer-protocol-ts": "0.4.1",
"@sicpa-dlab/value-transfer-protocol-ts": "0.4.5",
"@types/figlet": "^1.5.4",
"@types/inquirer": "^8.1.3",
"clear": "^0.1.0",
Expand Down
8 changes: 4 additions & 4 deletions packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "@sicpa-dlab/aries-framework-core",
"main": "build/index",
"types": "build/index",
"version": "0.4.1",
"version": "0.4.13-beta2",
"files": [
"build"
],
Expand All @@ -24,9 +24,9 @@
},
"dependencies": {
"@multiformats/base-x": "^4.0.1",
"@sicpa-dlab/value-transfer-common-ts": "0.3.5",
"@sicpa-dlab/value-transfer-protocol-ts": "0.4.1",
"@sicpa-dlab/witness-gossip-types-ts": "0.3.5",
"@sicpa-dlab/value-transfer-common-ts": "0.3.7",
"@sicpa-dlab/value-transfer-protocol-ts": "0.4.9",
"@sicpa-dlab/witness-gossip-types-ts": "0.3.9",
"@stablelib/ed25519": "^1.0.2",
"@stablelib/sha256": "^1.0.1",
"@stablelib/uuid": "^1.0.1",
Expand Down
7 changes: 1 addition & 6 deletions packages/core/src/agent/MessageSender.ts
Original file line number Diff line number Diff line change
Expand Up @@ -316,19 +316,14 @@ export class MessageSender {
): Promise<DidCommV2Service[] | undefined> {
if (!recipient) return undefined

const { didDocument: senderDidDocument } = await this.didResolverService.resolve(sender)

const { didDocument: recipientDidDocument } = await this.didResolverService.resolve(recipient)
if (!recipientDidDocument) {
throw new AriesFrameworkError(`Unable to resolve did document for did '${recipient}'`)
}

const senderServices = senderDidDocument?.service || []
const recipientServices = recipientDidDocument?.service || []

const senderTransports = senderServices.length
? senderServices.map((service) => service.protocolScheme)
: this.agentConfig.transports // FIXME: use outbound transports
const senderTransports = this.outboundTransports.flatMap((transport) => transport.supportedSchemes)

const supportedTransports = priorityTransports?.length
? [...priorityTransports, ...senderTransports]
Expand Down
21 changes: 13 additions & 8 deletions packages/core/src/agent/didcomm/v2/DIDCommV2BaseMessage.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import type { ParsedMessageType } from '../../../utils/messageType'
import type { Attachment } from 'didcomm'

import { Expose } from 'class-transformer'
import { IsArray, IsNumber, IsOptional, IsString, Matches } from 'class-validator'
import { Expose, Type } from 'class-transformer'
import { IsArray, IsNumber, IsOptional, IsString, Matches, ValidateNested } from 'class-validator'

import { V2Attachment } from '../../../decorators/attachment/V2Attachment'
import { JsonEncoder } from '../../../utils'
import { uuid } from '../../../utils/uuid'
import { MessageIdRegExp, MessageTypeRegExp } from '../validation'
Expand All @@ -20,7 +20,7 @@ export type DIDCommV2MessageParams = {
created_time?: number
expires_time?: number
from_prior?: string
attachments?: Array<Attachment>
attachments?: Array<V2Attachment>
body?: unknown
}

Expand Down Expand Up @@ -71,7 +71,12 @@ export class DIDCommV2BaseMessage {
public body!: unknown

@IsOptional()
public attachments?: Array<Attachment>
@Type(() => V2Attachment)
@IsArray()
@ValidateNested({
each: true,
})
public attachments?: Array<V2Attachment>

public constructor(options?: DIDCommV2MessageParams) {
if (options) {
Expand All @@ -93,7 +98,7 @@ export class DIDCommV2BaseMessage {
return uuid()
}

public static createJSONAttachment<T>(id: string, message: T): Attachment {
public static createJSONAttachment<T>(id: string, message: T): V2Attachment {
return {
id: id,
// media_type: ATTACHMENT_MEDIA_TYPE,
Expand All @@ -104,7 +109,7 @@ export class DIDCommV2BaseMessage {
}

// eslint-disable-next-line @typescript-eslint/no-explicit-any
public static createBase64Attachment<T>(id: string, message: T): Attachment {
public static createBase64Attachment<T>(id: string, message: T): V2Attachment {
return {
id: id,
// media_type: ATTACHMENT_MEDIA_TYPE,
Expand All @@ -114,7 +119,7 @@ export class DIDCommV2BaseMessage {
}
}

public static unpackAttachmentAsJson(attachment: Attachment) {
public static unpackAttachmentAsJson(attachment: V2Attachment) {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const data = attachment.data as any //FIXME: didcomm package doesn't provide convenient way to process attachment
if (typeof data.base64 === 'string') {
Expand Down
115 changes: 115 additions & 0 deletions packages/core/src/decorators/attachment/V2Attachment.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
import { Expose, Type } from 'class-transformer'
import { IsBase64, IsInstance, IsMimeType, IsOptional, IsString, ValidateNested } from 'class-validator'

import { Jws } from '../../crypto/JwsTypes'
import { uuid } from '../../utils/uuid'

export interface V2AttachmentOptions {
id?: string
description?: string
filename?: string
mediaType?: string
byteCount?: number
data: AttachmentData
}

export interface AttachmentDataOptions {
base64?: string
json?: Record<string, unknown>
links?: string[]
jws?: Jws
}

/**
* A JSON object that gives access to the actual content of the attachment
*/
export class AttachmentData {
/**
* Base64-encoded data, when representing arbitrary content inline instead of via links. Optional.
*/
@IsOptional()
@IsBase64()
public base64?: string

/**
* Directly embedded JSON data, when representing content inline instead of via links, and when the content is natively conveyable as JSON. Optional.
*/
@IsOptional()
public json?: unknown

/**
* A list of zero or more locations at which the content may be fetched. Optional.
*/
@IsOptional()
@IsString({ each: true })
public links?: string[]

/**
* A JSON Web Signature over the content of the attachment. Optional.
*/
@IsOptional()
public jws?: Jws

public constructor(options: AttachmentDataOptions) {
if (options) {
this.base64 = options.base64
this.json = options.json
this.links = options.links
this.jws = options.jws
}
}
}

/**
* Represents DIDComm attachment
* https://github.com/hyperledger/aries-rfcs/blob/master/concepts/0017-attachments/README.md
*/
export class V2Attachment {
public constructor(options: V2AttachmentOptions) {
if (options) {
this.id = options.id ?? uuid()
this.description = options.description
this.filename = options.filename
this.mediaType = options.mediaType
this.data = options.data
}
}

@IsOptional()
@IsString()
public id?: string

/**
* An optional human-readable description of the content.
*/
@IsOptional()
@IsString()
public description?: string

/**
* A hint about the name that might be used if this attachment is persisted as a file. It is not required, and need not be unique. If this field is present and mime-type is not, the extension on the filename may be used to infer a MIME type.
*/
@IsOptional()
@IsString()
public filename?: string

/**
* A hint about the attachment format
*/
@IsOptional()
@IsString()
public format?: string

/**
* Describes the MIME type of the attached content. Optional but recommended.
*/
@Expose({ name: 'media_type' })
@IsOptional()
@IsMimeType()
public mediaType?: string

@Type(() => AttachmentData)
@ValidateNested()
@IsInstance(AttachmentData)
public data!: AttachmentData
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { DIDCommV2MessageParams } from '../../../agent/didcomm'
import type { Attachment } from 'didcomm'
import type { V2Attachment } from '../../../decorators/attachment/V2Attachment'

import { Expose, Type } from 'class-transformer'
import { IsInstance, IsOptional, IsString, ValidateNested } from 'class-validator'
Expand Down Expand Up @@ -67,11 +67,11 @@ export class OutOfBandInvitationMessage extends DIDCommV2Message {
return JsonTransformer.fromJSON(json, OutOfBandInvitationMessage)
}

public static createAndroidNearbyHandshakeJSONAttachment(attachment: AndroidNearbyHandshakeAttachment): Attachment {
public static createAndroidNearbyHandshakeJSONAttachment(attachment: AndroidNearbyHandshakeAttachment): V2Attachment {
return this.createJSONAttachment(ANDROID_NEARBY_HANDSHAKE_ATTACHMENT_ID, JsonTransformer.toJSON(attachment))
}

public static createOutOfBandJSONAttachment(attachment: Record<string, unknown>): Attachment {
public static createOutOfBandJSONAttachment(attachment: Record<string, unknown>): V2Attachment {
return this.createJSONAttachment(ATTACHMENT_ID, JsonTransformer.toJSON(attachment))
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import type { DIDCommV2MessageParams } from '../../../../../../agent/didcomm'
import type { Attachment } from 'didcomm'

import { Type, Expose } from 'class-transformer'
import { ValidateNested, IsObject, IsOptional, IsString } from 'class-validator'
import { ValidateNested, IsObject, IsOptional, IsString, IsArray } from 'class-validator'

import { DIDCommV2Message } from '../../../../../../agent/didcomm'
import { V2Attachment } from '../../../../../../decorators/attachment/V2Attachment'
import { IsValidMessageType, parseMessageType } from '../../../../../../utils/messageType'

export type DeliveryMessageParams = {
body: DeliveryBody
attachments: Attachment[]
attachments: V2Attachment[]
} & DIDCommV2MessageParams

class DeliveryBody {
Expand All @@ -29,7 +29,12 @@ export class DeliveryMessage extends DIDCommV2Message {
public readonly type = DeliveryMessage.type.messageTypeUri
public static readonly type = parseMessageType('https://didcomm.org/messagepickup/3.0/delivery')

public attachments!: Array<Attachment>
@Type(() => V2Attachment)
@IsArray()
@ValidateNested({
each: true,
})
public attachments!: Array<V2Attachment>

public constructor(params?: DeliveryMessageParams) {
super(params)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export interface ValueTransferStateChangedEvent extends BaseEvent {
payload: {
record: ValueTransferRecord
previousState?: TransactionState | null
currentState: TransactionState
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ export class ValueTransferGetterService {
await this.valueTransferRepository.update(record)

// Raise event
await this.valueTransferService.emitStateChangedEvent(record.id)
await this.valueTransferService.emitStateChangedEvent(record.id, record.state)

this.logger.info(`< Getter: request payment VTP transaction completed`)

Expand Down Expand Up @@ -165,7 +165,7 @@ export class ValueTransferGetterService {
record.transaction = transaction
await this.valueTransferRepository.update(record)

const updatedRecord = await this.valueTransferService.emitStateChangedEvent(transaction.id)
const updatedRecord = await this.valueTransferService.emitStateChangedEvent(transaction.id, record.state)
this.logger.info(`< Getter: verify offer message for VTP transaction ${record.transaction.id} failed!`)
return { record: updatedRecord }
}
Expand Down Expand Up @@ -210,7 +210,7 @@ export class ValueTransferGetterService {
await this.valueTransferRepository.update(record)

// Raise event
await this.valueTransferService.emitStateChangedEvent(record.id)
await this.valueTransferService.emitStateChangedEvent(record.id, record.state)

this.logger.info(`< Getter: process offer message for VTP transaction ${offerMessage.thid} completed!`)
return { record }
Expand Down Expand Up @@ -258,7 +258,7 @@ export class ValueTransferGetterService {
}

// Raise event
const updatedRecord = await this.valueTransferService.emitStateChangedEvent(transaction.id)
const updatedRecord = await this.valueTransferService.emitStateChangedEvent(transaction.id, record.state)

this.logger.info(`> Getter: accept offer message for VTP transaction ${record.transaction.id} completed!`)
return { record: updatedRecord }
Expand Down Expand Up @@ -295,7 +295,7 @@ export class ValueTransferGetterService {
}

// Raise event
const updatedRecord = await this.valueTransferService.emitStateChangedEvent(transaction.id)
const updatedRecord = await this.valueTransferService.emitStateChangedEvent(transaction.id, transaction.state)

this.logger.info(
`< Getter: process request acceptance message for VTP transaction ${requestAcceptedWitnessedMessage.id}`
Expand Down Expand Up @@ -328,7 +328,7 @@ export class ValueTransferGetterService {
}

// Raise event
const record = await this.valueTransferService.emitStateChangedEvent(receipt.thid)
const record = await this.valueTransferService.emitStateChangedEvent(receipt.thid, transaction.state)

this.logger.info(`< Getter: process receipt message for VTP transaction ${getterReceiptMessage.id} completed!`)
return { record }
Expand Down
Loading