Skip to content

Commit

Permalink
script.Address()
Browse files Browse the repository at this point in the history
  • Loading branch information
shruggr committed Oct 18, 2024
1 parent 958954a commit 29c34cb
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions script/script.go
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,18 @@ func (s *Script) Chunks() ([]*ScriptChunk, error) {
return DecodeScript([]byte(*s))
}

// Address extracts the address from a P2PKH script.
func (s *Script) Address() (*Address, error) {
if !s.IsP2PKH() {
return nil, errors.New("script is not of type ScriptTypePubKeyHash")
}
parts, err := s.Chunks()
if err != nil {
return nil, err
}
return NewAddressFromPublicKeyHash(parts[2].Data, true)
}

// PubKey extracts the public key from a P2PK script.
func (s *Script) PubKey() (*ec.PublicKey, error) {
if !s.IsP2PK() {
Expand Down

0 comments on commit 29c34cb

Please sign in to comment.