import { MongoDb } from '@sidetree/db' ; import { methods } from '@sidetree/wallet' ; import { ICas , PublicKeyPurpose , Encoder } from '@sidetree/common' ; import QLDBLedger from '@sidetree/qldb' ; import { S3Cas } from '@sidetree/cas-s3' ; import Photon from '../Photon' ; import config from './photon-config.json' ; export const resetDatabase = async ( ) : Promise < void > => { await MongoDb . resetDatabase ( config . mongoDbConnectionString , config . databaseName ! ) ; } ; export const getTestLedger = async ( ) : Promise < QLDBLedger > => { const ledger = new QLDBLedger ( config . qldbLedger , config . qldbLedgerTable ) ; await ledger . reset ( ) ; return ledger ; } ; export const getTestCas = ( ) : ICas => { const cas = new S3Cas ( config . s3BucketName ) ; return cas ; } ; export const getTestPhoton = async ( ) : Promise < Photon > => { await resetDatabase ( ) ; const ledger = await getTestLedger ( ) ; const cas = await getTestCas ( ) ; const photon = new Photon ( config , config . versions , ledger , cas ) ; await photon . initialize ( false , false ) ; return photon ; } ; export const replaceMethod = ( result , defaultMethod = 'did:elem' , specificMethod = 'did:photon' ) : JSON => { const stringified = JSON . stringify ( result ) ; const updatedStringified = stringified . replace ( new RegExp ( defaultMethod , 'g' ) , specificMethod ) ; const updateResult = JSON . parse ( updatedStringified ) ; return updateResult ; } ; export const generateCreateOperation = async ( publicKey ) : Promise < any > => { const documentModel = { public_keys : [ { id : Encoder . encode ( Math . random ( ) . toString ( ) ) , type : 'JsonWebKey2020' , jwk : publicKey , purpose : [ PublicKeyPurpose . General ] } , ] } ; const createOperation = await methods . getCreatePayloadFromDocumentModel ( documentModel , publicKey , publicKey ) ; return createOperation ; } ;