How to use the curves function from elliptic

Find comprehensive JavaScript elliptic.curves code examples handpicked from public code repositorys.

elliptic.curves is a collection of elliptic curve objects that can be used to perform cryptographic operations in JavaScript using elliptic curve cryptography.

274
275
276
277
278
279
280
281
282
283
284
		'halfOrder': elliptic.curves.p256.n.shrn(1),
		'order': elliptic.curves.p256.n
	},
	'secp384r1': {
		'halfOrder': elliptic.curves.p384.n.shrn(1),
		'order': elliptic.curves.p384.n
	}
};


function _preventMalleability(sig, curveParams) {
fork icon524
star icon769
watch icon63

+ 71 other calls in file

119
120
121
122
123
124
125
126
127
128
hash.update(proposalBytes);
const digest = hash.digest('hex');
const privateKeyPEM = signerX509Identity.credentials.privateKey;
const { prvKeyHex } = KEYUTIL.getKey(privateKeyPEM); // convert the pem encoded key to hex encoded private key
const EC = elliptic.ec;
const ecdsaCurve = elliptic.curves.p256;
const ecdsa = new EC(ecdsaCurve);
const signKey = ecdsa.keyFromPrivate(prvKeyHex, 'hex');
let sig = ecdsa.sign(Buffer.from(digest, 'hex'), signKey);
sig = _preventMalleability(sig);
fork icon0
star icon0
watch icon1

+ 43 other calls in file

How does elliptic.curves work?

elliptic.curves is a collection of elliptic curve objects provided by the elliptic library, which can be used to perform cryptographic operations using elliptic curve cryptography in JavaScript.

When elliptic.curves is used, it provides a set of predefined elliptic curve objects, which can be used to perform cryptographic operations such as key generation, signing, and verification.

Each elliptic curve object contains a set of parameters that define the curve, including the field size, the equation defining the curve, and the coordinates of a base point on the curve.

By using elliptic curves for cryptographic operations, it is possible to achieve the same level of security as traditional cryptographic methods, but with smaller key sizes and faster computation times.

The elliptic library is often used in Node.js and browser-based applications to perform cryptographic operations, such as generating secure random numbers, signing and verifying digital signatures, and performing key exchanges.

179
180
181
182
183
184
185
186
187
188
189
190
// generates signatures properly in order to avoid massive rejection
// of transactions.


// map for easy lookup of the "N/2" value per elliptic curve
const halfOrdersForCurve = {
    'secp256r1': elliptic.curves.p256.n.shrn(1),
    'secp384r1': elliptic.curves.p384.n.shrn(1)
};


function _preventMalleability(sig, curveParams) {
fork icon0
star icon0
watch icon1

7868
7869
7870
7871
7872
7873
7874
7875
7876
7877

  options = elliptic.curves[options];
}

// Shortcut for `elliptic.ec(elliptic.curves.curveName)`
if (options instanceof elliptic.curves.PresetCurve)
  options = { curve: options };

this.curve = options.curve.curve;
this.n = this.curve.n;
fork icon0
star icon0
watch icon1

+ 2 other calls in file

Ai Example

1
2
3
4
5
6
7
const { ec } = require("elliptic");

const curve = new ec("secp256k1");
const keyPair = curve.genKeyPair();

console.log("Public key:", keyPair.getPublic("hex"));
console.log("Private key:", keyPair.getPrivate("hex"));

In this example, we're using require to load the elliptic library and get a reference to the ec (elliptic curve) object. We're then using the ec object to create a new curve object for the secp256k1 elliptic curve. We're using the genKeyPair method of the curve object to generate a new key pair, which consists of a public key and a private key. Finally, we're using console.log to output the hex-encoded public and private keys. When we run this code, we'll get output that looks something like this: vbnet Copy code