From 675156921d0667891e077b2ce7d7628fa1915945 Mon Sep 17 00:00:00 2001 From: Mark Vayngrib Date: Sun, 4 Feb 2018 14:46:45 -0500 Subject: [PATCH] fix: seals.create --- lib/seals.js | 9 ++++++++- src/provider.ts | 5 +++-- src/seals.ts | 13 +++++++++++++ 3 files changed, 24 insertions(+), 3 deletions(-) diff --git a/lib/seals.js b/lib/seals.js index 92595da4a..dc84dcb65 100644 --- a/lib/seals.js +++ b/lib/seals.js @@ -12,6 +12,7 @@ const _ = require("lodash"); const buildResource = require("@tradle/build-resource"); const constants_1 = require("@tradle/constants"); const utils_1 = require("./utils"); +const crypto_1 = require("./crypto"); const string_utils_1 = require("./string-utils"); const dbUtils = require("./db-utils"); const types = require("./typeforce-types"); @@ -126,6 +127,9 @@ class Seals { return results.filter(notNull); }); this.createSealRecord = (opts) => __awaiter(this, void 0, void 0, function* () { + if (!opts.key && opts.write) { + opts = Object.assign({}, opts, { key: yield this.provider.getMyChainKey() }); + } const seal = this.getNewSealParams(opts); try { yield this.table.put({ @@ -349,7 +353,10 @@ class Seals { only keeps the latest version.`); } }); - this.getNewSealParams = ({ key, link, permalink, counterparty, watchType = WATCH_TYPE.this, write }) => { + this.getNewSealParams = ({ key, object, link, permalink, counterparty, watchType = WATCH_TYPE.this, write }) => { + if (!(link && permalink) && object) { + ({ link, permalink } = crypto_1.getLinks(object)); + } const { blockchain, network } = this; let pubKey; if (watchType === WATCH_TYPE.this) { diff --git a/src/provider.ts b/src/provider.ts index 93fd077d4..173199b8c 100644 --- a/src/provider.ts +++ b/src/provider.ts @@ -48,7 +48,8 @@ import { IDebug, ILiveDeliveryOpts, ISendOpts, - IBatchSendOpts + IBatchSendOpts, + IECMiniPubKey } from './types' import Logger from './logger' @@ -107,7 +108,7 @@ export default class Provider { return keys } - public getMyChainKey = async ():Promise => { + public getMyChainKey = async ():Promise => { const { network } = this if (network.flavor === 'corda') return diff --git a/src/seals.ts b/src/seals.ts index 0f7b16c96..12d87a737 100644 --- a/src/seals.ts +++ b/src/seals.ts @@ -16,6 +16,7 @@ import { bindAll, summarizeObject } from './utils' +import { getLinks } from './crypto' import { prettify } from './string-utils' import dbUtils = require('./db-utils') import types = require('./typeforce-types') @@ -284,6 +285,13 @@ export default class Seals { } private createSealRecord = async (opts:SealRecordOpts):Promise => { + if (!opts.key && opts.write) { + opts = { + ...opts, + key: await this.provider.getMyChainKey() + } + } + const seal = this.getNewSealParams(opts) try { await this.table.put({ @@ -563,12 +571,17 @@ export default class Seals { private getNewSealParams = ({ key, + object, link, permalink, counterparty, watchType=WATCH_TYPE.this, write }:SealRecordOpts) => { + if (!(link && permalink) && object) { + ({ link, permalink } = getLinks(object)) + } + const { blockchain, network } = this // the next version's previous is the current version // the tx for next version will have a predictable seal based on the current version's link