Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lamport oracle test #2

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 58 additions & 13 deletions tests/lamportOracle.test.ts
Original file line number Diff line number Diff line change
@@ -1,36 +1,81 @@
// @ts-ignore
import btc = require('bitcore-lib-inquisition');
import { Tap } from '@cmdcode/tapscript' // Requires node >= 19
import btc = require('bitcore-lib-inquisition')
import { Tap } from '@cmdcode/tapscript' // Requires node >= 19

import * as dotenv from 'dotenv';
dotenv.config();
import * as dotenv from 'dotenv'
dotenv.config()

import { expect, use } from 'chai'
import { TestLamportOracle } from '../src/contracts/tests/testLamportOracle'
import {
LamportOracle,
LamportMsg,
LamportKey,
LamportSig,
LAMPORT_KEY_SIZE,
LAMPORT_MSG_BITS,
} from '../src/contracts/lamportOracle'
import { MerkleProof, NodePos } from '../src/contracts/merklePath'
import chaiAsPromised from 'chai-as-promised'
import { fetchP2WPKHUtxos } from './utils/txHelper';
import { Ripemd160, reverseByteString, toByteString } from 'scrypt-ts';
import { hash160, fill, bsv, Ripemd160, toByteString } from 'scrypt-ts'
use(chaiAsPromised)


describe('Test SmartContract `TestLamportOracle`', () => {
let instance: TestLamportOracle
let msg: LamportMsg
let sig: LamportSig
let pubKey: LamportKey
let pubKeyProof: MerkleProof

before(async () => {
await TestLamportOracle.loadArtifact()

const pubKeyRoot = Ripemd160(toByteString('0000000000000000000000000000000000000000'))
const pubKeyRoot = Ripemd160(
toByteString('0000000000000000000000000000000000000000')
)
const privKey = bsv.PrivateKey.fromRandom(
bsv.Networks.testnet
).toByteString()
const lamportKeys: LamportKey = fill(privKey, LAMPORT_KEY_SIZE)

pubKey = lamportKeys.map((pk) => hash160(pk), 16) as LamportKey

msg = [true, false, true, false, true, false, true, false]

sig = lamportKeys.slice(0, 8) as LamportSig
//msg.map(
// (bit, idx) => privKey[bit ? idx : LAMPORT_MSG_BITS + idx]
// ) as LamportSig

const leaf = LamportOracle.pubKey2Leaf(pubKey)

pubKeyProof = fill(
{
hash: toByteString('0000000000000000000000000000000000000000'),
pos: NodePos.Left,
},
32
) as MerkleProof

instance = new TestLamportOracle(pubKeyRoot)

console.log('Script:', instance.lockingScript.toASM())
console.log('Script len:', instance.lockingScript.toBuffer().length)
console.log('Script:', instance.lockingScript.toASM())
console.log('Script len:', instance.lockingScript.toBuffer().length)
console.log('Public Key:', pubKey)
console.log('Signature:', sig)
console.log('Merkle Proof:', pubKeyProof)
})


it('should pass oracle sig verify', async () => {

})

console.log('Testing with: ', {
msg,
sig,
pubKey,
pubKeyProof,
})

// await expect(instance.testVerifyMsg(msg, sig, pubKey, pubKeyProof)).to
// .be.true
})
})