btc contracts
Closed this issue · 3 comments
xhliu commented
xhliu commented
import { SmartContract, method, prop, assert, Ripemd160, hash160 } from 'scrypt-ts'
type Hash = Ripemd160
type HashPair = Hash[2]
export class Demo extends SmartContract {
@prop()
hashPairA: HashPair
@prop()
hashPairB: HashPair
@prop()
hashPairE: HashPair
constructor(
hashPairA: HashPair,
hashPairB: HashPair,
hashPairE: HashPair,
) {
super(...arguments)
this.hashPairA = hashPairA
this.hashPairB = hashPairB
this.hashPairE = hashPairE
}
@method()
public openGateCommit(
preimageA: ByteString,
preimageB: ByteString,
preimageE: ByteString,
) {
const bitA = this.bitValueCommit(this.hashPairA, preimageA)
const bitB = this.bitValueCommit(this.hashPairB, preimageB)
const bitE = this.bitValueCommit(this.hashPairE, preimageE)
assert(this.nand(bitA, bitB) == bitE)
}
@method()
bitValueCommit(hashPair: HashPair, preimage: ByteString): boolean {
const h = hash160(preimage)
assert (h == hashPair[0] || h == hashPair[1])
return h == hashPair[1]
}
@method()
nand(x: boolean, y: boolean): boolean {
return !(x && y)
}
}
xhliu commented
Maybe worth while to have a script/code to check if any compiled script output contains any disabled BTC opcode.
msinkec commented
Examples:
https://github.com/sCrypt-Inc/scrypt-btc-demo/
https://github.com/sCrypt-Inc/demo-bitvm
Libs:
https://github.com/sCrypt-Inc/scrypt-ts-btc
https://github.com/sCrypt-Inc/scryptlib-btc
https://github.com/sCrypt-Inc/scrypt-bitcore-lib (bsv submodule equivalent for BTC)