-
Notifications
You must be signed in to change notification settings - Fork 4
/
construction_api.go
151 lines (130 loc) · 5.9 KB
/
construction_api.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
package rosettaFilecoinLib
import (
"github.com/filecoin-project/go-address"
"github.com/ipfs/go-cid"
)
type RosettaConstructionTool interface {
// DeriveFromPublicKey defines the function to derive the address from an public key (secp256k1)
// @return
// - derivedAddress [string]
// - error when deriving address from the public key
DeriveFromPublicKey(publicKey []byte, network address.Network) (string, error)
// Sign defines the function to sign an arbitrary message with the secret key (secp256k1)
// @message [[]byte] a digest
// @return (secp256k1)
// - signature [string] the signature after the message is signed with the private key
// - error when signing a message
SignRaw(message []byte, sk []byte) ([]byte, error)
// Verify defines the function to verify the signature of an arbitrary message with the public key (secp256k1)
// @message [[]byte] a digest
// @return
// - error if invalid signature
VerifyRaw(message []byte, publicKey []byte, signature []byte) error
// ConstructPayment creates transaction for a normal send
// @return
// - unsigned transaction as json [string]
// - error while constructing the normal send transaction
ConstructPayment(request *PaymentRequest) (string, error)
// ConstructMultisigPayment creates transaction for a multisig send
// @return
// - unsigned transaction as json [string]
// - error while constructing the multisig send transaction
ConstructMultisigPayment(request *MultisigPaymentRequest, destinationActorId cid.Cid) (string, error)
// ConstructSwapAuthorizedParty creates transaction for a multisig SwapAuthorizedParty call
// @return
// - unsigned transaction as json [string]
// - error while constructing the multisig SwapAuthorizedParty call
ConstructSwapAuthorizedParty(request *MultisigPaymentRequest, destinationActorId cid.Cid) (string, error)
// ConstructRemoveAuthorizedParty creates transaction for a multisig RemoveAuthorizedParty call
// @return
// - unsigned transaction as json [string]
// - error while constructing the multisig RemoveAuthorizedParty call
ConstructRemoveAuthorizedParty(request *MultisigPaymentRequest, destinationActorId cid.Cid) (string, error)
// SignTx signs an unsignedTx (CBOR) using the secret key (secp256k1) and returns a signedTx
// @unsignedTransaction [string] unsigned transaction as CBOR
// @sk [[]byte] secp256k1 secret key
// @return
// - signedTx [string] the signed transaction as CBOR
// - error when signing a transaction
SignTx(unsignedTx []byte, sk []byte) ([]byte, error)
// SignTxJSON signs an unsignedTx (JSON) using the secret key (secp256k1) and return a signedTx
// @unsignedTransaction [string] unsigned transaction as JSON
// @sk [[]byte] secp256k1 secret key
// @return
// - signedTx [string] the signed transaction
// - error when signing a transaction
SignTxJSON(unsignedTransaction string, sk []byte) (string, error)
// ParseTx parses CBOR encoded transaction
// @tx [[]byte] signed or unsigned transaction CBOR encoded
// @return
// - message [string] the parsed transaction (message or unsigned message) represented as a JSON string
// - error when parsing a transaction
ParseTx(messageCbor []byte) (string, error)
// ParseParamsMultisigTx parses a JSON encoded transaction and decodes actor paramss assuming the destination
// address correspond to a multisig actor
// @tx [string] signed or unsigned transaction JSON encoded
// @return
// - message [string] the parsed params represented as a JSON string
// - error when parsing a transaction
ParseParamsMultisigTx(message string, destinationActorId cid.Cid) (string, error)
// Hash defines the function to calculate a tx hash
// @signedTx [string] base64 encoded signed transaction
// @return
// - txHash [string] transaction hash
// - error when calculating the tx hash
Hash(signedTx string) (string, error)
}
// Modify this as needed to add in new fields
type TxMetadata struct {
Nonce uint64 `json:"nonce"`
GasFeeCap string `json:"gasFeeCap"`
GasPremium string `json:"gasPremium"`
GasLimit int64 `json:"gasLimit,omitempty"`
ChainID string `json:"chainId,omitempty"`
Method uint64 `json:"method,omitempty"`
Params []byte `json:"params,omitempty"`
}
// PaymentRequest defines the input to ConstructPayment
type PaymentRequest struct {
From string `json:"from"`
To string `json:"to"`
Quantity string `json:"quantity"`
Metadata TxMetadata `json:"metadata"`
}
// MultisigPaymentParams defines params for MultisigPaymentRequest
type MultisigPaymentParams struct {
To string `json:"to"`
Quantity string `json:"quantity"`
}
// MultisigPaymentRequest defines the input to ConstructMultisigPayment
type MultisigPaymentRequest struct {
Multisig string `json:"multisig"`
From string `json:"from"`
Quantity string `json:"quantity"`
Metadata TxMetadata `json:"metadata"`
Params MultisigPaymentParams `json:"params"`
}
// SwapAuthorizedPartyParams defines the params
type SwapAuthorizedPartyParams struct {
From string `json:"from"`
To string `json:"to"`
}
// SwapAuthorizedPartyRequest defines the input to ConstructSwapAuthorizedParty
type SwapAuthorizedPartyRequest struct {
Multisig string `json:"multisig"`
From string `json:"from"`
Metadata TxMetadata `json:"metadata"`
Params SwapAuthorizedPartyParams `json:"params"`
}
// RemoveAuthorizedPartyParams defines the params
type RemoveAuthorizedPartyParams struct {
ToRemove string `json:"toRemove"`
Decrease bool `json:"decrease"`
}
// RemoveAuthorizedPartyRequest defines the input to ConstructRemoveAuthorizedParty
type RemoveAuthorizedPartyRequest struct {
Multisig string `json:"multisig"`
From string `json:"from"`
Metadata TxMetadata `json:"metadata"`
Params RemoveAuthorizedPartyParams `json:"params"`
}