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

feat: delete exchange record #222

Draft
wants to merge 1 commit into
base: develop-dco-fixed
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
415 changes: 415 additions & 0 deletions patches/@credo-ts+core+0.5.3+001+delete-exchange-records.patch

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions samples/cliConfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"indyNamespace": "bcovrin:testnet"
}
],
"endpoint": ["http://localhost:4002"],
"endpoint": ["http://192.168.1.71:4002"],
"autoAcceptConnections": true,
"autoAcceptCredentials": "always",
"autoAcceptProofs": "contentApproved",
Expand All @@ -42,5 +42,6 @@
"schemaManagerContractAddress": "0x4742d43C2dFCa5a1d4238240Afa8547Daf87Ee7a",
"rpcUrl": "https://rpc-amoy.polygon.technology",
"fileServerUrl": "https://schema.credebl.id",
"fileServerToken": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJBeWFuV29ya3MiLCJpZCI6ImNhZDI3ZjhjLTMyNWYtNDRmZC04ZmZkLWExNGNhZTY3NTMyMSJ9.I3IR7abjWbfStnxzn1BhxhV0OEzt1x3mULjDdUcgWHk"
"fileServerToken": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJBeWFuV29ya3MiLCJpZCI6ImNhZDI3ZjhjLTMyNWYtNDRmZC04ZmZkLWExNGNhZTY3NTMyMSJ9.I3IR7abjWbfStnxzn1BhxhV0OEzt1x3mULjDdUcgWHk",
"isPreserveExchangeRecords": false
}
47 changes: 47 additions & 0 deletions samples/cliConfigHolder.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
{
"label": "AFJ Rest Agent 2",
"walletId": "sampleHolder",
"walletKey": "sampleHolder",
"walletType": "postgres",
"walletUrl": "localhost:5432",
"walletAccount": "postgres",
"walletPassword": "postgres",
"walletAdminAccount": "postgres",
"walletAdminPassword": "postgres",
"walletScheme": "ProfilePerWallet",
"indyLedger": [
{
"genesisTransactions": "https://raw.githubusercontent.com/Indicio-tech/indicio-network/main/genesis_files/pool_transactions_testnet_genesis",
"indyNamespace": "indicio:testnet"
},
{
"genesisTransactions": "https://raw.githubusercontent.com/Indicio-tech/indicio-network/main/genesis_files/pool_transactions_demonet_genesis",
"indyNamespace": "indicio:demonet"
},
{
"genesisTransactions": "https://raw.githubusercontent.com/bcgov/von-network/main/BCovrin/genesis_test",
"indyNamespace": "bcovrin:testnet"
}
],
"endpoint": ["http://192.168.1.71:4004"],
"autoAcceptConnections": true,
"autoAcceptCredentials": "always",
"autoAcceptProofs": "contentApproved",
"logLevel": 2,
"inboundTransport": [
{
"transport": "http",
"port": 4004
}
],
"outboundTransport": ["http"],
"adminPort": 4003,
"tenancy": true,
"schemaFileServerURL": "https://schema.credebl.id/schemas/",
"didRegistryContractAddress": "0xcB80F37eDD2bE3570c6C9D5B0888614E04E1e49E",
"schemaManagerContractAddress": "0x4742d43C2dFCa5a1d4238240Afa8547Daf87Ee7a",
"rpcUrl": "https://rpc-amoy.polygon.technology",
"fileServerUrl": "https://schema.credebl.id",
"fileServerToken": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJBeWFuV29ya3MiLCJpZCI6ImNhZDI3ZjhjLTMyNWYtNDRmZC04ZmZkLWExNGNhZTY3NTMyMSJ9.I3IR7abjWbfStnxzn1BhxhV0OEzt1x3mULjDdUcgWHk",
"isPreserveExchangeRecords": false
}
4 changes: 3 additions & 1 deletion src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ interface Parsed {
rpcUrl?: string
fileServerUrl?: string
fileServerToken?: string
isPreserveExchangeRecords?: boolean
}

interface InboundTransport {
Expand Down Expand Up @@ -252,5 +253,6 @@ export async function runCliServer() {
rpcUrl: parsed.rpcUrl,
fileServerUrl: parsed.fileServerUrl,
fileServerToken: parsed.fileServerToken,
isPreserveExchangeRecords: parsed.isPreserveExchangeRecords,
} as AriesRestConfig)
}
}
29 changes: 21 additions & 8 deletions src/cliAgent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ export interface AriesRestConfig {
fileServerToken?: string
walletScheme?: AskarMultiWalletDatabaseScheme
schemaFileServerURL?: string
isPreserveExchangeRecords?: boolean
}

