Skip to content

Commit

Permalink
0.0.5
Browse files Browse the repository at this point in the history
build
  • Loading branch information
tamaina committed Mar 6, 2024
1 parent 07574af commit 6649179
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 14 deletions.
10 changes: 5 additions & 5 deletions dist/index.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -363,9 +363,9 @@ function parsePublicKey(input) {
}
}
}
async function importPublicKey(key, keyUsages = ["verify"], defaults = defaultSignInfoDefaults) {
async function importPublicKey(key, keyUsages = ["verify"], defaults = defaultSignInfoDefaults, extractable = false) {
const parsedPublicKey = parsePublicKey(key);
return await (await getWebcrypto()).subtle.importKey("spki", parsedPublicKey.der, genSignInfo(parsedPublicKey, defaults), false, keyUsages);
return await (await getWebcrypto()).subtle.importKey("spki", parsedPublicKey.der, genSignInfo(parsedPublicKey, defaults), extractable, keyUsages);
}
async function parseAndImportPublicKey(source, keyUsages = ["verify"], providedAlgorithm, errorLogger) {
if (typeof source === "string" || typeof source === "object" && !("type" in source) && (source instanceof Uint8Array || source instanceof ArrayBuffer || Array.isArray(source) || "enc" in source)) {
Expand Down Expand Up @@ -514,10 +514,10 @@ function parsePkcs8(input) {
attributesRaw: attributes ? asn1ToArrayBuffer(attributes) : null
};
}
async function importPrivateKey(key, keyUsages = ["sign"], defaults = defaultSignInfoDefaults) {
async function importPrivateKey(key, keyUsages = ["sign"], defaults = defaultSignInfoDefaults, extractable = false) {
const parsedPrivateKey = parsePkcs8(key);
const importParams = genSignInfo(parsedPrivateKey, defaults);
return await (await getWebcrypto()).subtle.importKey("pkcs8", parsedPrivateKey.der, importParams, true, keyUsages);
return await (await getWebcrypto()).subtle.importKey("pkcs8", parsedPrivateKey.der, importParams, extractable, keyUsages);
}

// src/draft/sign.ts
Expand Down Expand Up @@ -575,7 +575,7 @@ function genDraftSigningString(request, includeHeaders, additional) {
return results.join("\n");
}
async function genDraftSignature(privateKey, signingString, defaults = defaultSignInfoDefaults) {
const signatureAB = await (await getWebcrypto()).subtle.sign(genAlgorithmForSignAndVerify(privateKey.algorithm, defaults), privateKey, new TextEncoder().encode(signingString));
const signatureAB = await (await getWebcrypto()).subtle.sign(genAlgorithmForSignAndVerify(privateKey.algorithm, defaults.hash), privateKey, new TextEncoder().encode(signingString));
return encodeArrayBufferToBase64(signatureAB);
}
function genDraftSignatureHeader(includeHeaders, keyId, signature, algorithm) {
Expand Down
10 changes: 5 additions & 5 deletions dist/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -261,9 +261,9 @@ function parsePublicKey(input) {
}
}
}
async function importPublicKey(key, keyUsages = ["verify"], defaults = defaultSignInfoDefaults) {
async function importPublicKey(key, keyUsages = ["verify"], defaults = defaultSignInfoDefaults, extractable = false) {
const parsedPublicKey = parsePublicKey(key);
return await (await getWebcrypto()).subtle.importKey("spki", parsedPublicKey.der, genSignInfo(parsedPublicKey, defaults), false, keyUsages);
return await (await getWebcrypto()).subtle.importKey("spki", parsedPublicKey.der, genSignInfo(parsedPublicKey, defaults), extractable, keyUsages);
}
async function parseAndImportPublicKey(source, keyUsages = ["verify"], providedAlgorithm, errorLogger) {
if (typeof source === "string" || typeof source === "object" && !("type" in source) && (source instanceof Uint8Array || source instanceof ArrayBuffer || Array.isArray(source) || "enc" in source)) {
Expand Down Expand Up @@ -412,10 +412,10 @@ function parsePkcs8(input) {
attributesRaw: attributes ? asn1ToArrayBuffer(attributes) : null
};
}
async function importPrivateKey(key, keyUsages = ["sign"], defaults = defaultSignInfoDefaults) {
async function importPrivateKey(key, keyUsages = ["sign"], defaults = defaultSignInfoDefaults, extractable = false) {
const parsedPrivateKey = parsePkcs8(key);
const importParams = genSignInfo(parsedPrivateKey, defaults);
return await (await getWebcrypto()).subtle.importKey("pkcs8", parsedPrivateKey.der, importParams, true, keyUsages);
return await (await getWebcrypto()).subtle.importKey("pkcs8", parsedPrivateKey.der, importParams, extractable, keyUsages);
}

// src/draft/sign.ts
Expand Down Expand Up @@ -473,7 +473,7 @@ function genDraftSigningString(request, includeHeaders, additional) {
return results.join("\n");
}
async function genDraftSignature(privateKey, signingString, defaults = defaultSignInfoDefaults) {
const signatureAB = await (await getWebcrypto()).subtle.sign(genAlgorithmForSignAndVerify(privateKey.algorithm, defaults), privateKey, new TextEncoder().encode(signingString));
const signatureAB = await (await getWebcrypto()).subtle.sign(genAlgorithmForSignAndVerify(privateKey.algorithm, defaults.hash), privateKey, new TextEncoder().encode(signingString));
return encodeArrayBufferToBase64(signatureAB);
}
function genDraftSignatureHeader(includeHeaders, keyId, signature, algorithm) {
Expand Down
2 changes: 1 addition & 1 deletion dist/pem/pkcs8.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,4 @@ export declare function parsePkcs8(input: ASN1.StreamOrBinary): ParsedPkcs8;
* @param defaults
* @returns CryptoKey
*/
export declare function importPrivateKey(key: ASN1.StreamOrBinary, keyUsages?: webcrypto.KeyUsage[], defaults?: SignInfoDefaults): Promise<webcrypto.CryptoKey>;
export declare function importPrivateKey(key: ASN1.StreamOrBinary, keyUsages?: webcrypto.KeyUsage[], defaults?: SignInfoDefaults, extractable?: boolean): Promise<webcrypto.CryptoKey>;
2 changes: 1 addition & 1 deletion dist/pem/spki.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ export declare function parsePublicKey(input: ASN1.StreamOrBinary): SpkiParsedAl
* @param defaults
* @returns CryptoKey
*/
export declare function importPublicKey(key: ASN1.StreamOrBinary, keyUsages?: webcrypto.KeyUsage[], defaults?: SignInfoDefaults): Promise<webcrypto.CryptoKey>;
export declare function importPublicKey(key: ASN1.StreamOrBinary, keyUsages?: webcrypto.KeyUsage[], defaults?: SignInfoDefaults, extractable?: boolean): Promise<webcrypto.CryptoKey>;
/**
* Prepare public key for verification
* @param source PEM, DER or CryptoKey
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@misskey-dev/node-http-message-signatures",
"version": "0.0.4",
"version": "0.0.5",
"description": "",
"type": "module",
"engines": {
Expand Down
2 changes: 1 addition & 1 deletion test/performance/draft.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { signAsDraftToRequest, parseRequestSignature, genRFC3230DigestHeader, ve
import { rsa4096, prime256v1, ed25519, ed448 } from '../keys.js';
import httpSignature from '@peertube/http-signature';

const TRYES = 1;
const TRYES = 1600;

const getBasicOutgoingRequest = () => ({
headers: {
Expand Down

0 comments on commit 6649179

Please sign in to comment.