Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export default function (trasaction) {
const phraseToSign = generateHashKey(trasaction);
const hashcode = sha3256.update(phraseToSign).hex();
// const serialized = new Buffer(hashcode, 'hex');
const serialized = Buffer.alloc(hashcode, 'hex');
return serialized;
}
throw new Error(`No UTxO is found for tx ${inputTxId}! Maybe the blockchain is still syncing? If not - something is wrong.`)
}
const { address: inputAddress, amount: inputAmount } = txOutputs[inputIdx]
this.logger.debug(`Validating witness for input: ${inputTxId}.${inputIdx} (${inputAmount} coin from ${inputAddress})`)
const {
addressRoot,
addrAttr,
addressType,
} = ShelleyValidator.deconstructAddress(inputAddress)
if (addressType !== 0) {
this.logger.debug(`Unsupported address type: ${addressType}. Skipping witness validation for this input.`)
return
}
const addressRootHex = addressRoot.toString('hex')
const expectedStruct = [0, [0, sign[0]], addrAttr]
const encodedStruct = Buffer.from(sha3_256.update(
cbor.encodeCanonical(expectedStruct)).digest())
const expectedRootHex = blake.blake2bHex(encodedStruct, undefined, 28)
if (addressRootHex !== expectedRootHex) {
throw new Error(`Witness does not match! ${JSON.stringify({ addressRootHex, expectedRoot: expectedRootHex })}`)
}
})
}
export function makeTxHash(rawTrasaction) {
const phraseToSign = generateHashKey(rawTrasaction);
return sha3256.update(phraseToSign).hex();
}
}`)
}
const txOutputs = fullOutputs[inputTxId]
if (!txOutputs) {
throw new Error(`No UTxO is found for tx ${inputTxId}! Maybe the blockchain is still syncing? If not - something is wrong.`)
}
const { address: inputAddress, amount: inputAmount } = txOutputs[inputIdx]
this.logger.debug(`Validating witness for input: ${inputTxId}.${inputIdx} (${inputAmount} coin from ${inputAddress})`)
const { addressRoot, addrAttr, addressType } = ByronValidator.deconstructAddress(inputAddress)
if (addressType !== 0) {
this.logger.debug(`Unsupported address type: ${addressType}. Skipping witness validation for this input.`)
return
}
const addressRootHex = addressRoot.toString('hex')
const expectedStruct = [0, [0, sign[0]], addrAttr]
const encodedStruct = Buffer.from(sha3_256.update(
cbor.encodeCanonical(expectedStruct)).digest())
const expectedRootHex = blake.blake2bHex(encodedStruct, undefined, 28)
if (addressRootHex !== expectedRootHex) {
throw new Error(`Witness does not match! ${JSON.stringify({ addressRootHex, expectedRoot: expectedRootHex })}`)
}
})
}
export function serialize(trasaction) {
const phraseToSign = generateHashKey(trasaction);
const hashcode = sha3256.update(phraseToSign).hex();
return hashcode;
}