diff --git a/examples/cryptopro-cades/package.json b/examples/cryptopro-cades/package.json
index 7bed9e9..91a0259 100644
--- a/examples/cryptopro-cades/package.json
+++ b/examples/cryptopro-cades/package.json
@@ -34,6 +34,6 @@
},
"scripts": {
"build:prod": "webpack --mode=production --config webpack.config.js",
- "dev": "webpack serve --mode=development"
+ "dev": "webpack serve --mode=development --port 8081"
}
}
diff --git a/examples/cryptopro-cades/public/index.html b/examples/cryptopro-cades/public/index.html
index 86683d7..d832c18 100644
--- a/examples/cryptopro-cades/public/index.html
+++ b/examples/cryptopro-cades/public/index.html
@@ -8,7 +8,7 @@
name="description"
content="Web site created using create-react-app"
/>
-
React App
+ @astral/cryptopro-cades
diff --git a/examples/cryptopro-cades/src/App.tsx b/examples/cryptopro-cades/src/App.tsx
index d148d34..5d27d2d 100644
--- a/examples/cryptopro-cades/src/App.tsx
+++ b/examples/cryptopro-cades/src/App.tsx
@@ -48,24 +48,35 @@ const CryptoApp = () => {
const systemInfo = await getSystemInfo();
setVersionInfo(systemInfo);
} catch (error) {
- window.alert(error);
+ outputError(error);
+ window.alert(error?.toString());
}
}
async function fetchCertificates() {
- const fetchedCertificates = await getCertificates(STORE_TYPE.ALL);
+ try {
+ const fetchedCertificates = await getCertificates(STORE_TYPE.ALL);
- setCertificates(fetchedCertificates);
+ setCertificates(fetchedCertificates);
- // автоматически берем первый валидный серт если еще выбран
- if (!selectedCertificate) {
- setSelectedCertificate(
- fetchedCertificates.find((c) => c.isGost && c.hasPrivateKey)
- );
+ // автоматически берем первый валидный серт если еще выбран
+ if (!selectedCertificate) {
+ setSelectedCertificate(
+ fetchedCertificates.find((c) => c.isGost && c.hasPrivateKey)
+ );
+ }
+ } catch (error) {
+ outputError(error);
+ window.alert(error?.toString());
}
}
async function fetchCryptoProviders() {
- const cryptoProviders = await getCryptoProviders();
- setCryptoProviders(cryptoProviders);
+ try {
+ const cryptoProviders = await getCryptoProviders();
+ setCryptoProviders(cryptoProviders);
+ } catch (error) {
+ outputError(error);
+ window.alert(error?.toString());
+ }
}
if (showCryptoProviders) {
diff --git a/package-lock.json b/package-lock.json
index f89993c..38e907a 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -3650,10 +3650,9 @@
"license": "MIT"
},
"node_modules/@types/node": {
- "version": "17.0.35",
- "resolved": "https://registry.npmjs.org/@types/node/-/node-17.0.35.tgz",
- "integrity": "sha512-vu1SrqBjbbZ3J6vwY17jBs8Sr/BKA+/a/WtjRG+whKg1iuLFOosq872EXS0eXWILdO36DHQQeku/ZcL6hz2fpg==",
- "license": "MIT"
+ "version": "17.0.36",
+ "resolved": "https://registry.npmjs.org/@types/node/-/node-17.0.36.tgz",
+ "integrity": "sha512-V3orv+ggDsWVHP99K3JlwtH20R7J4IhI1Kksgc+64q5VxgfRkQG8Ws3MFm/FZOKDYGy9feGFlZ70/HpCNe9QaA=="
},
"node_modules/@types/normalize-package-data": {
"version": "2.4.1",
@@ -3668,16 +3667,6 @@
"integrity": "sha512-//oorEZjL6sbPcKUaCdIGlIUeH26mgzimjBB77G6XRgnDl/L5wOnpyBGRe/Mmf5CVW3PwEBE1NjiMZ/ssFh4wA==",
"license": "MIT"
},
- "node_modules/@types/pkijs": {
- "version": "0.0.14",
- "resolved": "https://registry.npmjs.org/@types/pkijs/-/pkijs-0.0.14.tgz",
- "integrity": "sha512-i2T9mjyNjWLqpv1Zg5Odo54VOv191EoahE41E2IKwOcZjQqCGVySpouAB3Ty5GXa8lnHHH0/DvbqzfGOl6GK7w==",
- "dev": true,
- "dependencies": {
- "@types/pvutils": "*",
- "asn1js": "^3.0.2"
- }
- },
"node_modules/@types/prettier": {
"version": "2.6.1",
"resolved": "https://registry.npmjs.org/@types/prettier/-/prettier-2.6.1.tgz",
@@ -3691,12 +3680,6 @@
"integrity": "sha512-JCB8C6SnDoQf0cNycqd/35A7MjcnK+ZTqE7judS6o7utxUCg6imJg3QK2qzHKszlTjcj2cn+NwMB2i96ubpj7w==",
"license": "MIT"
},
- "node_modules/@types/pvutils": {
- "version": "1.0.1",
- "resolved": "https://registry.npmjs.org/@types/pvutils/-/pvutils-1.0.1.tgz",
- "integrity": "sha512-OwGyloDb4Gz7cKzFt1ZfHkNXbh1gxd5706hPF5ot4cvsa2EfbqY1tz2nWtu6xWDccNSZ16p/pi027gloQu4hsQ==",
- "dev": true
- },
"node_modules/@types/qs": {
"version": "6.9.7",
"resolved": "https://registry.npmjs.org/@types/qs/-/qs-6.9.7.tgz",
@@ -5062,10 +5045,9 @@
"license": "MIT"
},
"node_modules/asn1js": {
- "version": "3.0.4",
- "resolved": "https://registry.npmjs.org/asn1js/-/asn1js-3.0.4.tgz",
- "integrity": "sha512-ZibuNYyfODvHiVyRFs80xLAUjCwBSkLbE+r1TasjlRKwdodENGT4AlLdaN12Pl/EcK3lFMDYXU6lE2g7Sq9VVQ==",
- "license": "BSD-3-Clause",
+ "version": "3.0.5",
+ "resolved": "https://registry.npmjs.org/asn1js/-/asn1js-3.0.5.tgz",
+ "integrity": "sha512-FVnvrKJwpt9LP2lAMl8qZswRNm3T4q9CON+bxldk2iwk3FFpuwhx2FfinyitizWHsVYyaY+y5JzDR0rCMV5yTQ==",
"dependencies": {
"pvtsutils": "^1.3.2",
"pvutils": "^1.1.3",
@@ -6026,10 +6008,9 @@
}
},
"node_modules/bytestreamjs": {
- "version": "1.0.29",
- "resolved": "https://registry.npmjs.org/bytestreamjs/-/bytestreamjs-1.0.29.tgz",
- "integrity": "sha512-Mri3yqoo9YvdaSvD5OYl4Rdu9zCBJInW/Ez31sdlNY4ikMy//EvTTmidfLcs0e+NBvKVEpPzYvJAesjgMdjnZg==",
- "license": "BSD-3-Clause",
+ "version": "2.0.0",
+ "resolved": "https://registry.npmjs.org/bytestreamjs/-/bytestreamjs-2.0.0.tgz",
+ "integrity": "sha512-TyOlxeS92FcMOaJwAVq5gwqW0vfkWUv5W+ErwdbBzolcUN/9XYpCKWvCV21jjzXU550D9Wt4GgE8Pr1vVbR+wQ==",
"engines": {
"node": ">=6.0.0"
}
@@ -13780,17 +13761,18 @@
}
},
"node_modules/pkijs": {
- "version": "2.4.0",
- "resolved": "https://registry.npmjs.org/pkijs/-/pkijs-2.4.0.tgz",
- "integrity": "sha512-cjJP/mYuGyMrjJ49jI04khId5Oufd3nFTUYBzQTIIVNI7/oAWdwXEfpwTF8HELFV/gz+WGYUBHCe3KHWD8rYvg==",
- "license": "BSD-3-Clause",
+ "version": "3.0.3",
+ "resolved": "https://registry.npmjs.org/pkijs/-/pkijs-3.0.3.tgz",
+ "integrity": "sha512-36EZzEAZj/Wi53qM9GQNPWaQ2YX6P+xbkTwlkXNwoMkRetJafGpxxZpi41hCoLVS3bqzw7/Ws9g1pzkOILos7Q==",
"dependencies": {
- "asn1js": "^3.0.3",
- "bytestreamjs": "^1.0.29",
- "pvutils": "^1.1.3"
+ "asn1js": "^3.0.5",
+ "bytestreamjs": "^2.0.0",
+ "pvtsutils": "^1.3.2",
+ "pvutils": "^1.1.3",
+ "tslib": "^2.4.0"
},
"engines": {
- "node": ">=6.0.0"
+ "node": ">=12.0.0"
}
},
"node_modules/please-upgrade-node": {
@@ -17863,16 +17845,14 @@
},
"packages/cryptopro-cades": {
"name": "@astral/cryptopro-cades",
- "version": "1.0.3",
"dependencies": {
- "asn1js": "^3.0.2",
- "buffer": "^6.0.3",
- "pkijs": "^2.3.1"
+ "asn1js": "3.0.5",
+ "buffer": "6.0.3",
+ "pkijs": "3.0.3"
},
"devDependencies": {
- "@types/node": "^17.0.33",
- "@types/pkijs": "0.0.14",
- "copyfiles": "^2.4.1"
+ "@types/node": "17.0.36",
+ "copyfiles": "2.4.1"
}
}
},
@@ -18236,12 +18216,11 @@
"@astral/cryptopro-cades": {
"version": "file:packages/cryptopro-cades",
"requires": {
- "@types/node": "^17.0.33",
- "@types/pkijs": "0.0.14",
- "asn1js": "^3.0.2",
- "buffer": "^6.0.3",
- "copyfiles": "^2.4.1",
- "pkijs": "^2.3.1"
+ "@types/node": "17.0.36",
+ "asn1js": "3.0.5",
+ "buffer": "6.0.3",
+ "copyfiles": "2.4.1",
+ "pkijs": "3.0.3"
}
},
"@babel/code-frame": {
@@ -20282,9 +20261,9 @@
"dev": true
},
"@types/node": {
- "version": "17.0.35",
- "resolved": "https://registry.npmjs.org/@types/node/-/node-17.0.35.tgz",
- "integrity": "sha512-vu1SrqBjbbZ3J6vwY17jBs8Sr/BKA+/a/WtjRG+whKg1iuLFOosq872EXS0eXWILdO36DHQQeku/ZcL6hz2fpg=="
+ "version": "17.0.36",
+ "resolved": "https://registry.npmjs.org/@types/node/-/node-17.0.36.tgz",
+ "integrity": "sha512-V3orv+ggDsWVHP99K3JlwtH20R7J4IhI1Kksgc+64q5VxgfRkQG8Ws3MFm/FZOKDYGy9feGFlZ70/HpCNe9QaA=="
},
"@types/normalize-package-data": {
"version": "2.4.1",
@@ -20297,16 +20276,6 @@
"resolved": "https://registry.npmjs.org/@types/parse-json/-/parse-json-4.0.0.tgz",
"integrity": "sha512-//oorEZjL6sbPcKUaCdIGlIUeH26mgzimjBB77G6XRgnDl/L5wOnpyBGRe/Mmf5CVW3PwEBE1NjiMZ/ssFh4wA=="
},
- "@types/pkijs": {
- "version": "0.0.14",
- "resolved": "https://registry.npmjs.org/@types/pkijs/-/pkijs-0.0.14.tgz",
- "integrity": "sha512-i2T9mjyNjWLqpv1Zg5Odo54VOv191EoahE41E2IKwOcZjQqCGVySpouAB3Ty5GXa8lnHHH0/DvbqzfGOl6GK7w==",
- "dev": true,
- "requires": {
- "@types/pvutils": "*",
- "asn1js": "^3.0.2"
- }
- },
"@types/prettier": {
"version": "2.6.1",
"resolved": "https://registry.npmjs.org/@types/prettier/-/prettier-2.6.1.tgz",
@@ -20318,12 +20287,6 @@
"resolved": "https://registry.npmjs.org/@types/prop-types/-/prop-types-15.7.5.tgz",
"integrity": "sha512-JCB8C6SnDoQf0cNycqd/35A7MjcnK+ZTqE7judS6o7utxUCg6imJg3QK2qzHKszlTjcj2cn+NwMB2i96ubpj7w=="
},
- "@types/pvutils": {
- "version": "1.0.1",
- "resolved": "https://registry.npmjs.org/@types/pvutils/-/pvutils-1.0.1.tgz",
- "integrity": "sha512-OwGyloDb4Gz7cKzFt1ZfHkNXbh1gxd5706hPF5ot4cvsa2EfbqY1tz2nWtu6xWDccNSZ16p/pi027gloQu4hsQ==",
- "dev": true
- },
"@types/qs": {
"version": "6.9.7",
"resolved": "https://registry.npmjs.org/@types/qs/-/qs-6.9.7.tgz",
@@ -21237,9 +21200,9 @@
"integrity": "sha512-BSHWgDSAiKs50o2Re8ppvp3seVHXSRM44cdSsT9FfNEUUZLOGWVCsiWaRPWM1Znn+mqZ1OfVZ3z3DWEzSp7hRA=="
},
"asn1js": {
- "version": "3.0.4",
- "resolved": "https://registry.npmjs.org/asn1js/-/asn1js-3.0.4.tgz",
- "integrity": "sha512-ZibuNYyfODvHiVyRFs80xLAUjCwBSkLbE+r1TasjlRKwdodENGT4AlLdaN12Pl/EcK3lFMDYXU6lE2g7Sq9VVQ==",
+ "version": "3.0.5",
+ "resolved": "https://registry.npmjs.org/asn1js/-/asn1js-3.0.5.tgz",
+ "integrity": "sha512-FVnvrKJwpt9LP2lAMl8qZswRNm3T4q9CON+bxldk2iwk3FFpuwhx2FfinyitizWHsVYyaY+y5JzDR0rCMV5yTQ==",
"requires": {
"pvtsutils": "^1.3.2",
"pvutils": "^1.1.3",
@@ -21937,9 +21900,9 @@
"integrity": "sha512-/Nf7TyzTx6S3yRJObOAV7956r8cr2+Oj8AC5dt8wSP3BQAoeX58NoHyCU8P8zGkNXStjTSi6fzO6F0pBdcYbEg=="
},
"bytestreamjs": {
- "version": "1.0.29",
- "resolved": "https://registry.npmjs.org/bytestreamjs/-/bytestreamjs-1.0.29.tgz",
- "integrity": "sha512-Mri3yqoo9YvdaSvD5OYl4Rdu9zCBJInW/Ez31sdlNY4ikMy//EvTTmidfLcs0e+NBvKVEpPzYvJAesjgMdjnZg=="
+ "version": "2.0.0",
+ "resolved": "https://registry.npmjs.org/bytestreamjs/-/bytestreamjs-2.0.0.tgz",
+ "integrity": "sha512-TyOlxeS92FcMOaJwAVq5gwqW0vfkWUv5W+ErwdbBzolcUN/9XYpCKWvCV21jjzXU550D9Wt4GgE8Pr1vVbR+wQ=="
},
"cacheable-request": {
"version": "2.1.4",
@@ -27254,13 +27217,15 @@
}
},
"pkijs": {
- "version": "2.4.0",
- "resolved": "https://registry.npmjs.org/pkijs/-/pkijs-2.4.0.tgz",
- "integrity": "sha512-cjJP/mYuGyMrjJ49jI04khId5Oufd3nFTUYBzQTIIVNI7/oAWdwXEfpwTF8HELFV/gz+WGYUBHCe3KHWD8rYvg==",
+ "version": "3.0.3",
+ "resolved": "https://registry.npmjs.org/pkijs/-/pkijs-3.0.3.tgz",
+ "integrity": "sha512-36EZzEAZj/Wi53qM9GQNPWaQ2YX6P+xbkTwlkXNwoMkRetJafGpxxZpi41hCoLVS3bqzw7/Ws9g1pzkOILos7Q==",
"requires": {
- "asn1js": "^3.0.3",
- "bytestreamjs": "^1.0.29",
- "pvutils": "^1.1.3"
+ "asn1js": "^3.0.5",
+ "bytestreamjs": "^2.0.0",
+ "pvtsutils": "^1.3.2",
+ "pvutils": "^1.1.3",
+ "tslib": "^2.4.0"
}
},
"please-upgrade-node": {
diff --git a/packages/cryptopro-cades/package.json b/packages/cryptopro-cades/package.json
index cbd01ec..65e6a4a 100644
--- a/packages/cryptopro-cades/package.json
+++ b/packages/cryptopro-cades/package.json
@@ -13,13 +13,13 @@
"lint": "eslint ./src --fix --quiet"
},
"dependencies": {
- "buffer": "^6.0.3",
- "pkijs": "^2.3.1",
- "asn1js": "^3.0.2"
+ "buffer": "6.0.3",
+ "pkijs": "3.0.3",
+ "asn1js": "3.0.5"
},
"devDependencies": {
- "@types/node": "^17.0.33",
- "copyfiles": "^2.4.1"
+ "@types/node": "17.0.36",
+ "copyfiles": "2.4.1"
},
"version": "1.2.0"
}
\ No newline at end of file
diff --git a/packages/cryptopro-cades/src/Certificate.ts b/packages/cryptopro-cades/src/Certificate.ts
index 1c36715..ccca57d 100644
--- a/packages/cryptopro-cades/src/Certificate.ts
+++ b/packages/cryptopro-cades/src/Certificate.ts
@@ -1,3 +1,4 @@
+import { unwrap } from './api/internal/unwrap';
import { CAPICOM_ENCODING_TYPE } from './constants';
import { CryptoError } from './errors';
import { ICertificate } from './types';
@@ -157,49 +158,25 @@ export class Certificate {
}
const certificate = new Certificate(cert);
- if (cert.SubjectName instanceof Promise) {
- certificate.subjectName = await cert.SubjectName;
- certificate.thumbprint = await cert.Thumbprint;
- certificate.notAfter = await cert.ValidToDate;
- certificate.notBefore = await cert.ValidFromDate;
- certificate.certificateBase64Data = await cert.Export(
- CAPICOM_ENCODING_TYPE.CAPICOM_ENCODE_BASE64
+ certificate.subjectName = await unwrap(cert.SubjectName);
+ certificate.thumbprint = await unwrap(cert.Thumbprint);
+ certificate.notAfter = await unwrap(cert.ValidToDate);
+ certificate.notBefore = await unwrap(cert.ValidFromDate);
+ certificate.certificateBase64Data = await unwrap(
+ cert.Export(CAPICOM_ENCODING_TYPE.CAPICOM_ENCODE_BASE64)
+ );
+ try {
+ certificate.hasPrivateKey = await unwrap(cert.HasPrivateKey());
+ const oPrivateKey = await unwrap(cert.PrivateKey);
+ certificate.providerName = await unwrap(oPrivateKey.ProviderName);
+ certificate.providerType = await unwrap(oPrivateKey.ProviderType);
+ } catch (error) {
+ // ошибка не критична, просто создаем ошибку (в дебаге оно залогируется само)
+ CryptoError.createCadesError(
+ error,
+ `Ошибка получения информации о приватном ключе сертификата ${certificate.thumbprint}.`
);
- try {
- certificate.hasPrivateKey = await cert.HasPrivateKey();
- const oPrivateKey = await cert.PrivateKey;
- certificate.providerName = await oPrivateKey.ProviderName;
- certificate.providerType = await oPrivateKey.ProviderType;
- } catch (error) {
- // ошибка не критична, просто создаем ошибку (в дебаге оно залогируется само)
- CryptoError.createCadesError(
- error,
- `Ошибка получения информации о приватном ключе сертификата ${certificate.thumbprint}.`
- );
- certificate.hasPrivateKey = false;
- }
- } else {
- certificate.subjectName = cert.SubjectName;
- certificate.thumbprint = cert.Thumbprint as string;
- certificate.notAfter = cert.ValidToDate as Date;
- certificate.notBefore = cert.ValidFromDate as Date;
- certificate.certificateBase64Data = cert.Export(
- CAPICOM_ENCODING_TYPE.CAPICOM_ENCODE_BASE64
- );
-
- try {
- certificate.hasPrivateKey = cert.HasPrivateKey();
- const oPrivateKey = cert.PrivateKey;
- certificate.providerName = oPrivateKey.ProviderName;
- certificate.providerType = oPrivateKey.ProviderType;
- } catch (error) {
- // ошибка не критична, просто создаем ошибку (в дебаге оно залогируется само)
- CryptoError.createCadesError(
- error,
- `Ошибка получения информации о приватном ключе сертификата ${certificate.thumbprint}.`
- );
- certificate.hasPrivateKey = false;
- }
+ certificate.hasPrivateKey = false;
}
parseCertificate(certificate);
diff --git a/packages/cryptopro-cades/src/api/createObject.ts b/packages/cryptopro-cades/src/api/createObject.ts
index d1a4d20..7cb17f8 100644
--- a/packages/cryptopro-cades/src/api/createObject.ts
+++ b/packages/cryptopro-cades/src/api/createObject.ts
@@ -1,8 +1,8 @@
import { CryptoError } from '../errors';
-import { deasync } from '../utils';
import { afterPluginLoaded } from './internal/afterPluginLoaded';
import { canAsync } from './internal/canAsync';
+import { unwrap } from './internal/unwrap';
/**
* Создание криптографического объекта.
@@ -12,7 +12,7 @@ import { canAsync } from './internal/canAsync';
* @returns {Promise