@@ -138,12 +138,12 @@ interface EncodeInput <T, Code extends number, Alg extends number> {
138
138
* @template Alg - multicodec code corresponding to the hashing algorithm used in CID creation.
139
139
*/
140
140
export async function encode < T , Code extends number , Alg extends number > ( { value, codec, hasher } : EncodeInput < T , Code , Alg > ) : Promise < API . BlockView < T , Code , Alg > > {
141
- if ( typeof value === 'undefined' ) throw new Error ( 'Missing required argument "value"' )
142
- if ( codec == null || hasher == null ) throw new Error ( 'Missing required argument: codec or hasher' )
141
+ if ( typeof value === 'undefined' ) { throw new Error ( 'Missing required argument "value"' ) }
142
+ if ( codec == null || hasher == null ) { throw new Error ( 'Missing required argument: codec or hasher' ) }
143
143
144
144
const bytes = codec . encode ( value )
145
145
const hash = await hasher . digest ( bytes )
146
- // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
146
+
147
147
const cid = CID . create (
148
148
1 ,
149
149
codec . code ,
@@ -165,12 +165,12 @@ interface DecodeInput <T, Code extends number, Alg extends number> {
165
165
* @template Alg - multicodec code corresponding to the hashing algorithm used in CID creation.
166
166
*/
167
167
export async function decode < T , Code extends number , Alg extends number > ( { bytes, codec, hasher } : DecodeInput < T , Code , Alg > ) : Promise < API . BlockView < T , Code , Alg > > {
168
- if ( bytes == null ) throw new Error ( 'Missing required argument "bytes"' )
169
- if ( codec == null || hasher == null ) throw new Error ( 'Missing required argument: codec or hasher' )
168
+ if ( bytes == null ) { throw new Error ( 'Missing required argument "bytes"' ) }
169
+ if ( codec == null || hasher == null ) { throw new Error ( 'Missing required argument: codec or hasher' ) }
170
170
171
171
const value = codec . decode ( bytes )
172
172
const hash = await hasher . digest ( bytes )
173
- // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
173
+
174
174
const cid = CID . create ( 1 , codec . code , hash ) as CID < T , Code , Alg , 1 >
175
175
176
176
return new Block ( { value, bytes, cid } )
@@ -195,12 +195,11 @@ type CreateUnsafeInput <T, Code extends number, Alg extends number, V extends AP
195
195
* @template V - CID version
196
196
*/
197
197
export function createUnsafe < T , Code extends number , Alg extends number , V extends API . Version > ( { bytes, cid, value : maybeValue , codec } : CreateUnsafeInput < T , Code , Alg , V > ) : API . BlockView < T , Code , Alg , V > {
198
- // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
199
198
const value = maybeValue !== undefined
200
199
? maybeValue
201
200
: ( codec ?. decode ( bytes ) )
202
201
203
- if ( value === undefined ) throw new Error ( 'Missing required argument, must either provide "value" or "codec"' )
202
+ if ( value === undefined ) { throw new Error ( 'Missing required argument, must either provide "value" or "codec"' ) }
204
203
205
204
return new Block ( {
206
205
cid : cid as CID < T , Code , Alg , V > ,
@@ -223,8 +222,8 @@ interface CreateInput <T, Code extends number, Alg extends number, V extends API
223
222
* @template V - CID version
224
223
*/
225
224
export async function create < T , Code extends number , Alg extends number , V extends API . Version > ( { bytes, cid, hasher, codec } : CreateInput < T , Code , Alg , V > ) : Promise < API . BlockView < T , Code , Alg , V > > {
226
- if ( bytes == null ) throw new Error ( 'Missing required argument "bytes"' )
227
- if ( hasher == null ) throw new Error ( 'Missing required argument "hasher"' )
225
+ if ( bytes == null ) { throw new Error ( 'Missing required argument "bytes"' ) }
226
+ if ( hasher == null ) { throw new Error ( 'Missing required argument "hasher"' ) }
228
227
const value = codec . decode ( bytes )
229
228
const hash = await hasher . digest ( bytes )
230
229
if ( ! binary . equals ( cid . multihash . bytes , hash . bytes ) ) {
0 commit comments