MCPcopy Index your code
hub / github.com/nodejs/node / signVerify

Function signVerify

lib/internal/crypto/webcrypto.js:1156–1204  ·  view source on GitHub ↗
(algorithm, key, data, signature)

Source from the content-addressed store, hash-verified

1154}
1155
1156function signVerify(algorithm, key, data, signature) {
1157 const operation = signature !== undefined ? 'verify' : 'sign'; // This is also usage
1158 const normalizedAlgorithm = normalizeAlgorithm(algorithm, operation);
1159
1160 if (normalizedAlgorithm.name !== getCryptoKeyAlgorithm(key).name)
1161 throw lazyDOMException('Key algorithm mismatch', 'InvalidAccessError');
1162
1163 if (!hasCryptoKeyUsage(key, operation))
1164 throw lazyDOMException(
1165 `Unable to use this key to ${operation}`, 'InvalidAccessError');
1166
1167 switch (normalizedAlgorithm.name) {
1168 case 'RSA-PSS':
1169 // Fall through
1170 case 'RSASSA-PKCS1-v1_5':
1171 return require('internal/crypto/rsa')
1172 .rsaSignVerify(key, data, normalizedAlgorithm, signature);
1173 case 'ECDSA':
1174 return require('internal/crypto/ec')
1175 .ecdsaSignVerify(key, data, normalizedAlgorithm, signature);
1176 case 'Ed25519':
1177 // Fall through
1178 case 'Ed448':
1179 // Fall through
1180 return require('internal/crypto/cfrg')
1181 .eddsaSignVerify(key, data, normalizedAlgorithm, signature);
1182 case 'HMAC':
1183 return require('internal/crypto/mac')
1184 .hmacSignVerify(key, data, normalizedAlgorithm, signature);
1185 case 'ML-DSA-44':
1186 // Fall through
1187 case 'ML-DSA-65':
1188 // Fall through
1189 case 'ML-DSA-87':
1190 return require('internal/crypto/ml_dsa')
1191 .mlDsaSignVerify(key, data, normalizedAlgorithm, signature);
1192 case 'KMAC128':
1193 // Fall through
1194 case 'KMAC256':
1195 return require('internal/crypto/mac')
1196 .kmacSignVerify(key, data, normalizedAlgorithm, signature);
1197 /* c8 ignore start */
1198 default: {
1199 const assert = require('internal/assert');
1200 assert.fail('Unreachable code');
1201 }
1202 /* c8 ignore stop */
1203 }
1204}
1205
1206function sign(algorithm, key, data) {
1207 return callSubtleCryptoMethod(signImpl, this, arguments);

Callers 2

signImplFunction · 0.85
verifyImplFunction · 0.85

Calls 6

getCryptoKeyAlgorithmFunction · 0.85
lazyDOMExceptionFunction · 0.85
hasCryptoKeyUsageFunction · 0.85
normalizeAlgorithmFunction · 0.70
requireFunction · 0.50
failMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…