feat: add blake3 support
Support hashes from 20 <= x <= 128 bytes, but does not yet have any option to generate anything else than 32 bytes hashes. This will be forward compatible when we add such option.
Claudia Richoux committed
Jun 30, 2022 at 22:32 UTC
2fb7437e2abc781320e10c113780148c0e1bb52d
5 files changed
+90
-7
go.mod
+2
-2
@@ -57,7 +57,7 @@ require (
57
github.com/ipfs/go-pinning-service-http-client v0.1.1
58
github.com/ipfs/go-unixfs v0.4.0
59
github.com/ipfs/go-unixfsnode v1.4.0
60
- github.com/ipfs/go-verifcid v0.0.1
60
+ github.com/ipfs/go-verifcid v0.0.2
61
github.com/ipfs/interface-go-ipfs-core v0.7.0
62
github.com/ipfs/tar-utils v0.0.2
63
github.com/ipld/go-car v0.4.0
@@ -88,7 +88,7 @@ require (
88
github.com/multiformats/go-multiaddr-dns v0.3.1
89
github.com/multiformats/go-multibase v0.1.0
90
github.com/multiformats/go-multicodec v0.5.0
91
- github.com/multiformats/go-multihash v0.2.0
91
+ github.com/multiformats/go-multihash v0.2.1
92
github.com/opentracing/opentracing-go v1.2.0
93
github.com/pkg/errors v0.9.1
94
github.com/prometheus/client_golang v1.12.1
go.sum
+4
-3
@@ -655,8 +655,9 @@ github.com/ipfs/go-unixfs v0.4.0/go.mod h1:I7Nqtm06HgOOd+setAoCU6rf/HgVFHE+peeNu
655
github.com/ipfs/go-unixfsnode v1.1.2/go.mod h1:5dcE2x03pyjHk4JjamXmunTMzz+VUtqvPwZjIEkfV6s=
656
github.com/ipfs/go-unixfsnode v1.4.0 h1:9BUxHBXrbNi8mWHc6j+5C580WJqtVw9uoeEKn4tMhwA=
657
github.com/ipfs/go-unixfsnode v1.4.0/go.mod h1:qc7YFFZ8tABc58p62HnIYbUMwj9chhUuFWmxSokfePo=
658
-github.com/ipfs/go-verifcid v0.0.1 h1:m2HI7zIuR5TFyQ1b79Da5N9dnnCP1vcu2QqawmWlK2E=
658
github.com/ipfs/go-verifcid v0.0.1/go.mod h1:5Hrva5KBeIog4A+UpqlaIU+DEstipcJYQQZc0g37pY0=
659
+github.com/ipfs/go-verifcid v0.0.2 h1:XPnUv0XmdH+ZIhLGKg6U2vaPaRDXb9urMyNVCE7uvTs=
660
+github.com/ipfs/go-verifcid v0.0.2/go.mod h1:40cD9x1y4OWnFXbLNJYRe7MpNvWlMn3LZAG5Wb4xnPU=
661
github.com/ipfs/interface-go-ipfs-core v0.4.0/go.mod h1:UJBcU6iNennuI05amq3FQ7g0JHUkibHFAfhfUIy927o=
662
github.com/ipfs/interface-go-ipfs-core v0.7.0 h1:7tb+2upz8oCcjIyjo1atdMk+P+u7wPmI+GksBlLE8js=
663
github.com/ipfs/interface-go-ipfs-core v0.7.0/go.mod h1:lF27E/nnSPbylPqKVXGZghal2hzifs3MmjyiEjnc9FY=
@@ -1277,8 +1278,8 @@ github.com/multiformats/go-multihash v0.0.14/go.mod h1:VdAWLKTwram9oKAatUcLxBNUj
1278
github.com/multiformats/go-multihash v0.0.15/go.mod h1:D6aZrWNLFTV/ynMpKsNtB40mJzmCl4jb1alC0OvHiHg=
1279
github.com/multiformats/go-multihash v0.0.16/go.mod h1:zhfEIgVnB/rPMfxgFw15ZmGoNaKyNUIE4IWHG/kC+Ag=
1280
github.com/multiformats/go-multihash v0.1.0/go.mod h1:RJlXsxt6vHGaia+S8We0ErjhojtKzPP2AH4+kYM7k84=
1280
-github.com/multiformats/go-multihash v0.2.0 h1:oytJb9ZA1OUW0r0f9ea18GiaPOo4SXyc7p2movyUuo4=
1281
-github.com/multiformats/go-multihash v0.2.0/go.mod h1:WxoMcYG85AZVQUyRyo9s4wULvW5qrI9vb2Lt6evduFc=
1281
+github.com/multiformats/go-multihash v0.2.1 h1:aem8ZT0VA2nCHHk7bPJ1BjUbHNciqZC/d16Vve9l108=
1282
+github.com/multiformats/go-multihash v0.2.1/go.mod h1:WxoMcYG85AZVQUyRyo9s4wULvW5qrI9vb2Lt6evduFc=
1283
github.com/multiformats/go-multistream v0.0.1/go.mod h1:fJTiDfXJVmItycydCnNx4+wSzZ5NwG2FEVAI30fiovg=
1284
github.com/multiformats/go-multistream v0.0.4/go.mod h1:fJTiDfXJVmItycydCnNx4+wSzZ5NwG2FEVAI30fiovg=
1285
github.com/multiformats/go-multistream v0.1.0/go.mod h1:fJTiDfXJVmItycydCnNx4+wSzZ5NwG2FEVAI30fiovg=
test/sharness/t0275-cid-security.sh
+2
-2
@@ -23,7 +23,7 @@ test_expect_success "adding using too short of a hash function gives out an erro
23
'
24
25
test_expect_success "error reason is pointed out" '
26
- grep "hashes must be at 20 least bytes long" block_out
26
+ grep "hashes must be at least 20 bytes long" block_out
27
'
28
29
@@ -45,7 +45,7 @@ test_cat_get() {
45
'
46
47
test_expect_success "error reason is pointed out" '
48
- grep "hashes must be at 20 least bytes long" ipfs_get
48
+ grep "hashes must be at least 20 bytes long" ipfs_get
49
'
50
}
51
test/sharness/t0290-cid.sh
+1
@@ -173,6 +173,7 @@ cat <<EOF > hashes_expect
173
27 keccak-256
174
28 keccak-384
175
29 keccak-512
176
+ 30 blake3
177
86 dbl-sha2-256
178
45588 blake2b-160
179
45589 blake2b-168
test/sharness/t0800-blake3.sh
new
+81
@@ -0,0 +1,81 @@
1
+#!/usr/bin/env bash
2
+#
3
+# Copyright (c) 2020 Claudia Richoux
4
+# MIT Licensed; see the LICENSE file in this repository.
5
+#
6
+
7
+test_description="Test blake3 mhash support"
8
+
9
+. lib/test-lib.sh
10
+
11
+test_init_ipfs
12
+
13
+# the blake3 hash of "foo\n" in UTF8 (which is what comes out of echo when you pipe into `ipfs`) starts with "49dc870df1de7fd60794cebce449f5ccdae575affaa67a24b62acb03e039db92"
14
+# without the newline it's "04e0bb39f30b1a3feb89f536c93be15055482df748674b00d26e5a75777702e9". so if you start seeing these values that's your problem
15
+BLAKE3RAWCID32BYTE="bafkr4icj3sdq34o6p7lapfgoxtset5om3lsxll72uz5cjnrkzmb6aoo3si"
16
+BLAKE3RAWCID64BYTE="bafkr4qcj3sdq34o6p7lapfgoxtset5om3lsxll72uz5cjnrkzmb6aoo3sknmbprpe27pbfrb67tonydgfot5ixuq4skiva76ppbgpjlzc4ua4"
17
+BLAKE3RAWCID128BYTE="bafkr5aabjhoiodpr3z75mb4uz26oispvztnok5np7kthujfwflfqhybz3ojjvqf6f4tl54eweh36nzxamyv2pvc6sdsjjcud7z54ez5fpelsqdtax2k3rvuq3wdl5a4blxv3gvsroa3nakfzzknamhu2apf3vvytyiobabrn2bfnfajq66ikjy5lewsp5jyddsg5l7u3emr2ancimryay"
18
+
19
+### block tests, including for various sizes of hash ###
20
+
21
+test_expect_success "putting a block with an mhash blake3 succeeds (default 32 bytes)" '
22
+ HASH=$(echo "foo" | ipfs block put --mhtype=blake3 --cid-codec=raw | tee actual_out) &&
23
+ test $BLAKE3RAWCID32BYTE = "$HASH"
24
+'
25
+
26
+test_expect_success "block get output looks right" '
27
+ ipfs block get $BLAKE3RAWCID32BYTE > blk_get_out &&
28
+ echo "foo" > blk_get_exp &&
29
+ test_cmp blk_get_exp blk_get_out
30
+'
31
+
32
+test_expect_success "putting a block with an mhash blake3 succeeds: 64 bytes" '
33
+ HASH=$(echo "foo" | ipfs block put --mhtype=blake3 --mhlen=64 --cid-codec=raw | tee actual_out) &&
34
+ test $BLAKE3RAWCID64BYTE = "$HASH"
35
+'
36
+
37
+test_expect_success "64B block get output looks right" '
38
+ ipfs block get $BLAKE3RAWCID64BYTE > blk_get_out &&
39
+ echo "foo" > blk_get_exp &&
40
+ test_cmp blk_get_exp blk_get_out
41
+'
42
+
43
+test_expect_success "putting a block with an mhash blake3 succeeds: 128 bytes" '
44
+ HASH=$(echo "foo" | ipfs block put --mhtype=blake3 --mhlen=128 --cid-codec=raw | tee actual_out) &&
45
+ test $BLAKE3RAWCID128BYTE = "$HASH"
46
+'
47
+
48
+test_expect_success "32B block get output looks right" '
49
+ ipfs block get $BLAKE3RAWCID128BYTE > blk_get_out &&
50
+ echo "foo" > blk_get_exp &&
51
+ test_cmp blk_get_exp blk_get_out
52
+'
53
+
54
+### dag tests ###
55
+
56
+test_expect_success "dag put works with blake3" '
57
+ HASH=$(echo "foo" | ipfs dag put --input-codec=raw --store-codec=raw --hash=blake3 | tee actual_out) &&
58
+ test $BLAKE3RAWCID32BYTE = "$HASH"
59
+'
60
+
61
+test_expect_success "dag get output looks right" '
62
+ ipfs dag get --output-codec=raw $BLAKE3RAWCID32BYTE > dag_get_out &&
63
+ echo "foo" > dag_get_exp &&
64
+ test_cmp dag_get_exp dag_get_out
65
+'
66
+
67
+### add and cat tests ###
68
+
69
+test_expect_success "adding a file with just foo in it to ipfs" '
70
+ echo "foo" > afile &&
71
+ HASH=$(ipfs add -q --hash=blake3 --raw-leaves afile | tee actual_out) &&
72
+ test $BLAKE3RAWCID32BYTE = "$HASH"
73
+'
74
+
75
+test_expect_success "catting it" '
76
+ ipfs cat $BLAKE3RAWCID32BYTE > cat_out &&
77
+ echo "foo" > cat_exp &&
78
+ test_cmp cat_exp cat_out
79
+'
80
+
81
+test_done