test/mocha/helpers.js
// this is supposed to emulate accessManager's createUser function
this is supposed to emulate accessManager's createUser function
this is supposed to emulate accessManager ' s createUser function
async function createUser({
  token,
  profile,
  recipients,
  client,
  keyAgreementKey,
  hmac,
  profileZcaps,
  invocationSigner,
  credentialEdv,
  issuerKey,
  publicAlias,
  edvId,
  privateKmsBaseUrl,
  publicKmsBaseUrl
}) {
  const integration = await profileAgents.create(
    {profileId: profile.id, token, privateKmsBaseUrl, publicKmsBaseUrl});
  const {profileAgent: issuerAgent} = integration;
  const credentialIssuerZcaps = await delegateEdvZcaps({
    documentsUrl: `${credentialEdv.edvId}/documents`,
    capability: `${credentialEdv.edvId}/zcaps/documents`,
    hmac: credentialEdv.hmac,
    edvClient: credentialEdv.edvClient,
    keyAgreementKey: credentialEdv.keyAgreementKey,
    controller: issuerAgent.id,
    signer: invocationSigner,
    prefix: 'credential'
  });
  const assertionKeyRequest = {
    '@context': ZCAP_CONTEXT_URL,
    id: `urn:zcap:${await edvHelpers.generateRandom()}`,
    referenceId: 'key-assertionMethod',
    allowedAction: 'sign',
    controller: issuerAgent.id,
    parentCapability: profileZcaps['key-assertionMethod'].id,
    invocationTarget: {
      id: issuerKey.id,
      type: issuerKey.type,
      publicAlias
    }
  };
  const issuerZcaps = {
    'key-assertionMethod': await delegate({
      signer: invocationSigner,
      zcap: assertionKeyRequest,
      capabilityChain: [issuerKey.id, profileZcaps['key-assertionMethod']]
    })
  };
  const capability = `${edvId}/zcaps/documents`;
  const documentsUrl = `${edvId}/documents`;
  const issuerContent = {
    name: 'test-issuer',
    type: ['User', 'Person'],
    zcaps: {...credentialIssuerZcaps, ...issuerZcaps}
  };
  const issuerDocId = await edvHelpers.generateRandom();
  const issuerDoc = new EdvDocument({
    id: issuerDocId,
    recipients,
    keyResolver,
    keyAgreementKey,
    hmac,
    capability,
    invocationSigner,
    client
  });
  const issuerDocument = {
    name: 'root',
    ...issuerContent,
    id: issuerAgent.id,
    type: ['Application'],
    zcaps: {...issuerAgent.zcaps, ...issuerContent.zcaps},
    authorizedDate: (new Date()).toISOString()
  };
  await issuerDoc.write({
    doc: {
      id: issuerDocId,
      content: issuerDocument
    }
  });
  const issuerCaps = await delegateAgentRecordZcaps({
    profileAgentId: issuerAgent.id,
    edvParentCapability: capability,
    client,
    docId: issuerDocId,
    keyAgreementKey,
    documentsUrl,
    invocationSigner
  });
  issuerAgent.sequence++;
  issuerAgent.zcaps = {...issuerAgent.zcaps, ...issuerCaps};
  await profileAgents.update({profileAgent: issuerAgent});
  return integration;
}
async function createUser ( { token , profile , recipients , client , keyAgreementKey , hmac , profileZcaps , invocationSigner , credentialEdv , issuerKey , publicAlias , edvId , privateKmsBaseUrl , publicKmsBaseUrl } ) { const integration = await profileAgents . create ( { profileId : profile . id , token , privateKmsBaseUrl , publicKmsBaseUrl } ) ; const { profileAgent : issuerAgent } = integration ; const credentialIssuerZcaps = await delegateEdvZcaps ( { documentsUrl : ` ${ credentialEdv . edvId } ` , capability : ` ${ credentialEdv . edvId } ` , hmac : credentialEdv . hmac , edvClient : credentialEdv . edvClient , keyAgreementKey : credentialEdv . keyAgreementKey , controller : issuerAgent . id , signer : invocationSigner , prefix : 'credential' } ) ; const assertionKeyRequest = { '@context' : ZCAP_CONTEXT_URL , id : ` ${ await edvHelpers . generateRandom ( ) } ` , referenceId : 'key-assertionMethod' , allowedAction : 'sign' , controller : issuerAgent . id , parentCapability : profileZcaps [ 'key-assertionMethod' ] . id , invocationTarget : { id : issuerKey . id , type : issuerKey . type , publicAlias } } ; const issuerZcaps = { 'key-assertionMethod' : await delegate ( { signer : invocationSigner , zcap : assertionKeyRequest , capabilityChain : [ issuerKey . id , profileZcaps [ 'key-assertionMethod' ] ] } ) } ; const capability = ` ${ edvId } ` ; const documentsUrl = ` ${ edvId } ` ; const issuerContent = { name : 'test-issuer' , type : [ 'User' , 'Person' ] , zcaps : { ... credentialIssuerZcaps , ... issuerZcaps } } ; const issuerDocId = await edvHelpers . generateRandom ( ) ; const issuerDoc = new EdvDocument ( { id : issuerDocId , recipients , keyResolver , keyAgreementKey , hmac , capability , invocationSigner , client } ) ; const issuerDocument = { name : 'root' , ... issuerContent , id : issuerAgent . id , type : [ 'Application' ] , zcaps : { ... issuerAgent . zcaps , ... issuerContent . zcaps } , authorizedDate : ( new Date ( ) ) . toISOString ( ) } ; await issuerDoc . write ( { doc : { id : issuerDocId , content : issuerDocument } } ) ; const issuerCaps = await delegateAgentRecordZcaps ( { profileAgentId : issuerAgent . id , edvParentCapability : capability , client , docId : issuerDocId , keyAgreementKey , documentsUrl , invocationSigner } ) ; issuerAgent . sequence ++ ; issuerAgent . zcaps = { ... issuerAgent . zcaps , ... issuerCaps } ; await profileAgents . update ( { profileAgent : issuerAgent } ) ; return integration ; }
this is supposed to emulate accessManager's createUser function
this is supposed to emulate accessManager ' s createUser function
// delegate the credential zcaps to the issuer // string should match KMS ops // this is the key used to actually issue a credential // FIXME what is the type of the issuerContent? // create a new document in the parent profile's user edv. // delegate access to the integration // puts all the keys it needs into the userDocument // remember to add a user Kak