diff --git a/src/contracts/blindEscrow.ts b/src/contracts/blindEscrow.ts index f5679975..b4781b57 100644 --- a/src/contracts/blindEscrow.ts +++ b/src/contracts/blindEscrow.ts @@ -21,17 +21,19 @@ import { SECP256K1, Signature } from 'scrypt-ts-lib' // All public keys must be in uncompressed form. This also affects // the values of the pub key hashes i.e. addresses. -export class BlindEscrow extends SmartContract { - // 4 possible actions: + // 4 possible actions: // - buyer signs and uses sellers stamp (releaseBySeller) // - buyer signs and uses arbiters stamp (releaseByArbiter) // - seller signs and uses buyers stamp (returnByBuyer) // - seller signs and uses arbiters stamp (returnByArbiter) - static readonly RELEASE_BY_SELLER = 0n - static readonly RELEASE_BY_ARBITER = 1n - static readonly RETURN_BY_BUYER = 2n - static readonly RETURN_BY_ARBITER = 3n - + export enum Actions{ + RELEASE_BY_SELLER, + RELEASE_BY_ARBITER, + RETURN_BY_BUYER, + RETURN_BY_ARBITER + } +export class BlindEscrow extends SmartContract { + @prop() seller: Addr @@ -73,16 +75,16 @@ export class BlindEscrow extends SmartContract { ) // Load correct addresses. - if (action == BlindEscrow.RELEASE_BY_SELLER) { + if (action == BigInt(Actions.RELEASE_BY_SELLER)) { spender = this.buyer oracle = this.seller - } else if (action == BlindEscrow.RELEASE_BY_ARBITER) { + } else if (action == BigInt(Actions.RELEASE_BY_ARBITER)) { spender = this.buyer oracle = this.arbiter - } else if (action == BlindEscrow.RETURN_BY_BUYER) { + } else if (action == BigInt(Actions.RETURN_BY_BUYER)) { spender = this.seller oracle = this.buyer - } else if (action == BlindEscrow.RETURN_BY_ARBITER) { + } else if (action == BigInt(Actions.RETURN_BY_ARBITER)) { spender = this.seller oracle = this.arbiter } else { diff --git a/tests/blindEscrow.test.ts b/tests/blindEscrow.test.ts index fbe78547..5923e0b8 100644 --- a/tests/blindEscrow.test.ts +++ b/tests/blindEscrow.test.ts @@ -13,7 +13,7 @@ import { pubKey2Addr, } from 'scrypt-ts' import { Signature } from 'scrypt-ts-lib' -import { BlindEscrow } from '../src/contracts/blindEscrow' +import { BlindEscrow, Actions } from '../src/contracts/blindEscrow' import { getDefaultSigner } from './utils/helper' use(chaiAsPromised) @@ -72,7 +72,7 @@ describe('Heavy: Test SmartContract `BlindEscrow`', () => { // Create "stamp", i.e. seller signature of the escrowNonce. const oracleMsg: ByteString = - escrowNonce + int2ByteString(BlindEscrow.RELEASE_BY_SELLER) + escrowNonce + int2ByteString(BigInt(Actions.RELEASE_BY_SELLER)) const hashBuff = Buffer.from(hash256(oracleMsg), 'hex') const oracleSigObj = bsv.crypto.ECDSA.sign(hashBuff, seller) const oracleSig: Signature = { @@ -89,7 +89,7 @@ describe('Heavy: Test SmartContract `BlindEscrow`', () => { PubKey(buyerPubKey.toByteString()), oracleSig, PubKey(sellerPubKey.toByteString()), - BlindEscrow.RELEASE_BY_SELLER, + Actions.RELEASE_BY_SELLER, { pubKeyOrAddrToSign: buyer.publicKey, } as MethodCallOptions @@ -102,7 +102,7 @@ describe('Heavy: Test SmartContract `BlindEscrow`', () => { //// Sig by buyer, stamp by arbiter. const oracleMsg: ByteString = - escrowNonce + int2ByteString(BlindEscrow.RELEASE_BY_ARBITER) + escrowNonce + int2ByteString(BigInt(Actions.RELEASE_BY_ARBITER)) const hashBuff = Buffer.from(hash256(oracleMsg), 'hex') const oracleSigObj = bsv.crypto.ECDSA.sign(hashBuff, arbiter) const oracleSig: Signature = { @@ -120,7 +120,7 @@ describe('Heavy: Test SmartContract `BlindEscrow`', () => { PubKey(buyerPubKey.toByteString()), oracleSig, PubKey(arbiterPubKey.toByteString()), - BlindEscrow.RELEASE_BY_ARBITER, + Actions.RELEASE_BY_ARBITER, { pubKeyOrAddrToSign: buyer.publicKey, } as MethodCallOptions @@ -133,7 +133,7 @@ describe('Heavy: Test SmartContract `BlindEscrow`', () => { //// Sig by seller, stamp by buyer. const oracleMsg: ByteString = - escrowNonce + int2ByteString(BlindEscrow.RETURN_BY_BUYER) + escrowNonce + int2ByteString(BigInt(Actions.RETURN_BY_BUYER)) const hashBuff = Buffer.from(hash256(oracleMsg), 'hex') const oracleSigObj = bsv.crypto.ECDSA.sign(hashBuff, buyer) const oracleSig: Signature = { @@ -149,7 +149,7 @@ describe('Heavy: Test SmartContract `BlindEscrow`', () => { PubKey(sellerPubKey.toByteString()), oracleSig, PubKey(buyerPubKey.toByteString()), - BlindEscrow.RETURN_BY_BUYER, + Actions.RETURN_BY_BUYER, { pubKeyOrAddrToSign: seller.publicKey, } as MethodCallOptions @@ -162,7 +162,7 @@ describe('Heavy: Test SmartContract `BlindEscrow`', () => { //// Sig by seller, stamp by arbiter. const oracleMsg: ByteString = - escrowNonce + int2ByteString(BlindEscrow.RETURN_BY_ARBITER) + escrowNonce + int2ByteString(BigInt(Actions.RETURN_BY_ARBITER)) const hashBuff = Buffer.from(hash256(oracleMsg), 'hex') const oracleSigObj = bsv.crypto.ECDSA.sign(hashBuff, arbiter) const oracleSig: Signature = { @@ -179,7 +179,7 @@ describe('Heavy: Test SmartContract `BlindEscrow`', () => { PubKey(sellerPubKey.toByteString()), oracleSig, PubKey(arbiterPubKey.toByteString()), - BlindEscrow.RETURN_BY_ARBITER, + Actions.RETURN_BY_ARBITER, { pubKeyOrAddrToSign: seller.publicKey, } as MethodCallOptions