Skip to content

Commit cdfbca3

Browse files
committed
feat(types): add native transfer approval
1 parent 0c826e0 commit cdfbca3

2 files changed

Lines changed: 23 additions & 1 deletion

File tree

client/intents.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,9 @@ func (resp *CreateIntentResponse) UnmarshalJSON(data []byte) error {
5959
case types.ApprovalToSignTypeCosign:
6060
resp.Cosign = new(types.ApprovalToSignCosign)
6161
return json.Unmarshal(raw.ParamsToSign, resp.Cosign)
62+
case types.ApprovalToSignTypeNativeTransfer:
63+
resp.NativeTransfer = new(types.ApprovalToSignNativeTransfer)
64+
return json.Unmarshal(raw.ParamsToSign, resp.NativeTransfer)
6265
default:
6366
return fmt.Errorf("unrecognized approval mechanism %v", resp.ApprovalMechanism)
6467
}

types/approvals.go

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,13 @@ import (
1010
// ApprovalToSign defines approval mechanisms used by different blockchains to transfer ownership of funds to resolver.
1111
//
1212
// `approvalMechanism` holds the type of approval mechanism required for signing operations, and one of
13-
// the `permit2|htlc|cosign` fields will be not nil (corresponding).
13+
// the `permit2|htlc|cosign|nativetransfer` fields will be not nil (corresponding).
1414
type ApprovalToSign struct {
1515
ApprovalMechanism ApprovalToSignType
1616
Permit2 *ApprovalToSignPermit2
1717
Htlc *ApprovalToSignHtlc
1818
Cosign *ApprovalToSignCosign
19+
NativeTransfer *ApprovalToSignNativeTransfer
1920
}
2021

2122
// ApprovalToSignType represents the type of approval mechanism required for signing operations.
@@ -28,6 +29,8 @@ const (
2829
ApprovalToSignTypeHtlc ApprovalToSignType = "htlc"
2930
// ApprovalToSignTypeCosign defines `cosign` approval types.
3031
ApprovalToSignTypeCosign ApprovalToSignType = "cosign"
32+
// ApprovalToSignTypeNativeTransfer defines `nativetransfer` approval types.
33+
ApprovalToSignTypeNativeTransfer ApprovalToSignType = "nativetransfer"
3134
)
3235

3336
// ApprovalToSignPermit2 represents parameters of a permit2 approval used to authorize a resolver as a spender.
@@ -68,12 +71,18 @@ type ApprovalToSignCosign struct {
6871
Nonce int64 `json:"nonce"`
6972
}
7073

74+
// ApprovalToSignNativeTransfer represents parameters of a native transfer approval used for Ethereum/Tron networks.
75+
type ApprovalToSignNativeTransfer struct {
76+
ResolverSignature string `json:"resolver_signature"`
77+
}
78+
7179
// IntentApproval is a container for the intent approval.
7280
type IntentApproval struct {
7381
approvalMechanism ApprovalToSignType
7482
permit2 *string
7583
psbt *string
7684
cosign *CosignApproval
85+
nativeTransfer *string
7786
}
7887

7988
// NewPermit2IntentApproval creates a new intent approval for permit2.
@@ -103,6 +112,14 @@ func NewCosignIntentApproval(transaction string, userAddress string) IntentAppro
103112
}
104113
}
105114

115+
// NewNativeTransferIntentApproval creates a new intent approval for native transfer.
116+
func NewNativeTransferIntentApproval(transactionHash string) IntentApproval {
117+
return IntentApproval{
118+
approvalMechanism: ApprovalToSignTypeNativeTransfer,
119+
nativeTransfer: &transactionHash,
120+
}
121+
}
122+
106123
// MarshalJSON implements json.Marshaler interface.
107124
func (a *IntentApproval) MarshalJSON() ([]byte, error) {
108125
var v = addIntentApprovalRequestCodec{Type: string(a.approvalMechanism)}
@@ -114,6 +131,8 @@ func (a *IntentApproval) MarshalJSON() ([]byte, error) {
114131
v.SignedData = *a.psbt
115132
case a.approvalMechanism == ApprovalToSignTypeCosign && a.cosign != nil:
116133
v.SignedData = *a.cosign
134+
case a.approvalMechanism == ApprovalToSignTypeNativeTransfer && a != nil:
135+
v.SignedData = *a.nativeTransfer
117136
default:
118137
return nil, fmt.Errorf("unrecognized approval mechanism %v or missing signed data", a.approvalMechanism)
119138
}

0 commit comments

Comments
 (0)