diff --git a/.idea/sqldialects.xml b/.idea/sqldialects.xml index f682500..9d2b463 100644 --- a/.idea/sqldialects.xml +++ b/.idea/sqldialects.xml @@ -3,10 +3,13 @@ + + + diff --git a/src/Socialbox/Classes/Resources/database/contact_known_keys.sql b/src/Socialbox/Classes/Resources/database/contact_known_keys.sql new file mode 100644 index 0000000..9304131 --- /dev/null +++ b/src/Socialbox/Classes/Resources/database/contact_known_keys.sql @@ -0,0 +1,20 @@ +create table contacts_known_keys +( + contact_uuid varchar(36) not null comment 'The UUID of the contact in reference to', + key_name varchar(64) not null comment 'The name of the key', + public_key varchar(64) not null comment 'The public signing key', + expires timestamp not null comment 'The Timestamp for when this key expires', + trusted_at timestamp default current_timestamp() not null comment 'The Timestamp for when this signing key was trusted', + primary key (contact_uuid, key_name) comment 'The unique key-name pair with the contact uuid to ensure no keys with the same names should exist', + constraint contacts_known_keys_contact_uuid_key_name_uindex + unique (contact_uuid, key_name) comment 'The unique key-name pair with the contact uuid to ensure no keys with the same names should exist', + constraint contacts_known_keys_contacts_uuid_fk + foreign key (contact_uuid) references contacts (uuid) + on update cascade on delete cascade +) + comment 'Table for housing known signing keys for peer contacts'; + +create index contacts_known_keys_key_name_index + on contacts_known_keys (key_name) + comment 'The index for the key name'; + diff --git a/src/Socialbox/Classes/Resources/database/contacts.sql b/src/Socialbox/Classes/Resources/database/contacts.sql new file mode 100644 index 0000000..b1124f1 --- /dev/null +++ b/src/Socialbox/Classes/Resources/database/contacts.sql @@ -0,0 +1,18 @@ +create table contacts +( + uuid varchar(36) default uuid() not null comment 'The contact UUID for the record' + primary key comment 'The Primary Unique Universal Identifier for the contact record', + peer_uuid varchar(36) not null comment 'The Peer UUID', + contact_peer_address varchar(256) not null comment 'The contact peer address', + relationship enum ('MUTUAL', 'TRUSTED', 'BLOCKED') default 'MUTUAL' not null comment 'The relationship between the two peers, MUTUAL=The contact peer is recognized', + created timestamp default current_timestamp() not null comment 'The Timestamp for when this contact was created', + constraint contacts_uuid_uindex + unique (uuid) comment 'The Primary Unique Universal Identifier for the contact record', + constraint peer_contacts_peer_uuid_contact_peer_address_uindex + unique (peer_uuid, contact_peer_address) comment 'The Unique Peer UUID & Contact Peer Address combination pair', + constraint peer_contacts_registered_peers_uuid_fk + foreign key (peer_uuid) references registered_peers (uuid) + on update cascade on delete cascade +) + comment 'Table for housing personal contacts for peers'; + diff --git a/src/Socialbox/Classes/Resources/database/signing_keys.sql b/src/Socialbox/Classes/Resources/database/signing_keys.sql new file mode 100644 index 0000000..8de9fbd --- /dev/null +++ b/src/Socialbox/Classes/Resources/database/signing_keys.sql @@ -0,0 +1,32 @@ +create table signing_keys +( + peer_uuid varchar(36) not null comment 'The UUID of the peer', + uuid varchar(36) default uuid() not null comment 'The UUID of the key record', + name varchar(64) null comment 'Optional. User provided name for the key', + public_key varchar(64) not null comment 'The Public Signature Key', + state enum ('ACTIVE', 'EXPIRED') default 'ACTIVE' not null comment 'The state of the public key', + expires timestamp null comment 'The Timestamp for when this key expires, null = Never expires', + created timestamp default current_timestamp() not null comment 'The Timestamp for when the signing key record was created', + primary key (peer_uuid, uuid) comment 'The Unique Index pair for the signing key name and the UUID of the peer', + constraint signing_keys_peer_uuid_uuid_uindex + unique (peer_uuid, uuid) comment 'The Unique Index pair for the signing key name and the UUID of the peer', + constraint signing_keys_pk + unique (peer_uuid, uuid) comment 'The Unique Index pair for the signing key name and the UUID of the peer', + constraint signing_keys_registered_peers_uuid_fk + foreign key (peer_uuid) references registered_peers (uuid) + on update cascade on delete cascade +) + comment 'Table for housing public signing keys for peers on the network'; + +create index signing_keys_peer_uuid_index + on signing_keys (peer_uuid) + comment 'The primary index for the peer UUID column'; + +create index signing_keys_state_index + on signing_keys (state) + comment 'Signing key state index'; + +create index signing_keys_uuid_index + on signing_keys (uuid) + comment 'The index for the signing key name'; + diff --git a/src/Socialbox/Enums/DatabaseObjects.php b/src/Socialbox/Enums/DatabaseObjects.php index 3f8acad..327698b 100644 --- a/src/Socialbox/Enums/DatabaseObjects.php +++ b/src/Socialbox/Enums/DatabaseObjects.php @@ -14,8 +14,12 @@ case AUTHENTICATION_OTP = 'authentication_otp.sql'; case CAPTCHA_IMAGES = 'captcha_images.sql'; case SESSIONS = 'sessions.sql'; + case CONTACTS = 'contacts.sql'; + case SIGNING_KEYS = 'signing_keys.sql'; case EXTERNAL_SESSIONS = 'external_sessions.sql'; + case CONTACT_KNOWN_KEYS = 'contact_known_keys.sql'; + /** * Returns the priority of the database object * @@ -34,8 +38,12 @@ self::AUTHENTICATION_PASSWORDS, self::AUTHENTICATION_OTP, self::CAPTCHA_IMAGES, + self::CONTACTS, self::SESSIONS, + self::SIGNING_KEYS, self::EXTERNAL_SESSIONS => 2, + + self::CONTACT_KNOWN_KEYS => 3, }; }