From 40f1e939d75ab20c24f505d816c40dfe722512b1 Mon Sep 17 00:00:00 2001 From: Daniel Lugo Date: Mon, 13 Jan 2020 15:59:18 -0400 Subject: [PATCH] order schema --- services/gunDB/contact-api/schema.js | 41 ++++++++++++++++++++++++++-- 1 file changed, 39 insertions(+), 2 deletions(-) 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' +}