@@ -157,7 +157,8 @@ export function validate (node) {
157
157
Data optional Bytes
158
158
}
159
159
*/
160
- if ( ! node || typeof node !== 'object' || Array . isArray ( node ) ) {
160
+ // @ts -ignore private property for TS
161
+ if ( ! node || typeof node !== 'object' || Array . isArray ( node ) || node instanceof Uint8Array || ( node [ '/' ] && node [ '/' ] === node . bytes ) ) {
161
162
throw new TypeError ( 'Invalid DAG-PB form' )
162
163
}
163
164
@@ -166,38 +167,44 @@ export function validate (node) {
166
167
}
167
168
168
169
if ( node . Data !== undefined && ! ( node . Data instanceof Uint8Array ) ) {
169
- throw new TypeError ( 'Invalid DAG-PB form (Data must be a Uint8Array )' )
170
+ throw new TypeError ( 'Invalid DAG-PB form (Data must be bytes )' )
170
171
}
171
172
172
173
if ( ! Array . isArray ( node . Links ) ) {
173
- throw new TypeError ( 'Invalid DAG-PB form (Links must be an array )' )
174
+ throw new TypeError ( 'Invalid DAG-PB form (Links must be a list )' )
174
175
}
175
176
176
177
for ( let i = 0 ; i < node . Links . length ; i ++ ) {
177
178
const link = node . Links [ i ]
178
- if ( ! link || typeof link !== 'object' || Array . isArray ( link ) ) {
179
- throw new TypeError ( 'Invalid DAG-PB form (bad link object)' )
179
+ // @ts -ignore private property for TS
180
+ if ( ! link || typeof link !== 'object' || Array . isArray ( link ) || link instanceof Uint8Array || ( link [ '/' ] && link [ '/' ] === link . bytes ) ) {
181
+ throw new TypeError ( 'Invalid DAG-PB form (bad link)' )
180
182
}
181
183
182
184
if ( ! hasOnlyProperties ( link , pbLinkProperties ) ) {
183
- throw new TypeError ( 'Invalid DAG-PB form (extraneous properties on link object )' )
185
+ throw new TypeError ( 'Invalid DAG-PB form (extraneous properties on link)' )
184
186
}
185
187
186
- if ( ! link . Hash ) {
188
+ if ( link . Hash === undefined ) {
187
189
throw new TypeError ( 'Invalid DAG-PB form (link must have a Hash)' )
188
190
}
189
191
190
192
// @ts -ignore private property for TS
191
- if ( link . Hash . asCID !== link . Hash ) {
193
+ if ( link . Hash == null || ! link . Hash [ '/' ] || link . Hash [ '/' ] !== link . Hash . bytes ) {
192
194
throw new TypeError ( 'Invalid DAG-PB form (link Hash must be a CID)' )
193
195
}
194
196
195
197
if ( link . Name !== undefined && typeof link . Name !== 'string' ) {
196
198
throw new TypeError ( 'Invalid DAG-PB form (link Name must be a string)' )
197
199
}
198
200
199
- if ( link . Tsize !== undefined && ( typeof link . Tsize !== 'number' || link . Tsize % 1 !== 0 ) ) {
200
- throw new TypeError ( 'Invalid DAG-PB form (link Tsize must be an integer)' )
201
+ if ( link . Tsize !== undefined ) {
202
+ if ( typeof link . Tsize !== 'number' || link . Tsize % 1 !== 0 ) {
203
+ throw new TypeError ( 'Invalid DAG-PB form (link Tsize must be an integer)' )
204
+ }
205
+ if ( link . Tsize < 0 ) {
206
+ throw new TypeError ( 'Invalid DAG-PB form (link Tsize cannot be negative)' )
207
+ }
201
208
}
202
209
203
210
if ( i > 0 && linkComparator ( link , node . Links [ i - 1 ] ) === - 1 ) {
0 commit comments