@tbd54566975/crypto
Advanced tools
Comparing version 0.8.0-alpha-20230728-70f8cf0 to 0.8.0-alpha-20230728-88c49a2
@@ -0,1 +1,2 @@ | ||
"use strict"; | ||
var __extends = (this && this.__extends) || (function () { | ||
@@ -52,6 +53,8 @@ var extendStatics = function (d, b) { | ||
}; | ||
import { universalTypeOf } from '@tbd54566975/common'; | ||
import { CryptoAlgorithm } from '../crypto-algorithm.js'; | ||
import { checkRequiredProperty } from '../../utils-new.js'; | ||
import { InvalidAccessError, OperationError } from '../errors.js'; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.BaseAesAlgorithm = void 0; | ||
var common_1 = require("@tbd54566975/common"); | ||
var crypto_algorithm_js_1 = require("../crypto-algorithm.js"); | ||
var utils_new_js_1 = require("../../utils-new.js"); | ||
var errors_js_1 = require("../errors.js"); | ||
var BaseAesAlgorithm = /** @class */ (function (_super) { | ||
@@ -67,5 +70,5 @@ __extends(BaseAesAlgorithm, _super); | ||
// The algorithm object must contain a length property. | ||
checkRequiredProperty({ property: 'length', inObject: algorithm }); | ||
(0, utils_new_js_1.checkRequiredProperty)({ property: 'length', inObject: algorithm }); | ||
// The length specified must be a number. | ||
if (universalTypeOf(algorithm.length) !== 'Number') { | ||
if ((0, common_1.universalTypeOf)(algorithm.length) !== 'Number') { | ||
throw new TypeError("Algorithm 'length' is not of type: Number."); | ||
@@ -75,3 +78,3 @@ } | ||
if (![128, 192, 256].includes(algorithm.length)) { | ||
throw new OperationError("Algorithm 'length' must be 128, 192, or 256."); | ||
throw new errors_js_1.OperationError("Algorithm 'length' must be 128, 192, or 256."); | ||
} | ||
@@ -84,3 +87,3 @@ // The key usages specified must be permitted by the algorithm implementation processing the operation. | ||
return __generator(this, function (_a) { | ||
throw new InvalidAccessError("Requested operation 'deriveBits' is not valid for ".concat(this.name, " keys.")); | ||
throw new errors_js_1.InvalidAccessError("Requested operation 'deriveBits' is not valid for ".concat(this.name, " keys.")); | ||
}); | ||
@@ -92,3 +95,3 @@ }); | ||
return __generator(this, function (_a) { | ||
throw new InvalidAccessError("Requested operation 'sign' is not valid for ".concat(this.name, " keys.")); | ||
throw new errors_js_1.InvalidAccessError("Requested operation 'sign' is not valid for ".concat(this.name, " keys.")); | ||
}); | ||
@@ -100,3 +103,3 @@ }); | ||
return __generator(this, function (_a) { | ||
throw new InvalidAccessError("Requested operation 'verify' is not valid for ".concat(this.name, " keys.")); | ||
throw new errors_js_1.InvalidAccessError("Requested operation 'verify' is not valid for ".concat(this.name, " keys.")); | ||
}); | ||
@@ -106,3 +109,3 @@ }); | ||
return BaseAesAlgorithm; | ||
}(CryptoAlgorithm)); | ||
export { BaseAesAlgorithm }; | ||
}(crypto_algorithm_js_1.CryptoAlgorithm)); | ||
exports.BaseAesAlgorithm = BaseAesAlgorithm; |
@@ -0,1 +1,2 @@ | ||
"use strict"; | ||
var __extends = (this && this.__extends) || (function () { | ||
@@ -16,6 +17,8 @@ var extendStatics = function (d, b) { | ||
})(); | ||
import { universalTypeOf } from '@tbd54566975/common'; | ||
import { BaseAesAlgorithm } from './base.js'; | ||
import { OperationError } from '../errors.js'; | ||
import { checkRequiredProperty } from '../../utils-new.js'; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.BaseAesCtrAlgorithm = void 0; | ||
var common_1 = require("@tbd54566975/common"); | ||
var base_js_1 = require("./base.js"); | ||
var errors_js_1 = require("../errors.js"); | ||
var utils_new_js_1 = require("../../utils-new.js"); | ||
var BaseAesCtrAlgorithm = /** @class */ (function (_super) { | ||
@@ -34,5 +37,5 @@ __extends(BaseAesCtrAlgorithm, _super); | ||
// The algorithm object must contain a counter property. | ||
checkRequiredProperty({ property: 'counter', inObject: algorithm }); | ||
(0, utils_new_js_1.checkRequiredProperty)({ property: 'counter', inObject: algorithm }); | ||
// The counter must an ArrayBuffer, DataView, or TypedArray. | ||
if (!(universalTypeOf(algorithm.counter) === 'ArrayBuffer' || ArrayBuffer.isView(algorithm.counter))) { | ||
if (!((0, common_1.universalTypeOf)(algorithm.counter) === 'ArrayBuffer' || ArrayBuffer.isView(algorithm.counter))) { | ||
throw new TypeError("Algorithm 'counter' is not of type: ArrayBuffer, DataView, or TypedArray."); | ||
@@ -42,8 +45,8 @@ } | ||
if (algorithm.counter.byteLength !== 16) { | ||
throw new OperationError("Algorithm 'counter' must have length: 16 bytes."); | ||
throw new errors_js_1.OperationError("Algorithm 'counter' must have length: 16 bytes."); | ||
} | ||
// The algorithm object must contain a length property. | ||
checkRequiredProperty({ property: 'length', inObject: algorithm }); | ||
(0, utils_new_js_1.checkRequiredProperty)({ property: 'length', inObject: algorithm }); | ||
// The length specified must be a number. | ||
if (universalTypeOf(algorithm.length) !== 'Number') { | ||
if ((0, common_1.universalTypeOf)(algorithm.length) !== 'Number') { | ||
throw new TypeError("Algorithm 'length' is not of type: Number."); | ||
@@ -53,6 +56,6 @@ } | ||
if ((algorithm.length < 1 || algorithm.length > 128)) { | ||
throw new OperationError("Algorithm 'length' should be in the range: 1 to 128."); | ||
throw new errors_js_1.OperationError("Algorithm 'length' should be in the range: 1 to 128."); | ||
} | ||
// The options object must contain a key property. | ||
checkRequiredProperty({ property: 'key', inObject: options }); | ||
(0, utils_new_js_1.checkRequiredProperty)({ property: 'key', inObject: options }); | ||
// The key object must be a CryptoKey. | ||
@@ -66,3 +69,3 @@ this.checkCryptoKey({ key: key }); | ||
return BaseAesCtrAlgorithm; | ||
}(BaseAesAlgorithm)); | ||
export { BaseAesCtrAlgorithm }; | ||
}(base_js_1.BaseAesAlgorithm)); | ||
exports.BaseAesCtrAlgorithm = BaseAesCtrAlgorithm; |
@@ -1,2 +0,18 @@ | ||
export * from './ctr.js'; | ||
export * from './base.js'; | ||
"use strict"; | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
var desc = Object.getOwnPropertyDescriptor(m, k); | ||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { | ||
desc = { enumerable: true, get: function() { return m[k]; } }; | ||
} | ||
Object.defineProperty(o, k2, desc); | ||
}) : (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
o[k2] = m[k]; | ||
})); | ||
var __exportStar = (this && this.__exportStar) || function(m, exports) { | ||
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
__exportStar(require("./ctr.js"), exports); | ||
__exportStar(require("./base.js"), exports); |
@@ -0,1 +1,2 @@ | ||
"use strict"; | ||
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) { | ||
@@ -10,3 +11,5 @@ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) { | ||
}; | ||
import { InvalidAccessError, NotSupportedError } from './errors.js'; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.CryptoAlgorithm = void 0; | ||
var errors_js_1 = require("./errors.js"); | ||
var CryptoAlgorithm = /** @class */ (function () { | ||
@@ -21,3 +24,3 @@ function CryptoAlgorithm() { | ||
if (algorithmName !== this.name) { | ||
throw new NotSupportedError("Algorithm not supported: '".concat(algorithmName, "'")); | ||
throw new errors_js_1.NotSupportedError("Algorithm not supported: '".concat(algorithmName, "'")); | ||
} | ||
@@ -37,3 +40,3 @@ }; | ||
if (keyAlgorithmName && keyAlgorithmName !== this.name) { | ||
throw new InvalidAccessError("Algorithm '".concat(this.name, "' does not match the provided '").concat(keyAlgorithmName, "' key.")); | ||
throw new errors_js_1.InvalidAccessError("Algorithm '".concat(this.name, "' does not match the provided '").concat(keyAlgorithmName, "' key.")); | ||
} | ||
@@ -47,3 +50,3 @@ }; | ||
if (keyType && keyType !== allowedKeyType) { | ||
throw new InvalidAccessError("Requested operation is not valid for the provided '".concat(keyType, "' key.")); | ||
throw new errors_js_1.InvalidAccessError("Requested operation is not valid for the provided '".concat(keyType, "' key.")); | ||
} | ||
@@ -58,3 +61,3 @@ }; | ||
if (!keyUsages.every(function (usage) { return allowedUsages.includes(usage); })) { | ||
throw new InvalidAccessError("Requested operation(s) '".concat(keyUsages.join(', '), "' is not valid for the provided key.")); | ||
throw new errors_js_1.InvalidAccessError("Requested operation(s) '".concat(keyUsages.join(', '), "' is not valid for the provided key.")); | ||
} | ||
@@ -77,2 +80,2 @@ }; | ||
}()); | ||
export { CryptoAlgorithm }; | ||
exports.CryptoAlgorithm = CryptoAlgorithm; |
@@ -0,1 +1,4 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.CryptoKey = void 0; | ||
var CryptoKey = /** @class */ (function () { | ||
@@ -47,2 +50,2 @@ function CryptoKey(algorithm, extractable, handle, type, usages) { | ||
}()); | ||
export { CryptoKey }; | ||
exports.CryptoKey = CryptoKey; |
@@ -0,1 +1,2 @@ | ||
"use strict"; | ||
var __extends = (this && this.__extends) || (function () { | ||
@@ -52,5 +53,7 @@ var extendStatics = function (d, b) { | ||
}; | ||
import { InvalidAccessError } from '../errors.js'; | ||
import { CryptoAlgorithm } from '../crypto-algorithm.js'; | ||
import { checkValidProperty, checkRequiredProperty } from '../../utils-new.js'; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.BaseEllipticCurveAlgorithm = void 0; | ||
var errors_js_1 = require("../errors.js"); | ||
var crypto_algorithm_js_1 = require("../crypto-algorithm.js"); | ||
var utils_new_js_1 = require("../../utils-new.js"); | ||
var BaseEllipticCurveAlgorithm = /** @class */ (function (_super) { | ||
@@ -66,5 +69,5 @@ __extends(BaseEllipticCurveAlgorithm, _super); | ||
// The algorithm object must contain a namedCurve property. | ||
checkRequiredProperty({ property: 'namedCurve', inObject: algorithm }); | ||
(0, utils_new_js_1.checkRequiredProperty)({ property: 'namedCurve', inObject: algorithm }); | ||
// The named curve specified must be supported by the algorithm implementation processing the operation. | ||
checkValidProperty({ property: algorithm.namedCurve, allowedProperties: this.namedCurves }); | ||
(0, utils_new_js_1.checkValidProperty)({ property: algorithm.namedCurve, allowedProperties: this.namedCurves }); | ||
// The key usages specified must be permitted by the algorithm implementation processing the operation. | ||
@@ -76,3 +79,3 @@ this.checkKeyUsages({ keyUsages: keyUsages, allowedKeyUsages: this.keyUsages }); | ||
return __generator(this, function (_a) { | ||
throw new InvalidAccessError("Requested operation 'decrypt' is not valid for ".concat(this.name, " keys.")); | ||
throw new errors_js_1.InvalidAccessError("Requested operation 'decrypt' is not valid for ".concat(this.name, " keys.")); | ||
}); | ||
@@ -84,3 +87,3 @@ }); | ||
return __generator(this, function (_a) { | ||
throw new InvalidAccessError("Requested operation 'encrypt' is not valid for ".concat(this.name, " keys.")); | ||
throw new errors_js_1.InvalidAccessError("Requested operation 'encrypt' is not valid for ".concat(this.name, " keys.")); | ||
}); | ||
@@ -90,3 +93,3 @@ }); | ||
return BaseEllipticCurveAlgorithm; | ||
}(CryptoAlgorithm)); | ||
export { BaseEllipticCurveAlgorithm }; | ||
}(crypto_algorithm_js_1.CryptoAlgorithm)); | ||
exports.BaseEllipticCurveAlgorithm = BaseEllipticCurveAlgorithm; |
@@ -0,1 +1,2 @@ | ||
"use strict"; | ||
var __extends = (this && this.__extends) || (function () { | ||
@@ -52,5 +53,7 @@ var extendStatics = function (d, b) { | ||
}; | ||
import { InvalidAccessError } from '../errors.js'; | ||
import { BaseEllipticCurveAlgorithm } from './base.js'; | ||
import { checkRequiredProperty } from '../../utils-new.js'; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.BaseEcdhAlgorithm = void 0; | ||
var errors_js_1 = require("../errors.js"); | ||
var base_js_1 = require("./base.js"); | ||
var utils_new_js_1 = require("../../utils-new.js"); | ||
var BaseEcdhAlgorithm = /** @class */ (function (_super) { | ||
@@ -72,3 +75,3 @@ __extends(BaseEcdhAlgorithm, _super); | ||
// The algorithm object must contain a publicKey property. | ||
checkRequiredProperty({ property: 'publicKey', inObject: algorithm }); | ||
(0, utils_new_js_1.checkRequiredProperty)({ property: 'publicKey', inObject: algorithm }); | ||
// The publicKey object must be a CryptoKey. | ||
@@ -81,3 +84,3 @@ this.checkCryptoKey({ key: algorithm.publicKey }); | ||
// The options object must contain a baseKey property. | ||
checkRequiredProperty({ property: 'baseKey', inObject: options }); | ||
(0, utils_new_js_1.checkRequiredProperty)({ property: 'baseKey', inObject: options }); | ||
// The baseKey object must be a CryptoKey. | ||
@@ -92,3 +95,3 @@ this.checkCryptoKey({ key: baseKey }); | ||
&& (algorithm.publicKey.algorithm.namedCurve !== baseKey.algorithm.namedCurve)) { | ||
throw new InvalidAccessError('The named curve of the publicKey and baseKey must match.'); | ||
throw new errors_js_1.InvalidAccessError('The named curve of the publicKey and baseKey must match.'); | ||
} | ||
@@ -99,3 +102,3 @@ }; | ||
return __generator(this, function (_a) { | ||
throw new InvalidAccessError("Requested operation 'sign' is not valid for ".concat(this.name, " keys.")); | ||
throw new errors_js_1.InvalidAccessError("Requested operation 'sign' is not valid for ".concat(this.name, " keys.")); | ||
}); | ||
@@ -107,3 +110,3 @@ }); | ||
return __generator(this, function (_a) { | ||
throw new InvalidAccessError("Requested operation 'verify' is not valid for ".concat(this.name, " keys.")); | ||
throw new errors_js_1.InvalidAccessError("Requested operation 'verify' is not valid for ".concat(this.name, " keys.")); | ||
}); | ||
@@ -113,3 +116,3 @@ }); | ||
return BaseEcdhAlgorithm; | ||
}(BaseEllipticCurveAlgorithm)); | ||
export { BaseEcdhAlgorithm }; | ||
}(base_js_1.BaseEllipticCurveAlgorithm)); | ||
exports.BaseEcdhAlgorithm = BaseEcdhAlgorithm; |
@@ -0,1 +1,2 @@ | ||
"use strict"; | ||
var __extends = (this && this.__extends) || (function () { | ||
@@ -52,5 +53,7 @@ var extendStatics = function (d, b) { | ||
}; | ||
import { InvalidAccessError } from '../errors.js'; | ||
import { BaseEllipticCurveAlgorithm } from './base.js'; | ||
import { checkValidProperty, checkRequiredProperty } from '../../utils-new.js'; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.BaseEcdsaAlgorithm = void 0; | ||
var errors_js_1 = require("../errors.js"); | ||
var base_js_1 = require("./base.js"); | ||
var utils_new_js_1 = require("../../utils-new.js"); | ||
var BaseEcdsaAlgorithm = /** @class */ (function (_super) { | ||
@@ -72,5 +75,5 @@ __extends(BaseEcdsaAlgorithm, _super); | ||
// The algorithm object must contain a hash property. | ||
checkRequiredProperty({ property: 'hash', inObject: algorithm }); | ||
(0, utils_new_js_1.checkRequiredProperty)({ property: 'hash', inObject: algorithm }); | ||
// The hash algorithm specified must be supported by the algorithm implementation processing the operation. | ||
checkValidProperty({ property: algorithm.hash, allowedProperties: this.hashAlgorithms }); | ||
(0, utils_new_js_1.checkValidProperty)({ property: algorithm.hash, allowedProperties: this.hashAlgorithms }); | ||
}; | ||
@@ -80,3 +83,3 @@ BaseEcdsaAlgorithm.prototype.deriveBits = function () { | ||
return __generator(this, function (_a) { | ||
throw new InvalidAccessError("Requested operation 'deriveBits' is not valid for ".concat(this.name, " keys.")); | ||
throw new errors_js_1.InvalidAccessError("Requested operation 'deriveBits' is not valid for ".concat(this.name, " keys.")); | ||
}); | ||
@@ -86,3 +89,3 @@ }); | ||
return BaseEcdsaAlgorithm; | ||
}(BaseEllipticCurveAlgorithm)); | ||
export { BaseEcdsaAlgorithm }; | ||
}(base_js_1.BaseEllipticCurveAlgorithm)); | ||
exports.BaseEcdsaAlgorithm = BaseEcdsaAlgorithm; |
@@ -0,1 +1,2 @@ | ||
"use strict"; | ||
var __extends = (this && this.__extends) || (function () { | ||
@@ -52,4 +53,6 @@ var extendStatics = function (d, b) { | ||
}; | ||
import { InvalidAccessError } from '../errors.js'; | ||
import { BaseEllipticCurveAlgorithm } from './base.js'; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.BaseEdDsaAlgorithm = void 0; | ||
var errors_js_1 = require("../errors.js"); | ||
var base_js_1 = require("./base.js"); | ||
var BaseEdDsaAlgorithm = /** @class */ (function (_super) { | ||
@@ -74,3 +77,3 @@ __extends(BaseEdDsaAlgorithm, _super); | ||
return __generator(this, function (_a) { | ||
throw new InvalidAccessError("Requested operation 'deriveBits' is not valid for ".concat(this.name, " keys.")); | ||
throw new errors_js_1.InvalidAccessError("Requested operation 'deriveBits' is not valid for ".concat(this.name, " keys.")); | ||
}); | ||
@@ -80,3 +83,3 @@ }); | ||
return BaseEdDsaAlgorithm; | ||
}(BaseEllipticCurveAlgorithm)); | ||
export { BaseEdDsaAlgorithm }; | ||
}(base_js_1.BaseEllipticCurveAlgorithm)); | ||
exports.BaseEdDsaAlgorithm = BaseEdDsaAlgorithm; |
@@ -1,4 +0,20 @@ | ||
export * from './base.js'; | ||
export * from './ecdh.js'; | ||
export * from './ecdsa.js'; | ||
export * from './eddsa.js'; | ||
"use strict"; | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
var desc = Object.getOwnPropertyDescriptor(m, k); | ||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { | ||
desc = { enumerable: true, get: function() { return m[k]; } }; | ||
} | ||
Object.defineProperty(o, k2, desc); | ||
}) : (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
o[k2] = m[k]; | ||
})); | ||
var __exportStar = (this && this.__exportStar) || function(m, exports) { | ||
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
__exportStar(require("./base.js"), exports); | ||
__exportStar(require("./ecdh.js"), exports); | ||
__exportStar(require("./ecdsa.js"), exports); | ||
__exportStar(require("./eddsa.js"), exports); |
@@ -0,1 +1,2 @@ | ||
"use strict"; | ||
/** | ||
@@ -33,2 +34,4 @@ * The methods of KeyManager and KeyManagementSystem interfaces return | ||
})(); | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.SyntaxError = exports.OperationError = exports.NotSupportedError = exports.InvalidAccessError = exports.DataError = exports.CryptoError = void 0; | ||
var CryptoError = /** @class */ (function (_super) { | ||
@@ -41,3 +44,3 @@ __extends(CryptoError, _super); | ||
}(Error)); | ||
export { CryptoError }; | ||
exports.CryptoError = CryptoError; | ||
var DataError = /** @class */ (function (_super) { | ||
@@ -50,3 +53,3 @@ __extends(DataError, _super); | ||
}(CryptoError)); | ||
export { DataError }; | ||
exports.DataError = DataError; | ||
var InvalidAccessError = /** @class */ (function (_super) { | ||
@@ -59,3 +62,3 @@ __extends(InvalidAccessError, _super); | ||
}(CryptoError)); | ||
export { InvalidAccessError }; | ||
exports.InvalidAccessError = InvalidAccessError; | ||
var NotSupportedError = /** @class */ (function (_super) { | ||
@@ -68,3 +71,3 @@ __extends(NotSupportedError, _super); | ||
}(CryptoError)); | ||
export { NotSupportedError }; | ||
exports.NotSupportedError = NotSupportedError; | ||
var OperationError = /** @class */ (function (_super) { | ||
@@ -77,3 +80,3 @@ __extends(OperationError, _super); | ||
}(CryptoError)); | ||
export { OperationError }; | ||
exports.OperationError = OperationError; | ||
var SyntaxError = /** @class */ (function (_super) { | ||
@@ -86,2 +89,2 @@ __extends(SyntaxError, _super); | ||
}(CryptoError)); | ||
export { SyntaxError }; | ||
exports.SyntaxError = SyntaxError; |
@@ -1,5 +0,21 @@ | ||
export * from './errors.js'; | ||
export * from './ec/index.js'; | ||
export * from './aes/index.js'; | ||
export * from './crypto-key.js'; | ||
export * from './crypto-algorithm.js'; | ||
"use strict"; | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
var desc = Object.getOwnPropertyDescriptor(m, k); | ||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { | ||
desc = { enumerable: true, get: function() { return m[k]; } }; | ||
} | ||
Object.defineProperty(o, k2, desc); | ||
}) : (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
o[k2] = m[k]; | ||
})); | ||
var __exportStar = (this && this.__exportStar) || function(m, exports) { | ||
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
__exportStar(require("./errors.js"), exports); | ||
__exportStar(require("./ec/index.js"), exports); | ||
__exportStar(require("./aes/index.js"), exports); | ||
__exportStar(require("./crypto-key.js"), exports); | ||
__exportStar(require("./crypto-algorithm.js"), exports); |
@@ -0,1 +1,2 @@ | ||
"use strict"; | ||
var __extends = (this && this.__extends) || (function () { | ||
@@ -52,5 +53,7 @@ var extendStatics = function (d, b) { | ||
}; | ||
import { universalTypeOf } from '@tbd54566975/common'; | ||
import { AesCtr } from '../crypto-primitives/index.js'; | ||
import { BaseAesCtrAlgorithm, CryptoKey } from '../algorithms-api/index.js'; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.AesCtrAlgorithm = void 0; | ||
var common_1 = require("@tbd54566975/common"); | ||
var index_js_1 = require("../crypto-primitives/index.js"); | ||
var index_js_2 = require("../algorithms-api/index.js"); | ||
var AesCtrAlgorithm = /** @class */ (function (_super) { | ||
@@ -69,3 +72,3 @@ __extends(AesCtrAlgorithm, _super); | ||
this.checkKeyUsages({ keyUsages: ['decrypt'], allowedKeyUsages: key.usages }); | ||
plaintext = AesCtr.decrypt({ | ||
plaintext = index_js_1.AesCtr.decrypt({ | ||
counter: algorithm.counter, | ||
@@ -88,3 +91,3 @@ data: data, | ||
this.checkKeyUsages({ keyUsages: ['encrypt'], allowedKeyUsages: key.usages }); | ||
ciphertext = AesCtr.encrypt({ | ||
ciphertext = index_js_1.AesCtr.encrypt({ | ||
counter: algorithm.counter, | ||
@@ -107,9 +110,9 @@ data: data, | ||
this.checkGenerateKey({ algorithm: algorithm, keyUsages: keyUsages }); | ||
return [4 /*yield*/, AesCtr.generateKey({ length: algorithm.length })]; | ||
return [4 /*yield*/, index_js_1.AesCtr.generateKey({ length: algorithm.length })]; | ||
case 1: | ||
secretKey = _a.sent(); | ||
if (universalTypeOf(secretKey) !== 'ArrayBuffer') { | ||
if ((0, common_1.universalTypeOf)(secretKey) !== 'ArrayBuffer') { | ||
throw new Error('Operation failed to generate key.'); | ||
} | ||
secretCryptoKey = new CryptoKey(algorithm, extractable, secretKey, 'secret', this.keyUsages); | ||
secretCryptoKey = new index_js_2.CryptoKey(algorithm, extractable, secretKey, 'secret', this.keyUsages); | ||
return [2 /*return*/, secretCryptoKey]; | ||
@@ -121,3 +124,3 @@ } | ||
return AesCtrAlgorithm; | ||
}(BaseAesCtrAlgorithm)); | ||
export { AesCtrAlgorithm }; | ||
}(index_js_2.BaseAesCtrAlgorithm)); | ||
exports.AesCtrAlgorithm = AesCtrAlgorithm; |
@@ -0,1 +1,2 @@ | ||
"use strict"; | ||
var __extends = (this && this.__extends) || (function () { | ||
@@ -52,5 +53,7 @@ var extendStatics = function (d, b) { | ||
}; | ||
import { isBufferKeyPair } from '../utils-new.js'; | ||
import { Secp256k1, X25519 } from '../crypto-primitives/index.js'; | ||
import { CryptoKey, BaseEcdhAlgorithm, OperationError } from '../algorithms-api/index.js'; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.EcdhAlgorithm = void 0; | ||
var utils_new_js_1 = require("../utils-new.js"); | ||
var index_js_1 = require("../crypto-primitives/index.js"); | ||
var index_js_2 = require("../algorithms-api/index.js"); | ||
var EcdhAlgorithm = /** @class */ (function (_super) { | ||
@@ -85,3 +88,3 @@ __extends(EcdhAlgorithm, _super); | ||
otherPartyPublicKey = algorithm.publicKey.handle; | ||
return [4 /*yield*/, Secp256k1.sharedSecret({ | ||
return [4 /*yield*/, index_js_1.Secp256k1.sharedSecret({ | ||
privateKey: ownPrivateKey, | ||
@@ -96,3 +99,3 @@ publicKey: otherPartyPublicKey | ||
otherPartyPublicKey = algorithm.publicKey.handle; | ||
return [4 /*yield*/, X25519.sharedSecret({ | ||
return [4 /*yield*/, index_js_1.X25519.sharedSecret({ | ||
privateKey: ownPrivateKey, | ||
@@ -111,7 +114,7 @@ publicKey: otherPartyPublicKey | ||
if (length && length % 8 !== 0) | ||
throw new OperationError("To be compatible with all browsers, 'length' must be a multiple of 8."); | ||
throw new index_js_2.OperationError("To be compatible with all browsers, 'length' must be a multiple of 8."); | ||
lengthInBytes = length / 8; | ||
// If length (converted to bytes) is larger than the derived secret, throw. | ||
if (sharedSecret.byteLength < lengthInBytes) | ||
throw new OperationError("Requested 'length' exceeds the byte length of the derived secret."); | ||
throw new index_js_2.OperationError("Requested 'length' exceeds the byte length of the derived secret."); | ||
// Otherwise, either return the secret or a truncated slice. | ||
@@ -143,3 +146,3 @@ return [2 /*return*/, lengthInBytes === sharedSecret.byteLength ? | ||
(_a = (_b = algorithm).compressedPublicKey) !== null && _a !== void 0 ? _a : (_b.compressedPublicKey = true); | ||
return [4 /*yield*/, Secp256k1.generateKeyPair({ | ||
return [4 /*yield*/, index_js_1.Secp256k1.generateKeyPair({ | ||
compressedPublicKey: algorithm.compressedPublicKey | ||
@@ -150,3 +153,3 @@ })]; | ||
return [3 /*break*/, 5]; | ||
case 3: return [4 /*yield*/, X25519.generateKeyPair()]; | ||
case 3: return [4 /*yield*/, index_js_1.X25519.generateKeyPair()]; | ||
case 4: | ||
@@ -156,8 +159,8 @@ keyPair = _d.sent(); | ||
case 5: | ||
if (!isBufferKeyPair(keyPair)) { | ||
if (!(0, utils_new_js_1.isBufferKeyPair)(keyPair)) { | ||
throw new Error('Operation failed to generate key pair.'); | ||
} | ||
cryptoKeyPair = { | ||
privateKey: new CryptoKey(algorithm, extractable, keyPair.privateKey, 'private', this.keyUsages.privateKey), | ||
publicKey: new CryptoKey(algorithm, true, keyPair.publicKey, 'public', this.keyUsages.publicKey) | ||
privateKey: new index_js_2.CryptoKey(algorithm, extractable, keyPair.privateKey, 'private', this.keyUsages.privateKey), | ||
publicKey: new index_js_2.CryptoKey(algorithm, true, keyPair.publicKey, 'public', this.keyUsages.publicKey) | ||
}; | ||
@@ -170,3 +173,3 @@ return [2 /*return*/, cryptoKeyPair]; | ||
return EcdhAlgorithm; | ||
}(BaseEcdhAlgorithm)); | ||
export { EcdhAlgorithm }; | ||
}(index_js_2.BaseEcdhAlgorithm)); | ||
exports.EcdhAlgorithm = EcdhAlgorithm; |
@@ -0,1 +1,2 @@ | ||
"use strict"; | ||
var __extends = (this && this.__extends) || (function () { | ||
@@ -52,5 +53,7 @@ var extendStatics = function (d, b) { | ||
}; | ||
import { isBufferKeyPair } from '../utils-new.js'; | ||
import { Secp256k1 } from '../crypto-primitives/index.js'; | ||
import { CryptoKey, BaseEcdsaAlgorithm } from '../algorithms-api/index.js'; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.EcdsaAlgorithm = void 0; | ||
var utils_new_js_1 = require("../utils-new.js"); | ||
var index_js_1 = require("../crypto-primitives/index.js"); | ||
var index_js_2 = require("../algorithms-api/index.js"); | ||
var EcdsaAlgorithm = /** @class */ (function (_super) { | ||
@@ -80,3 +83,3 @@ __extends(EcdsaAlgorithm, _super); | ||
(_a = algorithm.compressedPublicKey) !== null && _a !== void 0 ? _a : (algorithm.compressedPublicKey = true); | ||
return [4 /*yield*/, Secp256k1.generateKeyPair({ compressedPublicKey: algorithm.compressedPublicKey })]; | ||
return [4 /*yield*/, index_js_1.Secp256k1.generateKeyPair({ compressedPublicKey: algorithm.compressedPublicKey })]; | ||
case 2: | ||
@@ -86,8 +89,8 @@ keyPair = _c.sent(); | ||
case 3: | ||
if (!isBufferKeyPair(keyPair)) { | ||
if (!(0, utils_new_js_1.isBufferKeyPair)(keyPair)) { | ||
throw new Error('Operation failed to generate key pair.'); | ||
} | ||
cryptoKeyPair = { | ||
privateKey: new CryptoKey(algorithm, extractable, keyPair.privateKey, 'private', this.keyUsages.privateKey), | ||
publicKey: new CryptoKey(algorithm, true, keyPair.publicKey, 'public', this.keyUsages.publicKey) | ||
privateKey: new index_js_2.CryptoKey(algorithm, extractable, keyPair.privateKey, 'private', this.keyUsages.privateKey), | ||
publicKey: new index_js_2.CryptoKey(algorithm, true, keyPair.publicKey, 'public', this.keyUsages.publicKey) | ||
}; | ||
@@ -119,3 +122,3 @@ return [2 /*return*/, cryptoKeyPair]; | ||
return [3 /*break*/, 3]; | ||
case 1: return [4 /*yield*/, Secp256k1.sign({ hash: algorithm.hash, key: key.handle, data: data })]; | ||
case 1: return [4 /*yield*/, index_js_1.Secp256k1.sign({ hash: algorithm.hash, key: key.handle, data: data })]; | ||
case 2: | ||
@@ -150,3 +153,3 @@ signature = _b.sent(); | ||
return [3 /*break*/, 3]; | ||
case 1: return [4 /*yield*/, Secp256k1.verify({ hash: algorithm.hash, key: key.handle, signature: signature, data: data })]; | ||
case 1: return [4 /*yield*/, index_js_1.Secp256k1.verify({ hash: algorithm.hash, key: key.handle, signature: signature, data: data })]; | ||
case 2: | ||
@@ -162,3 +165,3 @@ isValid = _b.sent(); | ||
return EcdsaAlgorithm; | ||
}(BaseEcdsaAlgorithm)); | ||
export { EcdsaAlgorithm }; | ||
}(index_js_2.BaseEcdsaAlgorithm)); | ||
exports.EcdsaAlgorithm = EcdsaAlgorithm; |
@@ -0,1 +1,2 @@ | ||
"use strict"; | ||
var __extends = (this && this.__extends) || (function () { | ||
@@ -52,5 +53,7 @@ var extendStatics = function (d, b) { | ||
}; | ||
import { isBufferKeyPair } from '../utils-new.js'; | ||
import { Ed25519 } from '../crypto-primitives/index.js'; | ||
import { CryptoKey, BaseEdDsaAlgorithm } from '../algorithms-api/index.js'; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.EdDsaAlgorithm = void 0; | ||
var utils_new_js_1 = require("../utils-new.js"); | ||
var index_js_1 = require("../crypto-primitives/index.js"); | ||
var index_js_2 = require("../algorithms-api/index.js"); | ||
var EdDsaAlgorithm = /** @class */ (function (_super) { | ||
@@ -76,3 +79,3 @@ __extends(EdDsaAlgorithm, _super); | ||
return [3 /*break*/, 3]; | ||
case 1: return [4 /*yield*/, Ed25519.generateKeyPair()]; | ||
case 1: return [4 /*yield*/, index_js_1.Ed25519.generateKeyPair()]; | ||
case 2: | ||
@@ -82,8 +85,8 @@ keyPair = _b.sent(); | ||
case 3: | ||
if (!isBufferKeyPair(keyPair)) { | ||
if (!(0, utils_new_js_1.isBufferKeyPair)(keyPair)) { | ||
throw new Error('Operation failed to generate key pair.'); | ||
} | ||
cryptoKeyPair = { | ||
privateKey: new CryptoKey(algorithm, extractable, keyPair.privateKey, 'private', this.keyUsages.privateKey), | ||
publicKey: new CryptoKey(algorithm, true, keyPair.publicKey, 'public', this.keyUsages.publicKey) | ||
privateKey: new index_js_2.CryptoKey(algorithm, extractable, keyPair.privateKey, 'private', this.keyUsages.privateKey), | ||
publicKey: new index_js_2.CryptoKey(algorithm, true, keyPair.publicKey, 'public', this.keyUsages.publicKey) | ||
}; | ||
@@ -115,3 +118,3 @@ return [2 /*return*/, cryptoKeyPair]; | ||
return [3 /*break*/, 3]; | ||
case 1: return [4 /*yield*/, Ed25519.sign({ key: key.handle, data: data })]; | ||
case 1: return [4 /*yield*/, index_js_1.Ed25519.sign({ key: key.handle, data: data })]; | ||
case 2: | ||
@@ -146,3 +149,3 @@ signature = _b.sent(); | ||
return [3 /*break*/, 3]; | ||
case 1: return [4 /*yield*/, Ed25519.verify({ key: key.handle, signature: signature, data: data })]; | ||
case 1: return [4 /*yield*/, index_js_1.Ed25519.verify({ key: key.handle, signature: signature, data: data })]; | ||
case 2: | ||
@@ -158,3 +161,3 @@ isValid = _b.sent(); | ||
return EdDsaAlgorithm; | ||
}(BaseEdDsaAlgorithm)); | ||
export { EdDsaAlgorithm }; | ||
}(index_js_2.BaseEdDsaAlgorithm)); | ||
exports.EdDsaAlgorithm = EdDsaAlgorithm; |
@@ -1,4 +0,20 @@ | ||
export * from './ecdh.js'; | ||
export * from './ecdsa.js'; | ||
export * from './eddsa.js'; | ||
export * from './aes-ctr.js'; | ||
"use strict"; | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
var desc = Object.getOwnPropertyDescriptor(m, k); | ||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { | ||
desc = { enumerable: true, get: function() { return m[k]; } }; | ||
} | ||
Object.defineProperty(o, k2, desc); | ||
}) : (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
o[k2] = m[k]; | ||
})); | ||
var __exportStar = (this && this.__exportStar) || function(m, exports) { | ||
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
__exportStar(require("./ecdh.js"), exports); | ||
__exportStar(require("./ecdsa.js"), exports); | ||
__exportStar(require("./eddsa.js"), exports); | ||
__exportStar(require("./aes-ctr.js"), exports); |
@@ -0,1 +1,2 @@ | ||
"use strict"; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
@@ -37,3 +38,5 @@ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
}; | ||
import { crypto } from '@noble/hashes/crypto'; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.AesCtr = void 0; | ||
var crypto_1 = require("@noble/hashes/crypto"); | ||
/** | ||
@@ -92,3 +95,3 @@ * The `AesCtr` class provides an interface for AES-CTR | ||
webCryptoKey = _a.sent(); | ||
return [4 /*yield*/, crypto.subtle.decrypt({ name: 'AES-CTR', counter: counter, length: length }, webCryptoKey, data)]; | ||
return [4 /*yield*/, crypto_1.crypto.subtle.decrypt({ name: 'AES-CTR', counter: counter, length: length }, webCryptoKey, data)]; | ||
case 2: | ||
@@ -121,3 +124,3 @@ ciphertext = _a.sent(); | ||
webCryptoKey = _a.sent(); | ||
return [4 /*yield*/, crypto.subtle.encrypt({ name: 'AES-CTR', counter: counter, length: length }, webCryptoKey, data)]; | ||
return [4 /*yield*/, crypto_1.crypto.subtle.encrypt({ name: 'AES-CTR', counter: counter, length: length }, webCryptoKey, data)]; | ||
case 2: | ||
@@ -142,3 +145,3 @@ plaintext = _a.sent(); | ||
lengthInBytes = length / 8; | ||
secretKey = crypto.getRandomValues(new Uint8Array(lengthInBytes)); | ||
secretKey = crypto_1.crypto.getRandomValues(new Uint8Array(lengthInBytes)); | ||
return [2 /*return*/, secretKey.buffer]; | ||
@@ -157,3 +160,3 @@ }); | ||
return __generator(this, function (_a) { | ||
return [2 /*return*/, crypto.subtle.importKey('raw', key, { name: 'AES-CTR', length: key.byteLength * 8 }, true, ['encrypt', 'decrypt'])]; | ||
return [2 /*return*/, crypto_1.crypto.subtle.importKey('raw', key, { name: 'AES-CTR', length: key.byteLength * 8 }, true, ['encrypt', 'decrypt'])]; | ||
}); | ||
@@ -164,2 +167,2 @@ }); | ||
}()); | ||
export { AesCtr }; | ||
exports.AesCtr = AesCtr; |
@@ -0,1 +1,2 @@ | ||
"use strict"; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
@@ -37,3 +38,5 @@ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
}; | ||
import { crypto } from '@noble/hashes/crypto'; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.AesGcm = void 0; | ||
var crypto_1 = require("@noble/hashes/crypto"); | ||
/** | ||
@@ -97,3 +100,3 @@ * The `AesGcm` class provides an interface for AES-GCM | ||
: { name: 'AES-GCM', additionalData: additionalData, iv: iv, tagLength: tagLength }; | ||
return [4 /*yield*/, crypto.subtle.decrypt(algorithm, webCryptoKey, data)]; | ||
return [4 /*yield*/, crypto_1.crypto.subtle.decrypt(algorithm, webCryptoKey, data)]; | ||
case 2: | ||
@@ -130,3 +133,3 @@ ciphertext = _a.sent(); | ||
: { name: 'AES-GCM', additionalData: additionalData, iv: iv, tagLength: tagLength }; | ||
return [4 /*yield*/, crypto.subtle.encrypt(algorithm, webCryptoKey, data)]; | ||
return [4 /*yield*/, crypto_1.crypto.subtle.encrypt(algorithm, webCryptoKey, data)]; | ||
case 2: | ||
@@ -151,3 +154,3 @@ plaintext = _a.sent(); | ||
lengthInBytes = length / 8; | ||
secretKey = crypto.getRandomValues(new Uint8Array(lengthInBytes)); | ||
secretKey = crypto_1.crypto.getRandomValues(new Uint8Array(lengthInBytes)); | ||
return [2 /*return*/, secretKey.buffer]; | ||
@@ -166,3 +169,3 @@ }); | ||
return __generator(this, function (_a) { | ||
return [2 /*return*/, crypto.subtle.importKey('raw', key, { name: 'AES-GCM', length: key.byteLength * 8 }, true, ['encrypt', 'decrypt'])]; | ||
return [2 /*return*/, crypto_1.crypto.subtle.importKey('raw', key, { name: 'AES-GCM', length: key.byteLength * 8 }, true, ['encrypt', 'decrypt'])]; | ||
}); | ||
@@ -173,2 +176,2 @@ }); | ||
}()); | ||
export { AesGcm }; | ||
exports.AesGcm = AesGcm; |
@@ -0,1 +1,2 @@ | ||
"use strict"; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
@@ -37,6 +38,8 @@ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
}; | ||
import { sha256 } from '@noble/hashes/sha256'; | ||
import { concatBytes } from '@noble/hashes/utils'; | ||
import { Convert, universalTypeOf } from '@tbd54566975/common'; | ||
import { NotSupportedError } from '../algorithms-api/errors.js'; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.ConcatKdf = void 0; | ||
var sha256_1 = require("@noble/hashes/sha256"); | ||
var utils_1 = require("@noble/hashes/utils"); | ||
var common_1 = require("@tbd54566975/common"); | ||
var errors_js_1 = require("../algorithms-api/errors.js"); | ||
/** | ||
@@ -95,3 +98,3 @@ * An implementation of the Concatenation Key Derivation Function (ConcatKDF) | ||
if (roundCount !== 1) { | ||
throw new NotSupportedError("Concat KDF with ".concat(roundCount, " rounds not supported.")); | ||
throw new errors_js_1.NotSupportedError("Concat KDF with ".concat(roundCount, " rounds not supported.")); | ||
} | ||
@@ -102,3 +105,3 @@ counter = new Uint8Array(4); | ||
otherInfo = ConcatKdf.computeOtherInfo(options.otherInfo); | ||
derivedKeyingMaterial = sha256(concatBytes(counter, sharedSecretU8A, otherInfo)); | ||
derivedKeyingMaterial = (0, sha256_1.sha256)((0, utils_1.concatBytes)(counter, sharedSecretU8A, otherInfo)); | ||
// Return the bit string of derived keying material of length keyDataLen bits. | ||
@@ -137,3 +140,3 @@ return [2 /*return*/, derivedKeyingMaterial.buffer.slice(0, keyDataLen / 8)]; | ||
// Concatenate AlgorithmID || PartyUInfo || PartyVInfo || SuppPubInfo || SuppPrivInfo. | ||
var otherInfo = concatBytes(algorithmId, partyUInfo, partyVInfo, suppPubInfo, suppPrivInfo); | ||
var otherInfo = (0, utils_1.concatBytes)(algorithmId, partyUInfo, partyVInfo, suppPubInfo, suppPrivInfo); | ||
return otherInfo; | ||
@@ -163,3 +166,3 @@ }; | ||
var encodedData; | ||
var dataType = universalTypeOf(data); | ||
var dataType = (0, common_1.universalTypeOf)(data); | ||
// Return an emtpy octet sequence if data is not specified. | ||
@@ -172,3 +175,3 @@ if (dataType === 'Undefined') { | ||
? data | ||
: new Convert(data, dataType).toUint8Array(); | ||
: new common_1.Convert(data, dataType).toUint8Array(); | ||
var bufferLength = dataU8A.length; | ||
@@ -190,2 +193,2 @@ encodedData = new Uint8Array(4 + bufferLength); | ||
}()); | ||
export { ConcatKdf }; | ||
exports.ConcatKdf = ConcatKdf; |
@@ -0,1 +1,2 @@ | ||
"use strict"; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
@@ -37,4 +38,6 @@ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
}; | ||
import { Convert } from '@tbd54566975/common'; | ||
import { ed25519 } from '@noble/curves/ed25519'; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.Ed25519 = void 0; | ||
var common_1 = require("@tbd54566975/common"); | ||
var ed25519_1 = require("@noble/curves/ed25519"); | ||
/** | ||
@@ -79,4 +82,4 @@ * The `Ed25519` class provides an interface for generating Ed25519 key pairs, | ||
return __generator(this, function (_a) { | ||
privateKey = ed25519.utils.randomPrivateKey(); | ||
publicKey = ed25519.getPublicKey(privateKey); | ||
privateKey = ed25519_1.ed25519.utils.randomPrivateKey(); | ||
publicKey = ed25519_1.ed25519.getPublicKey(privateKey); | ||
keyPair = { | ||
@@ -102,4 +105,4 @@ privateKey: privateKey.buffer, | ||
privateKey = options.privateKey; | ||
privateKeyU8A = Convert.arrayBuffer(privateKey).toUint8Array(); | ||
publicKey = ed25519.getPublicKey(privateKeyU8A); | ||
privateKeyU8A = common_1.Convert.arrayBuffer(privateKey).toUint8Array(); | ||
publicKey = ed25519_1.ed25519.getPublicKey(privateKeyU8A); | ||
return [2 /*return*/, publicKey]; | ||
@@ -122,5 +125,5 @@ }); | ||
key = options.key, data = options.data; | ||
dataU8A = Convert.bufferSource(data).toUint8Array(); | ||
privateKeyU8A = Convert.arrayBuffer(key).toUint8Array(); | ||
signatureU8A = ed25519.sign(dataU8A, privateKeyU8A); | ||
dataU8A = common_1.Convert.bufferSource(data).toUint8Array(); | ||
privateKeyU8A = common_1.Convert.arrayBuffer(key).toUint8Array(); | ||
signatureU8A = ed25519_1.ed25519.sign(dataU8A, privateKeyU8A); | ||
return [2 /*return*/, signatureU8A.buffer]; | ||
@@ -144,6 +147,6 @@ }); | ||
key = options.key, signature = options.signature, data = options.data; | ||
publicKeyU8A = Convert.arrayBuffer(key).toUint8Array(); | ||
signatureU8A = Convert.arrayBuffer(signature).toUint8Array(); | ||
dataU8A = Convert.bufferSource(data).toUint8Array(); | ||
isValid = ed25519.verify(signatureU8A, dataU8A, publicKeyU8A); | ||
publicKeyU8A = common_1.Convert.arrayBuffer(key).toUint8Array(); | ||
signatureU8A = common_1.Convert.arrayBuffer(signature).toUint8Array(); | ||
dataU8A = common_1.Convert.bufferSource(data).toUint8Array(); | ||
isValid = ed25519_1.ed25519.verify(signatureU8A, dataU8A, publicKeyU8A); | ||
return [2 /*return*/, isValid]; | ||
@@ -155,2 +158,2 @@ }); | ||
}()); | ||
export { Ed25519 }; | ||
exports.Ed25519 = Ed25519; |
@@ -1,7 +0,23 @@ | ||
export * from './x25519.js'; | ||
export * from './aes-ctr.js'; | ||
export * from './aes-gcm.js'; | ||
export * from './ed25519.js'; | ||
export * from './secp256k1.js'; | ||
export * from './xchacha20.js'; | ||
export * from './concat-kdf.js'; | ||
"use strict"; | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
var desc = Object.getOwnPropertyDescriptor(m, k); | ||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { | ||
desc = { enumerable: true, get: function() { return m[k]; } }; | ||
} | ||
Object.defineProperty(o, k2, desc); | ||
}) : (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
o[k2] = m[k]; | ||
})); | ||
var __exportStar = (this && this.__exportStar) || function(m, exports) { | ||
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
__exportStar(require("./x25519.js"), exports); | ||
__exportStar(require("./aes-ctr.js"), exports); | ||
__exportStar(require("./aes-gcm.js"), exports); | ||
__exportStar(require("./ed25519.js"), exports); | ||
__exportStar(require("./secp256k1.js"), exports); | ||
__exportStar(require("./xchacha20.js"), exports); | ||
__exportStar(require("./concat-kdf.js"), exports); |
@@ -0,1 +1,2 @@ | ||
"use strict"; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
@@ -37,5 +38,7 @@ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
}; | ||
import { Convert } from '@tbd54566975/common'; | ||
import { sha256 } from '@noble/hashes/sha256'; | ||
import { secp256k1 } from '@noble/curves/secp256k1'; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.Secp256k1 = void 0; | ||
var common_1 = require("@tbd54566975/common"); | ||
var sha256_1 = require("@noble/hashes/sha256"); | ||
var secp256k1_1 = require("@noble/curves/secp256k1"); | ||
/** | ||
@@ -73,3 +76,3 @@ * The `Secp256k1` class provides an interface for generating secp256k1 key pairs, | ||
*/ | ||
export var Secp256k1 = /** @class */ (function () { | ||
var Secp256k1 = exports.Secp256k1 = /** @class */ (function () { | ||
function Secp256k1() { | ||
@@ -90,4 +93,4 @@ } | ||
compressedPublicKey !== null && compressedPublicKey !== void 0 ? compressedPublicKey : (compressedPublicKey = true); // Default to compressed public key, matching the default of @noble/secp256k1. | ||
privateKey = secp256k1.utils.randomPrivateKey(); | ||
publicKey = secp256k1.getPublicKey(privateKey, compressedPublicKey); | ||
privateKey = secp256k1_1.secp256k1.utils.randomPrivateKey(); | ||
publicKey = secp256k1_1.secp256k1.getPublicKey(privateKey, compressedPublicKey); | ||
keyPair = { | ||
@@ -117,4 +120,4 @@ privateKey: privateKey.buffer, | ||
compressedPublicKey !== null && compressedPublicKey !== void 0 ? compressedPublicKey : (compressedPublicKey = true); // Default to compressed public key, matching the default of @noble/secp256k1. | ||
privateKeyU8A = Convert.arrayBuffer(privateKey).toUint8Array(); | ||
publicKey = secp256k1.getPublicKey(privateKeyU8A, compressedPublicKey); | ||
privateKeyU8A = common_1.Convert.arrayBuffer(privateKey).toUint8Array(); | ||
publicKey = secp256k1_1.secp256k1.getPublicKey(privateKeyU8A, compressedPublicKey); | ||
return [2 /*return*/, publicKey]; | ||
@@ -143,5 +146,5 @@ }); | ||
privateKey = options.privateKey, publicKey = options.publicKey; | ||
privateKeyU8A = Convert.arrayBuffer(privateKey).toUint8Array(); | ||
publicKeyU8A = Convert.arrayBuffer(publicKey).toUint8Array(); | ||
sharedSecret = secp256k1.getSharedSecret(privateKeyU8A, publicKeyU8A); | ||
privateKeyU8A = common_1.Convert.arrayBuffer(privateKey).toUint8Array(); | ||
publicKeyU8A = common_1.Convert.arrayBuffer(publicKey).toUint8Array(); | ||
sharedSecret = secp256k1_1.secp256k1.getSharedSecret(privateKeyU8A, publicKeyU8A); | ||
// Remove the leading byte that indicates the sign of the y-coordinate | ||
@@ -167,7 +170,7 @@ // of the point on the elliptic curve. See note above. | ||
data = options.data, hash = options.hash, key = options.key; | ||
dataU8A = Convert.bufferSource(data).toUint8Array(); | ||
dataU8A = common_1.Convert.bufferSource(data).toUint8Array(); | ||
hashFunction = this.hashAlgorithms[hash]; | ||
digest = hashFunction(dataU8A); | ||
privateKeyU8A = Convert.arrayBuffer(key).toUint8Array(); | ||
signatureObject = secp256k1.sign(digest, privateKeyU8A); | ||
privateKeyU8A = common_1.Convert.arrayBuffer(key).toUint8Array(); | ||
signatureObject = secp256k1_1.secp256k1.sign(digest, privateKeyU8A); | ||
signatureU8A = signatureObject.toCompactRawBytes(); | ||
@@ -193,8 +196,8 @@ return [2 /*return*/, signatureU8A.buffer]; | ||
data = options.data, hash = options.hash, key = options.key, signature = options.signature; | ||
publicKeyU8A = Convert.arrayBuffer(key).toUint8Array(); | ||
signatureU8A = Convert.arrayBuffer(signature).toUint8Array(); | ||
dataU8A = Convert.bufferSource(data).toUint8Array(); | ||
publicKeyU8A = common_1.Convert.arrayBuffer(key).toUint8Array(); | ||
signatureU8A = common_1.Convert.arrayBuffer(signature).toUint8Array(); | ||
dataU8A = common_1.Convert.bufferSource(data).toUint8Array(); | ||
hashFunction = this.hashAlgorithms[hash]; | ||
digest = hashFunction(dataU8A); | ||
isValid = secp256k1.verify(signatureU8A, digest, publicKeyU8A); | ||
isValid = secp256k1_1.secp256k1.verify(signatureU8A, digest, publicKeyU8A); | ||
return [2 /*return*/, isValid]; | ||
@@ -210,5 +213,5 @@ }); | ||
Secp256k1.hashAlgorithms = { | ||
'SHA-256': sha256 | ||
'SHA-256': sha256_1.sha256 | ||
}; | ||
return Secp256k1; | ||
}()); |
@@ -0,1 +1,2 @@ | ||
"use strict"; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
@@ -37,4 +38,6 @@ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
}; | ||
import { Convert } from '@tbd54566975/common'; | ||
import { x25519 } from '@noble/curves/ed25519'; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.X25519 = void 0; | ||
var common_1 = require("@tbd54566975/common"); | ||
var ed25519_1 = require("@noble/curves/ed25519"); | ||
/** | ||
@@ -72,4 +75,4 @@ * The `X25519` class provides an interface for X25519 (Curve25519) key pair | ||
return __generator(this, function (_a) { | ||
privateKey = x25519.utils.randomPrivateKey(); | ||
publicKey = x25519.getPublicKey(privateKey); | ||
privateKey = ed25519_1.x25519.utils.randomPrivateKey(); | ||
publicKey = ed25519_1.x25519.getPublicKey(privateKey); | ||
keyPair = { | ||
@@ -95,4 +98,4 @@ privateKey: privateKey.buffer, | ||
privateKey = options.privateKey; | ||
privateKeyU8A = Convert.arrayBuffer(privateKey).toUint8Array(); | ||
publicKey = x25519.getPublicKey(privateKeyU8A); | ||
privateKeyU8A = common_1.Convert.arrayBuffer(privateKey).toUint8Array(); | ||
publicKey = ed25519_1.x25519.getPublicKey(privateKeyU8A); | ||
return [2 /*return*/, publicKey]; | ||
@@ -116,5 +119,5 @@ }); | ||
privateKey = options.privateKey, publicKey = options.publicKey; | ||
privateKeyU8A = Convert.arrayBuffer(privateKey).toUint8Array(); | ||
publicKeyU8A = Convert.arrayBuffer(publicKey).toUint8Array(); | ||
sharedSecret = x25519.getSharedSecret(privateKeyU8A, publicKeyU8A); | ||
privateKeyU8A = common_1.Convert.arrayBuffer(privateKey).toUint8Array(); | ||
publicKeyU8A = common_1.Convert.arrayBuffer(publicKey).toUint8Array(); | ||
sharedSecret = ed25519_1.x25519.getSharedSecret(privateKeyU8A, publicKeyU8A); | ||
return [2 /*return*/, sharedSecret.buffer]; | ||
@@ -126,2 +129,2 @@ }); | ||
}()); | ||
export { X25519 }; | ||
exports.X25519 = X25519; |
@@ -0,1 +1,2 @@ | ||
"use strict"; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
@@ -37,4 +38,6 @@ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
}; | ||
import { Convert } from '@tbd54566975/common'; | ||
import { xchacha20 } from '@noble/ciphers/chacha'; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.XChaCha20 = void 0; | ||
var common_1 = require("@tbd54566975/common"); | ||
var chacha_1 = require("@noble/ciphers/chacha"); | ||
var XChaCha20 = /** @class */ (function () { | ||
@@ -48,6 +51,6 @@ function XChaCha20() { | ||
data = options.data, key = options.key, nonce = options.nonce; | ||
dataU8A = Convert.bufferSource(data).toUint8Array(); | ||
keyU8A = Convert.arrayBuffer(key).toUint8Array(); | ||
nonceU8A = Convert.bufferSource(nonce).toUint8Array(); | ||
ciphertext = xchacha20(keyU8A, nonceU8A, dataU8A); | ||
dataU8A = common_1.Convert.bufferSource(data).toUint8Array(); | ||
keyU8A = common_1.Convert.arrayBuffer(key).toUint8Array(); | ||
nonceU8A = common_1.Convert.bufferSource(nonce).toUint8Array(); | ||
ciphertext = (0, chacha_1.xchacha20)(keyU8A, nonceU8A, dataU8A); | ||
return [2 /*return*/, ciphertext.buffer]; | ||
@@ -62,6 +65,6 @@ }); | ||
data = options.data, key = options.key, nonce = options.nonce; | ||
dataU8A = Convert.bufferSource(data).toUint8Array(); | ||
keyU8A = Convert.arrayBuffer(key).toUint8Array(); | ||
nonceU8A = Convert.bufferSource(nonce).toUint8Array(); | ||
plaintext = xchacha20(keyU8A, nonceU8A, dataU8A); | ||
dataU8A = common_1.Convert.bufferSource(data).toUint8Array(); | ||
keyU8A = common_1.Convert.arrayBuffer(key).toUint8Array(); | ||
nonceU8A = common_1.Convert.bufferSource(nonce).toUint8Array(); | ||
plaintext = (0, chacha_1.xchacha20)(keyU8A, nonceU8A, dataU8A); | ||
return [2 /*return*/, plaintext.buffer]; | ||
@@ -82,2 +85,2 @@ }); | ||
}()); | ||
export { XChaCha20 }; | ||
exports.XChaCha20 = XChaCha20; |
@@ -0,1 +1,2 @@ | ||
"use strict"; | ||
var __assign = (this && this.__assign) || function () { | ||
@@ -48,14 +49,20 @@ __assign = Object.assign || function(t) { | ||
}; | ||
import nacl from 'tweetnacl'; | ||
import ed2curve from 'ed2curve'; | ||
import { Convert } from '@tbd54566975/common'; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.verify = exports.sign = exports.keyPairToJwk = exports.deriveX25519KeyPair = exports.generateKeyPair = void 0; | ||
var tweetnacl_1 = __importDefault(require("tweetnacl")); | ||
var ed2curve_1 = __importDefault(require("ed2curve")); | ||
var common_1 = require("@tbd54566975/common"); | ||
// TODO: (not important) decide if we want to use tweetnacl or @noble/ed25519. is there a functional difference? | ||
// dwn-sdk-js also has ed25519 cryptosuite stuff | ||
export function generateKeyPair() { | ||
var ed25519KeyPair = nacl.sign.keyPair(); | ||
function generateKeyPair() { | ||
var ed25519KeyPair = tweetnacl_1.default.sign.keyPair(); | ||
return { publicKey: ed25519KeyPair.publicKey, privateKey: ed25519KeyPair.secretKey }; | ||
} | ||
export function deriveX25519KeyPair(ed25519KeyPair) { | ||
exports.generateKeyPair = generateKeyPair; | ||
function deriveX25519KeyPair(ed25519KeyPair) { | ||
// for some reason tweetnacl chose the term `secretKey` instead of `privateKey` even though ed25519 is asymmetric | ||
var x25519KeyPair = ed2curve.convertKeyPair({ publicKey: ed25519KeyPair.publicKey, secretKey: ed25519KeyPair.privateKey }); | ||
var x25519KeyPair = ed2curve_1.default.convertKeyPair({ publicKey: ed25519KeyPair.publicKey, secretKey: ed25519KeyPair.privateKey }); | ||
// apparently the return value of `convertKeyPair` can return null | ||
@@ -67,21 +74,24 @@ if (!x25519KeyPair) { | ||
} | ||
export function keyPairToJwk(keyPair, kid, overrides) { | ||
exports.deriveX25519KeyPair = deriveX25519KeyPair; | ||
function keyPairToJwk(keyPair, kid, overrides) { | ||
if (overrides === void 0) { overrides = { crv: 'Ed25519' }; } | ||
var jwk = { kty: 'OKP', crv: overrides.crv, kid: kid }; | ||
var encodedPublicKey = Convert.uint8Array(keyPair.publicKey).toBase64Url(); | ||
var encodedPublicKey = common_1.Convert.uint8Array(keyPair.publicKey).toBase64Url(); | ||
var publicKeyJwk = __assign(__assign({}, jwk), { x: encodedPublicKey }); | ||
var encodedSecretKey = Convert.uint8Array(keyPair.privateKey).toBase64Url(); | ||
var encodedSecretKey = common_1.Convert.uint8Array(keyPair.privateKey).toBase64Url(); | ||
var privateKeyJwk = __assign(__assign({}, publicKeyJwk), { d: encodedSecretKey }); | ||
return { publicKeyJwk: publicKeyJwk, privateKeyJwk: privateKeyJwk }; | ||
} | ||
export function sign(options) { | ||
exports.keyPairToJwk = keyPairToJwk; | ||
function sign(options) { | ||
var payload = options.payload, privateKeyJwk = options.privateKeyJwk; | ||
var privateKeyBytes = Convert.base64Url(privateKeyJwk.d).toUint8Array(); | ||
var privateKeyBytes = common_1.Convert.base64Url(privateKeyJwk.d).toUint8Array(); | ||
if (privateKeyJwk.crv !== 'Ed25519') { | ||
throw new Error('crv must be Ed25519'); | ||
} | ||
var signedData = nacl.sign(payload, privateKeyBytes); | ||
return signedData.slice(0, nacl.sign.signatureLength); | ||
var signedData = tweetnacl_1.default.sign(payload, privateKeyBytes); | ||
return signedData.slice(0, tweetnacl_1.default.sign.signatureLength); | ||
} | ||
export function verify(options) { | ||
exports.sign = sign; | ||
function verify(options) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
@@ -91,3 +101,3 @@ var signature, payload, publicKeyJwk, publicKeyBytes, signedData, result; | ||
signature = options.signature, payload = options.payload, publicKeyJwk = options.publicKeyJwk; | ||
publicKeyBytes = Convert.base64Url(publicKeyJwk.x).toUint8Array(); | ||
publicKeyBytes = common_1.Convert.base64Url(publicKeyJwk.x).toUint8Array(); | ||
if (publicKeyJwk.crv !== 'Ed25519') { | ||
@@ -99,3 +109,3 @@ throw new Error('crv must be Ed25519'); | ||
signedData.set(payload, signature.length); | ||
result = nacl.sign.open(signedData, publicKeyBytes); | ||
result = tweetnacl_1.default.sign.open(signedData, publicKeyBytes); | ||
return [2 /*return*/, !!result]; | ||
@@ -105,1 +115,2 @@ }); | ||
} | ||
exports.verify = verify; |
@@ -1,2 +0,18 @@ | ||
export * from './key-store.js'; | ||
export * from './key-manager.js'; | ||
"use strict"; | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
var desc = Object.getOwnPropertyDescriptor(m, k); | ||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { | ||
desc = { enumerable: true, get: function() { return m[k]; } }; | ||
} | ||
Object.defineProperty(o, k2, desc); | ||
}) : (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
o[k2] = m[k]; | ||
})); | ||
var __exportStar = (this && this.__exportStar) || function(m, exports) { | ||
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
__exportStar(require("./key-store.js"), exports); | ||
__exportStar(require("./key-manager.js"), exports); |
@@ -0,1 +1,2 @@ | ||
"use strict"; | ||
var __assign = (this && this.__assign) || function () { | ||
@@ -59,5 +60,7 @@ __assign = Object.assign || function(t) { | ||
}; | ||
import { MemoryStore } from '@tbd54566975/common'; | ||
import { LocalKms, KmsKeyStore, KmsPrivateKeyStore } from '../kms-local/index.js'; | ||
import { checkRequiredProperty, isManagedKey, isManagedKeyPair } from '../utils-new.js'; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.KeyManager = void 0; | ||
var common_1 = require("@tbd54566975/common"); | ||
var index_js_1 = require("../kms-local/index.js"); | ||
var utils_new_js_1 = require("../utils-new.js"); | ||
/** | ||
@@ -82,3 +85,3 @@ * KeyManager | ||
var _a; | ||
checkRequiredProperty({ property: 'store', inObject: options }); | ||
(0, utils_new_js_1.checkRequiredProperty)({ property: 'store', inObject: options }); | ||
this.keyStore = options.store; | ||
@@ -98,3 +101,3 @@ (_a = options.kms) !== null && _a !== void 0 ? _a : (options.kms = this.useLocalKms()); | ||
key = _a.sent(); | ||
if (!isManagedKey(key)) { | ||
if (!(0, utils_new_js_1.isManagedKey)(key)) { | ||
throw new Error("Key not found: '".concat(keyRef, "'.")); | ||
@@ -123,3 +126,3 @@ } | ||
ownKeyPair = _a.sent(); | ||
if (!isManagedKeyPair(ownKeyPair)) { | ||
if (!(0, utils_new_js_1.isManagedKeyPair)(ownKeyPair)) { | ||
throw new Error("Key not found: '".concat(baseKeyRef, "'.")); | ||
@@ -146,3 +149,3 @@ } | ||
key = _a.sent(); | ||
if (!isManagedKey(key)) { | ||
if (!(0, utils_new_js_1.isManagedKey)(key)) { | ||
throw new Error("Key not found: '".concat(keyRef, "'.")); | ||
@@ -225,3 +228,3 @@ } | ||
keyPair = _a.sent(); | ||
if (!isManagedKeyPair(keyPair)) { | ||
if (!(0, utils_new_js_1.isManagedKeyPair)(keyPair)) { | ||
throw new Error("Key not found: '".concat(keyRef, "'.")); | ||
@@ -250,3 +253,3 @@ } | ||
keyPair = _a.sent(); | ||
if (!isManagedKeyPair(keyPair)) { | ||
if (!(0, utils_new_js_1.isManagedKeyPair)(keyPair)) { | ||
throw new Error("Key not found: '".concat(keyRef, "'.")); | ||
@@ -277,9 +280,9 @@ } | ||
// Instantiate local in-memory store for KMS key metadata and public keys. | ||
var kmsMemoryStore = new MemoryStore(); | ||
var kmsKeyStore = new KmsKeyStore(kmsMemoryStore); | ||
var kmsMemoryStore = new common_1.MemoryStore(); | ||
var kmsKeyStore = new index_js_1.KmsKeyStore(kmsMemoryStore); | ||
// Instantiate local in-memory store for KMS private keys. | ||
var kmsPrivateMemoryStore = new MemoryStore(); | ||
var kmsPrivateKeyStore = new KmsPrivateKeyStore(kmsPrivateMemoryStore); | ||
var kmsPrivateMemoryStore = new common_1.MemoryStore(); | ||
var kmsPrivateKeyStore = new index_js_1.KmsPrivateKeyStore(kmsPrivateMemoryStore); | ||
// Instantiate local KMS using key stores. | ||
var kms = new LocalKms('local', kmsKeyStore, kmsPrivateKeyStore); | ||
var kms = new index_js_1.LocalKms('local', kmsKeyStore, kmsPrivateKeyStore); | ||
return { local: kms }; | ||
@@ -289,2 +292,2 @@ }; | ||
}()); | ||
export { KeyManager }; | ||
exports.KeyManager = KeyManager; |
@@ -0,1 +1,2 @@ | ||
"use strict"; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
@@ -37,3 +38,5 @@ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
}; | ||
import { isManagedKeyPair } from '../utils-new.js'; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.KeyManagerStore = void 0; | ||
var utils_new_js_1 = require("../utils-new.js"); | ||
/** | ||
@@ -84,3 +87,3 @@ * An implementation of `ManagedKeyStore` that stores key metadata and | ||
case 0: | ||
id = isManagedKeyPair(key) ? key.publicKey.id : key.id; | ||
id = (0, utils_new_js_1.isManagedKeyPair)(key) ? key.publicKey.id : key.id; | ||
return [4 /*yield*/, this.store.has(id)]; | ||
@@ -109,2 +112,2 @@ case 1: | ||
}()); | ||
export { KeyManagerStore }; | ||
exports.KeyManagerStore = KeyManagerStore; |
@@ -1,2 +0,18 @@ | ||
export * from './kms-local.js'; | ||
export * from './key-store.js'; | ||
"use strict"; | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
var desc = Object.getOwnPropertyDescriptor(m, k); | ||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { | ||
desc = { enumerable: true, get: function() { return m[k]; } }; | ||
} | ||
Object.defineProperty(o, k2, desc); | ||
}) : (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
o[k2] = m[k]; | ||
})); | ||
var __exportStar = (this && this.__exportStar) || function(m, exports) { | ||
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
__exportStar(require("./kms-local.js"), exports); | ||
__exportStar(require("./key-store.js"), exports); |
@@ -0,1 +1,2 @@ | ||
"use strict"; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
@@ -37,4 +38,6 @@ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
}; | ||
import { randomUuid } from '../utils-new.js'; | ||
import { isManagedKeyPair } from '../utils-new.js'; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.KmsPrivateKeyStore = exports.KmsKeyStore = void 0; | ||
var utils_new_js_1 = require("../utils-new.js"); | ||
var utils_new_js_2 = require("../utils-new.js"); | ||
/** | ||
@@ -87,7 +90,7 @@ * An implementation of `ManagedKeyStore` that stores key metadata and | ||
case 0: | ||
if (isManagedKeyPair(key)) { | ||
if ((0, utils_new_js_2.isManagedKeyPair)(key)) { | ||
id = key.publicKey.id; | ||
} | ||
else { | ||
(_b = key.id) !== null && _b !== void 0 ? _b : (key.id = randomUuid()); // If an ID wasn't specified, generate one. | ||
(_b = key.id) !== null && _b !== void 0 ? _b : (key.id = (0, utils_new_js_1.randomUuid)()); // If an ID wasn't specified, generate one. | ||
id = key.id; | ||
@@ -118,3 +121,3 @@ } | ||
}()); | ||
export { KmsKeyStore }; | ||
exports.KmsKeyStore = KmsKeyStore; | ||
/** | ||
@@ -171,3 +174,3 @@ * An implementation of `ManagedKeyStore` that stores private key | ||
clonedKey = structuredClone(key, { transfer: [key.material] }); | ||
clonedKey.id = randomUuid(); | ||
clonedKey.id = (0, utils_new_js_1.randomUuid)(); | ||
return [4 /*yield*/, this.keyStore.set(clonedKey.id, clonedKey)]; | ||
@@ -190,2 +193,2 @@ case 1: | ||
}()); | ||
export { KmsPrivateKeyStore }; | ||
exports.KmsPrivateKeyStore = KmsPrivateKeyStore; |
@@ -0,1 +1,2 @@ | ||
"use strict"; | ||
var __assign = (this && this.__assign) || function () { | ||
@@ -48,5 +49,7 @@ __assign = Object.assign || function(t) { | ||
}; | ||
import { Convert } from '@tbd54566975/common'; | ||
import { defaultAlgorithms } from './supported-algorithms.js'; | ||
import { checkRequiredProperty, isCryptoKeyPair, isManagedKey, isManagedKeyPair } from '../utils-new.js'; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.LocalKms = void 0; | ||
var common_1 = require("@tbd54566975/common"); | ||
var supported_algorithms_js_1 = require("./supported-algorithms.js"); | ||
var utils_new_js_1 = require("../utils-new.js"); | ||
var LocalKms = /** @class */ (function () { | ||
@@ -60,3 +63,3 @@ function LocalKms(kmsName, keyStore, privateKeyStore, options) { | ||
// Merge the default and custom algorithms and register with the KMS. | ||
var cryptoAlgorithms = __assign(__assign({}, defaultAlgorithms), options.cryptoAlgorithms); | ||
var cryptoAlgorithms = __assign(__assign({}, supported_algorithms_js_1.defaultAlgorithms), options.cryptoAlgorithms); | ||
this.registerSupportedAlgorithms(cryptoAlgorithms); | ||
@@ -74,3 +77,3 @@ } | ||
key = _a.sent(); | ||
if (!isManagedKey(key)) return [3 /*break*/, 3]; | ||
if (!(0, utils_new_js_1.isManagedKey)(key)) return [3 /*break*/, 3]; | ||
return [4 /*yield*/, this.privateKeyStore.getKey({ id: key.id })]; | ||
@@ -101,3 +104,3 @@ case 2: | ||
ownKeyPair = _a.sent(); | ||
if (!isManagedKeyPair(ownKeyPair)) return [3 /*break*/, 3]; | ||
if (!(0, utils_new_js_1.isManagedKeyPair)(ownKeyPair)) return [3 /*break*/, 3]; | ||
return [4 /*yield*/, this.privateKeyStore.getKey({ id: ownKeyPair.privateKey.id })]; | ||
@@ -128,3 +131,3 @@ case 2: | ||
key = _a.sent(); | ||
if (!isManagedKey(key)) return [3 /*break*/, 3]; | ||
if (!(0, utils_new_js_1.isManagedKey)(key)) return [3 /*break*/, 3]; | ||
return [4 /*yield*/, this.privateKeyStore.getKey({ id: key.id })]; | ||
@@ -158,3 +161,3 @@ case 2: | ||
cryptoKey = _a.sent(); | ||
if (!isCryptoKeyPair(cryptoKey)) return [3 /*break*/, 3]; | ||
if (!(0, utils_new_js_1.isCryptoKeyPair)(cryptoKey)) return [3 /*break*/, 3]; | ||
privateKeyType = cryptoKey.privateKey.type; | ||
@@ -207,4 +210,4 @@ return [4 /*yield*/, this.privateKeyStore.importKey({ key: { material: cryptoKey.privateKey.handle, type: privateKeyType } })]; | ||
throw new TypeError("Out of range: '".concat(privateKey.type, ", ").concat(publicKey.type, "'. Must be 'private, public'")); | ||
privateKey.material = Convert.bufferSource(privateKey.material).toArrayBuffer(); | ||
publicKey.material = Convert.bufferSource(publicKey.material).toArrayBuffer(); | ||
privateKey.material = common_1.Convert.bufferSource(privateKey.material).toArrayBuffer(); | ||
publicKey.material = common_1.Convert.bufferSource(publicKey.material).toArrayBuffer(); | ||
return [4 /*yield*/, this.privateKeyStore.importKey({ key: { material: privateKey.material, type: privateKey.type } })]; | ||
@@ -232,3 +235,3 @@ case 1: | ||
material = options.material; | ||
material = Convert.bufferSource(material).toArrayBuffer(); | ||
material = common_1.Convert.bufferSource(material).toArrayBuffer(); | ||
return [4 /*yield*/, this.privateKeyStore.importKey({ key: { material: material, type: keyType } })]; | ||
@@ -244,3 +247,3 @@ case 5: | ||
material = options.material; | ||
material = Convert.bufferSource(material).toArrayBuffer(); | ||
material = common_1.Convert.bufferSource(material).toArrayBuffer(); | ||
privateManagedKey = this.toManagedKey(__assign(__assign({}, options), { material: material, id: 'placeholder' })); | ||
@@ -254,3 +257,3 @@ _b = privateManagedKey; | ||
material = options.material; | ||
material = Convert.bufferSource(material).toArrayBuffer(); | ||
material = common_1.Convert.bufferSource(material).toArrayBuffer(); | ||
return [4 /*yield*/, this.privateKeyStore.importKey({ key: { material: material, type: keyType } })]; | ||
@@ -279,3 +282,3 @@ case 10: | ||
keyPair = _a.sent(); | ||
if (!isManagedKeyPair(keyPair)) return [3 /*break*/, 3]; | ||
if (!(0, utils_new_js_1.isManagedKeyPair)(keyPair)) return [3 /*break*/, 3]; | ||
return [4 /*yield*/, this.privateKeyStore.getKey({ id: keyPair.privateKey.id })]; | ||
@@ -306,3 +309,3 @@ case 2: | ||
keyPair = _a.sent(); | ||
if (isManagedKeyPair(keyPair)) { | ||
if ((0, utils_new_js_1.isManagedKeyPair)(keyPair)) { | ||
publicCryptoKey = this.toCryptoKey(__assign({}, keyPair.publicKey)); | ||
@@ -319,3 +322,3 @@ cryptoAlgorithm = this.getAlgorithm(algorithm); | ||
LocalKms.prototype.getAlgorithm = function (algorithmIdentifier) { | ||
checkRequiredProperty({ property: 'name', inObject: algorithmIdentifier }); | ||
(0, utils_new_js_1.checkRequiredProperty)({ property: 'name', inObject: algorithmIdentifier }); | ||
var algorithm = this.supportedAlgorithms.get(algorithmIdentifier.name.toUpperCase()); | ||
@@ -365,2 +368,2 @@ if (algorithm === undefined) { | ||
}()); | ||
export { LocalKms }; | ||
exports.LocalKms = LocalKms; |
@@ -1,8 +0,11 @@ | ||
import { EcdhAlgorithm, EcdsaAlgorithm, EdDsaAlgorithm, AesCtrAlgorithm, } from '../crypto-algorithms/index.js'; | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.defaultAlgorithms = void 0; | ||
var index_js_1 = require("../crypto-algorithms/index.js"); | ||
// Map key operations to algorithm specs to implementations. | ||
export var defaultAlgorithms = { | ||
'AES-CTR': AesCtrAlgorithm, | ||
ECDH: EcdhAlgorithm, | ||
ECDSA: EcdsaAlgorithm, | ||
EdDSA: EdDsaAlgorithm, | ||
exports.defaultAlgorithms = { | ||
'AES-CTR': index_js_1.AesCtrAlgorithm, | ||
ECDH: index_js_1.EcdhAlgorithm, | ||
ECDSA: index_js_1.EcdsaAlgorithm, | ||
EdDSA: index_js_1.EdDsaAlgorithm, | ||
}; |
@@ -1,7 +0,36 @@ | ||
export * as ed25519 from './ed25519.js'; | ||
export * from './utils-new.js'; | ||
export * from './kms-local/index.js'; | ||
export * from './key-manager/index.js'; | ||
export * from './algorithms-api/index.js'; | ||
export * from './crypto-algorithms/index.js'; | ||
export * from './crypto-primitives/index.js'; | ||
"use strict"; | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
var desc = Object.getOwnPropertyDescriptor(m, k); | ||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { | ||
desc = { enumerable: true, get: function() { return m[k]; } }; | ||
} | ||
Object.defineProperty(o, k2, desc); | ||
}) : (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
o[k2] = m[k]; | ||
})); | ||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { | ||
Object.defineProperty(o, "default", { enumerable: true, value: v }); | ||
}) : function(o, v) { | ||
o["default"] = v; | ||
}); | ||
var __importStar = (this && this.__importStar) || function (mod) { | ||
if (mod && mod.__esModule) return mod; | ||
var result = {}; | ||
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); | ||
__setModuleDefault(result, mod); | ||
return result; | ||
}; | ||
var __exportStar = (this && this.__exportStar) || function(m, exports) { | ||
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.ed25519 = void 0; | ||
exports.ed25519 = __importStar(require("./ed25519.js")); | ||
__exportStar(require("./utils-new.js"), exports); | ||
__exportStar(require("./kms-local/index.js"), exports); | ||
__exportStar(require("./key-manager/index.js"), exports); | ||
__exportStar(require("./algorithms-api/index.js"), exports); | ||
__exportStar(require("./crypto-algorithms/index.js"), exports); | ||
__exportStar(require("./crypto-primitives/index.js"), exports); |
@@ -1,1 +0,2 @@ | ||
export {}; | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); |
@@ -1,1 +0,2 @@ | ||
export {}; | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); |
@@ -1,1 +0,2 @@ | ||
export {}; | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); |
@@ -1,1 +0,2 @@ | ||
export {}; | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); |
@@ -1,1 +0,2 @@ | ||
export {}; | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); |
@@ -1,3 +0,6 @@ | ||
import { universalTypeOf } from '@tbd54566975/common'; | ||
import { bytesToHex, randomBytes } from '@noble/hashes/utils'; | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.randomUuid = exports.isManagedKeyPair = exports.isManagedKey = exports.isCryptoKeyPair = exports.isBufferKeyPair = exports.checkValidProperty = exports.checkRequiredProperty = void 0; | ||
var common_1 = require("@tbd54566975/common"); | ||
var utils_1 = require("@noble/hashes/utils"); | ||
/** | ||
@@ -11,3 +14,3 @@ * Checks whether the properties object provided contains the specified property. | ||
*/ | ||
export function checkRequiredProperty(options) { | ||
function checkRequiredProperty(options) { | ||
if (!options || options.property === undefined || options.inObject === undefined) { | ||
@@ -21,2 +24,3 @@ throw new TypeError("One or more required arguments missing: 'property, properties'"); | ||
} | ||
exports.checkRequiredProperty = checkRequiredProperty; | ||
/** | ||
@@ -30,3 +34,3 @@ * Checks whether the property specified is a member of the list of valid properties. | ||
*/ | ||
export function checkValidProperty(options) { | ||
function checkValidProperty(options) { | ||
if (!options || options.property === undefined || options.allowedProperties === undefined) { | ||
@@ -43,2 +47,3 @@ throw new TypeError("One or more required arguments missing: 'property, allowedProperties'"); | ||
} | ||
exports.checkValidProperty = checkValidProperty; | ||
/** | ||
@@ -51,7 +56,8 @@ * Type guard function to check if the given key is a raw key pair | ||
*/ | ||
export function isBufferKeyPair(key) { | ||
function isBufferKeyPair(key) { | ||
return (key && 'privateKey' in key && 'publicKey' in key && | ||
universalTypeOf(key.privateKey) === 'ArrayBuffer' && | ||
universalTypeOf(key.publicKey) === 'ArrayBuffer') ? true : false; | ||
(0, common_1.universalTypeOf)(key.privateKey) === 'ArrayBuffer' && | ||
(0, common_1.universalTypeOf)(key.publicKey) === 'ArrayBuffer') ? true : false; | ||
} | ||
exports.isBufferKeyPair = isBufferKeyPair; | ||
/** | ||
@@ -64,5 +70,6 @@ * Type guard function to check if the given key is a | ||
*/ | ||
export function isCryptoKeyPair(key) { | ||
function isCryptoKeyPair(key) { | ||
return key && 'privateKey' in key && 'publicKey' in key; | ||
} | ||
exports.isCryptoKeyPair = isCryptoKeyPair; | ||
/** | ||
@@ -74,5 +81,6 @@ * Type guard function to check if the given key is a ManagedKey. | ||
*/ | ||
export function isManagedKey(key) { | ||
function isManagedKey(key) { | ||
return key !== undefined && 'algorithm' in key && 'extractable' in key && 'type' in key && 'usages' in key; | ||
} | ||
exports.isManagedKey = isManagedKey; | ||
/** | ||
@@ -84,5 +92,6 @@ * Type guard function to check if the given key is a ManagedKeyPair. | ||
*/ | ||
export function isManagedKeyPair(key) { | ||
function isManagedKeyPair(key) { | ||
return key !== undefined && 'privateKey' in key && 'publicKey' in key; | ||
} | ||
exports.isManagedKeyPair = isManagedKeyPair; | ||
/** | ||
@@ -111,7 +120,7 @@ * Generates a UUID (Universally Unique Identifier) using a | ||
*/ | ||
export function randomUuid() { | ||
var bytes = randomBytes(16); | ||
function randomUuid() { | ||
var bytes = (0, utils_1.randomBytes)(16); | ||
bytes[6] = (bytes[6] & 0x0f) | 0x40; // set version 4 | ||
bytes[8] = (bytes[8] & 0x3f) | 0x80; // set variant 1 | ||
var hex = bytesToHex(bytes); | ||
var hex = (0, utils_1.bytesToHex)(bytes); | ||
bytes.fill(0); // wipe the random values array | ||
@@ -129,1 +138,2 @@ var segments = [ | ||
} | ||
exports.randomUuid = randomUuid; |
{ | ||
"name": "@tbd54566975/crypto", | ||
"version": "0.8.0-alpha-20230728-70f8cf0", | ||
"version": "0.8.0-alpha-20230728-88c49a2", | ||
"description": "TBD crypto library", | ||
@@ -73,3 +73,3 @@ "type": "module", | ||
"@noble/hashes": "1.3.1", | ||
"@tbd54566975/common": "0.8.0-alpha-20230728-70f8cf0", | ||
"@tbd54566975/common": "0.8.0-alpha-20230728-88c49a2", | ||
"ed2curve": "0.3.0" | ||
@@ -76,0 +76,0 @@ }, |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
2194413
11610
0
+ Added@tbd54566975/common@0.8.0-alpha-20230728-88c49a2(transitive)
- Removed@tbd54566975/common@0.8.0-alpha-20230728-70f8cf0(transitive)