From 35da03aaa18a04bc8cd1cdb9ca173518ff211b86 Mon Sep 17 00:00:00 2001 From: Oleh Date: Mon, 14 Sep 2026 17:41:52 +0300 Subject: [PATCH 1/2] Added user-transfer support --- client/intents.go | 28 ++++++++++++++++++++++++++++ types/approvals.go | 10 +++++++++- types/intents.go | 4 ++++ 3 files changed, 41 insertions(+), 1 deletion(-) diff --git a/client/intents.go b/client/intents.go index 03013c3..411dc77 100644 --- a/client/intents.go +++ b/client/intents.go @@ -40,6 +40,7 @@ func (resp *CreateIntentResponse) UnmarshalJSON(data []byte) error { SecretHash string `json:"secret_hash"` ApprovalMechanism types.ApprovalToSignType `json:"approval_mechanism"` ParamsToSign json.RawMessage `json:"params_to_sign"` + TransferAddress string `json:"transfer_address"` } var raw createIntentResponseCodec @@ -62,6 +63,14 @@ func (resp *CreateIntentResponse) UnmarshalJSON(data []byte) error { case types.ApprovalToSignTypeCosign: resp.Cosign = new(types.ApprovalToSignCosign) return json.Unmarshal(raw.ParamsToSign, resp.Cosign) + case types.ApprovalToSignTypeNone: + if raw.TransferAddress == "" { + return fmt.Errorf("no approval mechanism and no transfer address in the response") + } + + resp.Transfer = &types.ApprovalToSignTransfer{Address: raw.TransferAddress} + + return nil default: return fmt.Errorf("unrecognized approval mechanism %v", resp.ApprovalMechanism) } @@ -88,6 +97,25 @@ func (c *Client) AddIntentApproval(ctx context.Context, params AddIntentApproval return c.doRequest(ctx, http.MethodPost, endpoint, ¶ms.Approval, nil) } +// SubmitDepositParams represents parameters required to report a deposit the user made themselves. +type SubmitDepositParams struct { + IntentID uuid.UUID `json:"-"` + TxHash string `json:"tx_hash"` +} + +// SubmitDepositResponse represents the response from the SubmitDeposit API endpoint. +type SubmitDepositResponse struct { + FulfillmentDeadline int64 `json:"fulfillment_deadline"` +} + +// SubmitDeposit reports the transaction hash of a transfer the user broadcast themselves. +func (c *Client) SubmitDeposit(ctx context.Context, params SubmitDepositParams) (SubmitDepositResponse, error) { + var resp SubmitDepositResponse + endpoint := c.buildURL("intents/%s/deposit", params.IntentID.String()) + + return resp, c.doRequest(ctx, http.MethodPost, endpoint, ¶ms, &resp) +} + // GetIntentStatusResponse represents the response from the GetIntentStatus API endpoint. type GetIntentStatusResponse struct { Status types.CombinedStatus `json:"status"` diff --git a/types/approvals.go b/types/approvals.go index 00423e7..af05807 100644 --- a/types/approvals.go +++ b/types/approvals.go @@ -10,12 +10,13 @@ import ( // ApprovalToSign defines approval mechanisms used by different blockchains to transfer ownership of funds to resolver. // // `approvalMechanism` holds the type of approval mechanism required for signing operations, and one of -// the `permit2|htlc|cosign` fields will be not nil (corresponding). +// the `permit2|htlc|cosign|transfer` fields will be not nil (corresponding). type ApprovalToSign struct { ApprovalMechanism ApprovalToSignType Permit2 *ApprovalToSignPermit2 Htlc *ApprovalToSignHtlc Cosign *ApprovalToSignCosign + Transfer *ApprovalToSignTransfer } // ApprovalToSignType represents the type of approval mechanism required for signing operations. @@ -28,6 +29,8 @@ const ( ApprovalToSignTypeHtlc ApprovalToSignType = "htlc" // ApprovalToSignTypeCosign defines `cosign` approval types. ApprovalToSignTypeCosign ApprovalToSignType = "cosign" + // ApprovalToSignTypeNone is sent when no signature is needed + ApprovalToSignTypeNone ApprovalToSignType = "" ) // ApprovalToSignPermit2 represents parameters of a permit2 approval used to authorize a resolver as a spender. @@ -49,6 +52,11 @@ type Permit2AdditionalData struct { WitnessHash string `json:"witness_hash"` } +// ApprovalToSignTransfer carries the address the user sends a plain transfer to. +type ApprovalToSignTransfer struct { + Address string +} + // ParseWitness unmarshalls raw witness data into the provided struct. // // NOTE: `val` must be a pointer to a struct that implements `json.Unmarshaler`. diff --git a/types/intents.go b/types/intents.go index 25e86ce..ea9abcc 100644 --- a/types/intents.go +++ b/types/intents.go @@ -26,6 +26,10 @@ const ( CombinedStatusRefundRequested CombinedStatus = "RefundRequested" // CombinedStatusRefunded defines the `Refunded` status. CombinedStatusRefunded CombinedStatus = "Refunded" + // CombinedStatusAwaitingBroadcast defines the `AwaitingBroadcast` status. + CombinedStatusAwaitingBroadcast CombinedStatus = "AwaitingBroadcast" + // CombinedStatusLapsed defines the `Lapsed` status. + CombinedStatusLapsed CombinedStatus = "Lapsed" ) func (s CombinedStatus) String() string { From 843ecdd82b9276b427bbc515b846af1f0cc09c8d Mon Sep 17 00:00:00 2001 From: Oleh Date: Tue, 15 Sep 2026 17:51:32 +0300 Subject: [PATCH 2/2] Added ApprovalToSignTypeTransfer --- client/intents.go | 6 +++--- types/approvals.go | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/client/intents.go b/client/intents.go index 411dc77..b5b3ce9 100644 --- a/client/intents.go +++ b/client/intents.go @@ -63,9 +63,9 @@ func (resp *CreateIntentResponse) UnmarshalJSON(data []byte) error { case types.ApprovalToSignTypeCosign: resp.Cosign = new(types.ApprovalToSignCosign) return json.Unmarshal(raw.ParamsToSign, resp.Cosign) - case types.ApprovalToSignTypeNone: + case types.ApprovalToSignTypeTransfer: if raw.TransferAddress == "" { - return fmt.Errorf("no approval mechanism and no transfer address in the response") + return fmt.Errorf("transfer approval mechanism without a transfer address") } resp.Transfer = &types.ApprovalToSignTransfer{Address: raw.TransferAddress} @@ -100,7 +100,7 @@ func (c *Client) AddIntentApproval(ctx context.Context, params AddIntentApproval // SubmitDepositParams represents parameters required to report a deposit the user made themselves. type SubmitDepositParams struct { IntentID uuid.UUID `json:"-"` - TxHash string `json:"tx_hash"` + TxHash string `json:"tx_hash"` } // SubmitDepositResponse represents the response from the SubmitDeposit API endpoint. diff --git a/types/approvals.go b/types/approvals.go index af05807..361247a 100644 --- a/types/approvals.go +++ b/types/approvals.go @@ -29,8 +29,8 @@ const ( ApprovalToSignTypeHtlc ApprovalToSignType = "htlc" // ApprovalToSignTypeCosign defines `cosign` approval types. ApprovalToSignTypeCosign ApprovalToSignType = "cosign" - // ApprovalToSignTypeNone is sent when no signature is needed - ApprovalToSignTypeNone ApprovalToSignType = "" + // ApprovalToSignTypeTransfer defines the user-transfer flow. + ApprovalToSignTypeTransfer ApprovalToSignType = "transfer" ) // ApprovalToSignPermit2 represents parameters of a permit2 approval used to authorize a resolver as a spender.