OpenMined / PSI

Private Set Intersection Cardinality protocol based on ECDH and Bloom Filters

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

In a react-native app, how to read back data from server (node.js) when using fetch api

seyaobey-dev opened this issue · comments

Question

In a react-native app, how to read back data from server (node.js) when using fetch api.

Further Information

I have a react-native app sending contacts phone numbers to server for processing as described in the javascript readme document. Upon receiving data back, the call client.getIntersectionSize throws error:

BindingError: _emval_take_value has unknown type N4absl11string_viewE

I suspect this is due to the way I'm reading data back from server. Here are relevant excerpts from source code:

1. client sends serialized request:

...
const psi = await PSI();
const client = psi.client!.createWithNewKey(true);
...
const serializedClientRequest = request.serializeBinary();
const res = await fetch('__server_address__', {
   method: 'POST',
   body: serializedClientRequest,
});

2. server receives, processes then sends response back:

...
const psi = await PSI();
const server = psi.server!.createWithNewKey(true);
...
const serverResponse = server.processRequest(deserializedClientRequest);
const serializedServerResponse = serverResponse.serializeBinary();
const serializedServerSetup = serverSetup.serializeBinary();

// sends this json back. Is this correct?
return {
  serializedServerResponse,
  serializedServerSetup
};

3. clients receives data and attempts to get intersection size:

...
const psi = await PSI();
const client = psi.client!.createWithNewKey(true);
...
const res = await fetch('__server_address__', {
   method: 'POST',
   body: serializedClientRequest,
});
const response = await res.json();

// I must convert data received from server into Uint8Array otherwise below lines throw exception
const deserializedServerResponse = psi.response.deserializeBinary(new Uint8Array(response.serializedServerResponse));
const deserializedServerSetup = psi.serverSetup.deserializeBinary(new Uint8Array(response.serializedServerSetup));

// this line fails with error in title
const intersectionSize = client.getIntersectionSize(deserializedServerSetup, deserializedServerResponse);

Is the above code the correct way to process data received from server before attempting to retrieve intersection size"? This part is not very explicit in the javascript readme document. I have tried with the axios library then the fetch api, not sure if it makes any difference.

You help will be very appreciated as we would like to strictly adhere to best practices when it comes to mobile contacts discovery.

System Information

 - OS: IOS 15.1
 - react-native: 0.64.3
 - expo: 44
 - node: v14.18.1
 - npm: 8.3.0