Skip to content

Commit

Permalink
Merge pull request #2 from credebl/feat/agent-setup
Browse files Browse the repository at this point in the history
feat: add agent provider and agent modules
  • Loading branch information
amitpadmani-awts authored Oct 4, 2023
2 parents 949cfa8 + 43475e6 commit f827ed5
Show file tree
Hide file tree
Showing 14 changed files with 10,496 additions and 3,181 deletions.
63 changes: 62 additions & 1 deletion .github/workflows/pipeline.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,29 @@ on:
pull_request:
types: [opened, synchronize]

workflow_dispatch:
inputs:
release-type:
description: 'Type of release (major, minor, patch, alpha)'
required: true
default: alpha
type: choice
options:
- major
- minor
- patch
- alpha

package:
description: 'Which package to release'
required: true
default: ssi
type: choice
options:
- ssi

jobs:
continous-integration:
continuous-integration:
name: 'Continuous Integration'
runs-on: ubuntu-latest

Expand All @@ -30,3 +51,43 @@ jobs:

- name: Test
run: pnpm test

continuous-deployment:
if: github.event_name == 'workflow_dispatch'

name: 'Continuous Deployment'
runs-on: ubuntu-latest
needs: ['continuous-integration']

steps:
- uses: actions/checkout@v3

- uses: pnpm/action-setup@v2
with:
version: 8.6.0

- name: Install dependencies
run: pnpm install

- name: Build
run: pnpm build

- name: Initialise the NPM config
env:
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
run: npm config set //registry.npmjs.org/:_authToken $NPM_TOKEN

- name: Publish
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
shell: bash
run: |
git config --global user.email "sairanjit.tummalapalli@ayanworks.com"
git config --global user.name "Sai Ranjit Tummalapalli"
if [ ${{ inputs.release-type }} == 'alpha' ]; then
pnpm run --dir packages/${{ inputs.package }} release ${{ inputs.release-type }} --npm.tag=alpha
else
pnpm run --dir packages/${{ inputs.package }} release ${{ inputs.release-type }} --npm.tag=latest
fi
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
node_modules
build/
.DS_Store
build
4 changes: 4 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
pnpm-lock.yaml
node_modules
.DS_Store
build
8 changes: 8 additions & 0 deletions .release-it.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"git": {
"commitMessage": "chore: release v${version}"
},
"github": {
"release": true
}
}
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"check-format": "pnpm prettier --list-different",
"build": "pnpm -r build",
"clean": "pnpm -r clean",
"prettier": "prettier --ignore-path .gitignore '**/*.+(js|json|ts|md|yml|yaml)'",
"prettier": "prettier .",
"format": "pnpm prettier --write",
"validate": "pnpm lint && pnpm check-types && pnpm check-format"
},
Expand All @@ -32,6 +32,7 @@
"eslint-plugin-prettier": "^5.0.0",
"jest": "^29.7.0",
"prettier": "^3.0.3",
"release-it": "^16.2.1",
"ts-jest": "^29.1.1",
"ts-node": "^10.9.1",
"tsconfig-paths": "^4.2.0",
Expand Down
23 changes: 20 additions & 3 deletions packages/ssi/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
"license": "Apache-2.0",
"main": "build/index",
"source": "src/index",
"homepage": "https://github.com/hyperledger/anoncreds-rs/tree/main/wrappers/javascript/anoncreds-shared",
"homepage": "https://github.com/credebl/adeya-sdk/tree/main/packages/ssi",
"repository": {
"url": "https://github.com/hyperledger/anoncreds-rs",
"url": "https://github.com/credebl/adeya-sdk/tree/main/packages/ssi",
"type": "git",
"directory": "packages/ssi"
},
Expand All @@ -20,9 +20,26 @@
"check-types": "pnpm compile --noEmit",
"build": "pnpm clean && pnpm compile",
"clean": "rimraf -rf ./build",
"compile": "tsc"
"compile": "tsc",
"release": "release-it"
},
"dependencies": {
"@aries-framework/anoncreds": "0.4.1",
"@aries-framework/anoncreds-rs": "0.4.1",
"@aries-framework/askar": "0.4.1",
"@aries-framework/core": "0.4.1",
"@aries-framework/indy-vdr": "0.4.1",
"@aries-framework/push-notifications": "^0.6.0",
"@aries-framework/react-hooks": "0.5.0",
"@aries-framework/react-native": "0.4.1"
},
"peerDependencies": {
"@hyperledger/anoncreds-react-native": "^0.1.0",
"@hyperledger/aries-askar-react-native": "^0.1.1",
"@hyperledger/indy-vdr-react-native": "^0.1.0"
},
"devDependencies": {
"@types/react": "^18.0.24",
"rimraf": "3.0.2",
"typescript": "~5.2.2"
}
Expand Down
128 changes: 128 additions & 0 deletions packages/ssi/src/agent.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
import type { InitConfig } from '@aries-framework/core'
import type { IndyVdrPoolConfig } from '@aries-framework/indy-vdr'

