@@ -18,16 +18,16 @@ import (
18
18
" math/big"
19
19
20
20
" github.com/everFinance/goar/types"
21
- " github.com/everFinance/goar/wallet "
21
+ " github.com/everFinance/goar"
22
22
)
23
23
24
24
func main () {
25
- wallet , err := wallet. NewFromPath (" ./test-keyfile.json" , " https://arweave.net" )
25
+ wallet , err := goar. NewWalletFromPath (" ./test-keyfile.json" , " https://arweave.net" )
26
26
if err != nil {
27
27
panic (err)
28
28
}
29
29
30
- id , stat , err := wallet.SendWinston (
30
+ id , err := wallet.SendWinston (
31
31
big.NewInt (1 ), // Winston amount
32
32
{{target}}, // target address
33
33
[]types.Tag {
@@ -38,7 +38,7 @@ func main() {
38
38
},
39
39
)
40
40
41
- fmt.Println (id, stat, err) // {{id}}, Pending , nil
41
+ fmt.Println (id, err) // {{id}}, nil
42
42
}
43
43
44
44
```
@@ -52,16 +52,16 @@ import (
52
52
" fmt"
53
53
54
54
" github.com/everFinance/goar/types"
55
- " github.com/everFinance/goar/wallet "
55
+ " github.com/everFinance/goar"
56
56
)
57
57
58
58
func main () {
59
- wallet , err := wallet. NewFromPath (" ./test-keyfile.json" , " https://arweave.net" )
59
+ wallet , err := goar. NewWalletFromPath (" ./test-keyfile.json" , " https://arweave.net" )
60
60
if err != nil {
61
61
panic (err)
62
62
}
63
63
64
- id , stat , err := wallet.SendData (
64
+ id , err := wallet.SendData (
65
65
[]byte (" 123" ), // Data bytes
66
66
[]types.Tag {
67
67
types.Tag {
@@ -71,13 +71,13 @@ func main() {
71
71
},
72
72
)
73
73
74
- fmt.Println (id, stat, err) // {{id}}, Pending , nil
74
+ fmt.Println (id, err) // {{id}}, nil
75
75
}
76
76
```
77
77
78
- ### Golang Package
78
+ ### Components
79
79
80
- #### client
80
+ #### Client
81
81
82
82
- [x] GetInfo
83
83
- [x] GetTransactionByID
@@ -97,49 +97,75 @@ func main() {
97
97
Initialize the instance:
98
98
99
99
``` golang
100
- arClient := New (" https://arweave.net" )
100
+ arClient := goar. NewClient (" https://arweave.net" )
101
101
102
102
// if your network is not good, you can config http proxy
103
103
proxyUrl := " http://127.0.0.1:8001"
104
- arClient := New (" https://arweave.net" , proxyUrl)
104
+ arClient := goar. NewClient (" https://arweave.net" , proxyUrl)
105
105
```
106
106
107
- #### wallet
107
+ #### Wallet
108
108
109
109
- [x] SendAR
110
+ - [x] SendARSpeedUp
110
111
- [x] SendWinston
112
+ - [x] SendWinstonSpeedUp
111
113
- [x] SendData
112
114
- [x] SendDataSpeedUp
113
115
- [x] SendTransaction
114
116
115
117
Initialize the instance, use a keyfile.json:
116
118
117
119
``` golang
118
- arWallet := NewFromPath (" ./keyfile.json" )
120
+ arWallet := goar. NewWalletFromPath (" ./keyfile.json" )
119
121
120
122
// if your network is not good, you can config http proxy
121
123
proxyUrl := " http://127.0.0.1:8001"
122
- arWallet := NewFromPath (" ./keyfile.json" , " https://arweave.net" , proxyUrl)
124
+ arWallet := NewWalletFromPath (" ./keyfile.json" , " https://arweave.net" , proxyUrl)
123
125
```
124
126
127
+ #### Utils
128
+
129
+ Package for Arweave develop toolkit.
130
+
131
+ - [x] Base64Encode
132
+ - [x] Base64Decode
133
+ - [x] Sign
134
+ - [x] Verify
135
+ - [x] DeepHash
136
+ - [x] GenerateChunks
137
+ - [x] ValidatePath
138
+ - [x] OwnerToAddress
139
+ - [x] OwnerToPubKey
140
+ - [x] TagsEncode
141
+ - [x] TagsDecode
142
+ - [x] PrepareChunks
143
+ - [x] GetChunk
144
+ - [x] SignTransaction
145
+ - [x] GetSignatureData
146
+ - [x] VerifyTransaction
147
+
125
148
#### RSA Threshold Cryptography
126
149
127
- - [x] CreateKeyPair
150
+ - [x] CreateTcKeyPair
128
151
- [x] ThresholdSign
129
152
- [x] AssembleSigShares
130
153
- [x] VerifySigShare
131
154
132
155
Create RSA Threshold Cryptography:
156
+
133
157
``` golang
134
- bitSize := 1024 // If the values are 2048 and 4096, then the generation functions below will perform minute-level times, and we need 4096 bits as the maximum safety level for production environments.
158
+ bitSize := 512 // If the values are 2048 and 4096, then the generation functions below will perform minute-level times, and we need 4096 bits as the maximum safety level for production environments.
135
159
l := 5
136
160
k := 3
137
- keyShares , keyMeta , err := CreateKeyPair (bitSize, k, l)
161
+ keyShares , keyMeta , err := goar. CreateTcKeyPair (bitSize, k, l)
138
162
```
163
+
139
164
New sign instance:
165
+
140
166
``` golang
141
167
exampleData := []byte (" aaabbbcccddd112233" ) // need sign data
142
- ts , err := NewTcSign (keyMeta, exampleData)
168
+ ts , err := goar. NewTcSign (keyMeta, exampleData)
143
169
144
170
// signer threshold sign
145
171
signer01 := keyShares[0 ]
@@ -156,7 +182,6 @@ signature, err := ts.AssembleSigShares(signedShares)
156
182
err := ts.VerifySigShare (signer01)
157
183
```
158
184
159
-
160
185
### Development
161
186
162
187
#### Test
@@ -177,7 +202,7 @@ Simple example:
177
202
178
203
``` golang
179
204
arNode := " https://arweave.net"
180
- w , err := NewFromPath (" ../example/testKey.json" , arNode) // your wallet private key
205
+ w , err := goar. NewWalletFromPath (" ../example/testKey.json" , arNode) // your wallet private key
181
206
anchor , err := w.Client .GetTransactionAnchor ()
182
207
if err != nil {
183
208
return
@@ -196,18 +221,18 @@ Simple example:
196
221
Format : 2 ,
197
222
Target : " " ,
198
223
Quantity : " 0" ,
199
- Tags : types .TagsEncode (tags),
200
- Data : data,
224
+ Tags : utils .TagsEncode (tags),
225
+ Data : utils. Base64Encode ( data) ,
201
226
DataSize : fmt.Sprintf (" %d " , len (data)),
202
227
Reward : fmt.Sprintf (" %d " , reward*(100 +speedFactor)/100 ),
203
228
}
204
- if err = tx .SignTransaction (w.PubKey , w.PrvKey ); err != nil {
229
+ if err = utils .SignTransaction (tx, w.PubKey , w.PrvKey ); err != nil {
205
230
return
206
231
}
207
232
208
233
id = tx.ID
209
234
210
- uploader , err := uploader .CreateUploader (w.Client , tx, nil )
235
+ uploader , err := goar .CreateUploader (w.Client , tx, nil )
211
236
if err != nil {
212
237
return
213
238
}
@@ -218,10 +243,12 @@ Simple example:
218
243
}
219
244
}
220
245
```
246
+
221
247
##### Breakpoint continuingly
248
+
222
249
You can resume an upload from a saved uploader object, that you have persisted in storage some using json.marshal(uploader) at any stage of the upload.To resume, parse it back into an object and pass it to getUploader() along with the transactions data:
223
- ```
224
250
251
+ ``` golang
225
252
uploaderBuf , err := ioutil.ReadFile (" ./jsonUploaderFile.json" )
226
253
lastUploader := &txType.TransactionUploader {}
227
254
err = json.Unmarshal (uploaderBuf, lastUploader)
@@ -235,17 +262,19 @@ You can resume an upload from a saved uploader object, that you have persisted i
235
262
assert.NoError (t, err)
236
263
}
237
264
```
265
+
238
266
When resuming the upload, you must provide the same data as the original upload. When you serialize the uploader object with json.marshal() to save it somewhere, it will not include the data.
267
+
239
268
##### Breakpoint retransmission
269
+
240
270
You can also resume an upload from just the transaction ID and data, once it has been mined into a block. This can be useful if you didn't save the uploader somewhere but the upload got interrupted. This will re-upload all of the data from the beginning, since we don't know which parts have been uploaded:
241
271
242
272
``` golang
243
-
244
273
bigData , err := ioutil.ReadFile (filePath)
245
274
txId := " myTxId"
246
275
247
276
// get uploader by txId and post big data by chunks
248
- uploader , err := txType .CreateUploader (wallet.Client , txId, bigData)
277
+ uploader , err := goar .CreateUploader (wallet.Client , txId, bigData)
249
278
assert.NoError (t, err)
250
279
for !uploader.IsComplete () {
251
280
err := uploader.UploadChunk ()
0 commit comments