Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const tx: IMassTransferTransaction & WithId = {
type,
version,
senderPublicKey,
assetId: normalizeAssetId(paramsOrTx.assetId),
transfers: paramsOrTx.transfers,
fee: fee(paramsOrTx, 100000 + Math.ceil(0.5 * paramsOrTx.transfers.length) * 100000),
timestamp: paramsOrTx.timestamp || Date.now(),
attachment: paramsOrTx.attachment || '',
proofs: paramsOrTx.proofs || [],
id: '', //TODO: invalid id for masstransfer tx
}
validate.massTransfer(tx)
const bytes = binary.serializeTx(tx)
seedsAndIndexes.forEach(([s, i]) => addProof(tx, signBytes(s, bytes), i))
tx.id = base58Encode(blake2b(bytes))
return tx
}
const tx: ISetScriptTransaction & WithId = {
type,
version,
senderPublicKey,
chainId: networkByte(paramsOrTx.chainId, 87),
fee: fee(paramsOrTx, 1000000),
timestamp: paramsOrTx.timestamp || Date.now(),
proofs: paramsOrTx.proofs || [],
id: '',
script: base64Prefix(paramsOrTx.script),
}
validate.setScript(tx)
const bytes = binary.serializeTx(tx)
seedsAndIndexes.forEach(([s,i]) => addProof(tx, signBytes(s, bytes),i))
tx.id = base58Encode(blake2b(bytes))
return tx
}
name: paramsOrTx.name,
description: paramsOrTx.description,
quantity: paramsOrTx.quantity,
script: paramsOrTx.script == null ? undefined : base64Prefix(paramsOrTx.script)!,
decimals: paramsOrTx.decimals == null ? 8 : paramsOrTx.decimals,
reissuable: paramsOrTx.reissuable || false,
fee: paramsOrTx.quantity === 1 ? fee(paramsOrTx, 1000000) : fee(paramsOrTx, 100000000),
timestamp: paramsOrTx.timestamp || Date.now(),
chainId: networkByte(paramsOrTx.chainId, 87),
proofs: paramsOrTx.proofs || [],
id: '',
}
validate.issue(tx)
const bytes = binary.serializeTx(tx)
seedsAndIndexes.forEach(([s, i]) => addProof(tx, signBytes(s, bytes), i))
tx.id = base58Encode(blake2b(bytes))
return tx
}
const tx: IAliasTransaction & WithId = {
type,
version,
senderPublicKey,
alias: paramsOrTx.alias,
fee: fee(paramsOrTx, 100000),
timestamp: paramsOrTx.timestamp || Date.now(),
chainId: networkByte(paramsOrTx.chainId, 87),
proofs: paramsOrTx.proofs || [],
id: '',
}
validate.alias(tx)
const bytes = binary.serializeTx(tx)
seedsAndIndexes.forEach(([s, i]) => addProof(tx, signBytes(s, bytes), i))
const idBytes = [bytes[0], ...bytes.slice(36, -16)]
tx.id = base58Encode(blake2b(Uint8Array.from(idBytes)))
return tx
}
senderPublicKey,
order1: paramsOrTx.order1,
order2: paramsOrTx.order2,
price: paramsOrTx.price,
amount: paramsOrTx.amount,
buyMatcherFee: paramsOrTx.buyMatcherFee,
sellMatcherFee: paramsOrTx.sellMatcherFee,
fee: fee(paramsOrTx, 100000),
timestamp: paramsOrTx.timestamp || Date.now(),
proofs: paramsOrTx.proofs || [],
id: '',
}
validate.exchange(tx)
const bytes = binary.serializeTx(tx)
seedsAndIndexes.forEach(([s, i]) => addProof(tx, signBytes(s, bytes), i))
return {...tx, id: base58Encode(blake2b(bytes))}
}
const tx: ISetAssetScriptTransaction & WithId = {
type,
version,
senderPublicKey,
assetId: paramsOrTx.assetId,
chainId: networkByte(paramsOrTx.chainId, 87),
fee: fee(paramsOrTx, 100000000),
timestamp: paramsOrTx.timestamp || Date.now(),
proofs: paramsOrTx.proofs || [],
id: '',
script: base64Prefix(paramsOrTx.script),
}
validate.setAssetScript(tx)
const bytes = binary.serializeTx(tx)
seedsAndIndexes.forEach(([s, i]) => addProof(tx, signBytes(s, bytes), i))
tx.id = base58Encode(blake2b(bytes))
return tx
}
const tx: IBurnTransaction & WithId = {
type,
version,
senderPublicKey,
assetId: paramsOrTx.assetId,
quantity: paramsOrTx.quantity,
chainId: networkByte(paramsOrTx.chainId, 87),
fee: fee(paramsOrTx, 100000),
timestamp: paramsOrTx.timestamp || Date.now(),
proofs: paramsOrTx.proofs || [],
id: '',
}
validate.burn(tx)
const bytes = binary.serializeTx(tx)
seedsAndIndexes.forEach(([s, i]) => addProof(tx, signBytes(s, bytes), i))
tx.id = base58Encode(blake2b(bytes))
return tx
}
const tx: ILeaseTransaction & WithId = {
type,
version,
senderPublicKey,
amount: paramsOrTx.amount,
recipient: paramsOrTx.recipient,
fee: fee(paramsOrTx, 100000),
timestamp: paramsOrTx.timestamp || Date.now(),
proofs: paramsOrTx.proofs || [],
id: '',
}
validate.lease(tx)
const bytes = binary.serializeTx(tx)
seedsAndIndexes.forEach(([s, i]) => addProof(tx, signBytes(s, bytes), i))
tx.id = base58Encode(blake2b(bytes))
return tx
}
type,
version,
senderPublicKey,
assetId: paramsOrTx.assetId,
quantity: paramsOrTx.quantity,
reissuable: paramsOrTx.reissuable,
chainId: networkByte(paramsOrTx.chainId, 87),
fee: fee(paramsOrTx,100000000),
timestamp: paramsOrTx.timestamp || Date.now(),
proofs: paramsOrTx.proofs || [],
id: '',
}
validate.reissue(tx)
const bytes = binary.serializeTx(tx)
seedsAndIndexes.forEach(([s,i]) => addProof(tx, signBytes(s, bytes),i))
tx.id = base58Encode(blake2b(bytes))
return tx
}
export function serialize(obj: TTx | TOrder): Uint8Array {
if (isOrder(obj)) return binary.serializeOrder(obj)
return binary.serializeTx(obj)
}