This repository was archived by the owner on Sep 3, 2021. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +22
-1
lines changed Expand file tree Collapse file tree 2 files changed +22
-1
lines changed Original file line number Diff line number Diff line change @@ -24,6 +24,15 @@ var CIDUtil = {
24
24
return 'codec must be string'
25
25
}
26
26
27
+ if ( other . version === 0 ) {
28
+ if ( other . codec !== 'dag-pb' ) {
29
+ return `codec must be 'dag-pb' for CIDv0`
30
+ }
31
+ if ( other . multibaseName !== 'base58btc' ) {
32
+ return `multibaseName must be 'base58btc' for CIDv0`
33
+ }
34
+ }
35
+
27
36
if ( ! Buffer . isBuffer ( other . multihash ) ) {
28
37
return 'multihash must be a Buffer'
29
38
}
Original file line number Diff line number Diff line change @@ -66,7 +66,19 @@ describe('CID', () => {
66
66
) . to . throw ( )
67
67
} )
68
68
69
- it ( 'throws on trying to base encode CIDv0 in other base than base58 ' , ( ) => {
69
+ it ( 'throws on trying to create a CIDv0 with a codec other than dag-pb' , ( ) => {
70
+ expect (
71
+ ( ) => new CID ( 0 , 'dag-cbor' , hash )
72
+ ) . to . throw ( `codec must be 'dag-pb' for CIDv0` )
73
+ } )
74
+
75
+ it ( 'throws on trying to create a CIDv0 with a base other than base58btc' , ( ) => {
76
+ expect (
77
+ ( ) => new CID ( 0 , 'dag-pb' , hash , 'base32' )
78
+ ) . to . throw ( `multibaseName must be 'base58btc' for CIDv0` )
79
+ } )
80
+
81
+ it ( 'throws on trying to base encode CIDv0 in other base than base58btc' , ( ) => {
70
82
const mhStr = 'QmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n'
71
83
const cid = new CID ( mhStr )
72
84
expect ( ( ) => cid . toBaseEncodedString ( 'base16' ) ) . to . throw ( )
You can’t perform that action at this time.
0 commit comments