fix: format

This commit is contained in:
Richard Ramos 2023-01-03 13:49:46 -04:00 committed by RichΛrd
parent 3ab9bb046b
commit 3c2371252d
1 changed files with 333 additions and 161 deletions

View File

@ -1,5 +1,5 @@
import { NativeModules, Platform, NativeEventEmitter } from 'react-native';
import {decode, encode} from 'base-64'
import { decode, encode } from 'base-64';
const LINKING_ERROR =
`The package '@waku/react-native' doesn't seem to be linked. Make sure: \n\n` +
@ -7,7 +7,9 @@ const LINKING_ERROR =
'- You rebuilt the app after installing the package\n' +
'- You are not using Expo managed workflow\n';
const ReactNative = NativeModules.ReactNative ? NativeModules.ReactNative : new Proxy(
const ReactNative = NativeModules.ReactNative
? NativeModules.ReactNative
: new Proxy(
{},
{
get() {
@ -24,7 +26,7 @@ const OneMillion = BigInt(1_000_000);
export class WakuMessage {
payload: Uint8Array = new Uint8Array();
contentTopic: String | null = "";
contentTopic: String | null = '';
version: Number | null = 0;
timestamp?: Date = undefined;
@ -33,9 +35,11 @@ export class WakuMessage {
return {
contentTopic: this.contentTopic,
version: this.version,
timestamp: this.timestamp ? (BigInt(this.timestamp.valueOf()) * OneMillion).toString(10) : 0,
payload: b64encoded
}
timestamp: this.timestamp
? (BigInt(this.timestamp.valueOf()) * OneMillion).toString(10)
: 0,
payload: b64encoded,
};
}
}
@ -46,27 +50,31 @@ var eventEmitter = new NativeEventEmitter(NativeModules.ReactNative);
* @param cb callback to be eecuted
*/
export function onMessage(cb: (arg0: any) => void) {
eventEmitter.addListener("message", event => {
eventEmitter.addListener('message', (event) => {
let signal = JSON.parse(event.signal);
let msg = signal.event.wakuMessage;
signal.event.wakuMessage = new WakuMessage();
signal.event.wakuMessage.timestamp = msg.timestamp;
signal.event.wakuMessage.version = msg.version || 0;
signal.event.wakuMessage.contentTopic = msg.contentTopic;
signal.event.wakuMessage.payload = new Uint8Array(decode(msg.payload ?? []).split("").map((c:any) => c.charCodeAt(0)));
signal.event.wakuMessage.payload = new Uint8Array(
decode(msg.payload ?? [])
.split('')
.map((c: any) => c.charCodeAt(0))
);
cb(signal.event);
})
});
}
export class Config {
host: String | null = null
port: Number | null = null
advertiseAddr: String | null = null
nodeKey: String | null = null
keepAliveInterval: Number | null = null
relay: Boolean | null = null
filter: Boolean | null = null
minPeersToPublish: Number | null = null
host: String | null = null;
port: Number | null = null;
advertiseAddr: String | null = null;
nodeKey: String | null = null;
keepAliveInterval: Number | null = null;
relay: Boolean | null = null;
filter: Boolean | null = null;
minPeersToPublish: Number | null = null;
}
/**
@ -75,7 +83,9 @@ export class Config {
*/
export function newNode(config: Config | null): Promise<void> {
return new Promise<void>(async (resolve, reject) => {
let response = JSON.parse(await ReactNative.newNode(config ? JSON.stringify(config) : ""));
let response = JSON.parse(
await ReactNative.newNode(config ? JSON.stringify(config) : '')
);
if (response.error) {
reject(response.error);
} else {
@ -149,10 +159,16 @@ export function peerID(): Promise<string> {
* @param timeoutMs Timeout value in milliseconds to execute the call. If the function takes longer than this value, the execution will be canceled and an error returned
* @returns string containing the message id
*/
export function relayPublish(msg: WakuMessage, pubsubTopic: String = "", timeoutMs: Number = 0): Promise<string> {
export function relayPublish(
msg: WakuMessage,
pubsubTopic: String = '',
timeoutMs: Number = 0
): Promise<string> {
return new Promise<string>(async (resolve, reject) => {
let messageJSON = JSON.stringify(msg)
let response = JSON.parse(await ReactNative.relayPublish(messageJSON, pubsubTopic, timeoutMs));
let messageJSON = JSON.stringify(msg);
let response = JSON.parse(
await ReactNative.relayPublish(messageJSON, pubsubTopic, timeoutMs)
);
if (response.error) {
reject(response.error);
} else {
@ -170,10 +186,24 @@ export function relayPublish(msg: WakuMessage, pubsubTopic: String = "", timeout
* @param timeoutMs Timeout value in milliseconds to execute the call. If the function takes longer than this value, the execution will be canceled and an error returned
* @returns string containing the message id
*/
export function relayPublishEncodeAsymmetric(msg: WakuMessage, publicKey: String, optionalSigningKey: String = "", pubsubTopic: String = "", timeoutMs: Number = 0): Promise<string> {
export function relayPublishEncodeAsymmetric(
msg: WakuMessage,
publicKey: String,
optionalSigningKey: String = '',
pubsubTopic: String = '',
timeoutMs: Number = 0
): Promise<string> {
return new Promise<string>(async (resolve, reject) => {
let messageJSON = JSON.stringify(msg)
let response = JSON.parse(await ReactNative.relayPublishEncodeAsymmetric(messageJSON, pubsubTopic, publicKey, optionalSigningKey, timeoutMs));
let messageJSON = JSON.stringify(msg);
let response = JSON.parse(
await ReactNative.relayPublishEncodeAsymmetric(
messageJSON,
pubsubTopic,
publicKey,
optionalSigningKey,
timeoutMs
)
);
if (response.error) {
reject(response.error);
} else {
@ -191,10 +221,24 @@ export function relayPublishEncodeAsymmetric(msg: WakuMessage, publicKey: String
* @param timeoutMs Timeout value in milliseconds to execute the call. If the function takes longer than this value, the execution will be canceled and an error returned
* @returns string containing the message id
*/
export function relayPublishEncodeSymmetric(msg: WakuMessage, symmetricKey: String, optionalSigningKey: String = "", pubsubTopic: String = "", timeoutMs: Number = 0): Promise<string> {
export function relayPublishEncodeSymmetric(
msg: WakuMessage,
symmetricKey: String,
optionalSigningKey: String = '',
pubsubTopic: String = '',
timeoutMs: Number = 0
): Promise<string> {
return new Promise<string>(async (resolve, reject) => {
let messageJSON = JSON.stringify(msg)
let response = JSON.parse(await ReactNative.relayPublishEncodeAsymmetric(messageJSON, pubsubTopic, symmetricKey, optionalSigningKey, timeoutMs));
let messageJSON = JSON.stringify(msg);
let response = JSON.parse(
await ReactNative.relayPublishEncodeAsymmetric(
messageJSON,
pubsubTopic,
symmetricKey,
optionalSigningKey,
timeoutMs
)
);
if (response.error) {
reject(response.error);
} else {
@ -207,7 +251,7 @@ export function relayPublishEncodeSymmetric(msg: WakuMessage, symmetricKey: Stri
* Subscribe to a Waku Relay pubsub topic to receive messages.
* @param topic Pubsub topic to subscribe to.
*/
export function relaySubscribe(topic: String = ""): Promise<void> {
export function relaySubscribe(topic: String = ''): Promise<void> {
return new Promise<void>(async (resolve, reject) => {
let response = JSON.parse(await ReactNative.relaySubscribe(topic));
if (response.error) {
@ -247,9 +291,14 @@ export function listenAddresses(): Promise<Array<String>> {
* @param protocol protocol we expect the peer to support
* @returns peer ID as a base58 `string` of the peer that was added
*/
export function addPeer(multiAddress: String, protocol: String): Promise<String> {
export function addPeer(
multiAddress: String,
protocol: String
): Promise<String> {
return new Promise<string>(async (resolve, reject) => {
let response = JSON.parse(await ReactNative.addPeer(multiAddress, protocol));
let response = JSON.parse(
await ReactNative.addPeer(multiAddress, protocol)
);
if (response.error) {
reject(response.error);
} else {
@ -263,9 +312,14 @@ export function addPeer(multiAddress: String, protocol: String): Promise<String>
* @param multiAddress multiaddress to reach the peer being dialed
* @param timeoutMs Timeout value in milliseconds to execute the call. If the function takes longer than this value, the execution will be canceled and an error returned
*/
export function connect(multiAddress: String, timeoutMs: Number = 0): Promise<void> {
export function connect(
multiAddress: String,
timeoutMs: Number = 0
): Promise<void> {
return new Promise<void>(async (resolve, reject) => {
let response = JSON.parse(await ReactNative.connect(multiAddress, timeoutMs));
let response = JSON.parse(
await ReactNative.connect(multiAddress, timeoutMs)
);
if (response.error) {
reject(response.error);
} else {
@ -279,9 +333,14 @@ export function connect(multiAddress: String, timeoutMs: Number = 0): Promise<vo
* @param peerID Peer ID to dial. The peer must be already known. It must have been added before with `addPeer` or previously dialed with `connect`
* @param timeoutMs Timeout value in milliseconds to execute the call. If the function takes longer than this value, the execution will be canceled and an error returned
*/
export function connectPeerID(peerID: String, timeoutMs: Number = 0): Promise<void> {
export function connectPeerID(
peerID: String,
timeoutMs: Number = 0
): Promise<void> {
return new Promise<void>(async (resolve, reject) => {
let response = JSON.parse(await ReactNative.connectPeerID(peerID, timeoutMs));
let response = JSON.parse(
await ReactNative.connectPeerID(peerID, timeoutMs)
);
if (response.error) {
reject(response.error);
} else {
@ -323,8 +382,8 @@ export function peerCnt(): Promise<Number> {
export class DecodedPayload {
payload: Uint8Array = new Uint8Array();
padding: Uint8Array = new Uint8Array();
pubkey: String | null = "";
signature: String | null = "";
pubkey: String | null = '';
signature: String | null = '';
toJSON() {
const b64payload = encode(String.fromCharCode(...this.payload));
@ -334,7 +393,7 @@ export class DecodedPayload {
padding: b64padding,
pubkey: this.pubkey,
signature: this.signature,
}
};
}
}
@ -344,16 +403,29 @@ export class DecodedPayload {
* @param symmetricKey 32 byte symmetric key hex encoded
* @returns DecodedPayload
*/
export function decodeSymmetric(msg: WakuMessage, symmetricKey: String): Promise<DecodedPayload> {
export function decodeSymmetric(
msg: WakuMessage,
symmetricKey: String
): Promise<DecodedPayload> {
return new Promise<DecodedPayload>(async (resolve, reject) => {
let messageJSON = JSON.stringify(msg);
let response = JSON.parse(await ReactNative.decodeSymmetric(messageJSON, symmetricKey));
let response = JSON.parse(
await ReactNative.decodeSymmetric(messageJSON, symmetricKey)
);
if (response.error) {
reject(response.error);
} else {
let decodedPayload = new DecodedPayload();
decodedPayload.payload = new Uint8Array(atob(response.result.payload).split("").map(c => c.charCodeAt(0)));
decodedPayload.padding = new Uint8Array(atob(response.result.padding).split("").map(c => c.charCodeAt(0)));
decodedPayload.payload = new Uint8Array(
atob(response.result.payload)
.split('')
.map((c) => c.charCodeAt(0))
);
decodedPayload.padding = new Uint8Array(
atob(response.result.padding)
.split('')
.map((c) => c.charCodeAt(0))
);
decodedPayload.pubkey = response.result.pubkey;
decodedPayload.signature = response.result.signature;
resolve(decodedPayload);
@ -367,16 +439,29 @@ export function decodeSymmetric(msg: WakuMessage, symmetricKey: String): Promise
* @param privateKey secp256k1 private key hex encoded
* @returns DecodedPayload
*/
export function decodeAsymmetric(msg: WakuMessage, privateKey: String): Promise<DecodedPayload> {
export function decodeAsymmetric(
msg: WakuMessage,
privateKey: String
): Promise<DecodedPayload> {
return new Promise<DecodedPayload>(async (resolve, reject) => {
let messageJSON = JSON.stringify(msg);
let response = JSON.parse(await ReactNative.decodeSymmetric(messageJSON, privateKey));
let response = JSON.parse(
await ReactNative.decodeSymmetric(messageJSON, privateKey)
);
if (response.error) {
reject(response.error);
} else {
let decodedPayload = new DecodedPayload();
decodedPayload.payload = new Uint8Array(atob(response.result.payload).split("").map(c => c.charCodeAt(0)));
decodedPayload.padding = new Uint8Array(atob(response.result.padding).split("").map(c => c.charCodeAt(0)));
decodedPayload.payload = new Uint8Array(
atob(response.result.payload)
.split('')
.map((c) => c.charCodeAt(0))
);
decodedPayload.padding = new Uint8Array(
atob(response.result.padding)
.split('')
.map((c) => c.charCodeAt(0))
);
decodedPayload.pubkey = response.result.pubkey;
decodedPayload.signature = response.result.signature;
resolve(decodedPayload);
@ -389,7 +474,7 @@ export function decodeAsymmetric(msg: WakuMessage, privateKey: String): Promise<
* @param pubsubTopic Pubsub topic to verify. If not specified, it will verify the default pubsub topic
* @returns boolean indicates whether there are enough peers
*/
export function relayEnoughPeers(pubsubTopic: String = ""): Promise<Boolean> {
export function relayEnoughPeers(pubsubTopic: String = ''): Promise<Boolean> {
return new Promise<Boolean>(async (resolve, reject) => {
let response = JSON.parse(await ReactNative.relayEnoughPeers(pubsubTopic));
if (response.error) {
@ -404,7 +489,7 @@ export function relayEnoughPeers(pubsubTopic: String = ""): Promise<Boolean> {
* Closes the pubsub subscription to a pubsub topic. No more messages will be received from this pubsub topic.
* @param pubsubTopic
*/
export function relayUnsubscribe(pubsubTopic: String = ""): Promise<void> {
export function relayUnsubscribe(pubsubTopic: String = ''): Promise<void> {
return new Promise<void>(async (resolve, reject) => {
let response = JSON.parse(await ReactNative.relayUnsubscribe(pubsubTopic));
if (response.error) {
@ -423,10 +508,22 @@ export function relayUnsubscribe(pubsubTopic: String = ""): Promise<void> {
* @param timeoutMs Timeout value in milliseconds to execute the call. If the function takes longer than this value, the execution will be canceled and an error returned
* @returns the message ID
*/
export function lightpushPublish(msg: WakuMessage, pubsubTopic: String = "", peerID: String = "", timeoutMs: Number = 0): Promise<string> {
export function lightpushPublish(
msg: WakuMessage,
pubsubTopic: String = '',
peerID: String = '',
timeoutMs: Number = 0
): Promise<string> {
return new Promise<string>(async (resolve, reject) => {
let messageJSON = JSON.stringify(msg)
let response = JSON.parse(await ReactNative.lightpushPublish(messageJSON, pubsubTopic, peerID, timeoutMs));
let messageJSON = JSON.stringify(msg);
let response = JSON.parse(
await ReactNative.lightpushPublish(
messageJSON,
pubsubTopic,
peerID,
timeoutMs
)
);
if (response.error) {
reject(response.error);
} else {
@ -445,10 +542,26 @@ export function lightpushPublish(msg: WakuMessage, pubsubTopic: String = "", pee
* @param timeoutMs Timeout value in milliseconds to execute the call. If the function takes longer than this value, the execution will be canceled and an error returned
* @returns the message ID
*/
export function lightpushPublishEncAsymmetric(msg: WakuMessage, publicKey: String, optionalSigningKey: String = "", pubsubTopic: String = "", peerID: String = "", timeoutMs: Number = 0): Promise<string> {
export function lightpushPublishEncAsymmetric(
msg: WakuMessage,
publicKey: String,
optionalSigningKey: String = '',
pubsubTopic: String = '',
peerID: String = '',
timeoutMs: Number = 0
): Promise<string> {
return new Promise<string>(async (resolve, reject) => {
let messageJSON = JSON.stringify(msg)
let response = JSON.parse(await ReactNative.lightpushPublishEncodeAsymmetric(messageJSON, pubsubTopic, peerID, publicKey, optionalSigningKey, timeoutMs));
let messageJSON = JSON.stringify(msg);
let response = JSON.parse(
await ReactNative.lightpushPublishEncodeAsymmetric(
messageJSON,
pubsubTopic,
peerID,
publicKey,
optionalSigningKey,
timeoutMs
)
);
if (response.error) {
reject(response.error);
} else {
@ -467,10 +580,26 @@ export function lightpushPublishEncAsymmetric(msg: WakuMessage, publicKey: Strin
* @param timeoutMs Timeout value in milliseconds to execute the call. If the function takes longer than this value, the execution will be canceled and an error returned
* @returns the message ID
*/
export function lightpushPublishEncSymmetric(msg: WakuMessage, symmetricKey: String, optionalSigningKey: String = "", pubsubTopic: String = "", peerID: String = "", timeoutMs: Number = 0): Promise<string> {
export function lightpushPublishEncSymmetric(
msg: WakuMessage,
symmetricKey: String,
optionalSigningKey: String = '',
pubsubTopic: String = '',
peerID: String = '',
timeoutMs: Number = 0
): Promise<string> {
return new Promise<string>(async (resolve, reject) => {
let messageJSON = JSON.stringify(msg)
let response = JSON.parse(await ReactNative.lightpushPublishEncodeAsymmetric(messageJSON, pubsubTopic, peerID, symmetricKey, optionalSigningKey, timeoutMs));
let messageJSON = JSON.stringify(msg);
let response = JSON.parse(
await ReactNative.lightpushPublishEncodeAsymmetric(
messageJSON,
pubsubTopic,
peerID,
symmetricKey,
optionalSigningKey,
timeoutMs
)
);
if (response.error) {
reject(response.error);
} else {
@ -480,12 +609,17 @@ export function lightpushPublishEncSymmetric(msg: WakuMessage, symmetricKey: Str
}
export class Peer {
addrs: Array<String> = Array()
connected: Boolean = false
peerID: String = ""
protocols: Array<String> = Array()
addrs: Array<String> = Array();
connected: Boolean = false;
peerID: String = '';
protocols: Array<String> = Array();
constructor(addrs: Array<String>, connected: Boolean, peerID: String, protocols: Array<String>){
constructor(
addrs: Array<String>,
connected: Boolean,
peerID: String,
protocols: Array<String>
) {
this.addrs = addrs;
this.connected = connected;
this.peerID = peerID;
@ -503,50 +637,64 @@ export function peers(): Promise<Array<Peer>> {
if (response.error) {
reject(response.error);
} else {
resolve(response.result.map((x:any) => new Peer(x.addrs, x.connected, x.peerID, x.protocols)));
resolve(
response.result.map(
(x: any) => new Peer(x.addrs, x.connected, x.peerID, x.protocols)
)
);
}
})
});
}
export class Index {
digest: Uint8Array = new Uint8Array();
receiverTime: Number = 0
senderTime: Number = 0
pubsubTopic: String = ""
receiverTime: Number = 0;
senderTime: Number = 0;
pubsubTopic: String = '';
}
export class PagingOptions {
pageSize: Number = 0
cursor: Index | null = null
forward: Boolean = false
pageSize: Number = 0;
cursor: Index | null = null;
forward: Boolean = false;
constructor(pageSize: Number = 0, forward: Boolean = false, cursor: Index | null = null){
this.pageSize = pageSize
this.forward = forward
this.cursor = cursor
constructor(
pageSize: Number = 0,
forward: Boolean = false,
cursor: Index | null = null
) {
this.pageSize = pageSize;
this.forward = forward;
this.cursor = cursor;
}
}
export class ContentFilter {
contentTopic: String = ""
contentTopic: String = '';
constructor(contentTopic: String = "") {
this.contentTopic = contentTopic
constructor(contentTopic: String = '') {
this.contentTopic = contentTopic;
}
}
export class StoreQuery {
pubsubTopic: String | null = null
contentFilters: Array<ContentFilter> = Array()
startTime?: Date = undefined
endTime?: Date = undefined
pagingOptions: PagingOptions | null = null
pubsubTopic: String | null = null;
contentFilters: Array<ContentFilter> = Array();
startTime?: Date = undefined;
endTime?: Date = undefined;
pagingOptions: PagingOptions | null = null;
constructor(pubsubTopic: String | null = null, contentFilters: Array<ContentFilter> = Array(), startTime: Date | undefined = undefined, endTime: Date | undefined = undefined, pagingOptions: PagingOptions | null = null) {
this.pubsubTopic = pubsubTopic
this.contentFilters = contentFilters
this.startTime = startTime
this.endTime = endTime
this.pagingOptions = pagingOptions
constructor(
pubsubTopic: String | null = null,
contentFilters: Array<ContentFilter> = Array(),
startTime: Date | undefined = undefined,
endTime: Date | undefined = undefined,
pagingOptions: PagingOptions | null = null
) {
this.pubsubTopic = pubsubTopic;
this.contentFilters = contentFilters;
this.startTime = startTime;
this.endTime = endTime;
this.pagingOptions = pagingOptions;
}
}
@ -557,16 +705,26 @@ export class StoreQuery {
* @param timeoutMs Timeout value in milliseconds to execute the call. If the function takes longer than this value, the execution will be canceled and an error returned
* @returns
*/
export function storeQuery(query: StoreQuery, peerID: String = "", timeoutMs: Number = 0): Promise<any> {
export function storeQuery(
query: StoreQuery,
peerID: String = '',
timeoutMs: Number = 0
): Promise<any> {
return new Promise<string>(async (resolve, reject) => {
let queryJSON = JSON.stringify({
pubsubTopic: query.pubsubTopic,
contentFilters: query.contentFilters,
startTime: query.startTime ? (BigInt(query.startTime.valueOf()) * OneMillion).toString(10) : 0,
endTime: query.endTime ? (BigInt(query.endTime.valueOf()) * OneMillion).toString(10) : 0,
pagingOptions: query.pagingOptions
})
let response = JSON.parse(await ReactNative.storeQuery(queryJSON, peerID, timeoutMs));
startTime: query.startTime
? (BigInt(query.startTime.valueOf()) * OneMillion).toString(10)
: 0,
endTime: query.endTime
? (BigInt(query.endTime.valueOf()) * OneMillion).toString(10)
: 0,
pagingOptions: query.pagingOptions,
});
let response = JSON.parse(
await ReactNative.storeQuery(queryJSON, peerID, timeoutMs)
);
if (response.error) {
reject(response.error);
@ -577,12 +735,15 @@ export function storeQuery(query: StoreQuery, peerID: String = "", timeoutMs: Nu
}
export class FilterSubscription {
pubsubTopic: String | null = null
contentFilters: Array<ContentFilter> = Array()
pubsubTopic: String | null = null;
contentFilters: Array<ContentFilter> = Array();
constructor(pubsubTopic: String | null = null, contentFilters: Array<ContentFilter> = Array()) {
this.pubsubTopic = pubsubTopic
this.contentFilters = contentFilters
constructor(
pubsubTopic: String | null = null,
contentFilters: Array<ContentFilter> = Array()
) {
this.pubsubTopic = pubsubTopic;
this.contentFilters = contentFilters;
}
}
@ -592,10 +753,16 @@ export class FilterSubscription {
* @param peerID
* @param timeoutMs Timeout value in milliseconds to execute the call. If the function takes longer than this value, the execution will be canceled and an error returned
*/
export function filterSubscribe(filter: FilterSubscription, peerID: String = "", timeoutMs: Number = 0): Promise<void> {
export function filterSubscribe(
filter: FilterSubscription,
peerID: String = '',
timeoutMs: Number = 0
): Promise<void> {
return new Promise<void>(async (resolve, reject) => {
let filterJSON = JSON.stringify(filter)
let response = JSON.parse(await ReactNative.filterSubscribe(filterJSON, peerID, timeoutMs));
let filterJSON = JSON.stringify(filter);
let response = JSON.parse(
await ReactNative.filterSubscribe(filterJSON, peerID, timeoutMs)
);
if (response.error) {
reject(response.error);
@ -610,10 +777,15 @@ export function filterSubscribe(filter: FilterSubscription, peerID: String = "",
* @param filter
* @param timeoutMs Timeout value in milliseconds to execute the call. If the function takes longer than this value, the execution will be canceled and an error returned
*/
export function filterUnsubscribe(filter: FilterSubscription, timeoutMs: Number = 0): Promise<void> {
export function filterUnsubscribe(
filter: FilterSubscription,
timeoutMs: Number = 0
): Promise<void> {
return new Promise<void>(async (resolve, reject) => {
let filterJSON = JSON.stringify(filter)
let response = JSON.parse(await ReactNative.filterUnsubscribe(filterJSON, timeoutMs));
let filterJSON = JSON.stringify(filter);
let response = JSON.parse(
await ReactNative.filterUnsubscribe(filterJSON, timeoutMs)
);
if (response.error) {
reject(response.error);