Browse Source

test: add function for test User #0 to register a new user

pull/4/head
Trent Larson 2 years ago
parent
commit
4e1263d041
  1. 34
      README.md
  2. 60
      src/test/index.ts
  3. 4
      src/views/AccountViewView.vue

34
README.md

@ -20,6 +20,40 @@ npm run build
npm run lint npm run lint
``` ```
### Clear data & restart
Clear cache for localhost, then go to http://localhost:8080/start (because it'll regenerate if you start on the `/account` page).
### Test key contents
See [this page](openssl_signing_console.rst)
### Register new user on test server
New users require registration. This can be done with a claim payload like this by an existing user:
```
const vcClaim = {
"@context": "https://schema.org",
"@type": "RegisterAction",
agent: { did: identity0.did },
object: SERVICE_ID,
participant: { did: newIdentity.did },
};
```
On the test server, the user starting 0x000 has rights to register others, and the keys for that test User #0 are found in the codebase. You can invoke registration by User #0 on the `/account` page:
* Edit the `src/views/AccountViewView.vue` file and uncomment the lines referring to "test".
* Use the [Vue Devtools browser extension](https://devtools.vuejs.org/) and type this into the conosle: `$vm.ctx.testRegisterUser()`
### Create keys with alternate tools
See [this page](openssl_signing_console.rst)
### Customize configuration ### Customize configuration
See [Configuration Reference](https://cli.vuejs.org/config/). See [Configuration Reference](https://cli.vuejs.org/config/).

60
src/test/index.ts

@ -0,0 +1,60 @@
import axios from "axios";
import * as didJwt from "did-jwt";
import { AppString } from "@/constants/app";
import { db } from "../db";
import { SERVICE_ID } from "../libs/veramo/setup";
import { deriveAddress, newIdentifier } from "../libs/crypto";
export async function testServerRegisterUser() {
const testUser0Mnem =
"seminar accuse mystery assist delay law thing deal image undo guard initial shallow wrestle list fragile borrow velvet tomorrow awake explain test offer control";
const [addr, privateHex, publicHex, deriPath] = deriveAddress(testUser0Mnem);
const identity0 = newIdentifier(addr, publicHex, privateHex, deriPath);
await db.open();
const accounts = await db.accounts.toArray();
const thisIdentity = JSON.parse(accounts[0].identity);
// Make a claim
const vcClaim = {
"@context": "https://schema.org",
"@type": "RegisterAction",
agent: { did: identity0.did },
object: SERVICE_ID,
participant: { did: thisIdentity.did },
};
// Make a payload for the claim
const vcPayload = {
sub: "RegisterAction",
vc: {
"@context": ["https://www.w3.org/2018/credentials/v1"],
type: ["VerifiableCredential"],
credentialSubject: vcClaim,
},
};
// create a signature using private key of identity
// eslint-disable-next-line
const privateKeyHex: string = identity0.keys[0].privateKeyHex!;
const signer = await didJwt.SimpleSigner(privateKeyHex);
const alg = undefined;
// create a JWT for the request
const vcJwt: string = await didJwt.createJWT(vcPayload, {
alg: alg,
issuer: identity0.did,
signer: signer,
});
// Make the xhr request payload
const payload = JSON.stringify({ jwtEncoded: vcJwt });
const endorserApiServer = AppString.DEFAULT_ENDORSER_API_SERVER;
const url = endorserApiServer + "/api/claim";
const headers = {
"Content-Type": "application/json",
};
const resp = await axios.post(url, payload, { headers });
console.log("Result:", resp);
}

4
src/views/AccountViewView.vue

@ -178,6 +178,7 @@ import { createIdentifier, deriveAddress, newIdentifier } from "../libs/crypto";
import { db } from "../db"; import { db } from "../db";
import { useAppStore } from "@/store/app"; import { useAppStore } from "@/store/app";
import { ref } from "vue"; import { ref } from "vue";
//import { testServerRegisterUser } from "../test";
@Options({ @Options({
components: {}, components: {},
@ -191,6 +192,9 @@ export default class AccountViewView extends Vue {
source = ref("Hello"); source = ref("Hello");
copy = useClipboard().copy; copy = useClipboard().copy;
// This registers current user in vue plugin with: $vm.ctx.testRegisterUser()
//testRegisterUser = testServerRegisterUser;
// 'created' hook runs when the Vue instance is first created // 'created' hook runs when the Vue instance is first created
async created() { async created() {
const appCondition = useAppStore().condition; const appCondition = useAppStore().condition;

Loading…
Cancel
Save