How to use the @tanker/crypto.utils.fromString 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__ / UsersSerialize.js View on Github external
it('should serialize/unserialize a UserDeviceV3', async () => {
    const ephemeralKeys = tcrypto.makeSignKeyPair();
    const signatureKeys = tcrypto.makeSignKeyPair();
    const encryptionKeys = tcrypto.makeEncryptionKeyPair();
    const userDevice = {
      last_reset: new Uint8Array(tcrypto.HASH_SIZE),
      ephemeral_public_signature_key: ephemeralKeys.publicKey,
      user_id: utils.fromString('12341234123412341234123412341234'),
      delegation_signature: utils.fromString('1234123412341234123412341234123412341234123412341234123412341234'),
      public_signature_key: signatureKeys.publicKey,
      public_encryption_key: encryptionKeys.publicKey,
      user_key_pair: {
        public_encryption_key: makeUint8Array('user pub enc key', tcrypto.ENCRYPTION_PUBLIC_KEY_SIZE),
        encrypted_private_encryption_key: makeUint8Array('user enc priv key', tcrypto.SEALED_KEY_SIZE),
      },
      is_ghost_device: true,
      revoked: Number.MAX_SAFE_INTEGER,
    };

    expect(unserializeUserDeviceV3(serializeUserDeviceV3(userDevice))).to.deep.equal(userDevice);
  });
github TankerHQ / sdk-js / packages / functional-tests / src / encrypt.js View on Github external
it('throws when decrypting using a session in an invalid state', async () => {
      await expect(bobLaptop.decrypt(utils.fromString('test'))).to.be.rejectedWith(errors.PreconditionFailed);
    });
  });
github TankerHQ / sdk-js / packages / core / src / __tests__ / UsersSerialize.js View on Github external
it('should throw if the last reset is not null when serializing a new userDeviceV3', async () => {
    const ephemeralKeys = tcrypto.makeSignKeyPair();
    const signatureKeys = tcrypto.makeSignKeyPair();
    const encryptionKeys = tcrypto.makeEncryptionKeyPair();
    const userDevice = {
      last_reset: new Uint8Array(Array.from({ length: tcrypto.HASH_SIZE }, () => 1)),
      ephemeral_public_signature_key: ephemeralKeys.publicKey,
      user_id: utils.fromString('12341234123412341234123412341234'),
      delegation_signature: utils.fromString('1234123412341234123412341234123412341234123412341234123412341234'),
      public_signature_key: signatureKeys.publicKey,
      public_encryption_key: encryptionKeys.publicKey,
      user_key_pair: {
        public_encryption_key: makeUint8Array('user pub enc key', tcrypto.ENCRYPTION_PUBLIC_KEY_SIZE),
        encrypted_private_encryption_key: makeUint8Array('user enc priv key', tcrypto.SEALED_KEY_SIZE),
      },
      is_ghost_device: true,
      revoked: Number.MAX_SAFE_INTEGER,
    };

    expect(() => serializeUserDeviceV3(userDevice)).to.throw();
  });
github TankerHQ / sdk-js / packages / core / src / DataProtection / __tests__ / EncryptorStream.spec.js View on Github external
before(() => {
    key = utils.fromString('12345678123456781234567812345678');
    resourceId = random(tcrypto.MAC_SIZE);
  });
github TankerHQ / sdk-js / packages / core / src / Tanker.js View on Github external
async encrypt(plain: string, options?: $Shape & ProgressOptions>): Promise {
    this.assert(statuses.READY, 'encrypt');

    if (typeof plain !== 'string')
      throw new InvalidArgument('plain', 'string', plain);

    return this.encryptData(utils.fromString(plain), options);
  }
github TankerHQ / sdk-js / packages / core / src / CloudStorage / CloudStorageManager.js View on Github external
async _encryptAndShareMetadata(metadata: Object, b64ResourceId: b64string): Promise {
    const jsonMetadata = JSON.stringify(metadata);
    const clearMetadata = utils.fromString(jsonMetadata);
    const encryptedMetadata = await this._dataProtector.encryptData(clearMetadata, {}, { type: Uint8Array }, {}, b64ResourceId);
    return utils.toBase64(encryptedMetadata);
  }
github TankerHQ / sdk-js / packages / core / src / Unlock / unlock.js View on Github external
unlockKey,
  userSecret,
  privateSigKey
}: CreateUnlockKeyMessageParams): Promise {
  const message = {
    trustchainId,
    deviceId,
    claims: {},
    signature: new Uint8Array(0)
  };
  if (email)
    message.claims.email = utils.fromString(email);
  if (password)
    message.claims.password = generichash(utils.fromString(password));
  if (unlockKey)
    message.claims.unlockKey = EncryptorV2.encrypt(userSecret, utils.fromString(unlockKey));

  const buff = getSignData(message);
  message.signature = tcrypto.sign(buff, privateSigKey);
  return message;
}