@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; } }
@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(); }
@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; }
@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; } }
@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; } }