Skip to content

Commit 0d24af3

Browse files
committed
JAV-67 [Github #300] Fixed PersistentDelegationRequestTransaction
1 parent 61b3837 commit 0d24af3

File tree

5 files changed

+47
-27
lines changed

5 files changed

+47
-27
lines changed

src/model/message/PersistentHarvestingDelegationMessage.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,17 +32,19 @@ export class PersistentHarvestingDelegationMessage extends Message {
3232

3333
/**
3434
*
35-
* @param harvesterPublicKey - Haverster account public key
36-
* @param privateKey - Sender private key
35+
* @param delegatedPrivateKey - Private key of delegated account
36+
* @param senderPrivateKey - Sender private key
37+
* @param recipientPrivateKey - Recipient public key
3738
* @param {NetworkType} networkType - Catapult network type
3839
* @return {PersistentHarvestingDelegationMessage}
3940
*/
40-
public static create(harvesterPublicKey: string,
41-
privateKey: string,
41+
public static create(delegatedPrivateKey: string,
42+
senderPrivateKey: string,
43+
recipientPublicKey: string,
4244
networkType: NetworkType): PersistentHarvestingDelegationMessage {
4345
const signSchema = SHA3Hasher.resolveSignSchema(networkType);
4446
const encrypted = MessageMarker.PersistentDelegationUnlock +
45-
Crypto.encode(privateKey, harvesterPublicKey, harvesterPublicKey, signSchema, true).toUpperCase();
47+
Crypto.encode(senderPrivateKey, recipientPublicKey, delegatedPrivateKey, signSchema, true).toUpperCase();
4648
return new PersistentHarvestingDelegationMessage(encrypted);
4749
}
4850

src/model/transaction/PersistentDelegationRequestTransaction.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,19 +26,22 @@ export class PersistentDelegationRequestTransaction extends TransferTransaction
2626
* Create a PersistentDelegationRequestTransaction with special message payload
2727
* for presistent harvesting delegation unlocking
2828
* @param deadline - The deadline to include the transaction.
29-
* @param HarvestePublicKey - The harvester public key
29+
* @param delegatedPrivateKey - The private key of delegated account
30+
* @param recipientPublicKey - The recipient public key
3031
* @param senderPrivateKey - The sender's private key
3132
* @param networkType - The network type.
3233
* @param maxFee - (Optional) Max fee defined by the sender
3334
* @returns {TransferTransaction}
3435
*/
3536
public static createPersistentDelegationRequestTransaction(
3637
deadline: Deadline,
37-
HarvestePublicKey: string,
38+
delegatedPrivateKey: string,
39+
recipientPublicKey: string,
3840
senderPrivateKey: string,
3941
networkType: NetworkType,
4042
maxFee: UInt64 = new UInt64([0, 0])): PersistentDelegationRequestTransaction {
41-
const message = PersistentHarvestingDelegationMessage.create(HarvestePublicKey, senderPrivateKey, networkType);
42-
return super.create(deadline, Address.createFromPublicKey(HarvestePublicKey, networkType), [], message, networkType, maxFee);
43+
const message = PersistentHarvestingDelegationMessage
44+
.create(delegatedPrivateKey, senderPrivateKey, recipientPublicKey, networkType);
45+
return super.create(deadline, Address.createFromPublicKey(recipientPublicKey, networkType), [], message, networkType, maxFee);
4346
}
4447
}

test/model/message/PersistentHarvestingDelegationMessage.spec.ts

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ describe('PersistentHarvestingDelegationMessage', () => {
2929

3030
let sender_nis: Account;
3131
let recipient_nis: Account;
32+
const delegatedPrivateKey = 'F0AB1010EFEE19EE5373719881DF5123C13E643C519655F7E97347BFF77175BF';
3233
before(() => {
3334
sender = Account.createFromPrivateKey('2602F4236B199B3DF762B2AAB46FC3B77D8DDB214F0B62538D3827576C46C108',
3435
NetworkType.MIJIN_TEST);
@@ -43,7 +44,8 @@ describe('PersistentHarvestingDelegationMessage', () => {
4344

4445
it('should create a PersistentHarvestingDelegation message', () => {
4546
const encryptedMessage =
46-
PersistentHarvestingDelegationMessage.create(recipient.publicKey, sender.privateKey, NetworkType.MIJIN_TEST);
47+
PersistentHarvestingDelegationMessage
48+
.create(delegatedPrivateKey, sender.privateKey, recipient.publicKey, NetworkType.MIJIN_TEST);
4749
expect(encryptedMessage.payload.length).to.be.equal(208);
4850
expect(encryptedMessage.type).to.be.equal(MessageType.PersistentHarvestingDelegationMessage);
4951
});
@@ -66,17 +68,19 @@ describe('PersistentHarvestingDelegationMessage', () => {
6668

6769
it('should create and decrypt message', () => {
6870
const encryptedMessage =
69-
PersistentHarvestingDelegationMessage.create(recipient.publicKey, sender.privateKey, NetworkType.MIJIN_TEST);
71+
PersistentHarvestingDelegationMessage
72+
.create(delegatedPrivateKey, sender.privateKey, recipient.publicKey, NetworkType.MIJIN_TEST);
7073
const plainMessage =
7174
PersistentHarvestingDelegationMessage.decrypt(encryptedMessage, recipient.privateKey, sender.publicKey, NetworkType.MIJIN_TEST);
72-
expect(plainMessage).to.be.equal(recipient.publicKey);
75+
expect(plainMessage).to.be.equal(delegatedPrivateKey);
7376
});
7477

7578
it('should return should return decrepted message reading from message payload', () => {
7679
const generationHash = '57F7DA205008026C776CB6AED843393F04CD458E0AA2D9F1D5F31A402072B2D6';
7780
const tx =
7881
PersistentDelegationRequestTransaction.createPersistentDelegationRequestTransaction(
7982
Deadline.create(),
83+
delegatedPrivateKey,
8084
recipient.publicKey,
8185
sender.privateKey,
8286
NetworkType.MIJIN_TEST,
@@ -87,18 +91,19 @@ describe('PersistentHarvestingDelegationMessage', () => {
8791
.createFromPayload(signedTransaction.payload.substring(298, signedTransaction.payload.length));
8892
const plainMessage =
8993
PersistentHarvestingDelegationMessage.decrypt(encryptMessage, recipient.privateKey, sender.publicKey, NetworkType.MIJIN_TEST);
90-
expect(plainMessage).to.be.equal(recipient.publicKey);
94+
expect(plainMessage).to.be.equal(delegatedPrivateKey);
9195
});
9296

9397
it('should encrypt and decrypt message using NIS1 schema', () => {
9498
const encryptedMessage =
95-
PersistentHarvestingDelegationMessage.create(recipient_nis.publicKey, sender_nis.privateKey, NetworkType.TEST_NET);
99+
PersistentHarvestingDelegationMessage
100+
.create(delegatedPrivateKey, sender_nis.privateKey, recipient_nis.publicKey, NetworkType.TEST_NET);
96101
const plainMessage =
97102
PersistentHarvestingDelegationMessage.decrypt(encryptedMessage,
98103
recipient_nis.privateKey,
99104
sender_nis.publicKey,
100105
NetworkType.TEST_NET);
101-
expect(plainMessage).to.be.equal(recipient_nis.publicKey);
106+
expect(plainMessage).to.be.equal(delegatedPrivateKey);
102107
});
103108

104109
});

test/model/transaction/PersistentDelegationRequestTransaction.spec.ts

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ import { TestingAccount } from '../../conf/conf.spec';
2727

2828
describe('PersistentDelegationRequestTransaction', () => {
2929
let account: Account;
30-
const harvesterPublicKey = '8A78C9E9B0E59D0F74C0D47AB29FBD523C706293A3FA9CD9FE0EEB2C10EA924A';
30+
const delegatedPrivateKey = '8A78C9E9B0E59D0F74C0D47AB29FBD523C706293A3FA9CD9FE0EEB2C10EA924A';
31+
const recipientPublicKey = '9DBF67474D6E1F8B131B4EB1F5BA0595AFFAE1123607BC1048F342193D7E669F';
3132
const generationHash = '57F7DA205008026C776CB6AED843393F04CD458E0AA2D9F1D5F31A402072B2D6';
3233
const messageMarker = 'FECC71C764BFE598';
3334

@@ -39,7 +40,8 @@ describe('PersistentDelegationRequestTransaction', () => {
3940
const persistentDelegationRequestTransaction =
4041
PersistentDelegationRequestTransaction.createPersistentDelegationRequestTransaction(
4142
Deadline.create(),
42-
harvesterPublicKey,
43+
delegatedPrivateKey,
44+
recipientPublicKey,
4345
account.privateKey,
4446
NetworkType.MIJIN_TEST,
4547
);
@@ -52,7 +54,8 @@ describe('PersistentDelegationRequestTransaction', () => {
5254
const persistentDelegationRequestTransaction =
5355
PersistentDelegationRequestTransaction.createPersistentDelegationRequestTransaction(
5456
Deadline.create(),
55-
harvesterPublicKey,
57+
delegatedPrivateKey,
58+
recipientPublicKey,
5659
account.privateKey,
5760
NetworkType.MIJIN_TEST,
5861
new UInt64([1, 0]),
@@ -66,7 +69,8 @@ describe('PersistentDelegationRequestTransaction', () => {
6669
const persistentDelegationRequestTransaction =
6770
PersistentDelegationRequestTransaction.createPersistentDelegationRequestTransaction(
6871
Deadline.create(),
69-
harvesterPublicKey,
72+
delegatedPrivateKey,
73+
recipientPublicKey,
7074
account.privateKey,
7175
NetworkType.MIJIN_TEST,
7276
);
@@ -76,7 +80,7 @@ describe('PersistentDelegationRequestTransaction', () => {
7680
expect(persistentDelegationRequestTransaction.mosaics.length).to.be.equal(0);
7781
expect(persistentDelegationRequestTransaction.recipientAddress).to.be.instanceof(Address);
7882
expect((persistentDelegationRequestTransaction.recipientAddress as Address).plain())
79-
.to.be.equal('SAMA2UEQNAQ45DWYDNJVLPWKQJDAHFZIVLWACIGN');
83+
.to.be.equal('SDBC4JE7GTJAKN2XJCQWWRJMYA35AFOYQBATXOUA');
8084

8185
const signedTransaction = persistentDelegationRequestTransaction.signWith(account, generationHash);
8286

@@ -91,6 +95,7 @@ describe('PersistentDelegationRequestTransaction', () => {
9195
PersistentDelegationRequestTransaction.createPersistentDelegationRequestTransaction(
9296
Deadline.create(),
9397
'abc',
98+
recipientPublicKey,
9499
account.privateKey,
95100
NetworkType.MIJIN_TEST,
96101
new UInt64([1, 0]),
@@ -102,7 +107,8 @@ describe('PersistentDelegationRequestTransaction', () => {
102107
expect(() => {
103108
PersistentDelegationRequestTransaction.createPersistentDelegationRequestTransaction(
104109
Deadline.create(),
105-
harvesterPublicKey,
110+
delegatedPrivateKey,
111+
recipientPublicKey,
106112
'abc',
107113
NetworkType.MIJIN_TEST,
108114
new UInt64([1, 0]),

test/model/transaction/TransferTransaction.spec.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ import { TestingAccount } from '../../conf/conf.spec';
3131
describe('TransferTransaction', () => {
3232
let account: Account;
3333
const generationHash = '57F7DA205008026C776CB6AED843393F04CD458E0AA2D9F1D5F31A402072B2D6';
34-
const harvesterPublicKey = '8A78C9E9B0E59D0F74C0D47AB29FBD523C706293A3FA9CD9FE0EEB2C10EA924A';
34+
const delegatedPrivateKey = '8A78C9E9B0E59D0F74C0D47AB29FBD523C706293A3FA9CD9FE0EEB2C10EA924A';
35+
const recipientPublicKey = '9DBF67474D6E1F8B131B4EB1F5BA0595AFFAE1123607BC1048F342193D7E669F';
3536
const messageMarker = 'FECC71C764BFE598';
3637
before(() => {
3738
account = TestingAccount;
@@ -229,7 +230,8 @@ describe('TransferTransaction', () => {
229230
Deadline.create(),
230231
Address.createFromRawAddress('SBILTA367K2LX2FEXG5TFWAS7GEFYAGY7QLFBYKC'),
231232
[],
232-
PersistentHarvestingDelegationMessage.create(harvesterPublicKey, account.privateKey, NetworkType.MIJIN_TEST),
233+
PersistentHarvestingDelegationMessage
234+
.create(delegatedPrivateKey, account.privateKey, recipientPublicKey, NetworkType.MIJIN_TEST),
233235
NetworkType.MIJIN_TEST,
234236
);
235237

@@ -241,7 +243,8 @@ describe('TransferTransaction', () => {
241243
Deadline.create(),
242244
Address.createFromRawAddress('SBILTA367K2LX2FEXG5TFWAS7GEFYAGY7QLFBYKC'),
243245
[],
244-
PersistentHarvestingDelegationMessage.create(harvesterPublicKey, account.privateKey, NetworkType.MIJIN_TEST),
246+
PersistentHarvestingDelegationMessage
247+
.create(delegatedPrivateKey, account.privateKey, recipientPublicKey, NetworkType.MIJIN_TEST),
245248
NetworkType.MIJIN_TEST,
246249
);
247250

@@ -266,7 +269,8 @@ describe('TransferTransaction', () => {
266269
Deadline.create(),
267270
Address.createFromRawAddress('SBILTA367K2LX2FEXG5TFWAS7GEFYAGY7QLFBYKC'),
268271
[NetworkCurrencyMosaic.createRelative(100)],
269-
PersistentHarvestingDelegationMessage.create(harvesterPublicKey, account.privateKey, NetworkType.MIJIN_TEST),
272+
PersistentHarvestingDelegationMessage
273+
.create(delegatedPrivateKey, account.privateKey, recipientPublicKey, NetworkType.MIJIN_TEST),
270274
NetworkType.MIJIN_TEST,
271275
);
272276
}).to.throw(Error, 'PersistentDelegationRequestTransaction should be created without Mosaic');
@@ -278,7 +282,7 @@ describe('TransferTransaction', () => {
278282
Deadline.create(),
279283
Address.createFromRawAddress('SBILTA367K2LX2FEXG5TFWAS7GEFYAGY7QLFBYKC'),
280284
[NetworkCurrencyMosaic.createRelative(100)],
281-
PersistentHarvestingDelegationMessage.create('abc', account.privateKey, NetworkType.MIJIN_TEST),
285+
PersistentHarvestingDelegationMessage.create('abc', account.privateKey, recipientPublicKey, NetworkType.MIJIN_TEST),
282286
NetworkType.MIJIN_TEST,
283287
);
284288
}).to.throw();
@@ -290,7 +294,7 @@ describe('TransferTransaction', () => {
290294
Deadline.create(),
291295
Address.createFromRawAddress('SBILTA367K2LX2FEXG5TFWAS7GEFYAGY7QLFBYKC'),
292296
[NetworkCurrencyMosaic.createRelative(100)],
293-
PersistentHarvestingDelegationMessage.create(harvesterPublicKey, 'abc', NetworkType.MIJIN_TEST),
297+
PersistentHarvestingDelegationMessage.create(delegatedPrivateKey, 'abc', recipientPublicKey, NetworkType.MIJIN_TEST),
294298
NetworkType.MIJIN_TEST,
295299
);
296300
}).to.throw();

0 commit comments

Comments
 (0)