Skip to content

Commit

Permalink
Merge pull request #1 from BitcoinSchema/from-bpu
Browse files Browse the repository at this point in the history
From bpu
  • Loading branch information
rohenaz authored Nov 10, 2023
2 parents 95b83e1 + c00d51d commit b499597
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 1 deletion.
56 changes: 56 additions & 0 deletions bob.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package sigma

import (
"strconv"

"github.com/bitcoinschema/go-bpu"
)

func NewSigFromTape(tape bpu.Tape, vout int) (s *Sig) {
s = new(Sig)
s.FromTape(tape, vout)
return
}

// FromTape takes a BOB Tape and returns an Aip data structure.
// Using the FromTape() alone will prevent validation (data is needed via SetData to enable)
func (s *Sig) FromTape(tape bpu.Tape, vout int) {

// Not a valid tape?
if len(tape.Cell) < 4 {
return
}

// Loop to find start of AIP
var startIndex int
found := false
for i, cell := range tape.Cell {
if *cell.S == Prefix {
startIndex = i
found = true
break
}
}

if !found || len(tape.Cell) < 5 {
return
}
s.TargetVout = vout
// Set the SIGMA fields
if tape.Cell[startIndex+1].S != nil {
s.Algorithm = Algorithm(*tape.Cell[startIndex+1].S)
}
if tape.Cell[startIndex+2].S != nil {
s.Address = *tape.Cell[startIndex+2].S
}
if tape.Cell[startIndex+3].B != nil {
s.Signature = *tape.Cell[startIndex+3].B
}
if tape.Cell[startIndex+4].S != nil {
vin, err := strconv.Atoi(*tape.Cell[startIndex+4].S)
if err != nil {
return
}
s.Vin = int(vin)
}
}
5 changes: 4 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ module github.com/bitcoinschema/go-sigma

go 1.21.3

require github.com/libsv/go-bt/v2 v2.2.5
require (
github.com/bitcoinschema/go-bpu v0.1.3
github.com/libsv/go-bt/v2 v2.2.5
)

require (
github.com/bitcoinsv/bsvd v0.0.0-20190609155523-4c29707f7173 // indirect
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
github.com/bitcoinschema/go-bitcoin/v2 v2.0.5 h1:Sgh5Eb746Zck/46rFDrZZEXZWyO53fMuWYhNoZa1tck=
github.com/bitcoinschema/go-bitcoin/v2 v2.0.5/go.mod h1:JjO1ivfZv6vhK0uAXzyH08AAHlzNMAfnyK1Fiv9r4ZA=
github.com/bitcoinschema/go-bpu v0.1.3 h1:O7SvuptH4Q7hemD6G9OotPLINZ61CAVOgWKJWKM+edY=
github.com/bitcoinschema/go-bpu v0.1.3/go.mod h1:y4ZEDC0fSYRrA6N6bzKwHXdtMrRiQhpurpkTVobz07I=
github.com/bitcoinsv/bsvd v0.0.0-20190609155523-4c29707f7173 h1:2yTIV9u7H0BhRDGXH5xrAwAz7XibWJtX2dNezMeNsUo=
github.com/bitcoinsv/bsvd v0.0.0-20190609155523-4c29707f7173/go.mod h1:BZ1UcC9+tmcDEcdVXgpt13hMczwJxWzpAn68wNs7zRA=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
Expand Down
1 change: 1 addition & 0 deletions sigma.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (

type Algorithm string

const Prefix = "SIGMA"
const sigmaHex = "5349474d41"
const (
BSM Algorithm = "BSM"
Expand Down

0 comments on commit b499597

Please sign in to comment.