MCPcopy Create free account
hub / github.com/Dstack-TEE/dstack / sign

Function sign

vmm/src/x25519.js:1596–1611  ·  view source on GitHub ↗

* Signs the given message using the private key and returns signature. * * Optional random data argument (which must have 64 random bytes) turns on hash separation and randomization to make signatures non-deterministic. * * @export * @param {Uint8Array} secretKey * @par

(secretKey, msg, opt_random)

Source from the content-addressed store, hash-verified

1594 * @returns
1595 */
1596 function sign(secretKey, msg, opt_random) {
1597 checkArrayTypes(secretKey, msg);
1598 if (secretKey.length !== 32)
1599 throw new Error('wrong secret key length');
1600 if (opt_random) {
1601 checkArrayTypes(opt_random);
1602 if (opt_random.length !== 64)
1603 throw new Error('wrong random data length');
1604 }
1605 var buf = new Uint8Array((opt_random ? 128 : 64) + msg.length);
1606 curve25519_sign(buf, msg, msg.length, secretKey, opt_random);
1607 var signature = new Uint8Array(64);
1608 for (var i = 0; i < signature.length; i++)
1609 signature[i] = buf[i];
1610 return signature;
1611 }
1612 /**
1613 * Verifies the given signature for the message using the given private key. Returns true if the signature is valid, false otherwise.
1614 *

Callers

nothing calls this directly

Calls 2

checkArrayTypesFunction · 0.70
curve25519_signFunction · 0.70

Tested by

no test coverage detected