Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
(parseInt(nextMessage?.sentDate, 10) || 0) - (sentDate || 0) < 60000 // one minute
} else {
isFollowupMessage =
previousMessage && !inte.isMe && inte.memberPublicKey === previousMessage.memberPublicKey
isFollowedMessage =
nextMessage && !inte.isMe && inte.memberPublicKey === nextMessage.memberPublicKey
isWithinCollapseDuration =
nextMessage &&
inte?.memberPublicKey === nextMessage?.memberPublicKey &&
sentDate &&
nextMessage.sentDate &&
(parseInt(nextMessage?.sentDate, 10) || 0) - (sentDate || 0) < 60000 // one minute
if (!inte.isMe && inte.memberPublicKey) {
const h = new SHA3(256).update(inte.memberPublicKey).digest()
baseColor = '#' + pal[h[0]]
}
msgTextColor = inte.isMe
? inte.acknowledged
? color.white
: cmd
? color.grey
: baseColor
: baseColor
msgBackgroundColor = inte.isMe
? inte.acknowledged
? baseColor
: color.white
: Color(baseColor).alpha(0.1).string()
msgBorderColor = inte.isMe && (cmd ? border.color.grey : { borderColor: baseColor })
msgSenderColor = inte.isMe ? 'red' : baseColor
const senderAccountState = await this.getAccountState(senderAddress)
sequenceNumber = senderAccountState.sequenceNumber
}
const rawTransaction = new RawTransaction()
rawTransaction.setSenderAccount(senderAddress.toBytes())
rawTransaction.setSequenceNumber(sequenceNumber.toNumber())
rawTransaction.setProgram(transaction.program)
rawTransaction.setMaxGasAmount(transaction.gasContraint.maxGasAmount.toNumber())
rawTransaction.setGasUnitPrice(transaction.gasContraint.gasUnitPrice.toNumber())
rawTransaction.setExpirationTime(transaction.expirationTime.toNumber())
const signedTransaction = new SignedTransaction()
signedTransaction.setSenderPublicKey(sender.keyPair.getPublicKey())
const sha3 = new SHA3(256)
// Magic number provided by Libra
sha3.update('46f174df6ca8de5ad29745f91584bb913e7df8dd162e3e921a5c1d8637c88d16', 'hex')
sha3.update(new Buffer(rawTransaction.serializeBinary()))
signedTransaction.setSenderSignature(sender.generateSignature(sha3.digest()))
signedTransaction.setRawTxnBytes(rawTransaction.serializeBinary())
const request = new SubmitTransactionRequest()
request.setSignedTxn(signedTransaction)
return new Promise((resolve, reject) => {
this.client.submitTransaction(request, undefined, (error: any | null, response: SubmitTransactionResponse) => {
if (error) {
return reject(error)
}
resolve(response)
})
public getAddress(): AccountAddress {
if (this.address !== undefined) {
return this.address
}
const sha3 = new SHA3(256)
sha3.update(Buffer.from(this.keyPair.getPublicKey()))
this.address = new AccountAddress(new Uint8Array(sha3.digest()))
return this.address
}
private setAlgorithm(algo: string): void {
if (this.state.fileBuffer) {
let finalHash;
if (algo === "sha256") {
const hashAlgo = crypto.createHash(algo);
hashAlgo.update(this.state.fileBuffer);
finalHash = hashAlgo.digest("hex");
} else {
const hashAlgo = new SHA3(256);
hashAlgo.update(this.state.fileBuffer);
finalHash = hashAlgo.digest("hex");
}
this.setState({
fileAlgorithm: algo,
fileHash: finalHash
});
}
}
}
hashSha3(text) {
let hash = new SHA3(512);
hash.update(text);
return this._toHexStr(hash.digest());
}
_base_hash() {
const hash = sha3.SHA3(256);
hash.update(this._bytes(0));
return hash.digest("binary");
}
public getAddress(): AccountAddress {
if (this.address !== undefined) {
return this.address;
}
const sha3 = new SHA3(256);
sha3.update(Buffer.from(this.keyPair.getPublicKey()));
this.address = new AccountAddress(new Uint8Array(sha3.digest()));
return this.address;
}
}
_publish_hash() {
const hash = sha3.SHA3(256);
hash.update(this._bytes(1));
return hash.digest("binary");
}
(maxSize / 1048576).toFixed(1)} Mb.`
);
}
if (buffer.length === 0) {
throw new Error(`The file must be greater than 0 bytes in length.`);
}
let hex;
if (request.algorithm === "sha256") {
const hashAlgo = crypto.createHash(request.algorithm);
hashAlgo.update(buffer);
hex = hashAlgo.digest("hex");
} else if (request.algorithm === "sha3") {
const hashAlgo = new SHA3(256);
hashAlgo.update(buffer);
hex = hashAlgo.digest("hex");
}
if (hex !== request.hash) {
throw new Error(
`The hash for the file is incorrect '${request.hash}' was sent but it has been calculated as '${hex}'`);
}
const parts = /(https):\/\/(.*):(\d*)(.*)/.exec(config.ipfs.provider);
const ipfsConfig = {
protocol: parts[1],
host: parts[2],
port: parts[3],
"api-path": parts[4],