feature/refactor did state (#10)

* feat(did): remove account types

* feat: Refactor Property to Proof in zkprop.go

* feat: add ZKP proof mechanism for verifications

* fix: return bool and error from pinInitialVault

* feat: implement KeyshareSet for managing user and validator keyshares

* feat: Update Credential type in protobuf

* feat: update credential schema with sign count

* feat: migrate  and  modules to middleware

* refactor: rename vault module to ORM

* chore(dwn): add service worker registration to index template

* feat: integrate service worker for offline functionality

* refactor(did): use DIDNamespace enum for verification method in proto reflection

* refactor: update protobuf definitions to support Keyshare

* feat: expose did keeper in app keepers

* Add Motr Web App

* refactor: rename motr/handlers/discovery.go to motr/handlers/openid.go

* refactor: move session related code to middleware

* feat: add database operations for managing assets, chains, and credentials

* feat: add htmx support for UI updates

* refactor: extract common helper scripts

* chore: remove unused storage GUI components

* refactor: Move frontend rendering to dedicated handlers

* refactor: rename  to

* refactor: move alert implementation to templ

* feat: add alert component with icon, title, and message

* feat: add new RequestHeaders struct to store request headers

* Feature/create home view (#9)

* refactor: move view logic to new htmx handler

* refactor: remove unnecessary dependencies

* refactor: remove unused dependencies

* feat(devbox): integrate air for local development

* feat: implement openid connect discovery document

* refactor: rename  to

* refactor(did): update service handling to support DNS discovery

* feat: add support for user and validator keyshares

* refactor: move keyshare signing logic to signer
This commit is contained in:
Prad Nukala
2024-09-11 15:10:54 -04:00
committed by GitHub
parent 4f2d342649
commit bbfe2a2329
197 changed files with 14668 additions and 27810 deletions
+91
View File
@@ -0,0 +1,91 @@
package db
import (
"fmt"
"github.com/onsonr/sonr/internal/db/orm"
"gorm.io/gorm"
)
// createInitialTables creates the initial tables in the database.
func createInitialTables(db *gorm.DB) (*DB, error) {
err := db.AutoMigrate(
&orm.Account{},
&orm.Asset{},
&orm.Keyshare{},
&orm.Credential{},
&orm.Profile{},
&orm.Property{},
&orm.Permission{},
)
if err != nil {
return nil, fmt.Errorf("failed to create table: %w", err)
}
return &DB{db}, nil
}
// AddAccount adds a new account to the database
func (db *DB) AddAccount(account *orm.Account) error {
tx := db.Create(account)
if tx.Error != nil {
return fmt.Errorf("failed to add account: %w", tx.Error)
}
return nil
}
// AddKeyshare adds a new keyshare to the database
func (db *DB) AddKeyshare(keyshare *orm.Keyshare) error {
tx := db.Create(keyshare)
if tx.Error != nil {
return fmt.Errorf("failed to add keyshare: %w", tx.Error)
}
return nil
}
// AddCredential adds a new credential to the database
func (db *DB) AddCredential(credential *orm.Credential) error {
tx := db.Create(credential)
if tx.Error != nil {
return fmt.Errorf("failed to add credential: %w", tx.Error)
}
return nil
}
// AddProfile adds a new profile to the database
func (db *DB) AddProfile(profile *orm.Profile) error {
tx := db.Create(profile)
if tx.Error != nil {
return fmt.Errorf("failed to add profile: %w", tx.Error)
}
return nil
}
// AddProperty adds a new property to the database
func (db *DB) AddProperty(property *orm.Property) error {
tx := db.Create(property)
if tx.Error != nil {
return fmt.Errorf("failed to add property: %w", tx.Error)
}
return nil
}
// AddPermission adds a new permission to the database
func (db *DB) AddPermission(permission *orm.Permission) error {
tx := db.Create(permission)
if tx.Error != nil {
return fmt.Errorf("failed to add permission: %w", tx.Error)
}
return nil
}
+17
View File
@@ -0,0 +1,17 @@
package db
import "gorm.io/gorm"
type DB struct {
*gorm.DB
}
func New(opts ...DBOption) *DBConfig {
config := &DBConfig{
fileName: "vault.db",
}
for _, opt := range opts {
opt(config)
}
return config
}
-174
View File
@@ -1,174 +0,0 @@
package db
import (
"fmt"
"github.com/ncruces/go-sqlite3"
_ "github.com/ncruces/go-sqlite3/embed"
)
type DB struct {
*sqlite3.Conn
}
func New(opts ...DBOption) *DBConfig {
config := &DBConfig{
fileName: "vault.db",
}
for _, opt := range opts {
opt(config)
}
return config
}
func Open(config *DBConfig) (*DB, error) {
conn, err := sqlite3.Open(config.ConnectionString())
if err != nil {
return nil, fmt.Errorf("failed to open database: %w", err)
}
db := &DB{
Conn: conn,
}
if err := createTables(db); err != nil {
conn.Close()
return nil, fmt.Errorf("failed to create tables: %w", err)
}
return db, nil
}
func createTables(db *DB) error {
tables := []string{
createAccountsTable,
createAssetsTable,
createChainsTable,
createCredentialsTable,
createKeysharesTable,
createProfilesTable,
createPropertiesTable,
createPermissionsTable,
}
for _, table := range tables {
err := db.Exec(table)
if err != nil {
return fmt.Errorf("failed to create table: %w", err)
}
}
return nil
}
// AddAccount adds a new account to the database
func (db *DB) AddAccount(name, address string) error {
return db.Exec(insertAccountQuery(name, address))
}
// AddAsset adds a new asset to the database
func (db *DB) AddAsset(name, symbol string, decimals int, chainID int64) error {
return db.Exec(insertAssetQuery(name, symbol, decimals, chainID))
}
// AddChain adds a new chain to the database
func (db *DB) AddChain(name, networkID string) error {
return db.Exec(insertChainQuery(name, networkID))
}
// AddCredential adds a new credential to the database
func (db *DB) AddCredential(
handle, controller, attestationType, origin string,
credentialID, publicKey []byte,
transport string,
signCount uint32,
userPresent, userVerified, backupEligible, backupState, cloneWarning bool,
) error {
return db.Exec(insertCredentialQuery(
handle,
controller,
attestationType,
origin,
credentialID,
publicKey,
transport,
signCount,
userPresent,
userVerified,
backupEligible,
backupState,
cloneWarning,
))
}
//
// // AddProfile adds a new profile to the database
// func (db *DB) AddProfile(
// id, subject, controller, originURI string,
// publicMetadata, privateMetadata string,
// ) error {
// return db.statements["insertProfile"].Exec(
// id,
// subject,
// controller,
// originURI,
// publicMetadata,
// privateMetadata,
// )
// }
//
// // AddProperty adds a new property to the database
// func (db *DB) AddProperty(profileID, key string, accumulator, propertyKey []byte) error {
// return db.statements["insertProperty"].Exec(profileID, key, accumulator, propertyKey)
// }
//
// // AddPermission adds a new permission to the database
// func (db *DB) AddPermission(
// serviceID string,
// grants []DIDNamespace,
// scopes []PermissionScope,
// ) error {
// grantsJSON, err := json.Marshal(grants)
// if err != nil {
// return fmt.Errorf("failed to marshal grants: %w", err)
// }
//
// scopesJSON, err := json.Marshal(scopes)
// if err != nil {
// return fmt.Errorf("failed to marshal scopes: %w", err)
// }
//
// return db.statements["insertPermission"].Exec(
// serviceID,
// string(grantsJSON),
// string(scopesJSON),
// )
// }
//
// // GetPermission retrieves a permission from the database
// func (db *DB) GetPermission(serviceID string) ([]DIDNamespace, []PermissionScope, error) {
// stmt := db.statements["getPermission"]
// if err := stmt.Exec(serviceID); err != nil {
// return nil, nil, fmt.Errorf("failed to execute statement: %w", err)
// }
//
// if !stmt.Step() {
// return nil, nil, fmt.Errorf("permission not found")
// }
//
// grantsJSON := stmt.ColumnText(0)
// scopesJSON := stmt.ColumnText(1)
//
// var grants []DIDNamespace
// err := json.Unmarshal([]byte(grantsJSON), &grants)
// if err != nil {
// return nil, nil, fmt.Errorf("failed to unmarshal grants: %w", err)
// }
//
// var scopes []PermissionScope
// err = json.Unmarshal([]byte(scopesJSON), &scopes)
// if err != nil {
// return nil, nil, fmt.Errorf("failed to unmarshal scopes: %w", err)
// }
//
// return grants, scopes, nil
// }
-36
View File
@@ -1,36 +0,0 @@
package db
// DIDNamespace defines the different namespaces of DID
type DIDNamespace int
const (
DIDNamespaceUnspecified DIDNamespace = iota
DIDNamespaceIPFS
DIDNamespaceSonr
DIDNamespaceBitcoin
DIDNamespaceEthereum
DIDNamespaceIBC
DIDNamespaceWebauthn
DIDNamespaceDWN
DIDNamespaceService
)
// PermissionScope defines the Capabilities Controllers can grant for Services
type PermissionScope int
const (
PermissionScopeUnspecified PermissionScope = iota
PermissionScopeBasicInfo
PermissionScopeRecordsRead
PermissionScopeRecordsWrite
PermissionScopeTransactionsRead
PermissionScopeTransactionsWrite
PermissionScopeWalletsRead
PermissionScopeWalletsCreate
PermissionScopeWalletsSubscribe
PermissionScopeWalletsUpdate
PermissionScopeTransactionsVerify
PermissionScopeTransactionsBroadcast
PermissionScopeAdminUser
PermissionScopeAdminValidator
)
+9 -22
View File
@@ -4,11 +4,12 @@ import (
"crypto/rand"
"github.com/ncruces/go-sqlite3/gormlite"
"github.com/ncruces/go-sqlite3/vfs"
"golang.org/x/crypto/argon2"
"gorm.io/gorm"
"lukechampine.com/adiantum/hbsh"
"lukechampine.com/adiantum/hpolyc"
_ "github.com/ncruces/go-sqlite3/embed"
)
type DBOption func(config *DBConfig)
@@ -19,46 +20,32 @@ func WithDir(dir string) DBOption {
}
}
func WithInMemory() DBOption {
return func(config *DBConfig) {
config.InMemory = true
}
}
func WithSecretKey(secretKey string) DBOption {
return func(config *DBConfig) {
config.SecretKey = secretKey
}
}
func WithOpenFlag(flag vfs.OpenFlag) DBOption {
return func(config *DBConfig) {
config.OpenFlag = flag
}
}
type DBConfig struct {
Dir string
InMemory bool
SecretKey string
OpenFlag vfs.OpenFlag
fileName string
}
func (config *DBConfig) ConnectionString() string {
connStr := "file:"
if config.InMemory {
connStr += ":memory:"
} else {
connStr += config.Dir + "/" + config.fileName
}
connStr += config.Dir + "/" + config.fileName
return connStr
}
// GormDialector creates a gorm dialector for the database.
func (config *DBConfig) GormDialector() (*gorm.DB, error) {
return gorm.Open(gormlite.Open(config.ConnectionString()))
func (config *DBConfig) Open() (*DB, error) {
db, err := gorm.Open(gormlite.Open(config.ConnectionString()))
if err != nil {
return nil, err
}
return createInitialTables(db)
}
// HBSH creates an HBSH cipher given a key.
+14
View File
@@ -0,0 +1,14 @@
// Code generated from Pkl module `orm`. DO NOT EDIT.
package orm
type Account struct {
Id uint `pkl:"id" gorm:"primaryKey,autoIncrement" json:"id,omitempty" query:"id"`
Name string `pkl:"name" json:"name,omitempty" param:"name"`
Address string `pkl:"address" json:"address,omitempty" param:"address"`
PublicKey string `pkl:"publicKey" json:"publicKey,omitempty" param:"publicKey"`
CreatedAt *string `pkl:"createdAt" json:"createdAt,omitempty" param:"createdAt"`
}
+16
View File
@@ -0,0 +1,16 @@
// Code generated from Pkl module `orm`. DO NOT EDIT.
package orm
type Asset struct {
Id uint `pkl:"id" gorm:"primaryKey,autoIncrement" json:"id,omitempty" query:"id"`
Name string `pkl:"name" json:"name,omitempty" param:"name"`
Symbol string `pkl:"symbol" json:"symbol,omitempty" param:"symbol"`
Decimals int `pkl:"decimals" json:"decimals,omitempty" param:"decimals"`
ChainId *int `pkl:"chainId" json:"chainId,omitempty" param:"chainId"`
CreatedAt *string `pkl:"createdAt" json:"createdAt,omitempty" param:"createdAt"`
}
+12
View File
@@ -0,0 +1,12 @@
// Code generated from Pkl module `orm`. DO NOT EDIT.
package orm
type Chain struct {
Id uint `pkl:"id" gorm:"primaryKey,autoIncrement" json:"id,omitempty" query:"id"`
Name string `pkl:"name" json:"name,omitempty" param:"name"`
NetworkId string `pkl:"networkId" json:"networkId,omitempty" param:"networkId"`
CreatedAt *string `pkl:"createdAt" json:"createdAt,omitempty" param:"createdAt"`
}
+36
View File
@@ -0,0 +1,36 @@
// Code generated from Pkl module `orm`. DO NOT EDIT.
package orm
type Credential struct {
Id uint `pkl:"id" gorm:"primaryKey,autoIncrement" json:"id,omitempty" query:"id"`
Subject string `pkl:"subject" json:"subject,omitempty" param:"subject"`
Controller string `pkl:"controller" json:"controller,omitempty" param:"controller"`
AttestationType string `pkl:"attestationType" json:"attestationType,omitempty" param:"attestationType"`
Origin string `pkl:"origin" json:"origin,omitempty" param:"origin"`
CredentialId string `pkl:"credentialId" json:"credentialId,omitempty" param:"credentialId"`
PublicKey string `pkl:"publicKey" json:"publicKey,omitempty" param:"publicKey"`
Transport string `pkl:"transport" json:"transport,omitempty" param:"transport"`
SignCount uint `pkl:"signCount" json:"signCount,omitempty" param:"signCount"`
UserPresent bool `pkl:"userPresent" json:"userPresent,omitempty" param:"userPresent"`
UserVerified bool `pkl:"userVerified" json:"userVerified,omitempty" param:"userVerified"`
BackupEligible bool `pkl:"backupEligible" json:"backupEligible,omitempty" param:"backupEligible"`
BackupState bool `pkl:"backupState" json:"backupState,omitempty" param:"backupState"`
CloneWarning bool `pkl:"cloneWarning" json:"cloneWarning,omitempty" param:"cloneWarning"`
CreatedAt *string `pkl:"createdAt" json:"createdAt,omitempty" param:"createdAt"`
UpdatedAt *string `pkl:"updatedAt" json:"updatedAt,omitempty" param:"updatedAt"`
}
+34
View File
@@ -0,0 +1,34 @@
// Code generated from Pkl module `orm`. DO NOT EDIT.
package orm
type DiscoveryDocument struct {
Issuer string `pkl:"issuer" json:"issuer,omitempty" param:"issuer"`
AuthorizationEndpoint string `pkl:"authorization_endpoint" json:"authorization_endpoint,omitempty" param:"authorization_endpoint"`
TokenEndpoint string `pkl:"token_endpoint" json:"token_endpoint,omitempty" param:"token_endpoint"`
UserinfoEndpoint string `pkl:"userinfo_endpoint" json:"userinfo_endpoint,omitempty" param:"userinfo_endpoint"`
JwksUri string `pkl:"jwks_uri" json:"jwks_uri,omitempty" param:"jwks_uri"`
RegistrationEndpoint string `pkl:"registration_endpoint" json:"registration_endpoint,omitempty" param:"registration_endpoint"`
ScopesSupported []string `pkl:"scopes_supported" json:"scopes_supported,omitempty" param:"scopes_supported"`
ResponseTypesSupported []string `pkl:"response_types_supported" json:"response_types_supported,omitempty" param:"response_types_supported"`
ResponseModesSupported []string `pkl:"response_modes_supported" json:"response_modes_supported,omitempty" param:"response_modes_supported"`
SubjectTypesSupported []string `pkl:"subject_types_supported" json:"subject_types_supported,omitempty" param:"subject_types_supported"`
IdTokenSigningAlgValuesSupported []string `pkl:"id_token_signing_alg_values_supported" json:"id_token_signing_alg_values_supported,omitempty" param:"id_token_signing_alg_values_supported"`
ClaimsSupported []string `pkl:"claims_supported" json:"claims_supported,omitempty" param:"claims_supported"`
GrantTypesSupported []string `pkl:"grant_types_supported" json:"grant_types_supported,omitempty" param:"grant_types_supported"`
AcrValuesSupported []string `pkl:"acr_values_supported" json:"acr_values_supported,omitempty" param:"acr_values_supported"`
TokenEndpointAuthMethodsSupported []string `pkl:"token_endpoint_auth_methods_supported" json:"token_endpoint_auth_methods_supported,omitempty" param:"token_endpoint_auth_methods_supported"`
}
+20
View File
@@ -0,0 +1,20 @@
// Code generated from Pkl module `orm`. DO NOT EDIT.
package orm
type Keyshare struct {
Id uint `pkl:"id" gorm:"primaryKey,autoIncrement" json:"id,omitempty" query:"id"`
Metadata string `pkl:"metadata" json:"metadata,omitempty" param:"metadata"`
Payloads string `pkl:"payloads" json:"payloads,omitempty" param:"payloads"`
Protocol string `pkl:"protocol" json:"protocol,omitempty" param:"protocol"`
PublicKey string `pkl:"publicKey" json:"publicKey,omitempty" param:"publicKey"`
Role int `pkl:"role" json:"role,omitempty" param:"role"`
Version int `pkl:"version" json:"version,omitempty" param:"version"`
CreatedAt *string `pkl:"createdAt" json:"createdAt,omitempty" param:"createdAt"`
}
+36
View File
@@ -0,0 +1,36 @@
// Code generated from Pkl module `orm`. DO NOT EDIT.
package orm
import (
"context"
"github.com/apple/pkl-go/pkl"
)
type Orm struct {
}
// LoadFromPath loads the pkl module at the given path and evaluates it into a Orm
func LoadFromPath(ctx context.Context, path string) (ret *Orm, err error) {
evaluator, err := pkl.NewEvaluator(ctx, pkl.PreconfiguredOptions)
if err != nil {
return nil, err
}
defer func() {
cerr := evaluator.Close()
if err == nil {
err = cerr
}
}()
ret, err = Load(ctx, evaluator, pkl.FileSource(path))
return ret, err
}
// Load loads the pkl module at the given source and evaluates it with the given evaluator into a Orm
func Load(ctx context.Context, evaluator pkl.Evaluator, source *pkl.ModuleSource) (*Orm, error) {
var ret Orm
if err := evaluator.EvaluateModule(ctx, source, &ret); err != nil {
return nil, err
}
return &ret, nil
}
+16
View File
@@ -0,0 +1,16 @@
// Code generated from Pkl module `orm`. DO NOT EDIT.
package orm
type Permission struct {
Id uint `pkl:"id" gorm:"primaryKey,autoIncrement" json:"id,omitempty" query:"id"`
ServiceId string `pkl:"serviceId" json:"serviceId,omitempty" param:"serviceId"`
Grants string `pkl:"grants" json:"grants,omitempty" param:"grants"`
Scopes string `pkl:"scopes" json:"scopes,omitempty" param:"scopes"`
CreatedAt *string `pkl:"createdAt" json:"createdAt,omitempty" param:"createdAt"`
UpdatedAt *string `pkl:"updatedAt" json:"updatedAt,omitempty" param:"updatedAt"`
}
+20
View File
@@ -0,0 +1,20 @@
// Code generated from Pkl module `orm`. DO NOT EDIT.
package orm
type Profile struct {
Id string `pkl:"id" gorm:"primaryKey,autoIncrement" json:"id,omitempty" query:"id"`
Subject string `pkl:"subject" json:"subject,omitempty" param:"subject"`
Controller string `pkl:"controller" json:"controller,omitempty" param:"controller"`
OriginUri *string `pkl:"originUri" json:"originUri,omitempty" param:"originUri"`
PublicMetadata *string `pkl:"publicMetadata" json:"publicMetadata,omitempty" param:"publicMetadata"`
PrivateMetadata *string `pkl:"privateMetadata" json:"privateMetadata,omitempty" param:"privateMetadata"`
CreatedAt *string `pkl:"createdAt" json:"createdAt,omitempty" param:"createdAt"`
UpdatedAt *string `pkl:"updatedAt" json:"updatedAt,omitempty" param:"updatedAt"`
}
+14
View File
@@ -0,0 +1,14 @@
// Code generated from Pkl module `orm`. DO NOT EDIT.
package orm
type Property struct {
Id uint `pkl:"id" gorm:"primaryKey,autoIncrement" json:"id,omitempty" query:"id"`
ProfileId string `pkl:"profileId" json:"profileId,omitempty" param:"profileId"`
Key string `pkl:"key" json:"key,omitempty" param:"key"`
Accumulator string `pkl:"accumulator" json:"accumulator,omitempty" param:"accumulator"`
PropertyKey string `pkl:"propertyKey" json:"propertyKey,omitempty" param:"propertyKey"`
}
+16
View File
@@ -0,0 +1,16 @@
// Code generated from Pkl module `orm`. DO NOT EDIT.
package orm
type PublicKey struct {
Id uint `pkl:"id" gorm:"primaryKey,autoIncrement" json:"id,omitempty" query:"id"`
Role int `pkl:"role" json:"role,omitempty" param:"role"`
Algorithm int `pkl:"algorithm" json:"algorithm,omitempty" param:"algorithm"`
Encoding int `pkl:"encoding" json:"encoding,omitempty" param:"encoding"`
Jwk string `pkl:"jwk" json:"jwk,omitempty" param:"jwk"`
CreatedAt *string `pkl:"createdAt" json:"createdAt,omitempty" param:"createdAt"`
}
+18
View File
@@ -0,0 +1,18 @@
// Code generated from Pkl module `orm`. DO NOT EDIT.
package orm
import "github.com/apple/pkl-go/pkl"
func init() {
pkl.RegisterMapping("orm", Orm{})
pkl.RegisterMapping("orm#Account", Account{})
pkl.RegisterMapping("orm#Asset", Asset{})
pkl.RegisterMapping("orm#Chain", Chain{})
pkl.RegisterMapping("orm#Credential", Credential{})
pkl.RegisterMapping("orm#Profile", Profile{})
pkl.RegisterMapping("orm#Property", Property{})
pkl.RegisterMapping("orm#Keyshare", Keyshare{})
pkl.RegisterMapping("orm#PublicKey", PublicKey{})
pkl.RegisterMapping("orm#Permission", Permission{})
pkl.RegisterMapping("orm#DiscoveryDocument", DiscoveryDocument{})
}
-79
View File
@@ -1,79 +0,0 @@
package db
import "fmt"
// Account queries
func insertAccountQuery(name, address string) string {
return fmt.Sprintf(`INSERT INTO accounts (name, address) VALUES (%s, %s)`, name, address)
}
// Asset queries
func insertAssetQuery(name, symbol string, decimals int, chainID int64) string {
return fmt.Sprintf(
`INSERT INTO assets (name, symbol, decimals, chain_id) VALUES (%s, %s, %d, %d)`,
name,
symbol,
decimals,
chainID,
)
}
// Chain queries
func insertChainQuery(name string, networkID string) string {
return fmt.Sprintf(`INSERT INTO chains (name, network_id) VALUES (%s, %s)`, name, networkID)
}
// Credential queries
func insertCredentialQuery(
handle, controller, attestationType, origin string,
credentialID, publicKey []byte,
transport string,
signCount uint32,
userPresent, userVerified, backupEligible, backupState, cloneWarning bool,
) string {
return fmt.Sprintf(`INSERT INTO credentials (
handle, controller, attestation_type, origin,
credential_id, public_key, transport, sign_count,
user_present, user_verified, backup_eligible,
backup_state, clone_warning
) VALUES (%s, %s, %s, %s, %s, %s, %s, %d, %t, %t, %t, %t, %t)`,
handle, controller, attestationType, origin,
credentialID, publicKey, transport, signCount,
userPresent, userVerified, backupEligible,
backupState, cloneWarning)
}
// Profile queries
func insertProfileQuery(
id, subject, controller, originURI, publicMetadata, privateMetadata string,
) string {
return fmt.Sprintf(`INSERT INTO profiles (
id, subject, controller, origin_uri,
public_metadata, private_metadata
) VALUES (%s, %s, %s, %s, %s, %s)`,
id, subject, controller, originURI,
publicMetadata, privateMetadata)
}
// Property queries
func insertPropertyQuery(profileID, key, accumulator, propertyKey string) string {
return fmt.Sprintf(`INSERT INTO properties (
profile_id, key, accumulator, property_key
) VALUES (%s, %s, %s, %s)`,
profileID, key, accumulator, propertyKey)
}
// Permission queries
func insertPermissionQuery(serviceID, grants, scopes string) string {
return fmt.Sprintf(
`INSERT INTO permissions (service_id, grants, scopes) VALUES (%s, %s, %s)`,
serviceID,
grants,
scopes,
)
}
// GetPermission query
func getPermissionQuery(serviceID string) string {
return fmt.Sprintf(`SELECT grants, scopes FROM permissions WHERE service_id = %s`, serviceID)
}
-104
View File
@@ -1,104 +0,0 @@
package db
const (
createAccountsTable = `
CREATE TABLE IF NOT EXISTS accounts (
id INTEGER PRIMARY KEY AUTOINCREMENT,
name TEXT NOT NULL,
address TEXT NOT NULL UNIQUE,
public_key BLOB NOT NULL,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
)
`
createAssetsTable = `
CREATE TABLE IF NOT EXISTS assets (
id INTEGER PRIMARY KEY AUTOINCREMENT,
name TEXT NOT NULL,
symbol TEXT NOT NULL,
decimals INTEGER NOT NULL,
chain_id INTEGER,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (chain_id) REFERENCES chains(id)
)
`
createChainsTable = `
CREATE TABLE IF NOT EXISTS chains (
id INTEGER PRIMARY KEY AUTOINCREMENT,
name TEXT NOT NULL,
network_id TEXT NOT NULL UNIQUE,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
)
`
createCredentialsTable = `
CREATE TABLE IF NOT EXISTS credentials (
id INTEGER PRIMARY KEY AUTOINCREMENT,
handle TEXT NOT NULL,
controller TEXT NOT NULL,
attestation_type TEXT NOT NULL,
origin TEXT NOT NULL,
credential_id BLOB NOT NULL,
public_key BLOB NOT NULL,
transport TEXT NOT NULL,
sign_count INTEGER NOT NULL,
user_present BOOLEAN NOT NULL,
user_verified BOOLEAN NOT NULL,
backup_eligible BOOLEAN NOT NULL,
backup_state BOOLEAN NOT NULL,
clone_warning BOOLEAN NOT NULL,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
)
`
createProfilesTable = `
CREATE TABLE IF NOT EXISTS profiles (
id TEXT PRIMARY KEY,
subject TEXT NOT NULL,
controller TEXT NOT NULL,
origin_uri TEXT,
public_metadata TEXT,
private_metadata TEXT,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
)
`
createPropertiesTable = `
CREATE TABLE IF NOT EXISTS properties (
id INTEGER PRIMARY KEY AUTOINCREMENT,
profile_id TEXT NOT NULL,
key TEXT NOT NULL,
accumulator BLOB NOT NULL,
property_key BLOB NOT NULL,
FOREIGN KEY (profile_id) REFERENCES profiles(id)
)
`
createKeysharesTable = `
CREATE TABLE IF NOT EXISTS keyshares (
id INTEGER PRIMARY KEY AUTOINCREMENT,
metadata TEXT NOT NULL,
payloads TEXT NOT NULL,
protocol TEXT NOT NULL,
public_key BLOB NOT NULL,
role INTEGER NOT NULL,
version INTEGER NOT NULL,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
)
`
createPermissionsTable = `
CREATE TABLE IF NOT EXISTS permissions (
id INTEGER PRIMARY KEY AUTOINCREMENT,
service_id TEXT NOT NULL,
grants TEXT NOT NULL,
scopes TEXT NOT NULL,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (service_id) REFERENCES services(id)
)
`
)