Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NIP57 zap request support #17

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion pay.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ func CallPay(
msats int64,
comment string,
payerdata *PayerDataValues,
zapRequest *string,
) (*LNURLPayValues, error) {
qs := callback.Query()
qs.Set("amount", strconv.FormatInt(msats, 10))
Expand All @@ -44,6 +45,10 @@ func CallPay(
qs.Set("payerdata", payerdataJSON)
}

if zapRequest != nil {
qs.Set("nostr", *zapRequest)
}

callback.RawQuery = qs.Encode()
resp, err := actualClient.Get(callback.String())
if err != nil {
Expand Down Expand Up @@ -75,7 +80,9 @@ func CallPay(
values.PayerDataJSON = payerdataJSON

var hhash [32]byte
if payerdata != nil {
if zapRequest != nil {
hhash = sha256.Sum256([]byte(*zapRequest))
} else if payerdata != nil {
hhash = sha256.Sum256([]byte(metadata + payerdataJSON))
} else {
hhash = sha256.Sum256([]byte(metadata))
Expand Down Expand Up @@ -141,6 +148,8 @@ type LNURLPayParams struct {
EncodedMetadata string `json:"metadata"`
CommentAllowed int64 `json:"commentAllowed"`
PayerData *PayerDataSpec `json:"payerData,omitempty"`
AllowsNostr bool `json:"allowsNostr"`
NostrPubkey string `json:"nostrPubkey"`

Metadata Metadata `json:"-"`
}
Expand Down Expand Up @@ -302,6 +311,7 @@ func (params *LNURLPayParams) Normalize() error {
func (params LNURLPayParams) Call(
msats int64,
comment string,
zapRequest *string,
payerdata *PayerDataValues,
) (*LNURLPayValues, error) {
if params.PayerData == nil || !params.PayerData.Exists() {
Expand Down Expand Up @@ -334,12 +344,17 @@ func (params LNURLPayParams) Call(
}
}

if !params.AllowsNostr || params.NostrPubkey == "" {
zapRequest = nil
}

return CallPay(
params.MetadataEncoded(),
params.CallbackURL(),
msats,
comment,
payerdata,
zapRequest,
)
}

Expand Down