mirror of
https://github.com/onsonr/sonr.git
synced 2025-03-10 13:07:09 +00:00
feat: remove motr.mjs dependency
This commit is contained in:
parent
1267bc426a
commit
77d76938a3
22
.github/ISSUE_TEMPLATE/to-do.md
vendored
Normal file
22
.github/ISSUE_TEMPLATE/to-do.md
vendored
Normal 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.
|
34
.github/ISSUE_TEMPLATE/todo.yml
vendored
34
.github/ISSUE_TEMPLATE/todo.yml
vendored
@ -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
|
@ -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()),
|
||||
|
253
pkg/dwn/motr.mjs
253
pkg/dwn/motr.mjs
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
@ -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, ", ")
|
||||
}
|
||||
|
@ -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{}),
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user