How to use the @tanker/identity.createIdentity function in @tanker/identity

To help you get started, we’ve selected a few @tanker/identity examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github TankerHQ / sdk-js / packages / core / src / __tests__ / UserAccessor.spec.js View on Github external
it('throws InvalidArgument as appropriate', async () => {
      const { users, builder, generator } = await makeTestUsers();
      await builder.newUserCreationV3('alice');
      await builder.newUserCreationV3('bob');
      const aliceIdentity = await createIdentity(utils.toBase64(generator.trustchainId), utils.toBase64(generator.appSignKeys.privateKey), 'alice');
      const bobIdentity = await createIdentity(utils.toBase64(generator.trustchainId), utils.toBase64(generator.appSignKeys.privateKey), 'bob');

      const casperUnregisteredIdentity = await createIdentity(utils.toBase64(generator.trustchainId), utils.toBase64(generator.appSignKeys.privateKey), 'casper');

      const publicIdentities = await toPublicIdentities([aliceIdentity, bobIdentity, casperUnregisteredIdentity]);
      await expect(users.getUsers({ publicIdentities })).to.be.rejectedWith(InvalidArgument);
    });
  });
github TankerHQ / sdk-js / packages / core / src / __tests__ / UserAccessor.spec.js View on Github external
it('throws InvalidArgument as appropriate', async () => {
      const { users, builder, generator } = await makeTestUsers();
      await builder.newUserCreationV3('alice');
      await builder.newUserCreationV3('bob');
      const aliceIdentity = await createIdentity(utils.toBase64(generator.trustchainId), utils.toBase64(generator.appSignKeys.privateKey), 'alice');
      const bobIdentity = await createIdentity(utils.toBase64(generator.trustchainId), utils.toBase64(generator.appSignKeys.privateKey), 'bob');

      const casperUnregisteredIdentity = await createIdentity(utils.toBase64(generator.trustchainId), utils.toBase64(generator.appSignKeys.privateKey), 'casper');

      const publicIdentities = await toPublicIdentities([aliceIdentity, bobIdentity, casperUnregisteredIdentity]);
      await expect(users.getUsers({ publicIdentities })).to.be.rejectedWith(InvalidArgument);
    });
  });
github TankerHQ / sdk-js / packages / functional-tests / src / start.js View on Github external
it('throws when having configured a non existing app', async () => {
      const nonExistentB64AppSecret = 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA==';
      const publicKey = 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=';
      const publicKeyBytes = utils.fromBase64(publicKey);
      const nonExistentB64AppId = utils.toBase64(utils.generateAppID(publicKeyBytes));
      const userId = 'bob';
      bobIdentity = await createIdentity(nonExistentB64AppId, nonExistentB64AppSecret, userId);
      bobLaptop = args.makeTanker(nonExistentB64AppId);
      await expect(bobLaptop.start(bobIdentity)).to.be.rejectedWith(errors.NetworkError, 'trustchain_not_found');
    });
github TankerHQ / sdk-js / packages / core / src / __tests__ / UserAccessor.spec.js View on Github external
it('throws InvalidArgument as appropriate', async () => {
      const { users, builder, generator } = await makeTestUsers();
      await builder.newUserCreationV3('alice');
      await builder.newUserCreationV3('bob');
      const aliceIdentity = await createIdentity(utils.toBase64(generator.trustchainId), utils.toBase64(generator.appSignKeys.privateKey), 'alice');
      const bobIdentity = await createIdentity(utils.toBase64(generator.trustchainId), utils.toBase64(generator.appSignKeys.privateKey), 'bob');

      const casperUnregisteredIdentity = await createIdentity(utils.toBase64(generator.trustchainId), utils.toBase64(generator.appSignKeys.privateKey), 'casper');

      const publicIdentities = await toPublicIdentities([aliceIdentity, bobIdentity, casperUnregisteredIdentity]);
      await expect(users.getUsers({ publicIdentities })).to.be.rejectedWith(InvalidArgument);
    });
  });
