How to use elliptic

Comprehensive elliptic code examples:

How to use elliptic.rand:

7906
7907
7908
7909
7910
7911
7912
7913
7914
// Instantiate Hmac_DRBG
var drbg = new HmacDRBG({
  hash: this.hash,
  pers: options.pers,
  persEnc: options.persEnc || 'utf8',
  entropy: options.entropy || elliptic.rand(this.hash.hmacStrength),
  entropyEnc: options.entropy && options.entropyEnc || 'utf8',
  nonce: this.n.toArray()
});

How to use elliptic.eddsa:

2
3
4
5
6
7
8
9
10
11
// Organize imports
const assert = require("assert")
const brorand = require("brorand")
const BN = require("bn.js")
const elliptic = require("elliptic");
const Ed25519 = elliptic.eddsa('ed25519');
const Secp256k1 = elliptic.ec('secp256k1');
const hashjs = require("hash.js");
const Sha512 = require("ripple-keypairs/dist/Sha512")
const { codec, encodeAccountPublic, encodeNodePublic } = require("ripple-address-codec");

How to use elliptic.curve:

20
21
22
23
24
25
26
27
28
29
    c: "1",
    g: ["2ef3f9b423a2c8c74e9803958f6c320e854a1c1c06cd5cc8fd221dc052d76df7",
        "05a01167ea785d3f784224644a68e4067532c815f5f6d57d984b5c0e9c6c94b7"]
}

const altBabyJubjub = new elliptic.curve.edwards(babyJubjubParams);

function sign(message, privateKey, curve) {
    const r = (new BN(elliptic.rand(32), 16, "be")).umod(curve.n);
    // const r = new BN(3);

How to use elliptic.utils:

8
9
10
11
12
13
14
15
16
17
const BN = require('bn.js')
const secp256k1 = require('secp256k1')
const sha256 = require('./crypto/digest').sha256
const digest = require('./crypto/digest')
const schnorr = require('./crypto/schnorr')
const utils = elliptic.utils
const strings = require('./utils/strings.js')
const xc = require('./crypto/xor.js')
const Log = require('./log.js')
const { randomBytes } = require('crypto')

How to use elliptic.curves:

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) {

How to use elliptic.ec:

13
14
15
16
17
18
19
20
21
22
23
24
25


const aesKey = require('./aes/pkcs11_key.js');
const ecdsaKey = require('./ecdsa/pkcs11_key.js');


const elliptic = require('elliptic');
const EC = elliptic.ec;


const jsrsa = require('jsrsasign');
const KEYUTIL = jsrsa.KEYUTIL;