Skip to content

Commit 856303f

Browse files
committed
Migrate to Cidv1 for ipns libp2p keys
See also ipfs-shipyard/net-ipfs-core#28
1 parent 152f7be commit 856303f

File tree

2 files changed

+14
-12
lines changed

2 files changed

+14
-12
lines changed

src/CoreApi/KeyApi.cs

+9-9
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class KeyApi : IKeyApi
1616
public class KeyInfo : IKey
1717
{
1818
/// <inheritdoc />
19-
public MultiHash Id { get; set; }
19+
public Cid Id { get; set; }
2020

2121
/// <inheritdoc />
2222
public string Name { get; set; }
@@ -37,22 +37,22 @@ internal KeyApi(IpfsClient ipfs)
3737

3838
public async Task<IKey> CreateAsync(string name, string keyType, int size, CancellationToken cancel = default(CancellationToken))
3939
{
40-
var json = await ipfs.DoCommandAsync("key/gen", cancel, name, $"type={keyType}", $"size={size}", "ipns-base=base32");
40+
var json = await ipfs.DoCommandAsync("key/gen", cancel, name, $"type={keyType}", $"size={size}", "ipns-base=base36");
4141
var jobject = JObject.Parse(json);
4242

4343
string id = (string)jobject["Id"];
4444
string apiName = (string)jobject["Name"];
4545

4646
return new KeyInfo
4747
{
48-
Id = Cid.Decode(id).Hash,
48+
Id = id,
4949
Name = apiName
5050
};
5151
}
5252

5353
public async Task<IEnumerable<IKey>> ListAsync(CancellationToken cancel = default(CancellationToken))
5454
{
55-
var json = await ipfs.DoCommandAsync("key/list", cancel, null, "l=true", "ipns-base=base32");
55+
var json = await ipfs.DoCommandAsync("key/list", cancel, null, "l=true", "ipns-base=base36");
5656
var keys = (JArray)(JObject.Parse(json)["Keys"]);
5757

5858
return keys
@@ -63,15 +63,15 @@ internal KeyApi(IpfsClient ipfs)
6363

6464
return new KeyInfo
6565
{
66-
Id = Cid.Decode(id).Hash,
66+
Id = id,
6767
Name = name
6868
};
6969
});
7070
}
7171

7272
public async Task<IKey> RemoveAsync(string name, CancellationToken cancel = default(CancellationToken))
7373
{
74-
var json = await ipfs.DoCommandAsync("key/rm", cancel, name, "ipns-base=base32");
74+
var json = await ipfs.DoCommandAsync("key/rm", cancel, name, "ipns-base=base36");
7575
var keys = JObject.Parse(json)["Keys"] as JArray;
7676

7777
return keys?
@@ -82,7 +82,7 @@ internal KeyApi(IpfsClient ipfs)
8282

8383
return new KeyInfo
8484
{
85-
Id = Cid.Decode(id).Hash,
85+
Id = id,
8686
Name = keyName
8787
};
8888
})
@@ -91,15 +91,15 @@ internal KeyApi(IpfsClient ipfs)
9191

9292
public async Task<IKey> RenameAsync(string oldName, string newName, CancellationToken cancel = default(CancellationToken))
9393
{
94-
var json = await ipfs.DoCommandAsync("key/rename", cancel, oldName, $"arg={newName}", "ipns-base=base32");
94+
var json = await ipfs.DoCommandAsync("key/rename", cancel, oldName, $"arg={newName}", "ipns-base=base36");
9595
var jobject = JObject.Parse(json);
9696

9797
string id = (string)jobject["Id"];
9898
string currentName = (string)jobject["Now"];
9999

100100
return new KeyInfo
101101
{
102-
Id = Cid.Decode(id).Hash,
102+
Id = id,
103103
Name = currentName
104104
};
105105
}

test/CoreApi/NameApiTest.cs

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using Microsoft.VisualStudio.TestTools.UnitTesting;
22
using System;
3+
using System.Text;
34
using System.Threading;
45
using System.Threading.Tasks;
56

@@ -24,18 +25,19 @@ public async Task Resolve()
2425
}
2526

2627
[TestMethod]
27-
[Ignore("takes forever")]
2828
public async Task Publish()
2929
{
3030
var ipfs = TestFixture.Ipfs;
3131
var cs = new CancellationTokenSource(TimeSpan.FromMinutes(5));
3232
var content = await ipfs.FileSystem.AddTextAsync("hello world");
33-
var key = await ipfs.Key.CreateAsync("name-publish-test", "rsa", 1024);
33+
var key = await ipfs.Key.CreateAsync("name-publish-test", "rsa", 2048);
34+
3435
try
3536
{
3637
var result = await ipfs.Name.PublishAsync(content.Id, key.Name, cancel: cs.Token);
3738
Assert.IsNotNull(result);
38-
StringAssert.EndsWith(result.NamePath, key.Id.ToString());
39+
40+
StringAssert.EndsWith(result.NamePath, key.Id);
3941
StringAssert.EndsWith(result.ContentPath, content.Id.Encode());
4042
}
4143
finally

0 commit comments

Comments
 (0)