Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
throw new TypeError('HashMap.create() requires a \'hasher\' function and a \'hashBytes\' integer to use a custom \'hashAlg\'')
}
IAMap.registerHasher(hashAlg, hashBytes, hasher)
const bitWidth = fromOptions('bitWidth', 'number', DEFAULT_BITWIDTH)
const bucketSize = fromOptions('bucketSize', 'number', DEFAULT_BUCKET_SIZE)
const iamapOptions = { hashAlg, bitWidth, bucketSize }
let iamap
if (CID.isCID(root)) {
// load existing, ignoring bitWidth & bucketSize, they are loaded from the existing root
iamap = await IAMap.load(store, root)
} else {
// create new
iamap = await IAMap.create(store, iamapOptions)
}
return new HashMap(iamap)
}
const hasher = fromOptions('hasher', 'function', DEFAULT_HASHER)
const hashBytes = fromOptions('hashBytes', 'number', DEFAULT_HASH_BYTES)
if (hashAlg !== DEFAULT_HASH_ALGORITHM && (typeof options.hasher !== 'function' || options.hashBytes !== 'number')) {
throw new TypeError('HashMap.create() requires a \'hasher\' function and a \'hashBytes\' integer to use a custom \'hashAlg\'')
}
IAMap.registerHasher(hashAlg, hashBytes, hasher)
const bitWidth = fromOptions('bitWidth', 'number', DEFAULT_BITWIDTH)
const bucketSize = fromOptions('bucketSize', 'number', DEFAULT_BUCKET_SIZE)
const iamapOptions = { hashAlg, bitWidth, bucketSize }
let iamap
if (CID.isCID(root)) {
// load existing, ignoring bitWidth & bucketSize, they are loaded from the existing root
iamap = await IAMap.load(store, root)
} else {
// create new
iamap = await IAMap.create(store, iamapOptions)
}
return new HashMap(iamap)
}
isEqual (cid1, cid2) {
return cid1.equals(cid2)
},
isLink (obj) {
return CID.isCID(obj)
}
}
const hashAlg = fromOptions('hashAlg', 'string', DEFAULT_HASH_ALGORITHM)
const hasher = fromOptions('hasher', 'function', DEFAULT_HASHER)
const hashBytes = fromOptions('hashBytes', 'number', DEFAULT_HASH_BYTES)
if (hashAlg !== DEFAULT_HASH_ALGORITHM && (typeof options.hasher !== 'function' || options.hashBytes !== 'number')) {
throw new TypeError('HashMap.create() requires a \'hasher\' function and a \'hashBytes\' integer to use a custom \'hashAlg\'')
}
IAMap.registerHasher(hashAlg, hashBytes, hasher)
const bitWidth = fromOptions('bitWidth', 'number', DEFAULT_BITWIDTH)
const bucketSize = fromOptions('bucketSize', 'number', DEFAULT_BUCKET_SIZE)
const iamapOptions = { hashAlg, bitWidth, bucketSize }
let iamap
if (CID.isCID(root)) {
// load existing, ignoring bitWidth & bucketSize, they are loaded from the existing root
iamap = await IAMap.load(store, root)
} else {
// create new
iamap = await IAMap.create(store, iamapOptions)
}
return new HashMap(iamap)