Skip to content

Commit 8a74ba6

Browse files
rg911fboucquez
andauthored
Voting key modification (#610)
* Fixed #604 - Modify votingkey transaction * Fixed #604 - Modify votingkey transaction * Fixed #604 - Modify votingkey transaction * Updated catbuffer version * Fixed #604 - Modify votingkey transaction * Update catbufer version * Updated openAPI version * Removed requires * typescript-fetch rest client migration * Fixed #604 - Modify votingkey transaction * Updated catbuffer version * Removed requires * Updated accountKeyFlags * SupplementalAccountKeys => SupplementalPublicKeys * Updated getTransactionsById * Fixed supplemental key dto * Fixed e2e test and updated packge verion * Fixed transaction http test Co-authored-by: fboucquez <fboucquez@gmail.com>
1 parent 3640ee6 commit 8a74ba6

37 files changed

+465
-172
lines changed

e2e/infrastructure/IntegrationTestHelper.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,11 @@ import { TransactionService } from '../../src/service/TransactionService';
2727
import { NetworkCurrencyPublic } from '../../src/model/mosaic/NetworkCurrencyPublic';
2828
import { NetworkCurrencyLocal } from '../../src/model/mosaic/NetworkCurrencyLocal';
2929
import { NamespaceId } from '../../src/model/namespace/NamespaceId';
30+
import * as yaml from 'js-yaml';
31+
import * as path from 'path';
32+
import * as fs from 'fs';
3033

3134
export class IntegrationTestHelper {
32-
public readonly yaml = require('js-yaml');
3335
public apiUrl: string;
3436
public repositoryFactory: RepositoryFactory;
3537
public account: Account;
@@ -51,9 +53,7 @@ export class IntegrationTestHelper {
5153

5254
start(): Promise<IntegrationTestHelper> {
5355
return new Promise<IntegrationTestHelper>((resolve, reject) => {
54-
// eslint-disable-next-line @typescript-eslint/no-var-requires
55-
const path = require('path');
56-
require('fs').readFile(path.resolve(__dirname, '../conf/network.conf'), (err, jsonData) => {
56+
fs.readFile(path.resolve(__dirname, '../conf/network.conf'), (err, jsonData: any) => {
5757
if (err) {
5858
return reject(err);
5959
}
@@ -94,15 +94,15 @@ export class IntegrationTestHelper {
9494
const bootstrapRoot =
9595
process.env.CATAPULT_SERVICE_BOOTSTRAP || path.resolve(__dirname, '../../../../catapult-service-bootstrap');
9696
const bootstrapPath = `${bootstrapRoot}/build/generated-addresses/addresses.yaml`;
97-
require('fs').readFile(bootstrapPath, (error: any, yamlData: any) => {
97+
fs.readFile(bootstrapPath, (error: any, yamlData: any) => {
9898
if (error) {
9999
console.log(
100100
`catapult-service-bootstrap generated address could not be loaded from path ${bootstrapPath}. Ignoring and using accounts from network.conf.`,
101101
);
102102
return resolve(this);
103103
} else {
104104
console.log(`catapult-service-bootstrap generated address loaded from path ${bootstrapPath}.`);
105-
const parsedYaml = this.yaml.safeLoad(yamlData);
105+
const parsedYaml = yaml.safeLoad(yamlData);
106106
this.account = this.createAccount(parsedYaml.nemesis_addresses[0]);
107107
this.account2 = this.createAccount(parsedYaml.nemesis_addresses[1]);
108108
this.account3 = this.createAccount(parsedYaml.nemesis_addresses[2]);

e2e/infrastructure/MetadataHttp.spec.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,7 @@ describe('MetadataHttp', () => {
264264

265265
describe('getNamespaceMetadata', () => {
266266
it('should return metadata given a namespaceId', async () => {
267+
await new Promise((resolve) => setTimeout(resolve, 3000));
267268
const metadata = await metadataRepository.getNamespaceMetadata(namespaceId).toPromise();
268269
expect(metadata.length).to.be.greaterThan(0);
269270
expect(metadata[0].metadataEntry.scopedMetadataKey.toString()).to.be.equal('6');

e2e/infrastructure/TransactionHttp.spec.ts

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,10 @@ import { MosaicRestrictionFlag } from '../../src/model/restriction/MosaicRestric
7676
import { OperationRestrictionFlag } from '../../src/model/restriction/OperationRestrictionFlag';
7777
import { TransactionGroup } from '../../src/infrastructure/TransactionGroup';
7878
import { TransactionStatusRepository } from '../../src/infrastructure/TransactionStatusRepository';
79-
80-
// eslint-disable-next-line @typescript-eslint/no-var-requires
81-
const CryptoJS = require('crypto-js');
79+
import * as ripemd160 from 'ripemd160';
80+
import { sha256 } from 'js-sha256';
81+
import * as secureRandom from 'secure-random';
82+
import * as CryptoJS from 'crypto-js';
8283

8384
describe('TransactionHttp', () => {
8485
let transactionHash: string;
@@ -101,12 +102,6 @@ describe('TransactionHttp', () => {
101102
let transactionRepository: TransactionRepository;
102103
let transactionStatusRepository: TransactionStatusRepository;
103104
let votingKey: string;
104-
// eslint-disable-next-line @typescript-eslint/no-var-requires
105-
const secureRandom = require('secure-random');
106-
// eslint-disable-next-line @typescript-eslint/no-var-requires
107-
const sha256 = require('js-sha256');
108-
// eslint-disable-next-line @typescript-eslint/no-var-requires
109-
const ripemd160 = require('ripemd160');
110105

111106
const remoteAccount = Account.generateNewAccount(helper.networkType);
112107

@@ -737,6 +732,8 @@ describe('TransactionHttp', () => {
737732
const votingLinkTransaction = VotingKeyLinkTransaction.create(
738733
Deadline.create(),
739734
votingKey,
735+
UInt64.fromUint(100),
736+
UInt64.fromUint(300),
740737
LinkAction.Link,
741738
networkType,
742739
helper.maxFee,
@@ -745,6 +742,8 @@ describe('TransactionHttp', () => {
745742

746743
return helper.announce(signedTransaction).then((transaction: VotingKeyLinkTransaction) => {
747744
expect(transaction.linkedPublicKey, 'LinkedPublicKey').not.to.be.undefined;
745+
expect(transaction.startPoint, 'StartPoint').not.to.be.undefined;
746+
expect(transaction.endPoint, 'EndPoint').not.to.be.undefined;
748747
expect(transaction.linkAction, 'LinkAction').not.to.be.undefined;
749748
return signedTransaction;
750749
});
@@ -755,6 +754,8 @@ describe('TransactionHttp', () => {
755754
const votingLinkTransaction = VotingKeyLinkTransaction.create(
756755
Deadline.create(),
757756
votingKey,
757+
UInt64.fromUint(100),
758+
UInt64.fromUint(300),
758759
LinkAction.Unlink,
759760
networkType,
760761
helper.maxFee,
@@ -1402,13 +1403,13 @@ describe('TransactionHttp', () => {
14021403

14031404
describe('getTransactionsById', () => {
14041405
it('should return transaction info given array of transactionHash', async () => {
1405-
const transactions = await transactionRepository.getTransactionsById([transactionHash]).toPromise();
1406+
const transactions = await transactionRepository.getTransactionsById([transactionHash], TransactionGroup.Confirmed).toPromise();
14061407
expect(transactions[0].transactionInfo!.hash).to.be.equal(transactionHash);
14071408
expect(transactions[0].transactionInfo!.id).to.be.equal(transactionId);
14081409
});
14091410

14101411
it('should return transaction info given array of transactionId', async () => {
1411-
const transactions = await transactionRepository.getTransactionsById([transactionId]).toPromise();
1412+
const transactions = await transactionRepository.getTransactionsById([transactionId], TransactionGroup.Confirmed).toPromise();
14121413
expect(transactions[0].transactionInfo!.hash).to.be.equal(transactionHash);
14131414
expect(transactions[0].transactionInfo!.id).to.be.equal(transactionId);
14141415
});
@@ -1468,15 +1469,15 @@ describe('TransactionHttp', () => {
14681469
);
14691470
const signedTransaction = aggregateTransaction.signWith(cosignAccount1, generationHash);
14701471
const transactionAnnounceResponse = await transactionRepository.announceAggregateBonded(signedTransaction).toPromise();
1471-
expect(transactionAnnounceResponse.message).to.be.equal('packet 500 was pushed to the network via /transactions/partial');
1472+
expect(transactionAnnounceResponse.message).to.be.equal('packet 256 was pushed to the network via /transactions/partial');
14721473
});
14731474
});
14741475

14751476
describe('announceAggregateBondedCosignature', () => {
14761477
it('should return success when announceAggregateBondedCosignature', async () => {
14771478
const payload = new CosignatureSignedTransaction('', '', '');
14781479
const transactionAnnounceResponse = await transactionRepository.announceAggregateBondedCosignature(payload).toPromise();
1479-
expect(transactionAnnounceResponse.message).to.be.equal('packet 501 was pushed to the network via /transactions/cosignature');
1480+
expect(transactionAnnounceResponse.message).to.be.equal('packet 257 was pushed to the network via /transactions/cosignature');
14801481
});
14811482
});
14821483

package-lock.json

Lines changed: 16 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
"@types/lodash": "^4.14.85",
5454
"@types/long": "^4.0.0",
5555
"@types/mocha": "^2.2.44",
56+
"@types/ripemd160": "^2.0.0",
5657
"@types/request": "^2.47.0",
5758
"@types/request-promise-native": "^1.0.14",
5859
"@types/utf8": "^2.1.6",
@@ -81,7 +82,7 @@
8182
},
8283
"dependencies": {
8384
"bluebird": "^3.7.2",
84-
"catbuffer-typescript": "0.0.21-alpha-202006221403",
85+
"catbuffer-typescript": "0.0.21",
8586
"crypto-js": "^4.0.0",
8687
"diff": "^4.0.2",
8788
"futoin-hkdf": "^1.3.1",
@@ -98,7 +99,7 @@
9899
"ripemd160": "^2.0.2",
99100
"rxjs": "^6.5.3",
100101
"rxjs-compat": "^6.5.3",
101-
"symbol-openapi-typescript-fetch-client": "0.9.3-SNAPSHOT.202006231707",
102+
"symbol-openapi-typescript-fetch-client": "0.9.3",
102103
"tweetnacl": "^1.0.3",
103104
"utf8": "^3.0.0",
104105
"ws": "^7.2.3"

src/core/crypto/Crypto.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,8 @@
1717
import { Convert as convert } from '../format/Convert';
1818
import { KeyPair } from './KeyPair';
1919
import * as utility from './Utilities';
20-
21-
// eslint-disable-next-line @typescript-eslint/no-var-requires
22-
const CryptoJS = require('crypto-js');
20+
import * as crypto from 'crypto';
21+
import * as CryptoJS from 'crypto-js';
2322

2423
export class Crypto {
2524
/**
@@ -183,8 +182,6 @@ export class Crypto {
183182
* @return {Uint8Array}
184183
*/
185184
public static randomBytes = (length: number): any => {
186-
// eslint-disable-next-line @typescript-eslint/no-var-requires
187-
const crypto = require('crypto');
188185
return crypto.randomBytes(length);
189186
};
190187
}

src/core/crypto/Utilities.ts

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,16 @@
1616

1717
import { RawArray as array } from '../format';
1818
import * as nacl from './nacl_catapult';
19-
// eslint-disable-next-line @typescript-eslint/no-var-requires
20-
export const CryptoJS = require('crypto-js');
19+
import * as CryptoJS from 'crypto-js';
20+
import * as hkdf from 'futoin-hkdf';
21+
import { sha512 } from 'js-sha512';
22+
import { WordArray } from 'crypto-js';
23+
2124
export const Key_Size = 32;
2225
export const Signature_Size = 64;
2326
export const Half_Signature_Size = Signature_Size / 2;
2427
export const Hash_Size = 64;
2528
export const Half_Hash_Size = Hash_Size / 2;
26-
// eslint-disable-next-line @typescript-eslint/no-var-requires
27-
export const hkdf = require('futoin-hkdf');
28-
import { sha512 } from 'js-sha512';
29-
import { WordArray } from 'crypto-js';
30-
3129
/**
3230
* Convert an Uint8Array to WordArray
3331
*
@@ -88,7 +86,7 @@ export const catapult_crypto = ((): any => {
8886
const sharedSecret = catapult_crypto.deriveSharedSecret(privateKey, publicKey);
8987
const info = 'catapult';
9088
const hash = 'SHA-256';
91-
return hkdf(sharedSecret, 32, { salt: new Uint8Array(32), info, hash });
89+
return hkdf(sharedSecret, 32, { salt: Buffer.from(new Uint8Array(32)), info, hash });
9290
},
9391

9492
deriveSharedSecret: (privateKey: Uint8Array, publicKey: Uint8Array): Uint8Array => {

src/core/format/RawAddress.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
*/
1616

1717
import { sha3_256 } from 'js-sha3';
18-
import RIPEMD160 = require('ripemd160');
18+
import * as ripemd160 from 'ripemd160';
1919
import { NetworkType } from '../../model/network/NetworkType';
2020
import { Base32 } from './Base32';
2121
import { Convert } from './Convert';
@@ -83,7 +83,7 @@ export class RawAddress {
8383
const publicKeyHash = sha3_256.arrayBuffer(publicKey);
8484

8585
// step 2: ripemd160 hash of (1)
86-
const ripemdHash = new RIPEMD160().update(new Buffer(publicKeyHash)).digest();
86+
const ripemdHash = new ripemd160().update(new Buffer(publicKeyHash)).digest();
8787

8888
// step 3: add network identifier byte in front of (2)
8989
const decodedAddress = new Uint8Array(RawAddress.constants.sizes.addressDecoded);

src/core/utils/LockHashUtils.ts

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

1717
import { sha3_256 } from 'js-sha3';
1818
import { LockHashAlgorithm } from '../../model/transaction/LockHashAlgorithm';
19-
19+
import * as ripemd160 from 'ripemd160';
20+
import { sha256 } from 'js-sha256';
2021
/**
2122
* Hash utilities for SecretLock hashing
2223
*/
2324
export class LockHashUtils {
24-
private static sha256 = require('js-sha256');
25-
private static ripemd160 = require('ripemd160');
2625
/**
2726
* Perform SHA3_256 hash
2827
* @param input buffer to be hashed
@@ -38,8 +37,8 @@ export class LockHashUtils {
3837
* @returns {string} Hash in hexidecimal format
3938
*/
4039
public static Op_Hash_256(input: Uint8Array): string {
41-
const hash = LockHashUtils.sha256(input, 'hex');
42-
return LockHashUtils.sha256(Buffer.from(hash, 'hex')).toUpperCase();
40+
const hash = sha256(input);
41+
return sha256(Buffer.from(hash, 'hex')).toUpperCase();
4342
}
4443

4544
/**
@@ -48,8 +47,8 @@ export class LockHashUtils {
4847
* @returns {string} Hash in hexidecimal format
4948
*/
5049
public static Op_Hash_160(input: Uint8Array): string {
51-
const sha256Hash = LockHashUtils.sha256(input);
52-
return new LockHashUtils.ripemd160().update(Buffer.from(sha256Hash, 'hex')).digest('hex').toUpperCase();
50+
const sha256Hash = sha256(input);
51+
return new ripemd160().update(Buffer.from(sha256Hash, 'hex')).digest('hex').toUpperCase();
5352
}
5453

5554
/**

src/infrastructure/AccountHttp.ts

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,16 @@
1717
import { Observable } from 'rxjs';
1818
import { AccountInfoDTO, AccountRoutesApi } from 'symbol-openapi-typescript-fetch-client';
1919
import { AccountInfo } from '../model/account/AccountInfo';
20-
import { AccountKey } from '../model/account/AccountKey';
2120
import { ActivityBucket } from '../model/account/ActivityBucket';
2221
import { Address } from '../model/account/Address';
2322
import { Mosaic } from '../model/mosaic/Mosaic';
2423
import { MosaicId } from '../model/mosaic/MosaicId';
2524
import { UInt64 } from '../model/UInt64';
2625
import { AccountRepository } from './AccountRepository';
2726
import { Http } from './Http';
27+
import { SupplementalPublicKeys } from '../model/account/SupplementalPublicKeys';
28+
import { AccountLinkPublicKey } from '../model/account/AccountLinkPublicKey';
29+
import { AccountLinkVotingKey } from '../model/account/AccountLinkVotingKey';
2830

2931
/**
3032
* Account http repository.
@@ -83,7 +85,27 @@ export class AccountHttp extends Http implements AccountRepository {
8385
dto.account.publicKey,
8486
UInt64.fromNumericString(dto.account.publicKeyHeight),
8587
dto.account.accountType.valueOf(),
86-
dto.account.supplementalAccountKeys.map((key) => new AccountKey(key.keyType.valueOf(), key.key)),
88+
new SupplementalPublicKeys(
89+
dto.account.supplementalPublicKeys.linked
90+
? new AccountLinkPublicKey(dto.account.supplementalPublicKeys.linked?.publicKey)
91+
: undefined,
92+
dto.account.supplementalPublicKeys.node
93+
? new AccountLinkPublicKey(dto.account.supplementalPublicKeys.node?.publicKey)
94+
: undefined,
95+
dto.account.supplementalPublicKeys.vrf
96+
? new AccountLinkPublicKey(dto.account.supplementalPublicKeys.vrf?.publicKey)
97+
: undefined,
98+
dto.account.supplementalPublicKeys.voting
99+
? dto.account.supplementalPublicKeys.voting?.publicKeys.map(
100+
(v) =>
101+
new AccountLinkVotingKey(
102+
v.publicKey,
103+
UInt64.fromNumericString(v.startPoint),
104+
UInt64.fromNumericString(v.endPoint),
105+
),
106+
)
107+
: undefined,
108+
),
87109
dto.account.activityBuckets.map((bucket) => {
88110
return new ActivityBucket(
89111
UInt64.fromNumericString(bucket.startHeight),

0 commit comments

Comments
 (0)