package dwn var motrHandle = templ.NewOnceHandle() templ importScripts() { } templ indexFile(cfg string) { @importScripts() Sonr DWN
Loading...
@motrHandle.Once() { @initializeMotr(cfg) } } script initializeMotr(config string) { const motr = new Motr(JSON.parse(config)); async function demo() { try { // Insert a new account const accountId = await motr.insertAccount({ name: 'John Doe', address: '0x1234567890123456789012345678901234567890', publicKey: 'sample_public_key', chainCode: 'SONR', index: 0, controller: 'sample_controller', createdAt: new Date() }); console.log('Inserted account with ID:', accountId); // Retrieve the account const account = await motr.getAccount(accountId); console.log('Retrieved account:', account); // Insert a new credential const credentialId = await motr.insertCredential({ subject: 'john@example.com', label: 'John\'s Device', controller: 'sample_controller', attestationType: 'platform', origin: 'https://app.sonr.io' }); console.log('Inserted credential with ID:', credentialId); // Retrieve the credential const credential = await motr.getCredential(credentialId); console.log('Retrieved credential:', credential); document.getElementById('output').innerHTML = `

Demo Results:

Inserted account ID: ${accountId}

Retrieved account name: ${account.name}

Inserted credential ID: ${credentialId}

Retrieved credential subject: ${credential.subject}

`; } catch (error) { console.error('Error in demo:', error); document.getElementById('output').innerHTML = `

Error: ${error.message}

`; } } // Run the demo when the page loads window.onload = demo; }