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

Function signMessage

vmm/src/x25519.js:1546–1563  ·  view source on GitHub ↗

* Signs the given message using the private key and returns a signed message (signature concatenated with the message copy). * * Optional random data argument (which must have 64 random bytes) turns on hash separation and randomization to make signatures non-deterministic. * * @e

(secretKey, msg, opt_random)

Source from the content-addressed store, hash-verified

1544 * @returns
1545 */
1546 function signMessage(secretKey, msg, opt_random) {
1547 checkArrayTypes(msg, secretKey);
1548 if (secretKey.length !== 32)
1549 throw new Error('wrong secret key length');
1550 if (opt_random) {
1551 checkArrayTypes(opt_random);
1552 if (opt_random.length !== 64)
1553 throw new Error('wrong random data length');
1554 var buf = new Uint8Array(128 + msg.length);
1555 curve25519_sign(buf, msg, msg.length, secretKey, opt_random);
1556 return new Uint8Array(buf.subarray(0, 64 + msg.length));
1557 }
1558 else {
1559 var signedMsg = new Uint8Array(64 + msg.length);
1560 curve25519_sign(signedMsg, msg, msg.length, secretKey);
1561 return signedMsg;
1562 }
1563 }
1564 /**
1565 * Verifies signed message with the public key and returns the original message without signature if it's correct or null if verification fails.
1566 *

Callers

nothing calls this directly

Calls 2

checkArrayTypesFunction · 0.70
curve25519_signFunction · 0.70

Tested by

no test coverage detected