diff --git a/.github/ISSUE_TEMPLATE/to-do.md b/.github/ISSUE_TEMPLATE/to-do.md new file mode 100644 index 000000000..9999c04f5 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/to-do.md @@ -0,0 +1,22 @@ +--- +name: Default Todo +about: Break down feature requirements into tasks. +title: "Name of the new task" +labels: + - "#TODO" + - "#OKR" +assignees: "prnk28" +projects: "onsonr/37" +--- + +## Description + +The expected deliverable of the task. + +## Associated Files + +These files will be modified by this task. + +## References + +Use these documents to help you complete the task. diff --git a/.github/ISSUE_TEMPLATE/todo.yml b/.github/ISSUE_TEMPLATE/todo.yml deleted file mode 100644 index 140e19d6c..000000000 --- a/.github/ISSUE_TEMPLATE/todo.yml +++ /dev/null @@ -1,34 +0,0 @@ -name: Default Todo -description: Break down feature requirements into tasks. -title: "Name of the new task" -labels: ["#TODO", "#OKR"] -assignees: ["prnk28"] -projects: ["onsonr/37"] -body: - - type: textarea - attributes: - label: Description - description: The expected deliverable of the task. - render: markdown - validations: - required: false - - type: textarea - attributes: - label: Associated Files - description: | - These files will be modified by this task. - value: | - - [proto/did/v1/state.proto](https://github.com/onsonr/sonr/blob/develop/proto/did/v1/state.proto) - - [proto/did/v1/tx.proto](https://github.com/onsonr/sonr/blob/develop/proto/did/v1/tx.proto) - validations: - required: false - - type: textarea - attributes: - label: References - description: | - Use these documents to help you complete the task. - value: | - - [Cosmos ORM Docs](https://github.com/cosmos/orm) - - [DID Document Spec](https://docs.cosmos.network) - validations: - required: false diff --git a/pkg/dwn/embed.go b/pkg/dwn/embed.go index 4bd4bf500..134743eec 100644 --- a/pkg/dwn/embed.go +++ b/pkg/dwn/embed.go @@ -13,15 +13,11 @@ import ( //go:embed app.wasm var dwnWasmData []byte -//go:embed motr.mjs -var motrMJSData []byte - //go:embed sw.js var swJSData []byte var ( dwnWasmFile = files.NewBytesFile(dwnWasmData) - motrMJSFile = files.NewBytesFile(motrMJSData) swJSFile = files.NewBytesFile(swJSData) ) @@ -43,7 +39,6 @@ func NewVaultDirectory(cnfg *Config) (files.Node, error) { } fileMap := map[string]files.Node{ "config.json": files.NewBytesFile(dwnJSON), - "motr.mjs": motrMJSFile, "sw.js": swJSFile, "app.wasm": dwnWasmFile, "index.html": files.NewBytesFile(w.Bytes()), diff --git a/pkg/dwn/motr.mjs b/pkg/dwn/motr.mjs deleted file mode 100644 index cde5b7a68..000000000 --- a/pkg/dwn/motr.mjs +++ /dev/null @@ -1,253 +0,0 @@ -// motr.mjs - -import Dexie from "dexie"; - -export class Motr { - constructor(config) { - this.config = config; - this.vault = null; - this.initializeVault(); - } - - initializeVault() { - const { schema } = this.config; - this.vault = new Dexie("Vault"); - this.vault.version(schema.version).stores(schema); - } - - // Account methods - async insertAccount(accountData) { - return this.vault.account.add(accountData); - } - - async getAccount(id) { - return this.vault.account.get(id); - } - - async updateAccount(id, accountData) { - return this.vault.account.update(id, accountData); - } - - async deleteAccount(id) { - return this.vault.account.delete(id); - } - - // Asset methods - async insertAsset(assetData) { - return this.vault.asset.add(assetData); - } - - async getAsset(id) { - return this.vault.asset.get(id); - } - - async updateAsset(id, assetData) { - return this.vault.asset.update(id, assetData); - } - - async deleteAsset(id) { - return this.vault.asset.delete(id); - } - - // Chain methods - async insertChain(chainData) { - return this.vault.chain.add(chainData); - } - - async getChain(id) { - return this.vault.chain.get(id); - } - - async updateChain(id, chainData) { - return this.vault.chain.update(id, chainData); - } - - async deleteChain(id) { - return this.vault.chain.delete(id); - } - - // Credential methods - async insertCredential(credentialData) { - const publicKey = await this.createPublicKeyCredential(credentialData); - credentialData.credentialId = publicKey.id; - credentialData.publicKey = publicKey.publicKey; - return this.vault.credential.add(credentialData); - } - - async getCredential(id) { - return this.vault.credential.get(id); - } - - async updateCredential(id, credentialData) { - return this.vault.credential.update(id, credentialData); - } - - async deleteCredential(id) { - return this.vault.credential.delete(id); - } - - // JWK methods - async insertJwk(jwkData) { - return this.vault.jwk.add(jwkData); - } - - async getJwk(id) { - return this.vault.jwk.get(id); - } - - async updateJwk(id, jwkData) { - return this.vault.jwk.update(id, jwkData); - } - - async deleteJwk(id) { - return this.vault.jwk.delete(id); - } - - // Grant methods - async insertGrant(grantData) { - return this.vault.grant.add(grantData); - } - - async getGrant(id) { - return this.vault.grant.get(id); - } - - async updateGrant(id, grantData) { - return this.vault.grant.update(id, grantData); - } - - async deleteGrant(id) { - return this.vault.grant.delete(id); - } - - // Keyshare methods - async insertKeyshare(keyshareData) { - return this.vault.keyshare.add(keyshareData); - } - - async getKeyshare(id) { - return this.vault.keyshare.get(id); - } - - async updateKeyshare(id, keyshareData) { - return this.vault.keyshare.update(id, keyshareData); - } - - async deleteKeyshare(id) { - return this.vault.keyshare.delete(id); - } - - // PublicKey methods - async insertPublicKey(publicKeyData) { - return this.vault.publicKey.add(publicKeyData); - } - - async getPublicKey(id) { - return this.vault.publicKey.get(id); - } - - async updatePublicKey(id, publicKeyData) { - return this.vault.publicKey.update(id, publicKeyData); - } - - async deletePublicKey(id) { - return this.vault.publicKey.delete(id); - } - - // Profile methods - async insertProfile(profileData) { - return this.vault.profile.add(profileData); - } - - async getProfile(id) { - return this.vault.profile.get(id); - } - - async updateProfile(id, profileData) { - return this.vault.profile.update(id, profileData); - } - - async deleteProfile(id) { - return this.vault.profile.delete(id); - } - - // WebAuthn methods - async createPublicKeyCredential(options) { - const publicKeyCredentialCreationOptions = { - challenge: new Uint8Array(32), - rp: { - name: this.config.motr.origin, - id: new URL(this.config.motr.origin).hostname, - }, - user: { - id: new TextEncoder().encode(options.subject), - name: options.subject, - displayName: options.label, - }, - pubKeyCredParams: [ - { alg: -7, type: "public-key" }, - { alg: -257, type: "public-key" }, - ], - authenticatorSelection: { - authenticatorAttachment: "platform", - userVerification: "required", - }, - timeout: 60000, - attestation: "direct", - }; - - try { - const credential = await navigator.credentials.create({ - publicKey: publicKeyCredentialCreationOptions, - }); - - const publicKeyJwk = await crypto.subtle.exportKey( - "jwk", - credential.response.getPublicKey(), - ); - - return { - id: credential.id, - publicKey: publicKeyJwk, - type: credential.type, - transports: credential.response.getTransports(), - }; - } catch (error) { - console.error("Error creating credential:", error); - throw error; - } - } - - async getPublicKeyCredential(options) { - const publicKeyCredentialRequestOptions = { - challenge: new Uint8Array(32), - rpId: new URL(this.config.motr.origin).hostname, - allowCredentials: options.allowCredentials || [], - userVerification: "required", - timeout: 60000, - }; - - try { - const assertion = await navigator.credentials.get({ - publicKey: publicKeyCredentialRequestOptions, - }); - - return { - id: assertion.id, - type: assertion.type, - rawId: new Uint8Array(assertion.rawId), - response: { - authenticatorData: new Uint8Array( - assertion.response.authenticatorData, - ), - clientDataJSON: new Uint8Array(assertion.response.clientDataJSON), - signature: new Uint8Array(assertion.response.signature), - userHandle: new Uint8Array(assertion.response.userHandle), - }, - }; - } catch (error) { - console.error("Error getting credential:", error); - throw error; - } - } -} diff --git a/pkg/orm/schema.go b/pkg/orm/schema.go index a6da77bbd..c1beec87a 100644 --- a/pkg/orm/schema.go +++ b/pkg/orm/schema.go @@ -1,39 +1,39 @@ package orm -const SCHEMA_VERSION = 1 +import ( + "reflect" + "strings" +) -func AccountSchema() string { - return "++, id, name, address, publicKey, chainCode, index, controller, createdAt" +const SchemaVersion = 1 + +func toCamelCase(s string) string { + if s == "" { + return s + } + if len(s) == 1 { + return strings.ToLower(s) + } + return strings.ToLower(s[:1]) + s[1:] } -func AssetSchema() string { - return "++, id, name, symbol, decimals, chainCode, createdAt" -} +func GetSchema(structType interface{}) string { + t := reflect.TypeOf(structType) + if t.Kind() == reflect.Ptr { + t = t.Elem() + } -func ChainSchema() string { - return "++, id, name, networkId, chainCode, createdAt" -} + if t.Kind() != reflect.Struct { + return "" + } -func CredentialSchema() string { - return "++, id, subject, controller, attestationType, origin, label, deviceId, credentialId, publicKey, transport, signCount, userPresent, userVerified, backupEligible, backupState, cloneWarning, createdAt, updatedAt" -} + var fields []string + for i := 0; i < t.NumField(); i++ { + field := t.Field(i) + fieldName := toCamelCase(field.Name) + fields = append(fields, fieldName) + } -func DIDSchema() string { - return "++, id, role, algorithm, encoding, curve, key_type, raw, jwk" -} - -func JwkSchema() string { - return "++, kty, crv, x, y, n, e" -} - -func GrantSchema() string { - return "++, subject, controller, origin, token, scopes, createdAt, updatedAt" -} - -func KeyshareSchema() string { - return "++, id, data, role, createdAt, lastRefreshed" -} - -func ProfileSchema() string { - return "++, id, subject, controller, originUri, publicMetadata, privateMetadata, createdAt, updatedAt" + // Add "++" at the beginning, separated by a comma + return "++, " + strings.Join(fields, ", ") } diff --git a/x/vault/types/params.go b/x/vault/types/params.go index 1864cf599..0c028e4d9 100644 --- a/x/vault/types/params.go +++ b/x/vault/types/params.go @@ -34,14 +34,13 @@ func (p Params) Validate() error { // DefaultSchema returns the default schema func DefaultSchema() *Schema { return &Schema{ - Version: orm.SCHEMA_VERSION, - Account: orm.AccountSchema(), - Asset: orm.AssetSchema(), - Chain: orm.ChainSchema(), - Credential: orm.CredentialSchema(), - Jwk: orm.JwkSchema(), - Grant: orm.GrantSchema(), - Keyshare: orm.KeyshareSchema(), - Profile: orm.ProfileSchema(), + Version: orm.SchemaVersion, + Account: orm.GetSchema(&orm.Account{}), + Asset: orm.GetSchema(&orm.Asset{}), + Chain: orm.GetSchema(&orm.Chain{}), + Credential: orm.GetSchema(&orm.Credential{}), + Grant: orm.GetSchema(&orm.Grant{}), + Keyshare: orm.GetSchema(&orm.Keyshare{}), + Profile: orm.GetSchema(&orm.Profile{}), } }