Пример #1
0
  @Override
  public boolean removeMetadataBlob(
      UserPublicKey owner, byte[] encodedWritingPublicKey, byte[] writingKeySignedMapKeyPlusBlob) {
    UserPublicKey writingKey = new UserPublicKey(encodedWritingPublicKey);

    try {
      byte[] payload = writingKey.unsignMessage(writingKeySignedMapKeyPlusBlob);
      byte[] mapKey = Arrays.copyOfRange(payload, 0, 32);
      byte[] metadataBlob =
          Arrays.copyOfRange(
              payload,
              32,
              payload
                  .length); // will be zero length for now // TODO  change to the current blob hash
      MetadataBlob blob = new MetadataBlob(writingKey.getPublicKeys(), mapKey, metadataBlob);
      return blob.delete();
    } catch (TweetNaCl.InvalidSignatureException e) {
      System.err.println(
          "Invalid signature during removeMetadataBlob for owner: "
              + owner
              + " and sharer: "
              + writingKey);
      return false;
    }
  }
Пример #2
0
 @Override
 public boolean setStaticData(UserPublicKey owner, byte[] signedStaticData) {
   try {
     StaticData userData =
         new StaticData(owner.getPublicKeys(), owner.unsignMessage(signedStaticData));
     return userData.insert();
   } catch (TweetNaCl.InvalidSignatureException e) {
     System.err.println("Invalid signature setting static data for: " + owner);
     return false;
   }
 }
Пример #3
0
  @Override
  public boolean addUsername(
      String username, byte[] encodedUserKey, byte[] signed, byte[] staticData) {
    UserPublicKey key = new UserPublicKey(encodedUserKey);

    if (!key.isValidSignature(
        signed, ArrayOps.concat(username.getBytes(), encodedUserKey, staticData))) return false;

    UserPublicKey existingKey = getPublicKey(username);
    if (existingKey != null) return false;
    String existingUsername = getUsername(key.getPublicKeys());
    if (existingUsername.length() > 0) return false;

    UserData user = new UserData(username, key.getPublicKeys());
    return user.insert();
  }
Пример #4
0
 @Override
 public byte[] getStaticData(UserPublicKey owner) {
   byte[] dummy = null;
   StaticData staticData = new StaticData(owner.getPublicKeys(), dummy);
   RowData[] users = staticData.select();
   if (users == null || users.length != 1) return null;
   return users[0].data;
 }
Пример #5
0
  @Override
  public boolean setMetadataBlob(
      UserPublicKey owner, byte[] encodedWritingPublicKey, byte[] writingKeySignedMapKey) {
    UserPublicKey writingKey = new UserPublicKey(encodedWritingPublicKey);

    try {
      byte[] payload = writingKey.unsignMessage(writingKeySignedMapKey);
      byte[] mapKey = Arrays.copyOfRange(payload, 0, 32);
      byte[] metadataBlob = Arrays.copyOfRange(payload, 32, payload.length);
      MetadataBlob blob = new MetadataBlob(writingKey.getPublicKeys(), mapKey, metadataBlob);
      return blob.insert();
    } catch (TweetNaCl.InvalidSignatureException e) {
      System.err.println(
          "Invalid signature during setMetadataBlob for owner: "
              + owner
              + " and sharer: "
              + writingKey);
      return false;
    }
  }
Пример #6
0
  @Override
  public boolean removeFollowRequest(UserPublicKey owner, byte[] req) {
    try {
      byte[] unsigned = owner.unsignMessage(req);

      FollowRequestData request = new FollowRequestData(owner, unsigned);
      return request.delete();
    } catch (TweetNaCl.InvalidSignatureException e) {
      return false;
    }
  }
Пример #7
0
 FollowRequestData(UserPublicKey owner, byte[] publicKey) {
   super(owner.toString(), publicKey);
 }