test/mocha/helpers.js
// tests call on this to insert an issuerAgent
tests call on this to insert an issuerAgent
tests call on this to insert an issuerAgent
async function insertIssuerAgent({
  id, token, didMethod, privateKmsBaseUrl, publicKmsBaseUrl
}) {
  const {id: profileId} = await profiles.create({
    accountId: id, didMethod, privateKmsBaseUrl, publicKmsBaseUrl});
  const profileAgentRecord = await profileAgents.getByProfile(
    {profileId, accountId: id, includeSecrets: true});
  const {profileAgent} = profileAgentRecord;
  const {agentSigner, profileSigner} = await getSigners({profileAgentRecord});
  const keystoreAgent = await getProfileKeystoreAgent({profileSigner});
  const {edvId, hmac, keyAgreementKey} = await createProfileEdv({
    profileId,
    referenceId: profileAgentEdvDocument,
    keystoreAgent
  });
  const credentialEdv = await createProfileEdv({
    profileId,
    referenceId: credentialsEdv,
    keystoreAgent
  });
  const credentialZcaps = await delegateEdvZcaps({
    documentsUrl: `${credentialEdv.edvId}/documents`,
    capability: `${credentialEdv.edvId}/zcaps/documents`,
    hmac: credentialEdv.hmac,
    edvClient: {id: edvId},
    keyAgreementKey: credentialEdv.keyAgreementKey,
    controller: profileAgent.id,
    signer: agentSigner,
    prefix: 'credential'
  });
  const {key: issuerKey, kmsClient, publicAlias} = await createIssuerKey(
    {profileSigner, type: 'Ed25519VerificationKey2020'});
  const issuerKeyRequest = {
    referenceId: 'key-assertionMethod',
    revocationReferenceId: 'key-assertionMethod-revocations',
    allowedAction: 'sign',
    controller: profileId,
    parentCapability: issuerKey.id,
    invocationTarget: {
      id: issuerKey.id,
      type: issuerKey.type,
      publicAlias,
    }
  };
  const profileZcaps = {
    'key-assertionMethod': await delegateCapability({
      signer: profileSigner,
      request: issuerKeyRequest,
      kmsClient})
  };
  const profileContent = {
    name: 'test-user',
    type: ['User', 'Person'],
    zcaps: {...profileZcaps, ...credentialZcaps}
  };
  const result = await initializeAccessManagement({
    edvId,
    profileId,
    profileContent,
    hmac,
    keyAgreementKey,
    invocationSigner: profileSigner,
    profileAgentRecord
  });
  result.profile.account = id;
  const integration = await createUser({
    token,
    hmac,
    keyAgreementKey,
    profileZcaps,
    credentialEdv,
    issuerKey,
    edvId,
    publicKmsBaseUrl,
    privateKmsBaseUrl,
    publicAlias,
    invocationSigner: profileSigner,
    ...result
  });
  return {instance: {id: profileId}, integration};
}
async function insertIssuerAgent ( { id , token , didMethod , privateKmsBaseUrl , publicKmsBaseUrl } ) { const { id : profileId } = await profiles . create ( { accountId : id , didMethod , privateKmsBaseUrl , publicKmsBaseUrl } ) ; const profileAgentRecord = await profileAgents . getByProfile ( { profileId , accountId : id , includeSecrets : true } ) ; const { profileAgent } = profileAgentRecord ; const { agentSigner , profileSigner } = await getSigners ( { profileAgentRecord } ) ; const keystoreAgent = await getProfileKeystoreAgent ( { profileSigner } ) ; const { edvId , hmac , keyAgreementKey } = await createProfileEdv ( { profileId , referenceId : profileAgentEdvDocument , keystoreAgent } ) ; const credentialEdv = await createProfileEdv ( { profileId , referenceId : credentialsEdv , keystoreAgent } ) ; const credentialZcaps = await delegateEdvZcaps ( { documentsUrl : ` ${ credentialEdv . edvId } ` , capability : ` ${ credentialEdv . edvId } ` , hmac : credentialEdv . hmac , edvClient : { id : edvId } , keyAgreementKey : credentialEdv . keyAgreementKey , controller : profileAgent . id , signer : agentSigner , prefix : 'credential' } ) ; const { key : issuerKey , kmsClient , publicAlias } = await createIssuerKey ( { profileSigner , type : 'Ed25519VerificationKey2020' } ) ; const issuerKeyRequest = { referenceId : 'key-assertionMethod' , revocationReferenceId : 'key-assertionMethod-revocations' , allowedAction : 'sign' , controller : profileId , parentCapability : issuerKey . id , invocationTarget : { id : issuerKey . id , type : issuerKey . type , publicAlias , } } ; const profileZcaps = { 'key-assertionMethod' : await delegateCapability ( { signer : profileSigner , request : issuerKeyRequest , kmsClient } ) } ; const profileContent = { name : 'test-user' , type : [ 'User' , 'Person' ] , zcaps : { ... profileZcaps , ... credentialZcaps } } ; const result = await initializeAccessManagement ( { edvId , profileId , profileContent , hmac , keyAgreementKey , invocationSigner : profileSigner , profileAgentRecord } ) ; result . profile . account = id ; const integration = await createUser ( { token , hmac , keyAgreementKey , profileZcaps , credentialEdv , issuerKey , edvId , publicKmsBaseUrl , privateKmsBaseUrl , publicAlias , invocationSigner : profileSigner , ... result } ) ; return { instance : { id : profileId } , integration } ; }
tests call on this to insert an issuerAgent
tests call on this to insert an issuerAgent
// this is the profile associated with an issuer account // we will need this to delegate and invoke // the profile signer is authorized to sign with the profileAgent's key? // creates an edv for the profile-agent-edv-document // this is the userProfileEdv usually created in the wallet. // string should match KMS ops // this is the key used to actually issue a credential // this is the profileAgent created for an issuer instance integration // it is used to issue a credential.