feature/migrate models (#16)

* feat: add new supported attestation formats to genesis

* feat: refactor keyType to keytype enum

* refactor: remove unused imports and code

* refactor: update main.go to use src package

* refactor: move web-related structs from  to

* refactor: move client middleware package to root

* refactor: remove unused IndexedDB dependency

* feat: update worker implementation to use

* feat: add Caddyfile and Caddy configuration for vault service

* refactor(config): move keyshare and address to Motr config

* fix: validate service origin in AllocateVault

* chore: remove IndexedDB configuration

* feat: add support for IPNS-based vault access
This commit is contained in:
Prad Nukala
2024-09-19 02:04:22 -04:00
committed by GitHub
parent 6d8bd8fc85
commit 96e6486c43
151 changed files with 10997 additions and 21705 deletions
+141
View File
@@ -0,0 +1,141 @@
{
"apps": {
"http": {
"servers": {
"srv0": {
"listen": [
":443"
],
"routes": [
{
"match": [
{
"host": [
"vault.sonr.id"
]
}
],
"handle": [
{
"handler": "subroute",
"routes": [
{
"handle": [
{
"handler": "headers",
"response": {
"replace": {
"Content-Type": [
{
"replace": "application/wasm",
"search_regexp": ".wasm"
}
]
},
"set": {
"Service-Worker-Allowed": [
"/"
]
}
}
},
{
"encodings": {
"gzip": {},
"zstd": {}
},
"handler": "encode",
"prefer": [
"zstd",
"gzip"
]
}
]
},
{
"handle": [
{
"handler": "subroute",
"routes": [
{
"handle": [
{
"handler": "rewrite",
"uri_substring": [
{
"find": "/{http.regexp.vaultPath.0}",
"replace": "/ipns/{http.regexp.vaultPath.1}{http.regexp.vaultPath.2}"
}
]
},
{
"handler": "reverse_proxy",
"upstreams": [
{
"dial": "localhost:8080"
}
]
}
]
}
]
}
],
"match": [
{
"path_regexp": {
"name": "vaultPath",
"pattern": "^/([a-z0-9]{42})(/.*|)$"
}
}
]
},
{
"handle": [
{
"handler": "file_server",
"hide": [
"./Caddyfile"
]
}
]
}
]
}
],
"terminal": true
}
]
}
}
},
"tls": {
"automation": {
"policies": [
{
"subjects": [
"vault.sonr.id"
],
"issuers": [
{
"challenges": {
"dns": {
"provider": {
"api_token": "{env.CLOUDFLARE_API_TOKEN}",
"name": "cloudflare"
},
"resolvers": [
"1.1.1.1"
]
}
},
"email": "team@sonr.id",
"module": "acme"
}
]
}
]
}
}
}
}
+1 -5
View File
@@ -6,9 +6,5 @@ type Config struct {
Sonr *Sonr `pkl:"sonr" json:"sonr,omitempty"`
Keyshare *string `pkl:"keyshare" json:"keyshare,omitempty"`
Address *string `pkl:"address" json:"address,omitempty"`
Vault *IndexedDB `pkl:"vault" json:"vault,omitempty"`
Motr *Motr `pkl:"motr" json:"motr,omitempty"`
}
+2 -2
View File
@@ -2,7 +2,7 @@
package dwn
type IPFS struct {
ApiUrl string `pkl:"apiUrl"`
ApiUrl string `pkl:"apiUrl" json:"apiUrl,omitempty"`
GatewayUrl string `pkl:"gatewayUrl"`
GatewayUrl string `pkl:"gatewayUrl" json:"gatewayUrl,omitempty"`
}
-8
View File
@@ -1,8 +0,0 @@
// Code generated from Pkl module `dwn`. DO NOT EDIT.
package dwn
type IndexedDB struct {
Name string `pkl:"name"`
Version int `pkl:"version"`
}
+10
View File
@@ -0,0 +1,10 @@
// Code generated from Pkl module `dwn`. DO NOT EDIT.
package dwn
type Motr struct {
Keyshare string `pkl:"keyshare" json:"keyshare,omitempty"`
Address string `pkl:"address" json:"address,omitempty"`
Origin string `pkl:"origin" json:"origin,omitempty"`
}
+6 -4
View File
@@ -2,11 +2,13 @@
package dwn
type Sonr struct {
ApiUrl string `pkl:"apiUrl"`
ApiUrl string `pkl:"apiUrl" json:"apiUrl,omitempty"`
GrpcUrl string `pkl:"grpcUrl"`
GrpcUrl string `pkl:"grpcUrl" json:"grpcUrl,omitempty"`
RpcUrl string `pkl:"rpcUrl"`
RpcUrl string `pkl:"rpcUrl" json:"rpcUrl,omitempty"`
WebSocketUrl string `pkl:"webSocketUrl"`
WebSocketUrl string `pkl:"webSocketUrl" json:"webSocketUrl,omitempty"`
ChainId string `pkl:"chainId" json:"chainId,omitempty"`
}
+1 -1
View File
@@ -8,5 +8,5 @@ func init() {
pkl.RegisterMapping("dwn#Config", Config{})
pkl.RegisterMapping("dwn#IPFS", IPFS{})
pkl.RegisterMapping("dwn#Sonr", Sonr{})
pkl.RegisterMapping("dwn#IndexedDB", IndexedDB{})
pkl.RegisterMapping("dwn#Motr", Motr{})
}
+25 -12
View File
@@ -20,30 +20,43 @@ class Config {
sonr: Sonr
@JsonField
keyshare: JSON?
@JsonField
address: String?
@JsonField
vault: IndexedDB
}
class IndexedDB {
name: String = "vault"
version: Int = 1
motr: Motr
}
class IPFS {
@JsonField
apiUrl: String
@JsonField
gatewayUrl: String
}
class Motr {
@JsonField
keyshare: JSON
@JsonField
address: String
@JsonField
origin: String
}
class Sonr {
@JsonField
apiUrl: String
@JsonField
grpcUrl: String
@JsonField
rpcUrl: String
@JsonField
webSocketUrl: String
@JsonField
chainId: String
}
+60 -4
View File
@@ -1,6 +1,6 @@
@go.Package { name = "github.com/onsonr/sonr/internal/vfs/models" }
@go.Package { name = "github.com/onsonr/sonr/internal/orm" }
module models
module orm
import "package://pkg.pkl-lang.org/pkl-go/pkl.golang@0.5.0#/go.pkl"
@@ -15,7 +15,6 @@ typealias ChainCode = UInt
typealias Scope = String
typealias Hex = String
typealias UTF8 = String
class PrimaryKey extends go.Field {
structTags {
@@ -30,6 +29,28 @@ class JsonField extends go.Field {
}
}
// Enums
typealias AssetType = "native"|"wrapped"|"staking"|"pool"|"ibc"|"cw20"
typealias DIDMethod = "ipfs"|"sonr"|"bitcoin"|"ethereum"|"ibc"|"webauthn"|"dwn"|"service"
typealias KeyAlgorithm = "es256"|"es384"|"es512"|"eddsa"|"es256k"|"ecdsa"
typealias KeyCurve = "p256"|"p384"|"p521"|"x25519"|"x448"|"ed25519"|"ed448"|"secp256k1"|"bls12381"|"keccak256"
typealias KeyEncoding = "raw"|"hex"|"multibase"
typealias KeyRole = "authentication"|"assertion"|"delegation"|"invocation"
typealias KeyType = "octet"|"elliptic"|"rsa"|"symmetric"|"hmac"|"mpc"|"zk"|"webauthn"|"bip32"
typealias KeyShareRole = "user"|"validator"
typealias PermissionGrant = "none"|"read"|"write"|"verify"|"broadcast"|"admin"
typealias PermissionScope = "profile"|"metadata"|"permissions"|"wallets"|"transactions"|"user"|"validator"
class Account {
@PrimaryKey
id: DID
@@ -109,6 +130,12 @@ class Credential {
@JsonField
origin: String
@JsonField
label: String?
@JsonField
deviceId: String?
@JsonField
credentialId: Base64
@@ -143,6 +170,26 @@ class Credential {
updatedAt: String?
}
class JWK {
@JsonField
kty: String
@JsonField
crv: String
@JsonField
x: String
@JsonField
y: String
@JsonField
n: String
@JsonField
e: String
}
class Grant {
@PrimaryKey
id: UInt
@@ -188,7 +235,13 @@ class Keyshare {
class PublicKey {
@PrimaryKey
id: DID
role: KeyRole
algorithm: KeyAlgorithm
encoding: KeyEncoding
curve: KeyCurve
key_type: KeyType
raw: Base58
jwk: JWK
}
class Profile {
@@ -218,3 +271,6 @@ class Profile {
}
db_name: String = "vault"
db_version: Int = 1
+2 -11
View File
@@ -1,6 +1,6 @@
@go.Package { name = "github.com/onsonr/sonr/internal/vfs/txns" }
@go.Package { name = "github.com/onsonr/sonr/internal/orm/transactions" }
module txns
module transactions
import "package://pkg.pkl-lang.org/pkl-go/pkl.golang@0.5.0#/go.pkl"
@@ -25,15 +25,6 @@ class Proposal {
description: String
}
class SWT {
origin: String
location: String
identifier: String
scopes: List<String>
properties: Map<String, String>
expiryBlock: Int
}
/// Gov module messages
class MsgGovSubmitProposal extends Msg {
typeUrl = "/cosmos.gov.v1beta1.MsgSubmitProposal"
+72
View File
@@ -0,0 +1,72 @@
@go.Package { name = "github.com/onsonr/sonr/internal/orm/browser" }
module browser
import "package://pkg.pkl-lang.org/pkl-go/pkl.golang@0.5.0#/go.pkl"
class JsonField extends go.Field {
structTags {
["json"] = "%{name},omitempty"
}
}
class PublicKeyCredentialRequestOptions {
challenge: String
timeout: Int
rpId: String
allowCredentials: List<PublicKeyCredentialDescriptor>
userVerification: String
extensions: List<PublicKeyCredentialParameters>
}
class PublicKeyCredentialDescriptor {
id: String
transports: List<String>
type: String
}
class PublicKeyCredentialParameters {
type: String
alg: Int?
}
class AuthenticatorSelectionCriteria {
authenticatorAttachment: String
requireResidentKey: Boolean
userVerification: String
}
class PublicKeyCredentialCreationOptions {
rp: RpEntity
user: UserEntity
challenge: String
pubKeyCredParams: List<PublicKeyCredentialParameters>
timeout: Int
excludeCredentials: List<PublicKeyCredentialDescriptor>
authenticatorSelection: AuthenticatorSelectionCriteria?
attestation: String
extensions: List<PublicKeyCredentialParameters>
}
class RpEntity {
id: String
name: String?
icon: String?
}
class UserEntity {
id: String
displayName: String?
name: String?
}
class SWT {
origin: String
location: String
identifier: String
scopes: List<String>
properties: Map<String, String>
expiryBlock: Int
}