Skip to content

Commit

Permalink
feat: flip to v1+v2 by default
Browse files Browse the repository at this point in the history
  • Loading branch information
hacdias committed Jun 16, 2023
1 parent c5a71fa commit 5ebb39f
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 14 deletions.
10 changes: 8 additions & 2 deletions ipns/record.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,12 @@ func WithPublicKey(embedded bool) Option {
}

func processOptions(opts ...Option) *options {
options := &options{}
options := &options{
// TODO: produce V2-only records by default after IPIP-XXXX ships with Kubo
// and Helia for at least 6 months.
v1Compatibility: true,
}

for _, opt := range opts {
opt(options)
}
Expand All @@ -223,7 +228,8 @@ func processOptions(opts ...Option) *options {
// NewRecord creates a new IPNS [Record] and signs it with the given private key.
// By default, we embed the public key for key types whose peer IDs do not encode
// the public key, such as RSA and ECDSA key types. This can be changed with the
// option [WithPublicKey].
// option [WithPublicKey]. In addition, records are, by default created with V1
// compatibility.
func NewRecord(sk ic.PrivKey, value path.Path, seq uint64, eol time.Time, ttl time.Duration, opts ...Option) (*Record, error) {
options := processOptions(opts...)

Expand Down
22 changes: 11 additions & 11 deletions ipns/record_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,34 +88,34 @@ func TestNewRecord(t *testing.T) {
eol := time.Now().Add(time.Hour)
ttl := time.Minute * 10

t.Run("V2 only record by default", func(t *testing.T) {
t.Run("V1+V2 records by default", func(t *testing.T) {
t.Parallel()

rec := mustNewRecord(t, sk, testPath, seq, eol, ttl)
require.Empty(t, rec.pb.SignatureV1)
require.NotEmpty(t, rec.pb.SignatureV1)

_, err := rec.PubKey()
require.ErrorIs(t, err, ErrPublicKeyNotFound)

fieldsMatch(t, rec, testPath, seq, eol, ttl)
require.Empty(t, rec.pb.GetValue())
require.Empty(t, rec.pb.GetSequence())
require.Empty(t, rec.pb.GetValidity())
require.Empty(t, rec.pb.GetValidityType())
require.Empty(t, rec.pb.GetTtl())
fieldsMatchV1(t, rec, testPath, seq, eol, ttl)
})

t.Run("V1+V2 with option", func(t *testing.T) {
t.Run("V2 records with option", func(t *testing.T) {
t.Parallel()

rec := mustNewRecord(t, sk, testPath, seq, eol, ttl, WithV1Compatibility(true))
require.NotEmpty(t, rec.pb.SignatureV1)
rec := mustNewRecord(t, sk, testPath, seq, eol, ttl, WithV1Compatibility(false))
require.Empty(t, rec.pb.SignatureV1)

_, err := rec.PubKey()
require.ErrorIs(t, err, ErrPublicKeyNotFound)

fieldsMatch(t, rec, testPath, seq, eol, ttl)
fieldsMatchV1(t, rec, testPath, seq, eol, ttl)
require.Empty(t, rec.pb.GetValue())
require.Empty(t, rec.pb.GetSequence())
require.Empty(t, rec.pb.GetValidity())
require.Empty(t, rec.pb.GetValidityType())
require.Empty(t, rec.pb.GetTtl())
})

t.Run("Public key embedded by default for RSA and ECDSA keys", func(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion namesys/publisher.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ func (p *IpnsPublisher) updateRecord(ctx context.Context, k crypto.PrivKey, valu
opts := opts.ProcessPublishOptions(options)

// Create record
r, err := ipns.NewRecord(k, value, seqno, opts.EOL, opts.TTL, ipns.WithV1Compatibility(opts.CompatibleWithV1))
r, err := ipns.NewRecord(k, value, seqno, opts.EOL, opts.TTL)
if err != nil {
return nil, err
}
Expand Down

0 comments on commit 5ebb39f

Please sign in to comment.