function assertSupportedModelController(model: Model, ceramic: CeramicApi): void {
const unsupported = `Unsupported model controller ${model.metadata.controller}`
if (model.metadata.controller.startsWith('did:pkh:')){
if (ceramic.context.did == null) {
throw new Error(
`${unsupported}, did missing from ceramic context`
)
}
if (!ceramic.context.did.hasCapability()) {
throw new Error(
`${unsupported}, only did:pkh with CACAO is supported`
)
}
const cacao: Cacao = ceramic.context.did.capability();
if (cacao.p.exp == null) {
throw new Error(
`${unsupported}, only did:pkh CACAO without expiry is supported`
)
}
const hasModelResource = cacao.p.resources?.includes(`ceramic://${MODEL_STREAM_ID}`)
if (cacao.p.resources?.length != 1 || !hasModelResource) {
throw new Error(
`${unsupported}, only cacao with resource ${MODEL_STREAM_ID} is supported`
)
}
} else if (!model.metadata.controller.startsWith('did:key:')) {
throw new Error(
`${unsupported}, only did:key is supported`
)
}
}
the resource needs to be ceramic://*?model=kh4q0ozorrgaq2mezktnrmdwleo1d, we sometimes refer to this as the āmeta modelā
If we are about to create a new model, checking that the model is created ceramic.did with the correct CACAO is sufficient (e.g. here)
If we are just validating the validity of a Model, checking that the ceramic.did isnāt really necessary as we are just loading that model and we donāt need to be authenticated with a DID with an appropriate DID just for loading it. Instead we should validate that the signed commits that are being applied have the appropriate CACAO (e.g. here, and here)