-
Notifications
You must be signed in to change notification settings - Fork 51
Expand file tree
/
Copy pathutils.go
More file actions
627 lines (531 loc) · 20.2 KB
/
Copy pathutils.go
File metadata and controls
627 lines (531 loc) · 20.2 KB
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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
package contract
import (
"context"
"crypto/ecdsa"
"encoding/hex"
"fmt"
mbig "math/big"
"strings"
"time"
"unicode"
"unicode/utf8"
"github.com/ethereum/go-ethereum"
"github.com/ethereum/go-ethereum/common"
etypes "github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/crypto"
logging "github.com/ipfs/go-log/v2"
"github.com/jellydator/ttlcache/v2"
"golang.org/x/mod/semver"
"golang.org/x/xerrors"
"github.com/filecoin-project/go-address"
"github.com/filecoin-project/go-state-types/big"
"github.com/filecoin-project/go-state-types/builtin"
"github.com/filecoin-project/curio/harmony/harmonydb"
"github.com/filecoin-project/curio/lib/ethchain"
"github.com/filecoin-project/lotus/chain/types"
"github.com/filecoin-project/lotus/chain/types/ethtypes"
)
var log = logging.Logger("pdp")
// Standard capability keys for PDP product type (must match ServiceProviderRegistry.sol REQUIRED_PDP_KEYS Bloom filter)
const (
CapServiceURL = "serviceURL"
CapMinPieceSize = "minPieceSizeInBytes"
CapMaxPieceSize = "maxPieceSizeInBytes"
CapStoragePrice = "storagePricePerTibPerDay"
CapMinProvingPeriod = "minProvingPeriodInEpochs"
CapLocation = "location"
CapPaymentToken = "paymentTokenAddress"
// Optional PDP keys, including advertised storage capacity, are documented in ServiceProviderRegistry.sol:
// https://github.com/FilOzone/filecoin-services/blob/main/service_contracts/src/ServiceProviderRegistry.sol#L22
CapIpniPiece = "ipniPiece"
CapIpniIpfs = "ipniIpfs"
CapIpniPeerID = "ipniPeerId"
CapCapacityTiB = "capacityTiB"
// CapIpniPeerIDDeprecated is the old key for the IPNI peer ID. It was incorrectly cased
// and does not match the suggested key in the ServiceProviderRegistry contract. New
// registrations and updates write both keys for compatibility. This key will be removed
// in a future release.
CapIpniPeerIDDeprecated = "IPNIPeerID"
)
const pdpVerifierProcessPieceDeletionsAfterVersion = "v3.4.0"
func SemverVersion(version string) string {
if strings.HasPrefix(version, "v") {
return version
}
return "v" + version
}
func SupportsPieceDeletionProcessing(ctx context.Context, verifier *PDPVerifier) (bool, error) {
version, err := verifier.VERSION(EthCallOpts(ctx))
if err != nil {
return false, xerrors.Errorf("failed to get PDPVerifier version: %w", err)
}
return semver.Compare(SemverVersion(version), pdpVerifierProcessPieceDeletionsAfterVersion) > 0, nil
}
// PDPOfferingData converts a PDPOffering-like struct to capability key-value pairs
type PDPOfferingData struct {
ServiceURL string
MinPieceSizeInBytes *mbig.Int
MaxPieceSizeInBytes *mbig.Int
IpniPiece bool
IpniIpfs bool
IpniPeerID []byte
StoragePricePerTibPerDay *mbig.Int
MinProvingPeriodInEpochs *mbig.Int
Location string
PaymentTokenAddress common.Address
CapacityTiB *mbig.Int
}
func encodeBigIntCapability(i *mbig.Int) []byte {
if i == nil {
return nil
}
if i.Sign() == 0 {
return []byte{0x00}
}
return i.Bytes()
}
func OfferingToCapabilities(offering PDPOfferingData, additionalCaps map[string]string) ([]string, [][]byte, error) {
// Required PDP keys per REQUIRED_PDP_KEYS Bloom filter in ServiceProviderRegistry.sol
keys := []string{
CapServiceURL,
CapMinPieceSize,
CapMaxPieceSize,
CapStoragePrice,
CapMinProvingPeriod,
CapLocation,
CapPaymentToken,
}
values := [][]byte{
[]byte(offering.ServiceURL),
encodeBigIntCapability(offering.MinPieceSizeInBytes),
encodeBigIntCapability(offering.MaxPieceSizeInBytes),
encodeBigIntCapability(offering.StoragePricePerTibPerDay),
encodeBigIntCapability(offering.MinProvingPeriodInEpochs),
[]byte(offering.Location),
offering.PaymentTokenAddress.Bytes(),
}
// Add optional PDP keys if enabled
if offering.IpniPiece {
keys = append(keys, CapIpniPiece)
values = append(values, encodeBool(true))
}
if offering.IpniIpfs {
keys = append(keys, CapIpniIpfs)
values = append(values, encodeBool(true))
}
if offering.IpniIpfs || offering.IpniPiece {
if len(offering.IpniPeerID) == 0 {
return nil, nil, xerrors.Errorf("IpniPeerID is required if either IpniIpfs or IpniPiece is true")
}
// Write the correct key
keys = append(keys, CapIpniPeerID)
values = append(values, []byte(offering.IpniPeerID))
// Also write the deprecated key for compatibility with older SDK versions
keys = append(keys, CapIpniPeerIDDeprecated)
values = append(values, []byte(offering.IpniPeerID))
}
if offering.CapacityTiB != nil {
keys = append(keys, CapCapacityTiB)
values = append(values, encodeBigIntCapability(offering.CapacityTiB))
}
// Add custom capabilities
for k, v := range additionalCaps {
keys = append(keys, k)
// try hexadecimal
if len(v)%2 == 0 && len(v) > 3 && strings.HasPrefix(v, "0x") {
if decoded, err := hex.DecodeString(v[2:]); err == nil {
values = append(values, decoded)
continue
}
}
values = append(values, []byte(v))
}
return keys, values, nil
}
func encodeBool(b bool) []byte {
if b {
return []byte{0x01}
}
return []byte{0x00}
}
// viewAddressCache caches resolved view contract addresses keyed by service
// contract address. The view address is set at contract deploy time, but is
// changeable by contract owner.
var viewAddressCache *ttlcache.Cache
// viewAddressCacheTimeout is the duration for which resolved view addresses are
// cached. Set to 1 hour to balance between reducing RPC calls and allowing
// updates to be picked up without restarting the service.
const viewAddressCacheTimeout = time.Hour
func init() {
viewAddressCache = ttlcache.NewCache()
if err := viewAddressCache.SetTTL(viewAddressCacheTimeout); err != nil {
panic("failed to set view address cache TTL: " + err.Error())
}
viewAddressCache.SkipTTLExtensionOnHit(true)
}
// ResolveViewAddress resolves the view contract address for a service contract
// that implements viewContractAddress(). Service contracts (like FWSS) use
// separate view contracts for read-only operations that are not available on
// the service proxy itself.
//
// Results are cached for 1 hour to avoid repeated eth_call RPCs. The view
// address can be changed by the contract owner via setViewContract() (in FWSS
// at least) but this is expected to be infrequent (deployment or maintenance
// operations).
// A stale cache is safe: view contracts are intended to be read-only lenses
// over the same underlying storage, so an old view address still returns valid
// data. At worst, staleness delays visibility of newly added view functions,
// which would also require a Curio code update to consume.
func ResolveViewAddress(ctx context.Context, serviceAddr common.Address, ethClient ethchain.EthClient) (common.Address, error) {
key := strings.ToLower(serviceAddr.Hex())
if cached, err := viewAddressCache.Get(key); err == nil {
return cached.(common.Address), nil
}
svc, err := NewContractWithView(serviceAddr, ethClient)
if err != nil {
return common.Address{}, xerrors.Errorf("failed to bind to service at %s: %w", serviceAddr, err)
}
viewAddr, err := svc.ViewContractAddress(EthCallOpts(ctx))
if err != nil {
return common.Address{}, xerrors.Errorf("failed to get view contract address: %w", err)
}
if viewAddr == (common.Address{}) {
return common.Address{}, xerrors.Errorf("view contract address is zero")
}
if err := viewAddressCache.Set(key, viewAddr); err != nil {
log.Warnw("Failed to cache view address", "serviceAddr", serviceAddr, "error", err)
}
return viewAddr, nil
}
// GetProvingScheduleFromListener checks if a listener has a view contract and returns
// an IPDPProvingSchedule instance bound to the appropriate address.
// It uses the view contract address if available, otherwise uses the listener address directly.
func GetProvingScheduleFromListener(ctx context.Context, listenerAddr common.Address, ethClient ethchain.EthClient) (*IPDPProvingSchedule, error) {
provingScheduleAddr := listenerAddr
if viewAddr, err := ResolveViewAddress(ctx, listenerAddr, ethClient); err == nil {
provingScheduleAddr = viewAddr
} // else we'll assume that the listener contract itself implements IPDPProvingSchedule
provingSchedule, err := NewIPDPProvingSchedule(provingScheduleAddr, ethClient)
if err != nil {
return nil, xerrors.Errorf("failed to create proving schedule binding: %w", err)
}
return provingSchedule, nil
}
func GetDataSetMetadataAtKey(ctx context.Context, listenerAddr common.Address, ethClient ethchain.EthClient, dataSetId *mbig.Int, key string) (bool, string, error) {
metadataAddr := listenerAddr
if viewAddr, err := ResolveViewAddress(ctx, listenerAddr, ethClient); err == nil {
metadataAddr = viewAddr
} // else we'll still try from the listener contract just in case
// Create a metadata service viewer.
mDataService, err := NewListenerServiceWithMetaData(metadataAddr, ethClient)
if err != nil {
log.Debugw("Failed to create a meta data service from listener, returning metadata not found", "error", err)
return false, "", nil
}
out, err := mDataService.GetDataSetMetadata(EthCallOpts(ctx), dataSetId, key)
if err != nil {
return false, "", err
}
return out.Exists, out.Value, nil
}
func FSRegister(ctx context.Context, db *harmonydb.DB, ethClient ethchain.EthClient, name, description string, pdpOffering PDPOfferingData, capabilities map[string]string) error {
if len(name) > 128 {
return xerrors.Errorf("name is too long, max 128 characters allowed")
}
if name == "" {
return xerrors.Errorf("name is required")
}
if len(description) > 128 {
return xerrors.Errorf("description is too long, max 128 characters allowed")
}
// Convert PDPOffering to capability keys/values
keys, values, err := OfferingToCapabilities(pdpOffering, capabilities)
if err != nil {
return xerrors.Errorf("failed to convert offering to capabilities: %w", err)
}
// Validate capabilities
for _, k := range keys {
if len(k) > 32 {
return xerrors.Errorf("capabilities key %s is too long, max 32 characters allowed", k)
}
}
for _, v := range values {
if len(v) > 128 {
return xerrors.Errorf("capabilities value is too long, max 128 bytes allowed")
}
}
if len(keys) > 32 {
return xerrors.Errorf("too many capabilities, max 32 allowed")
}
sender, fSender, privateKey, err := getSender(ctx, db)
if err != nil {
return xerrors.Errorf("failed to get sender: %w", err)
}
amount, err := types.ParseFIL("5 FIL")
if err != nil {
return fmt.Errorf("failed to parse 5 FIL: %w", err)
}
balance, err := ethClient.BalanceAt(ctx, sender, nil)
if err != nil {
return xerrors.Errorf("failed to get wallet balance: %w", err)
}
if balance.Cmp(amount.Int) < 0 {
return xerrors.Errorf("wallet balance is too low")
}
walletEvm, err := ethtypes.EthAddressFromFilecoinAddress(fSender)
if err != nil {
return xerrors.Errorf("failed to convert wallet address to Eth address: %w", err)
}
contractAddr, err := ServiceRegistryAddress()
if err != nil {
return xerrors.Errorf("failed to get service registry address: %w", err)
}
srAbi, err := ServiceProviderRegistryMetaData.GetAbi()
if err != nil {
return xerrors.Errorf("failed to get service registry ABI: %w", err)
}
// Prepare EVM calldata - registerProvider(address payee, string name, string description, ProductType productType, string[] capabilityKeys, bytes[] capabilityValues)
calldata, err := srAbi.Pack("registerProvider", common.Address(walletEvm), name, description, uint8(0), keys, values)
if err != nil {
return fmt.Errorf("failed to serialize parameters for registerProvider: %w", err)
}
signedTx, err := createSignedTransaction(ctx, ethClient, privateKey, sender, contractAddr, amount.Int, calldata)
if err != nil {
return xerrors.Errorf("creating signed transaction: %w", err)
}
err = ethClient.SendTransaction(ctx, signedTx)
if err != nil {
return xerrors.Errorf("sending transaction: %w", err)
}
log.Infof("Sent Register Service Provider transaction %s at %s", signedTx.Hash().String(), time.Now().Format(time.RFC3339Nano))
return nil
}
func getSender(ctx context.Context, db *harmonydb.DB) (common.Address, address.Address, *ecdsa.PrivateKey, error) {
// Fetch the private key from the database
var privateKeyData []byte
err := db.QueryRow(ctx,
`SELECT private_key FROM eth_keys WHERE role = 'pdp'`).Scan(&privateKeyData)
if err != nil {
return common.Address{}, address.Address{}, nil, xerrors.Errorf("fetching pdp private key from db: %w", err)
}
privateKey, err := crypto.ToECDSA(privateKeyData)
if err != nil {
return common.Address{}, address.Address{}, nil, xerrors.Errorf("converting private key: %w", err)
}
sender := crypto.PubkeyToAddress(privateKey.PublicKey)
fSender, err := address.NewDelegatedAddress(builtin.EthereumAddressManagerActorID, sender.Bytes())
if err != nil {
return common.Address{}, address.Address{}, nil, xerrors.Errorf("failed to create delegated address: %w", err)
}
return sender, fSender, privateKey, nil
}
func createSignedTransaction(ctx context.Context, ethClient ethchain.EthClient, privateKey *ecdsa.PrivateKey, from, to common.Address, amount *mbig.Int, data []byte) (*etypes.Transaction, error) {
msg := ethereum.CallMsg{
From: from,
To: &to,
Value: amount,
Data: data,
}
gasLimit, err := ethClient.EstimateGas(ctx, msg)
if err != nil {
return nil, fmt.Errorf("failed to estimate gas: %w", err)
}
if gasLimit == 0 {
return nil, fmt.Errorf("estimated gas limit is zero")
}
// Fetch current base fee
header, err := ethClient.HeaderByNumber(ctx, nil)
if err != nil {
return nil, fmt.Errorf("failed to get latest block header: %w", err)
}
baseFee := header.BaseFee
if baseFee == nil {
return nil, fmt.Errorf("base fee not available; network might not support EIP-1559")
}
// Set GasTipCap (maxPriorityFeePerGas)
gasTipCap, err := ethClient.SuggestGasTipCap(ctx)
if err != nil {
return nil, xerrors.Errorf("estimating gas premium: %w", err)
}
// Calculate GasFeeCap (maxFeePerGas)
gasFeeCap := big.NewInt(0).Add(baseFee, gasTipCap)
chainID, err := ethClient.NetworkID(ctx)
if err != nil {
return nil, xerrors.Errorf("getting network ID: %w", err)
}
pendingNonce, err := ethClient.PendingNonceAt(ctx, from)
if err != nil {
return nil, xerrors.Errorf("getting pending nonce: %w", err)
}
// Create a new transaction with estimated gas limit and fee caps
tx := etypes.NewTx(&etypes.DynamicFeeTx{
ChainID: chainID,
Nonce: pendingNonce,
GasFeeCap: gasFeeCap,
GasTipCap: gasTipCap,
Gas: gasLimit,
To: &to,
Value: amount,
Data: data,
})
// Sign the transaction
signer := etypes.LatestSignerForChainID(chainID)
signedTx, err := etypes.SignTx(tx, signer, privateKey)
if err != nil {
return nil, xerrors.Errorf("signing transaction: %w", err)
}
return signedTx, nil
}
func FSUpdateProvider(ctx context.Context, name, description string, db *harmonydb.DB, ethClient ethchain.EthClient) (string, error) {
if len(name) > 128 {
return "", xerrors.Errorf("name is too long, max 128 characters allowed")
}
if name == "" {
return "", xerrors.Errorf("name is required")
}
if len(description) > 128 {
return "", xerrors.Errorf("description is too long, max 128 characters allowed")
}
sender, _, privateKey, err := getSender(ctx, db)
if err != nil {
return "", xerrors.Errorf("failed to get sender: %w", err)
}
contractAddr, err := ServiceRegistryAddress()
if err != nil {
return "", xerrors.Errorf("failed to get service registry address: %w", err)
}
srAbi, err := ServiceProviderRegistryMetaData.GetAbi()
if err != nil {
return "", xerrors.Errorf("failed to get service registry ABI: %w", err)
}
calldata, err := srAbi.Pack("updateProviderInfo", name, description)
if err != nil {
return "", xerrors.Errorf("failed to serialize parameters for updateProviderInfo: %w", err)
}
signedTx, err := createSignedTransaction(ctx, ethClient, privateKey, sender, contractAddr, mbig.NewInt(0), calldata)
if err != nil {
return "", xerrors.Errorf("creating signed transaction: %w", err)
}
err = ethClient.SendTransaction(ctx, signedTx)
if err != nil {
return "", xerrors.Errorf("sending transaction: %w", err)
}
return signedTx.Hash().String(), nil
}
func FSUpdatePDPService(ctx context.Context, db *harmonydb.DB, ethClient ethchain.EthClient, pdpOffering PDPOfferingData, capabilities map[string]string) (string, error) {
// Convert PDPOffering to capability keys/values
keys, values, err := OfferingToCapabilities(pdpOffering, capabilities)
if err != nil {
return "", xerrors.Errorf("failed to convert offering to capabilities: %w", err)
}
// Validate capabilities
for _, k := range keys {
if len(k) > 32 {
return "", xerrors.Errorf("capabilities key %s is too long, max 32 characters allowed", k)
}
}
for _, v := range values {
if len(v) > 128 {
return "", xerrors.Errorf("capabilities value is too long, max 128 bytes allowed")
}
}
if len(keys) > 32 {
return "", xerrors.Errorf("too many capabilities, max 32 allowed")
}
sender, _, privateKey, err := getSender(ctx, db)
if err != nil {
return "", xerrors.Errorf("failed to get sender: %w", err)
}
contractAddr, err := ServiceRegistryAddress()
if err != nil {
return "", xerrors.Errorf("failed to get service registry address: %w", err)
}
srAbi, err := ServiceProviderRegistryMetaData.GetAbi()
if err != nil {
return "", xerrors.Errorf("failed to get service registry ABI: %w", err)
}
// Call updateProduct instead of updatePDPServiceWithCapabilities
calldata, err := srAbi.Pack("updateProduct", uint8(0), keys, values)
if err != nil {
return "", xerrors.Errorf("failed to serialize parameters for updateProduct: %w", err)
}
signedTx, err := createSignedTransaction(ctx, ethClient, privateKey, sender, contractAddr, mbig.NewInt(0), calldata)
if err != nil {
return "", xerrors.Errorf("creating signed transaction: %w", err)
}
err = ethClient.SendTransaction(ctx, signedTx)
if err != nil {
return "", xerrors.Errorf("sending transaction: %w", err)
}
return signedTx.Hash().String(), nil
}
func FSDeregisterProvider(ctx context.Context, db *harmonydb.DB, ethClient ethchain.EthClient) (string, error) {
sender, _, privateKey, err := getSender(ctx, db)
if err != nil {
return "", xerrors.Errorf("failed to get sender: %w", err)
}
contractAddr, err := ServiceRegistryAddress()
if err != nil {
return "", xerrors.Errorf("failed to get service registry address: %w", err)
}
srAbi, err := ServiceProviderRegistryMetaData.GetAbi()
if err != nil {
return "", xerrors.Errorf("failed to get service registry ABI: %w", err)
}
calldata, err := srAbi.Pack("removeProvider")
if err != nil {
return "", xerrors.Errorf("failed to serialize parameters for removeProvider: %w", err)
}
signedTx, err := createSignedTransaction(ctx, ethClient, privateKey, sender, contractAddr, mbig.NewInt(0), calldata)
if err != nil {
return "", xerrors.Errorf("creating signed transaction: %w", err)
}
err = ethClient.SendTransaction(ctx, signedTx)
if err != nil {
return "", xerrors.Errorf("sending transaction: %w", err)
}
return signedTx.Hash().String(), nil
}
func DecodeAddressCapability(input []byte) common.Address {
// If input is longer than 32 bytes → return zero
if len(input) > 32 {
return common.Address{}
}
// 32-byte big-endian buffer
var buf [32]byte
if len(input) == 32 {
// Exact fit
copy(buf[:], input)
} else {
// Left pad if shorter
copy(buf[32-len(input):], input)
}
// Lowest 20 bytes are the address
return common.BytesToAddress(buf[12:])
}
// ShouldHexEncodeCapability reports whether a capability value needs hex-encoding
// to safely round-trip through JSON and browser input fields. Returns true for
// invalid UTF-8 or control characters; false for valid text (including CJK/emoji).
// See https://pkg.go.dev/unicode/utf8#DecodeRune for RuneError semantics.
func ShouldHexEncodeCapability(b []byte) bool {
for i := 0; i < len(b); {
r, size := utf8.DecodeRune(b[i:])
if r == utf8.RuneError && size == 1 { // invalid UTF-8
return true
}
if unicode.IsControl(r) {
return true
}
i += size
}
return false
}
// EncodeCapabilityForDisplay returns a display string for a capability value.
// Binary data gets "0x" hex prefix; valid UTF-8 text passes through as-is.
// Pairs with hex-decoding in OfferingToCapabilities.
func EncodeCapabilityForDisplay(b []byte) string {
if ShouldHexEncodeCapability(b) {
return "0x" + hex.EncodeToString(b)
}
return string(b)
}