import { Root } from 'protobufjs/light' ; import { encode as encodeProtobuf } from './protobuf' ; import { encode as encodeProtocol } from './protocol' ; import { createMessageFromName } from './protobuf/messages' ; async function sendBuffers ( sender , buffers ) { for ( const buffer of buffers ) { await sender ( buffer ) ; } } export function buildOne ( messages , name , data ) { const { Message , messageType } = createMessageFromName ( messages , name ) ; const buffer = encodeProtobuf ( Message , data ) ; return encodeProtocol ( buffer , { addTrezorHeaders : false , chunked : false , messageType , } ) ; } export const buildBuffers = ( messages , name , data ) => { const { Message , messageType } = createMessageFromName ( messages , name ) ; const buffer = encodeProtobuf ( Message , data ) ; return encodeProtocol ( buffer , { addTrezorHeaders : true , chunked : true , messageType , } ) ; } ; export async function buildAndSend ( messages , sender , name , data ) { const buffers = buildBuffers ( messages , name , data ) ; return sendBuffers ( sender , buffers ) ; }