Esempio n. 1
0
	def test_verifyMultiSigSignature(self):
		"Test the verifyMultiSigSignature function"

		tx = dummy_interfaces.Tracer()
		def getSignatureBodyHash(*args, **kwargs):
			tx.trace.append(("getSignatureBodyHash", args, kwargs))
			return "bodyHash"
		tx.getSignatureBodyHash = getSignatureBodyHash

		key = crypto.Key()
		key.makeNewKey()

		signature = bitcoinutils.signMultiSigTransaction(
			tx, 3, ["toPubKey1", "toPubKey2"], key)

		self.assertTrue(bitcoinutils.verifyMultiSigSignature(
			tx, 3, ["toPubKey1", "toPubKey2"], key, signature)
			)

		key2 = crypto.Key()
		key2.makeNewKey()
		self.assertFalse(bitcoinutils.verifyMultiSigSignature(
			tx, 3, ["toPubKey1", "toPubKey2"], key2, signature)
			)

		self.assertFalse(bitcoinutils.verifyMultiSigSignature(
			tx, 3, ["toPubKey1", "toPubKey2"], key, signature[:-1] + "\x02")
			)
Esempio n. 2
0
    def test_verifyMultiSigSignature(self):
        "Test the verifyMultiSigSignature function"

        tx = dummy_interfaces.Tracer()

        def getSignatureBodyHash(*args, **kwargs):
            tx.trace.append(("getSignatureBodyHash", args, kwargs))
            return "bodyHash"

        tx.getSignatureBodyHash = getSignatureBodyHash

        key = crypto.Key()
        key.makeNewKey()

        signature = bitcoinutils.signMultiSigTransaction(
            tx, 3, ["toPubKey1", "toPubKey2"], key)

        self.assertTrue(
            bitcoinutils.verifyMultiSigSignature(tx, 3,
                                                 ["toPubKey1", "toPubKey2"],
                                                 key, signature))

        key2 = crypto.Key()
        key2.makeNewKey()
        self.assertFalse(
            bitcoinutils.verifyMultiSigSignature(tx, 3,
                                                 ["toPubKey1", "toPubKey2"],
                                                 key2, signature))

        self.assertFalse(
            bitcoinutils.verifyMultiSigSignature(tx, 3,
                                                 ["toPubKey1", "toPubKey2"],
                                                 key, signature[:-1] + "\x02"))
Esempio n. 3
0
	def test_signMultiSigTransaction(self):
		"Test the signMultiSigTransaction function"

		tx = dummy_interfaces.Tracer()
		def getSignatureBodyHash(*args, **kwargs):
			tx.trace.append(("getSignatureBodyHash", args, kwargs))
			return "bodyHash"
		tx.getSignatureBodyHash = getSignatureBodyHash

		key = crypto.Key()
		key.makeNewKey()

		signature = bitcoinutils.signMultiSigTransaction(
			tx, 3, ["toPubKey1", "toPubKey2"], key)
		
		self.assertEqual(len(tx.trace), 1)
		self.assertEqual(tx.trace[0][0], "getSignatureBodyHash")
		self.assertEqual(tx.trace[0][1][0], 3)
		script = tx.trace[0][1][1]
		self.assertEqual(tx.trace[0][1][2], 1)
		self.assertEqual(script.elements,
			[OP.TWO, "toPubKey1", "toPubKey2", OP.TWO, OP.CHECKMULTISIG])

		self.assertEqual(signature[-1], "\x01")
		signature = signature[:-1]
		self.assertTrue(key.verify("bodyHash", signature))
Esempio n. 4
0
    def test_signMultiSigTransaction(self):
        "Test the signMultiSigTransaction function"

        tx = dummy_interfaces.Tracer()

        def getSignatureBodyHash(*args, **kwargs):
            tx.trace.append(("getSignatureBodyHash", args, kwargs))
            return "bodyHash"

        tx.getSignatureBodyHash = getSignatureBodyHash

        key = crypto.Key()
        key.makeNewKey()

        signature = bitcoinutils.signMultiSigTransaction(
            tx, 3, ["toPubKey1", "toPubKey2"], key)

        self.assertEqual(len(tx.trace), 1)
        self.assertEqual(tx.trace[0][0], "getSignatureBodyHash")
        self.assertEqual(tx.trace[0][1][0], 3)
        script = tx.trace[0][1][1]
        self.assertEqual(tx.trace[0][1][2], 1)
        self.assertEqual(
            script.elements,
            [OP.TWO, "toPubKey1", "toPubKey2", OP.TWO, OP.CHECKMULTISIG])

        self.assertEqual(signature[-1], "\x01")
        signature = signature[:-1]
        self.assertTrue(key.verify("bodyHash", signature))
Esempio n. 5
0
fee = 10000 #0.1 mBTC

outputHash = binascii.unhexlify(raw_input("Input hash (empty: create multisig): "))[::-1]

if outputHash == "":
	tx = sendToMultiSigPubKey(d, amount,
		key1.getPublicKey(),
		key2.getPublicKey(),
		keyHash2,
		fee=fee)
else:
	outputIndex = 0

	tx = makeSpendMultiSigTransaction(outputHash, outputIndex, amount, keyHash1, fee)

	sig1 = signMultiSigTransaction(
		tx, outputIndex, [key1.getPublicKey(), key2.getPublicKey()], key1)
	sig2 = signMultiSigTransaction(
		tx, outputIndex, [key1.getPublicKey(), key2.getPublicKey()], key2)

	applyMultiSigSignatures(tx, sig1, sig2)


print "Tx:", tx.serialize().encode("hex")

print "Tx ID:", tx.getTransactionID()[::-1].encode("hex")

tx_s = tx.serialize()
#d.sendRawTransaction(tx_s)

tx = bitcointransaction.Transaction.deserialize(tx_s)
tx_s2 = tx.serialize()