{"version":3,"file":"scion-toolkit-crypto.mjs","sources":["../../../../projects/scion/toolkit/crypto/src/crypto.util.ts","../../../../projects/scion/toolkit/crypto/src/public_api.ts","../../../../projects/scion/toolkit/crypto/src/scion-toolkit-crypto.ts"],"sourcesContent":["/*\n * Copyright (c) 2018-2022 Swiss Federal Railways\n *\n * This program and the accompanying materials are made\n * available under the terms of the Eclipse Public License 2.0\n * which is available at https://www.eclipse.org/legal/epl-2.0/\n *\n *  SPDX-License-Identifier: EPL-2.0\n */\n\n/**\n * Provides cryptographic functions.\n */\nexport namespace Crypto {\n\n  /**\n   * Generates a digest of the given data using the specified algorithm (or SHA-256 by default) and converts it to a hex string.\n   *\n   * Can only be used in secure contexts (HTTPS) or on localhost. For more information, refer to https://developer.mozilla.org/en-US/docs/Web/Security/Secure_Contexts.\n   *\n   * Credits: https://developer.mozilla.org/en-US/docs/Web/API/SubtleCrypto/digest\n   */\n  export async function digest(data: string | BufferSource, options?: {algorithm?: 'SHA-256' | 'SHA-384' | 'SHA-512'}): Promise<string> {\n    if (!isSecureContext) {\n      throw Error('Function \"digest\" of @scion/toolkit/crypto is available only in secure contexts (HTTPS) or on localhost. For more information, refer to https://developer.mozilla.org/en-US/docs/Web/Security/Secure_Contexts.');\n    }\n    data = typeof data === 'string' ? new TextEncoder().encode(data) : data;\n    // Hash the data.\n    const hashBuffer = await crypto.subtle.digest(options?.algorithm ?? 'SHA-256', data);\n    // Convert buffer to byte array.\n    const hashArray = Array.from(new Uint8Array(hashBuffer));\n    // Convert bytes to hex string.\n    return hashArray.map(b => b.toString(16).padStart(2, '0')).join('');\n  }\n}\n","/*\n * Copyright (c) 2018-2022 Swiss Federal Railways\n *\n * This program and the accompanying materials are made\n * available under the terms of the Eclipse Public License 2.0\n * which is available at https://www.eclipse.org/legal/epl-2.0/\n *\n *  SPDX-License-Identifier: EPL-2.0\n */\n\n/*\n * Secondary entrypoint: '@scion/toolkit/crypto'\n * This module does not depend on Angular.\n *\n * @see https://github.com/ng-packagr/ng-packagr/blob/master/docs/secondary-entrypoints.md\n */\nexport {Crypto} from './crypto.util';\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public_api';\n"],"names":[],"mappings":"AAAA;;;;;;;;AAQG;AAEH;;AAEG;AACG,IAAW;AAAjB,CAAA,UAAiB,MAAM,EAAA;AAErB;;;;;;AAMG;AACI,IAAA,eAAe,MAAM,CAAC,IAA2B,EAAE,OAAyD,EAAA;QACjH,IAAI,CAAC,eAAe,EAAE;AACpB,YAAA,MAAM,KAAK,CAAC,gNAAgN,CAAC;QAC/N;QACA,IAAI,GAAG,OAAO,IAAI,KAAK,QAAQ,GAAG,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,IAAI;;AAEvE,QAAA,MAAM,UAAU,GAAG,MAAM,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,OAAO,EAAE,SAAS,IAAI,SAAS,EAAE,IAAI,CAAC;;AAEpF,QAAA,MAAM,SAAS,GAAG,KAAK,CAAC,IAAI,CAAC,IAAI,UAAU,CAAC,UAAU,CAAC,CAAC;;QAExD,OAAO,SAAS,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC;IACrE;AAXsB,IAAA,MAAA,CAAA,MAAM,SAW3B;AACH,CAAC,EArBgB,MAAM,KAAN,MAAM,GAAA,EAAA,CAAA,CAAA;;ACbvB;;;;;;;;AAQG;AAEH;;;;;AAKG;;ACfH;;AAEG;;;;"}