-
-
Notifications
You must be signed in to change notification settings - Fork 11
Working with ADM key pairs
The library offers to create new ADAMANT account — a passphrase, key pair (public key & private key), and ADAMANT address. Read more about ADAMANT account and key pair.
createNewPassphrase()
makeKeypairFromHash()
createHashFromPassphrase()
createKeypairFromPassphrase()
createAddressFromPublicKey()
Generates a new mnemonic passphrase consisting of English words.
-
Typing
function createNewPassphrase(): string;
-
Parameters
None.
-
Returns
A new, randomly generated passphrase, string.
-
Example
import { createNewPassphrase } from 'adamant-api' const passphrase = createNewPassphrase() console.log(passphrase) // 'apple banana...'
Creates a pair of public and private keys from the provided hash, using Sodium (NaCl).
-
Typing
function makeKeypairFromHash(hash: Buffer): { publicKey: Buffer, privateKey: Buffer };
-
Parameters
-
hash
— SHA-256 hash of passphrase, used to generate key pair. UsecreateHashFromPassphrase
to obtainhash
.
-
-
Returns
An object containing
publicKey
andprivateKey
of the key pair. -
Example
import { createHashFromPassphrase, makeKeypairFromHash } from 'adamant-api' const hash = createHashFromPassphrase('apple banana...') const keypair = makeKeypairFromHash(hash) console.log('The key pair:') console.log(keypair)
Generates an SHA-256 hash from a given passphrase.
-
Typing
function createHashFromPassphrase(passphrase: string): Buffer;
-
Parameters
-
passphrase
— A 12-word mnemonic passphrase, string.
-
-
Returns
The generated
hash
using thecrypto
library, Buffer. -
Example
import { createNewPassphrase, createHashFromPassphrase } from 'adamant-api' const passphrase = createNewPassphrase() const hash = createHashFromPassphrase(passphrase) console.log(`hash: ${hash.toString('hex')}`)
Creates public and private keys based on a provided passphrase using Sodium (NaCl).
-
Typing
function createKeypairFromPassphrase(passphrase: string): { publicKey: string, privateKey: string };
-
Parameters
-
passphrase
— A 12-word mnemonic passphrase, string.
-
-
Returns
An object containing the
publicKey
andprivateKey
of the key pair. -
Example
import { createKeypairFromPassphrase } from 'adamant-api' let keyPair try { keyPair = createKeypairFromPassphrase(process.env.PASSPHRASE) } catch (error) { console.log(`❌ Invalid passphrase. Error: ${error}`) process.exit(-1) } console.log('✅ The given passphrase is valid')
Derives an ADAMANT address from the given public key.
-
Typing
function createAddressFromPublicKey(publicKey: Buffer | string): `U${string}`;
-
Parameters
-
publicKey
— The public key of an account.
-
-
Returns
The derived ADAMANT address, string in format
U123...
. -
Example
import { createKeypairFromPassphrase, createAddressFromPublicKey } from 'adamant-api' const { publicKey } = createKeypairFromPassphrase(process.env.PASSPHRASE) const address = createAddressFromPublicKey(publicKey) console.log(`Your ADAMANT address: ${address}`)