master
go 34 lines 743 Bytes
Raw
1 package ipns
2
3 import (
4 "context"
5
6 ft "github.com/ipfs/boxo/ipld/unixfs"
7 "github.com/ipfs/boxo/namesys"
8 "github.com/ipfs/boxo/path"
9 "github.com/ipfs/kubo/core"
10 ci "github.com/libp2p/go-libp2p/core/crypto"
11 )
12
13 // InitializeKeyspace sets the ipns record for the given key to
14 // point to an empty directory.
15 func InitializeKeyspace(n *core.IpfsNode, key ci.PrivKey) error {
16 ctx, cancel := context.WithCancel(n.Context())
17 defer cancel()
18
19 emptyDir := ft.EmptyDirNode()
20
21 err := n.Pinning.Pin(ctx, emptyDir, false, "")
22 if err != nil {
23 return err
24 }
25
26 err = n.Pinning.Flush(ctx)
27 if err != nil {
28 return err
29 }
30
31 pub := namesys.NewIPNSPublisher(n.Routing, n.Repo.Datastore())
32
33 return pub.Publish(ctx, key, path.FromCid(emptyDir.Cid()))
34 }