2023-11-08 13:36:55 +00:00
|
|
|
package morph
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
|
|
|
|
"github.com/nspcc-dev/neo-go/pkg/encoding/address"
|
|
|
|
"github.com/nspcc-dev/neo-go/pkg/smartcontract"
|
|
|
|
"github.com/nspcc-dev/neo-go/pkg/util"
|
|
|
|
"github.com/spf13/viper"
|
|
|
|
)
|
|
|
|
|
|
|
|
// neo-go doesn't support []util.Uint160 type:
|
|
|
|
// https://github.com/nspcc-dev/neo-go/blob/v0.103.0/pkg/smartcontract/parameter.go#L262
|
|
|
|
// Thus, return []smartcontract.Parameter.
|
2023-11-13 09:41:40 +00:00
|
|
|
func getFrostfsIDAuthorizedKeys(v *viper.Viper, defaultOwner util.Uint160) ([]smartcontract.Parameter, error) {
|
2023-11-08 13:36:55 +00:00
|
|
|
var res []smartcontract.Parameter
|
2023-11-13 09:41:40 +00:00
|
|
|
res = append(res, smartcontract.Parameter{Type: smartcontract.Hash160Type, Value: defaultOwner})
|
2023-11-08 13:36:55 +00:00
|
|
|
|
|
|
|
ks := v.GetStringSlice(frostfsIDAuthorizedKeysConfigKey)
|
|
|
|
for i := range ks {
|
|
|
|
h, err := address.StringToUint160(ks[i])
|
|
|
|
if err == nil {
|
|
|
|
res = append(res, smartcontract.Parameter{Type: smartcontract.Hash160Type, Value: h})
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
h, err = util.Uint160DecodeStringLE(ks[i])
|
|
|
|
if err == nil {
|
|
|
|
res = append(res, smartcontract.Parameter{Type: smartcontract.Hash160Type, Value: h})
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
pk, err := keys.NewPublicKeyFromString(ks[i])
|
|
|
|
if err == nil {
|
|
|
|
res = append(res, smartcontract.Parameter{Type: smartcontract.Hash160Type, Value: pk.GetScriptHash()})
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
return nil, fmt.Errorf("frostfsid: #%d item in authorized_keys is invalid: '%s'", i, ks[i])
|
|
|
|
}
|
|
|
|
return res, nil
|
|
|
|
}
|