From cdfbca390f87cc70bcd61ce90bac93f9c52d951f Mon Sep 17 00:00:00 2001 From: armyhaylenko Date: Fri, 24 Apr 2026 11:30:18 +0300 Subject: [PATCH] feat(types): add native transfer approval --- client/intents.go | 3 +++ types/approvals.go | 21 ++++++++++++++++++++- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/client/intents.go b/client/intents.go index de32a07..cc64fc0 100644 --- a/client/intents.go +++ b/client/intents.go @@ -59,6 +59,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.ApprovalToSignTypeNativeTransfer: + resp.NativeTransfer = new(types.ApprovalToSignNativeTransfer) + return json.Unmarshal(raw.ParamsToSign, resp.NativeTransfer) default: return fmt.Errorf("unrecognized approval mechanism %v", resp.ApprovalMechanism) } diff --git a/types/approvals.go b/types/approvals.go index 00423e7..73398f7 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|nativetransfer` fields will be not nil (corresponding). type ApprovalToSign struct { ApprovalMechanism ApprovalToSignType Permit2 *ApprovalToSignPermit2 Htlc *ApprovalToSignHtlc Cosign *ApprovalToSignCosign + NativeTransfer *ApprovalToSignNativeTransfer } // 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" + // ApprovalToSignTypeNativeTransfer defines `nativetransfer` approval types. + ApprovalToSignTypeNativeTransfer ApprovalToSignType = "nativetransfer" ) // ApprovalToSignPermit2 represents parameters of a permit2 approval used to authorize a resolver as a spender. @@ -68,12 +71,18 @@ type ApprovalToSignCosign struct { Nonce int64 `json:"nonce"` } +// ApprovalToSignNativeTransfer represents parameters of a native transfer approval used for Ethereum/Tron networks. +type ApprovalToSignNativeTransfer struct { + ResolverSignature string `json:"resolver_signature"` +} + // IntentApproval is a container for the intent approval. type IntentApproval struct { approvalMechanism ApprovalToSignType permit2 *string psbt *string cosign *CosignApproval + nativeTransfer *string } // NewPermit2IntentApproval creates a new intent approval for permit2. @@ -103,6 +112,14 @@ func NewCosignIntentApproval(transaction string, userAddress string) IntentAppro } } +// NewNativeTransferIntentApproval creates a new intent approval for native transfer. +func NewNativeTransferIntentApproval(transactionHash string) IntentApproval { + return IntentApproval{ + approvalMechanism: ApprovalToSignTypeNativeTransfer, + nativeTransfer: &transactionHash, + } +} + // MarshalJSON implements json.Marshaler interface. func (a *IntentApproval) MarshalJSON() ([]byte, error) { var v = addIntentApprovalRequestCodec{Type: string(a.approvalMechanism)} @@ -114,6 +131,8 @@ func (a *IntentApproval) MarshalJSON() ([]byte, error) { v.SignedData = *a.psbt case a.approvalMechanism == ApprovalToSignTypeCosign && a.cosign != nil: v.SignedData = *a.cosign + case a.approvalMechanism == ApprovalToSignTypeNativeTransfer && a != nil: + v.SignedData = *a.nativeTransfer default: return nil, fmt.Errorf("unrecognized approval mechanism %v or missing signed data", a.approvalMechanism) }