mirror of
https://github.com/lightninglabs/aperture.git
synced 2026-01-31 15:14:26 +01:00
sqlc: add table+queries for sessions
This commit is contained in:
99
aperturedb/sqlc/lnc_sessions.sql.go
Normal file
99
aperturedb/sqlc/lnc_sessions.sql.go
Normal file
@@ -0,0 +1,99 @@
|
||||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.18.0
|
||||
// source: lnc_sessions.sql
|
||||
|
||||
package sqlc
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"time"
|
||||
)
|
||||
|
||||
const getSession = `-- name: GetSession :one
|
||||
SELECT id, passphrase_words, passphrase_entropy, remote_static_pub_key, local_static_priv_key, mailbox_addr, created_at, expiry, dev_server
|
||||
FROM lnc_sessions
|
||||
WHERE passphrase_entropy = $1
|
||||
`
|
||||
|
||||
func (q *Queries) GetSession(ctx context.Context, passphraseEntropy []byte) (LncSession, error) {
|
||||
row := q.db.QueryRowContext(ctx, getSession, passphraseEntropy)
|
||||
var i LncSession
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.PassphraseWords,
|
||||
&i.PassphraseEntropy,
|
||||
&i.RemoteStaticPubKey,
|
||||
&i.LocalStaticPrivKey,
|
||||
&i.MailboxAddr,
|
||||
&i.CreatedAt,
|
||||
&i.Expiry,
|
||||
&i.DevServer,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const insertSession = `-- name: InsertSession :exec
|
||||
INSERT INTO lnc_sessions (
|
||||
passphrase_words, passphrase_entropy, local_static_priv_key, mailbox_addr,
|
||||
created_at, expiry, dev_server
|
||||
) VALUES (
|
||||
$1, $2, $3, $4, $5, $6, $7
|
||||
)
|
||||
`
|
||||
|
||||
type InsertSessionParams struct {
|
||||
PassphraseWords string
|
||||
PassphraseEntropy []byte
|
||||
LocalStaticPrivKey []byte
|
||||
MailboxAddr string
|
||||
CreatedAt time.Time
|
||||
Expiry sql.NullTime
|
||||
DevServer bool
|
||||
}
|
||||
|
||||
func (q *Queries) InsertSession(ctx context.Context, arg InsertSessionParams) error {
|
||||
_, err := q.db.ExecContext(ctx, insertSession,
|
||||
arg.PassphraseWords,
|
||||
arg.PassphraseEntropy,
|
||||
arg.LocalStaticPrivKey,
|
||||
arg.MailboxAddr,
|
||||
arg.CreatedAt,
|
||||
arg.Expiry,
|
||||
arg.DevServer,
|
||||
)
|
||||
return err
|
||||
}
|
||||
|
||||
const setExpiry = `-- name: SetExpiry :exec
|
||||
UPDATE lnc_sessions
|
||||
SET expiry=$1
|
||||
WHERE passphrase_entropy=$2
|
||||
`
|
||||
|
||||
type SetExpiryParams struct {
|
||||
Expiry sql.NullTime
|
||||
PassphraseEntropy []byte
|
||||
}
|
||||
|
||||
func (q *Queries) SetExpiry(ctx context.Context, arg SetExpiryParams) error {
|
||||
_, err := q.db.ExecContext(ctx, setExpiry, arg.Expiry, arg.PassphraseEntropy)
|
||||
return err
|
||||
}
|
||||
|
||||
const setRemotePubKey = `-- name: SetRemotePubKey :exec
|
||||
UPDATE lnc_sessions
|
||||
SET remote_static_pub_key=$1
|
||||
WHERE passphrase_entropy=$2
|
||||
`
|
||||
|
||||
type SetRemotePubKeyParams struct {
|
||||
RemoteStaticPubKey []byte
|
||||
PassphraseEntropy []byte
|
||||
}
|
||||
|
||||
func (q *Queries) SetRemotePubKey(ctx context.Context, arg SetRemotePubKeyParams) error {
|
||||
_, err := q.db.ExecContext(ctx, setRemotePubKey, arg.RemoteStaticPubKey, arg.PassphraseEntropy)
|
||||
return err
|
||||
}
|
||||
3
aperturedb/sqlc/migrations/000003_lnc_sessions.down.sql
Normal file
3
aperturedb/sqlc/migrations/000003_lnc_sessions.down.sql
Normal file
@@ -0,0 +1,3 @@
|
||||
DROP INDEX IF EXISTS lnc_sessions_passphrase_entropy_idx;
|
||||
DROP INDEX IF EXISTS lnc_sessions_label_idx;
|
||||
DROP TABLE IF EXISTS lnc_sessions;
|
||||
32
aperturedb/sqlc/migrations/000003_lnc_sessions.up.sql
Normal file
32
aperturedb/sqlc/migrations/000003_lnc_sessions.up.sql
Normal file
@@ -0,0 +1,32 @@
|
||||
-- lnc_sessions is table used to store data about LNC sesssions.
|
||||
CREATE TABLE IF NOT EXISTS lnc_sessions (
|
||||
id INTEGER PRIMARY KEY,
|
||||
|
||||
-- The passphrase words used to derive the passphrase entropy.
|
||||
passphrase_words TEXT NOT NULL UNIQUE,
|
||||
|
||||
-- The entropy bytes to be used for mask the local ephemeral key during the
|
||||
-- first step of the Noise XX handshake.
|
||||
passphrase_entropy BLOB NOT NULL UNIQUE,
|
||||
|
||||
-- The remote static key being used for the connection.
|
||||
remote_static_pub_key BLOB UNIQUE,
|
||||
|
||||
-- The local static key being used for the connection.
|
||||
local_static_priv_key BLOB NOT NULL,
|
||||
|
||||
-- mailbox_addr is the address of the mailbox used for the session.
|
||||
mailbox_addr TEXT NOT NULL,
|
||||
|
||||
-- created_at is the time the session was created.
|
||||
created_at TIMESTAMP NOT NULL,
|
||||
|
||||
-- expiry is the time the session will expire.
|
||||
expiry TIMESTAMP,
|
||||
|
||||
-- dev_server signals if we need to skip the verification of the server's
|
||||
-- tls certificate.
|
||||
dev_server BOOL NOT NULL
|
||||
);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS lnc_sessions_passphrase_entropy_idx ON lnc_sessions(passphrase_entropy);
|
||||
@@ -5,9 +5,22 @@
|
||||
package sqlc
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
"time"
|
||||
)
|
||||
|
||||
type LncSession struct {
|
||||
ID int32
|
||||
PassphraseWords string
|
||||
PassphraseEntropy []byte
|
||||
RemoteStaticPubKey []byte
|
||||
LocalStaticPrivKey []byte
|
||||
MailboxAddr string
|
||||
CreatedAt time.Time
|
||||
Expiry sql.NullTime
|
||||
DevServer bool
|
||||
}
|
||||
|
||||
type Onion struct {
|
||||
PrivateKey []byte
|
||||
CreatedAt time.Time
|
||||
|
||||
@@ -12,8 +12,12 @@ type Querier interface {
|
||||
DeleteOnionPrivateKey(ctx context.Context) error
|
||||
DeleteSecretByHash(ctx context.Context, hash []byte) (int64, error)
|
||||
GetSecretByHash(ctx context.Context, hash []byte) ([]byte, error)
|
||||
GetSession(ctx context.Context, passphraseEntropy []byte) (LncSession, error)
|
||||
InsertSecret(ctx context.Context, arg InsertSecretParams) (int32, error)
|
||||
InsertSession(ctx context.Context, arg InsertSessionParams) error
|
||||
SelectOnionPrivateKey(ctx context.Context) ([]byte, error)
|
||||
SetExpiry(ctx context.Context, arg SetExpiryParams) error
|
||||
SetRemotePubKey(ctx context.Context, arg SetRemotePubKeyParams) error
|
||||
UpsertOnion(ctx context.Context, arg UpsertOnionParams) error
|
||||
}
|
||||
|
||||
|
||||
22
aperturedb/sqlc/queries/lnc_sessions.sql
Normal file
22
aperturedb/sqlc/queries/lnc_sessions.sql
Normal file
@@ -0,0 +1,22 @@
|
||||
-- name: InsertSession :exec
|
||||
INSERT INTO lnc_sessions (
|
||||
passphrase_words, passphrase_entropy, local_static_priv_key, mailbox_addr,
|
||||
created_at, expiry, dev_server
|
||||
) VALUES (
|
||||
$1, $2, $3, $4, $5, $6, $7
|
||||
);
|
||||
|
||||
-- name: GetSession :one
|
||||
SELECT *
|
||||
FROM lnc_sessions
|
||||
WHERE passphrase_entropy = $1;
|
||||
|
||||
-- name: SetRemotePubKey :exec
|
||||
UPDATE lnc_sessions
|
||||
SET remote_static_pub_key=$1
|
||||
WHERE passphrase_entropy=$2;
|
||||
|
||||
-- name: SetExpiry :exec
|
||||
UPDATE lnc_sessions
|
||||
SET expiry=$1
|
||||
WHERE passphrase_entropy=$2;
|
||||
Reference in New Issue
Block a user