@pushprotocol/restapi
Advanced tools
Comparing version 0.3.2 to 0.3.3
@@ -5,2 +5,14 @@ # Changelog | ||
## [0.3.3](https://github.com/ethereum-push-notification-service/push-sdk/compare/restapi-0.3.1...restapi-0.3.2) (2023-02-08) | ||
### Bug Fixes | ||
* fixed response of chat.chats restapi ([ab1f432](https://github.com/ethereum-push-notification-service/push-sdk/commit/ab1f432dbe5443c72375ab1baa7226b997396aa4)) | ||
* fixed the message response object ([83d4f1e](https://github.com/ethereum-push-notification-service/push-sdk/commit/83d4f1e565b090d1c62859f7461f4e1c3bb9398a)) | ||
* Metamask reject handled ([#136](https://github.com/ethereum-push-notification-service/push-sdk/issues/136)) ([46a20b7](https://github.com/ethereum-push-notification-service/push-sdk/commit/46a20b751e655a526168c8ae7c400211f3b62b15)) | ||
* **restapi:** fix parse api response of notifications to send subject/title as asub ([#140](https://github.com/ethereum-push-notification-service/push-sdk/issues/140)) ([6a11feb](https://github.com/ethereum-push-notification-service/push-sdk/commit/6a11feb7cc02bf9ca0541b34f399992ad33f12a4)), closes [#139](https://github.com/ethereum-push-notification-service/push-sdk/issues/139) | ||
## [0.3.2](https://github.com/ethereum-push-notification-service/push-sdk/compare/restapi-0.3.1...restapi-0.3.2) (2023-02-03) | ||
@@ -7,0 +19,0 @@ |
{ | ||
"name": "@pushprotocol/restapi", | ||
"version": "0.3.2", | ||
"version": "0.3.3", | ||
"type": "commonjs", | ||
@@ -5,0 +5,0 @@ "publishConfig": { |
@@ -1,2 +0,2 @@ | ||
import { Message } from './ipfs'; | ||
import { IFeeds } from '../types'; | ||
/** | ||
@@ -11,2 +11,2 @@ * GET '/v1/chat/users/:did/chats | ||
}; | ||
export declare const chats: (options: ChatsOptionsType) => Promise<Message[]>; | ||
export declare const chats: (options: ChatsOptionsType) => Promise<IFeeds[]>; |
@@ -22,3 +22,3 @@ "use strict"; | ||
const chats = response.data.chats; | ||
const messages = yield (0, helpers_2.getInboxLists)({ | ||
const feeds = yield (0, helpers_2.getInboxLists)({ | ||
lists: chats, | ||
@@ -30,3 +30,3 @@ user, | ||
}); | ||
return messages; | ||
return feeds; | ||
} | ||
@@ -33,0 +33,0 @@ catch (err) { |
@@ -1,2 +0,2 @@ | ||
import { IConnectedUser, IFeeds, IMessageIPFSWithCID } from '../../types'; | ||
import { IConnectedUser, IFeeds, IMessageIPFSWithCID, IUser } from '../../types'; | ||
interface IEncryptedRequest { | ||
@@ -27,5 +27,7 @@ message: string; | ||
}) => Promise<string>; | ||
export declare const decryptFeeds: ({ feeds, connectedUser, }: { | ||
export declare const decryptFeeds: ({ feeds, connectedUser, pgpPrivateKey, env, }: { | ||
feeds: IFeeds[]; | ||
connectedUser: IConnectedUser; | ||
connectedUser: IUser; | ||
pgpPrivateKey?: string | undefined; | ||
env: string; | ||
}) => Promise<IFeeds[]>; | ||
@@ -32,0 +34,0 @@ interface IDecryptMessage { |
@@ -10,3 +10,5 @@ "use strict"; | ||
const helpers_1 = require("../../helpers"); | ||
const user_2 = require("../../user"); | ||
const service_1 = require("./service"); | ||
const constants_1 = require("../../constants"); | ||
const encryptAndSign = ({ plainText, fromPublicKeyArmored, toPublicKeyArmored, privateKeyArmored, }) => tslib_1.__awaiter(void 0, void 0, void 0, function* () { | ||
@@ -47,22 +49,28 @@ const secretKey = AES.generateRandomSecret(15); | ||
exports.decryptAndVerifySignature = decryptAndVerifySignature; | ||
const decryptFeeds = ({ feeds, connectedUser, }) => tslib_1.__awaiter(void 0, void 0, void 0, function* () { | ||
if (connectedUser.privateKey) { | ||
for (const feed of feeds) { | ||
if (feed.msg.encType !== 'PlainText' && feed.msg.encType !== null) { | ||
// To do signature verification it depends on who has sent the message | ||
let signatureValidationPubliKey; | ||
if (feed.msg.fromCAIP10 === connectedUser.wallets.split(',')[0]) { | ||
signatureValidationPubliKey = connectedUser.publicKey; | ||
const decryptFeeds = ({ feeds, connectedUser, pgpPrivateKey, env = constants_1.default.ENV.PROD, }) => tslib_1.__awaiter(void 0, void 0, void 0, function* () { | ||
let otherPeer; | ||
let signatureValidationPubliKey; // To do signature verification it depends on who has sent the message | ||
let gotOtherPeer = false; | ||
for (const feed of feeds) { | ||
if (feed.msg.encType !== 'PlainText') { | ||
if (!pgpPrivateKey) { | ||
throw Error('Decrypted private key is necessary'); | ||
} | ||
if (feed.msg.fromCAIP10 !== connectedUser.wallets.split(',')[0]) { | ||
if (!gotOtherPeer) { | ||
otherPeer = yield (0, user_2.get)({ account: feed.msg.fromCAIP10, env }); | ||
gotOtherPeer = true; | ||
} | ||
else { | ||
signatureValidationPubliKey = feed.publicKey; | ||
} | ||
feed.msg.lastMessage = yield (0, exports.decryptAndVerifySignature)({ | ||
cipherText: feed.msg.lastMessage, | ||
encryptedSecretKey: feed.msg.encryptedSecret, | ||
publicKeyArmored: signatureValidationPubliKey, | ||
signatureArmored: feed.msg.signature, | ||
privateKeyArmored: connectedUser.privateKey, | ||
}); | ||
signatureValidationPubliKey = otherPeer.publicKey; | ||
} | ||
else { | ||
signatureValidationPubliKey = connectedUser.publicKey; | ||
} | ||
feed.msg.messageContent = yield (0, exports.decryptAndVerifySignature)({ | ||
cipherText: feed.msg.messageContent, | ||
encryptedSecretKey: feed.msg.encryptedSecret, | ||
publicKeyArmored: signatureValidationPubliKey, | ||
signatureArmored: feed.msg.signature, | ||
privateKeyArmored: pgpPrivateKey, | ||
}); | ||
} | ||
@@ -69,0 +77,0 @@ } |
@@ -1,2 +0,2 @@ | ||
import { Chat, IMessageIPFS, IUser } from '../../types'; | ||
import { Chat, IFeeds, IMessageIPFS, IUser } from '../../types'; | ||
declare type InboxListsType = { | ||
@@ -15,4 +15,4 @@ lists: Chat[]; | ||
}; | ||
export declare const getInboxLists: (options: InboxListsType) => Promise<IMessageIPFS[]>; | ||
export declare const getInboxLists: (options: InboxListsType) => Promise<IFeeds[]>; | ||
export declare const decryptConversation: (options: DecryptConverationType) => Promise<IMessageIPFS[]>; | ||
export {}; |
@@ -9,15 +9,16 @@ "use strict"; | ||
const ipfs_1 = require("../ipfs"); | ||
const crypto_1 = require("./crypto"); | ||
const getInboxLists = (options) => tslib_1.__awaiter(void 0, void 0, void 0, function* () { | ||
const { lists, user, toDecrypt, pgpPrivateKey, env = constants_1.default.ENV.PROD, } = options || {}; | ||
const connectedUser = yield (0, user_1.get)({ account: (0, helpers_1.pCAIP10ToWallet)(user), env }); | ||
const messages = []; | ||
const feeds = []; | ||
for (const list of lists) { | ||
if (list.threadhash !== null) { | ||
const message = yield (0, ipfs_1.getCID)(list.threadhash, { env }); | ||
messages.push(message); | ||
feeds.push(Object.assign(Object.assign({}, list), { msg: message })); | ||
} | ||
} | ||
if (toDecrypt) | ||
return (0, exports.decryptConversation)({ messages, connectedUser, pgpPrivateKey, env }); | ||
return messages; | ||
return (0, crypto_1.decryptFeeds)({ feeds, connectedUser, pgpPrivateKey, env }); | ||
return feeds; | ||
}); | ||
@@ -24,0 +25,0 @@ exports.getInboxLists = getInboxLists; |
@@ -1,2 +0,2 @@ | ||
import { Message } from './ipfs'; | ||
import { IFeeds } from '../types'; | ||
/** | ||
@@ -11,2 +11,2 @@ * GET '/v1/chat/users/:did/requests | ||
}; | ||
export declare const requests: (options: RequestOptionsType) => Promise<Message[]>; | ||
export declare const requests: (options: RequestOptionsType) => Promise<IFeeds[]>; |
@@ -21,3 +21,3 @@ "use strict"; | ||
const requests = response.data.requests; | ||
const messages = yield (0, helpers_2.getInboxLists)({ | ||
const Feeds = yield (0, helpers_2.getInboxLists)({ | ||
lists: requests, | ||
@@ -29,3 +29,3 @@ user, | ||
}); | ||
return messages; | ||
return Feeds; | ||
} | ||
@@ -32,0 +32,0 @@ catch (err) { |
@@ -109,4 +109,2 @@ export declare type ApiNotificationType = { | ||
export interface IInboxChat { | ||
name: string; | ||
profilePicture: string; | ||
timestamp: number; | ||
@@ -124,8 +122,22 @@ fromDID: string; | ||
} | ||
export interface IMessageIPFS { | ||
fromCAIP10: string; | ||
toCAIP10: string; | ||
fromDID: string; | ||
toDID: string; | ||
messageType: string; | ||
messageContent: string; | ||
signature: string; | ||
sigType: string; | ||
link: string | null; | ||
timestamp?: number; | ||
encType: string; | ||
encryptedSecret: string; | ||
} | ||
export interface IFeeds { | ||
msg: IInboxChat; | ||
msg: IMessageIPFS; | ||
did: string; | ||
wallets: string; | ||
profilePicture: string | null; | ||
publicKey: string; | ||
publicKey: string | null; | ||
about: string | null; | ||
@@ -137,3 +149,3 @@ threadhash: string | null; | ||
combinedDID: string; | ||
cid: string; | ||
cid?: string; | ||
} | ||
@@ -158,16 +170,2 @@ export interface IUser { | ||
} | ||
export interface IMessageIPFS { | ||
fromCAIP10: string; | ||
toCAIP10: string; | ||
fromDID: string; | ||
toDID: string; | ||
messageType: string; | ||
messageContent: string; | ||
signature: string; | ||
sigType: string; | ||
link: string | null; | ||
timestamp?: number; | ||
encType: string; | ||
encryptedSecret: string; | ||
} | ||
export interface IMessageIPFSWithCID extends IMessageIPFS { | ||
@@ -174,0 +172,0 @@ cid: string; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
183395
2571