export async function readRestConfig(path: string) {
Expand All @@ -124,7 +125,9 @@ const getModules = (
autoAcceptConnections: boolean,
autoAcceptCredentials: AutoAcceptCredential,
autoAcceptProofs: AutoAcceptProof,
walletScheme: AskarMultiWalletDatabaseScheme
walletScheme: AskarMultiWalletDatabaseScheme,
// eslint-disable-next-line @typescript-eslint/no-unused-vars
isPreserveExchangeRecords: boolean
) => {
const legacyIndyCredentialFormat = new LegacyIndyCredentialFormatService()
const legacyIndyProofFormat = new LegacyIndyProofFormatService()
Expand Down Expand Up @@ -189,8 +192,11 @@ const getModules = (

questionAnswer: new QuestionAnswerModule(),
polygon: new PolygonModule({
didContractAddress: didRegistryContractAddress ? didRegistryContractAddress : (process.env.DID_CONTRACT_ADDRESS as string),
schemaManagerContractAddress: schemaManagerContractAddress || (process.env.SCHEMA_MANAGER_CONTRACT_ADDRESS as string),
didContractAddress: didRegistryContractAddress
? didRegistryContractAddress
: (process.env.DID_CONTRACT_ADDRESS as string),
schemaManagerContractAddress:
schemaManagerContractAddress || (process.env.SCHEMA_MANAGER_CONTRACT_ADDRESS as string),
fileServerToken: fileServerToken ? fileServerToken : (process.env.FILE_SERVER_TOKEN as string),
rpcUrl: rpcUrl ? rpcUrl : (process.env.RPC_URL as string),
serverUrl: fileServerUrl ? fileServerUrl : (process.env.SERVER_URL as string),
Expand All @@ -209,7 +215,8 @@ const getWithTenantModules = (
autoAcceptConnections: boolean,
autoAcceptCredentials: AutoAcceptCredential,
autoAcceptProofs: AutoAcceptProof,
walletScheme: AskarMultiWalletDatabaseScheme
walletScheme: AskarMultiWalletDatabaseScheme,
isPreserveExchangeRecords: boolean
) => {
const modules = getModules(
networkConfig,
Expand All @@ -221,7 +228,8 @@ const getWithTenantModules = (
autoAcceptConnections,
autoAcceptCredentials,
autoAcceptProofs,
walletScheme
walletScheme,
isPreserveExchangeRecords
)
return {
tenants: new TenantsModule<typeof modules>({
Expand Down Expand Up @@ -268,6 +276,7 @@ export async function runRestAgent(restConfig: AriesRestConfig) {
autoAcceptCredentials,
autoAcceptProofs,
walletScheme,
isPreserveExchangeRecords,
...afjConfig
} = restConfig

Expand All @@ -281,6 +290,8 @@ export async function runRestAgent(restConfig: AriesRestConfig) {
},
...afjConfig,
logger,
isPreserveExchangeRecords:
isPreserveExchangeRecords || (process.env.IS_PRESERVE_EXCHANGE_RECORD as unknown as boolean) || true,
autoUpdateStorageOnStartup: true,
// As backup is only supported for sqlite storage
// we need to manually take backup of the storage before updating the storage
Expand Down Expand Up @@ -352,7 +363,8 @@ export async function runRestAgent(restConfig: AriesRestConfig) {
autoAcceptConnections || true,
autoAcceptCredentials || AutoAcceptCredential.Always,
autoAcceptProofs || AutoAcceptProof.ContentApproved,
walletScheme || AskarMultiWalletDatabaseScheme.ProfilePerWallet
walletScheme || AskarMultiWalletDatabaseScheme.ProfilePerWallet,
isPreserveExchangeRecords || (process.env.IS_PRESERV_EXCHANGE_RECORD as unknown as boolean)
)
const modules = getModules(
networkConfig,
Expand All @@ -364,7 +376,8 @@ export async function runRestAgent(restConfig: AriesRestConfig) {
autoAcceptConnections || true,
autoAcceptCredentials || AutoAcceptCredential.Always,
autoAcceptProofs || AutoAcceptProof.ContentApproved,
walletScheme || AskarMultiWalletDatabaseScheme.ProfilePerWallet
walletScheme || AskarMultiWalletDatabaseScheme.ProfilePerWallet,
isPreserveExchangeRecords || (process.env.IS_PRESERV_EXCHANGE_RECORD as unknown as boolean)
)
const agent = new Agent({
config: agentConfig,
Expand Down Expand Up @@ -440,4 +453,4 @@ export async function runRestAgent(restConfig: AriesRestConfig) {
app.listen(adminPort, () => {
logger.info(`Successfully started server on port ${adminPort}`)
})
}
}
3 changes: 2 additions & 1 deletion src/controllers/credentials/CredentialController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ export class CredentialController extends Controller {
credentialFormats: outOfBandOption.credentialFormats,
autoAcceptCredential: outOfBandOption.autoAcceptCredential,
comment: outOfBandOption.comment,
isPreserveExchangeRecord: outOfBandOption.isPreserveExchangeRecord,
})

const credentialMessage = offerOob.message
Expand Down Expand Up @@ -295,4 +296,4 @@ export class CredentialController extends Controller {
throw ErrorHandlingService.handle(error)
}
}
}
}
5 changes: 4 additions & 1 deletion src/controllers/multi-tenancy/MultiTenancyController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1279,6 +1279,7 @@ export class MultiTenancyController extends Controller {
protocolVersion: createOfferOptions.protocolVersion as CredentialProtocolVersionType<[]>,
credentialFormats: createOfferOptions.credentialFormats,
autoAcceptCredential: createOfferOptions.autoAcceptCredential,
isPreserveExchangeRecord: createOfferOptions.isPreserveExchangeRecord,
})
})

Expand Down Expand Up @@ -1328,6 +1329,7 @@ export class MultiTenancyController extends Controller {
credentialFormats: createOfferOptions.credentialFormats,
autoAcceptCredential: createOfferOptions.autoAcceptCredential,
comment: createOfferOptions.comment,
isPreserveExchangeRecord: createOfferOptions.isPreserveExchangeRecord,
})

const credentialMessage = offerOob.message
Expand Down Expand Up @@ -1526,6 +1528,7 @@ export class MultiTenancyController extends Controller {
parentThreadId: createRequestOptions.parentThreadId,
autoAcceptProof: createRequestOptions.autoAcceptProof,
comment: createRequestOptions.comment,
isPreserveExchangeRecord: createRequestOptions.isPreserveExchangeRecord,
})

const proofMessage = proof.message
Expand Down Expand Up @@ -1888,4 +1891,4 @@ export class MultiTenancyController extends Controller {
throw ErrorHandlingService.handle(error)
}
}
}
}
3 changes: 2 additions & 1 deletion src/controllers/proofs/ProofController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ export class ProofController extends Controller {
parentThreadId: createRequestOptions.parentThreadId,
autoAcceptProof: createRequestOptions.autoAcceptProof,
comment: createRequestOptions.comment,
isPreserveExchangeRecord: createRequestOptions.isPreserveExchangeRecord,
})
const proofMessage = proof.message
const outOfBandRecord = await this.agent.oob.createInvitation({
Expand Down Expand Up @@ -279,4 +280,4 @@ export class ProofController extends Controller {
throw ErrorHandlingService.handle(error)
}
}
}
}
6 changes: 5 additions & 1 deletion src/controllers/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ export interface AcceptCredentialProposalOptions {
}