import {
AnonCredsCredentialFormatService,
AnonCredsModule,
AnonCredsProofFormatService,
LegacyIndyCredentialFormatService,
LegacyIndyProofFormatService,
V1CredentialProtocol,
V1ProofProtocol
} from '@aries-framework/anoncreds'
import { AnonCredsRsModule } from '@aries-framework/anoncreds-rs'
import { AskarModule } from '@aries-framework/askar'
import {
JwkDidRegistrar,
JwkDidResolver,
Agent,
DidsModule,
WebDidResolver,
CredentialsModule,
V2CredentialProtocol,
ProofsModule,
V2ProofProtocol,
AutoAcceptProof,
AutoAcceptCredential,
MediationRecipientModule,
HttpOutboundTransport,
WsOutboundTransport,
ConnectionsModule,
MediatorPickupStrategy,
JsonLdCredentialFormatService
} from '@aries-framework/core'
import {
IndyVdrAnonCredsRegistry,
IndyVdrIndyDidResolver,
IndyVdrModule,
IndyVdrSovDidResolver
} from '@aries-framework/indy-vdr'
import { PushNotificationsFcmModule } from '@aries-framework/push-notifications'
import { agentDependencies } from '@aries-framework/react-native'
import { anoncreds } from '@hyperledger/anoncreds-react-native'
import { ariesAskar } from '@hyperledger/aries-askar-react-native'
import { indyVdr } from '@hyperledger/indy-vdr-react-native'

const getAgentModules = (mediatorInvitationUrl: string, indyNetworks: [IndyVdrPoolConfig, ...IndyVdrPoolConfig[]]) => {
return {
askar: new AskarModule({
ariesAskar
}),
anoncredsRs: new AnonCredsRsModule({
anoncreds
}),
anoncreds: new AnonCredsModule({
registries: [new IndyVdrAnonCredsRegistry()]
}),
mediationRecipient: new MediationRecipientModule({
mediatorPickupStrategy: MediatorPickupStrategy.PickUpV2,
mediatorInvitationUrl: mediatorInvitationUrl
}),
dids: new DidsModule({
registrars: [new JwkDidRegistrar()],
resolvers: [new WebDidResolver(), new JwkDidResolver(), new IndyVdrSovDidResolver(), new IndyVdrIndyDidResolver()]
}),
indyVdr: new IndyVdrModule({
indyVdr,
networks: indyNetworks
}),
credentials: new CredentialsModule({
autoAcceptCredentials: AutoAcceptCredential.ContentApproved,
credentialProtocols: [
new V1CredentialProtocol({
indyCredentialFormat: new LegacyIndyCredentialFormatService()
}),
new V2CredentialProtocol({
credentialFormats: [
new LegacyIndyCredentialFormatService(),
new AnonCredsCredentialFormatService(),
new JsonLdCredentialFormatService()
]
})
]
}),
proofs: new ProofsModule({
autoAcceptProofs: AutoAcceptProof.ContentApproved,
proofProtocols: [
new V1ProofProtocol({
indyProofFormat: new LegacyIndyProofFormatService()
}),
new V2ProofProtocol({
proofFormats: [new LegacyIndyProofFormatService(), new AnonCredsProofFormatService()]
})
]
}),
connections: new ConnectionsModule({
autoAcceptConnections: true
}),
pushNotificationsFcm: new PushNotificationsFcmModule()
}
}

export const initializeAgent = async ({
agentConfig,
mediatorInvitationUrl,
indyNetworks
}: {
agentConfig: InitConfig
mediatorInvitationUrl: string
indyNetworks: [IndyVdrPoolConfig, ...IndyVdrPoolConfig[]]
}) => {
const agent = new Agent({
dependencies: agentDependencies,
config: {
autoUpdateStorageOnStartup: true,
...agentConfig
},
modules: getAgentModules(mediatorInvitationUrl, indyNetworks)
})

agent.registerOutboundTransport(new HttpOutboundTransport())
agent.registerOutboundTransport(new WsOutboundTransport())

await agent.initialize()

return agent
}

