Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
it('should create SecretLockTransaction', () => {
const proof = 'B778A39A3663719DFC5E48C9D78431B1E45C2AF9DF538782BF199C189DABEAC7';
const recipientAddress = Address.createFromRawAddress('SDBDG4IT43MPCW2W4CBBCSJJT42AYALQN7A4VVWL');
const secretLockTransaction = SecretLockTransaction.create(
Deadline.create(),
NetworkCurrencyMosaic.createAbsolute(10),
UInt64.fromUint(100),
HashType.Op_Sha3_256,
sha3_256.create().update(convert.hexToUint8(proof)).hex(),
recipientAddress,
NetworkType.MIJIN_TEST,
);
const json = secretLockTransaction.toJSON();
expect(json.transaction.type).to.be.equal(TransactionType.SECRET_LOCK);
expect(json.transaction.hashAlgorithm).to.be.equal(HashType.Op_Sha3_256);
});
it('should be created with HashType: Op_Sha3_256 secret', () => {
const proof = 'B778A39A3663719DFC5E48C9D78431B1E45C2AF9DF538782BF199C189DABEAC7';
const secretProofTransaction = SecretProofTransaction.create(
Deadline.create(),
HashType.Op_Sha3_256,
sha3_256.create().update(convert.hexToUint8(proof)).hex(),
account.address,
proof,
NetworkType.MIJIN_TEST,
);
expect(secretProofTransaction.hashType).to.be.equal(0);
expect(secretProofTransaction.secret).to.be.equal('9b3155b37159da50aa52d5967c509b410f5a36a3b1e31ecb5ac76675d79b4a5e' );
expect(secretProofTransaction.proof).to.be.equal(proof);
});
public recoverKey(shares: any): string {
const offset = this.getOffsetMapping(shares[0])
const translatedShares = []
for (let i = 0; i < shares.length; i++) {
const words = shares[i].split(' ')
const firstHalf = words.slice(0, 24)
const secondHalf = words.slice(24, words.length)
translatedShares[i] = `${bip39.mnemonicToEntropy(firstHalf.join(' '))}${bip39.mnemonicToEntropy(secondHalf.join(' '))}`.substr(
0,
offset.offset
)
}
const secretDigester = sha3_256.create()
const combine = secretJS.combine(translatedShares)
const seed = combine.slice(0, -this.checkSumLength)
secretDigester.update(seed)
const checksum = secretDigester.hex().slice(0, this.checkSumLength)
const checksum2 = combine.substr(-this.checkSumLength)
if (checksum !== checksum2) {
throw new Error(
'Checksum error, either the passed shares were generated for different secrets or the amount of shares is below the threshold'
)
}
return bip39.entropyToMnemonic(seed)
}
}
const hashData = (msg) => {
let message = '';
switch (typeof msg) {
case 'string':
message = msg;
break;
case 'object':
case 'number':
message = msg.toString();
break;
default:
throw new Error('Invalid msg type');
}
const hash = SHA3256.create();
return hash.update(message).hex();
};
hashWorker.onmessage = event => {
const secureRandomArray = new Uint8Array(this.ENTROPY_SIZE)
window.crypto.getRandomValues(secureRandomArray)
const hash = sha3_256.create()
hash.update(event.data.hash)
hash.update(secureRandomArray)
resolve(hash.hex())
}
from: genHexBuf(tx.from, BYTESIZES.ADDRESS),
to: genHexBuf(tx.to ? tx.to : '', BYTESIZES.ADDRESS),
value: genHexBuf(tx.value ? BigNumber(tx.value).toString(16) : '', BYTESIZES.VALUE),
nonce: tx.nonce,
chainId: tx.chain_id,
payload: (tx.payload === undefined || tx.payload === '') ? null : binary.from(tx.payload, 'hex'),
};
const root = protobuf.Root.fromJSON(jsonDescriptor);
const TxHashTarget = root.lookupType('TransactionHashTarget');
const errMsg = TxHashTarget.verify(txHashTarget);
if (errMsg) throw Error(errMsg);
const message = TxHashTarget.create(txHashTarget);
const buf = TxHashTarget.encode(message).finish();
const hash = SHA3256.create();
return hash.update(buf).hex();
};
const isValidAddressDecoded = (decoded): boolean => {
const hash = sha3_256.create();
const checksumBegin = 25 - 4;
hash.update(decoded.subarray(0, checksumBegin));
const checksum = new Uint8Array(4);
arrayCopy(checksum, uint8View(hash.arrayBuffer()), 4);
return deepEqual(checksum, decoded.subarray(checksumBegin), 4);
}
const generateId = (parentId, name) => {
const hash = sha3_256.create();
hash.update(Uint32Array.from(parentId).buffer);
hash.update(name);
const result = new Uint32Array(hash.arrayBuffer());
return [result[0], result[1]];
};