export interface CreateOfferOptions {
isPreserveExchangeRecord?: boolean
protocolVersion: ProtocolVersion
connectionId: RecordId
credentialFormats: CredentialFormatPayload<CredentialFormats, 'createOffer'>
Expand All @@ -99,6 +100,7 @@ export interface CreateOfferOptions {
type CredentialFormatType = LegacyIndyCredentialFormat | JsonLdCredentialFormat | AnonCredsCredentialFormat

export interface CreateOfferOobOptions {
isPreserveExchangeRecord?: boolean
protocolVersion: string
credentialFormats: CredentialFormatPayload<CredentialFormatType[], 'createOffer'>
autoAcceptCredential?: AutoAcceptCredential
Expand All @@ -119,6 +121,7 @@ export interface CredentialCreateOfferOptions {
}

export interface CreateProofRequestOobOptions {
isPreserveExchangeRecord?: boolean
protocolVersion: string
proofFormats: any
goalCode?: string
Expand Down Expand Up @@ -234,6 +237,7 @@ export interface ConnectionInvitationSchema {
// }

export interface RequestProofOptions {
isPreserveExchangeRecord?: boolean
connectionId: string
protocolVersion: string
proofFormats: any
Expand Down Expand Up @@ -387,4 +391,4 @@ export interface SchemaMetadata {
/**
* @example "ea4e5e69-fc04-465a-90d2-9f8ff78aa71d"
*/
export type ThreadId = string
export type ThreadId = string
3 changes: 2 additions & 1 deletion src/utils/agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export const setupAgent = async ({ name, endpoints, port }: { name: string; endp
const logger = new TsLogger(LogLevel.debug)

const config: InitConfig = {
isPreserveExchangeRecords: (process.env.IS_PRESERVE_EXCHANGE_RECORD as unknown as boolean) || true,
label: name,
endpoints: endpoints,
walletConfig: {
Expand Down Expand Up @@ -146,4 +147,4 @@ export const setupAgent = async ({ name, endpoints, port }: { name: string; endp
await agent.initialize()

return agent
}
}