import { Column , Entity } from 'typeorm' ; import { Base } from '../Base/NoSqlBase' ; import { VaultBindingModel } from './VaultBindingModel' ; @ Entity ( ) export class Vault extends Base { @ Column ( ) edvId ? : string ; @ Column ( ) referenceId ? : string ; @ Column ( ) sequence ? : number ; @ Column ( ) controller ? : string ; @ Column ( ) keyAgreementKey ? : { id : string ; type : string ; } ; @ Column ( ) hmac ? : { id : string ; type : string ; } ; static getReferenceKey ( controller , referenceId ) { return `${ encodeURIComponent ( controller ) }:${ encodeURIComponent ( referenceId ) }` ; } static fromBindingModel ( bindingModel ) { const entity = new Vault ( ) ; Object . keys ( bindingModel ) . forEach ( ( k ) => { entity [ k ] = ( bindingModel as any ) [ k ] ; } ) ; return entity ; } public toExternal ( baseUrl = 'http://localhost:9876/edvs' ) { const config = { id : `${ baseUrl }/${ this . id }` , sequence : this . sequence , controller : this . controller , keyAgreementKey : this . keyAgreementKey , hmac : this . hmac } ; if ( this . referenceId ) { config . referenceId = this . referenceId ; } return config ; } public toFs ( baseUrl = '/edvs' ) { const config = { id : `${ baseUrl }/${ this . id }` , sequence : this . sequence , controller : this . controller , keyAgreementKey : this . keyAgreementKey , hmac : this . hmac } ; if ( this . referenceId ) { config . referenceId = this . referenceId ; } return JSON . stringify ( config , null , 2 ) ; } }