UNPKG

@gleif-it/did-webs-ts

Version:
20 lines (19 loc) 806 B
import { createAid } from '../../core/Aid.js'; import { getKeyState } from './getKeyState.js'; import { sortKeyEventStream } from './sortKeyEventStream.js'; export const getController = (parsed) => { const controllerEvent = parsed[0]; if (controllerEvent.t !== 'icp') { throw new Error("Starting event is not an 'icp' event"); } // AID is the 'i' field of the 'icp' event const controllerAID = createAid(controllerEvent.i); // now look up the key state of the controller AID const keyState = getKeyState(controllerAID, sortKeyEventStream(parsed)); // check if the key state is null if (keyState === null) { throw new Error(`Key state for ${controllerAID} not found`); } // return the key state as an IdentifierAndKeyState return keyState; };