Accounts

Creation

Create an account from seed

1
$seedText = "manage manual recall harvest series desert melt police rose hollow moral pledge kitten position add";
2
3
$factory = new LTO\AccountFactory('T'); // 'T' for testnet, 'L' for mainnet
4
$account = $factory->seed($seedText);
Copied!

Create an account from private sign key

1
$secretKey = 'wJ4WH8dD88fSkNdFQRjaAhjFUZzZhV5yiDLDwNUnp6bYwRXrvWV8MJhQ9HL9uqMDG1n7XpTGZx7PafqaayQV8Rp';
2
3
$factory = new LTO\AccountFactory('T'); // 'T' for testnet, 'L' for mainnet
4
$account = $factory->create($secretKey);
Copied!

Create an account from full info

1
$accountInfo = [
2
'address' => '3PLSsSDUn3kZdGe8qWEDak9y8oAjLVecXV1',
3
'sign' => [
4
'secretkey' => 'wJ4WH8dD88fSkNdFQRjaAhjFUZzZhV5yiDLDwNUnp6bYwRXrvWV8MJhQ9HL9uqMDG1n7XpTGZx7PafqaayQV8Rp',
5
'publickey' => 'FkU1XyfrCftc4pQKXCrrDyRLSnifX1SMvmx1CYiiyB3Y'
6
],
7
'encrypt' => [
8
'secretkey' => 'BnjFJJarge15FiqcxrB7Mzt68nseBXXR4LQ54qFBsWJN',
9
'publickey' => 'BVv1ZuE3gKFa6krwWJQwEmrLYUESuUabNCXgYTmCoBt6'
10
]
11
];
12
13
$factory = new LTO\AccountFactory('T'); // 'T' for testnet, 'L' for mainnet
14
$account = $factory->create($accountInfo);
Copied!
Properties that are specified will be verified. Properties that are omitted will be generated where possible.

Signing (ED25519)

Sign a message

1
$signature = $account->sign('hello world'); // Base58 encoded signature
Copied!

Verify a signature

1
if (!$account->verify($signature, 'hello world')) {
2
throw new RuntimeException('invalid signature');
3
}
Copied!

Encryption (X25519)

Encrypt a message for another account

1
$message = 'hello world';
2
3
$recipientPublicKey = "HBqhfdFASRQ5eBBpu2y6c6KKi1az6bMx8v1JxX4iW1Q8"; // base58 encoded X25519 public key
4
$recipient = $factory->createPublic(null, $recipientPublicKey);
5
6
$cyphertext = $account->encryptFor($recipient, $message); // Raw binary, not encoded
Copied!
You can use $account->encryptFor($account, $message) to encrypt a message for yourself.

Decrypt a message received from another account

1
$senderPublicKey = "HBqhfdFASRQ5eBBpu2y6c6KKi1az6bMx8v1JxX4iW1Q8"; // base58 encoded X25519 public key
2
$sender = $factory->createPublic(null, $senderPublicKey);
3
4
$message = $account->decryptFrom($sender, $cyphertext);
Copied!
You can use $account->decryptFrom($account, $message) to decrypt a message from yourself.
Last modified 6mo ago