Skip to content

Migrate Credo Backchannel to ESM and Ts.ED v7 from v6 #889

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
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
4 changes: 3 additions & 1 deletion aries-backchannels/credo-ts/ngrok-wait.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,6 @@ fi

echo "Starting Credo agent ..."

yarn ts-node src/index.ts "$@"
#yarn ts-node src/index.ts "$@"
#yarn node --loader ts-node/esm src/index.ts "$@"
yarn tsx src/index.ts "$@"
39 changes: 21 additions & 18 deletions aries-backchannels/credo-ts/server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,31 @@
"name": "credo-ts-backchannel",
"version": "1.0.0",
"license": "Apache-2.0",
"description": "Aries Agent Test Harness backchannel for Credo-ts",
"description": "OWL Agent Test Harness backchannel for Credo-ts",
"type": "module",
"scripts": {
"build": "yarn tsc",
"tsc": "tsc --project tsconfig.compile.json",
"start": "nodemon --watch \"src/**/*.ts\" --ignore \"node_modules/**/*\" --exec ts-node src/index.ts",
"start": "nodemon --watch \"src/**/*.ts\" --ignore \"node_modules/**/*\" --exec tsx src/index.ts",
"start:prod": "cross-env NODE_ENV=production node dist/index.js",
"format": "prettier --ignore-path .gitignore '**/*.+(js|json|ts|md|yml|yaml)' --write"
},
"dependencies": {
"@credo-ts/anoncreds": "^0.5.3",
"@credo-ts/askar": "^0.5.3",
"@credo-ts/core": "^0.5.3",
"@credo-ts/indy-vdr": "^0.5.3",
"@credo-ts/node": "^0.5.3",
"@hyperledger/anoncreds-nodejs": "^0.2.1",
"@hyperledger/aries-askar-nodejs": "^0.2.1",
"@hyperledger/indy-vdr-nodejs": "^0.2.0",
"@tsed/common": "^6.75.4",
"@tsed/core": "^6.75.4",
"@tsed/di": "^6.75.4",
"@tsed/exceptions": "^6.75.4",
"@tsed/platform-express": "^6.75.4",
"@tsed/swagger": "^6.88.0",
"@credo-ts/anoncreds": "^0.5.13",
"@credo-ts/askar": "^0.5.13",
"@credo-ts/core": "^0.5.13",
"@credo-ts/indy-vdr": "^0.5.13",
"@credo-ts/node": "^0.5.13",
"@hyperledger/anoncreds-nodejs": "^0.2.4",
"@hyperledger/aries-askar-nodejs": "^0.2.3",
"@hyperledger/indy-vdr-nodejs": "^0.2.2",
"@tsed/common": "^7.85.1",
"@tsed/core": "^7.85.1",
"@tsed/di": "^7.85.1",
"@tsed/exceptions": "^7.85.1",
"@tsed/platform-express": "^7.85.1",
"@tsed/swagger": "^7.85.1",
"@tsed/logger": "6",
"body-parser": "1.20.3",
"cross-env": "7.0.3",
"express": "^4.17.1",
Expand All @@ -41,8 +43,9 @@
"@types/ref-struct-di": "^1.1.12",
"nodemon": "2.0.14",
"prettier": "^2.4.1",
"ts-node": "10.3.0",
"typescript": "^5.4.5"
"ts-node": "^10.9.2",
"typescript": "^5.7.2",
"tsx": "^4.19.2"
},
"resolutions": {
"ffi-napi": "npm:@2060.io/ffi-napi",
Expand Down
10 changes: 3 additions & 7 deletions aries-backchannels/credo-ts/server/src/BaseController.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
import { Inject } from '@tsed/di'
import { TestHarnessConfig } from './TestHarnessConfig'

export abstract class BaseController {
protected testHarnessConfig: TestHarnessConfig

public constructor(testHarnessConfig: TestHarnessConfig) {
this.testHarnessConfig = testHarnessConfig

this.testHarnessConfig.addController(this)
}
@Inject()
protected testHarnessConfig!: TestHarnessConfig

protected get agent() {
return this.testHarnessConfig.agent
Expand Down
9 changes: 8 additions & 1 deletion aries-backchannels/credo-ts/server/src/Server.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
import { Configuration, Inject } from '@tsed/di'
import { Configuration, Inject, Injectable } from '@tsed/di'
import { PlatformApplication } from '@tsed/common'
import '@tsed/platform-express' // /!\ keep this import
import '@tsed/swagger' // import swagger Ts.ED module
import * as bodyParser from 'body-parser'
import { fileURLToPath } from 'url'
import { dirname } from 'path'

const __filename = fileURLToPath(import.meta.url)
const __dirname = dirname(__filename)

export const rootDir = __dirname

@Configuration({
Expand All @@ -19,6 +25,7 @@ export const rootDir = __dirname
'/': [`${rootDir}/controllers/**/*.ts`],
},
})
@Injectable()
export class Server {
@Inject()
app!: PlatformApplication
Expand Down
1 change: 0 additions & 1 deletion aries-backchannels/credo-ts/server/src/TestAgent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { AnonCredsModule, LegacyIndyCredentialFormatService, LegacyIndyProofForm
//import { AnonCredsRsModule } from '@aries-framework/anoncreds-rs'
import { IndyVdrAnonCredsRegistry, IndyVdrModule, IndyVdrSovDidResolver, IndyVdrIndyDidResolver, IndyVdrPoolConfig, IndyVdrIndyDidRegistrar } from '@credo-ts/indy-vdr'
import { TsedLogger } from './TsedLogger'
import { TransportConfig } from './TestHarnessConfig'
import { anoncreds } from '@hyperledger/anoncreds-nodejs'
import { ariesAskar } from '@hyperledger/aries-askar-nodejs'
import { indyVdr } from '@hyperledger/indy-vdr-nodejs'
Expand Down
9 changes: 5 additions & 4 deletions aries-backchannels/credo-ts/server/src/TestHarnessConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@ import {
} from '@credo-ts/core'
import { HttpInboundTransport, WsInboundTransport } from '@credo-ts/node'
import { $log } from '@tsed/common'
import { BaseController } from './BaseController'
import { createAgent, TestAgent } from './TestAgent'
import { getGenesisPath, getRandomSeed, registerPublicDid } from './utils/ledgerUtils'
import { indyDidFromPublicKeyBase58 } from '@credo-ts/core/build/utils/did'
import { Injectable } from '@tsed/di'

@Injectable()
export class TestHarnessConfig {
private _createAgentArgs?: CreateAgentArguments
private agentPorts: AgentPorts
Expand All @@ -25,7 +26,7 @@ export class TestHarnessConfig {

private _agent?: TestAgent

private _controllers: BaseController[] = []
private _controllers: (() => void)[] = []

public constructor({ backchannelPort }: { backchannelPort: number }) {
this.agentPorts = {
Expand All @@ -40,7 +41,7 @@ export class TestHarnessConfig {
this.externalHost = this.runMode === 'docker' ? this.dockerHost : 'localhost'
}

public addController(controller: BaseController): void {
public addController(controller: () => void): void {
$log.info('Register controller')
this._controllers.push(controller)
}
Expand Down Expand Up @@ -70,7 +71,7 @@ export class TestHarnessConfig {
public async agentStartup() {
// Call handlers
for (const controller of this._controllers) {
await controller.onStartup.call(controller)
await controller()
}
}

Expand Down
12 changes: 7 additions & 5 deletions aries-backchannels/credo-ts/server/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { $log, Logger, registerProvider } from '@tsed/common'
import { $log, registerProvider, InjectorService } from '@tsed/common'
import minimist from 'minimist'

import { TestHarnessConfig } from './TestHarnessConfig'
import { PlatformExpress } from '@tsed/platform-express'
import { Server } from './Server'
import { TestHarnessConfig } from './TestHarnessConfig'

async function startup() {
const cliArguments = minimist(process.argv.slice(2), {
Expand Down Expand Up @@ -33,8 +32,11 @@ async function startup() {

const platform = await PlatformExpress.bootstrap(Server, {
httpPort: testHarnessConfig.backchannelPort,
});

})

const injector = platform.injector as InjectorService
injector.addProvider(TestHarnessConfig, { useValue: testHarnessConfig })

await testHarnessConfig.agentStartup()

await platform.listen(true)
Expand Down
7 changes: 0 additions & 7 deletions aries-backchannels/credo-ts/server/tsconfig.compile.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,7 @@
"compilerOptions": {
"baseUrl": ".",
"outDir": "./dist",
"moduleResolution": "node",
"declaration": true,
"noResolve": false,
"preserveConstEnums": true,
"sourceMap": true,
"noEmit": false,
"inlineSources": true,
"skipLibCheck": true,
"strict": true
}
}
11 changes: 6 additions & 5 deletions aries-backchannels/credo-ts/server/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
{
"compilerOptions": {
"module": "commonjs",
"target": "es2016",
"module": "ESNext",
"target": "ESNext",
"sourceMap": true,
"declaration": false,
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
"moduleResolution": "node",
"moduleResolution": "Node",
"isolatedModules": false,
"suppressImplicitAnyIndexErrors": false,
"noImplicitAny": true,
"strict": true,
"strict": false,
"strictNullChecks": true,
"skipLibCheck": true,
"noUnusedLocals": false,
"noUnusedParameters": false,
"allowSyntheticDefaultImports": true,
Expand All @@ -28,4 +29,4 @@
"linterOptions": {
"exclude": []
}
}
}