export type AdeyaAgent = Awaited<ReturnType<typeof initializeAgent>>
43 changes: 43 additions & 0 deletions packages/ssi/src/hooks/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import {
useBasicMessages,
useBasicMessagesByConnectionId,
useConnectionById,
useConnections,
useCredentialById,
useCredentialByState,
useCredentialNotInState,
useCredentials,
useCredentialsByConnectionId,
useExchanges,
useExchangesByConnectionId,
useProofById,
useProofByState,
useProofNotInState,
useProofs,
useProofsByConnectionId,
useQuestionAnswer,
useQuestionAnswerByConnectionId,
useQuestionAnswerById
} from '@aries-framework/react-hooks'

export {
useBasicMessages,
useBasicMessagesByConnectionId,
useConnectionById,
useConnections,
useCredentialById,
useCredentialByState,
useCredentialNotInState,
useCredentials,
useCredentialsByConnectionId,
useExchanges,
useExchangesByConnectionId,
useProofById,
useProofByState,
useProofNotInState,
useProofs,
useProofsByConnectionId,
useQuestionAnswer,
useQuestionAnswerByConnectionId,
useQuestionAnswerById
}
53 changes: 51 additions & 2 deletions packages/ssi/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,52 @@
export const add = (a: number, b: number) => {
return a + b
import type { InitConfig } from '@aries-framework/core'

// Anoncreds
import {
V1RequestPresentationMessage,
AnonCredsCredentialOffer,
AnonCredsCredentialsForProofRequest,
AnonCredsRequestedAttributeMatch,
AnonCredsRequestedPredicateMatch,
AnonCredsNonRevokedInterval,
AnonCredsProofRequestRestriction,
AnonCredsProofFormat,
AnonCredsProofFormatService,
LegacyIndyProofFormat,
LegacyIndyProofFormatService,
AnonCredsPredicateType,
AnonCredsProof,
AnonCredsRequestedAttribute,
AnonCredsRequestedPredicate,
LegacyIndyProofRequest,
AnonCredsProofRequest
} from '@aries-framework/anoncreds'
import { AnonCredsCredentialMetadataKey } from '@aries-framework/anoncreds/build/utils/metadata'
// Core
import { LogLevel, ConsoleLogger } from '@aries-framework/core'
// Indy VDR
import { IndyVdrPoolConfig } from '@aries-framework/indy-vdr'

export { initializeAgent, AdeyaAgent } from './agent'
export { LogLevel, ConsoleLogger, InitConfig, IndyVdrPoolConfig }
export * from './providers'
export * from './hooks'
export {
V1RequestPresentationMessage,
AnonCredsCredentialOffer,
AnonCredsCredentialsForProofRequest,
AnonCredsRequestedAttributeMatch,
AnonCredsRequestedPredicateMatch,
AnonCredsNonRevokedInterval,
AnonCredsProofRequestRestriction,
AnonCredsProofFormat,
AnonCredsProofFormatService,
LegacyIndyProofFormat,
LegacyIndyProofFormatService,
AnonCredsPredicateType,
AnonCredsProof,
AnonCredsRequestedAttribute,
AnonCredsRequestedPredicate,
LegacyIndyProofRequest,
AnonCredsProofRequest,
AnonCredsCredentialMetadataKey
}
3 changes: 3 additions & 0 deletions packages/ssi/src/providers/AgentProvider.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import AgentProvider, { useAgent } from '@aries-framework/react-hooks'

export { useAgent as useAdeyaAgent, AgentProvider as AdeyaAgentProvider }
1 change: 1 addition & 0 deletions packages/ssi/src/providers/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { AdeyaAgentProvider, useAdeyaAgent } from './AgentProvider'
8 changes: 2 additions & 6 deletions packages/ssi/tests/ssi.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
import { add } from '../src'

describe('add function', () => {
it('should return the sum of two numbers', () => {
expect(add(1, 2)).toBe(3)
expect(add(0, 0)).toBe(0)
expect(add(-1, 1)).toBe(0)
it('should add two numbers', () => {
expect(1 + 1).toBe(2)
})
})
Loading

0 comments on commit f827ed5

Please sign in to comment.