Skip to content

Commit 5f60492

Browse files
authored
Fixed #571 (#572)
- Added signature and signer to loadFromPayload
1 parent d2b0ff1 commit 5f60492

27 files changed

+1433
-56
lines changed

src/model/transaction/AccountAddressRestrictionTransaction.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ export class AccountAddressRestrictionTransaction extends Transaction {
5050
* @param restrictionDeletions - Account restriction deletions.
5151
* @param networkType - The network type.
5252
* @param maxFee - (Optional) Max fee defined by the sender
53+
* @param signature - (Optional) Transaction signature
54+
* @param signer - (Optional) Signer public account
5355
* @returns {AccountAddressRestrictionTransaction}
5456
*/
5557
public static create(
@@ -59,6 +61,8 @@ export class AccountAddressRestrictionTransaction extends Transaction {
5961
restrictionDeletions: (Address | NamespaceId)[],
6062
networkType: NetworkType,
6163
maxFee: UInt64 = new UInt64([0, 0]),
64+
signature?: string,
65+
signer?: PublicAccount,
6266
): AccountAddressRestrictionTransaction {
6367
return new AccountAddressRestrictionTransaction(
6468
networkType,
@@ -68,6 +72,8 @@ export class AccountAddressRestrictionTransaction extends Transaction {
6872
restrictionFlags,
6973
restrictionAdditions,
7074
restrictionDeletions,
75+
signature,
76+
signer,
7177
);
7278
}
7379

@@ -110,6 +116,7 @@ export class AccountAddressRestrictionTransaction extends Transaction {
110116
: AccountAddressRestrictionTransactionBuilder.loadFromBinary(Convert.hexToUint8(payload));
111117
const signerPublicKey = Convert.uint8ToHex(builder.getSignerPublicKey().key);
112118
const networkType = builder.getNetwork().valueOf();
119+
const signature = payload.substring(16, 144);
113120
const transaction = AccountAddressRestrictionTransaction.create(
114121
isEmbedded
115122
? Deadline.create()
@@ -123,6 +130,8 @@ export class AccountAddressRestrictionTransaction extends Transaction {
123130
}),
124131
networkType,
125132
isEmbedded ? new UInt64([0, 0]) : new UInt64((builder as AccountAddressRestrictionTransactionBuilder).fee.amount),
133+
isEmbedded || signature.match(`^[0]+$`) ? undefined : signature,
134+
signerPublicKey.match(`^[0]+$`) ? undefined : PublicAccount.createFromPublicKey(signerPublicKey, networkType),
126135
);
127136
return isEmbedded ? transaction.toAggregate(PublicAccount.createFromPublicKey(signerPublicKey, networkType)) : transaction;
128137
}
@@ -160,8 +169,8 @@ export class AccountAddressRestrictionTransaction extends Transaction {
160169
* @returns {Uint8Array}
161170
*/
162171
protected generateBytes(): Uint8Array {
163-
const signerBuffer = new Uint8Array(32);
164-
const signatureBuffer = new Uint8Array(64);
172+
const signerBuffer = this.signer !== undefined ? Convert.hexToUint8(this.signer.publicKey) : new Uint8Array(32);
173+
const signatureBuffer = this.signature !== undefined ? Convert.hexToUint8(this.signature) : new Uint8Array(64);
165174

166175
const transactionBuilder = new AccountAddressRestrictionTransactionBuilder(
167176
new SignatureDto(signatureBuffer),

src/model/transaction/AccountKeyLinkTransaction.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ export class AccountKeyLinkTransaction extends Transaction {
4646
* @param remotePublicKey - The public key of the remote account.
4747
* @param linkAction - The account link action.
4848
* @param maxFee - (Optional) Max fee defined by the sender
49+
* @param signature - (Optional) Transaction signature
50+
* @param signer - (Optional) Signer public account
4951
* @returns {AccountLinkTransaction}
5052
*/
5153
public static create(
@@ -54,6 +56,8 @@ export class AccountKeyLinkTransaction extends Transaction {
5456
linkAction: LinkAction,
5557
networkType: NetworkType,
5658
maxFee: UInt64 = new UInt64([0, 0]),
59+
signature?: string,
60+
signer?: PublicAccount,
5761
): AccountKeyLinkTransaction {
5862
return new AccountKeyLinkTransaction(
5963
networkType,
@@ -62,6 +66,8 @@ export class AccountKeyLinkTransaction extends Transaction {
6266
maxFee,
6367
remotePublicKey,
6468
linkAction,
69+
signature,
70+
signer,
6571
);
6672
}
6773

@@ -108,12 +114,15 @@ export class AccountKeyLinkTransaction extends Transaction {
108114
: AccountKeyLinkTransactionBuilder.loadFromBinary(Convert.hexToUint8(payload));
109115
const signerPublicKey = Convert.uint8ToHex(builder.getSignerPublicKey().key);
110116
const networkType = builder.getNetwork().valueOf();
117+
const signature = payload.substring(16, 144);
111118
const transaction = AccountKeyLinkTransaction.create(
112119
isEmbedded ? Deadline.create() : Deadline.createFromDTO((builder as AccountKeyLinkTransactionBuilder).getDeadline().timestamp),
113120
Convert.uint8ToHex(builder.getRemotePublicKey().key),
114121
builder.getLinkAction().valueOf(),
115122
networkType,
116123
isEmbedded ? new UInt64([0, 0]) : new UInt64((builder as AccountKeyLinkTransactionBuilder).fee.amount),
124+
isEmbedded || signature.match(`^[0]+$`) ? undefined : signature,
125+
signerPublicKey.match(`^[0]+$`) ? undefined : PublicAccount.createFromPublicKey(signerPublicKey, networkType),
117126
);
118127
return isEmbedded ? transaction.toAggregate(PublicAccount.createFromPublicKey(signerPublicKey, networkType)) : transaction;
119128
}
@@ -139,8 +148,8 @@ export class AccountKeyLinkTransaction extends Transaction {
139148
* @returns {Uint8Array}
140149
*/
141150
protected generateBytes(): Uint8Array {
142-
const signerBuffer = new Uint8Array(32);
143-
const signatureBuffer = new Uint8Array(64);
151+
const signerBuffer = this.signer !== undefined ? Convert.hexToUint8(this.signer.publicKey) : new Uint8Array(32);
152+
const signatureBuffer = this.signature !== undefined ? Convert.hexToUint8(this.signature) : new Uint8Array(64);
144153

145154
const transactionBuilder = new AccountKeyLinkTransactionBuilder(
146155
new SignatureDto(signatureBuffer),

src/model/transaction/AccountMetadataTransaction.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ export class AccountMetadataTransaction extends Transaction {
4949
* You can calculate value as xor(previous-value, new-value).
5050
* If there is no previous value, use directly the new value.
5151
* @param maxFee - (Optional) Max fee defined by the sender
52+
* @param signature - (Optional) Transaction signature
53+
* @param signer - (Optional) Signer public account
5254
* @returns {AccountMetadataTransaction}
5355
*/
5456
public static create(
@@ -59,6 +61,8 @@ export class AccountMetadataTransaction extends Transaction {
5961
value: string,
6062
networkType: NetworkType,
6163
maxFee: UInt64 = new UInt64([0, 0]),
64+
signature?: string,
65+
signer?: PublicAccount,
6266
): AccountMetadataTransaction {
6367
return new AccountMetadataTransaction(
6468
networkType,
@@ -69,6 +73,8 @@ export class AccountMetadataTransaction extends Transaction {
6973
scopedMetadataKey,
7074
valueSizeDelta,
7175
value,
76+
signature,
77+
signer,
7278
);
7379
}
7480

@@ -126,6 +132,7 @@ export class AccountMetadataTransaction extends Transaction {
126132
: AccountMetadataTransactionBuilder.loadFromBinary(Convert.hexToUint8(payload));
127133
const signerPublicKey = Convert.uint8ToHex(builder.getSignerPublicKey().key);
128134
const networkType = builder.getNetwork().valueOf();
135+
const signature = payload.substring(16, 144);
129136
const transaction = AccountMetadataTransaction.create(
130137
isEmbedded ? Deadline.create() : Deadline.createFromDTO((builder as AccountMetadataTransactionBuilder).getDeadline().timestamp),
131138
Convert.uint8ToHex(builder.getTargetPublicKey().key),
@@ -134,6 +141,8 @@ export class AccountMetadataTransaction extends Transaction {
134141
Convert.uint8ToUtf8(builder.getValue()),
135142
networkType,
136143
isEmbedded ? new UInt64([0, 0]) : new UInt64((builder as AccountMetadataTransactionBuilder).fee.amount),
144+
isEmbedded || signature.match(`^[0]+$`) ? undefined : signature,
145+
signerPublicKey.match(`^[0]+$`) ? undefined : PublicAccount.createFromPublicKey(signerPublicKey, networkType),
137146
);
138147
return isEmbedded ? transaction.toAggregate(PublicAccount.createFromPublicKey(signerPublicKey, networkType)) : transaction;
139148
}
@@ -161,8 +170,8 @@ export class AccountMetadataTransaction extends Transaction {
161170
* @returns {Uint8Array}
162171
*/
163172
protected generateBytes(): Uint8Array {
164-
const signerBuffer = new Uint8Array(32);
165-
const signatureBuffer = new Uint8Array(64);
173+
const signerBuffer = this.signer !== undefined ? Convert.hexToUint8(this.signer.publicKey) : new Uint8Array(32);
174+
const signatureBuffer = this.signature !== undefined ? Convert.hexToUint8(this.signature) : new Uint8Array(64);
166175

167176
const transactionBuilder = new AccountMetadataTransactionBuilder(
168177
new SignatureDto(signatureBuffer),

src/model/transaction/AccountMosaicRestrictionTransaction.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ export class AccountMosaicRestrictionTransaction extends Transaction {
5050
* @param restrictionDeletions - Account restriction deletions.
5151
* @param networkType - The network type.
5252
* @param maxFee - (Optional) Max fee defined by the sender
53+
* @param signature - (Optional) Transaction signature
54+
* @param signer - (Optional) Signer public account
5355
* @returns {AccountAddressRestrictionTransaction}
5456
*/
5557
public static create(
@@ -59,6 +61,8 @@ export class AccountMosaicRestrictionTransaction extends Transaction {
5961
restrictionDeletions: (MosaicId | NamespaceId)[],
6062
networkType: NetworkType,
6163
maxFee: UInt64 = new UInt64([0, 0]),
64+
signature?: string,
65+
signer?: PublicAccount,
6266
): AccountMosaicRestrictionTransaction {
6367
return new AccountMosaicRestrictionTransaction(
6468
networkType,
@@ -68,6 +72,8 @@ export class AccountMosaicRestrictionTransaction extends Transaction {
6872
restrictionFlags,
6973
restrictionAdditions,
7074
restrictionDeletions,
75+
signature,
76+
signer,
7177
);
7278
}
7379

@@ -110,6 +116,7 @@ export class AccountMosaicRestrictionTransaction extends Transaction {
110116
: AccountMosaicRestrictionTransactionBuilder.loadFromBinary(Convert.hexToUint8(payload));
111117
const signerPublicKey = Convert.uint8ToHex(builder.getSignerPublicKey().key);
112118
const networkType = builder.getNetwork().valueOf();
119+
const signature = payload.substring(16, 144);
113120
const transaction = AccountMosaicRestrictionTransaction.create(
114121
isEmbedded
115122
? Deadline.create()
@@ -123,6 +130,8 @@ export class AccountMosaicRestrictionTransaction extends Transaction {
123130
}),
124131
networkType,
125132
isEmbedded ? new UInt64([0, 0]) : new UInt64((builder as AccountMosaicRestrictionTransactionBuilder).fee.amount),
133+
isEmbedded || signature.match(`^[0]+$`) ? undefined : signature,
134+
signerPublicKey.match(`^[0]+$`) ? undefined : PublicAccount.createFromPublicKey(signerPublicKey, networkType),
126135
);
127136
return isEmbedded ? transaction.toAggregate(PublicAccount.createFromPublicKey(signerPublicKey, networkType)) : transaction;
128137
}
@@ -160,8 +169,8 @@ export class AccountMosaicRestrictionTransaction extends Transaction {
160169
* @returns {Uint8Array}
161170
*/
162171
protected generateBytes(): Uint8Array {
163-
const signerBuffer = new Uint8Array(32);
164-
const signatureBuffer = new Uint8Array(64);
172+
const signerBuffer = this.signer !== undefined ? Convert.hexToUint8(this.signer.publicKey) : new Uint8Array(32);
173+
const signatureBuffer = this.signature !== undefined ? Convert.hexToUint8(this.signature) : new Uint8Array(64);
165174

166175
const transactionBuilder = new AccountMosaicRestrictionTransactionBuilder(
167176
new SignatureDto(signatureBuffer),

src/model/transaction/AccountOperationRestrictionTransaction.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ export class AccountOperationRestrictionTransaction extends Transaction {
4444
* @param restrictionDeletions - Account restriction deletions.
4545
* @param networkType - The network type.
4646
* @param maxFee - (Optional) Max fee defined by the sender
47+
* @param signature - (Optional) Transaction signature
48+
* @param signer - (Optional) Signer public account
4749
* @returns {AccountOperationRestrictionTransaction}
4850
*/
4951
public static create(
@@ -53,6 +55,8 @@ export class AccountOperationRestrictionTransaction extends Transaction {
5355
restrictionDeletions: TransactionType[],
5456
networkType: NetworkType,
5557
maxFee: UInt64 = new UInt64([0, 0]),
58+
signature?: string,
59+
signer?: PublicAccount,
5660
): AccountOperationRestrictionTransaction {
5761
return new AccountOperationRestrictionTransaction(
5862
networkType,
@@ -62,6 +66,8 @@ export class AccountOperationRestrictionTransaction extends Transaction {
6266
restrictionFlags,
6367
restrictionAdditions,
6468
restrictionDeletions,
69+
signature,
70+
signer,
6571
);
6672
}
6773

@@ -104,6 +110,7 @@ export class AccountOperationRestrictionTransaction extends Transaction {
104110
: AccountOperationRestrictionTransactionBuilder.loadFromBinary(Convert.hexToUint8(payload));
105111
const signer = Convert.uint8ToHex(builder.getSignerPublicKey().key);
106112
const networkType = builder.getNetwork().valueOf();
113+
const signature = payload.substring(16, 144);
107114
const transaction = AccountOperationRestrictionTransaction.create(
108115
isEmbedded
109116
? Deadline.create()
@@ -113,6 +120,8 @@ export class AccountOperationRestrictionTransaction extends Transaction {
113120
builder.getRestrictionDeletions(),
114121
networkType,
115122
isEmbedded ? new UInt64([0, 0]) : new UInt64((builder as AccountOperationRestrictionTransactionBuilder).fee.amount),
123+
isEmbedded || signature.match(`^[0]+$`) ? undefined : signature,
124+
signer.match(`^[0]+$`) ? undefined : PublicAccount.createFromPublicKey(signer, networkType),
116125
);
117126
return isEmbedded ? transaction.toAggregate(PublicAccount.createFromPublicKey(signer, networkType)) : transaction;
118127
}
@@ -150,8 +159,8 @@ export class AccountOperationRestrictionTransaction extends Transaction {
150159
* @returns {Uint8Array}
151160
*/
152161
protected generateBytes(): Uint8Array {
153-
const signerBuffer = new Uint8Array(32);
154-
const signatureBuffer = new Uint8Array(64);
162+
const signerBuffer = this.signer !== undefined ? Convert.hexToUint8(this.signer.publicKey) : new Uint8Array(32);
163+
const signatureBuffer = this.signature !== undefined ? Convert.hexToUint8(this.signature) : new Uint8Array(64);
155164

156165
const transactionBuilder = new AccountOperationRestrictionTransactionBuilder(
157166
new SignatureDto(signatureBuffer),

src/model/transaction/AccountRestrictionTransaction.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import { AccountMosaicRestrictionTransaction } from './AccountMosaicRestrictionT
2525
import { AccountOperationRestrictionTransaction } from './AccountOperationRestrictionTransaction';
2626
import { Deadline } from './Deadline';
2727
import { TransactionType } from './TransactionType';
28+
import { PublicAccount } from '../account/PublicAccount';
2829

2930
export class AccountRestrictionTransaction {
3031
/**
@@ -35,6 +36,8 @@ export class AccountRestrictionTransaction {
3536
* @param restrictionDeletions - Account restriction deletions.
3637
* @param networkType - The network type.
3738
* @param maxFee - (Optional) Max fee defined by the sender
39+
* @param signature - (Optional) Transaction signature
40+
* @param signer - (Optional) Signer public account
3841
* @returns {AccountAddressRestrictionTransaction}
3942
*/
4043
public static createAddressRestrictionModificationTransaction(
@@ -44,6 +47,8 @@ export class AccountRestrictionTransaction {
4447
restrictionDeletions: (Address | NamespaceId)[],
4548
networkType: NetworkType,
4649
maxFee: UInt64 = new UInt64([0, 0]),
50+
signature?: string,
51+
signer?: PublicAccount,
4752
): AccountAddressRestrictionTransaction {
4853
if (
4954
![
@@ -62,6 +67,8 @@ export class AccountRestrictionTransaction {
6267
restrictionDeletions,
6368
networkType,
6469
maxFee,
70+
signature,
71+
signer,
6572
);
6673
}
6774

@@ -73,6 +80,8 @@ export class AccountRestrictionTransaction {
7380
* @param restrictionDeletions - Account restriction deletions.
7481
* @param networkType - The network type.
7582
* @param maxFee - (Optional) Max fee defined by the sender
83+
* @param signature - (Optional) Transaction signature
84+
* @param signer - (Optional) Signer public account
7685
* @returns {AccountMosaicRestrictionTransaction}
7786
*/
7887
public static createMosaicRestrictionModificationTransaction(
@@ -82,6 +91,8 @@ export class AccountRestrictionTransaction {
8291
restrictionDeletions: (MosaicId | NamespaceId)[],
8392
networkType: NetworkType,
8493
maxFee: UInt64 = new UInt64([0, 0]),
94+
signature?: string,
95+
signer?: PublicAccount,
8596
): AccountMosaicRestrictionTransaction {
8697
if (![AccountRestrictionFlags.AllowMosaic, AccountRestrictionFlags.BlockMosaic].includes(restrictionFlags)) {
8798
throw new Error('Restriction type is not allowed.');
@@ -93,6 +104,8 @@ export class AccountRestrictionTransaction {
93104
restrictionDeletions,
94105
networkType,
95106
maxFee,
107+
signature,
108+
signer,
96109
);
97110
}
98111

@@ -104,6 +117,8 @@ export class AccountRestrictionTransaction {
104117
* @param restrictionDeletions - Account restriction deletions.
105118
* @param networkType - The network type.
106119
* @param maxFee - (Optional) Max fee defined by the sender
120+
* @param signature - (Optional) Transaction signature
121+
* @param signer - (Optional) Signer public account
107122
* @returns {AccountOperationRestrictionTransaction}
108123
*/
109124
public static createOperationRestrictionModificationTransaction(
@@ -113,6 +128,8 @@ export class AccountRestrictionTransaction {
113128
restrictionDeletions: TransactionType[],
114129
networkType: NetworkType,
115130
maxFee: UInt64 = new UInt64([0, 0]),
131+
signature?: string,
132+
signer?: PublicAccount,
116133
): AccountOperationRestrictionTransaction {
117134
if (
118135
![AccountRestrictionFlags.AllowOutgoingTransactionType, AccountRestrictionFlags.BlockOutgoingTransactionType].includes(
@@ -128,6 +145,8 @@ export class AccountRestrictionTransaction {
128145
restrictionDeletions,
129146
networkType,
130147
maxFee,
148+
signature,
149+
signer,
131150
);
132151
}
133152
}

0 commit comments

Comments
 (0)