diff --git a/README.md b/README.md index 6e4919bd..e6217db1 100644 --- a/README.md +++ b/README.md @@ -41,6 +41,10 @@ You must have the _exact_ go version listed in `go.mod` - you can verify this by 1. `dev/migrate-authz $MIGRATION_NAME` +### Updating the SQLC Queries for the MLSStore + +If you modify `pkg/mls/store/queries.sql` you need to run `./dev/sqlc` from the root of this package to regenerate any generated code. + ### Debugging metrics 1. `dev/run --metrics` diff --git a/dev/run b/dev/run index a995db08..a160bc5b 100755 --- a/dev/run +++ b/dev/run @@ -2,8 +2,8 @@ set -e MESSAGE_DB_DSN="postgres://postgres:xmtp@localhost:15432/postgres?sslmode=disable" -MLS_DB_DSN="postgres://postgres:xmtp@localhost:15432/postgres?sslmode=disable" -AUTHZ_DB_DSN="postgres://postgres:xmtp@localhost:15432/postgres?sslmode=disable" +MLS_DB_DSN="postgres://postgres:xmtp@localhost:7654/postgres?sslmode=disable" +AUTHZ_DB_DSN="postgres://postgres:xmtp@localhost:6543/postgres?sslmode=disable" NODE_KEY="8a30dcb604b0b53627a5adc054dbf434b446628d4bd1eccc681d223f0550ce67" go run cmd/xmtpd/main.go \ @@ -15,6 +15,7 @@ go run cmd/xmtpd/main.go \ --store.reader-db-connection-string "${MESSAGE_DB_DSN}" \ --store.metrics-period 5s \ --mls-store.db-connection-string "${MLS_DB_DSN}" \ + --mls-validation.grpc-address=validation:50051 \ --authz-db-connection-string "${AUTHZ_DB_DSN}" \ --go-profiling \ "$@" diff --git a/dev/sqlc b/dev/sqlc new file mode 100755 index 00000000..73d3557c --- /dev/null +++ b/dev/sqlc @@ -0,0 +1,4 @@ +#!/bin/bash +set -e + +docker run --rm -v $(pwd):/src -w /src sqlc/sqlc generate \ No newline at end of file diff --git a/go.mod b/go.mod index 83044d23..28fef3cf 100644 --- a/go.mod +++ b/go.mod @@ -12,6 +12,7 @@ require ( github.com/hashicorp/go-retryablehttp v0.7.0 github.com/hashicorp/golang-lru v0.5.5-0.20210104140557-80c98217689d github.com/huandu/go-sqlbuilder v1.13.0 + github.com/jackc/pgx/v5 v5.5.5 github.com/jarcoal/httpmock v1.2.0 github.com/jessevdk/go-flags v1.4.0 github.com/libp2p/go-libp2p v0.29.2 @@ -39,6 +40,12 @@ require ( gopkg.in/DataDog/dd-trace-go.v1 v1.40.1 ) +require ( + github.com/jackc/pgpassfile v1.0.0 // indirect + github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a // indirect + github.com/jackc/puddle/v2 v2.2.1 // indirect +) + require ( github.com/DataDog/datadog-agent/pkg/obfuscate v0.0.0-20211129110424-6491aa3bf583 // indirect github.com/DataDog/datadog-go v4.8.2+incompatible // indirect @@ -170,12 +177,12 @@ require ( go.uber.org/dig v1.17.0 // indirect go.uber.org/fx v1.20.0 // indirect go.uber.org/multierr v1.11.0 // indirect - golang.org/x/crypto v0.13.0 // indirect + golang.org/x/crypto v0.17.0 // indirect golang.org/x/exp v0.0.0-20230713183714-613f0c0eb8a1 // indirect golang.org/x/mod v0.12.0 // indirect golang.org/x/net v0.14.0 // indirect - golang.org/x/sys v0.12.0 // indirect - golang.org/x/text v0.13.0 // indirect + golang.org/x/sys v0.15.0 // indirect + golang.org/x/text v0.14.0 // indirect golang.org/x/time v0.0.0-20220922220347-f3bd1da661af // indirect golang.org/x/tools v0.12.1-0.20230818130535-1517d1a3ba60 // indirect golang.org/x/xerrors v0.0.0-20220517211312-f3a8303e98df // indirect diff --git a/go.sum b/go.sum index c40fd15d..d3e17389 100644 --- a/go.sum +++ b/go.sum @@ -571,6 +571,7 @@ github.com/jackc/pgio v1.0.0/go.mod h1:oP+2QK2wFfUWgr+gxjoBH9KGBb31Eio69xUb0w5bY github.com/jackc/pgmock v0.0.0-20190831213851-13a1b77aafa2/go.mod h1:fGZlG77KXmcq05nJLRkk0+p82V8B8Dw8KN2/V9c/OAE= github.com/jackc/pgmock v0.0.0-20201204152224-4fe30f7445fd/go.mod h1:hrBW0Enj2AZTNpt/7Y5rr2xe/9Mn757Wtb2xeBzPv2c= github.com/jackc/pgmock v0.0.0-20210724152146-4ad1a8207f65/go.mod h1:5R2h2EEX+qri8jOWMbJCtaPWkrrNc7OHwsp2TCqp7ak= +github.com/jackc/pgpassfile v1.0.0 h1:/6Hmqy13Ss2zCq62VdNG8tM1wchn8zjSGOBJ6icpsIM= github.com/jackc/pgpassfile v1.0.0/go.mod h1:CEx0iS5ambNFdcRtxPj5JhEz+xB6uRky5eyVu/W2HEg= github.com/jackc/pgproto3 v1.1.0/go.mod h1:eR5FA3leWg7p9aeAqi37XOTgTIbkABlvcPB3E5rlc78= github.com/jackc/pgproto3/v2 v2.0.0-alpha1.0.20190420180111-c116219b62db/go.mod h1:bhq50y+xrl9n5mRYyCBFKkpRVTLYJVWeCc+mEAI3yXA= @@ -584,6 +585,8 @@ github.com/jackc/pgproto3/v2 v2.1.1/go.mod h1:WfJCnwN3HIg9Ish/j3sgWXnAfK8A9Y0bwX github.com/jackc/pgproto3/v2 v2.2.0/go.mod h1:WfJCnwN3HIg9Ish/j3sgWXnAfK8A9Y0bwXYU5xKaEdA= github.com/jackc/pgservicefile v0.0.0-20200307190119-3430c5407db8/go.mod h1:vsD4gTJCa9TptPL8sPkXrLZ+hDuNrZCnj29CQpr4X1E= github.com/jackc/pgservicefile v0.0.0-20200714003250-2b9c44734f2b/go.mod h1:vsD4gTJCa9TptPL8sPkXrLZ+hDuNrZCnj29CQpr4X1E= +github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a h1:bbPeKD0xmW/Y25WS6cokEszi5g+S0QxI/d45PkRi7Nk= +github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a/go.mod h1:5TJZWKEWniPve33vlWYSoGYefn3gLQRzjfDlhSJ9ZKM= github.com/jackc/pgtype v0.0.0-20190421001408-4ed0de4755e0/go.mod h1:hdSHsc1V01CGwFsrv11mJRHWJ6aifDLfdV3aVjFF0zg= github.com/jackc/pgtype v0.0.0-20190824184912-ab885b375b90/go.mod h1:KcahbBH1nCMSo2DXpzsoWOAfFkdEtEJpPbVLq8eE+mc= github.com/jackc/pgtype v0.0.0-20190828014616-a8802b16cc59/go.mod h1:MWlu30kVJrUS8lot6TQqcg7mtthZ9T0EoIBFiJcmcyw= @@ -602,12 +605,16 @@ github.com/jackc/pgx/v4 v4.6.1-0.20200606145419-4e5062306904/go.mod h1:ZDaNWkt9s github.com/jackc/pgx/v4 v4.8.1/go.mod h1:4HOLxrl8wToZJReD04/yB20GDwf4KBYETvlHciCnwW0= github.com/jackc/pgx/v4 v4.12.1-0.20210724153913-640aa07df17c/go.mod h1:1QD0+tgSXP7iUjYm9C1NxKhny7lq6ee99u/z+IHFcgs= github.com/jackc/pgx/v4 v4.14.0/go.mod h1:jT3ibf/A0ZVCp89rtCIN0zCJxcE74ypROmHEZYsG/j8= +github.com/jackc/pgx/v5 v5.5.5 h1:amBjrZVmksIdNjxGW/IiIMzxMKZFelXbUoPNb+8sjQw= +github.com/jackc/pgx/v5 v5.5.5/go.mod h1:ez9gk+OAat140fv9ErkZDYFWmXLfV+++K0uAOiwgm1A= github.com/jackc/puddle v0.0.0-20190413234325-e4ced69a3a2b/go.mod h1:m4B5Dj62Y0fbyuIc15OsIqK0+JU8nkqQjsgx7dvjSWk= github.com/jackc/puddle v0.0.0-20190608224051-11cab39313c9/go.mod h1:m4B5Dj62Y0fbyuIc15OsIqK0+JU8nkqQjsgx7dvjSWk= github.com/jackc/puddle v1.1.0/go.mod h1:m4B5Dj62Y0fbyuIc15OsIqK0+JU8nkqQjsgx7dvjSWk= github.com/jackc/puddle v1.1.1/go.mod h1:m4B5Dj62Y0fbyuIc15OsIqK0+JU8nkqQjsgx7dvjSWk= github.com/jackc/puddle v1.1.3/go.mod h1:m4B5Dj62Y0fbyuIc15OsIqK0+JU8nkqQjsgx7dvjSWk= github.com/jackc/puddle v1.2.0/go.mod h1:m4B5Dj62Y0fbyuIc15OsIqK0+JU8nkqQjsgx7dvjSWk= +github.com/jackc/puddle/v2 v2.2.1 h1:RhxXJtFG022u4ibrCSMSiu5aOq1i77R3OHKNJj77OAk= +github.com/jackc/puddle/v2 v2.2.1/go.mod h1:vriiEXHvEE654aYKXXjOvZM39qJ0q+azkZFrfEOc3H4= github.com/jackpal/go-nat-pmp v1.0.2 h1:KzKSgb7qkJvOUTqYl9/Hg/me3pWgBmERKrTGD7BdWus= github.com/jackpal/go-nat-pmp v1.0.2/go.mod h1:QPH045xvCAeXUZOxsnwmrtiCoxIr9eob+4orBN1SBKc= github.com/jarcoal/httpmock v1.2.0 h1:gSvTxxFR/MEMfsGrvRbdfpRUMBStovlSRLw0Ep1bwwc= @@ -668,8 +675,8 @@ github.com/koron/go-ssdp v0.0.4 h1:1IDwrghSKYM7yLf7XCzbByg2sJ/JcNOZRXS2jczTwz0= github.com/koron/go-ssdp v0.0.4/go.mod h1:oDXq+E5IL5q0U8uSBcoAXzTzInwy5lEgC91HoKtbmZk= github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc= github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= -github.com/kr/pretty v0.2.1 h1:Fmg33tUaq4/8ym9TJN1x7sLJnHVwhP33CNkpYV/7rwI= github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI= +github.com/kr/pretty v0.3.0 h1:WgNl7dwNpEZ6jJ9k1snq4pZsg7DOEN8hP9Xw0Tsjwk0= github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/pty v1.1.3/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/pty v1.1.8/go.mod h1:O1sed60cT9XZ5uDucP5qwvh+TE3NnUj51EiZO/lmSfw= @@ -970,6 +977,7 @@ github.com/rjeczalik/notify v0.9.1/go.mod h1:rKwnCoCGeuQnwBtTSPL9Dad03Vh2n40ePRr github.com/rjeczalik/notify v0.9.3 h1:6rJAzHTGKXGj76sbRgDiDcYj/HniypXmSJo1SWakZeY= github.com/rjeczalik/notify v0.9.3/go.mod h1:gF3zSOrafR9DQEWSE8TjfI9NkooDxbyT4UgRGKZA0lc= github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= +github.com/rogpeppe/go-internal v1.10.0 h1:TMyTOH3F/DB16zRVcYyreMH6GnZZrwQVAoYjRBZyWFQ= github.com/rs/cors v1.7.0 h1:+88SsELBHx5r+hZ8TCkggzSstaWNbDvThkVK8H6f9ik= github.com/rs/cors v1.7.0/go.mod h1:gFx+x8UowdsKA9AchylcLynDq+nNFfI8FkUZdN/jGCU= github.com/rs/xid v1.2.1/go.mod h1:+uKXf+4Djp6Md1KODXJxgGQPKngRmWyn10oCKFzNHOQ= @@ -1239,8 +1247,8 @@ golang.org/x/crypto v0.0.0-20210616213533-5ff15b29337e/go.mod h1:GvvjBRRGRdwPK5y golang.org/x/crypto v0.0.0-20210711020723-a769d52b0f97/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= golang.org/x/crypto v0.0.0-20220214200702-86341886e292/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= golang.org/x/crypto v0.0.0-20220331220935-ae2d96664a29/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= -golang.org/x/crypto v0.13.0 h1:mvySKfSWJ+UKUii46M40LOvyWfN0s2U+46/jDd0e6Ck= -golang.org/x/crypto v0.13.0/go.mod h1:y6Z2r+Rw4iayiXXAIxJIDAJ1zMW4yaTpebo8fPOliYc= +golang.org/x/crypto v0.17.0 h1:r8bRNjWL3GshPW3gkd+RpvzWrZAwPS49OmTGZ/uhM4k= +golang.org/x/crypto v0.17.0/go.mod h1:gCAAfMLgwOJRpTjQ2zCCt2OcSfYMTeZVSRtQlPC7Nq4= golang.org/x/exp v0.0.0-20180321215751-8460e604b9de/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20180807140117-3d87b88a115f/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= @@ -1442,8 +1450,8 @@ golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.12.0 h1:CM0HF96J0hcLAwsHPJZjfdNzs0gftsLfgKt57wWHJ0o= -golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.15.0 h1:h48lPFYpsTvQJZF4EKyI4aLHaev3CxivZmv7yZig9pc= +golang.org/x/sys v0.15.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= @@ -1457,8 +1465,8 @@ golang.org/x/text v0.3.4/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.5/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= -golang.org/x/text v0.13.0 h1:ablQoSUd0tRdKxZewP80B+BaqeKJuVhuRxj/dkrun3k= -golang.org/x/text v0.13.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE= +golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ= +golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= golang.org/x/time v0.0.0-20180412165947-fbb02b2291d2/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= diff --git a/pkg/migrations/mls/20240411200242_init-identity.up.sql b/pkg/migrations/mls/20240411200242_init-identity.up.sql index 4fdeef44..cc56762e 100644 --- a/pkg/migrations/mls/20240411200242_init-identity.up.sql +++ b/pkg/migrations/mls/20240411200242_init-identity.up.sql @@ -24,4 +24,4 @@ CREATE TABLE address_log ( --bun:split -CREATE INDEX idx_address_log_address_inbox_id ON address_log(address, inbox_id); +CREATE INDEX idx_address_log_address_inbox_id ON address_log(address, inbox_id); \ No newline at end of file diff --git a/pkg/migrations/mls/20240425021053_add-inbox-filters.down.sql b/pkg/migrations/mls/20240425021053_add-inbox-filters.down.sql new file mode 100644 index 00000000..f5b5f1c0 --- /dev/null +++ b/pkg/migrations/mls/20240425021053_add-inbox-filters.down.sql @@ -0,0 +1,5 @@ +SET statement_timeout = 0; + +--bun:split + +DROP TYPE IF EXISTS inbox_filter; \ No newline at end of file diff --git a/pkg/migrations/mls/20240425021053_add-inbox-filters.up.sql b/pkg/migrations/mls/20240425021053_add-inbox-filters.up.sql new file mode 100644 index 00000000..edd4b911 --- /dev/null +++ b/pkg/migrations/mls/20240425021053_add-inbox-filters.up.sql @@ -0,0 +1,8 @@ +SET statement_timeout = 0; + +--bun:split + +CREATE TYPE inbox_filter AS ( + inbox_id TEXT, + sequence_id BIGINT +); diff --git a/pkg/mls/store/queries.sql b/pkg/mls/store/queries.sql new file mode 100644 index 00000000..6436fd3b --- /dev/null +++ b/pkg/mls/store/queries.sql @@ -0,0 +1,78 @@ +-- name: GetAllInboxLogs :many +SELECT * FROM inbox_log +WHERE inbox_id = $1 +ORDER BY sequence_id ASC FOR UPDATE; + +-- name: GetInboxLogFiltered :many +SELECT a.* FROM inbox_log AS a +JOIN ( + SELECT * FROM json_populate_recordset(null::inbox_filter, sqlc.arg(filters)) as b(inbox_id, sequence_id) +) as b on b.inbox_id = a.inbox_id AND a.sequence_id > b.sequence_id +ORDER BY a.sequence_id ASC; + +-- name: InsertInboxLog :one +INSERT INTO inbox_log (inbox_id, server_timestamp_ns, identity_update_proto) +VALUES ($1, $2, $3) +RETURNING sequence_id; + +-- name: CreateInstallation :exec +INSERT INTO installations (id, wallet_address, created_at, updated_at, credential_identity, key_package, expiration) +VALUES ($1, $2, $3, $3, $4, $5, $6); + +-- name: UpdateKeyPackage :execrows +UPDATE installations +SET key_package = @key_package, updated_at = @updated_at, expiration = @expiration +WHERE id = @id; + +-- name: FetchKeyPackages :many +SELECT id, key_package FROM installations +WHERE ID IN (@ids); + +-- name: GetIdentityUpdates :many +SELECT * FROM installations +WHERE wallet_address IN (@wallet_addresses) +AND (created_at > @start_time OR revoked_at > @start_time) +ORDER BY created_at ASC; + +-- name: RevokeInstallation :exec +UPDATE installations +SET revoked_at = @revoked_at +WHERE id = @installation_id +AND revoked_at IS NULL; + +-- name: InsertGroupMessage :one +INSERT INTO group_messages (group_id, data, group_id_data_hash) +VALUES ($1, $2, $3) +RETURNING *; + +-- name: InsertWelcomeMessage :one +INSERT INTO welcome_messages (installation_key, data, installation_key_data_hash, hpke_public_key) +VALUES ($1, $2, $3, $4) +RETURNING *; + +-- name: QueryGroupMessagesAsc :many +SELECT * FROM group_messages +WHERE group_id = @group_id +ORDER BY id ASC +LIMIT @numrows; + +-- name: QueryGroupMessagesDesc :many +SELECT * FROM group_messages +WHERE group_id = @group_id +ORDER BY id DESC +LIMIT @numrows; + +-- name: QueryGroupMessagesWithCursorAsc :many +SELECT * FROM group_messages +WHERE group_id = $1 +AND id > $2 +ORDER BY id ASC +LIMIT $3; + +-- name: QueryGroupMessagesWithCursorDesc :many +SELECT * FROM group_messages +WHERE group_id = $1 +AND id < $2 +ORDER BY id DESC +LIMIT $3; + diff --git a/pkg/mls/store/queries/db.go b/pkg/mls/store/queries/db.go new file mode 100644 index 00000000..fa785733 --- /dev/null +++ b/pkg/mls/store/queries/db.go @@ -0,0 +1,31 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.26.0 + +package queries + +import ( + "context" + "database/sql" +) + +type DBTX interface { + ExecContext(context.Context, string, ...interface{}) (sql.Result, error) + PrepareContext(context.Context, string) (*sql.Stmt, error) + QueryContext(context.Context, string, ...interface{}) (*sql.Rows, error) + QueryRowContext(context.Context, string, ...interface{}) *sql.Row +} + +func New(db DBTX) *Queries { + return &Queries{db: db} +} + +type Queries struct { + db DBTX +} + +func (q *Queries) WithTx(tx *sql.Tx) *Queries { + return &Queries{ + db: tx, + } +} diff --git a/pkg/mls/store/queries/models.go b/pkg/mls/store/queries/models.go new file mode 100644 index 00000000..cc2ae9d3 --- /dev/null +++ b/pkg/mls/store/queries/models.go @@ -0,0 +1,52 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.26.0 + +package queries + +import ( + "database/sql" + "time" +) + +type AddressLog struct { + Address string + InboxID string + AssociationSequenceID sql.NullInt64 + RevocationSequenceID sql.NullInt64 +} + +type GroupMessage struct { + ID int64 + CreatedAt time.Time + GroupID []byte + Data []byte + GroupIDDataHash []byte +} + +type InboxLog struct { + SequenceID int64 + InboxID string + ServerTimestampNs int64 + IdentityUpdateProto []byte +} + +type Installation struct { + ID []byte + WalletAddress string + CreatedAt int64 + UpdatedAt int64 + CredentialIdentity []byte + RevokedAt sql.NullInt64 + KeyPackage []byte + Expiration int64 +} + +type WelcomeMessage struct { + ID int64 + CreatedAt time.Time + InstallationKey []byte + Data []byte + InstallationKeyDataHash []byte + HpkePublicKey []byte +} diff --git a/pkg/mls/store/queries/queries.sql.go b/pkg/mls/store/queries/queries.sql.go new file mode 100644 index 00000000..337eebd8 --- /dev/null +++ b/pkg/mls/store/queries/queries.sql.go @@ -0,0 +1,472 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.26.0 +// source: queries.sql + +package queries + +import ( + "context" + "database/sql" + "encoding/json" +) + +const createInstallation = `-- name: CreateInstallation :exec +INSERT INTO installations (id, wallet_address, created_at, updated_at, credential_identity, key_package, expiration) +VALUES ($1, $2, $3, $3, $4, $5, $6) +` + +type CreateInstallationParams struct { + ID []byte + WalletAddress string + CreatedAt int64 + CredentialIdentity []byte + KeyPackage []byte + Expiration int64 +} + +func (q *Queries) CreateInstallation(ctx context.Context, arg CreateInstallationParams) error { + _, err := q.db.ExecContext(ctx, createInstallation, + arg.ID, + arg.WalletAddress, + arg.CreatedAt, + arg.CredentialIdentity, + arg.KeyPackage, + arg.Expiration, + ) + return err +} + +const fetchKeyPackages = `-- name: FetchKeyPackages :many +SELECT id, key_package FROM installations +WHERE ID IN ($1) +` + +type FetchKeyPackagesRow struct { + ID []byte + KeyPackage []byte +} + +func (q *Queries) FetchKeyPackages(ctx context.Context, ids []byte) ([]FetchKeyPackagesRow, error) { + rows, err := q.db.QueryContext(ctx, fetchKeyPackages, ids) + if err != nil { + return nil, err + } + defer rows.Close() + var items []FetchKeyPackagesRow + for rows.Next() { + var i FetchKeyPackagesRow + if err := rows.Scan(&i.ID, &i.KeyPackage); err != nil { + return nil, err + } + items = append(items, i) + } + if err := rows.Close(); err != nil { + return nil, err + } + if err := rows.Err(); err != nil { + return nil, err + } + return items, nil +} + +const getAllInboxLogs = `-- name: GetAllInboxLogs :many +SELECT sequence_id, inbox_id, server_timestamp_ns, identity_update_proto FROM inbox_log +WHERE inbox_id = $1 +ORDER BY sequence_id ASC FOR UPDATE +` + +func (q *Queries) GetAllInboxLogs(ctx context.Context, inboxID string) ([]InboxLog, error) { + rows, err := q.db.QueryContext(ctx, getAllInboxLogs, inboxID) + if err != nil { + return nil, err + } + defer rows.Close() + var items []InboxLog + for rows.Next() { + var i InboxLog + if err := rows.Scan( + &i.SequenceID, + &i.InboxID, + &i.ServerTimestampNs, + &i.IdentityUpdateProto, + ); err != nil { + return nil, err + } + items = append(items, i) + } + if err := rows.Close(); err != nil { + return nil, err + } + if err := rows.Err(); err != nil { + return nil, err + } + return items, nil +} + +const getIdentityUpdates = `-- name: GetIdentityUpdates :many +SELECT id, wallet_address, created_at, updated_at, credential_identity, revoked_at, key_package, expiration FROM installations +WHERE wallet_address IN ($1) +AND (created_at > $2 OR revoked_at > $2) +ORDER BY created_at ASC +` + +type GetIdentityUpdatesParams struct { + WalletAddresses string + StartTime int64 +} + +func (q *Queries) GetIdentityUpdates(ctx context.Context, arg GetIdentityUpdatesParams) ([]Installation, error) { + rows, err := q.db.QueryContext(ctx, getIdentityUpdates, arg.WalletAddresses, arg.StartTime) + if err != nil { + return nil, err + } + defer rows.Close() + var items []Installation + for rows.Next() { + var i Installation + if err := rows.Scan( + &i.ID, + &i.WalletAddress, + &i.CreatedAt, + &i.UpdatedAt, + &i.CredentialIdentity, + &i.RevokedAt, + &i.KeyPackage, + &i.Expiration, + ); err != nil { + return nil, err + } + items = append(items, i) + } + if err := rows.Close(); err != nil { + return nil, err + } + if err := rows.Err(); err != nil { + return nil, err + } + return items, nil +} + +const getInboxLogFiltered = `-- name: GetInboxLogFiltered :many +SELECT a.sequence_id, a.inbox_id, a.server_timestamp_ns, a.identity_update_proto FROM inbox_log AS a +JOIN ( + SELECT inbox_id, sequence_id FROM json_populate_recordset(null::inbox_filter, $1) as b(inbox_id, sequence_id) +) as b on b.inbox_id = a.inbox_id AND a.sequence_id > b.sequence_id +ORDER BY a.sequence_id ASC +` + +func (q *Queries) GetInboxLogFiltered(ctx context.Context, filters json.RawMessage) ([]InboxLog, error) { + rows, err := q.db.QueryContext(ctx, getInboxLogFiltered, filters) + if err != nil { + return nil, err + } + defer rows.Close() + var items []InboxLog + for rows.Next() { + var i InboxLog + if err := rows.Scan( + &i.SequenceID, + &i.InboxID, + &i.ServerTimestampNs, + &i.IdentityUpdateProto, + ); err != nil { + return nil, err + } + items = append(items, i) + } + if err := rows.Close(); err != nil { + return nil, err + } + if err := rows.Err(); err != nil { + return nil, err + } + return items, nil +} + +const insertGroupMessage = `-- name: InsertGroupMessage :one +INSERT INTO group_messages (group_id, data, group_id_data_hash) +VALUES ($1, $2, $3) +RETURNING id, created_at, group_id, data, group_id_data_hash +` + +type InsertGroupMessageParams struct { + GroupID []byte + Data []byte + GroupIDDataHash []byte +} + +func (q *Queries) InsertGroupMessage(ctx context.Context, arg InsertGroupMessageParams) (GroupMessage, error) { + row := q.db.QueryRowContext(ctx, insertGroupMessage, arg.GroupID, arg.Data, arg.GroupIDDataHash) + var i GroupMessage + err := row.Scan( + &i.ID, + &i.CreatedAt, + &i.GroupID, + &i.Data, + &i.GroupIDDataHash, + ) + return i, err +} + +const insertInboxLog = `-- name: InsertInboxLog :one +INSERT INTO inbox_log (inbox_id, server_timestamp_ns, identity_update_proto) +VALUES ($1, $2, $3) +RETURNING sequence_id +` + +type InsertInboxLogParams struct { + InboxID string + ServerTimestampNs int64 + IdentityUpdateProto []byte +} + +func (q *Queries) InsertInboxLog(ctx context.Context, arg InsertInboxLogParams) (int64, error) { + row := q.db.QueryRowContext(ctx, insertInboxLog, arg.InboxID, arg.ServerTimestampNs, arg.IdentityUpdateProto) + var sequence_id int64 + err := row.Scan(&sequence_id) + return sequence_id, err +} + +const insertWelcomeMessage = `-- name: InsertWelcomeMessage :one +INSERT INTO welcome_messages (installation_key, data, installation_key_data_hash, hpke_public_key) +VALUES ($1, $2, $3, $4) +RETURNING id, created_at, installation_key, data, installation_key_data_hash, hpke_public_key +` + +type InsertWelcomeMessageParams struct { + InstallationKey []byte + Data []byte + InstallationKeyDataHash []byte + HpkePublicKey []byte +} + +func (q *Queries) InsertWelcomeMessage(ctx context.Context, arg InsertWelcomeMessageParams) (WelcomeMessage, error) { + row := q.db.QueryRowContext(ctx, insertWelcomeMessage, + arg.InstallationKey, + arg.Data, + arg.InstallationKeyDataHash, + arg.HpkePublicKey, + ) + var i WelcomeMessage + err := row.Scan( + &i.ID, + &i.CreatedAt, + &i.InstallationKey, + &i.Data, + &i.InstallationKeyDataHash, + &i.HpkePublicKey, + ) + return i, err +} + +const queryGroupMessagesAsc = `-- name: QueryGroupMessagesAsc :many +SELECT id, created_at, group_id, data, group_id_data_hash FROM group_messages +WHERE group_id = $1 +ORDER BY id ASC +LIMIT $2 +` + +type QueryGroupMessagesAscParams struct { + GroupID []byte + Numrows int32 +} + +func (q *Queries) QueryGroupMessagesAsc(ctx context.Context, arg QueryGroupMessagesAscParams) ([]GroupMessage, error) { + rows, err := q.db.QueryContext(ctx, queryGroupMessagesAsc, arg.GroupID, arg.Numrows) + if err != nil { + return nil, err + } + defer rows.Close() + var items []GroupMessage + for rows.Next() { + var i GroupMessage + if err := rows.Scan( + &i.ID, + &i.CreatedAt, + &i.GroupID, + &i.Data, + &i.GroupIDDataHash, + ); err != nil { + return nil, err + } + items = append(items, i) + } + if err := rows.Close(); err != nil { + return nil, err + } + if err := rows.Err(); err != nil { + return nil, err + } + return items, nil +} + +const queryGroupMessagesDesc = `-- name: QueryGroupMessagesDesc :many +SELECT id, created_at, group_id, data, group_id_data_hash FROM group_messages +WHERE group_id = $1 +ORDER BY id DESC +LIMIT $2 +` + +type QueryGroupMessagesDescParams struct { + GroupID []byte + Numrows int32 +} + +func (q *Queries) QueryGroupMessagesDesc(ctx context.Context, arg QueryGroupMessagesDescParams) ([]GroupMessage, error) { + rows, err := q.db.QueryContext(ctx, queryGroupMessagesDesc, arg.GroupID, arg.Numrows) + if err != nil { + return nil, err + } + defer rows.Close() + var items []GroupMessage + for rows.Next() { + var i GroupMessage + if err := rows.Scan( + &i.ID, + &i.CreatedAt, + &i.GroupID, + &i.Data, + &i.GroupIDDataHash, + ); err != nil { + return nil, err + } + items = append(items, i) + } + if err := rows.Close(); err != nil { + return nil, err + } + if err := rows.Err(); err != nil { + return nil, err + } + return items, nil +} + +const queryGroupMessagesWithCursorAsc = `-- name: QueryGroupMessagesWithCursorAsc :many +SELECT id, created_at, group_id, data, group_id_data_hash FROM group_messages +WHERE group_id = $1 +AND id > $2 +ORDER BY id ASC +LIMIT $3 +` + +type QueryGroupMessagesWithCursorAscParams struct { + GroupID []byte + ID int64 + Limit int32 +} + +func (q *Queries) QueryGroupMessagesWithCursorAsc(ctx context.Context, arg QueryGroupMessagesWithCursorAscParams) ([]GroupMessage, error) { + rows, err := q.db.QueryContext(ctx, queryGroupMessagesWithCursorAsc, arg.GroupID, arg.ID, arg.Limit) + if err != nil { + return nil, err + } + defer rows.Close() + var items []GroupMessage + for rows.Next() { + var i GroupMessage + if err := rows.Scan( + &i.ID, + &i.CreatedAt, + &i.GroupID, + &i.Data, + &i.GroupIDDataHash, + ); err != nil { + return nil, err + } + items = append(items, i) + } + if err := rows.Close(); err != nil { + return nil, err + } + if err := rows.Err(); err != nil { + return nil, err + } + return items, nil +} + +const queryGroupMessagesWithCursorDesc = `-- name: QueryGroupMessagesWithCursorDesc :many +SELECT id, created_at, group_id, data, group_id_data_hash FROM group_messages +WHERE group_id = $1 +AND id < $2 +ORDER BY id DESC +LIMIT $3 +` + +type QueryGroupMessagesWithCursorDescParams struct { + GroupID []byte + ID int64 + Limit int32 +} + +func (q *Queries) QueryGroupMessagesWithCursorDesc(ctx context.Context, arg QueryGroupMessagesWithCursorDescParams) ([]GroupMessage, error) { + rows, err := q.db.QueryContext(ctx, queryGroupMessagesWithCursorDesc, arg.GroupID, arg.ID, arg.Limit) + if err != nil { + return nil, err + } + defer rows.Close() + var items []GroupMessage + for rows.Next() { + var i GroupMessage + if err := rows.Scan( + &i.ID, + &i.CreatedAt, + &i.GroupID, + &i.Data, + &i.GroupIDDataHash, + ); err != nil { + return nil, err + } + items = append(items, i) + } + if err := rows.Close(); err != nil { + return nil, err + } + if err := rows.Err(); err != nil { + return nil, err + } + return items, nil +} + +const revokeInstallation = `-- name: RevokeInstallation :exec +UPDATE installations +SET revoked_at = $1 +WHERE id = $2 +AND revoked_at IS NULL +` + +type RevokeInstallationParams struct { + RevokedAt sql.NullInt64 + InstallationID []byte +} + +func (q *Queries) RevokeInstallation(ctx context.Context, arg RevokeInstallationParams) error { + _, err := q.db.ExecContext(ctx, revokeInstallation, arg.RevokedAt, arg.InstallationID) + return err +} + +const updateKeyPackage = `-- name: UpdateKeyPackage :execrows +UPDATE installations +SET key_package = $1, updated_at = $2, expiration = $3 +WHERE id = $4 +` + +type UpdateKeyPackageParams struct { + KeyPackage []byte + UpdatedAt int64 + Expiration int64 + ID []byte +} + +func (q *Queries) UpdateKeyPackage(ctx context.Context, arg UpdateKeyPackageParams) (int64, error) { + result, err := q.db.ExecContext(ctx, updateKeyPackage, + arg.KeyPackage, + arg.UpdatedAt, + arg.Expiration, + arg.ID, + ) + if err != nil { + return 0, err + } + return result.RowsAffected() +} diff --git a/pkg/proto/identity/associations/signature.pb.go b/pkg/proto/identity/associations/signature.pb.go index 9a49794b..8f9824dc 100644 --- a/pkg/proto/identity/associations/signature.pb.go +++ b/pkg/proto/identity/associations/signature.pb.go @@ -78,7 +78,10 @@ type RecoverableEd25519Signature struct { sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields + // 64 bytes [R(32 bytes) || S(32 bytes)] Bytes []byte `protobuf:"bytes,1,opt,name=bytes,proto3" json:"bytes,omitempty"` + // 32 bytes + PublicKey []byte `protobuf:"bytes,2,opt,name=public_key,json=publicKey,proto3" json:"public_key,omitempty"` } func (x *RecoverableEd25519Signature) Reset() { @@ -120,15 +123,22 @@ func (x *RecoverableEd25519Signature) GetBytes() []byte { return nil } +func (x *RecoverableEd25519Signature) GetPublicKey() []byte { + if x != nil { + return x.PublicKey + } + return nil +} + // Smart wallet signature type Erc1271Signature struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields - // CAIP-10 contract address + // CAIP-10 // https://github.com/ChainAgnostic/CAIPs/blob/main/CAIPs/caip-10.md - ContractAddress string `protobuf:"bytes,1,opt,name=contract_address,json=contractAddress,proto3" json:"contract_address,omitempty"` + AccountId string `protobuf:"bytes,1,opt,name=account_id,json=accountId,proto3" json:"account_id,omitempty"` // Specify the block number to verify the signature against BlockNumber uint64 `protobuf:"varint,2,opt,name=block_number,json=blockNumber,proto3" json:"block_number,omitempty"` // The actual signature bytes @@ -167,9 +177,9 @@ func (*Erc1271Signature) Descriptor() ([]byte, []int) { return file_identity_associations_signature_proto_rawDescGZIP(), []int{2} } -func (x *Erc1271Signature) GetContractAddress() string { +func (x *Erc1271Signature) GetAccountId() string { if x != nil { - return x.ContractAddress + return x.AccountId } return "" } @@ -377,71 +387,72 @@ var file_identity_associations_signature_proto_rawDesc = []byte{ 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0x31, 0x0a, 0x19, 0x52, 0x65, 0x63, 0x6f, 0x76, 0x65, 0x72, 0x61, 0x62, 0x6c, 0x65, 0x45, 0x63, 0x64, 0x73, 0x61, 0x53, 0x69, 0x67, 0x6e, 0x61, 0x74, 0x75, 0x72, 0x65, 0x12, 0x14, 0x0a, 0x05, 0x62, 0x79, 0x74, 0x65, 0x73, 0x18, 0x01, 0x20, 0x01, - 0x28, 0x0c, 0x52, 0x05, 0x62, 0x79, 0x74, 0x65, 0x73, 0x22, 0x33, 0x0a, 0x1b, 0x52, 0x65, 0x63, + 0x28, 0x0c, 0x52, 0x05, 0x62, 0x79, 0x74, 0x65, 0x73, 0x22, 0x52, 0x0a, 0x1b, 0x52, 0x65, 0x63, 0x6f, 0x76, 0x65, 0x72, 0x61, 0x62, 0x6c, 0x65, 0x45, 0x64, 0x32, 0x35, 0x35, 0x31, 0x39, 0x53, 0x69, 0x67, 0x6e, 0x61, 0x74, 0x75, 0x72, 0x65, 0x12, 0x14, 0x0a, 0x05, 0x62, 0x79, 0x74, 0x65, - 0x73, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x05, 0x62, 0x79, 0x74, 0x65, 0x73, 0x22, 0x7e, - 0x0a, 0x10, 0x45, 0x72, 0x63, 0x31, 0x32, 0x37, 0x31, 0x53, 0x69, 0x67, 0x6e, 0x61, 0x74, 0x75, - 0x72, 0x65, 0x12, 0x29, 0x0a, 0x10, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x61, 0x63, 0x74, 0x5f, 0x61, - 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0f, 0x63, 0x6f, - 0x6e, 0x74, 0x72, 0x61, 0x63, 0x74, 0x41, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x12, 0x21, 0x0a, - 0x0c, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x5f, 0x6e, 0x75, 0x6d, 0x62, 0x65, 0x72, 0x18, 0x02, 0x20, - 0x01, 0x28, 0x04, 0x52, 0x0b, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x4e, 0x75, 0x6d, 0x62, 0x65, 0x72, - 0x12, 0x1c, 0x0a, 0x09, 0x73, 0x69, 0x67, 0x6e, 0x61, 0x74, 0x75, 0x72, 0x65, 0x18, 0x03, 0x20, - 0x01, 0x28, 0x0c, 0x52, 0x09, 0x73, 0x69, 0x67, 0x6e, 0x61, 0x74, 0x75, 0x72, 0x65, 0x22, 0xbc, - 0x01, 0x0a, 0x18, 0x4c, 0x65, 0x67, 0x61, 0x63, 0x79, 0x44, 0x65, 0x6c, 0x65, 0x67, 0x61, 0x74, - 0x65, 0x64, 0x53, 0x69, 0x67, 0x6e, 0x61, 0x74, 0x75, 0x72, 0x65, 0x12, 0x4b, 0x0a, 0x0d, 0x64, - 0x65, 0x6c, 0x65, 0x67, 0x61, 0x74, 0x65, 0x64, 0x5f, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, - 0x28, 0x0b, 0x32, 0x26, 0x2e, 0x78, 0x6d, 0x74, 0x70, 0x2e, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, - 0x65, 0x5f, 0x63, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x74, 0x73, 0x2e, 0x53, 0x69, 0x67, 0x6e, 0x65, - 0x64, 0x50, 0x75, 0x62, 0x6c, 0x69, 0x63, 0x4b, 0x65, 0x79, 0x52, 0x0c, 0x64, 0x65, 0x6c, 0x65, - 0x67, 0x61, 0x74, 0x65, 0x64, 0x4b, 0x65, 0x79, 0x12, 0x53, 0x0a, 0x09, 0x73, 0x69, 0x67, 0x6e, - 0x61, 0x74, 0x75, 0x72, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x35, 0x2e, 0x78, 0x6d, - 0x74, 0x70, 0x2e, 0x69, 0x64, 0x65, 0x6e, 0x74, 0x69, 0x74, 0x79, 0x2e, 0x61, 0x73, 0x73, 0x6f, - 0x63, 0x69, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x2e, 0x52, 0x65, 0x63, 0x6f, 0x76, 0x65, 0x72, - 0x61, 0x62, 0x6c, 0x65, 0x45, 0x63, 0x64, 0x73, 0x61, 0x53, 0x69, 0x67, 0x6e, 0x61, 0x74, 0x75, - 0x72, 0x65, 0x52, 0x09, 0x73, 0x69, 0x67, 0x6e, 0x61, 0x74, 0x75, 0x72, 0x65, 0x22, 0xff, 0x02, - 0x0a, 0x09, 0x53, 0x69, 0x67, 0x6e, 0x61, 0x74, 0x75, 0x72, 0x65, 0x12, 0x50, 0x0a, 0x07, 0x65, - 0x72, 0x63, 0x5f, 0x31, 0x39, 0x31, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x35, 0x2e, 0x78, - 0x6d, 0x74, 0x70, 0x2e, 0x69, 0x64, 0x65, 0x6e, 0x74, 0x69, 0x74, 0x79, 0x2e, 0x61, 0x73, 0x73, - 0x6f, 0x63, 0x69, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x2e, 0x52, 0x65, 0x63, 0x6f, 0x76, 0x65, - 0x72, 0x61, 0x62, 0x6c, 0x65, 0x45, 0x63, 0x64, 0x73, 0x61, 0x53, 0x69, 0x67, 0x6e, 0x61, 0x74, - 0x75, 0x72, 0x65, 0x48, 0x00, 0x52, 0x06, 0x65, 0x72, 0x63, 0x31, 0x39, 0x31, 0x12, 0x49, 0x0a, - 0x08, 0x65, 0x72, 0x63, 0x5f, 0x31, 0x32, 0x37, 0x31, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, - 0x2c, 0x2e, 0x78, 0x6d, 0x74, 0x70, 0x2e, 0x69, 0x64, 0x65, 0x6e, 0x74, 0x69, 0x74, 0x79, 0x2e, - 0x61, 0x73, 0x73, 0x6f, 0x63, 0x69, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x2e, 0x45, 0x72, 0x63, - 0x31, 0x32, 0x37, 0x31, 0x53, 0x69, 0x67, 0x6e, 0x61, 0x74, 0x75, 0x72, 0x65, 0x48, 0x00, 0x52, - 0x07, 0x65, 0x72, 0x63, 0x31, 0x32, 0x37, 0x31, 0x12, 0x64, 0x0a, 0x10, 0x69, 0x6e, 0x73, 0x74, - 0x61, 0x6c, 0x6c, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x5f, 0x6b, 0x65, 0x79, 0x18, 0x03, 0x20, 0x01, - 0x28, 0x0b, 0x32, 0x37, 0x2e, 0x78, 0x6d, 0x74, 0x70, 0x2e, 0x69, 0x64, 0x65, 0x6e, 0x74, 0x69, + 0x73, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x05, 0x62, 0x79, 0x74, 0x65, 0x73, 0x12, 0x1d, + 0x0a, 0x0a, 0x70, 0x75, 0x62, 0x6c, 0x69, 0x63, 0x5f, 0x6b, 0x65, 0x79, 0x18, 0x02, 0x20, 0x01, + 0x28, 0x0c, 0x52, 0x09, 0x70, 0x75, 0x62, 0x6c, 0x69, 0x63, 0x4b, 0x65, 0x79, 0x22, 0x72, 0x0a, + 0x10, 0x45, 0x72, 0x63, 0x31, 0x32, 0x37, 0x31, 0x53, 0x69, 0x67, 0x6e, 0x61, 0x74, 0x75, 0x72, + 0x65, 0x12, 0x1d, 0x0a, 0x0a, 0x61, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x5f, 0x69, 0x64, 0x18, + 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x61, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x49, 0x64, + 0x12, 0x21, 0x0a, 0x0c, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x5f, 0x6e, 0x75, 0x6d, 0x62, 0x65, 0x72, + 0x18, 0x02, 0x20, 0x01, 0x28, 0x04, 0x52, 0x0b, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x4e, 0x75, 0x6d, + 0x62, 0x65, 0x72, 0x12, 0x1c, 0x0a, 0x09, 0x73, 0x69, 0x67, 0x6e, 0x61, 0x74, 0x75, 0x72, 0x65, + 0x18, 0x03, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x09, 0x73, 0x69, 0x67, 0x6e, 0x61, 0x74, 0x75, 0x72, + 0x65, 0x22, 0xbc, 0x01, 0x0a, 0x18, 0x4c, 0x65, 0x67, 0x61, 0x63, 0x79, 0x44, 0x65, 0x6c, 0x65, + 0x67, 0x61, 0x74, 0x65, 0x64, 0x53, 0x69, 0x67, 0x6e, 0x61, 0x74, 0x75, 0x72, 0x65, 0x12, 0x4b, + 0x0a, 0x0d, 0x64, 0x65, 0x6c, 0x65, 0x67, 0x61, 0x74, 0x65, 0x64, 0x5f, 0x6b, 0x65, 0x79, 0x18, + 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x26, 0x2e, 0x78, 0x6d, 0x74, 0x70, 0x2e, 0x6d, 0x65, 0x73, + 0x73, 0x61, 0x67, 0x65, 0x5f, 0x63, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x74, 0x73, 0x2e, 0x53, 0x69, + 0x67, 0x6e, 0x65, 0x64, 0x50, 0x75, 0x62, 0x6c, 0x69, 0x63, 0x4b, 0x65, 0x79, 0x52, 0x0c, 0x64, + 0x65, 0x6c, 0x65, 0x67, 0x61, 0x74, 0x65, 0x64, 0x4b, 0x65, 0x79, 0x12, 0x53, 0x0a, 0x09, 0x73, + 0x69, 0x67, 0x6e, 0x61, 0x74, 0x75, 0x72, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x35, + 0x2e, 0x78, 0x6d, 0x74, 0x70, 0x2e, 0x69, 0x64, 0x65, 0x6e, 0x74, 0x69, 0x74, 0x79, 0x2e, 0x61, + 0x73, 0x73, 0x6f, 0x63, 0x69, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x2e, 0x52, 0x65, 0x63, 0x6f, + 0x76, 0x65, 0x72, 0x61, 0x62, 0x6c, 0x65, 0x45, 0x63, 0x64, 0x73, 0x61, 0x53, 0x69, 0x67, 0x6e, + 0x61, 0x74, 0x75, 0x72, 0x65, 0x52, 0x09, 0x73, 0x69, 0x67, 0x6e, 0x61, 0x74, 0x75, 0x72, 0x65, + 0x22, 0xff, 0x02, 0x0a, 0x09, 0x53, 0x69, 0x67, 0x6e, 0x61, 0x74, 0x75, 0x72, 0x65, 0x12, 0x50, + 0x0a, 0x07, 0x65, 0x72, 0x63, 0x5f, 0x31, 0x39, 0x31, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, + 0x35, 0x2e, 0x78, 0x6d, 0x74, 0x70, 0x2e, 0x69, 0x64, 0x65, 0x6e, 0x74, 0x69, 0x74, 0x79, 0x2e, + 0x61, 0x73, 0x73, 0x6f, 0x63, 0x69, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x2e, 0x52, 0x65, 0x63, + 0x6f, 0x76, 0x65, 0x72, 0x61, 0x62, 0x6c, 0x65, 0x45, 0x63, 0x64, 0x73, 0x61, 0x53, 0x69, 0x67, + 0x6e, 0x61, 0x74, 0x75, 0x72, 0x65, 0x48, 0x00, 0x52, 0x06, 0x65, 0x72, 0x63, 0x31, 0x39, 0x31, + 0x12, 0x49, 0x0a, 0x08, 0x65, 0x72, 0x63, 0x5f, 0x31, 0x32, 0x37, 0x31, 0x18, 0x02, 0x20, 0x01, + 0x28, 0x0b, 0x32, 0x2c, 0x2e, 0x78, 0x6d, 0x74, 0x70, 0x2e, 0x69, 0x64, 0x65, 0x6e, 0x74, 0x69, 0x74, 0x79, 0x2e, 0x61, 0x73, 0x73, 0x6f, 0x63, 0x69, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x2e, - 0x52, 0x65, 0x63, 0x6f, 0x76, 0x65, 0x72, 0x61, 0x62, 0x6c, 0x65, 0x45, 0x64, 0x32, 0x35, 0x35, - 0x31, 0x39, 0x53, 0x69, 0x67, 0x6e, 0x61, 0x74, 0x75, 0x72, 0x65, 0x48, 0x00, 0x52, 0x0f, 0x69, - 0x6e, 0x73, 0x74, 0x61, 0x6c, 0x6c, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x4b, 0x65, 0x79, 0x12, 0x62, - 0x0a, 0x11, 0x64, 0x65, 0x6c, 0x65, 0x67, 0x61, 0x74, 0x65, 0x64, 0x5f, 0x65, 0x72, 0x63, 0x5f, - 0x31, 0x39, 0x31, 0x18, 0x04, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x34, 0x2e, 0x78, 0x6d, 0x74, 0x70, - 0x2e, 0x69, 0x64, 0x65, 0x6e, 0x74, 0x69, 0x74, 0x79, 0x2e, 0x61, 0x73, 0x73, 0x6f, 0x63, 0x69, - 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x2e, 0x4c, 0x65, 0x67, 0x61, 0x63, 0x79, 0x44, 0x65, 0x6c, - 0x65, 0x67, 0x61, 0x74, 0x65, 0x64, 0x53, 0x69, 0x67, 0x6e, 0x61, 0x74, 0x75, 0x72, 0x65, 0x48, - 0x00, 0x52, 0x0f, 0x64, 0x65, 0x6c, 0x65, 0x67, 0x61, 0x74, 0x65, 0x64, 0x45, 0x72, 0x63, 0x31, - 0x39, 0x31, 0x42, 0x0b, 0x0a, 0x09, 0x73, 0x69, 0x67, 0x6e, 0x61, 0x74, 0x75, 0x72, 0x65, 0x42, - 0xf8, 0x01, 0x0a, 0x1e, 0x63, 0x6f, 0x6d, 0x2e, 0x78, 0x6d, 0x74, 0x70, 0x2e, 0x69, 0x64, 0x65, + 0x45, 0x72, 0x63, 0x31, 0x32, 0x37, 0x31, 0x53, 0x69, 0x67, 0x6e, 0x61, 0x74, 0x75, 0x72, 0x65, + 0x48, 0x00, 0x52, 0x07, 0x65, 0x72, 0x63, 0x31, 0x32, 0x37, 0x31, 0x12, 0x64, 0x0a, 0x10, 0x69, + 0x6e, 0x73, 0x74, 0x61, 0x6c, 0x6c, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x5f, 0x6b, 0x65, 0x79, 0x18, + 0x03, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x37, 0x2e, 0x78, 0x6d, 0x74, 0x70, 0x2e, 0x69, 0x64, 0x65, 0x6e, 0x74, 0x69, 0x74, 0x79, 0x2e, 0x61, 0x73, 0x73, 0x6f, 0x63, 0x69, 0x61, 0x74, 0x69, 0x6f, - 0x6e, 0x73, 0x42, 0x0e, 0x53, 0x69, 0x67, 0x6e, 0x61, 0x74, 0x75, 0x72, 0x65, 0x50, 0x72, 0x6f, - 0x74, 0x6f, 0x50, 0x01, 0x5a, 0x3c, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, - 0x2f, 0x78, 0x6d, 0x74, 0x70, 0x2f, 0x78, 0x6d, 0x74, 0x70, 0x2d, 0x6e, 0x6f, 0x64, 0x65, 0x2d, - 0x67, 0x6f, 0x2f, 0x70, 0x6b, 0x67, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2f, 0x69, 0x64, 0x65, - 0x6e, 0x74, 0x69, 0x74, 0x79, 0x2f, 0x61, 0x73, 0x73, 0x6f, 0x63, 0x69, 0x61, 0x74, 0x69, 0x6f, - 0x6e, 0x73, 0xa2, 0x02, 0x03, 0x58, 0x49, 0x41, 0xaa, 0x02, 0x1a, 0x58, 0x6d, 0x74, 0x70, 0x2e, - 0x49, 0x64, 0x65, 0x6e, 0x74, 0x69, 0x74, 0x79, 0x2e, 0x41, 0x73, 0x73, 0x6f, 0x63, 0x69, 0x61, - 0x74, 0x69, 0x6f, 0x6e, 0x73, 0xca, 0x02, 0x1a, 0x58, 0x6d, 0x74, 0x70, 0x5c, 0x49, 0x64, 0x65, + 0x6e, 0x73, 0x2e, 0x52, 0x65, 0x63, 0x6f, 0x76, 0x65, 0x72, 0x61, 0x62, 0x6c, 0x65, 0x45, 0x64, + 0x32, 0x35, 0x35, 0x31, 0x39, 0x53, 0x69, 0x67, 0x6e, 0x61, 0x74, 0x75, 0x72, 0x65, 0x48, 0x00, + 0x52, 0x0f, 0x69, 0x6e, 0x73, 0x74, 0x61, 0x6c, 0x6c, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x4b, 0x65, + 0x79, 0x12, 0x62, 0x0a, 0x11, 0x64, 0x65, 0x6c, 0x65, 0x67, 0x61, 0x74, 0x65, 0x64, 0x5f, 0x65, + 0x72, 0x63, 0x5f, 0x31, 0x39, 0x31, 0x18, 0x04, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x34, 0x2e, 0x78, + 0x6d, 0x74, 0x70, 0x2e, 0x69, 0x64, 0x65, 0x6e, 0x74, 0x69, 0x74, 0x79, 0x2e, 0x61, 0x73, 0x73, + 0x6f, 0x63, 0x69, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x2e, 0x4c, 0x65, 0x67, 0x61, 0x63, 0x79, + 0x44, 0x65, 0x6c, 0x65, 0x67, 0x61, 0x74, 0x65, 0x64, 0x53, 0x69, 0x67, 0x6e, 0x61, 0x74, 0x75, + 0x72, 0x65, 0x48, 0x00, 0x52, 0x0f, 0x64, 0x65, 0x6c, 0x65, 0x67, 0x61, 0x74, 0x65, 0x64, 0x45, + 0x72, 0x63, 0x31, 0x39, 0x31, 0x42, 0x0b, 0x0a, 0x09, 0x73, 0x69, 0x67, 0x6e, 0x61, 0x74, 0x75, + 0x72, 0x65, 0x42, 0xf8, 0x01, 0x0a, 0x1e, 0x63, 0x6f, 0x6d, 0x2e, 0x78, 0x6d, 0x74, 0x70, 0x2e, + 0x69, 0x64, 0x65, 0x6e, 0x74, 0x69, 0x74, 0x79, 0x2e, 0x61, 0x73, 0x73, 0x6f, 0x63, 0x69, 0x61, + 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x42, 0x0e, 0x53, 0x69, 0x67, 0x6e, 0x61, 0x74, 0x75, 0x72, 0x65, + 0x50, 0x72, 0x6f, 0x74, 0x6f, 0x50, 0x01, 0x5a, 0x3c, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, + 0x63, 0x6f, 0x6d, 0x2f, 0x78, 0x6d, 0x74, 0x70, 0x2f, 0x78, 0x6d, 0x74, 0x70, 0x2d, 0x6e, 0x6f, + 0x64, 0x65, 0x2d, 0x67, 0x6f, 0x2f, 0x70, 0x6b, 0x67, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2f, + 0x69, 0x64, 0x65, 0x6e, 0x74, 0x69, 0x74, 0x79, 0x2f, 0x61, 0x73, 0x73, 0x6f, 0x63, 0x69, 0x61, + 0x74, 0x69, 0x6f, 0x6e, 0x73, 0xa2, 0x02, 0x03, 0x58, 0x49, 0x41, 0xaa, 0x02, 0x1a, 0x58, 0x6d, + 0x74, 0x70, 0x2e, 0x49, 0x64, 0x65, 0x6e, 0x74, 0x69, 0x74, 0x79, 0x2e, 0x41, 0x73, 0x73, 0x6f, + 0x63, 0x69, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0xca, 0x02, 0x1a, 0x58, 0x6d, 0x74, 0x70, 0x5c, + 0x49, 0x64, 0x65, 0x6e, 0x74, 0x69, 0x74, 0x79, 0x5c, 0x41, 0x73, 0x73, 0x6f, 0x63, 0x69, 0x61, + 0x74, 0x69, 0x6f, 0x6e, 0x73, 0xe2, 0x02, 0x26, 0x58, 0x6d, 0x74, 0x70, 0x5c, 0x49, 0x64, 0x65, 0x6e, 0x74, 0x69, 0x74, 0x79, 0x5c, 0x41, 0x73, 0x73, 0x6f, 0x63, 0x69, 0x61, 0x74, 0x69, 0x6f, - 0x6e, 0x73, 0xe2, 0x02, 0x26, 0x58, 0x6d, 0x74, 0x70, 0x5c, 0x49, 0x64, 0x65, 0x6e, 0x74, 0x69, - 0x74, 0x79, 0x5c, 0x41, 0x73, 0x73, 0x6f, 0x63, 0x69, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x5c, - 0x47, 0x50, 0x42, 0x4d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0xea, 0x02, 0x1c, 0x58, 0x6d, - 0x74, 0x70, 0x3a, 0x3a, 0x49, 0x64, 0x65, 0x6e, 0x74, 0x69, 0x74, 0x79, 0x3a, 0x3a, 0x41, 0x73, - 0x73, 0x6f, 0x63, 0x69, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, - 0x6f, 0x33, + 0x6e, 0x73, 0x5c, 0x47, 0x50, 0x42, 0x4d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0xea, 0x02, + 0x1c, 0x58, 0x6d, 0x74, 0x70, 0x3a, 0x3a, 0x49, 0x64, 0x65, 0x6e, 0x74, 0x69, 0x74, 0x79, 0x3a, + 0x3a, 0x41, 0x73, 0x73, 0x6f, 0x63, 0x69, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x62, 0x06, 0x70, + 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( diff --git a/pkg/proto/openapi/identity/api/v1/identity.swagger.json b/pkg/proto/openapi/identity/api/v1/identity.swagger.json index c0e1850b..ce2bc819 100644 --- a/pkg/proto/openapi/identity/api/v1/identity.swagger.json +++ b/pkg/proto/openapi/identity/api/v1/identity.swagger.json @@ -213,9 +213,9 @@ "associationsErc1271Signature": { "type": "object", "properties": { - "contractAddress": { + "accountId": { "type": "string", - "title": "CAIP-10 contract address\nhttps://github.com/ChainAgnostic/CAIPs/blob/main/CAIPs/caip-10.md" + "title": "CAIP-10\nhttps://github.com/ChainAgnostic/CAIPs/blob/main/CAIPs/caip-10.md" }, "blockNumber": { "type": "string", @@ -298,7 +298,13 @@ "properties": { "bytes": { "type": "string", - "format": "byte" + "format": "byte", + "title": "64 bytes [R(32 bytes) || S(32 bytes)]" + }, + "publicKey": { + "type": "string", + "format": "byte", + "title": "32 bytes" } }, "title": "EdDSA signature for 25519" diff --git a/pkg/proto/openapi/mls_validation/v1/service.swagger.json b/pkg/proto/openapi/mls_validation/v1/service.swagger.json index 736ffc92..e581e909 100644 --- a/pkg/proto/openapi/mls_validation/v1/service.swagger.json +++ b/pkg/proto/openapi/mls_validation/v1/service.swagger.json @@ -142,9 +142,9 @@ "associationsErc1271Signature": { "type": "object", "properties": { - "contractAddress": { + "accountId": { "type": "string", - "title": "CAIP-10 contract address\nhttps://github.com/ChainAgnostic/CAIPs/blob/main/CAIPs/caip-10.md" + "title": "CAIP-10\nhttps://github.com/ChainAgnostic/CAIPs/blob/main/CAIPs/caip-10.md" }, "blockNumber": { "type": "string", @@ -251,7 +251,13 @@ "properties": { "bytes": { "type": "string", - "format": "byte" + "format": "byte", + "title": "64 bytes [R(32 bytes) || S(32 bytes)]" + }, + "publicKey": { + "type": "string", + "format": "byte", + "title": "32 bytes" } }, "title": "EdDSA signature for 25519" diff --git a/pkg/server/pgxdb.go b/pkg/server/pgxdb.go new file mode 100644 index 00000000..2c33c905 --- /dev/null +++ b/pkg/server/pgxdb.go @@ -0,0 +1,49 @@ +package server + +import ( + "context" + "database/sql" + "fmt" + "time" + + "github.com/jackc/pgx/v5" + "github.com/jackc/pgx/v5/pgxpool" + "github.com/jackc/pgx/v5/stdlib" + _ "github.com/jackc/pgx/v5/stdlib" + "github.com/uptrace/bun" + "github.com/uptrace/bun/dialect/pgdialect" +) + +func newPGXDB(dsn string, waitForDB, statementTimeout time.Duration) (*sql.DB, error) { + config, err := pgxpool.ParseConfig(dsn) + if err != nil { + return nil, err + } + config.ConnConfig.DefaultQueryExecMode = pgx.QueryExecModeSimpleProtocol + config.ConnConfig.RuntimeParams["statement_timeout"] = fmt.Sprint(statementTimeout.Milliseconds()) + + dbpool, err := pgxpool.NewWithConfig(context.Background(), config) + if err != nil { + return nil, err + } + db := stdlib.OpenDBFromPool(dbpool) + + waitUntil := time.Now().Add(waitForDB) + + err = db.Ping() + for err != nil && time.Now().Before(waitUntil) { + time.Sleep(3 * time.Second) + err = db.Ping() + } + + return db, nil +} + +func newBunPGXDb(dsn string, waitForDB, statementTimeout time.Duration) (*bun.DB, error) { + pgxDb, err := newPGXDB(dsn, waitForDB, statementTimeout) + if err != nil { + return nil, err + } + + return bun.NewDB(pgxDb, pgdialect.New()), nil +} diff --git a/pkg/server/server.go b/pkg/server/server.go index 13d3e1b9..6dc0e4af 100644 --- a/pkg/server/server.go +++ b/pkg/server/server.go @@ -231,7 +231,7 @@ func New(ctx context.Context, log *zap.Logger, options Options) (*Server, error) var MLSStore *mlsstore.Store if options.MLSStore.DbConnectionString != "" { - if s.mlsDB, err = createBunDB(options.MLSStore.DbConnectionString, options.WaitForDB, options.MLSStore.ReadTimeout, options.MLSStore.WriteTimeout, options.MLSStore.MaxOpenConns); err != nil { + if s.mlsDB, err = newBunPGXDb(options.MLSStore.DbConnectionString, options.WaitForDB, options.MLSStore.ReadTimeout); err != nil { return nil, errors.Wrap(err, "creating mls db") } diff --git a/pkg/testing/store.go b/pkg/testing/store.go index bb4c4aff..cb30a27a 100644 --- a/pkg/testing/store.go +++ b/pkg/testing/store.go @@ -5,6 +5,8 @@ import ( "database/sql" "testing" + "github.com/jackc/pgx/v5" + "github.com/jackc/pgx/v5/stdlib" "github.com/stretchr/testify/require" "github.com/uptrace/bun" "github.com/uptrace/bun/dialect/pgdialect" @@ -36,6 +38,27 @@ func NewDB(t testing.TB) (*sql.DB, string, func()) { } } +func NewPGXDB(t testing.TB) (*sql.DB, string, func()) { + dsn := localTestDBDSNPrefix + localTestDBDSNSuffix + config, err := pgx.ParseConfig(dsn) + require.NoError(t, err) + ctlDB := stdlib.OpenDB(*config) + dbName := "test_" + RandomStringLower(12) + _, err = ctlDB.Exec("CREATE DATABASE " + dbName) + require.NoError(t, err) + + dsn = localTestDBDSNPrefix + "/" + dbName + localTestDBDSNSuffix + config2, err := pgx.ParseConfig(dsn) + require.NoError(t, err) + db := stdlib.OpenDB(*config2) + return db, dsn, func() { + db.Close() + _, err = ctlDB.Exec("DROP DATABASE " + dbName) + require.NoError(t, err) + ctlDB.Close() + } +} + func NewAuthzDB(t testing.TB) (*bun.DB, string, func()) { db, dsn, cleanup := NewDB(t) bunDB := bun.NewDB(db, pgdialect.New()) @@ -51,7 +74,7 @@ func NewAuthzDB(t testing.TB) (*bun.DB, string, func()) { } func NewMLSDB(t *testing.T) (*bun.DB, string, func()) { - db, dsn, cleanup := NewDB(t) + db, dsn, cleanup := NewPGXDB(t) bunDB := bun.NewDB(db, pgdialect.New()) ctx := context.Background() diff --git a/sqlc.yaml b/sqlc.yaml new file mode 100644 index 00000000..30575b4c --- /dev/null +++ b/sqlc.yaml @@ -0,0 +1,9 @@ +version: "2" +sql: + - engine: "postgresql" + queries: "pkg/mls/store/queries.sql" + schema: "pkg/migrations/mls" + gen: + go: + package: "queries" + out: "pkg/mls/store/queries"