deriveKeyPair function
Generate a keypair using a derivation function with a seed and an index. Each keys is prepending with a curve identification.
seed
: Keypair derivation seedindex
: Number to identify the order of keys to generatecurve
: Elliptic curve to use ("P256", "secp256k1", "ed25519")originId
: Origin id of the public key (0, 1, 2) = ("on chain wallet", "software", "tpm")
Implementation
KeyPair deriveKeyPair(
String seed,
int index, {
String curve = 'ed25519',
bool isSeedHexa = true,
int originId = softwareId,
}) {
if (index < 0) {
throw "index' must be a positive number";
}
final pvBuf = derivePrivateKey(seed, index, isSeedHexa: isSeedHexa);
return generateDeterministicKeyPair(pvBuf, curve, originId);
}