Javascript/Typescript account creation tools for Radix DLT
npm install radix-account-tools-js
npm install --save-dev radix-account-tools-js
`
$3
You can update the package to the latest version using npm:
`
npm install radix-account-tools-js@latest
`
$3
I created 2 demo functions to illustrate how the code could be used in an application.
The demo functions are in the ./src/demo.ts file.
If you have installed the package in your project using npm, you can run the demo functions with the following command from your project folder:
`
npm run demo
`
Functions
$3
Generates a 12 word mnemonic phrase that can be used for account creation
#### inputs
None
#### outputs
string containing 12 words separated by a comma
$3
Generates a 24 word mnemonic phrase that can be used as a seed for account creation.
#### inputs
none
#### outputs
string: a string containing 24 words separated by a comma
$3
Creates several accounts from the provided mnomonic seed phrase and indices.
#### inputs
string: The mnemonic seed phrase as a string of comma separated words
number Array: The indices of the private/public key pairs to use for account creation. By setting the array to [0, 1, 2] you can access the first 3 accounts generated with that mnemonic seed phrase. If you want to access the 100th account, you can set the array to [99] without the need to access the previous 99 accounts.
number: The id number of the radix network for which to create the account (mainnet = 1, stokenet = 2)
#### outputs
AccountData Array: an array of objects with the account keys and address
#### example
`
// generates the first 3 accounts from the given 24 word mnemonic phrase.
// by setting the array to [0, 1, 2] you can access the first 3 accounts generated
// from that mnemonic phrase,
let new_accounts = await generateAccountsFromMnemonic(
"test seed diet dose potato arrive bar oxygen secret ordinary science
shaft cherry laptop timber tower online angle chest indicate mother
ticket match type",
[0, 1, 2],
0
);
`
$3
Creates an account from the provided private key bytes.
#### inputs
UInt8 Array: An array of bytes (numbers) that is used to generate a private key
number: The id number of the radix network for which to create the account (mainnet = 1, stokenet = 2)
#### outputs
AccountData: an object with the account keys and address
#### example
`
let new_account = await generateAccountFromPrivateKeyBytes(UintArray.from(
[
59, 221, 206, 186, 244, 250, 32, 61, 48, 35, 211, 187, 215, 144, 255, 221,
195, 4, 159, 158, 149, 222, 251, 113, 141, 82, 164, 202, 44, 150, 174, 79,
]
));
`
$3
Creates a private/public key pair from the provided provided mnemonic seed phrase and index.
#### inputs
string: The mnemonic seed phrase as a string of space separated words
number: The index of the private/public key pair to use for account creation. Example: to access the first account, set it to 0. To access the 100th account, set to 99.
number: The id number of the radix network for which to create the account (mainnet = 1, stokenet = 2)
number (optional: default = 525): The number representing the type of entity you want to create (account = 525, identity = 618)
#### outputs
KeyPair: an object with PrivateKey and PublicKey fields
#### example
`
// generates a private/public key pair for an account from the given 24 word mnemonic phrase with index 5
let new_keypair = generateKeyPair(
"test seed diet dose potato arrive bar oxygen secret ordinary science
shaft cherry laptop timber tower online angle chest indicate mother
ticket match type",
0,
0
);
`
$3
Derives an account address from the provided public key
#### inputs
PublicKey: The pulbic key to derive an account address from
number: The id number of the radix network for which to create the account (mainnet = 1, stokenet = 2)
#### outputs
string: the radix global address of the account
#### example
`
let accountData = await generateAccountFromMnemonic(
"test seed diet dose potato arrive bar oxygen secret ordinary science
shaft cherry laptop timber tower online angle chest indicate mother
ticket match type",
0,
0
)
// derives an account address from the provided public key
let account_address = await deriveAccountAddressFromPublicKey(
accountData.publicKey,
0
);
`
$3
Generates an Ed25519 private key from the provided bytes array
#### inputs
UInt8 Array: An array of bytes (numbers) that is used to generate a private key
#### outputs
PrivateKey: a private key object
#### example
`
let privateKey = await generateEd25519PrivateKey(UintArray.from(
[
59, 221, 206, 186, 244, 250, 32, 61, 48, 35, 211, 187, 215, 144, 255, 221,
195, 4, 159, 158, 149, 222, 251, 113, 141, 82, 164, 202, 44, 150, 174, 79,
]
));
`
$3
Generates a new account associated with the provided private key
#### inputs
PrivateKey: the private key to use for creating the account
number: The id number of the radix network for which to create the account (mainnet = 1, stokenet = 2)
#### outputs
AccountData: an object with the account keys and address
#### example
`
let newAccount = await generateVirtualAccount(
privateKey,
0
);
`
$3
Generates a hex seed from a mnemonic phrase
#### inputs
string: The mnemonic seed phrase as a string of space separated words
#### outputs
string: a hex string that can be used as the seed for account derivation
#### example
`
let hexSeed = mnemonicToSeed(
"test seed diet dose potato arrive bar oxygen secret ordinary science
shaft cherry laptop timber tower online angle chest indicate mother
ticket match type"
);
`
$3
derives private/public key data using the provided derivation path and hex seed
#### inputs
string: the derivation path used to determine the pay pair data
string: the hex seed string to use for the derivation
#### outputs
Keys: an object containing data used to derive private/public keys
#### example
`
let derivationPath =
m/44'/1022'/${networkId}'/${entityType}'/${KEY_TYPE.TRANSACTION_SIGNING}'/${entityIndex}'
let hexSeed = mnemonicToSeed(
"test seed diet dose potato arrive bar oxygen secret ordinary science
shaft cherry laptop timber tower online angle chest indicate mother
ticket match type"
);
let keyData = deriveKeyData(
derivationPath,
hexSeed,
);
``