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

Function testSign

test/parallel/test-webcrypto-sign-verify-eddsa.js:152–253  ·  view source on GitHub ↗
({ name,
                          context,
                          publicKeyBuffer,
                          privateKeyBuffer,
                          signature,
                          data })

Source from the content-addressed store, hash-verified

150}
151
152async function testSign({ name,
153 context,
154 publicKeyBuffer,
155 privateKeyBuffer,
156 signature,
157 data }) {
158 const [
159 publicKey,
160 privateKey,
161 hmacKey,
162 rsaKeys,
163 ecKeys,
164 ] = await Promise.all([
165 subtle.importKey(
166 'spki',
167 publicKeyBuffer,
168 { name },
169 false,
170 ['verify']),
171 subtle.importKey(
172 'pkcs8',
173 privateKeyBuffer,
174 { name },
175 false,
176 ['sign']),
177 subtle.generateKey(
178 { name: 'HMAC', hash: 'SHA-256' },
179 false,
180 ['sign']),
181 subtle.generateKey(
182 {
183 name: 'RSA-PSS',
184 modulusLength: 1024,
185 publicExponent: new Uint8Array([1, 0, 1]),
186 hash: 'SHA-256',
187 },
188 false,
189 ['sign']),
190 subtle.generateKey(
191 {
192 name: 'ECDSA',
193 namedCurve: 'P-256'
194 },
195 false,
196 ['sign']),
197 ]);
198
199 {
200 const sig = await subtle.sign({ name, context }, privateKey, data);
201 assert.strictEqual(sig.byteLength, signature.byteLength);
202 assert(await subtle.verify({ name, context }, publicKey, sig, data));
203 if (context?.byteLength !== undefined) {
204 if (supportsContext) {
205 assert(!(await subtle.verify({ name, context: crypto.randomBytes(30) }, publicKey, signature, data)));
206 }
207 if (context.byteLength === 0) {
208 assert(await subtle.verify({ name }, publicKey, signature, data));
209 }

Calls 4

allMethod · 0.80
assertFunction · 0.50
verifyMethod · 0.45
fromMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…