In EOS the account name (address) is a separate concept from the pub/priv keys. In EOS an account can have multiple keys associate with it, by default there is an Owner and Active key that all accounts need when they are created. Additionally the keys can be changed if the user suspects they have been compromised.
Standard account names are 12 digits and only the following characters are allowed:
'.12345abcdefghijklmnopqrstuvwxyz'
This is done so that all account names can be encoded into a uint64_t
If you wanted to tie the public key into the account name, one idea would be to take the first 8 bytes of the pub key buffer and use that as your account name.
You can look at decodeName
and decodeNameHex
methods from
eosjs format.test as an example for converting a 64 byte value into an EOS account name
==================
Update Answer
To create an Account requires three actions:
- newaccount
- buyrambytes
- delegatebw
Below is an example using eosjs
const wif = '5JBNSUbD4anpFFe3CbURTBtbpbUGLGtVUatDd1uL1i1HbjZjqGd';
const fetch = require('node-fetch');
const { TextDecoder, TextEncoder } = require('util');
const { Api, JsonRpc } = require('eosjs');
const rpc = new JsonRpc('https://eos.greymass.com', { fetch });
const signatureProvider = new JsSignatureProvider([wif]);
const api = new Api({ rpc, signatureProvider, textDecoder: new TextDecoder(), textEncoder: new TextEncoder() });
const transaction: IEosTransactionResult = await api.transact({
actions: [{
account: 'eosio',
name: 'newaccount',
authorization: [{
actor: accountCreator,
permission: 'active',
}],
data: {
creator: accountCreator,
name: accountName,
owner: {
threshold: 1,
keys: [{
key: pubKeyOwner,
weight: 1
}],
accounts: [],
waits: []
},
active: {
threshold: 1,
keys: [{
key: pubKeyActive,
weight: 1
}],
accounts: [],
waits: []
},
},
},
{
account: 'eosio',
name: 'buyrambytes',
authorization: [{
actor: accountCreator,
permission: 'active',
}],
data: {
payer: accountCreator,
receiver: accountName,
bytes: 8192,
},
},
{
account: 'eosio',
name: 'delegatebw',
authorization: [{
actor: accountCreator,
permission: 'active',
}],
data: {
from: accountCreator,
receiver: accountName,
stake_net_quantity: '1.0000 EOS',
stake_cpu_quantity: '1.0000 EOS',
transfer: false,
}
}]
}, {
blocksBehind: 3,
expireSeconds: 30,
});