Addresses Management

createAddress(password, saveKey = true)

It creates an address and saves the payload (by default) in the localStorage. If false is passed to the second parameter, the method does not save the payload in the localStorage.

Attention, the localStorage is not checked! In case of presence of a previous payload this will be overwritten. Carefully check the backup and write phases of the payloads in your app.

const scrypta = window.ScryptaCore
let password = 'AStrongPassword'
let payload = await scrypta.createAddress(password, false)
/*
{
"pub":"LLLjx7yV4nhUzSapBAHogb5BdgUR6VCB3o",
"api_secret":"33239857dbe3d37fd35b807578a0132b",
"key":"03097163386854cde5801aec574948e15b9e24c79da65414d4e5588e7140846165",
"prv":"SnvpeER7kdeMFGRimBzV5EJfX2ZfxmAQwin1qAHD2kXb8XRF983g",
"walletstore":"LLLjx7yV4nhUzSapBAHogb5BdgUR6VCB3o:d287884b4af9e3e844da643646cb17e364cffc018f3704dfe5db1e04429b6a26986c0151a1008403209e6087ba3eaf75c79544ea93437053f60eb527dabba4acee76fad8e9821c4ce3e5cc54e04b0baa100476fb6010a9c426f8372bc9a4f67297244737f9631e02655fff1f10d04fce8f22743b623f024144f1efc7bc91cc3604e8a87a8f080cde7ef140c9f2c1b93d6d5fe275293cc33e8adae78a63ce63e84250fa59e75fb016cb2f4b3871ed32e0e182b56ec4f6578065f782e961606b3e"
}
*/

Identity payload composition

  • pub: the newly generated public address.

  • api_secret: a "strong" key that can be used as an encryption key for information written in blockchain.

  • key: the public key of the newly generated address. This is necessary for the validation of written information and for the creation of Trustlinks.

  • prv: the private key of the address, used to spend the funds.

  • walletstore: the encrypted version of the payload, which must be saved by the user (in localStorage and separately)

buildWallet(password, pub, wallet, saveKey)

This method, which is normally invoked internally, is used to build the encrypted version of the wallet; that is what the createAddress method called walletstore. However it may be necessary to refer to this method in other contexts. As an example: it could be recalled if you want to change the password of your saved payload.

In this case you should proceed as follows:

const scrypta = window.ScryptaCore
let oldpassword = 'WeakPassword'
let newpassword = 'AStrongPassword'
let payload = await scrypta.readKey(oldpassword)
if(payload !== false){
scrypta.buildWallet(
newpassword,
payload.pub,
{
prv: payload.prv,
api_secret: payload.api_secret,
key: payload.key
},
true //Salva il wallet nel localStorage
}

As you can see, the public address is outside the identity payload, in fact it can be saved without compromising security: the public address is for consultation only.

The public key and the public address are two separate entities. The public address is obtained by having a double function of hash from the public key. The public key instead is obtained directly from the private key and is the one that allows the validation of written and signed information on the blockchain.

initAddress(address)

This method initializes the address, which means that an available IdaNode sends a minimal amount of LYRA to the initialized address. In the case of Scrypta's IdaNode the quantity is 0.05 LYRA. The answer you get from the IdaNode includes the TXID of the transaction.

const scrypta = window.ScryptaCore
let address = 'LLLjx7yV4nhUzSapBAHogb5BdgUR6VCB3o'
let init = await scrypta.initAddress(address)
/*
Risposta:
{
airdrop_tx: "202d34a32e0deaa897bddac60109b844f3be72d2511d56057dd15470f04b6252",
dapp_address: "LLLjx7yV4nhUzSapBAHogb5BdgUR6VCB3o"
}
*/

getPublicKey(privateWif)

This method allows you to recreate the public key of the address starting from its private key.

const scrypta = window.ScryptaCore
let prv = 'SnvpeER7kdeMFGRimBzV5EJfX2ZfxmAQwin1qAHD2kXb8XRF983g'
let key = scrypta.getPublicKey(prv)
/*
Risposta:
03097163386854cde5801aec574948e15b9e24c79da65414d4e5588e7140846165
*/

getAddressFromPubKey(pubKey)

This method allows you to re-create an address starting from its public key, useful for verifying that the public key actually corresponds to the address.

const scrypta = window.ScryptaCore
let key = '03097163386854cde5801aec574948e15b9e24c79da65414d4e5588e7140846165'
let address = await scrypta.getAddressFromPubKey(key)
/*
Risposta:
LLLjx7yV4nhUzSapBAHogb5BdgUR6VCB3o
*/