Added auth and request storage
This commit is contained in:
@@ -23,8 +23,19 @@ export const up = async (db: Kysely<DatabaseTables>): Promise<void> => {
|
||||
.addColumn('public_key', 'text', (col) => col.notNull())
|
||||
.addColumn('blob', 'blob', (col) => col.notNull())
|
||||
.addColumn('timestamp', 'integer', (col) => col.notNull().defaultTo(millisecondTime))
|
||||
.addColumn('signature', 'text', (col) => col.notNull())
|
||||
.addPrimaryKeyConstraint('pk_resource_data', [ 'resource_id', 'public_key' ])
|
||||
.execute();
|
||||
|
||||
// Table for authed requests
|
||||
// We will store the signature and the timestamp of the request, and we will clear out rows that are older than our msTimeout for our auth
|
||||
await db.schema
|
||||
.createTable('authed_requests')
|
||||
.ifNotExists()
|
||||
.addColumn('signature', 'text', (col) => col.notNull())
|
||||
.addColumn('timestamp', 'integer', (col) => col.notNull().defaultTo(millisecondTime))
|
||||
.addPrimaryKeyConstraint('pk_authed_requests', [ 'signature' ])
|
||||
.execute();
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -35,4 +46,5 @@ export const up = async (db: Kysely<DatabaseTables>): Promise<void> => {
|
||||
export const down = async (db: Kysely<DatabaseTables>): Promise<void> => {
|
||||
await db.schema.dropTable('resource_data').ifExists()
|
||||
.execute();
|
||||
await db.schema.dropTable('authed_requests').ifExists().execute();
|
||||
};
|
||||
|
||||
@@ -22,9 +22,44 @@ export interface ResourceDataTable {
|
||||
|
||||
/** Millisecond timestamp of the last write. */
|
||||
timestamp: Timestamp;
|
||||
|
||||
/** Signature of the write. */
|
||||
signature: string;
|
||||
}
|
||||
|
||||
export interface AuthedRequestsTable {
|
||||
/** Signature of the request. */
|
||||
signature: string;
|
||||
|
||||
/** Millisecond timestamp of the request. */
|
||||
timestamp: Timestamp;
|
||||
}
|
||||
|
||||
// export interface PaymentsTable {
|
||||
// /** Unique identifier for the payment. */
|
||||
// payment_id: string;
|
||||
|
||||
// /** Public key of the account in the transaction */
|
||||
// public_key: string;
|
||||
|
||||
// /** Amount of the payment. This can be positive or negative.*/
|
||||
// amount: number;
|
||||
|
||||
// /** Timestamp of the payment. */
|
||||
// timestamp: Timestamp;
|
||||
|
||||
// /** Signature of the payment. */
|
||||
// signature: string;
|
||||
|
||||
// /** Hash of the message that was signed. */
|
||||
// message_hash: string;
|
||||
|
||||
// /** Resource ID of the payment. */
|
||||
// resource_id: string;
|
||||
// }
|
||||
|
||||
/** Complete Kysely schema mapping for the sync server database. */
|
||||
export interface DatabaseTables {
|
||||
resource_data: ResourceDataTable;
|
||||
authed_requests: AuthedRequestsTable;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user