feat: remove motr.mjs dependency

This commit is contained in:
Prad Nukala 2024-10-04 01:57:43 -04:00
parent 1267bc426a
commit 77d76938a3
6 changed files with 60 additions and 331 deletions

22
.github/ISSUE_TEMPLATE/to-do.md vendored Normal file
View File

@ -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.

View File

@ -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

View File

@ -13,15 +13,11 @@ import (
//go:embed app.wasm //go:embed app.wasm
var dwnWasmData []byte var dwnWasmData []byte
//go:embed motr.mjs
var motrMJSData []byte
//go:embed sw.js //go:embed sw.js
var swJSData []byte var swJSData []byte
var ( var (
dwnWasmFile = files.NewBytesFile(dwnWasmData) dwnWasmFile = files.NewBytesFile(dwnWasmData)
motrMJSFile = files.NewBytesFile(motrMJSData)
swJSFile = files.NewBytesFile(swJSData) swJSFile = files.NewBytesFile(swJSData)
) )
@ -43,7 +39,6 @@ func NewVaultDirectory(cnfg *Config) (files.Node, error) {
} }
fileMap := map[string]files.Node{ fileMap := map[string]files.Node{
"config.json": files.NewBytesFile(dwnJSON), "config.json": files.NewBytesFile(dwnJSON),
"motr.mjs": motrMJSFile,
"sw.js": swJSFile, "sw.js": swJSFile,
"app.wasm": dwnWasmFile, "app.wasm": dwnWasmFile,
"index.html": files.NewBytesFile(w.Bytes()), "index.html": files.NewBytesFile(w.Bytes()),

View File

@ -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;
}
}
}

View File

@ -1,39 +1,39 @@
package orm package orm
const SCHEMA_VERSION = 1 import (
"reflect"
"strings"
)
func AccountSchema() string { const SchemaVersion = 1
return "++, id, name, address, publicKey, chainCode, index, controller, createdAt"
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 { func GetSchema(structType interface{}) string {
return "++, id, name, symbol, decimals, chainCode, createdAt" t := reflect.TypeOf(structType)
} if t.Kind() == reflect.Ptr {
t = t.Elem()
}
func ChainSchema() string { if t.Kind() != reflect.Struct {
return "++, id, name, networkId, chainCode, createdAt" return ""
} }
func CredentialSchema() string { var fields []string
return "++, id, subject, controller, attestationType, origin, label, deviceId, credentialId, publicKey, transport, signCount, userPresent, userVerified, backupEligible, backupState, cloneWarning, createdAt, updatedAt" for i := 0; i < t.NumField(); i++ {
} field := t.Field(i)
fieldName := toCamelCase(field.Name)
fields = append(fields, fieldName)
}
func DIDSchema() string { // Add "++" at the beginning, separated by a comma
return "++, id, role, algorithm, encoding, curve, key_type, raw, jwk" return "++, " + strings.Join(fields, ", ")
}
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"
} }

View File

@ -34,14 +34,13 @@ func (p Params) Validate() error {
// DefaultSchema returns the default schema // DefaultSchema returns the default schema
func DefaultSchema() *Schema { func DefaultSchema() *Schema {
return &Schema{ return &Schema{
Version: orm.SCHEMA_VERSION, Version: orm.SchemaVersion,
Account: orm.AccountSchema(), Account: orm.GetSchema(&orm.Account{}),
Asset: orm.AssetSchema(), Asset: orm.GetSchema(&orm.Asset{}),
Chain: orm.ChainSchema(), Chain: orm.GetSchema(&orm.Chain{}),
Credential: orm.CredentialSchema(), Credential: orm.GetSchema(&orm.Credential{}),
Jwk: orm.JwkSchema(), Grant: orm.GetSchema(&orm.Grant{}),
Grant: orm.GrantSchema(), Keyshare: orm.GetSchema(&orm.Keyshare{}),
Keyshare: orm.KeyshareSchema(), Profile: orm.GetSchema(&orm.Profile{}),
Profile: orm.ProfileSchema(),
} }
} }