src/hub/registration.js
async function registerAccount(options) {
    options = options || {};
    const atlasClient = options.atlasClient || await AtlasClient.factory();
    const name = options.name || defaultName;
    const registrationId = libsignal.keyhelper.generateRegistrationId();
    const password = generatePassword();
    const signalingKey = generateSignalingKey();
    const response = await atlasClient.fetch('/v1/provision/account', {
        method: 'PUT',
        json: {
            signalingKey: signalingKey.toString('base64'),
            supportsSms: false,
            fetchesMessages: true,
            registrationId,
            name,
            password
        }
    });
    const addr = response.userId;
    const username = `${addr}.${response.deviceId}`;
    const identity = libsignal.keyhelper.generateIdentityKeyPair();
    await storage.clearSessionStore();
    await storage.removeOurIdentity();
    await storage.removeIdentity(addr);
    await storage.saveIdentity(addr, identity.pubKey);
    await storage.saveOurIdentity(identity);
    await storage.putState('addr', addr);
    await storage.putState('serverUrl', response.serverUrl);
    await storage.putState('deviceId', response.deviceId);
    await storage.putState('name', name);
    await storage.putState('username', username);
    await storage.putState('password', password);
    await storage.putState('registrationId', registrationId);
    await storage.putState('signalingKey', signalingKey);
    const sc = new SignalClient(username, password, response.serverUrl);
    await sc.registerKeys(await sc.generateKeys());
}
async function registerAccount(options) {
    options = options || {};
    const atlasClient = options.atlasClient || await AtlasClient.factory();
    const name = options.name || defaultName;
    const registrationId = libsignal.keyhelper.generateRegistrationId();
    const password = generatePassword();
    const signalingKey = generateSignalingKey();
    const response = await atlasClient.fetch('/v1/provision/account', {
        method: 'PUT',
        json: {
            signalingKey: signalingKey.toString('base64'),
            supportsSms: false,
            fetchesMessages: true,
            registrationId,
            name,
            password
        }
    });
    const addr = response.userId;
    const username = `${addr}.${response.deviceId}`;
    const identity = libsignal.keyhelper.generateIdentityKeyPair();
    await storage.clearSessionStore();
    await storage.removeOurIdentity();
    await storage.removeIdentity(addr);
    await storage.saveIdentity(addr, identity.pubKey);
    await storage.saveOurIdentity(identity);
    await storage.putState('addr', addr);
    await storage.putState('serverUrl', response.serverUrl);
    await storage.putState('deviceId', response.deviceId);
    await storage.putState('name', name);
    await storage.putState('username', username);
    await storage.putState('password', password);
    await storage.putState('registrationId', registrationId);
    await storage.putState('signalingKey', signalingKey);
    const sc = new SignalClient(username, password, response.serverUrl);
    await sc.registerKeys(await sc.generateKeys());
}
async function registerAccount ( options ) { options = options || { } ; const atlasClient = options . atlasClient || await AtlasClient . factory ( ) ; const name = options . name || defaultName ; const registrationId = libsignal . keyhelper . generateRegistrationId ( ) ; const password = generatePassword ( ) ; const signalingKey = generateSignalingKey ( ) ; const response = await atlasClient . fetch ( '/v1/provision/account' , { method : 'PUT' , json : { signalingKey : signalingKey . toString ( 'base64' ) , supportsSms : false , fetchesMessages : true , registrationId , name , password } } ) ; const addr = response . userId ; const username = ` ${ addr } ${ response . deviceId } ` ; const identity = libsignal . keyhelper . generateIdentityKeyPair ( ) ; await storage . clearSessionStore ( ) ; await storage . removeOurIdentity ( ) ; await storage . removeIdentity ( addr ) ; await storage . saveIdentity ( addr , identity . pubKey ) ; await storage . saveOurIdentity ( identity ) ; await storage . putState ( 'addr' , addr ) ; await storage . putState ( 'serverUrl' , response . serverUrl ) ; await storage . putState ( 'deviceId' , response . deviceId ) ; await storage . putState ( 'name' , name ) ; await storage . putState ( 'username' , username ) ; await storage . putState ( 'password' , password ) ; await storage . putState ( 'registrationId' , registrationId ) ; await storage . putState ( 'signalingKey' , signalingKey ) ; const sc = new SignalClient ( username , password , response . serverUrl ) ; await sc . registerKeys ( await sc . generateKeys ( ) ) ; }
Create a new identity key and create or replace the signal account.
Note that any existing devices asssociated with your account will be
purged as a result of this action.  This should only be used for new
accounts or when you need to start over.

@param {Object} [options]
@param {string} [options.name] - The public name to store in the signal server.
@param {AtlasClient} [options.atlasClient]
Create a new identity key and create or replace the signal account . Note that any existing devices asssociated with your account will be purged as a result of this action . This should only be used for new accounts or when you need to start over .