diff --git a/README.md b/README.md index 5844d3c..ea408e2 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,22 @@ # go-aip + Author Identity Protocol Library for working with [Author Identity Protocol](https://github.com/BitcoinFiles/AUTHOR_IDENTITY_PROTOCOL) in go + +## Related packages + +- [go-bob](https://github.com/rohenaz/go-bob) +- [go-bmap](https://github.com/rohenaz/go-bmap) + +# Validate Bob Tapes + +```go + bobData := bob.New() + bobData.FromString(sampleBobTx) + + tapes := bobData.Out[0].Tape + if !ValidateTapes(tapes) { + t.Error("Failed to validate AIP signature") + } +``` diff --git a/aip.go b/aip.go index a6e4e16..93fe381 100644 --- a/aip.go +++ b/aip.go @@ -1,7 +1,6 @@ package aip import ( - "log" "strconv" "strings" @@ -98,6 +97,7 @@ func (a *Aip) FromTape(tape bob.Tape) { a.Indicies = make([]int, len(tape.Cell)-4) + // TODO: Consider OP_RETURN is included in sig when processing a tx using indices // Loop over remaining indicies if they exist and append to indicies slice for x := 4; x < len(tape.Cell); x++ { // log.Println("X IS", x) @@ -126,7 +126,6 @@ func (a *Aip) Validate() (ok bool) { } switch a.Algorithm { case BITCOIN_ECDSA: - log.Println("Validating", a.Signature, a.Address, a.Data) // Validate verifies a Bitcoin signed message signature return bitcoin.VerifyMessage(a.Address, a.Signature, strings.Join(a.Data, "")) } @@ -148,7 +147,5 @@ func ValidateTapes(tapes []bob.Tape) bool { a := New() a.FromTape(aipTape) a.SetData(tapes) - - log.Println("Data was set", a.Data) return a.Validate() } diff --git a/aip_test.go b/aip_test.go index 9cc8dae..500922d 100644 --- a/aip_test.go +++ b/aip_test.go @@ -14,35 +14,19 @@ import ( // const sampleBobTx = `{ "_id": "5f08ddeed1352a2c3432f4db", "tx": { "h": "26b754e6fdf04121b8d91160a0b252a22ae30204fc552605b7f6d3f08419f29e" }, "in": [ { "i": 0, "seq": 4294967295, "tape": [ { "cell": [ { "s": "0E\u0002!\u0000����;�Z��\b\th�&���5����6��` + "`" + `\u0016�Z�N\u0002 WUI\u001bz)\nE{\u001f��0�g�꨻*}\u0018QV��dO�D@�A", "h": "3045022100afbbffff3bb55aaec20809689026acbccf35bcb4e2f29c36aaf86016d85abe4e02205755491b7a290a457b1fbea2308567ddeaa8bb2a7d185156a1f3644f854440d941", "b": "MEUCIQCvu///O7VarsIICWiQJqy8zzW8tOLynDaq+GAW2Fq+TgIgV1VJG3opCkV7H76iMIVn3eqouyp9GFFWofNkT4VEQNlB", "i": 0, "ii": 0 }, { "s": "\u0004@��8��x��x���,#\u001d�(��B�A%\f����E��\u0000��T[�=(�\u0017Ϳ\u0001\u0010*\u001cr\\iZ��\u0007Ha�\u0018WM�(", "h": "0440ffb338848f78bfbb78b9b4a82c231dc728ceef42b341250c84ba99cf458bf2af0095df545bef3d28e717cdbf01102a1c725c695adfe40748619518574df228", "b": "BED/sziEj3i/u3i5tKgsIx3HKM7vQrNBJQyEupnPRYvyrwCV31Rb7z0o5xfNvwEQKhxyXGla3+QHSGGVGFdN8ig=", "i": 1, "ii": 1 } ], "i": 0 } ], "e": { "h": "744a55a8637aa191aa058630da51803abbeadc2de3d65b4acace1f5f10789c5b", "i": 1, "a": "1LC16EQVsqVYGeYTCrjvNf8j28zr4DwBuk" } } ], "out": [ { "i": 0, "tape": [ { "cell": [ { "op": 0, "ops": "OP_0", "i": 0, "ii": 0 }, { "op": 106, "ops": "OP_RETURN", "i": 1, "ii": 1 } ], "i": 0 }, { "cell": [ { "s": "1BAPSuaPnfGnSBM3GLV9yhxUdYe4vGbdMT", "h": "31424150537561506e66476e53424d33474c56397968785564596534764762644d54", "b": "MUJBUFN1YVBuZkduU0JNM0dMVjl5aHhVZFllNHZHYmRNVA==", "i": 0, "ii": 2 }, { "s": "ATTEST", "h": "415454455354", "b": "QVRURVNU", "i": 1, "ii": 3 }, { "s": "16ca90ce3c6347132adba40aa0d5faa3b2bf2015678ffc63db1511b676885e25", "h": "31366361393063653363363334373133326164626134306161306435666161336232626632303135363738666663363364623135313162363736383835653235", "b": "MTZjYTkwY2UzYzYzNDcxMzJhZGJhNDBhYTBkNWZhYTNiMmJmMjAxNTY3OGZmYzYzZGIxNTExYjY3Njg4NWUyNQ==", "i": 2, "ii": 4 }, { "s": "0", "h": "30", "b": "MA==", "i": 3, "ii": 5 } ], "i": 1 }, { "cell": [ { "s": "15PciHG22SNLQJXMoSUaWVi7WSqc7hCfva", "h": "313550636948473232534e4c514a584d6f5355615756693757537163376843667661", "b": "MTVQY2lIRzIyU05MUUpYTW9TVWFXVmk3V1NxYzdoQ2Z2YQ==", "i": 0, "ii": 7 }, { "s": "BITCOIN_ECDSA", "h": "424954434f494e5f4543445341", "b": "QklUQ09JTl9FQ0RTQQ==", "i": 1, "ii": 8 }, { "s": "134a6TXxzgQ9Az3w8BcvgdZyA5UqRL89da", "h": "31333461365458787a675139417a33773842637667645a7941355571524c38396461", "b": "MTM0YTZUWHh6Z1E5QXozdzhCY3ZnZFp5QTVVcVJMODlkYQ==", "i": 2, "ii": 9 }, { "s": "\u001f�V���j{k�\u0010ҕ�QA�]�Ӛ` + "`" + `7N����^���)YΓ\u001f@�qWcH}�V��Y�\u0019F�C�V�@�\r�a�", "h": "1fc756c3fcc76a7b6bcf10d295a75141ef5dbbd39a60374ea796eb92d85e84a0a32959ce931f40dc715763487de7a856acca59fc19468343b4569340d20d9761ed", "b": "H8dWw/zHantrzxDSladRQe9du9OaYDdOp5brkthehKCjKVnOkx9A3HFXY0h956hWrMpZ/BlGg0O0VpNA0g2XYe0=", "i": 3, "ii": 10 } ], "i": 2 } ], "e": { "v": 0, "i": 0, "a": "false" } }, { "i": 1, "tape": [ { "cell": [ { "op": 118, "ops": "OP_DUP", "i": 0, "ii": 0 }, { "op": 169, "ops": "OP_HASH160", "i": 1, "ii": 1 }, { "s": "�\no;L˺��E\t^��{i\u0011}", "h": "d27f0a6f3b4ccbbacaf945095ed3eeb97b69117d", "b": "0n8KbztMy7rK+UUJXtPuuXtpEX0=", "i": 2, "ii": 2 }, { "op": 136, "ops": "OP_EQUALVERIFY", "i": 3, "ii": 3 }, { "op": 172, "ops": "OP_CHECKSIG", "i": 4, "ii": 4 } ], "i": 0 } ], "e": { "v": 14491552, "i": 1, "a": "1LC16EQVsqVYGeYTCrjvNf8j28zr4DwBuk" } } ], "lock": 0, "timestamp": 1594416622135 }` // const sampleBobTx = `{ "_id": "5f08ddeed1352a2c3432f4db", "tx": { "h": "26b754e6fdf04121b8d91160a0b252a22ae30204fc552605b7f6d3f08419f29e" }, "in": [ { "i": 0, "seq": 4294967295, "tape": [ { "cell": [ { "s": "0E\u0002!\u0000����;�Z��\b\th�&���5����6��` + "`" + `\u0016�Z�N\u0002 WUI\u001bz)\nE{\u001f��0�g�꨻*}\u0018QV��dO�D@�A", "h": "3045022100afbbffff3bb55aaec20809689026acbccf35bcb4e2f29c36aaf86016d85abe4e02205755491b7a290a457b1fbea2308567ddeaa8bb2a7d185156a1f3644f854440d941", "b": "MEUCIQCvu///O7VarsIICWiQJqy8zzW8tOLynDaq+GAW2Fq+TgIgV1VJG3opCkV7H76iMIVn3eqouyp9GFFWofNkT4VEQNlB", "i": 0, "ii": 0 }, { "s": "\u0004@��8��x��x���,#\u001d�(��B�A%\f����E��\u0000��T[�=(�\u0017Ϳ\u0001\u0010*\u001cr\\iZ��\u0007Ha�\u0018WM�(", "h": "0440ffb338848f78bfbb78b9b4a82c231dc728ceef42b341250c84ba99cf458bf2af0095df545bef3d28e717cdbf01102a1c725c695adfe40748619518574df228", "b": "BED/sziEj3i/u3i5tKgsIx3HKM7vQrNBJQyEupnPRYvyrwCV31Rb7z0o5xfNvwEQKhxyXGla3+QHSGGVGFdN8ig=", "i": 1, "ii": 1 } ], "i": 0 } ], "e": { "h": "744a55a8637aa191aa058630da51803abbeadc2de3d65b4acace1f5f10789c5b", "i": 1, "a": "1LC16EQVsqVYGeYTCrjvNf8j28zr4DwBuk" } } ], "out": [ { "i": 0, "tape": [ { "cell": [ { "op": 0, "ops": "OP_0", "i": 0, "ii": 0 }, { "op": 106, "ops": "OP_RETURN", "i": 1, "ii": 1 } ], "i": 0 }, { "cell": [ { "s": "1BAPSuaPnfGnSBM3GLV9yhxUdYe4vGbdMT", "h": "31424150537561506e66476e53424d33474c56397968785564596534764762644d54", "b": "MUJBUFN1YVBuZkduU0JNM0dMVjl5aHhVZFllNHZHYmRNVA==", "i": 0, "ii": 2 }, { "s": "ATTEST", "h": "415454455354", "b": "QVRURVNU", "i": 1, "ii": 3 }, { "s": "16ca90ce3c6347132adba40aa0d5faa3b2bf2015678ffc63db1511b676885e25", "h": "31366361393063653363363334373133326164626134306161306435666161336232626632303135363738666663363364623135313162363736383835653235", "b": "MTZjYTkwY2UzYzYzNDcxMzJhZGJhNDBhYTBkNWZhYTNiMmJmMjAxNTY3OGZmYzYzZGIxNTExYjY3Njg4NWUyNQ==", "i": 2, "ii": 4 }, { "s": "0", "h": "30", "b": "MA==", "i": 3, "ii": 5 } ], "i": 1 }, { "cell": [ { "s": "15PciHG22SNLQJXMoSUaWVi7WSqc7hCfva", "h": "313550636948473232534e4c514a584d6f5355615756693757537163376843667661", "b": "MTVQY2lIRzIyU05MUUpYTW9TVWFXVmk3V1NxYzdoQ2Z2YQ==", "i": 0, "ii": 7 }, { "s": "BITCOIN_ECDSA", "h": "424954434f494e5f4543445341", "b": "QklUQ09JTl9FQ0RTQQ==", "i": 1, "ii": 8 }, { "s": "134a6TXxzgQ9Az3w8BcvgdZyA5UqRL89da", "h": "31333461365458787a675139417a33773842637667645a7941355571524c38396461", "b": "MTM0YTZUWHh6Z1E5QXozdzhCY3ZnZFp5QTVVcVJMODlkYQ==", "i": 2, "ii": 9 }, { "s": "\u001f�V���j{k�\u0010ҕ�QA�]�Ӛ` + "`" + `7N����^���)YΓ\u001f@�qWcH}�V��Y�\u0019F�C�V�@�\r�a�", "h": "1fc756c3fcc76a7b6bcf10d295a75141ef5dbbd39a60374ea796eb92d85e84a0a32959ce931f40dc715763487de7a856acca59fc19468343b4569340d20d9761ed", "b": "H8dWw/zHantrzxDSladRQe9du9OaYDdOp5brkthehKCjKVnOkx9A3HFXY0h956hWrMpZ/BlGg0O0VpNA0g2XYe0=", "i": 3, "ii": 10 } ], "i": 2 } ], "e": { "v": 0, "i": 0, "a": "false" } }, { "i": 1, "tape": [ { "cell": [ { "op": 118, "ops": "OP_DUP", "i": 0, "ii": 0 }, { "op": 169, "ops": "OP_HASH160", "i": 1, "ii": 1 }, { "s": "�\no;L˺��E\t^��{i\u0011}", "h": "d27f0a6f3b4ccbbacaf945095ed3eeb97b69117d", "b": "0n8KbztMy7rK+UUJXtPuuXtpEX0=", "i": 2, "ii": 2 }, { "op": 136, "ops": "OP_EQUALVERIFY", "i": 3, "ii": 3 }, { "op": 172, "ops": "OP_CHECKSIG", "i": 4, "ii": 4 } ], "i": 0 } ], "e": { "v": 14491552, "i": 1, "a": "1LC16EQVsqVYGeYTCrjvNf8j28zr4DwBuk" } } ], "lock": 0, "timestamp": 1594416622135 }` +// const sampleBobTx = `{ "_id": "5ed07f4b57cd6b1658b817f7", "tx": { "h": "375e67f427d04e1e1a202be6f27ec33a382d3a655af539c079a9f595ec606bef" }, "in": [ { "i": 0, "tape": [ { "cell": [ { "b": "MEQCIAIKjpbGASg3rUKJwqUPW08rlcf+inWtoaTa6fnDV/gMAiBXl1x2YSZpvLi6OVot1+G23BQbIIViDv09YbFXZy+mBUE=", "s": "0D\u0002 \u0002\n���\u0001(7�B�¥\u000f[O+����u�������W�\f\u0002 W�\\va&i���9Z-���\u0014\u001b �b\u000e�=a�Wg/�\u0005A", "ii": 0, "i": 0 }, { "b": "A1B3SiT3OTW6r9F1cT651UwXkAG64vhQJeSnsCrL9fA4", "s": "\u0003PwJ$�95���uq>��L\u0017�\u0001���P%䧰*���8", "ii": 1, "i": 1 } ], "i": 0 } ], "e": { "h": "48e93234cb6aaf1098c4195164e426c67b0104b744758f146e0d1496bb7d6ebf", "i": 5, "a": "1Bpx4FdsENLcFgvkpEmBVu1o2AgqW2Ye5j" }, "seq": 4294967295 } ], "out": [ { "i": 0, "tape": [ { "cell": [ { "op": 0, "ops": "OP_0", "ii": 0, "i": 0 }, { "op": 106, "ops": "OP_RETURN", "ii": 1, "i": 1 } ], "i": 0 }, { "cell": [ { "b": "MUxvdmVGN3FRaWpwamFzY1B5dEhvcjJ1U0VFakhISDhZQg==", "s": "1LoveF7qQijpjascPytHor2uSEEjHHH8YB", "ii": 2, "i": 0 }, { "b": "NWYwNDcwMTEwZTExNTIwNzlmMjU2MjNhZDJjYzNhYmRmOGU0ODU4MzFkMGI1MzJhYzkxNWY3Zjc0MGQ5NWFiMQ==", "s": "5f0470110e1152079f25623ad2cc3abdf8e485831d0b532ac915f7f740d95ab1", "ii": 3, "i": 1 }, { "b": "dHdldGNo", "s": "twetch", "ii": 4, "i": 2 }, { "b": "YmUxMzI0NzYtM2IxZS00Mzk0LTk1YTItODM2Y2I2ZjE3M2I4", "s": "be132476-3b1e-4394-95a2-836cb6f173b8", "ii": 5, "i": 3 } ], "i": 1 }, { "cell": [ { "b": "MTVQY2lIRzIyU05MUUpYTW9TVWFXVmk3V1NxYzdoQ2Z2YQ==", "s": "15PciHG22SNLQJXMoSUaWVi7WSqc7hCfva", "ii": 7, "i": 0 }, { "b": "QklUQ09JTl9FQ0RTQQ==", "s": "BITCOIN_ECDSA", "ii": 8, "i": 1 }, { "b": "MTQ4c3hhY1BYYXBRTmhGQlJuWTlQUFk1cWN5b2lhY0dlcQ==", "s": "148sxacPXapQNhFBRnY9PPY5qcyoiacGeq", "ii": 9, "i": 2 }, { "b": "SVAxUTE0UGxZL1lrRnQwZy9Dd29sdFRKTGhMa2trb3lsOWtJaWhyaE4zWFlQSFRJaDFxbUNteElkTXZ6OTIvaDBnYWdCRnU2ZWtsbUEvMWpaL21DSUV3PQ==", "s": "IP1Q14PlY/YkFt0g/CwoltTJLhLkkkoyl9kIihrhN3XYPHTIh1qmCmxIdMvz92/h0gagBFu6eklmA/1jZ/mCIEw=", "ii": 10, "i": 3 } ], "i": 2 } ], "e": { "v": 0, "i": 0, "a": "false" } }, { "i": 1, "tape": [ { "cell": [ { "op": 118, "ops": "OP_DUP", "ii": 0, "i": 0 }, { "op": 169, "ops": "OP_HASH160", "ii": 1, "i": 1 }, { "b": "tyEUOsrxZFF9FqST84M12N7gJXk=", "s": "�!\u0014:��dQ}\u0016���5���%y", "ii": 2, "i": 2 }, { "op": 136, "ops": "OP_EQUALVERIFY", "ii": 3, "i": 3 }, { "op": 172, "ops": "OP_CHECKSIG", "ii": 4, "i": 4 } ], "i": 0 } ], "e": { "v": 546, "i": 1, "a": "1HhJHUbJskwHEmxnHE62hVZrbWKAZyXegm" } }, { "i": 2, "tape": [ { "cell": [ { "op": 118, "ops": "OP_DUP", "ii": 0, "i": 0 }, { "op": 169, "ops": "OP_HASH160", "ii": 1, "i": 1 }, { "b": "BRhv8HEO0AQinmRMBlOymFxkiiM=", "s": "\u0005\u0018o�q\u000e�\u0004\"�dL\u0006S��\\d�#", "ii": 2, "i": 2 }, { "op": 136, "ops": "OP_EQUALVERIFY", "ii": 3, "i": 3 }, { "op": 172, "ops": "OP_CHECKSIG", "ii": 4, "i": 4 } ], "i": 0 } ], "e": { "v": 4718, "i": 2, "a": "1Twetcht1cTUxpdDoX5HQRpoXeuupAdyf" } }, { "i": 3, "tape": [ { "cell": [ { "op": 118, "ops": "OP_DUP", "ii": 0, "i": 0 }, { "op": 169, "ops": "OP_HASH160", "ii": 1, "i": 1 }, { "b": "ge8V46sxXUTHoX/MDhoMTUDe5aU=", "s": "��\u0015�1]Dǡ�\u000e\u001a\fM@��", "ii": 2, "i": 2 }, { "op": 136, "ops": "OP_EQUALVERIFY", "ii": 3, "i": 3 }, { "op": 172, "ops": "OP_CHECKSIG", "ii": 4, "i": 4 } ], "i": 0 } ], "e": { "v": 6990, "i": 3, "a": "1Cr2ahVvRz5gdNVbKMrNUbqudzeXgVKrx2" } }, { "i": 4, "tape": [ { "cell": [ { "op": 118, "ops": "OP_DUP", "ii": 0, "i": 0 }, { "op": 169, "ops": "OP_HASH160", "ii": 1, "i": 1 }, { "b": "Z3WtDwnQdIHbl2gZcRtaVBF/Xng=", "s": "gu�\u000f\t�t�ۗh\u0019q\u001bZT\u0011^x", "ii": 2, "i": 2 }, { "op": 136, "ops": "OP_EQUALVERIFY", "ii": 3, "i": 3 }, { "op": 172, "ops": "OP_CHECKSIG", "ii": 4, "i": 4 } ], "i": 0 } ], "e": { "v": 13980, "i": 4, "a": "1AS3a2ocVtMEBFxYiyWKywsZYxRyxxWQCZ" } }, { "i": 5, "tape": [ { "cell": [ { "op": 118, "ops": "OP_DUP", "ii": 0, "i": 0 }, { "op": 169, "ops": "OP_HASH160", "ii": 1, "i": 1 }, { "b": "bnGmFJIqldGih1Hpvw+zKO9pbkQ=", "s": "nq�\u0014�*�Ѣ�Q�\u000f�(�inD", "ii": 2, "i": 2 }, { "op": 136, "ops": "OP_EQUALVERIFY", "ii": 3, "i": 3 }, { "op": 172, "ops": "OP_CHECKSIG", "ii": 4, "i": 4 } ], "i": 0 } ], "e": { "v": 1699347, "i": 5, "a": "1B4yUZC7NkikrXPXEyPEQ6WhVBvYz3asN1" } } ], "lock": 0, "blk": { "i": 635130, "h": "000000000000000002f50329db73a826c97deb0e642e142dc81cdfda4b4a39ba", "t": 1589606545 }, "i": 2690 }` func TestValidate(t *testing.T) { - // const sampleBobTx = `{ "_id": "5ed07f4b57cd6b1658b817f7", "tx": { "h": "375e67f427d04e1e1a202be6f27ec33a382d3a655af539c079a9f595ec606bef" }, "in": [ { "i": 0, "tape": [ { "cell": [ { "b": "MEQCIAIKjpbGASg3rUKJwqUPW08rlcf+inWtoaTa6fnDV/gMAiBXl1x2YSZpvLi6OVot1+G23BQbIIViDv09YbFXZy+mBUE=", "s": "0D\u0002 \u0002\n���\u0001(7�B�¥\u000f[O+����u�������W�\f\u0002 W�\\va&i���9Z-���\u0014\u001b �b\u000e�=a�Wg/�\u0005A", "ii": 0, "i": 0 }, { "b": "A1B3SiT3OTW6r9F1cT651UwXkAG64vhQJeSnsCrL9fA4", "s": "\u0003PwJ$�95���uq>��L\u0017�\u0001���P%䧰*���8", "ii": 1, "i": 1 } ], "i": 0 } ], "e": { "h": "48e93234cb6aaf1098c4195164e426c67b0104b744758f146e0d1496bb7d6ebf", "i": 5, "a": "1Bpx4FdsENLcFgvkpEmBVu1o2AgqW2Ye5j" }, "seq": 4294967295 } ], "out": [ { "i": 0, "tape": [ { "cell": [ { "op": 0, "ops": "OP_0", "ii": 0, "i": 0 }, { "op": 106, "ops": "OP_RETURN", "ii": 1, "i": 1 } ], "i": 0 }, { "cell": [ { "b": "MUxvdmVGN3FRaWpwamFzY1B5dEhvcjJ1U0VFakhISDhZQg==", "s": "1LoveF7qQijpjascPytHor2uSEEjHHH8YB", "ii": 2, "i": 0 }, { "b": "NWYwNDcwMTEwZTExNTIwNzlmMjU2MjNhZDJjYzNhYmRmOGU0ODU4MzFkMGI1MzJhYzkxNWY3Zjc0MGQ5NWFiMQ==", "s": "5f0470110e1152079f25623ad2cc3abdf8e485831d0b532ac915f7f740d95ab1", "ii": 3, "i": 1 }, { "b": "dHdldGNo", "s": "twetch", "ii": 4, "i": 2 }, { "b": "YmUxMzI0NzYtM2IxZS00Mzk0LTk1YTItODM2Y2I2ZjE3M2I4", "s": "be132476-3b1e-4394-95a2-836cb6f173b8", "ii": 5, "i": 3 } ], "i": 1 }, { "cell": [ { "b": "MTVQY2lIRzIyU05MUUpYTW9TVWFXVmk3V1NxYzdoQ2Z2YQ==", "s": "15PciHG22SNLQJXMoSUaWVi7WSqc7hCfva", "ii": 7, "i": 0 }, { "b": "QklUQ09JTl9FQ0RTQQ==", "s": "BITCOIN_ECDSA", "ii": 8, "i": 1 }, { "b": "MTQ4c3hhY1BYYXBRTmhGQlJuWTlQUFk1cWN5b2lhY0dlcQ==", "s": "148sxacPXapQNhFBRnY9PPY5qcyoiacGeq", "ii": 9, "i": 2 }, { "b": "SVAxUTE0UGxZL1lrRnQwZy9Dd29sdFRKTGhMa2trb3lsOWtJaWhyaE4zWFlQSFRJaDFxbUNteElkTXZ6OTIvaDBnYWdCRnU2ZWtsbUEvMWpaL21DSUV3PQ==", "s": "IP1Q14PlY/YkFt0g/CwoltTJLhLkkkoyl9kIihrhN3XYPHTIh1qmCmxIdMvz92/h0gagBFu6eklmA/1jZ/mCIEw=", "ii": 10, "i": 3 } ], "i": 2 } ], "e": { "v": 0, "i": 0, "a": "false" } }, { "i": 1, "tape": [ { "cell": [ { "op": 118, "ops": "OP_DUP", "ii": 0, "i": 0 }, { "op": 169, "ops": "OP_HASH160", "ii": 1, "i": 1 }, { "b": "tyEUOsrxZFF9FqST84M12N7gJXk=", "s": "�!\u0014:��dQ}\u0016���5���%y", "ii": 2, "i": 2 }, { "op": 136, "ops": "OP_EQUALVERIFY", "ii": 3, "i": 3 }, { "op": 172, "ops": "OP_CHECKSIG", "ii": 4, "i": 4 } ], "i": 0 } ], "e": { "v": 546, "i": 1, "a": "1HhJHUbJskwHEmxnHE62hVZrbWKAZyXegm" } }, { "i": 2, "tape": [ { "cell": [ { "op": 118, "ops": "OP_DUP", "ii": 0, "i": 0 }, { "op": 169, "ops": "OP_HASH160", "ii": 1, "i": 1 }, { "b": "BRhv8HEO0AQinmRMBlOymFxkiiM=", "s": "\u0005\u0018o�q\u000e�\u0004\"�dL\u0006S��\\d�#", "ii": 2, "i": 2 }, { "op": 136, "ops": "OP_EQUALVERIFY", "ii": 3, "i": 3 }, { "op": 172, "ops": "OP_CHECKSIG", "ii": 4, "i": 4 } ], "i": 0 } ], "e": { "v": 4718, "i": 2, "a": "1Twetcht1cTUxpdDoX5HQRpoXeuupAdyf" } }, { "i": 3, "tape": [ { "cell": [ { "op": 118, "ops": "OP_DUP", "ii": 0, "i": 0 }, { "op": 169, "ops": "OP_HASH160", "ii": 1, "i": 1 }, { "b": "ge8V46sxXUTHoX/MDhoMTUDe5aU=", "s": "��\u0015�1]Dǡ�\u000e\u001a\fM@��", "ii": 2, "i": 2 }, { "op": 136, "ops": "OP_EQUALVERIFY", "ii": 3, "i": 3 }, { "op": 172, "ops": "OP_CHECKSIG", "ii": 4, "i": 4 } ], "i": 0 } ], "e": { "v": 6990, "i": 3, "a": "1Cr2ahVvRz5gdNVbKMrNUbqudzeXgVKrx2" } }, { "i": 4, "tape": [ { "cell": [ { "op": 118, "ops": "OP_DUP", "ii": 0, "i": 0 }, { "op": 169, "ops": "OP_HASH160", "ii": 1, "i": 1 }, { "b": "Z3WtDwnQdIHbl2gZcRtaVBF/Xng=", "s": "gu�\u000f\t�t�ۗh\u0019q\u001bZT\u0011^x", "ii": 2, "i": 2 }, { "op": 136, "ops": "OP_EQUALVERIFY", "ii": 3, "i": 3 }, { "op": 172, "ops": "OP_CHECKSIG", "ii": 4, "i": 4 } ], "i": 0 } ], "e": { "v": 13980, "i": 4, "a": "1AS3a2ocVtMEBFxYiyWKywsZYxRyxxWQCZ" } }, { "i": 5, "tape": [ { "cell": [ { "op": 118, "ops": "OP_DUP", "ii": 0, "i": 0 }, { "op": 169, "ops": "OP_HASH160", "ii": 1, "i": 1 }, { "b": "bnGmFJIqldGih1Hpvw+zKO9pbkQ=", "s": "nq�\u0014�*�Ѣ�Q�\u000f�(�inD", "ii": 2, "i": 2 }, { "op": 136, "ops": "OP_EQUALVERIFY", "ii": 3, "i": 3 }, { "op": 172, "ops": "OP_CHECKSIG", "ii": 4, "i": 4 } ], "i": 0 } ], "e": { "v": 1699347, "i": 5, "a": "1B4yUZC7NkikrXPXEyPEQ6WhVBvYz3asN1" } } ], "lock": 0, "blk": { "i": 635130, "h": "000000000000000002f50329db73a826c97deb0e642e142dc81cdfda4b4a39ba", "t": 1589606545 }, "i": 2690 }` - const sampleBobTx = `{ "_id": "5f08ddb0f797435fbff1ddf0", "tx": { "h": "744a55a8637aa191aa058630da51803abbeadc2de3d65b4acace1f5f10789c5b" }, "in": [ { "i": 0, "seq": 4294967295, "tape": [ { "cell": [ { "s": "0E\u0002!\u0000�\u0000��>�ȇ�ii}6��\\\t.���eB�\u0015\u0016�Ezd\u0002 !��6�V��L\u0002�-)�Ή=\f\u0003\u001co\u001f5|�\u001dn2��A", "h": "3045022100e000f9e33ebac8878269697d368edc5c092ee48be79ec965429e1516d1457a6402202195d036f456a1cf4c02e2aa2d29b5ce893d0c031c6f1f357ce91d6e32e3e8a541", "b": "MEUCIQDgAPnjPrrIh4JpaX02jtxcCS7ki+eeyWVCnhUW0UV6ZAIgIZXQNvRWoc9MAuKqLSm1zok9DAMcbx81fOkdbjLj6KVB", "i": 0, "ii": 0 }, { "s": "\u0004@��8��x��x���,#\u001d�(��B�A%\f����E��\u0000��T[�=(�\u0017Ϳ\u0001\u0010*\u001cr\\iZ��\u0007Ha�\u0018WM�(", "h": "0440ffb338848f78bfbb78b9b4a82c231dc728ceef42b341250c84ba99cf458bf2af0095df545bef3d28e717cdbf01102a1c725c695adfe40748619518574df228", "b": "BED/sziEj3i/u3i5tKgsIx3HKM7vQrNBJQyEupnPRYvyrwCV31Rb7z0o5xfNvwEQKhxyXGla3+QHSGGVGFdN8ig=", "i": 1, "ii": 1 } ], "i": 0 } ], "e": { "h": "eec0d4693a11b441211c046d25ce49514e72be0ce4437f3805af2d93ad905bc3", "i": 1, "a": "1LC16EQVsqVYGeYTCrjvNf8j28zr4DwBuk" } } ], "out": [ { "i": 0, "tape": [ { "cell": [ { "op": 0, "ops": "OP_0", "i": 0, "ii": 0 }, { "op": 106, "ops": "OP_RETURN", "i": 1, "ii": 1 } ], "i": 0 }, { "cell": [ { "s": "1BAPSuaPnfGnSBM3GLV9yhxUdYe4vGbdMT", "h": "31424150537561506e66476e53424d33474c56397968785564596534764762644d54", "b": "MUJBUFN1YVBuZkduU0JNM0dMVjl5aHhVZFllNHZHYmRNVA==", "i": 0, "ii": 2 }, { "s": "ATTEST", "h": "415454455354", "b": "QVRURVNU", "i": 1, "ii": 3 }, { "s": "cf39fc55da24dc23eff1809e6e6cf32a0fe6aecc81296543e9ac84b8c501bac5", "h": "63663339666335356461323464633233656666313830396536653663663332613066653661656363383132393635343365396163383462386335303162616335", "b": "Y2YzOWZjNTVkYTI0ZGMyM2VmZjE4MDllNmU2Y2YzMmEwZmU2YWVjYzgxMjk2NTQzZTlhYzg0YjhjNTAxYmFjNQ==", "i": 2, "ii": 4 }, { "s": "0", "h": "30", "b": "MA==", "i": 3, "ii": 5 } ], "i": 1 }, { "cell": [ { "s": "15PciHG22SNLQJXMoSUaWVi7WSqc7hCfva", "h": "313550636948473232534e4c514a584d6f5355615756693757537163376843667661", "b": "MTVQY2lIRzIyU05MUUpYTW9TVWFXVmk3V1NxYzdoQ2Z2YQ==", "i": 0, "ii": 7 }, { "s": "BITCOIN_ECDSA", "h": "424954434f494e5f4543445341", "b": "QklUQ09JTl9FQ0RTQQ==", "i": 1, "ii": 8 }, { "s": "134a6TXxzgQ9Az3w8BcvgdZyA5UqRL89da", "h": "31333461365458787a675139417a33773842637667645a7941355571524c38396461", "b": "MTM0YTZUWHh6Z1E5QXozdzhCY3ZnZFp5QTVVcVJMODlkYQ==", "i": 2, "ii": 9 }, { "s": "\u001f�nm�3坨\u001b�{\u001f\t��\u0000��(ӏ��h�D��o\u000b\u0006�$�(\u001a�'i��_�\u0006YA\"\f��ޚ` + "`" + `/U.\u0012�^W�\n", "h": "1fe96e6df733e59da81bc07b1f098ff19fad00b3fe28d38f81e768ed44d7c16f0b06932480281ab42769bdbb5fef065941220ccfcdde9a602f552e12dc5e57d70a", "b": "H+lubfcz5Z2oG8B7HwmP8Z+tALP+KNOPgedo7UTXwW8LBpMkgCgatCdpvbtf7wZZQSIMz83emmAvVS4S3F5X1wo=", "i": 3, "ii": 10 } ], "i": 2 } ], "e": { "v": 0, "i": 0, "a": "false" } }, { "i": 1, "tape": [ { "cell": [ { "op": 118, "ops": "OP_DUP", "i": 0, "ii": 0 }, { "op": 169, "ops": "OP_HASH160", "i": 1, "ii": 1 }, { "s": "�\no;L˺��E\t^��{i\u0011}", "h": "d27f0a6f3b4ccbbacaf945095ed3eeb97b69117d", "b": "0n8KbztMy7rK+UUJXtPuuXtpEX0=", "i": 2, "ii": 2 }, { "op": 136, "ops": "OP_EQUALVERIFY", "i": 3, "ii": 3 }, { "op": 172, "ops": "OP_CHECKSIG", "i": 4, "ii": 4 } ], "i": 0 } ], "e": { "v": 14492205, "i": 1, "a": "1LC16EQVsqVYGeYTCrjvNf8j28zr4DwBuk" } } ], "lock": 0, "timestamp": 1594416560292 }` + const sampleBobTx = `{ "_id": "5f08ddb0f797435fbff1ddf0", "tx": { "h": "744a55a8637aa191aa058630da51803abbeadc2de3d65b4acace1f5f10789c5b" }, "out": [ { "i": 0, "tape": [ { "cell": [ { "op": 0, "ops": "OP_0", "i": 0, "ii": 0 }, { "op": 106, "ops": "OP_RETURN", "i": 1, "ii": 1 } ], "i": 0 }, { "cell": [ { "s": "1BAPSuaPnfGnSBM3GLV9yhxUdYe4vGbdMT", "h": "31424150537561506e66476e53424d33474c56397968785564596534764762644d54", "b": "MUJBUFN1YVBuZkduU0JNM0dMVjl5aHhVZFllNHZHYmRNVA==", "i": 0, "ii": 2 }, { "s": "ATTEST", "h": "415454455354", "b": "QVRURVNU", "i": 1, "ii": 3 }, { "s": "cf39fc55da24dc23eff1809e6e6cf32a0fe6aecc81296543e9ac84b8c501bac5", "h": "63663339666335356461323464633233656666313830396536653663663332613066653661656363383132393635343365396163383462386335303162616335", "b": "Y2YzOWZjNTVkYTI0ZGMyM2VmZjE4MDllNmU2Y2YzMmEwZmU2YWVjYzgxMjk2NTQzZTlhYzg0YjhjNTAxYmFjNQ==", "i": 2, "ii": 4 }, { "s": "0", "h": "30", "b": "MA==", "i": 3, "ii": 5 } ], "i": 1 }, { "cell": [ { "s": "15PciHG22SNLQJXMoSUaWVi7WSqc7hCfva", "h": "313550636948473232534e4c514a584d6f5355615756693757537163376843667661", "b": "MTVQY2lIRzIyU05MUUpYTW9TVWFXVmk3V1NxYzdoQ2Z2YQ==", "i": 0, "ii": 7 }, { "s": "BITCOIN_ECDSA", "h": "424954434f494e5f4543445341", "b": "QklUQ09JTl9FQ0RTQQ==", "i": 1, "ii": 8 }, { "s": "134a6TXxzgQ9Az3w8BcvgdZyA5UqRL89da", "h": "31333461365458787a675139417a33773842637667645a7941355571524c38396461", "b": "MTM0YTZUWHh6Z1E5QXozdzhCY3ZnZFp5QTVVcVJMODlkYQ==", "i": 2, "ii": 9 }, { "s": "\u001f�nm�3坨\u001b�{\u001f\t��\u0000��(ӏ��h�D��o\u000b\u0006�$�(\u001a�'i��_�\u0006YA\"\f��ޚ` + "`" + `/U.\u0012�^W�\n", "h": "1fe96e6df733e59da81bc07b1f098ff19fad00b3fe28d38f81e768ed44d7c16f0b06932480281ab42769bdbb5fef065941220ccfcdde9a602f552e12dc5e57d70a", "b": "H+lubfcz5Z2oG8B7HwmP8Z+tALP+KNOPgedo7UTXwW8LBpMkgCgatCdpvbtf7wZZQSIMz83emmAvVS4S3F5X1wo=", "i": 3, "ii": 10 } ], "i": 2 } ], "e": { "v": 0, "i": 0, "a": "false" } }, { "i": 1, "tape": [ { "cell": [ { "op": 118, "ops": "OP_DUP", "i": 0, "ii": 0 }, { "op": 169, "ops": "OP_HASH160", "i": 1, "ii": 1 }, { "s": "�\no;L˺��E\t^��{i\u0011}", "h": "d27f0a6f3b4ccbbacaf945095ed3eeb97b69117d", "b": "0n8KbztMy7rK+UUJXtPuuXtpEX0=", "i": 2, "ii": 2 }, { "op": 136, "ops": "OP_EQUALVERIFY", "i": 3, "ii": 3 }, { "op": 172, "ops": "OP_CHECKSIG", "i": 4, "ii": 4 } ], "i": 0 } ], "e": { "v": 14492205, "i": 1, "a": "1LC16EQVsqVYGeYTCrjvNf8j28zr4DwBuk" } } ], "lock": 0, "timestamp": 1594416560292 }` bobData := bob.New() bobData.FromString(sampleBobTx) - // if bobData.Tx.H != "744a55a8637aa191aa058630da51803abbeadc2de3d65b4acace1f5f10789c5b" { - // t.Error("From String Failed") - // } - tapes := bobData.Out[0].Tape if !ValidateTapes(tapes) { t.Error("Failed to validate AIP signature") } - - // bobData2 := bob.New() - // bobData2.FromString(sampleBobTx2) - - // if bobData2.Tx.H != "6c6e52da3f16f6a03a9ee5bfd68dd6a9fb7fce16fc66f137a265a4bf7cbb4cba" { - // t.Error("From String Failed") - // } - - // tapes2 := bobData2.Out[0].Tape - // if !ValidateTapes(tapes2) { - // t.Error("Failed to validate AIP signature 2") - // } } func TestSetData(t *testing.T) { @@ -54,9 +38,10 @@ func TestSetData(t *testing.T) { aip := New() aip.SetData(bobData.Out[0].Tape) - // 1BAPSuaPnfGnSBM3GLV9yhxUdYe4vGbdMT ATTEST cf39fc55da24dc23eff1809e6e6cf32a0fe6aecc81296543e9ac84b8c501bac5 0 | - if aip.Data[0] != "1BAPSuaPnfGnSBM3GLV9yhxUdYe4vGbdMT" || aip.Data[1] != "ATTEST" && aip.Data[2] != "cf39fc55da24dc23eff1809e6e6cf32a0fe6aecc81296543e9ac84b8c501bac5" || aip.Data[3] != "0" { - t.Error("Failed setting aip data") + // 0x6a 1BAPSuaPnfGnSBM3GLV9yhxUdYe4vGbdMT ATTEST cf39fc55da24dc23eff1809e6e6cf32a0fe6aecc81296543e9ac84b8c501bac5 0 | + // 0x6a (OP_RETURN) in ascii is 'j' + if aip.Data[0] != "j" || aip.Data[1] != "1BAPSuaPnfGnSBM3GLV9yhxUdYe4vGbdMT" || aip.Data[2] != "ATTEST" && aip.Data[3] != "cf39fc55da24dc23eff1809e6e6cf32a0fe6aecc81296543e9ac84b8c501bac5" || aip.Data[4] != "0" { + t.Errorf("Failed setting aip data %+v", aip.Data) } }