+ public URI getDeviceLinkUri() throws TimeoutException, IOException {
+ password = Util.getSecret(18);
+
+ accountManager = new SignalServiceAccountManager(URL, TRUST_STORE, username, password, USER_AGENT);
+ String uuid = accountManager.getNewDeviceUuid();
+
+ registered = false;
+ try {
+ return new URI("tsdevice:/?uuid=" + URLEncoder.encode(uuid, "utf-8") + "&pub_key=" + URLEncoder.encode(Base64.encodeBytesWithoutPadding(signalProtocolStore.getIdentityKeyPair().getPublicKey().serialize()), "utf-8"));
+ } catch (URISyntaxException e) {
+ // Shouldn't happen
+ return null;
+ }
+ }
+
+ public void finishDeviceLink(String deviceName) throws IOException, InvalidKeyException, TimeoutException, UserAlreadyExists {
+ signalingKey = Util.getSecret(52);
+ SignalServiceAccountManager.NewDeviceRegistrationReturn ret = accountManager.finishNewDeviceRegistration(signalProtocolStore.getIdentityKeyPair(), signalingKey, false, true, signalProtocolStore.getLocalRegistrationId(), deviceName);
+ deviceId = ret.getDeviceId();
+ username = ret.getNumber();
+ // TODO do this check before actually registering
+ if (userExists()) {
+ throw new UserAlreadyExists(username, getFileName());
+ }
+ signalProtocolStore = new JsonSignalProtocolStore(ret.getIdentity(), signalProtocolStore.getLocalRegistrationId());
+
+ registered = true;
+ refreshPreKeys();
+ }
+