navio-blsct
Version:
TypeScript bindings for the `libblsct` library used by the [Navio](https://nav.io/) blockchain to construct confidential transactions based on the BLS12-381 curve.
78 lines (63 loc) • 1.37 kB
text/typescript
import {
CTX_ID_SIZE,
} from '../blsct'
import * as crypto from 'crypto'
import { CTxId } from '../ctxId'
import { OutPoint } from '../outPoint'
import { Scalar } from '../scalar'
import { TokenId } from '../tokenId'
import { TxIn } from '../txIn'
const genTxIn = (): TxIn => {
const spendingKey = Scalar.random()
const tokenId = TokenId.default()
const ctxIdHex = crypto.randomBytes(CTX_ID_SIZE).toString('hex')
const ctxId = CTxId.deserialize(ctxIdHex)
const outPoint = OutPoint.generate(ctxId, 1)
return TxIn.generate(
123,
456,
spendingKey,
tokenId,
outPoint,
false,
false,
)
}
test('generate', () => {
genTxIn()
})
test('getAmount', () => {
const x = genTxIn()
x.getAmount()
})
test('getGamma', () => {
const x = genTxIn()
x.getGamma()
})
test('getSpendingKey', () => {
const x = genTxIn()
x.getSpendingKey()
})
test('getTokenId', () => {
const x = genTxIn()
x.getTokenId()
})
test('getOutPoint', () => {
const x = genTxIn()
x.getOutPoint()
})
test('getIsStakedCommitment', () => {
const x = genTxIn()
x.getStakedCommitment()
})
test('getIsRbf', () => {
const x = genTxIn()
x.getRbf()
})
test('serialize and deserialize', () => {
const a = genTxIn()
const a_hex = a.serialize()
const b = TxIn.deserialize(a_hex)
const b_hex = b.serialize()
expect(a_hex).toBe(b_hex)
})