import { tx , wallet } from "@cityofzion/neon-core" ; import { checkProperty } from "./common" ; import { ManagedApiBasicConfig } from "./types" ; function addSignature ( transaction , signature ) { transaction . scripts . push ( tx . Witness . deserialize ( signature ) ) ; } param config return export async function signTx < T extends ManagedApiBasicConfig < tx . BaseTransaction > > ( config ) { checkProperty ( config , "signingFunction" , "tx" ) ; const signatures = await config . signingFunction ! ( config . tx ! . serialize ( false ) , config . account ! . publicKey ) ; if ( signatures instanceof Array ) { signatures . forEach ( ( sig ) => { addSignature ( config . tx ! , sig ) ; } ) ; } else { addSignature ( config . tx ! , signatures ) ; } return config ; } export function signWithPrivateKey ( privateKey ) { const pubKey = new wallet . Account ( privateKey ) . publicKey ; return async ( txString , publicKey ? ) => { const sig = wallet . sign ( txString , privateKey ) ; const witness = tx . Witness . fromSignature ( sig , publicKey || pubKey ) ; return witness . serialize ( ) ; } ; }