Skip to content

Commit

Permalink
nns: Use format of Neo address records specified in NEP-18 standard
Browse files Browse the repository at this point in the history
From now verified nodes' domain records are prefixed with `address=` in
order to comply the Neo specification.

Signed-off-by: Leonard Lyubich <[email protected]>
  • Loading branch information
cthulhu-rider committed Oct 10, 2023
1 parent 3d6c865 commit be4c57d
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 8 deletions.
17 changes: 13 additions & 4 deletions cmd/neofs-adm/internal/modules/morph/verified_domains.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ import (
"github.com/spf13/viper"
)

// as described in NEP-18 Specification https://github.com/neo-project/proposals/pull/133
const nnsNeoAddressTextRecordPrefix = "address="

func verifiedNodesDomainAccessList(cmd *cobra.Command, _ []string) error {
vpr := viper.GetViper()

Expand Down Expand Up @@ -51,7 +54,13 @@ func verifiedNodesDomainAccessList(cmd *cobra.Command, _ []string) error {
}

for i := range records {
cmd.Println(records[i])
neoAddr := strings.TrimPrefix(records[i], nnsNeoAddressTextRecordPrefix)
if len(neoAddr) == len(records[i]) {
cmd.Printf("%s (not a Neo address)\n", records[i])
continue
}

cmd.Println(neoAddr)
}

return nil
Expand Down Expand Up @@ -87,9 +96,9 @@ func verifiedNodesDomainSetAccessList(cmd *cobra.Command, _ []string) error {
if err != nil {
return fmt.Errorf("address #%d is invalid: %w", i, err)
}
}

additionalRecords = strNeoAddresses
additionalRecords = append(additionalRecords, nnsNeoAddressTextRecordPrefix+strNeoAddresses[i])
}
} else {
additionalRecords = make([]string, len(strPublicKeys))

Expand All @@ -105,7 +114,7 @@ func verifiedNodesDomainSetAccessList(cmd *cobra.Command, _ []string) error {
return fmt.Errorf("public key #%d is not a HEX-encoded public key: %w", i, err)
}

additionalRecords[i] = address.Uint160ToString(pubKey.GetScriptHash())
additionalRecords[i] = nnsNeoAddressTextRecordPrefix + address.Uint160ToString(pubKey.GetScriptHash())
}
}

Expand Down
2 changes: 1 addition & 1 deletion docs/verified-node-domains.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ the network map.
For each public key, a record is created - a structure with at least 3 fields:
1. `ByteString` with name of the corresponding domain
2. `Integer` that is `16` for TXT records (other record types are allowed but left unprocessed)
3. `ByteString` with Neo address of the storage node's public key
3. `ByteString` with `address=<Neo address>` value described in [NEP-18 Specification](https://github.com/neo-project/proposals/pull/133)

### Management

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ func (x *Validator) VerifyAndUpdate(info *netmap.NodeInfo) error {
emit.CheckSig(buf.BinWriter, bNodeKey)
nodeNeoAddress := address.Uint160ToString(hash.Hash160(buf.Bytes()))

err := x.nns.CheckDomainRecord(verifiedNodesDomain, nodeNeoAddress)
// record format is described in NEP-18 Specification https://github.com/neo-project/proposals/pull/133
err := x.nns.CheckDomainRecord(verifiedNodesDomain, "address="+nodeNeoAddress)
if err != nil {
if errors.Is(err, ErrMissingDomainRecord) {
return errAccessDenied
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ func (x *testNNS) CheckDomainRecord(domainName string, record string) error {
func TestValidator_VerifyAndUpdate(t *testing.T) {
const verifiedDomain = "nodes.some-org.neofs"
const hNodeKey = "02a70577a832b338772c8cd07e7eaf526cae8d9b025a51b41671de5a4363eafe07"
const nodeNeoAddress = "NZ1czz5gkEDamTg6Tiw6cxqp9Me1KLs8ae"
const anyOtherNeoAddress = "NfMvD6WmBiCr4erfEnFFLs7jdj4Y5CM7nN"
const nodeNeoAddress = "address=NZ1czz5gkEDamTg6Tiw6cxqp9Me1KLs8ae"
const anyOtherNeoAddress = "address=NfMvD6WmBiCr4erfEnFFLs7jdj4Y5CM7nN"

bNodeKey, err := hex.DecodeString(hNodeKey)
require.NoError(t, err)
Expand Down

0 comments on commit be4c57d

Please sign in to comment.