Skip to content

Commit

Permalink
feat: (WIP) added ownerId, tenantId, and origin.
Browse files Browse the repository at this point in the history
  • Loading branch information
sksadjad committed Mar 14, 2024
1 parent 03d3feb commit d9b8623
Show file tree
Hide file tree
Showing 22 changed files with 428 additions and 103 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { TAgent } from '@veramo/core'
import {TAgent} from '@veramo/core'
import {
CorrelationIdentifierEnum,
CredentialRole,
ElectronicAddress,
GetPartiesArgs,
Identity,
IdentityRoleEnum,
IdentityOrigin,
NaturalPerson,
NonPersistedElectronicAddress,
NonPersistedIdentity,
Expand All @@ -14,7 +15,7 @@ import {
PartyTypeEnum,
PhysicalAddress,
} from '../../../data-store/src'
import { AddContactArgs, IContactManager } from '../../src'
import {AddContactArgs, IContactManager} from '../../src'

type ConfiguredAgent = TAgent<IContactManager>

Expand Down Expand Up @@ -43,7 +44,8 @@ export default (testContext: { getAgent: () => ConfiguredAgent; setup: () => Pro
const correlationId = 'default_example_did'
const identity: NonPersistedIdentity = {
alias: correlationId,
roles: [IdentityRoleEnum.ISSUER, IdentityRoleEnum.VERIFIER],
origin: IdentityOrigin.EXTRERNAL,
roles: [CredentialRole.ISSUER, CredentialRole.VERIFIER],
identifier: {
type: CorrelationIdentifierEnum.DID,
correlationId,
Expand Down Expand Up @@ -237,7 +239,8 @@ export default (testContext: { getAgent: () => ConfiguredAgent; setup: () => Pro
const correlationId = 'new_example_did'
const identity: NonPersistedIdentity = {
alias: correlationId,
roles: [IdentityRoleEnum.ISSUER, IdentityRoleEnum.VERIFIER],
origin: IdentityOrigin.EXTRERNAL,
roles: [CredentialRole.ISSUER, CredentialRole.VERIFIER],
identifier: {
type: CorrelationIdentifierEnum.DID,
correlationId,
Expand All @@ -261,7 +264,8 @@ export default (testContext: { getAgent: () => ConfiguredAgent; setup: () => Pro
const correlationId = 'missing_connection_add_example'
const identity: NonPersistedIdentity = {
alias: correlationId,
roles: [IdentityRoleEnum.ISSUER, IdentityRoleEnum.VERIFIER],
origin: IdentityOrigin.EXTRERNAL,
roles: [CredentialRole.ISSUER, CredentialRole.VERIFIER],
identifier: {
type: CorrelationIdentifierEnum.URL,
correlationId,
Expand All @@ -277,7 +281,8 @@ export default (testContext: { getAgent: () => ConfiguredAgent; setup: () => Pro
const correlationId = 'missing_connection_update_example'
const identity: NonPersistedIdentity = {
alias: correlationId,
roles: [IdentityRoleEnum.ISSUER, IdentityRoleEnum.VERIFIER],

roles: [CredentialRole.ISSUER, CredentialRole.VERIFIER],
identifier: {
type: CorrelationIdentifierEnum.DID,
correlationId,
Expand All @@ -293,7 +298,8 @@ export default (testContext: { getAgent: () => ConfiguredAgent; setup: () => Pro
const correlationId = 'new_update_example_did'
const identity: NonPersistedIdentity = {
alias: 'update_example_did',
roles: [IdentityRoleEnum.ISSUER, IdentityRoleEnum.VERIFIER],
origin: IdentityOrigin.EXTRERNAL,
roles: [CredentialRole.ISSUER, CredentialRole.VERIFIER],
identifier: {
type: CorrelationIdentifierEnum.DID,
correlationId: 'update_example_did',
Expand Down
4 changes: 4 additions & 0 deletions packages/contact-manager/src/agent/ContactManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ import {
UpdatePhysicalAddressArgs,
UpdateRelationshipArgs,
} from '../types/IContactManager'
import {IdentityOrigin} from "@sphereon/ssi-sdk.data-store/dist";

/**
* {@inheritDoc IContactManager}
Expand Down Expand Up @@ -141,6 +142,9 @@ export class ContactManager implements IAgentPlugin {
/** {@inheritDoc IContactManager.cmAddIdentity} */
private async cmAddIdentity(args: AddIdentityArgs, context: RequiredContext): Promise<Identity> {
const { contactId, identity } = args
if(!identity.origin) {
identity.origin = IdentityOrigin.EXTRERNAL
}
return this.store.addIdentity({ partyId: contactId, identity })
}

Expand Down
85 changes: 51 additions & 34 deletions packages/data-store/src/__tests__/contact.entities.test.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
import { DataSource, FindOptionsWhere } from 'typeorm'
import { DataStoreContactEntities, DataStoreMigrations } from '../index'
import { BaseContactEntity } from '../entities/contact/BaseContactEntity'
import { ConnectionEntity } from '../entities/contact/ConnectionEntity'
import { CorrelationIdentifierEntity } from '../entities/contact/CorrelationIdentifierEntity'
import { DidAuthConfigEntity } from '../entities/contact/DidAuthConfigEntity'
import { ElectronicAddressEntity } from '../entities/contact/ElectronicAddressEntity'
import { IdentityEntity } from '../entities/contact/IdentityEntity'
import { IdentityMetadataItemEntity } from '../entities/contact/IdentityMetadataItemEntity'
import { NaturalPersonEntity } from '../entities/contact/NaturalPersonEntity'
import { OpenIdConfigEntity } from '../entities/contact/OpenIdConfigEntity'
import { OrganizationEntity } from '../entities/contact/OrganizationEntity'
import { PartyEntity } from '../entities/contact/PartyEntity'
import { PartyRelationshipEntity } from '../entities/contact/PartyRelationshipEntity'
import { PartyTypeEntity } from '../entities/contact/PartyTypeEntity'
import { PhysicalAddressEntity } from '../entities/contact/PhysicalAddressEntity'
import {DataSource, FindOptionsWhere} from 'typeorm'
import {DataStoreContactEntities, DataStoreMigrations, IdentityOrigin} from '../index'
import {BaseContactEntity} from '../entities/contact/BaseContactEntity'
import {ConnectionEntity} from '../entities/contact/ConnectionEntity'
import {CorrelationIdentifierEntity} from '../entities/contact/CorrelationIdentifierEntity'
import {DidAuthConfigEntity} from '../entities/contact/DidAuthConfigEntity'
import {ElectronicAddressEntity} from '../entities/contact/ElectronicAddressEntity'
import {IdentityEntity} from '../entities/contact/IdentityEntity'
import {IdentityMetadataItemEntity} from '../entities/contact/IdentityMetadataItemEntity'
import {NaturalPersonEntity} from '../entities/contact/NaturalPersonEntity'
import {OpenIdConfigEntity} from '../entities/contact/OpenIdConfigEntity'
import {OrganizationEntity} from '../entities/contact/OrganizationEntity'
import {PartyEntity} from '../entities/contact/PartyEntity'
import {PartyRelationshipEntity} from '../entities/contact/PartyRelationshipEntity'
import {PartyTypeEntity} from '../entities/contact/PartyTypeEntity'
import {PhysicalAddressEntity} from '../entities/contact/PhysicalAddressEntity'
import {
ConnectionTypeEnum,
CorrelationIdentifierEnum,
IdentityRoleEnum,
CredentialRole,
NaturalPerson,
NonPersistedConnection,
NonPersistedDidAuthConfig,
Expand Down Expand Up @@ -397,7 +397,8 @@ describe('Database entities tests', (): void => {
const alias = 'non_unique_alias'
const identity1: NonPersistedIdentity = {
alias,
roles: [IdentityRoleEnum.ISSUER, IdentityRoleEnum.VERIFIER],
origin: IdentityOrigin.EXTRERNAL,
roles: [CredentialRole.ISSUER, CredentialRole.VERIFIER],
identifier: {
type: CorrelationIdentifierEnum.DID,
correlationId: 'unique_correlationId1',
Expand All @@ -408,7 +409,8 @@ describe('Database entities tests', (): void => {

const identity2: NonPersistedIdentity = {
alias: alias,
roles: [IdentityRoleEnum.ISSUER, IdentityRoleEnum.VERIFIER],
origin: IdentityOrigin.EXTRERNAL,
roles: [CredentialRole.ISSUER, CredentialRole.VERIFIER],
identifier: {
type: CorrelationIdentifierEnum.DID,
correlationId: 'unique_correlationId2',
Expand All @@ -424,7 +426,8 @@ describe('Database entities tests', (): void => {
const correlationId = 'non_unique_correlationId'
const identity1: NonPersistedIdentity = {
alias: 'unique_alias1',
roles: [IdentityRoleEnum.ISSUER, IdentityRoleEnum.VERIFIER],
origin: IdentityOrigin.EXTRERNAL,
roles: [CredentialRole.ISSUER, CredentialRole.VERIFIER],
identifier: {
type: CorrelationIdentifierEnum.DID,
correlationId,
Expand All @@ -435,7 +438,8 @@ describe('Database entities tests', (): void => {

const identity2: NonPersistedIdentity = {
alias: 'unique_alias2',
roles: [IdentityRoleEnum.ISSUER, IdentityRoleEnum.VERIFIER],
origin: IdentityOrigin.EXTRERNAL,
roles: [CredentialRole.ISSUER, CredentialRole.VERIFIER],
identifier: {
type: CorrelationIdentifierEnum.DID,
correlationId,
Expand All @@ -451,7 +455,8 @@ describe('Database entities tests', (): void => {
const correlationId = 'example_did'
const identity: NonPersistedIdentity = {
alias: correlationId,
roles: [IdentityRoleEnum.ISSUER, IdentityRoleEnum.VERIFIER],
origin: IdentityOrigin.EXTRERNAL,
roles: [CredentialRole.ISSUER, CredentialRole.VERIFIER],
identifier: {
type: CorrelationIdentifierEnum.DID,
correlationId,
Expand Down Expand Up @@ -480,7 +485,8 @@ describe('Database entities tests', (): void => {
it('should throw error when saving identity with blank alias', async (): Promise<void> => {
const identity: NonPersistedIdentity = {
alias: '',
roles: [IdentityRoleEnum.ISSUER, IdentityRoleEnum.VERIFIER],
origin: IdentityOrigin.EXTRERNAL,
roles: [CredentialRole.ISSUER, CredentialRole.VERIFIER],
identifier: {
type: CorrelationIdentifierEnum.DID,
correlationId: 'example_did',
Expand All @@ -495,7 +501,8 @@ describe('Database entities tests', (): void => {
it('should throw error when saving identity with blank correlation id', async (): Promise<void> => {
const identity: NonPersistedIdentity = {
alias: 'example_did',
roles: [IdentityRoleEnum.ISSUER, IdentityRoleEnum.VERIFIER],
origin: IdentityOrigin.EXTRERNAL,
roles: [CredentialRole.ISSUER, CredentialRole.VERIFIER],
identifier: {
type: CorrelationIdentifierEnum.DID,
correlationId: '',
Expand All @@ -511,7 +518,8 @@ describe('Database entities tests', (): void => {
const correlationId = 'example_did'
const identity: NonPersistedIdentity = {
alias: correlationId,
roles: [IdentityRoleEnum.ISSUER, IdentityRoleEnum.VERIFIER],
origin: IdentityOrigin.EXTRERNAL,
roles: [CredentialRole.ISSUER, CredentialRole.VERIFIER],
identifier: {
type: CorrelationIdentifierEnum.DID,
correlationId,
Expand All @@ -533,7 +541,8 @@ describe('Database entities tests', (): void => {
const correlationId = 'example_did'
const identity: NonPersistedIdentity = {
alias: correlationId,
roles: [IdentityRoleEnum.ISSUER, IdentityRoleEnum.VERIFIER],
origin: IdentityOrigin.EXTRERNAL,
roles: [CredentialRole.ISSUER, CredentialRole.VERIFIER],
identifier: {
type: CorrelationIdentifierEnum.DID,
correlationId,
Expand All @@ -555,7 +564,8 @@ describe('Database entities tests', (): void => {
const correlationId = 'example.com'
const identity: NonPersistedIdentity = {
alias: correlationId,
roles: [IdentityRoleEnum.ISSUER, IdentityRoleEnum.VERIFIER],
origin: IdentityOrigin.EXTRERNAL,
roles: [CredentialRole.ISSUER, CredentialRole.VERIFIER],
identifier: {
type: CorrelationIdentifierEnum.URL,
correlationId,
Expand Down Expand Up @@ -600,7 +610,8 @@ describe('Database entities tests', (): void => {
const correlationId = 'example.com'
const identity: NonPersistedIdentity = {
alias: correlationId,
roles: [IdentityRoleEnum.ISSUER, IdentityRoleEnum.VERIFIER],
origin: IdentityOrigin.EXTRERNAL,
roles: [CredentialRole.ISSUER, CredentialRole.VERIFIER],
identifier: {
type: CorrelationIdentifierEnum.URL,
correlationId,
Expand Down Expand Up @@ -811,7 +822,8 @@ describe('Database entities tests', (): void => {
const correlationId = 'relation_example.com'
const identity: NonPersistedIdentity = {
alias: correlationId,
roles: [IdentityRoleEnum.ISSUER, IdentityRoleEnum.VERIFIER],
origin: IdentityOrigin.EXTRERNAL,
roles: [CredentialRole.ISSUER, CredentialRole.VERIFIER],
identifier: {
type: CorrelationIdentifierEnum.URL,
correlationId,
Expand Down Expand Up @@ -970,7 +982,8 @@ describe('Database entities tests', (): void => {
const correlationId = 'relation_example.com'
const identity: NonPersistedIdentity = {
alias: correlationId,
roles: [IdentityRoleEnum.ISSUER, IdentityRoleEnum.VERIFIER],
origin: IdentityOrigin.EXTRERNAL,
roles: [CredentialRole.ISSUER, CredentialRole.VERIFIER],
identifier: {
type: CorrelationIdentifierEnum.URL,
correlationId,
Expand Down Expand Up @@ -1070,7 +1083,8 @@ describe('Database entities tests', (): void => {
const correlationId = 'relation_example.com'
const identity: NonPersistedIdentity = {
alias: correlationId,
roles: [IdentityRoleEnum.ISSUER, IdentityRoleEnum.VERIFIER],
origin: IdentityOrigin.EXTRERNAL,
roles: [CredentialRole.ISSUER, CredentialRole.VERIFIER],
identifier: {
type: CorrelationIdentifierEnum.URL,
correlationId,
Expand Down Expand Up @@ -1191,7 +1205,8 @@ describe('Database entities tests', (): void => {
const correlationId = 'example_did'
const identity: NonPersistedIdentity = {
alias: correlationId,
roles: [IdentityRoleEnum.ISSUER, IdentityRoleEnum.VERIFIER],
origin: IdentityOrigin.EXTRERNAL,
roles: [CredentialRole.ISSUER, CredentialRole.VERIFIER],
identifier: {
type: CorrelationIdentifierEnum.DID,
correlationId,
Expand All @@ -1217,7 +1232,8 @@ describe('Database entities tests', (): void => {
const correlationId = 'example_did'
const identity: NonPersistedIdentity = {
alias: correlationId,
roles: [IdentityRoleEnum.ISSUER, IdentityRoleEnum.VERIFIER],
origin: IdentityOrigin.EXTRERNAL,
roles: [CredentialRole.ISSUER, CredentialRole.VERIFIER],
identifier: {
type: CorrelationIdentifierEnum.DID,
correlationId,
Expand Down Expand Up @@ -1354,7 +1370,8 @@ describe('Database entities tests', (): void => {
const correlationId = 'example_did'
const identity: NonPersistedIdentity = {
alias: correlationId,
roles: [IdentityRoleEnum.ISSUER, IdentityRoleEnum.VERIFIER],
origin: IdentityOrigin.EXTRERNAL,
roles: [CredentialRole.ISSUER, CredentialRole.VERIFIER],
identifier: {
type: CorrelationIdentifierEnum.DID,
correlationId,
Expand Down
Loading

0 comments on commit d9b8623

Please sign in to comment.