import * as ABIDecoder from "abi-decoder" ; import BigNumber from "bignumber.js" ; import * as crypto from "crypto" ; import ethUtil = require ( "ethereumjs-util" ) ; import * as _ from "lodash" ; import * as solidity from "../../utils/solidity" ; import { Address , Bytes32 , Log , UInt } from "../common" ; import { RegistryEntryParameters , SemanticVersion } from "./schema" ; export class DebtRegistryEntry { public params : RegistryEntryParameters ; public salt : BigNumber ; public constructor ( params , salt ? ) { this . params = params ; this . salt = salt || this . generateSalt ( ) ; } public getIssuanceHash ( ) { const issuanceHash = solidity . SHA3 ( [ this . params . version , this . params . debtor , this . params . underwriter , this . params . underwriterRiskRating , this . params . termsContract , this . params . termsContractParameters , this . salt , ] ) ; const issuanceHashHex = ethUtil . bufferToHex ( issuanceHash ) ; return issuanceHashHex ; } public getDebtor ( ) { return this . params . debtor ; } public getBeneficiary ( ) { return this . params . beneficiary ; } public getVersion ( ) { return this . params . version ; } public getUnderwriter ( ) { return this . params . underwriter ; } public getUnderwriterRiskRating ( ) { return this . params . underwriterRiskRating ; } public getTermsContract ( ) { return this . params . termsContract ; } public getTermsContractParameters ( ) { return this . params . termsContractParameters ; } public getSalt ( ) { return this . salt ; } public getTokenId ( ) { return new BigNumber ( this . getIssuanceHash ( ) ) ; } private generateSalt ( ) { const saltBuffer = crypto . randomBytes ( 32 ) ; const saltBufferHex = ethUtil . bufferToHex ( saltBuffer ) ; return new BigNumber ( saltBufferHex ) ; } }