Skip to main content

ReceiveMessages

Initiates a bidirectional stream to receive messages for a specific receiver. This stream implements the challenge-response handshake required for receiver authentication before messages are delivered.

Expected flow:

  1. Client -> Server: ReceiveMessagesRequest(init = InitReceive{...})
  2. Server -> Client: ReceiveMessagesResponse(challenge = Challenge{...})
  3. Client -> Server: ReceiveMessagesRequest(auth_sig = AuthSignature{...})
  4. Server -> Client: [Stream of ReceiveMessagesResponse( message = MailboxMessage{...} )]
  5. Server -> Client: ReceiveMessagesResponse(eos = EndOfStream{})

Source: authmailboxrpc/mailbox.proto

gRPC

info

This is a bidirectional-streaming RPC

rpc ReceiveMessages (stream ReceiveMessagesRequest) returns (stream ReceiveMessagesResponse);

REST

HTTP MethodPath
POST /v1/taproot-assets/mailbox/receive

Code Samples

const fs = require('fs');
const grpc = require('@grpc/grpc-js');
const protoLoader = require('@grpc/proto-loader');

const GRPC_HOST = 'localhost:10029'
const MACAROON_PATH = 'TAPROOT-ASSETS_DIR/regtest/taproot-assets.macaroon'
const TLS_PATH = 'TAPROOT-ASSETS_DIR/tls.cert'

const loaderOptions = {
keepCase: true,
longs: String,
enums: String,
defaults: true,
oneofs: true,
};
const packageDefinition = protoLoader.loadSync('authmailboxrpc/mailbox.proto', loaderOptions);
const authmailboxrpc = grpc.loadPackageDefinition(packageDefinition).authmailboxrpc;
process.env.GRPC_SSL_CIPHER_SUITES = 'HIGH+ECDSA';
const tlsCert = fs.readFileSync(TLS_PATH);
const sslCreds = grpc.credentials.createSsl(tlsCert);
const macaroon = fs.readFileSync(MACAROON_PATH).toString('hex');
const macaroonCreds = grpc.credentials.createFromMetadataGenerator(function(args, callback) {
let metadata = new grpc.Metadata();
metadata.add('macaroon', macaroon);
callback(null, metadata);
});
let creds = grpc.credentials.combineChannelCredentials(sslCreds, macaroonCreds);
let client = new authmailboxrpc.Mailbox(GRPC_HOST, creds);
let request = {
init: <InitReceive>,
auth_sig: <AuthSignature>,
};
let call = client.receiveMessages({});
call.on('data', function(response) {
// A response was received from the server.
console.log(response);
});
call.on('status', function(status) {
// The current status of the stream.
});
call.on('end', function() {
// The server has closed the stream.
});
call.write(request);
// Console output:
// {
// "challenge": <Challenge>,
// "auth_success": <bool>,
// "messages": <MailboxMessages>,
// "eos": <EndOfStream>,
// }

Messages

authmailboxrpc.ReceiveMessagesRequest

Source: authmailboxrpc/mailbox.proto

FieldgRPC TypeREST TypeREST Placement
init
InitReceiveobjectbody
auth_sig
AuthSignatureobjectbody

authmailboxrpc.ReceiveMessagesResponse

Source: authmailboxrpc/mailbox.proto

FieldgRPC TypeREST Type
challenge
Challengeobject
auth_success
boolboolean
messages
MailboxMessagesobject
eos
EndOfStreamobject

Nested Messages

authmailboxrpc.AuthSignature

FieldgRPC TypeREST Type
signature
bytesstring

authmailboxrpc.Challenge

FieldgRPC TypeREST Type
challenge_hash
bytesstring

authmailboxrpc.EndOfStream

note

This response has no parameters.

authmailboxrpc.InitReceive

FieldgRPC TypeREST Type
receiver_id
bytesstring
start_message_id_exclusive
uint64string
start_block_height_inclusive
uint32integer
start_timestamp_exclusive
int64string

authmailboxrpc.MailboxMessage

FieldgRPC TypeREST Type
message_id
uint64string
encrypted_payload
bytesstring
arrival_timestamp
int64string
expiry_block_height
uint32integer

authmailboxrpc.MailboxMessages

FieldgRPC TypeREST Type
messages
MailboxMessage[]array