@transmute/cose
Advanced tools
Comparing version 0.2.6 to 0.2.7
@@ -26,12 +26,12 @@ "use strict"; | ||
const cryptoKeyPair = yield (0, jose_1.generateKeyPair)(knownAlgorithm.Name, { extractable: true }); | ||
const secretKeyJwk = yield (0, jose_1.exportJWK)(cryptoKeyPair.privateKey); | ||
const jwkThumbprint = yield (0, jose_1.calculateJwkThumbprint)(secretKeyJwk); | ||
secretKeyJwk.kid = jwkThumbprint; | ||
secretKeyJwk.alg = alg; | ||
const privateKeyJwk = yield (0, jose_1.exportJWK)(cryptoKeyPair.privateKey); | ||
const jwkThumbprint = yield (0, jose_1.calculateJwkThumbprint)(privateKeyJwk); | ||
privateKeyJwk.kid = jwkThumbprint; | ||
privateKeyJwk.alg = alg; | ||
if (contentType === 'application/jwk+json') { | ||
return (0, formatJwk_1.formatJwk)(secretKeyJwk); | ||
return (0, formatJwk_1.formatJwk)(privateKeyJwk); | ||
} | ||
if (contentType === 'application/cose-key') { | ||
delete secretKeyJwk.kid; | ||
const secretKeyCoseKey = yield (0, convertJsonWebKeyToCoseKey_1.convertJsonWebKeyToCoseKey)(secretKeyJwk); | ||
delete privateKeyJwk.kid; | ||
const secretKeyCoseKey = yield (0, convertJsonWebKeyToCoseKey_1.convertJsonWebKeyToCoseKey)(privateKeyJwk); | ||
const coseKeyThumbprint = yield thumbprint_1.thumbprint.calculateCoseKeyThumbprint(secretKeyCoseKey); | ||
@@ -38,0 +38,0 @@ secretKeyCoseKey.set(2, coseKeyThumbprint); |
import { CoseKey } from "."; | ||
import { SecretKeyJwk } from "../sign1"; | ||
export declare const extracePublicKeyJwk: (secretKeyJwk: SecretKeyJwk) => { | ||
export declare const extracePublicKeyJwk: (privateKeyJwk: SecretKeyJwk) => { | ||
alg?: string | undefined; | ||
@@ -5,0 +5,0 @@ crv?: string | undefined; |
@@ -15,8 +15,8 @@ "use strict"; | ||
exports.publicFromPrivate = exports.extractPublicCoseKey = exports.extracePublicKeyJwk = void 0; | ||
const extracePublicKeyJwk = (secretKeyJwk) => { | ||
if (secretKeyJwk.kty !== 'EC') { | ||
const extracePublicKeyJwk = (privateKeyJwk) => { | ||
if (privateKeyJwk.kty !== 'EC') { | ||
throw new Error('Only EC keys are supported'); | ||
} | ||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
const { d, p, q, dp, dq, qi, key_ops } = secretKeyJwk, publicKeyJwk = __rest(secretKeyJwk, ["d", "p", "q", "dp", "dq", "qi", "key_ops"]); | ||
const { d, p, q, dp, dq, qi, key_ops } = privateKeyJwk, publicKeyJwk = __rest(privateKeyJwk, ["d", "p", "q", "dp", "dq", "qi", "key_ops"]); | ||
return publicKeyJwk; | ||
@@ -23,0 +23,0 @@ }; |
import { SecretKeyJwk } from '../cose/sign1'; | ||
declare const signer: ({ secretKeyJwk }: { | ||
secretKeyJwk: SecretKeyJwk; | ||
declare const signer: ({ privateKeyJwk }: { | ||
privateKeyJwk: SecretKeyJwk; | ||
}) => { | ||
@@ -5,0 +5,0 @@ sign: (toBeSigned: ArrayBuffer) => Promise<ArrayBuffer>; |
@@ -18,10 +18,10 @@ "use strict"; | ||
const getDigestFromVerificationKey_1 = __importDefault(require("../cose/sign1/getDigestFromVerificationKey")); | ||
const signer = ({ secretKeyJwk }) => { | ||
const digest = (0, getDigestFromVerificationKey_1.default)(`${secretKeyJwk.alg}`); | ||
const signer = ({ privateKeyJwk }) => { | ||
const digest = (0, getDigestFromVerificationKey_1.default)(`${privateKeyJwk.alg}`); | ||
return { | ||
sign: (toBeSigned) => __awaiter(void 0, void 0, void 0, function* () { | ||
const subtle = yield (0, subtleCryptoProvider_1.default)(); | ||
const signingKey = yield subtle.importKey("jwk", secretKeyJwk, { | ||
const signingKey = yield subtle.importKey("jwk", privateKeyJwk, { | ||
name: "ECDSA", | ||
namedCurve: secretKeyJwk.crv, | ||
namedCurve: privateKeyJwk.crv, | ||
}, true, ["sign"]); | ||
@@ -28,0 +28,0 @@ const signature = yield subtle.sign({ |
@@ -38,3 +38,2 @@ "use strict"; | ||
const x509 = __importStar(require("@peculiar/x509")); | ||
const uuid_1 = require("uuid"); | ||
const __1 = require(".."); | ||
@@ -79,5 +78,5 @@ const __2 = require(".."); | ||
const extensions = [ | ||
{ | ||
type: 'url', value: `urn:uuid:${(0, uuid_1.v4)()}` | ||
} | ||
// { | ||
// type: 'url', value: `https://vendor.example` | ||
// } | ||
]; | ||
@@ -111,7 +110,7 @@ const webCryptoAlgorithm = algTowebCryptoParams[req.alg]; | ||
} | ||
const secretKeyJwk = yield (0, jose_1.exportJWK)(yield (0, jose_1.importPKCS8)(privateKeyPKCS8, `${foundAlgorithm.Name}`)); | ||
secretKeyJwk.alg = foundAlgorithm.Name; | ||
const privateKeyJwk = yield (0, jose_1.exportJWK)(yield (0, jose_1.importPKCS8)(privateKeyPKCS8, `${foundAlgorithm.Name}`)); | ||
privateKeyJwk.alg = foundAlgorithm.Name; | ||
return __1.detached.signer({ | ||
remote: __2.crypto.signer({ | ||
secretKeyJwk | ||
privateKeyJwk | ||
}) | ||
@@ -118,0 +117,0 @@ }); |
{ | ||
"name": "@transmute/cose", | ||
"version": "0.2.6", | ||
"version": "0.2.7", | ||
"description": "COSE and related work.", | ||
@@ -5,0 +5,0 @@ "main": "./dist/index.js", |
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
318191
7863