How to use the @tanker/crypto.tcrypto.makeSignKeyPair function in @tanker/crypto

To help you get started, we’ve selected a few @tanker/crypto 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__ / Generator.js View on Github external
createUser(args: { userId: string, parentDevice?: GeneratorDevice, userKeys: tcrypto.SodiumKeyPair, nature: Nature}): CreateUserResult {
    const ephemeralKeys = tcrypto.makeSignKeyPair();
    const signKeys = tcrypto.makeSignKeyPair();
    const encryptionKeys = tcrypto.makeEncryptionKeyPair();

    const obfuscatedUserId = obfuscateUserId(this.trustchainId, args.userId);
    const delegationBuffer = utils.concatArrays(ephemeralKeys.publicKey, obfuscatedUserId);

    let authorPrivateKey = this.appSignKeys.privateKey;
    let author = this.root.entry.hash;
    if (args.parentDevice) {
      // A parent device exists so we are in the add Device case
      authorPrivateKey = args.parentDevice.signKeys.privateKey;
      author = args.parentDevice.id;
    }
    let userKeyPair = null;
    if (args.nature === NATURE.device_creation_v3) {
      userKeyPair = {
        public_encryption_key: args.userKeys.publicKey,
github TankerHQ / sdk-js / packages / core / src / __tests__ / Tanker.spec.js View on Github external
it('should throw when identity\'s trustchain does not match tanker\'s', async () => {
        const otherAppKeyPair = tcrypto.makeSignKeyPair();
        const otherAppId = utils.generateAppID(otherAppKeyPair.publicKey);
        const identity = await createIdentity(
          utils.toBase64(otherAppId),
          utils.toBase64(otherAppKeyPair.privateKey),
          userId,
        );
        await expect(tanker.start(identity)).to.be.rejectedWith(InvalidArgument);
      });
github TankerHQ / sdk-js / packages / core / src / __tests__ / GroupUpdater.spec.js View on Github external
beforeEach(async () => {
    builder = await makeTrustchainBuilder();
    groupStore = await makeMemoryGroupStore();

    provisionalUserKeys = {
      appSignatureKeyPair: tcrypto.makeSignKeyPair(),
      appEncryptionKeyPair: tcrypto.makeEncryptionKeyPair(),
      tankerSignatureKeyPair: tcrypto.makeSignKeyPair(),
      tankerEncryptionKeyPair: tcrypto.makeEncryptionKeyPair(),
    };
    publicProvisionalUser = {
      trustchainId: builder.generator.trustchainId,
      target: 'email',
      value: 'bob@mail.com',
      appSignaturePublicKey: provisionalUserKeys.appSignatureKeyPair.publicKey,
      appEncryptionPublicKey: provisionalUserKeys.appEncryptionKeyPair.publicKey,
      tankerSignaturePublicKey: provisionalUserKeys.tankerSignatureKeyPair.publicKey,
      tankerEncryptionPublicKey: provisionalUserKeys.tankerEncryptionKeyPair.publicKey,
    };
  });
github TankerHQ / sdk-js / packages / core / src / __tests__ / GroupUpdater.spec.js View on Github external
beforeEach(async () => {
    builder = await makeTrustchainBuilder();
    groupStore = await makeMemoryGroupStore();

    provisionalUserKeys = {
      appSignatureKeyPair: tcrypto.makeSignKeyPair(),
      appEncryptionKeyPair: tcrypto.makeEncryptionKeyPair(),
      tankerSignatureKeyPair: tcrypto.makeSignKeyPair(),
      tankerEncryptionKeyPair: tcrypto.makeEncryptionKeyPair(),
    };
    publicProvisionalUser = {
      trustchainId: builder.generator.trustchainId,
      target: 'email',
      value: 'bob@mail.com',
      appSignaturePublicKey: provisionalUserKeys.appSignatureKeyPair.publicKey,
      appEncryptionPublicKey: provisionalUserKeys.appEncryptionKeyPair.publicKey,
      tankerSignaturePublicKey: provisionalUserKeys.tankerSignatureKeyPair.publicKey,
      tankerEncryptionPublicKey: provisionalUserKeys.tankerEncryptionKeyPair.publicKey,
    };
  });
github TankerHQ / sdk-js / packages / core / src / __tests__ / LocalUser.spec.js View on Github external
before(async () => {
    trustchainKeyPair = tcrypto.makeSignKeyPair();
    trustchainId = utils.generateAppID(trustchainKeyPair.publicKey);
    userIdString = 'clear user id';
  });
github TankerHQ / sdk-js / packages / core / src / __tests__ / TestGenerator.js View on Github external
function createDelegationToken(userId: Uint8Array, trustchainPrivateKey: Uint8Array): DelegationToken {
  const ephemeralKeys = tcrypto.makeSignKeyPair();

  const delegationBuffer = utils.concatArrays(ephemeralKeys.publicKey, userId);

  return {
    ephemeral_private_signature_key: ephemeralKeys.privateKey,
    ephemeral_public_signature_key: ephemeralKeys.publicKey,
    user_id: userId,
    delegation_signature: tcrypto.sign(delegationBuffer, trustchainPrivateKey),
    last_reset: new Uint8Array(32),
  };
}
github TankerHQ / sdk-js / packages / core / src / LocalUser / UserCreation.js View on Github external
export const generateDeviceFromGhostDevice = (
  trustchainId: Uint8Array,
  userId: Uint8Array,
  deviceEncryptionKeyPair: tcrypto.SodiumKeyPair,
  deviceSignatureKeyPair: tcrypto.SodiumKeyPair,
  ghostDevice: GhostDevice,
  ghostDeviceId: Uint8Array,
  userKeys: tcrypto.SodiumKeyPair,
) => {
  const ephemeralKeys = tcrypto.makeSignKeyPair();
  const delegationBuffer = utils.concatArrays(ephemeralKeys.publicKey, userId);

  const encryptedUserKeyForNewDevice = tcrypto.sealEncrypt(
    userKeys.privateKey,
    deviceEncryptionKeyPair.publicKey
  );

  const payload = serializeUserDeviceV3({
    ephemeral_public_signature_key: ephemeralKeys.publicKey,
    user_id: userId,
    delegation_signature: tcrypto.sign(delegationBuffer, ghostDevice.privateSignatureKey),
    public_signature_key: deviceSignatureKeyPair.publicKey,
    public_encryption_key: deviceEncryptionKeyPair.publicKey,
    last_reset: new Uint8Array(tcrypto.HASH_SIZE),
    user_key_pair: {
      public_encryption_key: userKeys.publicKey,
github TankerHQ / sdk-js / packages / core / src / Session / LocalUser / ghostDevice.js View on Github external
export const generateGhostDeviceKeys = (): GhostDeviceKeys => ({
  encryptionKeyPair: tcrypto.makeEncryptionKeyPair(),
  signatureKeyPair: tcrypto.makeSignKeyPair(),
});
github TankerHQ / sdk-js / packages / core / src / Session / LocalUser / KeySafe.js View on Github external
export function generateKeySafe(): KeySafe {
  return {
    deviceId: null,
    signaturePair: tcrypto.makeSignKeyPair(),
    encryptionPair: tcrypto.makeEncryptionKeyPair(),
    provisionalUserKeys: {},
    devices: [],
    trustchainPublicKey: null,
    localUserKeys: null,
  };
}