|
@@ -185,15 +185,28 @@ class BankClient {
|
|
|
return uploadResponse.hash;
|
|
return uploadResponse.hash;
|
|
|
});
|
|
});
|
|
|
}
|
|
}
|
|
|
- appendBank(bankAddress, bankTopic, itemHash) {
|
|
|
|
|
|
|
+ appendPrivate(slim, peerAddr, topic, hash, replaceHash, deleteHash) {
|
|
|
return __awaiter(this, void 0, void 0, function* () {
|
|
return __awaiter(this, void 0, void 0, function* () {
|
|
|
- const payload = yield this.makePlaintextPayload(itemHash);
|
|
|
|
|
- const topicURL = this.urlBase + '/bank/private/' + encodeURIComponent(bankAddress) + '/' + encodeURIComponent(bankTopic);
|
|
|
|
|
- yield this.webClient.requestJSON({
|
|
|
|
|
- body: payload,
|
|
|
|
|
|
|
+ const nonce = yield this.getNonce();
|
|
|
|
|
+ const payload = yield this.makePlaintextPayload(JSON.stringify({
|
|
|
|
|
+ _date: new Date().toISOString(),
|
|
|
|
|
+ _nonce: nonce,
|
|
|
|
|
+ deleteHash,
|
|
|
|
|
+ hash,
|
|
|
|
|
+ replaceHash,
|
|
|
|
|
+ }));
|
|
|
|
|
+ const topicURL = this.urlBase + '/bank/private/' + encodeURIComponent(peerAddr) + '/' + encodeURIComponent(topic);
|
|
|
|
|
+ const result = yield this.webClient.request({
|
|
|
|
|
+ body: JSON.stringify(payload),
|
|
|
|
|
+ headers: {
|
|
|
|
|
+ 'content-type': 'application/json'
|
|
|
|
|
+ },
|
|
|
method: 'PUT',
|
|
method: 'PUT',
|
|
|
url: topicURL
|
|
url: topicURL
|
|
|
});
|
|
});
|
|
|
|
|
+ if (!slim && topic !== 'all' && !deleteHash) {
|
|
|
|
|
+ yield this.appendPrivate(slim, peerAddr, 'all', hash, undefined, undefined);
|
|
|
|
|
+ }
|
|
|
});
|
|
});
|
|
|
}
|
|
}
|
|
|
retrievePrivate(peerAddr, topic) {
|
|
retrievePrivate(peerAddr, topic) {
|
|
@@ -220,27 +233,6 @@ class BankClient {
|
|
|
yield this.connectWebsocket(peerAddr, topic, connectCallback, messageCallback);
|
|
yield this.connectWebsocket(peerAddr, topic, connectCallback, messageCallback);
|
|
|
});
|
|
});
|
|
|
}
|
|
}
|
|
|
- appendPrivate(peerAddr, topic, hash, replaceHash, deleteHash) {
|
|
|
|
|
- return __awaiter(this, void 0, void 0, function* () {
|
|
|
|
|
- const nonce = yield this.getNonce();
|
|
|
|
|
- const payload = yield this.makePlaintextPayload(JSON.stringify({
|
|
|
|
|
- _date: new Date().toISOString(),
|
|
|
|
|
- _nonce: nonce,
|
|
|
|
|
- deleteHash,
|
|
|
|
|
- hash,
|
|
|
|
|
- replaceHash,
|
|
|
|
|
- }));
|
|
|
|
|
- const topicURL = this.urlBase + '/bank/private/' + encodeURIComponent(peerAddr) + '/' + encodeURIComponent(topic);
|
|
|
|
|
- const result = yield this.webClient.request({
|
|
|
|
|
- body: JSON.stringify(payload),
|
|
|
|
|
- headers: {
|
|
|
|
|
- 'content-type': 'application/json'
|
|
|
|
|
- },
|
|
|
|
|
- method: 'PUT',
|
|
|
|
|
- url: topicURL
|
|
|
|
|
- });
|
|
|
|
|
- });
|
|
|
|
|
- }
|
|
|
|
|
getOrCreateContact(peerId, contactAddr) {
|
|
getOrCreateContact(peerId, contactAddr) {
|
|
|
return __awaiter(this, void 0, void 0, function* () {
|
|
return __awaiter(this, void 0, void 0, function* () {
|
|
|
const contactList = yield this.retrievePrivate(peerId, '📇');
|
|
const contactList = yield this.retrievePrivate(peerId, '📇');
|
|
@@ -257,7 +249,7 @@ class BankClient {
|
|
|
id: util_1.uuid()
|
|
id: util_1.uuid()
|
|
|
};
|
|
};
|
|
|
const newItemHash = yield this.uploadSlimJSON(newItem);
|
|
const newItemHash = yield this.uploadSlimJSON(newItem);
|
|
|
- yield this.appendPrivate(peerId, '📇', newItemHash);
|
|
|
|
|
|
|
+ yield this.appendPrivate(true, peerId, '📇', newItemHash);
|
|
|
return newItem;
|
|
return newItem;
|
|
|
});
|
|
});
|
|
|
}
|
|
}
|
|
@@ -280,7 +272,7 @@ class BankClient {
|
|
|
const newItem = util_1.mergeDeep(existing, newProps);
|
|
const newItem = util_1.mergeDeep(existing, newProps);
|
|
|
delete newItem.hash;
|
|
delete newItem.hash;
|
|
|
const newItemHash = yield this.uploadSlimJSON(newItem);
|
|
const newItemHash = yield this.uploadSlimJSON(newItem);
|
|
|
- yield this.appendPrivate(peerId, '📇', newItemHash, existing.hash);
|
|
|
|
|
|
|
+ yield this.appendPrivate(true, peerId, '📇', newItemHash, existing.hash);
|
|
|
return yield this.getContactById(peerId, contactId);
|
|
return yield this.getContactById(peerId, contactId);
|
|
|
});
|
|
});
|
|
|
}
|
|
}
|