Skip to content

Commit

Permalink
remove migration and fix typos (#197)
Browse files Browse the repository at this point in the history
  • Loading branch information
decentralgabe authored Apr 22, 2024
1 parent 83b3add commit 26ea0ad
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 83 deletions.
68 changes: 1 addition & 67 deletions impl/pkg/storage/db/bolt/bolt.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import (

const (
dhtNamespace = "dht"
oldDHTNamespace = "pkarr"
failedNamespace = "failed"
)

Expand All @@ -39,72 +38,7 @@ func NewBolt(path string) (*Bolt, error) {
if err != nil {
return nil, err
}

b := Bolt{db: db}
b.migrate(context.Background())
return &b, nil
}

func (b *Bolt) migrate(ctx context.Context) {
_, span := telemetry.GetTracer().Start(ctx, "bolt.migrate")
defer span.End()

// Delete new namespace
err := b.db.Update(func(tx *bolt.Tx) error {
return tx.DeleteBucket([]byte(dhtNamespace))
})
if err != nil {
logrus.WithContext(ctx).WithError(err).Error("error deleting new namespace")
}

// Migrate old namespace to new namespace
var nextPageToken []byte
var migratedCount int
var failedCount int
for {
pageSize := 1000
oldRecords, err := b.readSeveral(ctx, oldDHTNamespace, nextPageToken, pageSize)
if err != nil {
logrus.WithContext(ctx).WithError(err).Error("error reading old namespace")
return
}

for _, oldRecord := range oldRecords {
key := string(oldRecord.key)
var encodedRecord base64BEP44Record
if err = json.Unmarshal(oldRecord.value, &encodedRecord); err != nil {
logrus.WithContext(ctx).WithError(err).Errorf("error decoding[%s]", key)
continue
}
record, err := encodedRecord.Decode()
if err != nil {
logrus.WithContext(ctx).WithError(err).Errorf("error decoding[%s]", key)
continue
}
if err = b.write(ctx, dhtNamespace, record.ID(), oldRecord.value); err != nil {
logrus.WithContext(ctx).WithError(err).Errorf("error writing[%s] to new namespace", key)
failedCount++
} else {
migratedCount++
}
}

if len(oldRecords) == pageSize {
nextPageToken = oldRecords[len(oldRecords)-1].key
} else {
break
}
}

logrus.WithContext(ctx).Infof("migrated %d records, failed %d records", migratedCount, failedCount)
if failedCount == 0 {
err = b.db.Update(func(tx *bolt.Tx) error {
return tx.DeleteBucket([]byte(oldDHTNamespace))
})
if err != nil {
logrus.WithContext(ctx).WithError(err).Error("error deleting old namespace")
}
}
return &Bolt{db: db}, nil
}

// WriteRecord writes the given record to the storage
Expand Down
34 changes: 18 additions & 16 deletions spec/spec.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ The DID DHT Method Specification 1.0

**Draft Created:** October 20, 2023

**Latest Update:** April 3, 2024
**Latest Update:** April 22, 2024

**Editors:**
~ [Gabe Cohen](https://github.com/decentralgabe)
Expand Down Expand Up @@ -74,13 +74,15 @@ specification and shall be registered with the [[spec:DID-Spec-Registries]].

## Conformance

The keywords MAY, MUST, MUST NOT, RECOMMENDED, SHOULD, and SHOULD NOT in this document are to be interpreted as described in [BCP 14](https://www.rfc-editor.org/info/bcp14) [[spec:RFC2119]] [[spec:RFC8174]] when, and only when, they appear in all capitals, as shown here.
The keywords MAY, MUST, MUST NOT, RECOMMENDED, SHOULD, and SHOULD NOT in this document are to be interpreted as
described in [BCP 14](https://www.rfc-editor.org/info/bcp14) [[spec:RFC2119]] [[spec:RFC8174]] when, and only when,
they appear in all capitals, as shown here.

## Terminology

[[def:Decentralized Identifier, Decentralized Identifier, DID, DIDs, DID Document, DID Documents]]
~ A [W3C specification](https://www.w3.org/TR/did-core/) describing an _identifier that enables verifiable,
decentralized digital identity_. A DID identifier is associated with a JSON document containing cryptograhpic keys,
decentralized digital identity_. A DID identifier is associated with a JSON document containing cryptographic keys,
services, and other properties outlined in the specification.

[[def:DID Suffix, Suffix]]
Expand Down Expand Up @@ -167,19 +169,19 @@ to the initial publisher. Consequently, DHT records, including DID DHT Documents
implies that trust in a specific [[ref:Mainline]] or [[ref:Gateway]] server for providing unaltered messages is unnecessary. Instead,
all clients can, and should, verify messages themselves. This approach significantly mitigates risks associated with other DID methods,
where a compromised server or [DID resolver](https://www.w3.org/TR/did-core/#choosing-did-resolvers) might tamper with a [[ref:DID Document]]
which would be undecetable by a client.
which would be undetectable by a client.

Currently, [[ref:Mainline]] exclusively supports the [[ref:Ed25519]] key type. In turn, [[ref:Ed25519]] is required by DID DHT and is
used to uniquely identify DID DHT Documents. DID DHT identifiers are formed by concatenating the `did:dht:` prefix with a [[ref:z-base-32]]
encoded Identity Key, which acts as its [[ref:suffix]]. Identity Keys ****MUST**** have the identifier `0` as both its Verification Method
`id` and JWK `kid` [[spec:RFC7517]]. Identity Keys ****MUST**** have the [Verification Relationships](#verification-relationships)
_Authentication_, _Assertion_, _Capabilitiy Invocation_, and _Capability Delegation_.
_Authentication_, _Assertion_, _Capability Invocation_, and _Capability Delegation_.

While the system requires at least one [[ref:Ed25519]], a DID DHT Document can include any number of additional keys. Additional key
types ****MUST**** be registered in the [Key Type Index](registry/index.html##key-type-index).

As a unique consequence of the requirement of the Identity Key, DID DHT Documents are able to be partially-resolved without contacting
[[ref:Maineline]] or [[ref:Gateway]] servers, though it is ****RECOMMENDED**** that deterministic resolution is only used as a fallback mechanism.
[[ref:Mainline]] or [[ref:Gateway]] servers, though it is ****RECOMMENDED**** that deterministic resolution is only used as a fallback mechanism.
Similarly, the requirement of an Identity Key enables [interoperability with other DID methods](#interoperability-with-other-did-methods).

### DIDs as DNS Records
Expand Down Expand Up @@ -214,7 +216,7 @@ each `key` or `service` as attributes.
- The DNS packet ****MUST**** set the _Authoritative Answer_ flag since this is always an _Authoritative_ packet.

- `TXT` records ****MAY**** exceed 255 characters as per [[spec:RFC1035]]. Records exceeding 255 characters are
represented as multiple strings, which upon DID Document reconstructin, can be concatenated to a single value.
represented as multiple strings, which upon DID Document reconstruction, can be concatenated to a single value.

#### Root Record

Expand Down Expand Up @@ -279,7 +281,7 @@ A [DID controller](https://www.w3.org/TR/did-core/#did-controller) ****MAY**** b

- The [Controller](https://www.w3.org/TR/did-core/#did-controller) record's **type** is `TXT`, indicating a Text record.

- The [Controller](https://www.w3.org/TR/did-core/#did-controller) record's **data** is represented as a comma-separatedlist of controller DID identifiers.
- The [Controller](https://www.w3.org/TR/did-core/#did-controller) record's **data** is represented as a comma-separated list of controller DID identifiers.

To ensure that the DID controller is authorized to make changes to the DID Document, the controller for the [[ref:Identity Key]] Verification Method ****MUST**** be contained within the controller property.

Expand Down Expand Up @@ -314,13 +316,13 @@ as a `_kN._did.` record where `N` is the zero-indexed positional index of a give

- Each [Verification Method](https://www.w3.org/TR/did-core/#verification-methods) record's **rdata** is represented by the form
`id=M;t=N;k=O;a=P` where `M` is the Verification Method's `id`, `N` is the index of the key's type from the
[key type index](registry/index.html#key-type-index), `N` is the unpadded base64URL [[spec:RFC4648]] representation of
[key type index](registry/index.html#key-type-index), `O` is the unpadded base64URL [[spec:RFC4648]] representation of
the public key, and `P` is the `JWK` `alg` identifier of the key.

- Verification Method `id`s ****MAY**** be omitted. If omitted, they can be computed according to the
rules specified in the section on [representing keys](#representing-keys) when reconstructing the DID Document.

- `alg` identifiers ****MAY**** be ommitted. If omimtted, they are assigned to the default value specified in the
- `alg` identifiers ****MAY**** be omitted. If omitted, they are assigned to the default value specified in the
[key type index](registry/index.html#key-type-index).

- The [[ref:Identity Key]] ****MUST**** always be at index `_k0` with `id` `0`.
Expand Down Expand Up @@ -950,21 +952,21 @@ access-token-based approach.

### DID Resolution

The process for resoloving a DID DHT Document via a [[ref:Gateway]] is outlined in the [read section above](#read).
The process for resolving a DID DHT Document via a [[ref:Gateway]] is outlined in the [read section above](#read).
However, we provide additional guidance for [DID Resolvers](https://www.w3.org/TR/did-core/#dfn-did-resolvers) supplying
[DID Document Metadata](https://www.w3.org/TR/did-core/#did-document-metadata) and
[DID Resolution Metadata](https://www.w3.org/TR/did-core/#did-resolution-metadata) as follows:

#### DID Document Metadata

* The metadata's [`versionId` property](https://www.w3.org/TR/did-core/#dfn-versionid) ****MUST**** be set to the
* The metadata [`versionId` property](https://www.w3.org/TR/did-core/#dfn-versionid) ****MUST**** be set to the
[[ref:DID Document]] packet's current [[ref:sequence number]].

* The metadata's [`created` property](https://www.w3.org/TR/did-core/#dfn-created) ****MUST**** be set to
* The metadata [`created` property](https://www.w3.org/TR/did-core/#dfn-created) ****MUST**** be set to
[XML Datetime](https://www.w3.org/TR/xmlschema11-2/#dateTime) representation of the earliest known sequence number
for the DID.

* The metadata's [`updated` property](https://www.w3.org/TR/did-core/#dfn-updated) ****MUST**** be set to the
* The metadata [`updated` property](https://www.w3.org/TR/did-core/#dfn-updated) ****MUST**** be set to the
[XML Datetime](https://www.w3.org/TR/xmlschema11-2/#dateTime) representation of the last known sequence number
for the DID.

Expand All @@ -973,10 +975,10 @@ for the DID.

#### DID Resolution Metadata

* The metadata's `types` property ****MUST**** be set to an array of strings representing type values if
* The metadata `types` property ****MUST**** be set to an array of strings representing type values if
[type data](#type-indexing) is present in the [[ref:DID Document]]'s packet.

* The metadata's `gateway` property ****MUST**** be set to a string representing the [[ref:Gateway]]'s URI
* The metadata `gateway` property ****MUST**** be set to a string representing the [[ref:Gateway]]'s URI
from which the DID was resolved. This is useful in cases where a [DID Resolvers](https://www.w3.org/TR/did-core/#dfn-did-resolvers)
performs resolution against an [Authoritative Gateway](#designating-authoritative-gateways).

Expand Down

0 comments on commit 26ea0ad

Please sign in to comment.