Skip to content
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

refactor: require native shared components implementation #1349

Merged
Merged
Show file tree
Hide file tree
Changes from 29 commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
018d90c
feat: configure indy-vdr optional peer dependencies
Feb 27, 2023
fc8d7bf
feat(indy-vdr): add indyVdr argument to new IndyVdrModule instances
Feb 27, 2023
9394d6e
Merge branch 'main' into shared-component-module
TimoGlastra Feb 27, 2023
e717548
fix: PR review
Feb 28, 2023
ec92db2
Merge branch 'shared-component-module' of https://github.com/Vickysom…
Feb 28, 2023
e8a27da
Merge branch 'main' into shared-component-module
TimoGlastra Feb 28, 2023
198a59a
fix: resolve PR review
Feb 28, 2023
12949ba
Merge branch 'shared-component-module' of https://github.com/Vickysom…
Feb 28, 2023
7b56f68
fix: resolve PR review
Feb 28, 2023
46db7a9
fix: remove required statement from IndyVdrModule
Mar 2, 2023
7014b9b
Merge branch 'main' into shared-component-module
TimoGlastra Mar 2, 2023
c1a06be
feat: add AskerModule Config
Mar 3, 2023
c871440
feat: Anoncreds optional peer dependency setup
Mar 3, 2023
24c8848
chore: add depencies
Mar 3, 2023
5484f71
Merge branch 'shared-component-module' of https://github.com/Vickysom…
Mar 3, 2023
6159278
fix: move anoncreds dependency to anoncred-rs
Mar 7, 2023
2aa5830
feat: askar module configuration
Mar 7, 2023
04a98c3
Merge branch 'main' into shared-component-module
genaris Mar 8, 2023
be8eb1f
fix: resolve PR review
Mar 8, 2023
c85c806
Merge branch 'shared-component-module' of https://github.com/Vickysom…
Mar 8, 2023
4b5431d
fix: eslint error
Mar 8, 2023
afd5923
Merge remote-tracking branch 'upstream/main' into shared-component-mo…
genaris Mar 9, 2023
6894eb7
style: fix lint error
genaris Mar 9, 2023
2e79ea3
fix: missing indyVdr in tests
genaris Mar 9, 2023
4569bf0
Merge remote-tracking branch 'upstream/main' into shared-component-mo…
TimoGlastra Mar 11, 2023
1bc4d8c
mediation timeout
TimoGlastra Mar 11, 2023
2853c2e
style
TimoGlastra Mar 11, 2023
d42668c
pin indy-vdr to 9
TimoGlastra Mar 11, 2023
63c0519
Merge remote-tracking branch 'upstream/main' into shared-component-mo…
TimoGlastra Mar 11, 2023
ce3ce05
Merge branch 'main' into shared-component-module
genaris Mar 11, 2023
ab45a13
Merge remote-tracking branch 'upstream/main' into shared-component-mo…
TimoGlastra Mar 17, 2023
805af9a
chore: update hyperledger deps
TimoGlastra Mar 17, 2023
e4fcc3d
chore: update dependencies
TimoGlastra Mar 18, 2023
fc6c5a1
Merge remote-tracking branch 'upstream/main' into shared-component-mo…
TimoGlastra Mar 18, 2023
4143e27
Merge branch 'main' into shared-component-module
TimoGlastra Mar 18, 2023
35d5609
Merge branch 'main' into shared-component-module
TimoGlastra Mar 18, 2023
07c0430
fix: yarn.lock
TimoGlastra Mar 18, 2023
bfc8b9e
chore: same version askar
TimoGlastra Mar 18, 2023
8eec9eb
fix: askar
TimoGlastra Mar 18, 2023
dad8884
Merge remote-tracking branch 'upstream/main' into shared-component-mo…
TimoGlastra Mar 19, 2023
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
5 changes: 5 additions & 0 deletions demo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@
"faber": "ts-node src/FaberInquirer.ts",
"refresh": "rm -rf ./node_modules ./yarn.lock && yarn"
},
"dependencies": {
"@hyperledger/indy-vdr-nodejs": "0.1.0-dev.9",
"@hyperledger/anoncreds-nodejs": "^0.1.0-dev.6",
"@hyperledger/aries-askar-nodejs": "^0.1.0-dev.4"
},
"devDependencies": {
"@aries-framework/anoncreds": "*",
"@aries-framework/anoncreds-rs": "*",
Expand Down
12 changes: 10 additions & 2 deletions demo/src/BaseAgent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ import {
import { IndySdkAnonCredsRegistry, IndySdkModule, IndySdkSovDidResolver } from '@aries-framework/indy-sdk'
import { IndyVdrAnonCredsRegistry, IndyVdrModule, IndyVdrSovDidResolver } from '@aries-framework/indy-vdr'
import { agentDependencies, HttpInboundTransport } from '@aries-framework/node'
import { anoncreds } from '@hyperledger/anoncreds-nodejs'
import { ariesAskar } from '@hyperledger/aries-askar-nodejs'
import { indyVdr } from '@hyperledger/indy-vdr-nodejs'
import { randomUUID } from 'crypto'
import indySdk from 'indy-sdk'

Expand Down Expand Up @@ -125,14 +128,19 @@ function getAskarAnonCredsIndyModules() {
anoncreds: new AnonCredsModule({
registries: [new IndyVdrAnonCredsRegistry()],
}),
anoncredsRs: new AnonCredsRsModule(),
anoncredsRs: new AnonCredsRsModule({
anoncreds,
}),
indyVdr: new IndyVdrModule({
indyVdr,
networks: [indyNetworkConfig],
}),
dids: new DidsModule({
resolvers: [new IndyVdrSovDidResolver()],
}),
askar: new AskarModule(),
askar: new AskarModule({
ariesAskar,
}),
} as const
}

Expand Down
19 changes: 9 additions & 10 deletions packages/anoncreds-rs/src/AnonCredsRsModule.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type { AnonCredsRsModuleConfigOptions } from './AnonCredsRsModuleConfig'
import type { DependencyManager, Module } from '@aries-framework/core'

import {
Expand All @@ -6,20 +7,18 @@ import {
AnonCredsVerifierServiceSymbol,
} from '@aries-framework/anoncreds'

import { AnonCredsRsModuleConfig } from './AnonCredsRsModuleConfig'
import { AnonCredsRsHolderService, AnonCredsRsIssuerService, AnonCredsRsVerifierService } from './services'

export class AnonCredsRsModule implements Module {
public readonly config: AnonCredsRsModuleConfig

public constructor(config: AnonCredsRsModuleConfigOptions) {
this.config = new AnonCredsRsModuleConfig(config)
}

public register(dependencyManager: DependencyManager) {
try {
// eslint-disable-next-line import/no-extraneous-dependencies
require('@hyperledger/anoncreds-nodejs')
} catch (error) {
try {
require('@hyperledger/anoncreds-react-native')
} catch (error) {
throw new Error('Could not load anoncreds bindings')
}
}
dependencyManager.registerInstance(AnonCredsRsModuleConfig, this.config)

// Register services
dependencyManager.registerSingleton(AnonCredsHolderServiceSymbol, AnonCredsRsHolderService)
Expand Down
54 changes: 54 additions & 0 deletions packages/anoncreds-rs/src/AnonCredsRsModuleConfig.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import type { Anoncreds } from '@hyperledger/anoncreds-shared'

/**
* @public
* AnonCredsRsModuleConfigOptions defines the interface for the options of the AnonCredsRsModuleConfig class.
*/
export interface AnonCredsRsModuleConfigOptions {
/**
*
* ## Node.JS
*
* ```ts
* import { anoncreds } from '@hyperledger/anoncreds-nodejs'
*
* const agent = new Agent({
* config: {},
* dependencies: agentDependencies,
* modules: {
* anoncredsRs: new AnoncredsRsModule({
* anoncreds,
* })
* }
* })
* ```
*
* ## React Native
*
* ```ts
* import { anoncreds } from '@hyperledger/anoncreds-react-native'
*
* const agent = new Agent({
* config: {},
* dependencies: agentDependencies,
* modules: {
* anoncredsRs: new AnoncredsRsModule({
* anoncreds,
* })
* }
* })
* ```
*/
anoncreds: Anoncreds
}

/**
* @public
*/
export class AnonCredsRsModuleConfig {
private options: AnonCredsRsModuleConfigOptions

public constructor(options: AnonCredsRsModuleConfigOptions) {
this.options = options
}
}
1 change: 1 addition & 0 deletions packages/anoncreds/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
},
"devDependencies": {
"@aries-framework/node": "0.3.3",
"@hyperledger/anoncreds-nodejs": "^0.1.0-dev.6",
"indy-sdk": "^1.16.0-dev-1636",
"rimraf": "^4.0.7",
"rxjs": "^7.8.0",
Expand Down
23 changes: 7 additions & 16 deletions packages/anoncreds/tests/legacyAnonCredsSetup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,21 +27,19 @@ import {
V2ProofProtocol,
DidsModule,
} from '@aries-framework/core'
import { anoncreds } from '@hyperledger/anoncreds-nodejs'
import { randomUUID } from 'crypto'

import { AnonCredsRsModule } from '../../anoncreds-rs/src'
import { AskarModule } from '../../askar/src'
import { askarModuleConfig } from '../../askar/tests/helpers'
import { sleep } from '../../core/src/utils/sleep'
import { uuid } from '../../core/src/utils/uuid'
import { setupSubjectTransports, setupEventReplaySubjects } from '../../core/tests'
import {
getAgentOptions,
importExistingIndyDidFromPrivateKey,
makeConnection,
publicDidSeed,
genesisTransactions,
taaVersion,
taaAcceptanceMechanism,
waitForCredentialRecordSubject,
waitForProofExchangeRecordSubject,
} from '../../core/tests/helpers'
Expand All @@ -67,6 +65,7 @@ import {
IndyVdrIndyDidResolver,
IndyVdrIndyDidRegistrar,
} from '../../indy-vdr/src'
import { indyVdrModuleConfig } from '../../indy-vdr/tests/helpers'
import {
V1CredentialProtocol,
V1ProofProtocol,
Expand Down Expand Up @@ -130,14 +129,6 @@ export const getAskarAnonCredsIndyModules = ({
const legacyIndyCredentialFormatService = new LegacyIndyCredentialFormatService()
const legacyIndyProofFormatService = new LegacyIndyProofFormatService()

const indyNetworkConfig = {
id: `localhost-${uuid()}`,
isProduction: false,
genesisTransactions,
indyNamespace: 'pool:localtest',
transactionAuthorAgreement: { version: taaVersion, acceptanceMechanism: taaAcceptanceMechanism },
}

const modules = {
credentials: new CredentialsModule({
autoAcceptCredentials,
Expand All @@ -164,15 +155,15 @@ export const getAskarAnonCredsIndyModules = ({
anoncreds: new AnonCredsModule({
registries: [new IndyVdrAnonCredsRegistry()],
}),
anoncredsRs: new AnonCredsRsModule(),
indyVdr: new IndyVdrModule({
Vickysomtee marked this conversation as resolved.
Show resolved Hide resolved
networks: [indyNetworkConfig],
anoncredsRs: new AnonCredsRsModule({
anoncreds,
}),
indyVdr: new IndyVdrModule(indyVdrModuleConfig),
dids: new DidsModule({
resolvers: [new IndyVdrSovDidResolver(), new IndyVdrIndyDidResolver()],
registrars: [new IndyVdrIndyDidRegistrar()],
}),
askar: new AskarModule(),
askar: new AskarModule(askarModuleConfig),
cache: new CacheModule({
cache: new InMemoryLruCache({ limit: 100 }),
}),
Expand Down
18 changes: 8 additions & 10 deletions packages/askar/src/AskarModule.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,20 @@
import type { AskarModuleConfigOptions } from './AskarModuleConfig'
import type { DependencyManager, Module } from '@aries-framework/core'

import { AriesFrameworkError, InjectionSymbols } from '@aries-framework/core'

import { AskarModuleConfig } from './AskarModuleConfig'
import { AskarStorageService } from './storage'
import { AskarWallet } from './wallet'

export class AskarModule implements Module {
public readonly config: AskarModuleConfig

public constructor(config: AskarModuleConfigOptions) {
this.config = new AskarModuleConfig(config)
}
public register(dependencyManager: DependencyManager) {
try {
// eslint-disable-next-line import/no-extraneous-dependencies
require('@hyperledger/aries-askar-nodejs')
} catch (error) {
try {
require('@hyperledger/aries-askar-react-native')
} catch (error) {
throw new Error('Could not load aries-askar bindings')
}
}
dependencyManager.registerInstance(AskarModuleConfig, this.config)

if (dependencyManager.isRegistered(InjectionSymbols.Wallet)) {
throw new AriesFrameworkError('There is an instance of Wallet already registered')
Expand Down
54 changes: 54 additions & 0 deletions packages/askar/src/AskarModuleConfig.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import type { AriesAskar } from '@hyperledger/aries-askar-shared'

export interface AskarModuleConfigOptions {
/**
*
* ## Node.JS
*
* ```ts
* import { ariesAskar } from '@hyperledger/aries-askar-nodejs'
*
* const agent = new Agent({
* config: {},
* dependencies: agentDependencies,
* modules: {
* ariesAskar: new AskarModule({
* ariesAskar,
* })
* }
* })
* ```
*
* ## React Native
*
* ```ts
* import { ariesAskar } from '@hyperledger/aries-askar-react-native'
*
* const agent = new Agent({
* config: {},
* dependencies: agentDependencies,
* modules: {
* ariesAskar: new AskarModule({
* ariesAskar,
* })
* }
* })
* ```
*/
ariesAskar: AriesAskar
}

/**
* @public
*/
export class AskarModuleConfig {
private options: AskarModuleConfigOptions

public constructor(options: AskarModuleConfigOptions) {
this.options = options
}

public get ariesAskar() {
return this.options.ariesAskar
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
RecordDuplicateError,
RecordNotFoundError,
} from '@aries-framework/core'
import { ariesAskar } from '@hyperledger/aries-askar-shared'
import { ariesAskar } from '@hyperledger/aries-askar-nodejs'

import { describeRunInNodeVersion } from '../../../../../tests/runInVersion'
import { TestRecord } from '../../../../core/src/storage/__tests__/TestRecord'
Expand All @@ -30,8 +30,7 @@ describeRunInNodeVersion([18], 'AskarStorageService', () => {
wallet,
agentConfig,
})
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
await wallet.createAndOpen(agentConfig.walletConfig!)
await wallet.createAndOpen(agentConfig.walletConfig)
storageService = new AskarStorageService<TestRecord>()
})

Expand Down
8 changes: 6 additions & 2 deletions packages/askar/tests/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,15 @@ import type { AskarWalletPostgresStorageConfig } from '../src/wallet'
import type { InitConfig } from '@aries-framework/core'

import { LogLevel } from '@aries-framework/core'
import { ariesAskar } from '@hyperledger/aries-askar-nodejs'
import path from 'path'

import { TestLogger } from '../../core/tests/logger'
import { agentDependencies } from '../../node/src'
import { AskarModule } from '../src/AskarModule'
import { AskarModuleConfig } from '../src/AskarModuleConfig'

export const askarModuleConfig = new AskarModuleConfig({ ariesAskar })

export const genesisPath = process.env.GENESIS_TXN_PATH
? path.resolve(process.env.GENESIS_TXN_PATH)
Expand Down Expand Up @@ -34,7 +38,7 @@ export function getPostgresAgentOptions(
return {
config,
dependencies: agentDependencies,
modules: { askar: new AskarModule() },
modules: { askar: new AskarModule(askarModuleConfig) },
} as const
}

Expand All @@ -54,6 +58,6 @@ export function getSqliteAgentOptions(name: string, extraConfig: Partial<InitCon
return {
config,
dependencies: agentDependencies,
modules: { askar: new AskarModule() },
modules: { askar: new AskarModule(askarModuleConfig) },
} as const
}
8 changes: 1 addition & 7 deletions packages/askar/tests/setup.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
import 'reflect-metadata'
import '@hyperledger/aries-askar-nodejs'

jest.setTimeout(180000)

try {
// eslint-disable-next-line import/no-extraneous-dependencies
require('@hyperledger/aries-askar-nodejs')
} catch (error) {
throw new Error('Could not load aries-askar bindings')
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { SubjectOutboundTransport } from '../../../../../../tests/transport/Subj
import { getIndySdkModules } from '../../../../../indy-sdk/tests/setupIndySdkModule'
import { getAgentOptions, waitForBasicMessage } from '../../../../tests/helpers'
import { Agent } from '../../../agent/Agent'
import { sleep } from '../../../utils/sleep'
import { ConnectionRecord, HandshakeProtocol } from '../../connections'
import { MediatorPickupStrategy } from '../MediatorPickupStrategy'
import { MediationState } from '../models/MediationState'
Expand Down Expand Up @@ -143,6 +144,10 @@ describe('mediator establishment', () => {
content: message,
})

// polling interval is 100ms, so 500ms should be enough to make sure no messages are sent
await recipientAgent.mediationRecipient.stopMessagePickup()
await sleep(500)

expect(basicMessage.content).toBe(message)
}

Expand All @@ -159,6 +164,7 @@ describe('mediator establishment', () => {
config: {
...recipientAgentOptions.config,
mediatorPickupStrategy: MediatorPickupStrategy.PickUpV1,
mediatorPollingInterval: 100,
},
})
})
Expand All @@ -175,6 +181,7 @@ describe('mediator establishment', () => {
...recipientAgentOptions.config,
mediatorPickupStrategy: MediatorPickupStrategy.PickUpV1,
useDidKeyInProtocols: false,
mediatorPollingInterval: 100,
},
}
)
Expand Down
Loading