@peculiar/jose
Advanced tools
Comparing version 1.2.3 to 1.3.0
@@ -15,105 +15,93 @@ "use strict"; | ||
} | ||
exportKey(...args) { | ||
return tslib_1.__awaiter(this, arguments, void 0, function* () { | ||
let algorithm; | ||
let keyUsages = ["verify"]; | ||
let crypto = tslib_1.__classPrivateFieldGet(this, _cryptoProvider); | ||
if (arguments.length < 2) { | ||
crypto = args[0] || crypto; | ||
switch (this.kty) { | ||
case key_types_1.KeyTypes.RSA: | ||
algorithm = { name: "RSASSA-PKCS1-v1_5", hash: "SHA-256" }; | ||
break; | ||
case key_types_1.KeyTypes.EC: | ||
algorithm = { name: "ECDSA", namedCurve: this.crv }; | ||
break; | ||
case key_types_1.KeyTypes.OctetSequence: | ||
algorithm = { name: "HMAC", hash: "SHA-256" }; | ||
break; | ||
default: | ||
throw new Error("Unsupported type of JWK"); | ||
} | ||
} | ||
else { | ||
algorithm = args[0]; | ||
keyUsages = args[1]; | ||
crypto = args[2] || crypto; | ||
} | ||
return yield crypto.subtle.importKey("jwk", this, algorithm, true, keyUsages); | ||
}); | ||
} | ||
getThumbprint(alg = algorithms_1.Algorithms.SHA256) { | ||
return tslib_1.__awaiter(this, void 0, void 0, function* () { | ||
const listKeys = {}; | ||
if (this.crv) { | ||
listKeys["crv"] = this.crv.toString(); | ||
} | ||
if (this.e) { | ||
listKeys["e"] = this.e; | ||
} | ||
if (this.k) { | ||
listKeys["k"] = this.k; | ||
} | ||
if (this.kty) { | ||
listKeys["kty"] = this.kty.toString(); | ||
} | ||
if (this.n) { | ||
listKeys["n"] = this.n; | ||
} | ||
if (this.x) { | ||
listKeys["x"] = this.x; | ||
} | ||
if (this.y) { | ||
listKeys["y"] = this.y; | ||
} | ||
const json = JSON.stringify(listKeys); | ||
switch (alg) { | ||
case algorithms_1.Algorithms.SHA256: | ||
return pvtsutils.Convert.ToHex(yield this.digest(json, "SHA-256")); | ||
case algorithms_1.Algorithms.SHA1: | ||
return pvtsutils.Convert.ToHex(yield this.digest(json, "SHA-1")); | ||
async exportKey(...args) { | ||
let algorithm; | ||
let keyUsages = ["verify"]; | ||
let crypto = tslib_1.__classPrivateFieldGet(this, _cryptoProvider); | ||
if (arguments.length < 2) { | ||
crypto = args[0] || crypto; | ||
switch (this.kty) { | ||
case key_types_1.KeyTypes.RSA: | ||
algorithm = { name: "RSASSA-PKCS1-v1_5", hash: "SHA-256" }; | ||
break; | ||
case key_types_1.KeyTypes.EC: | ||
algorithm = { name: "ECDSA", namedCurve: this.crv }; | ||
break; | ||
case key_types_1.KeyTypes.OctetSequence: | ||
algorithm = { name: "HMAC", hash: "SHA-256" }; | ||
break; | ||
default: | ||
throw new Error(`Unsupported algorithm: ${alg}`); | ||
throw new Error("Unsupported type of JWK"); | ||
} | ||
}); | ||
} | ||
else { | ||
algorithm = args[0]; | ||
keyUsages = args[1]; | ||
crypto = args[2] || crypto; | ||
} | ||
return await crypto.subtle.importKey("jwk", this, algorithm, true, keyUsages); | ||
} | ||
digest(json, alg) { | ||
return tslib_1.__awaiter(this, void 0, void 0, function* () { | ||
const hash = yield tslib_1.__classPrivateFieldGet(this, _cryptoProvider).subtle.digest({ | ||
name: alg, | ||
}, pvtsutils.BufferSourceConverter.toUint8Array(pvtsutils.Convert.FromUtf8String(json))); | ||
return hash; | ||
}); | ||
async getThumbprint(alg = algorithms_1.Algorithms.SHA256) { | ||
const listKeys = {}; | ||
if (this.crv) { | ||
listKeys["crv"] = this.crv.toString(); | ||
} | ||
if (this.e) { | ||
listKeys["e"] = this.e; | ||
} | ||
if (this.k) { | ||
listKeys["k"] = this.k; | ||
} | ||
if (this.kty) { | ||
listKeys["kty"] = this.kty.toString(); | ||
} | ||
if (this.n) { | ||
listKeys["n"] = this.n; | ||
} | ||
if (this.x) { | ||
listKeys["x"] = this.x; | ||
} | ||
if (this.y) { | ||
listKeys["y"] = this.y; | ||
} | ||
const json = JSON.stringify(listKeys); | ||
switch (alg) { | ||
case algorithms_1.Algorithms.SHA256: | ||
return pvtsutils.Convert.ToHex(await this.digest(json, "SHA-256")); | ||
case algorithms_1.Algorithms.SHA1: | ||
return pvtsutils.Convert.ToHex(await this.digest(json, "SHA-1")); | ||
default: | ||
throw new Error(`Unsupported algorithm: ${alg}`); | ||
} | ||
} | ||
getPublicKey() { | ||
return tslib_1.__awaiter(this, void 0, void 0, function* () { | ||
if (this.kty === key_types_1.KeyTypes.EC) { | ||
return this.getEcdsaPublicKey(); | ||
} | ||
else if (this.kty === key_types_1.KeyTypes.RSA) { | ||
return this.getRsaPublicKey(); | ||
} | ||
throw new Error(`Unsupported type ${this.kty}`); | ||
}); | ||
async digest(json, alg) { | ||
const hash = await tslib_1.__classPrivateFieldGet(this, _cryptoProvider).subtle.digest({ | ||
name: alg, | ||
}, pvtsutils.BufferSourceConverter.toUint8Array(pvtsutils.Convert.FromUtf8String(json))); | ||
return hash; | ||
} | ||
getEcdsaPublicKey() { | ||
return tslib_1.__awaiter(this, void 0, void 0, function* () { | ||
const alg = { | ||
name: "ECDSA", | ||
namedCurve: this.crv, | ||
}; | ||
return yield tslib_1.__classPrivateFieldGet(this, _cryptoProvider).subtle.importKey("jwk", this, alg, true, ["verify"]); | ||
}); | ||
async getPublicKey() { | ||
if (this.kty === key_types_1.KeyTypes.EC) { | ||
return this.getEcdsaPublicKey(); | ||
} | ||
else if (this.kty === key_types_1.KeyTypes.RSA) { | ||
return this.getRsaPublicKey(); | ||
} | ||
throw new Error(`Unsupported type ${this.kty}`); | ||
} | ||
getRsaPublicKey() { | ||
return tslib_1.__awaiter(this, void 0, void 0, function* () { | ||
const alg = { | ||
name: "RSASSA-PKCS1-v1_5", | ||
hash: { name: "SHA-256" }, | ||
}; | ||
return yield tslib_1.__classPrivateFieldGet(this, _cryptoProvider).subtle.importKey("jwk", this, alg, true, ["verify"]); | ||
}); | ||
async getEcdsaPublicKey() { | ||
const alg = { | ||
name: "ECDSA", | ||
namedCurve: this.crv, | ||
}; | ||
return await tslib_1.__classPrivateFieldGet(this, _cryptoProvider).subtle.importKey("jwk", this, alg, true, ["verify"]); | ||
} | ||
async getRsaPublicKey() { | ||
const alg = { | ||
name: "RSASSA-PKCS1-v1_5", | ||
hash: { name: "SHA-256" }, | ||
}; | ||
return await tslib_1.__classPrivateFieldGet(this, _cryptoProvider).subtle.importKey("jwk", this, alg, true, ["verify"]); | ||
} | ||
} | ||
exports.JsonWebKey = JsonWebKey; | ||
_cryptoProvider = new WeakMap(); |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.JsonWebSignature = void 0; | ||
const tslib_1 = require("tslib"); | ||
const pvtsutils_1 = require("pvtsutils"); | ||
@@ -72,58 +71,52 @@ const jwa_1 = require("./jwa"); | ||
} | ||
verify(key, crypto) { | ||
return tslib_1.__awaiter(this, void 0, void 0, function* () { | ||
const attrs = this.getProtected(); | ||
if (!attrs.alg) { | ||
throw new Error("JWS.protected doesn't have required parameter 'alg'"); | ||
async verify(key, crypto) { | ||
const attrs = this.getProtected(); | ||
if (!attrs.alg) { | ||
throw new Error("JWS.protected doesn't have required parameter 'alg'"); | ||
} | ||
const alg = jwa_1.JsonWebAlgorithmConverter.toAlgorithm(attrs.alg); | ||
if (!alg) { | ||
throw new Error("Cannot convert JWA to WebCrypto algorithm"); | ||
} | ||
if (!key) { | ||
const jwk = await this.getKey(crypto); | ||
if (!jwk) { | ||
throw new Error("Cannot get JWK key"); | ||
} | ||
const alg = jwa_1.JsonWebAlgorithmConverter.toAlgorithm(attrs.alg); | ||
if (!alg) { | ||
throw new Error("Cannot convert JWA to WebCrypto algorithm"); | ||
} | ||
if (!key) { | ||
const jwk = yield this.getKey(crypto); | ||
if (!jwk) { | ||
throw new Error("Cannot get JWK key"); | ||
} | ||
key = jwk; | ||
} | ||
const data = pvtsutils_1.Convert.FromUtf8String(this.toStringSign()); | ||
const ok = yield this.getCryptoProvider(crypto).subtle.verify(alg, key, this.getSignature(), data); | ||
return ok; | ||
}); | ||
key = jwk; | ||
} | ||
const data = pvtsutils_1.Convert.FromUtf8String(this.toStringSign()); | ||
const ok = await this.getCryptoProvider(crypto).subtle.verify(alg, key, this.getSignature(), data); | ||
return ok; | ||
} | ||
getKey(crypto) { | ||
return tslib_1.__awaiter(this, void 0, void 0, function* () { | ||
const attrs = this.getProtected(); | ||
if (!attrs.jwk) { | ||
return null; | ||
} | ||
if (!attrs.alg) { | ||
throw new Error("JWS.protected doesn't have required parameter 'alg'"); | ||
} | ||
const signingAlg = jwa_1.JsonWebAlgorithmConverter.toAlgorithm(attrs.alg); | ||
if (!signingAlg) { | ||
throw new Error("Cannot convert JWA to WebCrypto algorithm"); | ||
} | ||
const alg = Object.assign({}, signingAlg); | ||
if (alg.name === "ECDSA") { | ||
alg.namedCurve = attrs.jwk.crv; | ||
} | ||
const key = yield this.getCryptoProvider(crypto).subtle.importKey("jwk", attrs.jwk, alg, true, ["verify"]); | ||
return key; | ||
}); | ||
async getKey(crypto) { | ||
const attrs = this.getProtected(); | ||
if (!attrs.jwk) { | ||
return null; | ||
} | ||
if (!attrs.alg) { | ||
throw new Error("JWS.protected doesn't have required parameter 'alg'"); | ||
} | ||
const signingAlg = jwa_1.JsonWebAlgorithmConverter.toAlgorithm(attrs.alg); | ||
if (!signingAlg) { | ||
throw new Error("Cannot convert JWA to WebCrypto algorithm"); | ||
} | ||
const alg = { ...signingAlg }; | ||
if (alg.name === "ECDSA") { | ||
alg.namedCurve = attrs.jwk.crv; | ||
} | ||
const key = await this.getCryptoProvider(crypto).subtle.importKey("jwk", attrs.jwk, alg, true, ["verify"]); | ||
return key; | ||
} | ||
sign(algorithm, key, crypto) { | ||
return tslib_1.__awaiter(this, void 0, void 0, function* () { | ||
const attrs = this.getProtected(); | ||
const jwa = jwa_1.JsonWebAlgorithmConverter.fromAlgorithm(Object.assign(Object.assign({}, algorithm), key.algorithm)); | ||
if (!jwa) { | ||
throw new Error("Cannot convert WebCrypto algorithm to JWA"); | ||
} | ||
attrs.alg = jwa; | ||
this.setProtected(attrs); | ||
const data = pvtsutils_1.Convert.FromUtf8String(this.toStringSign()); | ||
const signature = yield this.getCryptoProvider(crypto).subtle.sign(algorithm, key, data); | ||
this.setSignature(signature); | ||
}); | ||
async sign(algorithm, key, crypto) { | ||
const attrs = this.getProtected(); | ||
const jwa = jwa_1.JsonWebAlgorithmConverter.fromAlgorithm({ ...algorithm, ...key.algorithm }); | ||
if (!jwa) { | ||
throw new Error("Cannot convert WebCrypto algorithm to JWA"); | ||
} | ||
attrs.alg = jwa; | ||
this.setProtected(attrs); | ||
const data = pvtsutils_1.Convert.FromUtf8String(this.toStringSign()); | ||
const signature = await this.getCryptoProvider(crypto).subtle.sign(algorithm, key, data); | ||
this.setSignature(signature); | ||
} | ||
@@ -130,0 +123,0 @@ toStringSign() { |
var _cryptoProvider; | ||
import { __awaiter, __classPrivateFieldGet, __classPrivateFieldSet } from "tslib"; | ||
import { __classPrivateFieldGet, __classPrivateFieldSet } from "tslib"; | ||
import { Algorithms } from "./algorithms"; | ||
@@ -12,104 +12,92 @@ import { KeyTypes } from "./key_types"; | ||
} | ||
exportKey(...args) { | ||
return __awaiter(this, arguments, void 0, function* () { | ||
let algorithm; | ||
let keyUsages = ["verify"]; | ||
let crypto = __classPrivateFieldGet(this, _cryptoProvider); | ||
if (arguments.length < 2) { | ||
crypto = args[0] || crypto; | ||
switch (this.kty) { | ||
case KeyTypes.RSA: | ||
algorithm = { name: "RSASSA-PKCS1-v1_5", hash: "SHA-256" }; | ||
break; | ||
case KeyTypes.EC: | ||
algorithm = { name: "ECDSA", namedCurve: this.crv }; | ||
break; | ||
case KeyTypes.OctetSequence: | ||
algorithm = { name: "HMAC", hash: "SHA-256" }; | ||
break; | ||
default: | ||
throw new Error("Unsupported type of JWK"); | ||
} | ||
} | ||
else { | ||
algorithm = args[0]; | ||
keyUsages = args[1]; | ||
crypto = args[2] || crypto; | ||
} | ||
return yield crypto.subtle.importKey("jwk", this, algorithm, true, keyUsages); | ||
}); | ||
} | ||
getThumbprint(alg = Algorithms.SHA256) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const listKeys = {}; | ||
if (this.crv) { | ||
listKeys["crv"] = this.crv.toString(); | ||
} | ||
if (this.e) { | ||
listKeys["e"] = this.e; | ||
} | ||
if (this.k) { | ||
listKeys["k"] = this.k; | ||
} | ||
if (this.kty) { | ||
listKeys["kty"] = this.kty.toString(); | ||
} | ||
if (this.n) { | ||
listKeys["n"] = this.n; | ||
} | ||
if (this.x) { | ||
listKeys["x"] = this.x; | ||
} | ||
if (this.y) { | ||
listKeys["y"] = this.y; | ||
} | ||
const json = JSON.stringify(listKeys); | ||
switch (alg) { | ||
case Algorithms.SHA256: | ||
return pvtsutils.Convert.ToHex(yield this.digest(json, "SHA-256")); | ||
case Algorithms.SHA1: | ||
return pvtsutils.Convert.ToHex(yield this.digest(json, "SHA-1")); | ||
async exportKey(...args) { | ||
let algorithm; | ||
let keyUsages = ["verify"]; | ||
let crypto = __classPrivateFieldGet(this, _cryptoProvider); | ||
if (arguments.length < 2) { | ||
crypto = args[0] || crypto; | ||
switch (this.kty) { | ||
case KeyTypes.RSA: | ||
algorithm = { name: "RSASSA-PKCS1-v1_5", hash: "SHA-256" }; | ||
break; | ||
case KeyTypes.EC: | ||
algorithm = { name: "ECDSA", namedCurve: this.crv }; | ||
break; | ||
case KeyTypes.OctetSequence: | ||
algorithm = { name: "HMAC", hash: "SHA-256" }; | ||
break; | ||
default: | ||
throw new Error(`Unsupported algorithm: ${alg}`); | ||
throw new Error("Unsupported type of JWK"); | ||
} | ||
}); | ||
} | ||
else { | ||
algorithm = args[0]; | ||
keyUsages = args[1]; | ||
crypto = args[2] || crypto; | ||
} | ||
return await crypto.subtle.importKey("jwk", this, algorithm, true, keyUsages); | ||
} | ||
digest(json, alg) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const hash = yield __classPrivateFieldGet(this, _cryptoProvider).subtle.digest({ | ||
name: alg, | ||
}, pvtsutils.BufferSourceConverter.toUint8Array(pvtsutils.Convert.FromUtf8String(json))); | ||
return hash; | ||
}); | ||
async getThumbprint(alg = Algorithms.SHA256) { | ||
const listKeys = {}; | ||
if (this.crv) { | ||
listKeys["crv"] = this.crv.toString(); | ||
} | ||
if (this.e) { | ||
listKeys["e"] = this.e; | ||
} | ||
if (this.k) { | ||
listKeys["k"] = this.k; | ||
} | ||
if (this.kty) { | ||
listKeys["kty"] = this.kty.toString(); | ||
} | ||
if (this.n) { | ||
listKeys["n"] = this.n; | ||
} | ||
if (this.x) { | ||
listKeys["x"] = this.x; | ||
} | ||
if (this.y) { | ||
listKeys["y"] = this.y; | ||
} | ||
const json = JSON.stringify(listKeys); | ||
switch (alg) { | ||
case Algorithms.SHA256: | ||
return pvtsutils.Convert.ToHex(await this.digest(json, "SHA-256")); | ||
case Algorithms.SHA1: | ||
return pvtsutils.Convert.ToHex(await this.digest(json, "SHA-1")); | ||
default: | ||
throw new Error(`Unsupported algorithm: ${alg}`); | ||
} | ||
} | ||
getPublicKey() { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
if (this.kty === KeyTypes.EC) { | ||
return this.getEcdsaPublicKey(); | ||
} | ||
else if (this.kty === KeyTypes.RSA) { | ||
return this.getRsaPublicKey(); | ||
} | ||
throw new Error(`Unsupported type ${this.kty}`); | ||
}); | ||
async digest(json, alg) { | ||
const hash = await __classPrivateFieldGet(this, _cryptoProvider).subtle.digest({ | ||
name: alg, | ||
}, pvtsutils.BufferSourceConverter.toUint8Array(pvtsutils.Convert.FromUtf8String(json))); | ||
return hash; | ||
} | ||
getEcdsaPublicKey() { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const alg = { | ||
name: "ECDSA", | ||
namedCurve: this.crv, | ||
}; | ||
return yield __classPrivateFieldGet(this, _cryptoProvider).subtle.importKey("jwk", this, alg, true, ["verify"]); | ||
}); | ||
async getPublicKey() { | ||
if (this.kty === KeyTypes.EC) { | ||
return this.getEcdsaPublicKey(); | ||
} | ||
else if (this.kty === KeyTypes.RSA) { | ||
return this.getRsaPublicKey(); | ||
} | ||
throw new Error(`Unsupported type ${this.kty}`); | ||
} | ||
getRsaPublicKey() { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const alg = { | ||
name: "RSASSA-PKCS1-v1_5", | ||
hash: { name: "SHA-256" }, | ||
}; | ||
return yield __classPrivateFieldGet(this, _cryptoProvider).subtle.importKey("jwk", this, alg, true, ["verify"]); | ||
}); | ||
async getEcdsaPublicKey() { | ||
const alg = { | ||
name: "ECDSA", | ||
namedCurve: this.crv, | ||
}; | ||
return await __classPrivateFieldGet(this, _cryptoProvider).subtle.importKey("jwk", this, alg, true, ["verify"]); | ||
} | ||
async getRsaPublicKey() { | ||
const alg = { | ||
name: "RSASSA-PKCS1-v1_5", | ||
hash: { name: "SHA-256" }, | ||
}; | ||
return await __classPrivateFieldGet(this, _cryptoProvider).subtle.importKey("jwk", this, alg, true, ["verify"]); | ||
} | ||
} | ||
_cryptoProvider = new WeakMap(); |
@@ -1,2 +0,1 @@ | ||
import { __awaiter } from "tslib"; | ||
import { Convert } from "pvtsutils"; | ||
@@ -69,58 +68,52 @@ import { JsonWebAlgorithmConverter } from "./jwa"; | ||
} | ||
verify(key, crypto) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const attrs = this.getProtected(); | ||
if (!attrs.alg) { | ||
throw new Error("JWS.protected doesn't have required parameter 'alg'"); | ||
async verify(key, crypto) { | ||
const attrs = this.getProtected(); | ||
if (!attrs.alg) { | ||
throw new Error("JWS.protected doesn't have required parameter 'alg'"); | ||
} | ||
const alg = JsonWebAlgorithmConverter.toAlgorithm(attrs.alg); | ||
if (!alg) { | ||
throw new Error("Cannot convert JWA to WebCrypto algorithm"); | ||
} | ||
if (!key) { | ||
const jwk = await this.getKey(crypto); | ||
if (!jwk) { | ||
throw new Error("Cannot get JWK key"); | ||
} | ||
const alg = JsonWebAlgorithmConverter.toAlgorithm(attrs.alg); | ||
if (!alg) { | ||
throw new Error("Cannot convert JWA to WebCrypto algorithm"); | ||
} | ||
if (!key) { | ||
const jwk = yield this.getKey(crypto); | ||
if (!jwk) { | ||
throw new Error("Cannot get JWK key"); | ||
} | ||
key = jwk; | ||
} | ||
const data = Convert.FromUtf8String(this.toStringSign()); | ||
const ok = yield this.getCryptoProvider(crypto).subtle.verify(alg, key, this.getSignature(), data); | ||
return ok; | ||
}); | ||
key = jwk; | ||
} | ||
const data = Convert.FromUtf8String(this.toStringSign()); | ||
const ok = await this.getCryptoProvider(crypto).subtle.verify(alg, key, this.getSignature(), data); | ||
return ok; | ||
} | ||
getKey(crypto) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const attrs = this.getProtected(); | ||
if (!attrs.jwk) { | ||
return null; | ||
} | ||
if (!attrs.alg) { | ||
throw new Error("JWS.protected doesn't have required parameter 'alg'"); | ||
} | ||
const signingAlg = JsonWebAlgorithmConverter.toAlgorithm(attrs.alg); | ||
if (!signingAlg) { | ||
throw new Error("Cannot convert JWA to WebCrypto algorithm"); | ||
} | ||
const alg = Object.assign({}, signingAlg); | ||
if (alg.name === "ECDSA") { | ||
alg.namedCurve = attrs.jwk.crv; | ||
} | ||
const key = yield this.getCryptoProvider(crypto).subtle.importKey("jwk", attrs.jwk, alg, true, ["verify"]); | ||
return key; | ||
}); | ||
async getKey(crypto) { | ||
const attrs = this.getProtected(); | ||
if (!attrs.jwk) { | ||
return null; | ||
} | ||
if (!attrs.alg) { | ||
throw new Error("JWS.protected doesn't have required parameter 'alg'"); | ||
} | ||
const signingAlg = JsonWebAlgorithmConverter.toAlgorithm(attrs.alg); | ||
if (!signingAlg) { | ||
throw new Error("Cannot convert JWA to WebCrypto algorithm"); | ||
} | ||
const alg = { ...signingAlg }; | ||
if (alg.name === "ECDSA") { | ||
alg.namedCurve = attrs.jwk.crv; | ||
} | ||
const key = await this.getCryptoProvider(crypto).subtle.importKey("jwk", attrs.jwk, alg, true, ["verify"]); | ||
return key; | ||
} | ||
sign(algorithm, key, crypto) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const attrs = this.getProtected(); | ||
const jwa = JsonWebAlgorithmConverter.fromAlgorithm(Object.assign(Object.assign({}, algorithm), key.algorithm)); | ||
if (!jwa) { | ||
throw new Error("Cannot convert WebCrypto algorithm to JWA"); | ||
} | ||
attrs.alg = jwa; | ||
this.setProtected(attrs); | ||
const data = Convert.FromUtf8String(this.toStringSign()); | ||
const signature = yield this.getCryptoProvider(crypto).subtle.sign(algorithm, key, data); | ||
this.setSignature(signature); | ||
}); | ||
async sign(algorithm, key, crypto) { | ||
const attrs = this.getProtected(); | ||
const jwa = JsonWebAlgorithmConverter.fromAlgorithm({ ...algorithm, ...key.algorithm }); | ||
if (!jwa) { | ||
throw new Error("Cannot convert WebCrypto algorithm to JWA"); | ||
} | ||
attrs.alg = jwa; | ||
this.setProtected(attrs); | ||
const data = Convert.FromUtf8String(this.toStringSign()); | ||
const signature = await this.getCryptoProvider(crypto).subtle.sign(algorithm, key, data); | ||
this.setSignature(signature); | ||
} | ||
@@ -127,0 +120,0 @@ toStringSign() { |
@@ -6,2 +6,10 @@ # Change Log | ||
# [1.3.0](https://github.com/PeculiarVentures/acme-ts/compare/v1.2.13...v1.3.0) (2020-12-09) | ||
**Note:** Version bump only for package @peculiar/jose | ||
## [1.2.3](https://github.com/PeculiarVentures/acme-ts/compare/v1.2.2...v1.2.3) (2020-10-13) | ||
@@ -8,0 +16,0 @@ |
{ | ||
"name": "@peculiar/jose", | ||
"version": "1.2.3", | ||
"version": "1.3.0", | ||
"description": "Implementation of Javascript Object Signing and Encryption (jose)", | ||
@@ -30,3 +30,3 @@ "keywords": [ | ||
"dependencies": { | ||
"pvtsutils": "1.0.14" | ||
"pvtsutils": "1.1.1" | ||
}, | ||
@@ -48,3 +48,3 @@ "scripts": { | ||
"homepage": "https://github.com/PeculiarVentures/acme-ts#readme", | ||
"gitHead": "e423e2bf1b95ca032cc533fde89f4949436274a8" | ||
"gitHead": "b011b49c4cdb6f38d34328fc352f2bd7a965ae61" | ||
} |
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
75411
1056
+ Addedpvtsutils@1.1.1(transitive)
- Removedpvtsutils@1.0.14(transitive)
Updatedpvtsutils@1.1.1