This repository was archived by the owner on Aug 24, 2021. It is now read-only.
File tree Expand file tree Collapse file tree 3 files changed +15
-4
lines changed Expand file tree Collapse file tree 3 files changed +15
-4
lines changed Original file line number Diff line number Diff line change 3
3
'use strict'
4
4
5
5
exports . names = Object . freeze ( {
6
- 'id' : 0x0 ,
6
+ 'identity' : 0x0 ,
7
7
'sha1' : 0x11 ,
8
8
'sha2-256' : 0x12 ,
9
9
'sha2-512' : 0x13 ,
@@ -343,6 +343,9 @@ exports.names = Object.freeze({
343
343
} )
344
344
345
345
exports . codes = Object . freeze ( {
346
+ 0x0 : 'identity' ,
347
+
348
+ // sha family
346
349
0x11 : 'sha1' ,
347
350
0x12 : 'sha2-256' ,
348
351
0x13 : 'sha2-512' ,
@@ -357,6 +360,7 @@ exports.codes = Object.freeze({
357
360
0x1B : 'keccak-256' ,
358
361
0x1C : 'keccak-384' ,
359
362
0x1D : 'keccak-512' ,
363
+
360
364
0x22 : 'murmur3-128' ,
361
365
0x23 : 'murmur3-32' ,
362
366
Original file line number Diff line number Diff line change @@ -118,7 +118,7 @@ exports.decode = function decode (buf) {
118
118
* @returns {Buffer }
119
119
*/
120
120
exports . encode = function encode ( digest , code , length ) {
121
- if ( ! digest || ! code ) {
121
+ if ( ! digest || code === undefined ) {
122
122
throw new Error ( 'multihash encode requires at least two args: digest, code' )
123
123
}
124
124
@@ -154,7 +154,7 @@ exports.coerceCode = function coerceCode (name) {
154
154
let code = name
155
155
156
156
if ( typeof name === 'string' ) {
157
- if ( ! cs . names [ name ] ) {
157
+ if ( cs . names [ name ] === undefined ) {
158
158
throw new Error ( `Unrecognized hash function named: ${ name } ` )
159
159
}
160
160
code = cs . names [ name ]
@@ -164,7 +164,7 @@ exports.coerceCode = function coerceCode (name) {
164
164
throw new Error ( `Hash function code should be a number. Got: ${ code } ` )
165
165
}
166
166
167
- if ( ! cs . codes [ code ] && ! exports . isAppCode ( code ) ) {
167
+ if ( cs . codes [ code ] === undefined && ! exports . isAppCode ( code ) ) {
168
168
throw new Error ( `Unrecognized function code: ${ code } ` )
169
169
}
170
170
Original file line number Diff line number Diff line change @@ -28,4 +28,11 @@ module.exports = [{
28
28
} ,
29
29
hex : '2c26b46b' ,
30
30
size : 4
31
+ } , {
32
+ encoding : {
33
+ code : 0x0 ,
34
+ name : 'identity'
35
+ } ,
36
+ hex : '7465737420737472696e6720f09f918d' ,
37
+ size : 16
31
38
} ]
You can’t perform that action at this time.
0 commit comments