@microsoft/useragent-sdk
Version:
SDK for building decentralized identity wallets and enterprise agents.
31 lines • 1.36 kB
JavaScript
;
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
Object.defineProperty(exports, "__esModule", { value: true });
const crypto = require("crypto");
const multihashes = require('multihashes');
/**
* Class that performs hashing operations using the multihash format.
*/
class Multihash {
/**
* Hashes the content using the hashing algorithm specified by the latest protocol version.
*/
static hash(content, hashAlgorithmInMultihashCode) {
const hashAlgorithm = hashAlgorithmInMultihashCode;
let hash;
switch (hashAlgorithm) {
case 18: // SHA256
hash = crypto.createHash('sha256').update(content).digest();
break;
default:
throw new Error(`Hashing algorithm '${hashAlgorithm}' not supported.`);
}
const hashAlgorithmName = multihashes.codes[hashAlgorithm];
return multihashes.encode(hash, hashAlgorithmName);
}
}
exports.default = Multihash;
//# sourceMappingURL=Multihash.js.map