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
5 changes: 4 additions & 1 deletion demo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,11 @@
},
"devDependencies": {
"@aries-framework/core": "file:../packages/core",
"@aries-framework/gossip": "file:../packages/gossip",
"@aries-framework/node": "file:../packages/node",
"@sicpa-dlab/value-transfer-protocol-ts": "0.4.1",
"@aries-framework/value-transfer": "file:../packages/value-transfer",
"@aries-framework/value-transfer-events": "file:../packages/value-transfer-events",
"@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
37 changes: 19 additions & 18 deletions demo/src/Anna.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,21 @@
/*eslint import/no-cycle: [2, { maxDepth: 1 }]*/
import type { ValueTransferRecord } from '@aries-framework/core'
import type { ValueTransferModule, ValueTransferRecord } from '@aries-framework/value-transfer'

import { AutoAcceptValueTransfer, DidMarker, Transports } from '@aries-framework/core'
import { DidMarker, Transports } from '@aries-framework/core'
import { AutoAcceptValueTransfer, initValueTransfer } from '@aries-framework/value-transfer'
import { TransactionState } from '@sicpa-dlab/value-transfer-protocol-ts'

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

export class Anna extends BaseAgent {
public valueTransfer!: ValueTransferModule
public valueTransferRecordId?: string
public static valueTransferConfig = {
autoAcceptOfferedPaymentRequest: AutoAcceptValueTransfer.Always,
witnessDid:
'did:peer:2.Ez6LSfsT5gHMCVEya8VDwW9QbAdVUhJCKbVscrrb82SwCPKKT.Vz6MkgNdE8ad1k8cPCHnXZ6vSxrTuFauRKDzzUHLPvdsLycz5.SeyJzIjoiaHR0cDovL2xvY2FsaG9zdDozMDAwL2FwaS92MSIsInQiOiJkbSIsInIiOlsiZGlkOnBlZXI6Mi5FejZMU25IUzlmM2hyTXVMck45ejZaaG83VGNCUnZTeUs3SFBqUXR3S211M29zV3dGLlZ6Nk1rcmFoQW9WTFFTOVM1R0Y1c1VLdHVkWE1lZFVTWmRkZUpoakh0QUZhVjRob1YuU1czc2ljeUk2SW1oMGRIQTZMeTlzYjJOaGJHaHZjM1E2TXpBd01DOWhjR2t2ZGpFaUxDSjBJam9pWkcwaUxDSnlJanBiWFN3aVlTSTZXeUprYVdSamIyMXRMM1l5SWwxOUxIc2ljeUk2SW5kek9pOHZiRzlqWVd4b2IzTjBPak13TURBdllYQnBMM1l4SWl3aWRDSTZJbVJ0SWl3aWNpSTZXMTBzSW1FaU9sc2laR2xrWTI5dGJTOTJNaUpkZlYwIl0sImEiOlsiZGlkY29tbS92MiJdfQ',
}

public constructor(name: string, port?: number) {
super({
Expand All @@ -23,26 +30,20 @@ export class Anna extends BaseAgent {
transports: [Transports.Nearby, Transports.NFC, Transports.HTTP],
},
],
valueTransferConfig: {
party: {
autoAcceptOfferedPaymentRequest: AutoAcceptValueTransfer.Always,
witnessDid:
'did:peer:2.Ez6LSfsT5gHMCVEya8VDwW9QbAdVUhJCKbVscrrb82SwCPKKT.Vz6MkgNdE8ad1k8cPCHnXZ6vSxrTuFauRKDzzUHLPvdsLycz5.SeyJzIjoiaHR0cDovL2xvY2FsaG9zdDozMDAwL2FwaS92MSIsInQiOiJkbSIsInIiOlsiZGlkOnBlZXI6Mi5FejZMU25IUzlmM2hyTXVMck45ejZaaG83VGNCUnZTeUs3SFBqUXR3S211M29zV3dGLlZ6Nk1rcmFoQW9WTFFTOVM1R0Y1c1VLdHVkWE1lZFVTWmRkZUpoakh0QUZhVjRob1YuU1czc2ljeUk2SW1oMGRIQTZMeTlzYjJOaGJHaHZjM1E2TXpBd01DOWhjR2t2ZGpFaUxDSjBJam9pWkcwaUxDSnlJanBiWFN3aVlTSTZXeUprYVdSamIyMXRMM1l5SWwxOUxIc2ljeUk2SW5kek9pOHZiRzlqWVd4b2IzTjBPak13TURBdllYQnBMM1l4SWl3aWRDSTZJbVJ0SWl3aWNpSTZXMTBzSW1FaU9sc2laR2xrWTI5dGJTOTJNaUpkZlYwIl0sImEiOlsiZGlkY29tbS92MiJdfQ',
},
},
})
}

public static async build(): Promise<Anna> {
const giver = new Anna('anna', undefined)
await giver.initializeAgent()
giver.valueTransfer = await initValueTransfer(giver.agent, this.valueTransferConfig)

const publicDid = await giver.agent.getStaticDid(DidMarker.Public)
console.log(`Anna Public DID: ${publicDid?.did}`)

const active = await giver.agent.valueTransfer.getActiveTransaction()
const active = await giver.valueTransfer.getActiveTransaction()
if (active.record?.id) {
await giver.agent.valueTransfer.abortTransaction(active.record?.id)
await giver.valueTransfer.abortTransaction(active.record?.id)
}

return giver
Expand All @@ -52,20 +53,20 @@ export class Anna extends BaseAgent {
if (!this.valueTransferRecordId) {
throw Error(redText(Output.MissingValueTransferRecord))
}
return await this.agent.valueTransfer.getById(this.valueTransferRecordId)
return await this.valueTransfer.getById(this.valueTransferRecordId)
}

private async waitForPayment() {
const valueTransferRecord = await this.getValueTransferRecord()

console.log('Waiting for finishing payment...')
try {
const record = await this.agent.valueTransfer.returnWhenIsCompleted(valueTransferRecord.id)
const record = await this.valueTransfer.returnWhenIsCompleted(valueTransferRecord.id)
if (record.state === TransactionState.Completed) {
console.log(greenText(Output.PaymentDone))
console.log(greenText('Receipt:'))
console.log(record.receipt)
const balance = await this.agent.valueTransfer.getBalance()
const balance = await this.valueTransfer.getBalance()
console.log(greenText('Balance: ' + balance))
}
if (record.state === TransactionState.Failed) {
Expand All @@ -79,21 +80,21 @@ export class Anna extends BaseAgent {
}

public async acceptPaymentRequest(valueTransferRecord: ValueTransferRecord) {
const { record } = await this.agent.valueTransfer.acceptPaymentRequest({ recordId: valueTransferRecord.id })
const { record } = await this.valueTransfer.acceptPaymentRequest({ recordId: valueTransferRecord.id })
this.valueTransferRecordId = record?.id
console.log(greenText('\nPayment request accepted!\n'))
await this.waitForPayment()
}

public async abortPaymentRequest(valueTransferRecord: ValueTransferRecord) {
const { record } = await this.agent.valueTransfer.abortTransaction(valueTransferRecord.id)
const { record } = await this.valueTransfer.abortTransaction(valueTransferRecord.id)
this.valueTransferRecordId = record?.id
console.log(redText('\nPayment request rejected!\n'))
console.log(record?.error)
}

public async offerPayment(getter: string) {
const { record } = await this.agent.valueTransfer.offerPayment({
const { record } = await this.valueTransfer.offerPayment({
amount: 1,
getter,
transport: Transports.NFC,
Expand All @@ -104,7 +105,7 @@ export class Anna extends BaseAgent {
}

public async requestPayment(witness: string, giver: string) {
const { record } = await this.agent.valueTransfer.requestPayment({
const { record } = await this.valueTransfer.requestPayment({
amount: 1,
giver,
witness,
Expand Down
6 changes: 3 additions & 3 deletions demo/src/AnnaInquirer.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { ValueTransferRecord } from '@aries-framework/core'
import type { ValueTransferRecord } from '@aries-framework/value-transfer'

import { clear } from 'console'
import { textSync } from 'figlet'
Expand Down Expand Up @@ -44,7 +44,7 @@ export class AnnaInquirer extends BaseInquirer {
}

private async getPromptChoice() {
const balance = await this.giver.agent.valueTransfer.getBalance()
const balance = await this.giver.valueTransfer.getBalance()
console.log(greenText('Balance: ' + balance))
return prompt([this.inquireOptions(this.promptOptionsString)])
}
Expand Down Expand Up @@ -82,7 +82,7 @@ export class AnnaInquirer extends BaseInquirer {
}

public async acceptPaymentRequest(valueTransferRecord: ValueTransferRecord) {
const balance = await this.giver.agent.valueTransfer.getBalance()
const balance = await this.giver.valueTransfer.getBalance()
console.log(greenText(`\nCurrent balance: ${balance}`))
const confirm = await prompt([this.inquireConfirmation(Title.PaymentRequestTitle)])
if (confirm.options === ConfirmOptions.No) {
Expand Down
3 changes: 0 additions & 3 deletions demo/src/BaseAgent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import type {
InternetChecker,
Logger,
OutboundTransport,
ValueTransferConfig,
} from '@aries-framework/core'

import {
Expand Down Expand Up @@ -106,7 +105,6 @@ export class BaseAgent {
staticDids?: DidProps[]
port?: number
transports?: Transports[]
valueTransferConfig?: ValueTransferConfig
mediatorConnectionsInvite?: string
endpoints?: string[]
emulateOfflineCase?: boolean
Expand Down Expand Up @@ -137,7 +135,6 @@ export class BaseAgent {
autoAcceptProofs: AutoAcceptProof.ContentApproved,
mediatorPickupStrategy: MediatorPickupStrategy.Explicit,
mediatorPollingInterval: 5000,
valueTransferConfig: props.valueTransferConfig,
transports: props.transports,
mediatorConnectionsInvite: props.mediatorConnectionsInvite,
mediatorDeliveryStrategy: MediatorDeliveryStrategy.WebSocket,
Expand Down
26 changes: 14 additions & 12 deletions demo/src/Bob.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
/*eslint import/no-cycle: [2, { maxDepth: 1 }]*/
import type { ValueTransferRecord } from '@aries-framework/core'
import type { ValueTransferModule, ValueTransferRecord } from '@aries-framework/value-transfer'

import { DidMarker, Transports } from '@aries-framework/core'
import { initValueTransfer } from '@aries-framework/value-transfer'
import { TransactionState } from '@sicpa-dlab/value-transfer-protocol-ts'

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

export class Bob extends BaseAgent {
public valueTransfer!: ValueTransferModule
public valueTransferRecordId?: string
public static valueTransferConfig = {}

public constructor(name: string, port?: number) {
super({
Expand All @@ -23,16 +26,15 @@ export class Bob extends BaseAgent {
marker: DidMarker.Public,
},
],
valueTransferConfig: {
party: {},
},
internetChecker: doesNotHasInternetChecker,
})
}

public static async build(): Promise<Bob> {
const getter = new Bob('bob', undefined)
await getter.initializeAgent()
getter.valueTransfer = await initValueTransfer(getter.agent, this.valueTransferConfig)

const publicDid = await getter.agent.getStaticDid(DidMarker.Public)
console.log(`Bob Public DID: ${publicDid?.did}`)
return getter
Expand All @@ -42,11 +44,11 @@ export class Bob extends BaseAgent {
if (!this.valueTransferRecordId) {
throw Error(redText(Output.MissingValueTransferRecord))
}
return await this.agent.valueTransfer.getById(this.valueTransferRecordId)
return await this.valueTransfer.getById(this.valueTransferRecordId)
}

public async requestPayment(witness: string, giver: string) {
const { record } = await this.agent.valueTransfer.requestPayment({
const { record } = await this.valueTransfer.requestPayment({
amount: 1,
giver,
witness,
Expand All @@ -58,21 +60,21 @@ export class Bob extends BaseAgent {
}

public async acceptPaymentRequest(valueTransferRecord: ValueTransferRecord) {
const { record } = await this.agent.valueTransfer.acceptPaymentRequest({ recordId: valueTransferRecord.id })
const { record } = await this.valueTransfer.acceptPaymentRequest({ recordId: valueTransferRecord.id })
this.valueTransferRecordId = record?.id
console.log(greenText('\nPayment request accepted!\n'))
await this.waitForPayment()
}

public async abortPaymentRequest(valueTransferRecord: ValueTransferRecord) {
const { record } = await this.agent.valueTransfer.abortTransaction(valueTransferRecord.id)
const { record } = await this.valueTransfer.abortTransaction(valueTransferRecord.id)
this.valueTransferRecordId = record?.id
console.log(redText('\nPayment request rejected!\n'))
console.log(record?.error)
}

public async acceptPaymentOffer(valueTransferRecord: ValueTransferRecord, witness: string) {
const { record } = await this.agent.valueTransfer.acceptPaymentOffer({
const { record } = await this.valueTransfer.acceptPaymentOffer({
recordId: valueTransferRecord.id,
witness,
})
Expand All @@ -82,7 +84,7 @@ export class Bob extends BaseAgent {
}

public async abortPaymentOffer(valueTransferRecord: ValueTransferRecord) {
const { record } = await this.agent.valueTransfer.abortTransaction(valueTransferRecord.id)
const { record } = await this.valueTransfer.abortTransaction(valueTransferRecord.id)
this.valueTransferRecordId = record?.id
console.log(redText('\nPayment request rejected!\n'))
console.log(record?.error)
Expand All @@ -93,12 +95,12 @@ export class Bob extends BaseAgent {

console.log('Waiting for Giver to pay...')
try {
const record = await this.agent.valueTransfer.returnWhenIsCompleted(valueTransferRecord.id)
const record = await this.valueTransfer.returnWhenIsCompleted(valueTransferRecord.id)
if (record.state === TransactionState.Completed) {
console.log(greenText(Output.PaymentDone))
console.log(greenText('Receipt:'))
console.log(record.receipt)
const balance = await this.agent.valueTransfer.getBalance()
const balance = await this.valueTransfer.getBalance()
console.log(greenText('Balance: ' + balance))
}
if (record.state === TransactionState.Failed) {
Expand Down
6 changes: 3 additions & 3 deletions demo/src/BobInquirer.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { ValueTransferRecord } from '@aries-framework/core'
import type { ValueTransferRecord } from '@aries-framework/value-transfer'

import { clear } from 'console'
import { textSync } from 'figlet'
Expand Down Expand Up @@ -71,7 +71,7 @@ export class BobInquirer extends BaseInquirer {
}

public async acceptPaymentRequest(valueTransferRecord: ValueTransferRecord) {
const balance = await this.getter.agent.valueTransfer.getBalance()
const balance = await this.getter.valueTransfer.getBalance()
console.log(greenText(`\nCurrent balance: ${balance}`))
const confirm = await prompt([this.inquireConfirmation(Title.PaymentRequestTitle)])
if (confirm.options === ConfirmOptions.No) {
Expand All @@ -82,7 +82,7 @@ export class BobInquirer extends BaseInquirer {
}

public async acceptPaymentOffer(valueTransferRecord: ValueTransferRecord) {
const balance = await this.getter.agent.valueTransfer.getBalance()
const balance = await this.getter.valueTransfer.getBalance()
console.log(greenText(`\nCurrent balance: ${balance}`))
const confirm = await prompt([this.inquireConfirmation(Title.PaymentOfferTitle)])
if (confirm.options === ConfirmOptions.No) {
Expand Down
26 changes: 14 additions & 12 deletions demo/src/Carol.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
/*eslint import/no-cycle: [2, { maxDepth: 1 }]*/
import type { ValueTransferRecord } from '@aries-framework/core'
import type { ValueTransferModule, ValueTransferRecord } from '@aries-framework/value-transfer'

import { DidMarker, Transports } from '@aries-framework/core'
import { initValueTransfer } from '@aries-framework/value-transfer'
import { TransactionState } from '@sicpa-dlab/value-transfer-protocol-ts'

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

export class Carol extends BaseAgent {
public valueTransfer!: ValueTransferModule
public valueTransferRecordId?: string
public static valueTransferConfig = {}

public constructor(name: string, port?: number) {
super({
Expand All @@ -23,21 +26,20 @@ export class Carol extends BaseAgent {
marker: DidMarker.Public,
},
],
valueTransferConfig: {
party: {},
},
})
}

public static async build(): Promise<Carol> {
const getter = new Carol('carol', undefined)
await getter.initializeAgent()
getter.valueTransfer = await initValueTransfer(getter.agent, this.valueTransferConfig)

const publicDid = await getter.agent.getStaticDid(DidMarker.Public)
console.log(`Carol Public DID: ${publicDid?.did}`)

const active = await getter.agent.valueTransfer.getActiveTransaction()
const active = await getter.valueTransfer.getActiveTransaction()
if (active.record?.id) {
await getter.agent.valueTransfer.abortTransaction(active.record?.id)
await getter.valueTransfer.abortTransaction(active.record?.id)
}

return getter
Expand All @@ -47,11 +49,11 @@ export class Carol extends BaseAgent {
if (!this.valueTransferRecordId) {
throw Error(redText(Output.MissingValueTransferRecord))
}
return await this.agent.valueTransfer.getById(this.valueTransferRecordId)
return await this.valueTransfer.getById(this.valueTransferRecordId)
}

public async requestPayment(witness: string) {
const { record } = await this.agent.valueTransfer.requestPayment({
const { record } = await this.valueTransfer.requestPayment({
amount: 1,
witness,
transport: Transports.Nearby,
Expand All @@ -62,7 +64,7 @@ export class Carol extends BaseAgent {
}

public async acceptPaymentOffer(valueTransferRecord: ValueTransferRecord, witness: string) {
const { record } = await this.agent.valueTransfer.acceptPaymentOffer({
const { record } = await this.valueTransfer.acceptPaymentOffer({
recordId: valueTransferRecord.id,
witness,
})
Expand All @@ -72,7 +74,7 @@ export class Carol extends BaseAgent {
}

public async abortPaymentOffer(valueTransferRecord: ValueTransferRecord) {
const { record } = await this.agent.valueTransfer.abortTransaction(valueTransferRecord.id)
const { record } = await this.valueTransfer.abortTransaction(valueTransferRecord.id)
this.valueTransferRecordId = record?.id
console.log(redText('\nPayment request rejected!\n'))
console.log(record?.error)
Expand All @@ -83,12 +85,12 @@ export class Carol extends BaseAgent {

console.log('Waiting for Giver to pay...')
try {
const record = await this.agent.valueTransfer.returnWhenIsCompleted(valueTransferRecord.id)
const record = await this.valueTransfer.returnWhenIsCompleted(valueTransferRecord.id)
if (record.state === TransactionState.Completed) {
console.log(greenText(Output.PaymentDone))
console.log(greenText('Receipt:'))
console.log(record.receipt)
const balance = await this.agent.valueTransfer.getBalance()
const balance = await this.valueTransfer.getBalance()
console.log(greenText('Balance: ' + balance))
}
if (record.state === TransactionState.Failed) {
Expand Down
Loading