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:
- Client -> Server: ReceiveMessagesRequest(init = InitReceive{...})
- Server -> Client: ReceiveMessagesResponse(challenge = Challenge{...})
- Client -> Server: ReceiveMessagesRequest(auth_sig = AuthSignature{...})
- Server -> Client: [Stream of ReceiveMessagesResponse( message = MailboxMessage{...} )]
- 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 Method | Path |
|---|---|
| POST | /v1/taproot-assets/mailbox/receive |
Code Samples
gRPC
const fs = require('fs');
const grpc = require('@grpc/grpc-js');
const protoLoader = require('@grpc/proto-loader');
const GRPC_HOST = 'localhost:10029'
const MACAROON_PATH = 'TAPD_DIR/data/regtest/admin.macaroon'
const TLS_PATH = 'TAPD_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) {
console.log(response);
});
call.on('status', function(status) {
});
call.on('end', function() {
});
call.write(request);
Python
import codecs, grpc, os
import mailbox_pb2 as authmailboxrpc, mailbox_pb2_grpc as mailboxstub
GRPC_HOST = 'localhost:10029'
MACAROON_PATH = 'TAPD_DIR/data/regtest/admin.macaroon'
TLS_PATH = 'TAPD_DIR/tls.cert'
macaroon = codecs.encode(open(MACAROON_PATH, 'rb').read(), 'hex')
def metadata_callback(context, callback):
callback([('macaroon', macaroon)], None)
auth_creds = grpc.metadata_call_credentials(metadata_callback)
os.environ['GRPC_SSL_CIPHER_SUITES'] = 'HIGH+ECDSA'
cert = open(TLS_PATH, 'rb').read()
ssl_creds = grpc.ssl_channel_credentials(cert)
combined_creds = grpc.composite_channel_credentials(ssl_creds, auth_creds)
channel = grpc.secure_channel(GRPC_HOST, combined_creds)
stub = mailboxstub.MailboxStub(channel)
def request_generator():
while True:
request = authmailboxrpc.ReceiveMessagesRequest(
init=<InitReceive>,
auth_sig=<AuthSignature>,
)
yield request
request_iterable = request_generator()
for response in stub.ReceiveMessages(request_iterable):
print(response)
curl
# Client streaming or bidirectional streaming RPCs are not easily supported by grpcurl. Please use a programming language client for this RPC.
Messages
authmailboxrpc.ReceiveMessagesRequest
| Field | gRPC Type | REST Type | REST Placement |
|---|---|---|---|
init The initial parameters sent by the client to start receiving messages. |
InitReceive |
object |
body |
auth_sig The client's signature in response to the server's challenge. |
AuthSignature |
object |
body |
authmailboxrpc.ReceiveMessagesResponse
| Field | gRPC Type | REST Type |
|---|---|---|
challenge The challenge sent by the server to the client, which the client must sign to prove ownership of the receiver's public key. |
Challenge |
object |
auth_success A successful authentication response, indicating the client has successfully signed the challenge and is now authenticated to receive messages. |
bool |
boolean |
messages A list of mailbox messages sent to the client. |
MailboxMessages |
object |
eos An EndOfStream message indicating that the server is shutting down. |
EndOfStream |
object |
Nested Messages
authmailboxrpc.AuthSignature
| Field | gRPC Type | REST Type |
|---|---|---|
signature The client's Schnorr signature over the challenge hash provided by the server. |
bytes |
string |
authmailboxrpc.Challenge
| Field | gRPC Type | REST Type |
|---|---|---|
challenge_hash The challenge hash that the client must sign to prove ownership of the receiver's public key. |
bytes |
string |
authmailboxrpc.EndOfStream
note
This response has no parameters.
authmailboxrpc.InitReceive
| Field | gRPC Type | REST Type |
|---|---|---|
receiver_id The public key identifier of the receiver of the messages. |
bytes |
string |
start_message_id_exclusive The exclusive start message ID. |
uint64 |
string |
start_block_height_inclusive The inclusive start block height. |
uint32 |
integer |
start_timestamp_exclusive The exclusive start timestamp. |
int64 |
string |
authmailboxrpc.MailboxMessage
| Field | gRPC Type | REST Type |
|---|---|---|
message_id The unique ID assigned to the message by the server. |
uint64 |
string |
encrypted_payload The ECIES encrypted message payload, intended for the receiver. |
bytes |
string |
arrival_timestamp Timestamp when the message arrived at the server. |
int64 |
string |
authmailboxrpc.MailboxMessages
| Field | gRPC Type | REST Type |
|---|---|---|
messages The list of mailbox messages. |
MailboxMessage[] |
array |