From 4e1263d041f50f624dbabf849961cc12af0b0f2f Mon Sep 17 00:00:00 2001 From: Trent Larson Date: Sat, 7 Jan 2023 23:15:39 -0700 Subject: [PATCH 1/3] test: add function for test User #0 to register a new user --- README.md | 34 ++++++++++++++++++++ src/test/index.ts | 60 +++++++++++++++++++++++++++++++++++ src/views/AccountViewView.vue | 4 +++ 3 files changed, 98 insertions(+) create mode 100644 src/test/index.ts diff --git a/README.md b/README.md index 1fefb06..53666ba 100644 --- a/README.md +++ b/README.md @@ -20,6 +20,40 @@ npm run build 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 See [Configuration Reference](https://cli.vuejs.org/config/). diff --git a/src/test/index.ts b/src/test/index.ts new file mode 100644 index 0000000..4f10fb7 --- /dev/null +++ b/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); +} diff --git a/src/views/AccountViewView.vue b/src/views/AccountViewView.vue index ea60473..e22bb03 100644 --- a/src/views/AccountViewView.vue +++ b/src/views/AccountViewView.vue @@ -178,6 +178,7 @@ import { createIdentifier, deriveAddress, newIdentifier } from "../libs/crypto"; import { db } from "../db"; import { useAppStore } from "@/store/app"; import { ref } from "vue"; +//import { testServerRegisterUser } from "../test"; @Options({ components: {}, @@ -191,6 +192,9 @@ export default class AccountViewView extends Vue { source = ref("Hello"); 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 async created() { const appCondition = useAppStore().condition; From d3e590822e3786ffacf1e44cd270257fe0c01b5a Mon Sep 17 00:00:00 2001 From: Trent Larson Date: Sat, 7 Jan 2023 23:34:42 -0700 Subject: [PATCH 2/3] docs: fix spelling error --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 53666ba..5660880 100644 --- a/README.md +++ b/README.md @@ -46,7 +46,7 @@ On the test server, the user starting 0x000 has rights to register others, and t * 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()` +* Use the [Vue Devtools browser extension](https://devtools.vuejs.org/) and type this into the console: `$vm.ctx.testRegisterUser()` From 693df1bda1e21c9736d284e8bf1704dd6a6604ee Mon Sep 17 00:00:00 2001 From: Trent Larson Date: Sat, 7 Jan 2023 23:37:38 -0700 Subject: [PATCH 3/3] feat: switch to the SimpleSigner code for working signatures --- src/libs/crypto/index.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libs/crypto/index.ts b/src/libs/crypto/index.ts index 8d8df5a..a71cec1 100644 --- a/src/libs/crypto/index.ts +++ b/src/libs/crypto/index.ts @@ -122,7 +122,7 @@ export const accessToken = async (identifier: IIdentifier) => { : privateKeyHex; const privateKeyBytes = u8a.fromString(input.toLowerCase(), "base16"); - const signer = didJwt.ES256KSigner(privateKeyBytes, true); + const signer = didJwt.SimpleSigner(privateKeyHex); const nowEpoch = Math.floor(Date.now() / 1000); const endEpoch = nowEpoch + 60; // add one minute @@ -143,7 +143,7 @@ export const sign = async (privateKeyHex: string) => { : privateKeyHex; const privateKeyBytes = u8a.fromString(input.toLowerCase(), "base16"); - const signer = didJwt.ES256KSigner(privateKeyBytes, true); + const signer = didJwt.SimpleSigner(privateKeyHex); return signer; };