Skip to content

Commit b4e993f

Browse files
authored
Fixed - #147 (#648)
- Updated delegated harvesting message marker - Added vrf private key to the message payload
1 parent 57fcb26 commit b4e993f

8 files changed

+80
-32
lines changed

e2e/infrastructure/MetadataHttp.spec.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,30 @@ describe('MetadataHttp', () => {
130130
});
131131
});
132132

133+
describe('AccountMetadataTransaction', () => {
134+
it('aggregate', () => {
135+
const accountMetadataTransaction = AccountMetadataTransaction.create(
136+
Deadline.create(),
137+
account.address,
138+
UInt64.fromUint(6),
139+
0,
140+
`Test account mett value`,
141+
networkType,
142+
helper.maxFee,
143+
);
144+
145+
const aggregateTransaction = AggregateTransaction.createComplete(
146+
Deadline.create(),
147+
[accountMetadataTransaction.toAggregate(account.publicAccount)],
148+
networkType,
149+
[],
150+
helper.maxFee,
151+
);
152+
const signedTransaction = aggregateTransaction.signWith(account, generationHash);
153+
return helper.announce(signedTransaction);
154+
});
155+
});
156+
133157
describe('MosaicMetadataTransaction', () => {
134158
it('aggregate', () => {
135159
const mosaicMetadataTransaction = MosaicMetadataTransaction.create(

src/model/message/MessageMarker.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
export class MessageMarker {
1818
/**
19-
* 8-byte marker: FE2A8061577301E2 for PersistentDelegationRequestTransaction message
19+
* 8-byte marker: E201735761802AFE for PersistentDelegationRequestTransaction message
2020
*/
21-
public static readonly PersistentDelegationUnlock = 'FE2A8061577301E2';
21+
public static readonly PersistentDelegationUnlock = 'E201735761802AFE';
2222
}

src/model/message/PersistentHarvestingDelegationMessage.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,22 +31,23 @@ export class PersistentHarvestingDelegationMessage extends Message {
3131
}
3232

3333
/**
34-
*
35-
* @param delegatedPrivateKey - Private key of delegated account
36-
* @param recipientPublicKey - Recipient public key
34+
* @param signingPrivateKey - Remote harvester signing private key linked to the main account
35+
* @param vrfPrivateKey - VRF private key linked to the main account
36+
* @param nodePublicKey - Node certificate public key
3737
* @param {NetworkType} networkType - Catapult network type
3838
* @return {PersistentHarvestingDelegationMessage}
3939
*/
4040
public static create(
41-
delegatedPrivateKey: string,
42-
recipientPublicKey: string,
41+
signingPrivateKey: string,
42+
vrfPrivateKey: string,
43+
nodePublicKey: string,
4344
networkType: NetworkType,
4445
): PersistentHarvestingDelegationMessage {
4546
const ephemeralKeypair = Account.generateNewAccount(networkType);
4647
const encrypted =
4748
MessageMarker.PersistentDelegationUnlock +
4849
ephemeralKeypair.publicKey +
49-
Crypto.encode(ephemeralKeypair.privateKey, recipientPublicKey, delegatedPrivateKey, true).toUpperCase();
50+
Crypto.encode(ephemeralKeypair.privateKey, nodePublicKey, signingPrivateKey + vrfPrivateKey, true).toUpperCase();
5051
return new PersistentHarvestingDelegationMessage(encrypted);
5152
}
5253

@@ -62,7 +63,7 @@ export class PersistentHarvestingDelegationMessage extends Message {
6263
/**
6364
*
6465
* @param encryptMessage - Encrypted message to be decrypted
65-
* @param privateKey - Recipient private key
66+
* @param privateKey - Node certificate private key
6667
* @return {string}
6768
*/
6869
public static decrypt(encryptMessage: PersistentHarvestingDelegationMessage, privateKey: string): string {

src/model/transaction/PersistentDelegationRequestTransaction.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,9 @@ export class PersistentDelegationRequestTransaction extends TransferTransaction
2727
* Create a PersistentDelegationRequestTransaction with special message payload
2828
* for presistent harvesting delegation unlocking
2929
* @param deadline - The deadline to include the transaction.
30-
* @param delegatedPrivateKey - The private key of delegated account
31-
* @param recipientPublicKey - The recipient public key
30+
* @param signingPrivateKey - Remote harvester signing private key linked to the main account
31+
* @param vrfPrivateKey - VRF private key linked to the main account
32+
* @param nodePublicKey - Node certificate public key
3233
* @param networkType - The network type.
3334
* @param maxFee - (Optional) Max fee defined by the sender
3435
* @param signature - (Optional) Transaction signature
@@ -37,17 +38,18 @@ export class PersistentDelegationRequestTransaction extends TransferTransaction
3738
*/
3839
public static createPersistentDelegationRequestTransaction(
3940
deadline: Deadline,
40-
delegatedPrivateKey: string,
41-
recipientPublicKey: string,
41+
signingPrivateKey: string,
42+
vrfPrivateKey: string,
43+
nodePublicKey: string,
4244
networkType: NetworkType,
4345
maxFee: UInt64 = new UInt64([0, 0]),
4446
signature?: string,
4547
signer?: PublicAccount,
4648
): PersistentDelegationRequestTransaction {
47-
const message = PersistentHarvestingDelegationMessage.create(delegatedPrivateKey, recipientPublicKey, networkType);
49+
const message = PersistentHarvestingDelegationMessage.create(signingPrivateKey, vrfPrivateKey, nodePublicKey, networkType);
4850
return super.create(
4951
deadline,
50-
Address.createFromPublicKey(recipientPublicKey, networkType),
52+
Address.createFromPublicKey(nodePublicKey, networkType),
5153
[],
5254
message,
5355
networkType,

src/model/transaction/TransferTransaction.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ export class TransferTransaction extends Transaction {
171171
if (this.message.type === MessageType.PersistentHarvestingDelegationMessage) {
172172
if (this.mosaics.length > 0) {
173173
throw new Error('PersistentDelegationRequestTransaction should be created without Mosaic');
174-
} else if (!/^[0-9a-fA-F]{200}$/.test(this.message.payload)) {
174+
} else if (!/^[0-9a-fA-F]{264}$/.test(this.message.payload)) {
175175
throw new Error('PersistentDelegationRequestTransaction message is invalid');
176176
}
177177
}

test/model/message/PersistentHarvestingDelegationMessage.spec.ts

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ describe('PersistentHarvestingDelegationMessage', () => {
2626
let sender: Account;
2727
let recipient: Account;
2828
let recipient_nis: Account;
29-
const delegatedPrivateKey = 'F0AB1010EFEE19EE5373719881DF5123C13E643C519655F7E97347BFF77175BF';
29+
const signingPrivateKey = 'F0AB1010EFEE19EE5373719881DF5123C13E643C519655F7E97347BFF77175BF';
30+
const vrfPrivateKey = '800F35F1CC66C2B62CE9DD9F31003B9B3E5C7A2F381FB8952A294277A1015D83';
3031
before(() => {
3132
sender = Account.createFromPrivateKey('2602F4236B199B3DF762B2AAB46FC3B77D8DDB214F0B62538D3827576C46C108', NetworkType.MIJIN_TEST);
3233
recipient = Account.createFromPrivateKey(
@@ -41,11 +42,12 @@ describe('PersistentHarvestingDelegationMessage', () => {
4142

4243
it('should create a PersistentHarvestingDelegation message', () => {
4344
const encryptedMessage = PersistentHarvestingDelegationMessage.create(
44-
delegatedPrivateKey,
45+
signingPrivateKey,
46+
vrfPrivateKey,
4547
recipient.publicKey,
4648
NetworkType.MIJIN_TEST,
4749
);
48-
expect(encryptedMessage.payload.length).to.be.equal(200);
50+
expect(encryptedMessage.payload.length).to.be.equal(264);
4951
expect(encryptedMessage.type).to.be.equal(MessageType.PersistentHarvestingDelegationMessage);
5052
});
5153

@@ -68,19 +70,21 @@ describe('PersistentHarvestingDelegationMessage', () => {
6870

6971
it('should create and decrypt message', () => {
7072
const encryptedMessage = PersistentHarvestingDelegationMessage.create(
71-
delegatedPrivateKey,
73+
signingPrivateKey,
74+
vrfPrivateKey,
7275
recipient.publicKey,
7376
NetworkType.MIJIN_TEST,
7477
);
7578
const plainMessage = PersistentHarvestingDelegationMessage.decrypt(encryptedMessage, recipient.privateKey);
76-
expect(plainMessage).to.be.equal(delegatedPrivateKey);
79+
expect(plainMessage).to.be.equal(signingPrivateKey + vrfPrivateKey);
7780
});
7881

7982
it('return decrepted message reading from message payload', () => {
8083
const generationHash = '57F7DA205008026C776CB6AED843393F04CD458E0AA2D9F1D5F31A402072B2D6';
8184
const tx = PersistentDelegationRequestTransaction.createPersistentDelegationRequestTransaction(
8285
Deadline.create(),
83-
delegatedPrivateKey,
86+
signingPrivateKey,
87+
vrfPrivateKey,
8488
recipient.publicKey,
8589
NetworkType.MIJIN_TEST,
8690
);
@@ -89,16 +93,17 @@ describe('PersistentHarvestingDelegationMessage', () => {
8993
signedTransaction.payload.substring(322, signedTransaction.payload.length),
9094
);
9195
const plainMessage = PersistentHarvestingDelegationMessage.decrypt(encryptMessage, recipient.privateKey);
92-
expect(plainMessage).to.be.equal(delegatedPrivateKey);
96+
expect(plainMessage).to.be.equal(signingPrivateKey + vrfPrivateKey);
9397
});
9498

9599
it('should encrypt and decrypt message using NIS1 schema', () => {
96100
const encryptedMessage = PersistentHarvestingDelegationMessage.create(
97-
delegatedPrivateKey,
101+
signingPrivateKey,
102+
vrfPrivateKey,
98103
recipient_nis.publicKey,
99104
NetworkType.TEST_NET,
100105
);
101106
const plainMessage = PersistentHarvestingDelegationMessage.decrypt(encryptedMessage, recipient_nis.privateKey);
102-
expect(plainMessage).to.be.equal(delegatedPrivateKey);
107+
expect(plainMessage).to.be.equal(signingPrivateKey + vrfPrivateKey);
103108
});
104109
});

test/model/transaction/PersistentDelegationRequestTransaction.spec.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import { TestingAccount } from '../../conf/conf.spec';
2727
describe('PersistentDelegationRequestTransaction', () => {
2828
let account: Account;
2929
const delegatedPrivateKey = '8A78C9E9B0E59D0F74C0D47AB29FBD523C706293A3FA9CD9FE0EEB2C10EA924A';
30+
const vrfPrivateKey = '800F35F1CC66C2B62CE9DD9F31003B9B3E5C7A2F381FB8952A294277A1015D83';
3031
const recipientPublicKey = '9DBF67474D6E1F8B131B4EB1F5BA0595AFFAE1123607BC1048F342193D7E669F';
3132
const generationHash = '57F7DA205008026C776CB6AED843393F04CD458E0AA2D9F1D5F31A402072B2D6';
3233
const messageMarker = MessageMarker.PersistentDelegationUnlock;
@@ -39,6 +40,7 @@ describe('PersistentDelegationRequestTransaction', () => {
3940
const persistentDelegationRequestTransaction = PersistentDelegationRequestTransaction.createPersistentDelegationRequestTransaction(
4041
Deadline.create(),
4142
delegatedPrivateKey,
43+
vrfPrivateKey,
4244
recipientPublicKey,
4345
NetworkType.MIJIN_TEST,
4446
);
@@ -51,6 +53,7 @@ describe('PersistentDelegationRequestTransaction', () => {
5153
const persistentDelegationRequestTransaction = PersistentDelegationRequestTransaction.createPersistentDelegationRequestTransaction(
5254
Deadline.create(),
5355
delegatedPrivateKey,
56+
vrfPrivateKey,
5457
recipientPublicKey,
5558
NetworkType.MIJIN_TEST,
5659
new UInt64([1, 0]),
@@ -64,11 +67,12 @@ describe('PersistentDelegationRequestTransaction', () => {
6467
const persistentDelegationRequestTransaction = PersistentDelegationRequestTransaction.createPersistentDelegationRequestTransaction(
6568
Deadline.create(),
6669
delegatedPrivateKey,
70+
vrfPrivateKey,
6771
recipientPublicKey,
6872
NetworkType.MIJIN_TEST,
6973
);
7074

71-
expect(persistentDelegationRequestTransaction.message.payload.length).to.be.equal(184 + messageMarker.length);
75+
expect(persistentDelegationRequestTransaction.message.payload.length).to.be.equal(248 + messageMarker.length);
7276
expect(persistentDelegationRequestTransaction.message.payload.includes(messageMarker)).to.be.true;
7377
expect(persistentDelegationRequestTransaction.mosaics.length).to.be.equal(0);
7478
expect(persistentDelegationRequestTransaction.recipientAddress).to.be.instanceof(Address);
@@ -90,6 +94,7 @@ describe('PersistentDelegationRequestTransaction', () => {
9094
PersistentDelegationRequestTransaction.createPersistentDelegationRequestTransaction(
9195
Deadline.create(),
9296
'abc',
97+
vrfPrivateKey,
9398
recipientPublicKey,
9499
NetworkType.MIJIN_TEST,
95100
new UInt64([1, 0]),

test/model/transaction/TransferTransaction.spec.ts

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ describe('TransferTransaction', () => {
4444
let account: Account;
4545
const generationHash = '57F7DA205008026C776CB6AED843393F04CD458E0AA2D9F1D5F31A402072B2D6';
4646
const delegatedPrivateKey = '8A78C9E9B0E59D0F74C0D47AB29FBD523C706293A3FA9CD9FE0EEB2C10EA924A';
47+
const vrfPrivateKey = '800F35F1CC66C2B62CE9DD9F31003B9B3E5C7A2F381FB8952A294277A1015D83';
4748
const recipientPublicKey = '9DBF67474D6E1F8B131B4EB1F5BA0595AFFAE1123607BC1048F342193D7E669F';
4849
const messageMarker = MessageMarker.PersistentDelegationUnlock;
4950
let statement: Statement;
@@ -252,7 +253,7 @@ describe('TransferTransaction', () => {
252253
Deadline.create(),
253254
Address.createFromRawAddress('SATNE7Q5BITMUTRRN6IB4I7FLSDRDWZA34I2PMQ'),
254255
[],
255-
PersistentHarvestingDelegationMessage.create(delegatedPrivateKey, recipientPublicKey, NetworkType.MIJIN_TEST),
256+
PersistentHarvestingDelegationMessage.create(delegatedPrivateKey, vrfPrivateKey, recipientPublicKey, NetworkType.MIJIN_TEST),
256257
NetworkType.MIJIN_TEST,
257258
);
258259

@@ -264,10 +265,10 @@ describe('TransferTransaction', () => {
264265
Deadline.create(),
265266
Address.createFromRawAddress('SATNE7Q5BITMUTRRN6IB4I7FLSDRDWZA34I2PMQ'),
266267
[],
267-
PersistentHarvestingDelegationMessage.create(delegatedPrivateKey, recipientPublicKey, NetworkType.MIJIN_TEST),
268+
PersistentHarvestingDelegationMessage.create(delegatedPrivateKey, vrfPrivateKey, recipientPublicKey, NetworkType.MIJIN_TEST),
268269
NetworkType.MIJIN_TEST,
269270
);
270-
expect(transferTransaction.message.payload.length).to.be.equal(184 + messageMarker.length);
271+
expect(transferTransaction.message.payload.length).to.be.equal(248 + messageMarker.length);
271272
expect(transferTransaction.message.payload.includes(messageMarker)).to.be.true;
272273
expect(transferTransaction.mosaics.length).to.be.equal(0);
273274
expect(transferTransaction.recipientAddress).to.be.instanceof(Address);
@@ -285,7 +286,12 @@ describe('TransferTransaction', () => {
285286
Deadline.create(),
286287
Address.createFromRawAddress('SATNE7Q5BITMUTRRN6IB4I7FLSDRDWZA34I2PMQ'),
287288
[NetworkCurrencyLocal.createRelative(100)],
288-
PersistentHarvestingDelegationMessage.create(delegatedPrivateKey, recipientPublicKey, NetworkType.MIJIN_TEST),
289+
PersistentHarvestingDelegationMessage.create(
290+
delegatedPrivateKey,
291+
vrfPrivateKey,
292+
recipientPublicKey,
293+
NetworkType.MIJIN_TEST,
294+
),
289295
NetworkType.MIJIN_TEST,
290296
);
291297
}).to.throw(Error, 'PersistentDelegationRequestTransaction should be created without Mosaic');
@@ -297,7 +303,7 @@ describe('TransferTransaction', () => {
297303
Deadline.create(),
298304
Address.createFromRawAddress('SATNE7Q5BITMUTRRN6IB4I7FLSDRDWZA34I2PMQ'),
299305
[NetworkCurrencyLocal.createRelative(100)],
300-
PersistentHarvestingDelegationMessage.create('abc', recipientPublicKey, NetworkType.MIJIN_TEST),
306+
PersistentHarvestingDelegationMessage.create('abc', vrfPrivateKey, recipientPublicKey, NetworkType.MIJIN_TEST),
301307
NetworkType.MIJIN_TEST,
302308
);
303309
}).to.throw();
@@ -309,7 +315,12 @@ describe('TransferTransaction', () => {
309315
Deadline.create(),
310316
Address.createFromRawAddress('SATNE7Q5BITMUTRRN6IB4I7FLSDRDWZA34I2PMQ'),
311317
[NetworkCurrencyLocal.createRelative(100)],
312-
PersistentHarvestingDelegationMessage.create(delegatedPrivateKey, recipientPublicKey, NetworkType.MIJIN_TEST),
318+
PersistentHarvestingDelegationMessage.create(
319+
delegatedPrivateKey,
320+
vrfPrivateKey,
321+
recipientPublicKey,
322+
NetworkType.MIJIN_TEST,
323+
),
313324
NetworkType.MIJIN_TEST,
314325
);
315326
}).to.throw();

0 commit comments

Comments
 (0)