Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion e2e/infrastructure/AccountHttp.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ describe('AccountHttp', () => {
UInt64.fromUint(9),
NetworkType.MIJIN_TEST,
);
namespaceId = new NamespaceId(namespaceName);
namespaceId = new NamespaceId(namespaceName, NetworkType.MIJIN_TEST);
const signedTransaction = registerNamespaceTransaction.signWith(account, generationHash);
listener.confirmed(account.address).subscribe(() => {
done();
Expand Down
2 changes: 1 addition & 1 deletion e2e/infrastructure/Listener.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ describe('Listener', () => {
});
describe('Get network currency mosaic id', () => {
it('get mosaicId', (done) => {
namespaceHttp.getLinkedMosaicId(new NamespaceId('cat.currency')).subscribe((networkMosaicId) => {
namespaceHttp.getLinkedMosaicId(new NamespaceId('cat.currency', NetworkType.MIJIN_TEST)).subscribe((networkMosaicId) => {
networkCurrencyMosaicId = networkMosaicId;
done();
});
Expand Down
4 changes: 2 additions & 2 deletions e2e/infrastructure/MetadataHttp.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ describe('MetadataHttp', () => {
});
it('standalone', (done) => {
const nonce = MosaicNonce.createRandom();
mosaicId = MosaicId.createFromNonce(nonce, account.publicAccount);
mosaicId = MosaicId.createFromNonce(nonce, account.publicAccount, NetworkType.MIJIN_TEST);
const mosaicDefinitionTransaction = MosaicDefinitionTransaction.create(
Deadline.create(),
nonce,
Expand Down Expand Up @@ -135,7 +135,7 @@ describe('MetadataHttp', () => {
UInt64.fromUint(9),
NetworkType.MIJIN_TEST,
);
namespaceId = new NamespaceId(namespaceName);
namespaceId = new NamespaceId(namespaceName, NetworkType.MIJIN_TEST);
const signedTransaction = registerNamespaceTransaction.signWith(account, generationHash);
listener.confirmed(account.address).subscribe(() => {
done();
Expand Down
4 changes: 2 additions & 2 deletions e2e/infrastructure/MosaicHttp.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ describe('MosaicHttp', () => {
});
it('Announce MosaicDefinitionTransaction', (done) => {
const nonce = MosaicNonce.createRandom();
mosaicId = MosaicId.createFromNonce(nonce, account.publicAccount);
mosaicId = MosaicId.createFromNonce(nonce, account.publicAccount, NetworkType.MIJIN_TEST);
const mosaicDefinitionTransaction = MosaicDefinitionTransaction.create(
Deadline.create(),
nonce,
Expand Down Expand Up @@ -104,7 +104,7 @@ describe('MosaicHttp', () => {
UInt64.fromUint(1000),
NetworkType.MIJIN_TEST,
);
namespaceId = new NamespaceId(namespaceName);
namespaceId = new NamespaceId(namespaceName, NetworkType.MIJIN_TEST);
const signedTransaction = registerNamespaceTransaction.signWith(account, generationHash);
listener.confirmed(account.address).subscribe((transaction) => {
done();
Expand Down
2 changes: 1 addition & 1 deletion e2e/infrastructure/NamespaceHttp.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ describe('NamespaceHttp', () => {
UInt64.fromUint(1000),
NetworkType.MIJIN_TEST,
);
namespaceId = new NamespaceId(namespaceName);
namespaceId = new NamespaceId(namespaceName, NetworkType.MIJIN_TEST);
const signedTransaction = registerNamespaceTransaction.signWith(account, generationHash);
listener.confirmed(account.address).subscribe((transaction) => {
done();
Expand Down
4 changes: 2 additions & 2 deletions e2e/infrastructure/RestrictionHttp.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ describe('RestrictionHttp', () => {
});
it('standalone', (done) => {
const nonce = MosaicNonce.createRandom();
mosaicId = MosaicId.createFromNonce(nonce, account.publicAccount);
mosaicId = MosaicId.createFromNonce(nonce, account.publicAccount, NetworkType.MIJIN_TEST);
const mosaicDefinitionTransaction = MosaicDefinitionTransaction.create(
Deadline.create(),
nonce,
Expand Down Expand Up @@ -134,7 +134,7 @@ describe('RestrictionHttp', () => {
});
it('standalone', (done) => {
const nonce = MosaicNonce.createRandom();
referenceMosaicId = MosaicId.createFromNonce(nonce, account.publicAccount);
referenceMosaicId = MosaicId.createFromNonce(nonce, account.publicAccount, NetworkType.MIJIN_TEST);
const mosaicDefinitionTransaction = MosaicDefinitionTransaction.create(
Deadline.create(),
nonce,
Expand Down
10 changes: 6 additions & 4 deletions e2e/infrastructure/TransactionHttp.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ describe('TransactionHttp', () => {
});
it('standalone', (done) => {
const nonce = MosaicNonce.createRandom();
mosaicId = MosaicId.createFromNonce(nonce, account.publicAccount);
mosaicId = MosaicId.createFromNonce(nonce, account.publicAccount, NetworkType.MIJIN_TEST);
const mosaicDefinitionTransaction = MosaicDefinitionTransaction.create(
Deadline.create(),
nonce,
Expand Down Expand Up @@ -182,7 +182,7 @@ describe('TransactionHttp', () => {
const mosaicDefinitionTransaction = MosaicDefinitionTransaction.create(
Deadline.create(),
nonce,
MosaicId.createFromNonce(nonce, account.publicAccount),
MosaicId.createFromNonce(nonce, account.publicAccount, NetworkType.MIJIN_TEST),
MosaicFlags.create( true, true, true),
3,
UInt64.fromUint(0),
Expand Down Expand Up @@ -310,7 +310,7 @@ describe('TransactionHttp', () => {
UInt64.fromUint(10),
NetworkType.MIJIN_TEST,
);
namespaceId = new NamespaceId(namespaceName);
namespaceId = new NamespaceId(namespaceName, NetworkType.MIJIN_TEST);
const signedTransaction = registerNamespaceTransaction.signWith(account, generationHash);
listener.confirmed(account.address).subscribe((transaction: NamespaceRegistrationTransaction) => {
expect(transaction.namespaceId, 'NamespaceId').not.to.be.undefined;
Expand Down Expand Up @@ -1219,7 +1219,9 @@ describe('TransactionHttp', () => {
);
const signedTransaction = account.sign(aggregateTransaction, generationHash);
const hashLockTransaction = HashLockTransaction.create(Deadline.create(),
new Mosaic(new NamespaceId('cat.currency'), UInt64.fromUint(10 * Math.pow(10, NetworkCurrencyMosaic.DIVISIBILITY))),
new Mosaic(
new NamespaceId('cat.currency', NetworkType.MIJIN_TEST),
UInt64.fromUint(10 * Math.pow(10, NetworkCurrencyMosaic.DIVISIBILITY))),
UInt64.fromUint(10000),
signedTransaction,
NetworkType.MIJIN_TEST);
Expand Down
8 changes: 4 additions & 4 deletions e2e/infrastructure/UnresolvedMapping.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ describe('TransactionHttp', () => {
*/
describe('Get network currency mosaic id', () => {
it('get mosaicId', (done) => {
namespaceHttp.getLinkedMosaicId(new NamespaceId('cat.currency')).subscribe((networkMosaicId) => {
namespaceHttp.getLinkedMosaicId(new NamespaceId('cat.currency', NetworkType.MIJIN_TEST)).subscribe((networkMosaicId) => {
networkCurrencyMosaicId = networkMosaicId;
done();
});
Expand All @@ -111,7 +111,7 @@ describe('TransactionHttp', () => {
});
it('standalone', (done) => {
const nonce = MosaicNonce.createRandom();
mosaicId = MosaicId.createFromNonce(nonce, account.publicAccount);
mosaicId = MosaicId.createFromNonce(nonce, account.publicAccount, NetworkType.MIJIN_TEST);
const mosaicDefinitionTransaction = MosaicDefinitionTransaction.create(
Deadline.create(),
nonce,
Expand Down Expand Up @@ -151,7 +151,7 @@ describe('TransactionHttp', () => {
UInt64.fromUint(50),
NetworkType.MIJIN_TEST,
);
namespaceIdMosaic = new NamespaceId(namespaceName);
namespaceIdMosaic = new NamespaceId(namespaceName, NetworkType.MIJIN_TEST);
const signedTransaction = registerNamespaceTransaction.signWith(account, generationHash);
listener.confirmed(account.address).subscribe(() => {
done();
Expand Down Expand Up @@ -182,7 +182,7 @@ describe('TransactionHttp', () => {
UInt64.fromUint(50),
NetworkType.MIJIN_TEST,
);
namespaceIdAddress = new NamespaceId(namespaceName);
namespaceIdAddress = new NamespaceId(namespaceName, NetworkType.MIJIN_TEST);
const signedTransaction = registerNamespaceTransaction.signWith(account, generationHash);
listener.confirmed(account.address).subscribe(() => {
done();
Expand Down
4 changes: 2 additions & 2 deletions e2e/service/MetadataTransactionService.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ describe('MetadataTransactionService', () => {
});
it('standalone', (done) => {
const nonce = MosaicNonce.createRandom();
mosaicId = MosaicId.createFromNonce(nonce, targetAccount.publicAccount);
mosaicId = MosaicId.createFromNonce(nonce, targetAccount.publicAccount, NetworkType.MIJIN_TEST);
const mosaicDefinitionTransaction = MosaicDefinitionTransaction.create(
Deadline.create(),
nonce,
Expand Down Expand Up @@ -105,7 +105,7 @@ describe('MetadataTransactionService', () => {
UInt64.fromUint(9),
NetworkType.MIJIN_TEST,
);
namespaceId = new NamespaceId(namespaceName);
namespaceId = new NamespaceId(namespaceName, NetworkType.MIJIN_TEST);
const signedTransaction = registerNamespaceTransaction.signWith(targetAccount, generationHash);
listener.confirmed(targetAccount.address).subscribe(() => {
done();
Expand Down
2 changes: 1 addition & 1 deletion e2e/service/MosaicRestrictionTransactionService.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ describe('MosaicRestrictionTransactionService', () => {
});
it('standalone', (done) => {
const nonce = MosaicNonce.createRandom();
mosaicId = MosaicId.createFromNonce(nonce, account.publicAccount);
mosaicId = MosaicId.createFromNonce(nonce, account.publicAccount, NetworkType.MIJIN_TEST);
const mosaicDefinitionTransaction = MosaicDefinitionTransaction.create(
Deadline.create(),
nonce,
Expand Down
6 changes: 3 additions & 3 deletions src/core/crypto/Utilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@
* limitations under the License.
*/

const CryptoJS = require('crypto-js');
import { RawArray as array } from '../format';
import * as nacl from './nacl_catapult';
import { SHA3Hasher as sha3Hasher } from './SHA3Hasher';
import { SignSchema } from './SignSchema';
export const CryptoJS = require('crypto-js');
export const Key_Size = 32;
export const Signature_Size = 64;
export const Half_Signature_Size = Signature_Size / 2;
Expand Down Expand Up @@ -68,7 +68,7 @@ export const catapult_hash = {
};

// custom catapult crypto functions
export const catapult_crypto = (function() {
export const catapult_crypto = (() => {
function clamp(d) {
d[0] &= 248;
d[31] &= 127;
Expand All @@ -82,7 +82,7 @@ export const catapult_crypto = (function() {
return d;
}

const encodedSChecker = (function() {
const encodedSChecker = (() => {
const Is_Reduced = 1;
const Is_Zero = 2;

Expand Down
58 changes: 49 additions & 9 deletions src/core/format/IdGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,40 +13,80 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import {sha3_256} from 'js-sha3';
import {NetworkType} from '../../model/blockchain/NetworkType';
import {SHA3Hasher} from '../crypto/SHA3Hasher';
import * as utilities from './Utilities';

export class IdGenerator {
/**
* Generates a mosaic id given a nonce and a public id.
* @param {object} nonce The mosaic nonce.
* @param {object} ownerPublicId The public id.
* @param {object} nonce The mosaic nonce.
* @param {object} ownerPublicId The public id.
* @param {NetworkType} networkType The network type for hash algorithm resolution
* @returns {module:coders/uint64~uint64} The mosaic id.
*/
public static generateMosaicId = (nonce, ownerPublicId) => {
const hash = sha3_256.create();
public static generateMosaicId = (
nonce,
ownerPublicId,
networkType: NetworkType,
) => {
const signSchema = SHA3Hasher.resolveSignSchema(networkType);
const hash = SHA3Hasher.getHasher(32, signSchema).create();
hash.update(nonce);
hash.update(ownerPublicId);
const result = new Uint32Array(hash.arrayBuffer());
return [result[0], result[1] & 0x7FFFFFFF];
}

/**
* Generates a namespace id given a parent id and name.
* @param {object} parentId The parent namespace id.
* @param {object} name The namespace name.
* @param {NetworkType} networkType The network type for hash algorithm resolution
* @returns {module:coders/uint64~uint64} The namespace id.
*/
public static generateNamespaceId = (
parentId,
name: string,
networkType: NetworkType,
) => {
const signSchema = SHA3Hasher.resolveSignSchema(networkType);
const hash = SHA3Hasher.getHasher(32, signSchema).create();
hash.update(Uint32Array.from(parentId).buffer as any);
hash.update(name);
const result = new Uint32Array(hash.arrayBuffer());
// right zero-filling required to keep unsigned number representation
return [result[0], (result[1] | 0x80000000) >>> 0];
}

/**
* Parses a unified namespace name into a path.
* @param {string} name The unified namespace name.
* @param {string} name The unified namespace name.
* @param {NetworkType} networkType The network type for hash algorithm resolution
* @returns {array<module:coders/uint64~uint64>} The namespace path.
*/
public static generateNamespacePath = (name: string) => {
public static generateNamespacePath = (
name: string,
networkType: NetworkType,
) => {
if (0 >= name.length) {
utilities.throwInvalidFqn('having zero length', name);
}
let namespaceId = utilities.idGeneratorConst.namespace_base_id;
const path = [];
const start = utilities.split(name, (substringStart, size) => {
namespaceId = utilities.generateNamespaceId(namespaceId, utilities.extractPartName(name, substringStart, size));
namespaceId = IdGenerator.generateNamespaceId(
namespaceId,
utilities.extractPartName(name, substringStart, size),
networkType,
);
utilities.append(path, namespaceId, name);
});
namespaceId = utilities.generateNamespaceId(namespaceId, utilities.extractPartName(name, start, name.length - start));
namespaceId = IdGenerator.generateNamespaceId(
namespaceId,
utilities.extractPartName(name, start, name.length - start),
networkType,
);
utilities.append(path, namespaceId, name);
return path;
}
Expand Down
9 changes: 0 additions & 9 deletions src/core/format/Utilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,15 +131,6 @@ export const split = (name, processor) => {
return start;
};

export const generateNamespaceId = (parentId, name) => {
const hash = sha3_256.create();
hash.update(Uint32Array.from(parentId).buffer as any);
hash.update(name);
const result = new Uint32Array(hash.arrayBuffer());
// right zero-filling required to keep unsigned number representation
return [result[0], (result[1] | 0x80000000) >>> 0];
};

export const encodeBlock = (input, inputOffset, output, outputOffset) => {
output[outputOffset + 0] = Alphabet[input[inputOffset + 0] >> 3];
output[outputOffset + 1] = Alphabet[((input[inputOffset + 0] & 0x07) << 2) | (input[inputOffset + 1] >> 6)];
Expand Down
Loading