diff --git a/services/gunDB/contact-api/schema.js b/services/gunDB/contact-api/schema.js index 929534c9..9a7d57bf 100644 --- a/services/gunDB/contact-api/schema.js +++ b/services/gunDB/contact-api/schema.js @@ -1,5 +1,5 @@ /** - * @prettier + * @format */ /** * @typedef {object} HandshakeRequest @@ -316,7 +316,6 @@ exports.isPartialOutgoing = item => { } /** - * * @param {any} item * @returns {item is Outgoing} */ @@ -337,3 +336,41 @@ exports.isOutgoing = item => { return typeof obj.with === 'string' && messagesAreMessages } + +/** + * @typedef {object} Order + * @prop {string} from Public key of sender. + * @prop {string} amount Encrypted + * @prop {string} memo Encrypted + * @prop {number} timestamp + */ + +/** + * @param {any} item + * @returns {item is Order} + */ +exports.isOrder = item => { + if (typeof item !== 'object') { + return false + } + + if (item === null) { + return false + } + + const obj = /** @type {Order} */ (item) + + if (typeof obj.amount !== 'string') { + return false + } + + if (typeof obj.from !== 'string') { + return false + } + + if (typeof obj.memo !== 'string') { + return false + } + + return typeof obj.timestamp === 'number' +}