Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export const convertIdentifierToNamespaceId = (value: string) => {
if(/[0-9a-fA-F]{16}/.test(value)) {
return NamespaceId.createFromEncoded(value)
}
try {
const namespaceId = new NamespaceId(value)
return namespaceId
} catch (_) {
// try next
}
const hex = convertUInt64ToHex(value)
if(! /[0-9a-fA-F]{16}/.test(hex)) {
throw new Error("Can't convert")
}
return NamespaceId.createFromEncoded(hex)
}
addresses.map((address: Address) => {
const transferTx = TransferTransaction.create(
Deadline.create(),
address,
[new Mosaic(mosaicId, UInt64.fromUint(amount))],
PlainMessage.create('nem2-sandbox initial coin distribution'),
this.networkType,
UInt64.fromUint(1000000), // 1 XEM fee
)
transferTxes.push(transferTx.toAggregate(publicAccount))
})
addresses.map((address: Address) => {
const transferTx = TransferTransaction.create(
Deadline.create(),
address,
[new Mosaic(mosaicId, UInt64.fromUint(amount))],
PlainMessage.create('nem2-sandbox initial coin distribution'),
this.networkType,
UInt64.fromUint(1000000), // 1 XEM fee
)
transferTxes.push(transferTx.toAggregate(publicAccount))
})
public signedHashing(data: string, signerPrivateKey: string, networkType: NetworkType): string {
const dataHash = CryptoJS.SHA3(data, { outputLength: 256 }).toString();
if (networkType === NetworkType.MAIN_NET || networkType === NetworkType.TEST_NET) {
const keyPair = nem.crypto.keyPair.create(signerPrivateKey);
return this.checksum + keyPair.sign(dataHash).toString();
} else {
// sha-3 signing
const signer = Account.createFromPrivateKey(signerPrivateKey, networkType);
return this.checksum + signer.signData(dataHash);
}
}
}
it('should return true after creation', async () => {
const privateApostille = Apostille.initFromSeed('new random seed', generator);
const creator = Account.createFromPrivateKey(sk, NetworkType.MIJIN_TEST);
const Icreator = new Initiator(creator);
expect.assertions(1);
const creationTransaction = privateApostille.update('raw');
const signedTransaction = Icreator.sign(creationTransaction, generationHash);
await apostilleHttp.announce(signedTransaction);
return apostilleHttp.isCreated(privateApostille.publicAccount).then((result) => {
expect(result).toBeTruthy();
});
});
private getAccount(): Account
{
return Account.createFromPrivateKey(this.privateKey, NetworkType.MIJIN_TEST);
}
static getMosaicId(rawMosaicId: string): MosaicId | NamespaceId {
let mosaicId: MosaicId | NamespaceId;
if (rawMosaicId.charAt(0) === MosaicService.ALIAS_TAG) {
mosaicId = new NamespaceId(rawMosaicId.substring(1));
} else {
mosaicId = new MosaicId(rawMosaicId);
}
return mosaicId;
}
static getMosaicId(rawMosaicId: string): MosaicId | NamespaceId {
let mosaicId: MosaicId | NamespaceId;
if (rawMosaicId.charAt(0) === MosaicService.ALIAS_TAG) {
mosaicId = new NamespaceId(rawMosaicId.substring(1));
} else {
mosaicId = new MosaicId(rawMosaicId);
}
return mosaicId;
}
public static createLockFundsTransaction(signedAggregateBondedTransaction: SignedTransaction): LockFundsTransaction {
const lockFundsTransaction = LockFundsTransaction.create(
Deadline.create(),
new Mosaic(new NamespaceId('nem.xem'), UInt64.fromUint(10)),
UInt64.fromUint(480),
signedAggregateBondedTransaction,
signedAggregateBondedTransaction.networkType);
return lockFundsTransaction;
}
public update(fileContent: string, hashFunction: HashFunction): TransferTransaction {
this.hash = hashFunction.nonSignedHashing(fileContent);
const creationTransaction = TransferTransaction.create(
Deadline.create(),
this.sinkAddress,
[
new Mosaic(new NamespaceId('nem.xem'), UInt64.fromUint(10)),
],
PlainMessage.create(this.hash),
this.sinkAddress.networkType,
);
return creationTransaction;
}