diff --git a/src/generated/push/block_pb.d.ts b/src/generated/push/block_pb.d.ts index deca6f1..5071081 100644 --- a/src/generated/push/block_pb.d.ts +++ b/src/generated/push/block_pb.d.ts @@ -274,10 +274,31 @@ export namespace Transaction { } } -export class InitDid extends jspb.Message { - getDid(): string; - setDid(value: string): void; +export class WalletToEncDerivedKey extends jspb.Message { + getEncderivedprivkey(): string; + setEncderivedprivkey(value: string): void; + + getSignature(): string; + setSignature(value: string): void; + + serializeBinary(): Uint8Array; + toObject(includeInstance?: boolean): WalletToEncDerivedKey.AsObject; + static toObject(includeInstance: boolean, msg: WalletToEncDerivedKey): WalletToEncDerivedKey.AsObject; + static extensions: {[key: number]: jspb.ExtensionFieldInfo}; + static extensionsBinary: {[key: number]: jspb.ExtensionFieldBinaryInfo}; + static serializeBinaryToWriter(message: WalletToEncDerivedKey, writer: jspb.BinaryWriter): void; + static deserializeBinary(bytes: Uint8Array): WalletToEncDerivedKey; + static deserializeBinaryFromReader(message: WalletToEncDerivedKey, reader: jspb.BinaryReader): WalletToEncDerivedKey; +} + +export namespace WalletToEncDerivedKey { + export type AsObject = { + encderivedprivkey: string, + signature: string, + } +} +export class InitDid extends jspb.Message { getMasterpubkey(): string; setMasterpubkey(value: string): void; @@ -287,7 +308,7 @@ export class InitDid extends jspb.Message { getDerivedpubkey(): string; setDerivedpubkey(value: string): void; - getWallettoencderivedkeyMap(): jspb.Map; + getWallettoencderivedkeyMap(): jspb.Map; clearWallettoencderivedkeyMap(): void; serializeBinary(): Uint8Array; toObject(includeInstance?: boolean): InitDid.AsObject; @@ -301,11 +322,10 @@ export class InitDid extends jspb.Message { export namespace InitDid { export type AsObject = { - did: string, masterpubkey: string, derivedkeyindex: number, derivedpubkey: string, - wallettoencderivedkeyMap: Array<[string, string]>, + wallettoencderivedkeyMap: Array<[string, WalletToEncDerivedKey.AsObject]>, } } diff --git a/src/generated/push/block_pb.js b/src/generated/push/block_pb.js index 168c4c9..6cd2427 100644 --- a/src/generated/push/block_pb.js +++ b/src/generated/push/block_pb.js @@ -35,6 +35,7 @@ goog.exportSymbol('proto.push.TransactionObj', null, global); goog.exportSymbol('proto.push.TxAttestorData', null, global); goog.exportSymbol('proto.push.TxValidatorData', null, global); goog.exportSymbol('proto.push.Vote', null, global); +goog.exportSymbol('proto.push.WalletToEncDerivedKey', null, global); /** * Generated by JsPbCodeGenerator. * @param {Array=} opt_data Optional initial data array, typically from a @@ -224,6 +225,27 @@ if (goog.DEBUG && !COMPILED) { */ proto.push.Transaction.displayName = 'proto.push.Transaction'; } +/** + * Generated by JsPbCodeGenerator. + * @param {Array=} opt_data Optional initial data array, typically from a + * server response, or constructed directly in Javascript. The array is used + * in place and becomes part of the constructed object. It is not cloned. + * If no data is provided, the constructed object will be empty, but still + * valid. + * @extends {jspb.Message} + * @constructor + */ +proto.push.WalletToEncDerivedKey = function(opt_data) { + jspb.Message.initialize(this, opt_data, 0, -1, null, null); +}; +goog.inherits(proto.push.WalletToEncDerivedKey, jspb.Message); +if (goog.DEBUG && !COMPILED) { + /** + * @public + * @override + */ + proto.push.WalletToEncDerivedKey.displayName = 'proto.push.WalletToEncDerivedKey'; +} /** * Generated by JsPbCodeGenerator. * @param {Array=} opt_data Optional initial data array, typically from a @@ -2394,6 +2416,166 @@ proto.push.Transaction.prototype.setFee = function(value) { +if (jspb.Message.GENERATE_TO_OBJECT) { +/** + * Creates an object representation of this proto. + * Field names that are reserved in JavaScript and will be renamed to pb_name. + * Optional fields that are not set will be set to undefined. + * To access a reserved field use, foo.pb_, eg, foo.pb_default. + * For the list of reserved names please see: + * net/proto2/compiler/js/internal/generator.cc#kKeyword. + * @param {boolean=} opt_includeInstance Deprecated. whether to include the + * JSPB instance for transitional soy proto support: + * http://goto/soy-param-migration + * @return {!Object} + */ +proto.push.WalletToEncDerivedKey.prototype.toObject = function(opt_includeInstance) { + return proto.push.WalletToEncDerivedKey.toObject(opt_includeInstance, this); +}; + + +/** + * Static version of the {@see toObject} method. + * @param {boolean|undefined} includeInstance Deprecated. Whether to include + * the JSPB instance for transitional soy proto support: + * http://goto/soy-param-migration + * @param {!proto.push.WalletToEncDerivedKey} msg The msg instance to transform. + * @return {!Object} + * @suppress {unusedLocalVariables} f is only used for nested messages + */ +proto.push.WalletToEncDerivedKey.toObject = function(includeInstance, msg) { + var f, obj = { + encderivedprivkey: jspb.Message.getFieldWithDefault(msg, 1, ""), + signature: jspb.Message.getFieldWithDefault(msg, 2, "") + }; + + if (includeInstance) { + obj.$jspbMessageInstance = msg; + } + return obj; +}; +} + + +/** + * Deserializes binary data (in protobuf wire format). + * @param {jspb.ByteSource} bytes The bytes to deserialize. + * @return {!proto.push.WalletToEncDerivedKey} + */ +proto.push.WalletToEncDerivedKey.deserializeBinary = function(bytes) { + var reader = new jspb.BinaryReader(bytes); + var msg = new proto.push.WalletToEncDerivedKey; + return proto.push.WalletToEncDerivedKey.deserializeBinaryFromReader(msg, reader); +}; + + +/** + * Deserializes binary data (in protobuf wire format) from the + * given reader into the given message object. + * @param {!proto.push.WalletToEncDerivedKey} msg The message object to deserialize into. + * @param {!jspb.BinaryReader} reader The BinaryReader to use. + * @return {!proto.push.WalletToEncDerivedKey} + */ +proto.push.WalletToEncDerivedKey.deserializeBinaryFromReader = function(msg, reader) { + while (reader.nextField()) { + if (reader.isEndGroup()) { + break; + } + var field = reader.getFieldNumber(); + switch (field) { + case 1: + var value = /** @type {string} */ (reader.readString()); + msg.setEncderivedprivkey(value); + break; + case 2: + var value = /** @type {string} */ (reader.readString()); + msg.setSignature(value); + break; + default: + reader.skipField(); + break; + } + } + return msg; +}; + + +/** + * Serializes the message to binary data (in protobuf wire format). + * @return {!Uint8Array} + */ +proto.push.WalletToEncDerivedKey.prototype.serializeBinary = function() { + var writer = new jspb.BinaryWriter(); + proto.push.WalletToEncDerivedKey.serializeBinaryToWriter(this, writer); + return writer.getResultBuffer(); +}; + + +/** + * Serializes the given message to binary data (in protobuf wire + * format), writing to the given BinaryWriter. + * @param {!proto.push.WalletToEncDerivedKey} message + * @param {!jspb.BinaryWriter} writer + * @suppress {unusedLocalVariables} f is only used for nested messages + */ +proto.push.WalletToEncDerivedKey.serializeBinaryToWriter = function(message, writer) { + var f = undefined; + f = message.getEncderivedprivkey(); + if (f.length > 0) { + writer.writeString( + 1, + f + ); + } + f = message.getSignature(); + if (f.length > 0) { + writer.writeString( + 2, + f + ); + } +}; + + +/** + * optional string encDerivedPrivKey = 1; + * @return {string} + */ +proto.push.WalletToEncDerivedKey.prototype.getEncderivedprivkey = function() { + return /** @type {string} */ (jspb.Message.getFieldWithDefault(this, 1, "")); +}; + + +/** + * @param {string} value + * @return {!proto.push.WalletToEncDerivedKey} returns this + */ +proto.push.WalletToEncDerivedKey.prototype.setEncderivedprivkey = function(value) { + return jspb.Message.setProto3StringField(this, 1, value); +}; + + +/** + * optional string signature = 2; + * @return {string} + */ +proto.push.WalletToEncDerivedKey.prototype.getSignature = function() { + return /** @type {string} */ (jspb.Message.getFieldWithDefault(this, 2, "")); +}; + + +/** + * @param {string} value + * @return {!proto.push.WalletToEncDerivedKey} returns this + */ +proto.push.WalletToEncDerivedKey.prototype.setSignature = function(value) { + return jspb.Message.setProto3StringField(this, 2, value); +}; + + + + + if (jspb.Message.GENERATE_TO_OBJECT) { /** * Creates an object representation of this proto. @@ -2423,11 +2605,10 @@ proto.push.InitDid.prototype.toObject = function(opt_includeInstance) { */ proto.push.InitDid.toObject = function(includeInstance, msg) { var f, obj = { - did: jspb.Message.getFieldWithDefault(msg, 1, ""), - masterpubkey: jspb.Message.getFieldWithDefault(msg, 2, ""), - derivedkeyindex: jspb.Message.getFieldWithDefault(msg, 3, 0), - derivedpubkey: jspb.Message.getFieldWithDefault(msg, 4, ""), - wallettoencderivedkeyMap: (f = msg.getWallettoencderivedkeyMap()) ? f.toObject(includeInstance, undefined) : [] + masterpubkey: jspb.Message.getFieldWithDefault(msg, 1, ""), + derivedkeyindex: jspb.Message.getFieldWithDefault(msg, 2, 0), + derivedpubkey: jspb.Message.getFieldWithDefault(msg, 3, ""), + wallettoencderivedkeyMap: (f = msg.getWallettoencderivedkeyMap()) ? f.toObject(includeInstance, proto.push.WalletToEncDerivedKey.toObject) : [] }; if (includeInstance) { @@ -2465,25 +2646,21 @@ proto.push.InitDid.deserializeBinaryFromReader = function(msg, reader) { var field = reader.getFieldNumber(); switch (field) { case 1: - var value = /** @type {string} */ (reader.readString()); - msg.setDid(value); - break; - case 2: var value = /** @type {string} */ (reader.readString()); msg.setMasterpubkey(value); break; - case 3: + case 2: var value = /** @type {number} */ (reader.readUint32()); msg.setDerivedkeyindex(value); break; - case 4: + case 3: var value = /** @type {string} */ (reader.readString()); msg.setDerivedpubkey(value); break; - case 6: + case 4: var value = msg.getWallettoencderivedkeyMap(); reader.readMessage(value, function(message, reader) { - jspb.Map.deserializeBinary(message, reader, jspb.BinaryReader.prototype.readString, jspb.BinaryReader.prototype.readString, null, "", ""); + jspb.Map.deserializeBinary(message, reader, jspb.BinaryReader.prototype.readString, jspb.BinaryReader.prototype.readMessage, proto.push.WalletToEncDerivedKey.deserializeBinaryFromReader, "", new proto.push.WalletToEncDerivedKey()); }); break; default: @@ -2515,65 +2692,40 @@ proto.push.InitDid.prototype.serializeBinary = function() { */ proto.push.InitDid.serializeBinaryToWriter = function(message, writer) { var f = undefined; - f = message.getDid(); - if (f.length > 0) { - writer.writeString( - 1, - f - ); - } f = message.getMasterpubkey(); if (f.length > 0) { writer.writeString( - 2, + 1, f ); } f = message.getDerivedkeyindex(); if (f !== 0) { writer.writeUint32( - 3, + 2, f ); } f = message.getDerivedpubkey(); if (f.length > 0) { writer.writeString( - 4, + 3, f ); } f = message.getWallettoencderivedkeyMap(true); if (f && f.getLength() > 0) { - f.serializeBinary(6, writer, jspb.BinaryWriter.prototype.writeString, jspb.BinaryWriter.prototype.writeString); + f.serializeBinary(4, writer, jspb.BinaryWriter.prototype.writeString, jspb.BinaryWriter.prototype.writeMessage, proto.push.WalletToEncDerivedKey.serializeBinaryToWriter); } }; /** - * optional string did = 1; - * @return {string} - */ -proto.push.InitDid.prototype.getDid = function() { - return /** @type {string} */ (jspb.Message.getFieldWithDefault(this, 1, "")); -}; - - -/** - * @param {string} value - * @return {!proto.push.InitDid} returns this - */ -proto.push.InitDid.prototype.setDid = function(value) { - return jspb.Message.setProto3StringField(this, 1, value); -}; - - -/** - * optional string masterPubKey = 2; + * optional string masterPubKey = 1; * @return {string} */ proto.push.InitDid.prototype.getMasterpubkey = function() { - return /** @type {string} */ (jspb.Message.getFieldWithDefault(this, 2, "")); + return /** @type {string} */ (jspb.Message.getFieldWithDefault(this, 1, "")); }; @@ -2582,16 +2734,16 @@ proto.push.InitDid.prototype.getMasterpubkey = function() { * @return {!proto.push.InitDid} returns this */ proto.push.InitDid.prototype.setMasterpubkey = function(value) { - return jspb.Message.setProto3StringField(this, 2, value); + return jspb.Message.setProto3StringField(this, 1, value); }; /** - * optional uint32 derivedKeyIndex = 3; + * optional uint32 derivedKeyIndex = 2; * @return {number} */ proto.push.InitDid.prototype.getDerivedkeyindex = function() { - return /** @type {number} */ (jspb.Message.getFieldWithDefault(this, 3, 0)); + return /** @type {number} */ (jspb.Message.getFieldWithDefault(this, 2, 0)); }; @@ -2600,16 +2752,16 @@ proto.push.InitDid.prototype.getDerivedkeyindex = function() { * @return {!proto.push.InitDid} returns this */ proto.push.InitDid.prototype.setDerivedkeyindex = function(value) { - return jspb.Message.setProto3IntField(this, 3, value); + return jspb.Message.setProto3IntField(this, 2, value); }; /** - * optional string derivedPubKey = 4; + * optional string derivedPubKey = 3; * @return {string} */ proto.push.InitDid.prototype.getDerivedpubkey = function() { - return /** @type {string} */ (jspb.Message.getFieldWithDefault(this, 4, "")); + return /** @type {string} */ (jspb.Message.getFieldWithDefault(this, 3, "")); }; @@ -2618,20 +2770,20 @@ proto.push.InitDid.prototype.getDerivedpubkey = function() { * @return {!proto.push.InitDid} returns this */ proto.push.InitDid.prototype.setDerivedpubkey = function(value) { - return jspb.Message.setProto3StringField(this, 4, value); + return jspb.Message.setProto3StringField(this, 3, value); }; /** - * map walletToEncDerivedKey = 6; + * map walletToEncDerivedKey = 4; * @param {boolean=} opt_noLazyCreate Do not create the map if * empty, instead returning `undefined` - * @return {!jspb.Map} + * @return {!jspb.Map} */ proto.push.InitDid.prototype.getWallettoencderivedkeyMap = function(opt_noLazyCreate) { - return /** @type {!jspb.Map} */ ( - jspb.Message.getMapField(this, 6, opt_noLazyCreate, - null)); + return /** @type {!jspb.Map} */ ( + jspb.Message.getMapField(this, 4, opt_noLazyCreate, + proto.push.WalletToEncDerivedKey)); }; diff --git a/src/proto/push/block.proto b/src/proto/push/block.proto index 6ac9d38..09ba74f 100644 --- a/src/proto/push/block.proto +++ b/src/proto/push/block.proto @@ -99,15 +99,18 @@ message Transaction { // PAYLOADS ------------------------------------------------------------------------------------------------------------ +message WalletToEncDerivedKey { + string encDerivedPrivKey = 1; + // Helps Vnode to proof that encryptedData is indeed signed by wallet + string signature = 2; +} + // INIT_DID message InitDid { - string did = 1; - string masterPubKey = 2; - uint32 derivedKeyIndex = 3; - string derivedPubKey = 4; - // Map to store wallet address and corresponding encrypted derived key - // Note:- There will always be altest 1 mapping - map walletToEncDerivedKey = 6; + string masterPubKey = 1; + uint32 derivedKeyIndex = 2; + string derivedPubKey = 3; + map walletToEncDerivedKey = 4; } enum KeyAction { diff --git a/src/services/messaging/validatorNode.ts b/src/services/messaging/validatorNode.ts index b92dd00..8d9ad56 100644 --- a/src/services/messaging/validatorNode.ts +++ b/src/services/messaging/validatorNode.ts @@ -187,9 +187,6 @@ export class ValidatorNode implements StorageContractListener { if (tx.getCategory() === 'INIT_DID') { let txData = InitDid.deserializeBinary(tx.getData()); - if (StrUtil.isEmpty(txData.getDid())) { - throw new TransactionError(`did missing`); - } if (StrUtil.isEmpty(txData.getMasterpubkey())) { throw new TransactionError(`masterPubKey missing`); } diff --git a/tests/block/block.test.ts b/tests/block/block.test.ts index 8535627..aa5011a 100644 --- a/tests/block/block.test.ts +++ b/tests/block/block.test.ts @@ -65,11 +65,10 @@ describe('block tests', function () { it('sample transaction 1', async function () { const data = new InitDid(); - data.setDid('0xAA'); data.setMasterpubkey('0xBB'); data.setDerivedkeyindex(1); data.setDerivedpubkey('0xCC'); - data.getWallettoencderivedkeyMap().set('0xAA', '0xBB'); + data.getWallettoencderivedkeyMap().set('0xAA', {encDerivedPrivKey: '0xDD', signature : '0xEE'}); const t = new Transaction(); t.setType(0); @@ -129,11 +128,10 @@ describe('block tests', function () { console.log("building ------------------------- "); // build transaction data (app-dependent) const data = new InitDid(); - data.setDid('0xAA'); data.setMasterpubkey('0xBB'); data.setDerivedkeyindex(1); data.setDerivedpubkey('0xCC'); - data.getWallettoencderivedkeyMap().set('0xAA', '0xBB'); + data.getWallettoencderivedkeyMap().set('0xAA', {encDerivedPrivKey: '0xDD', signature : '0xEE'}); console.log("data as json", JSON.stringify(data.toObject())); // build transaction