github TankerHQ / sdk-js / packages / core / src / __tests__ / LocalUser.spec.js View on Github external
beforeEach(async () => {
    testGenerator = new TestGenerator();
    trustchainCreation = testGenerator.makeTrustchainCreation();
    trustchainId = utils.toBase64(trustchainCreation.unverifiedTrustchainCreation.hash);
    trustchainKeyPair = trustchainCreation.trustchainKeys;
    identity = await createIdentity(trustchainId, utils.toBase64(trustchainKeyPair.privateKey), userIdString);
    userData = extractUserData(identity);

    trustchainCreationBlock = trustchainCreation.block;
    deviceCreation1 = await testGenerator.makeUserCreation(userData.userId);
    deviceCreation1Block = deviceCreation1.block;
    deviceCreation2 = testGenerator.makeDeviceCreation(deviceCreation1);
    deviceCreation2Block = deviceCreation2.block;

    const localData = {
      deviceSignatureKeyPair: deviceCreation2.testDevice.signKeys,
      deviceEncryptionKeyPair: deviceCreation2.testDevice.encryptionKeys,
      userKeys: {},
      currentUserKey: null,
      devices: [],
      deviceId: null,
      trustchainPublicKey: null
github TankerHQ / sdk-js / packages / core / src / __tests__ / SessionOpener.spec.js View on Github external
before(async () => {
      userIdString = 'clear user id';
      identity = await createIdentity(utils.toBase64(trustchainId), utils.toBase64(trustchainKeyPair.privateKey), userIdString);
      userData = extractUserData(identity);
    });
github TankerHQ / sdk-js / packages / functional-tests / src / Helpers.js View on Github external
generateIdentity(userId?: string): Promise {
    const id = userId || uuid.v4();
    return createIdentity(utils.toBase64(this.appId), utils.toBase64(this.appKeyPair.privateKey), id);
  }
github TankerHQ / sdk-js / packages / core / src / __tests__ / TestGenerator.js View on Github external
const delegationToken = createDelegationToken(userId, this._trustchainKeys.privateKey);
    const ghostDeviceKeys = generateGhostDeviceKeys();

    const { userCreationBlock, ghostDevice } = generateUserCreation(this._trustchainId, userId, deviceEncryptionKeyPair, deviceSignatureKeyPair, ghostDeviceKeys, delegationToken);
    const unverifiedDeviceCreation = ((userEntryFromBlock(userCreationBlock): any): DeviceCreationEntry);

    const privateUserKey = tcrypto.sealDecrypt(unverifiedDeviceCreation.user_key_pair.encrypted_private_encryption_key, ghostDeviceKeys.encryptionKeyPair);

    const testDevice: TestDevice = {
      id: unverifiedDeviceCreation.hash,
      signKeys: ghostDeviceKeys.signatureKeyPair,
      encryptionKeys: ghostDeviceKeys.encryptionKeyPair,
      revoked: false,
      isGhost: true,
    };
    const identity = await createIdentity(utils.toBase64(this._trustchainId), utils.toBase64(this._trustchainKeys.privateKey), utils.toBase64(userId));
    const publicIdentity = await getPublicIdentity(identity);

    const testUser: TestUser = {
      id: userId,
      userKeys: [{
        publicKey: unverifiedDeviceCreation.user_key_pair.public_encryption_key,
        privateKey: privateUserKey,
      }],
      devices: [testDevice],
      ghostDevice,
      identity,
      publicIdentity,
    };

    return {
      unverifiedDeviceCreation,
github TankerHQ / sdk-js / packages / verification-ui / example / index.js View on Github external
const email = getURIParameter('email');
const userId = uuid.v4();

if (!appId || !appSecret || !email) {
  const message = `You must run the example app from the following url: ${window.location.origin}?<b>appId</b>=appId&amp;<b>appSecret</b>=appSecret&amp;<b>email</b>=email, where <b>appId</b> and <b>appSecret</b> are a Tanker app ID and secret as obtained when creating an app in <a href="https://dashboard.tanker.io">the dashboard</a>, and <b>email</b> is a valid email address that will be used in this example to send verification emails to.`;

  const container = document.getElementById('root');
  if (container) {
    container.innerHTML = message;
    container.style.cssText = 'font-family: "Trebuchet MS", Helvetica, sans-serif; line-height: 1.5';
  }

  throw new Error(message);
}

createIdentity(appId, appSecret, userId).then(async identity =&gt; {
  const provisionalIdentity = await createProvisionalIdentity(appId, email);
  const tanker = new Tanker({ appId, url });
  const verificationUI = new VerificationUI(tanker);
  await verificationUI.start(email, identity, provisionalIdentity);
});
github TankerHQ / quickstart-examples / server / src / server.js View on Github external
if (user) {
    if (user.identity) {
      log(`Email ${email} already taken`, 1);
      res.status(409).json({ error: 'Email already taken' });
      return;
    }
  } else {
    user = { id: uuid(), email };
  }

  log('Hash the password', 1);
  user.hashed_password = auth.hashPassword(password);

  log('Generate a new Tanker identity', 1);
  user.identity = await createIdentity(
    appId,
    appSecret,
    user.id,
  );

  log('Save the user to storage', 1);
  app.storage.save(user);

  log('Save the userId in the session', 1);
  await session.regenerate(req);
  req.session.userId = user.id;

  log('Return the user', 1);
  res.set('Content-Type', 'application/json');
  res.status(201).json(await sanitizeUser(user));
}));