Compare commits
1 Commits
fb44c8aa48
...
experiment
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9e4046a69d |
52
README.md
52
README.md
@@ -20,62 +20,10 @@ 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: { identifier: identity0.did },
|
|
||||||
object: SERVICE_ID,
|
|
||||||
participant: { identifier: newIdentity.did },
|
|
||||||
};
|
|
||||||
```
|
|
||||||
|
|
||||||
On the test server, User #0 has rights to register others, so you can start playing one of two ways:
|
|
||||||
|
|
||||||
- Import the keys for that test User `did:ethr:0x000Ee5654b9742f6Fe18ea970e32b97ee2247B51` by importing this seed phrase: `seminar accuse mystery assist delay law thing deal image undo guard initial shallow wrestle list fragile borrow velvet tomorrow awake explain test offer control`
|
|
||||||
|
|
||||||
- Register someone else under 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 console: `$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/).
|
||||||
|
|
||||||
|
|
||||||
## Dependencies
|
|
||||||
|
|
||||||
See https://tea.xyz
|
|
||||||
|
|
||||||
| Project | Version |
|
|
||||||
| ---------- | --------- |
|
|
||||||
| nodejs.org | ^16.0.0 |
|
|
||||||
| npmjs.com | ^8.0.0 |
|
|
||||||
|
|
||||||
## Other
|
|
||||||
|
|
||||||
```
|
```
|
||||||
// reference material from https://github.com/trentlarson/endorser-mobile/blob/8dc8e0353e0cc80ffa7ed89ded15c8b0da92726b/src/utility/idUtility.ts#L83
|
|
||||||
|
|
||||||
// Import an existing ID
|
// Import an existing ID
|
||||||
export const importAndStoreIdentifier = async (mnemonic: string, mnemonicPassword: string, toLowercase: boolean, previousIdentifiers: Array<IIdentifier>) => {
|
export const importAndStoreIdentifier = async (mnemonic: string, mnemonicPassword: string, toLowercase: boolean, previousIdentifiers: Array<IIdentifier>) => {
|
||||||
|
|
||||||
|
|||||||
@@ -1,45 +0,0 @@
|
|||||||
You can create a JWT using a library or by encoding the header and payload base64Url and signing it with a secret using a ES256K algorithm. Here is an example of how you can create a JWT using the jq and openssl command line utilities:
|
|
||||||
|
|
||||||
Here is an example of how you can use openssl to sign a JWT with the ES256K algorithm:
|
|
||||||
|
|
||||||
Generate an ECDSA key pair using the secp256k1 curve:
|
|
||||||
|
|
||||||
openssl ecparam -name secp256k1 -genkey -noout -out private.pem
|
|
||||||
openssl ec -in private.pem -pubout -out public.pem
|
|
||||||
|
|
||||||
First, create a header object as a JSON object containing the alg (algorithm) and typ (type) fields. For example:
|
|
||||||
|
|
||||||
header='{"alg":"ES256K", "issuer": "", "typ":"JWT"}'
|
|
||||||
|
|
||||||
Next, create a payload object as a JSON object containing the claims you want to include in the JWT. For example schema.org :
|
|
||||||
|
|
||||||
payload='{"@context": "http://schema.org", "@type": "PlanAction", "identifier": "did:ethr:0xb86913f83A867b5Ef04902419614A6FF67466c12", "name": "Test", "description": "Me"}'
|
|
||||||
|
|
||||||
Encode the header and payload objects as base64Url strings. You can use the jq command line utility to do this:
|
|
||||||
|
|
||||||
header_b64=$(echo -n "$header" | jq -c -M . | tr -d '\n')
|
|
||||||
payload_b64=$(echo -n "$payload" | jq -c -M . | tr -d '\n')
|
|
||||||
|
|
||||||
Concatenate the encoded header, payload, and a secret to create the signing input:
|
|
||||||
|
|
||||||
signing_input="$header_b64.$payload_b64"
|
|
||||||
|
|
||||||
Create the signature by signing the signing input with a ES256K algorithm and your secret. You can use the openssl command line utility to do this:
|
|
||||||
|
|
||||||
signature=$(echo -n "$signing_input" | openssl dgst -sha256 -sign private.pem)
|
|
||||||
|
|
||||||
Finally, encode the signature as a base64Url string and concatenate it with the signing input to create the JWT:
|
|
||||||
|
|
||||||
signature_b64=$(echo -n "$signature" | base64 | tr -d '=' | tr '+' '-' | tr '/' '_')
|
|
||||||
jwt="$signing_input.$signature_b64"
|
|
||||||
|
|
||||||
This JWT can then be passed in the Authorization header of a HTTP request as a bearer token, for example:
|
|
||||||
|
|
||||||
Authorization: Bearer $jwt
|
|
||||||
|
|
||||||
To verify the JWT, you can use the openssl utility with the public key:
|
|
||||||
|
|
||||||
openssl dgst -sha256 -verify public.pem -signature <(echo -n "$signature") "$signing_input"
|
|
||||||
|
|
||||||
This will verify the signature and output Verified OK if the signature is valid. If the signature is not valid, it will output an error.
|
|
||||||
|
|
||||||
66
package-lock.json
generated
66
package-lock.json
generated
@@ -22,11 +22,9 @@
|
|||||||
"@veramo/key-manager": "^4.1.1",
|
"@veramo/key-manager": "^4.1.1",
|
||||||
"@vueuse/core": "^9.6.0",
|
"@vueuse/core": "^9.6.0",
|
||||||
"@zxing/text-encoding": "^0.9.0",
|
"@zxing/text-encoding": "^0.9.0",
|
||||||
"axios": "^1.2.2",
|
|
||||||
"class-transformer": "^0.5.1",
|
"class-transformer": "^0.5.1",
|
||||||
"core-js": "^3.26.1",
|
"core-js": "^3.26.1",
|
||||||
"dexie": "^3.2.2",
|
"dexie": "^3.2.2",
|
||||||
"did-jwt": "^6.9.0",
|
|
||||||
"ethereum-cryptography": "^1.1.2",
|
"ethereum-cryptography": "^1.1.2",
|
||||||
"ethereumjs-util": "^7.1.5",
|
"ethereumjs-util": "^7.1.5",
|
||||||
"ethr-did-resolver": "^8.0.0",
|
"ethr-did-resolver": "^8.0.0",
|
||||||
@@ -34,7 +32,6 @@
|
|||||||
"localstorage-slim": "^2.3.0",
|
"localstorage-slim": "^2.3.0",
|
||||||
"luxon": "^3.1.1",
|
"luxon": "^3.1.1",
|
||||||
"merkletreejs": "^0.3.9",
|
"merkletreejs": "^0.3.9",
|
||||||
"moment": "^2.29.4",
|
|
||||||
"papaparse": "^5.3.2",
|
"papaparse": "^5.3.2",
|
||||||
"pina": "^0.20.2204228",
|
"pina": "^0.20.2204228",
|
||||||
"pinia-plugin-persistedstate": "^3.0.1",
|
"pinia-plugin-persistedstate": "^3.0.1",
|
||||||
@@ -43,7 +40,6 @@
|
|||||||
"reflect-metadata": "^0.1.13",
|
"reflect-metadata": "^0.1.13",
|
||||||
"register-service-worker": "^1.7.2",
|
"register-service-worker": "^1.7.2",
|
||||||
"vue": "^3.2.45",
|
"vue": "^3.2.45",
|
||||||
"vue-axios": "^3.5.2",
|
|
||||||
"vue-class-component": "^8.0.0-0",
|
"vue-class-component": "^8.0.0-0",
|
||||||
"vue-property-decorator": "^9.1.2",
|
"vue-property-decorator": "^9.1.2",
|
||||||
"vue-router": "^4.1.6",
|
"vue-router": "^4.1.6",
|
||||||
@@ -9689,7 +9685,9 @@
|
|||||||
"node_modules/asynckit": {
|
"node_modules/asynckit": {
|
||||||
"version": "0.4.0",
|
"version": "0.4.0",
|
||||||
"resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz",
|
"resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz",
|
||||||
"integrity": "sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q=="
|
"integrity": "sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q==",
|
||||||
|
"optional": true,
|
||||||
|
"peer": true
|
||||||
},
|
},
|
||||||
"node_modules/at-least-node": {
|
"node_modules/at-least-node": {
|
||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
@@ -9746,29 +9744,6 @@
|
|||||||
"postcss": "^8.1.0"
|
"postcss": "^8.1.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/axios": {
|
|
||||||
"version": "1.2.2",
|
|
||||||
"resolved": "https://registry.npmjs.org/axios/-/axios-1.2.2.tgz",
|
|
||||||
"integrity": "sha512-bz/J4gS2S3I7mpN/YZfGFTqhXTYzRho8Ay38w2otuuDR322KzFIWm/4W2K6gIwvWaws5n+mnb7D1lN9uD+QH6Q==",
|
|
||||||
"dependencies": {
|
|
||||||
"follow-redirects": "^1.15.0",
|
|
||||||
"form-data": "^4.0.0",
|
|
||||||
"proxy-from-env": "^1.1.0"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"node_modules/axios/node_modules/form-data": {
|
|
||||||
"version": "4.0.0",
|
|
||||||
"resolved": "https://registry.npmjs.org/form-data/-/form-data-4.0.0.tgz",
|
|
||||||
"integrity": "sha512-ETEklSGi5t0QMZuiXoA/Q6vcnxcLQP5vdugSpuAyi6SVGi2clPPp+xgEhuMaHC+zGgn31Kd235W35f7Hykkaww==",
|
|
||||||
"dependencies": {
|
|
||||||
"asynckit": "^0.4.0",
|
|
||||||
"combined-stream": "^1.0.8",
|
|
||||||
"mime-types": "^2.1.12"
|
|
||||||
},
|
|
||||||
"engines": {
|
|
||||||
"node": ">= 6"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"node_modules/b64-lite": {
|
"node_modules/b64-lite": {
|
||||||
"version": "1.4.0",
|
"version": "1.4.0",
|
||||||
"resolved": "https://registry.npmjs.org/b64-lite/-/b64-lite-1.4.0.tgz",
|
"resolved": "https://registry.npmjs.org/b64-lite/-/b64-lite-1.4.0.tgz",
|
||||||
@@ -11050,6 +11025,8 @@
|
|||||||
"version": "1.0.8",
|
"version": "1.0.8",
|
||||||
"resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz",
|
"resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz",
|
||||||
"integrity": "sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==",
|
"integrity": "sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==",
|
||||||
|
"optional": true,
|
||||||
|
"peer": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"delayed-stream": "~1.0.0"
|
"delayed-stream": "~1.0.0"
|
||||||
},
|
},
|
||||||
@@ -12126,6 +12103,8 @@
|
|||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
"resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz",
|
"resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz",
|
||||||
"integrity": "sha512-ZySD7Nf91aLB0RxL4KGrKHBXl7Eds1DAmEdcoVawXnLD7SDhpNgtuII2aAkg7a7QS41jxPSZ17p4VdGnMHk3MQ==",
|
"integrity": "sha512-ZySD7Nf91aLB0RxL4KGrKHBXl7Eds1DAmEdcoVawXnLD7SDhpNgtuII2aAkg7a7QS41jxPSZ17p4VdGnMHk3MQ==",
|
||||||
|
"optional": true,
|
||||||
|
"peer": true,
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=0.4.0"
|
"node": ">=0.4.0"
|
||||||
}
|
}
|
||||||
@@ -12188,9 +12167,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/did-jwt": {
|
"node_modules/did-jwt": {
|
||||||
"version": "6.9.0",
|
"version": "6.10.1",
|
||||||
"resolved": "https://registry.npmjs.org/did-jwt/-/did-jwt-6.9.0.tgz",
|
"resolved": "https://registry.npmjs.org/did-jwt/-/did-jwt-6.10.1.tgz",
|
||||||
"integrity": "sha512-kZ8pakovM2VkG0pia6x0SA9/1rl9dOUti4i2FL3xg7arJDWW7dACJxX+6gQK7iR/DvXrfFo8F784ejHVbw9ryA==",
|
"integrity": "sha512-YJOvkuPKKX364ooAFNxZPcz/KBLRwLhRABQVQlVEqOjygsCkplNFB3UL97UqZ7Y3cAG6Jh5jKoAC4xFSm+h0qw==",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@stablelib/ed25519": "^1.0.2",
|
"@stablelib/ed25519": "^1.0.2",
|
||||||
"@stablelib/random": "^1.0.1",
|
"@stablelib/random": "^1.0.1",
|
||||||
@@ -14603,6 +14582,7 @@
|
|||||||
"version": "1.15.2",
|
"version": "1.15.2",
|
||||||
"resolved": "https://registry.npmmirror.com/follow-redirects/-/follow-redirects-1.15.2.tgz",
|
"resolved": "https://registry.npmmirror.com/follow-redirects/-/follow-redirects-1.15.2.tgz",
|
||||||
"integrity": "sha512-VQLG33o04KaQ8uYi2tVNbdrWp1QWxNNea+nmIB4EVM28v0hmP17z7aG1+wAkNzVq4KeXTq3221ye5qTJP91JwA==",
|
"integrity": "sha512-VQLG33o04KaQ8uYi2tVNbdrWp1QWxNNea+nmIB4EVM28v0hmP17z7aG1+wAkNzVq4KeXTq3221ye5qTJP91JwA==",
|
||||||
|
"dev": true,
|
||||||
"funding": [
|
"funding": [
|
||||||
{
|
{
|
||||||
"type": "individual",
|
"type": "individual",
|
||||||
@@ -19069,6 +19049,7 @@
|
|||||||
"version": "1.52.0",
|
"version": "1.52.0",
|
||||||
"resolved": "https://registry.npmmirror.com/mime-db/-/mime-db-1.52.0.tgz",
|
"resolved": "https://registry.npmmirror.com/mime-db/-/mime-db-1.52.0.tgz",
|
||||||
"integrity": "sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg==",
|
"integrity": "sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg==",
|
||||||
|
"devOptional": true,
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">= 0.6"
|
"node": ">= 0.6"
|
||||||
}
|
}
|
||||||
@@ -19077,6 +19058,7 @@
|
|||||||
"version": "2.1.35",
|
"version": "2.1.35",
|
||||||
"resolved": "https://registry.npmmirror.com/mime-types/-/mime-types-2.1.35.tgz",
|
"resolved": "https://registry.npmmirror.com/mime-types/-/mime-types-2.1.35.tgz",
|
||||||
"integrity": "sha512-ZDY+bPm5zTTF+YpCrAU9nK0UgICYPT0QtT1NZWFv4s++TNkcgVaT0g6+4R2uI4MjQjzysHB1zxuWL50hzaeXiw==",
|
"integrity": "sha512-ZDY+bPm5zTTF+YpCrAU9nK0UgICYPT0QtT1NZWFv4s++TNkcgVaT0g6+4R2uI4MjQjzysHB1zxuWL50hzaeXiw==",
|
||||||
|
"devOptional": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"mime-db": "1.52.0"
|
"mime-db": "1.52.0"
|
||||||
},
|
},
|
||||||
@@ -19279,14 +19261,6 @@
|
|||||||
"integrity": "sha512-A/78XjoX2EmNvppVWEhM2oGk3x4lLxnkEA4jTbaK97QKSDjkIoOsKQlfylt/d3kKKi596Qy3NP5XrXJ6fZIC9Q==",
|
"integrity": "sha512-A/78XjoX2EmNvppVWEhM2oGk3x4lLxnkEA4jTbaK97QKSDjkIoOsKQlfylt/d3kKKi596Qy3NP5XrXJ6fZIC9Q==",
|
||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
"node_modules/moment": {
|
|
||||||
"version": "2.29.4",
|
|
||||||
"resolved": "https://registry.npmjs.org/moment/-/moment-2.29.4.tgz",
|
|
||||||
"integrity": "sha512-5LC9SOxjSc2HF6vO2CyuTDNivEdoz2IvyJJGj6X8DJ0eFyfszE0QiEd+iXmBvUP3WHxSjFH/vIsA0EN00cgr8w==",
|
|
||||||
"engines": {
|
|
||||||
"node": "*"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"node_modules/mrmime": {
|
"node_modules/mrmime": {
|
||||||
"version": "1.0.1",
|
"version": "1.0.1",
|
||||||
"resolved": "https://registry.npmmirror.com/mrmime/-/mrmime-1.0.1.tgz",
|
"resolved": "https://registry.npmmirror.com/mrmime/-/mrmime-1.0.1.tgz",
|
||||||
@@ -21456,11 +21430,6 @@
|
|||||||
"node": ">= 0.10"
|
"node": ">= 0.10"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/proxy-from-env": {
|
|
||||||
"version": "1.1.0",
|
|
||||||
"resolved": "https://registry.npmjs.org/proxy-from-env/-/proxy-from-env-1.1.0.tgz",
|
|
||||||
"integrity": "sha512-D+zkORCbA9f1tdWRK0RaCR3GPv50cMxcrz4X8k5LTSUD1Dkw47mKJEZQNunItRTkWwgtaUSo1RVFRIG9ZXiFYg=="
|
|
||||||
},
|
|
||||||
"node_modules/pseudomap": {
|
"node_modules/pseudomap": {
|
||||||
"version": "1.0.2",
|
"version": "1.0.2",
|
||||||
"resolved": "https://registry.npmmirror.com/pseudomap/-/pseudomap-1.0.2.tgz",
|
"resolved": "https://registry.npmmirror.com/pseudomap/-/pseudomap-1.0.2.tgz",
|
||||||
@@ -25285,15 +25254,6 @@
|
|||||||
"@vue/shared": "3.2.45"
|
"@vue/shared": "3.2.45"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/vue-axios": {
|
|
||||||
"version": "3.5.2",
|
|
||||||
"resolved": "https://registry.npmjs.org/vue-axios/-/vue-axios-3.5.2.tgz",
|
|
||||||
"integrity": "sha512-GP+dct7UlAWkl1qoP3ppw0z6jcSua5/IrMpjB5O8bh089iIiJ+hdxPYH2NPEpajlYgkW5EVMP95ttXWdas1O0g==",
|
|
||||||
"peerDependencies": {
|
|
||||||
"axios": "*",
|
|
||||||
"vue": "^3.0.0 || ^2.0.0"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"node_modules/vue-class-component": {
|
"node_modules/vue-class-component": {
|
||||||
"version": "8.0.0-rc.1",
|
"version": "8.0.0-rc.1",
|
||||||
"resolved": "https://registry.npmmirror.com/vue-class-component/-/vue-class-component-8.0.0-rc.1.tgz",
|
"resolved": "https://registry.npmmirror.com/vue-class-component/-/vue-class-component-8.0.0-rc.1.tgz",
|
||||||
|
|||||||
@@ -22,11 +22,9 @@
|
|||||||
"@veramo/key-manager": "^4.1.1",
|
"@veramo/key-manager": "^4.1.1",
|
||||||
"@vueuse/core": "^9.6.0",
|
"@vueuse/core": "^9.6.0",
|
||||||
"@zxing/text-encoding": "^0.9.0",
|
"@zxing/text-encoding": "^0.9.0",
|
||||||
"axios": "^1.2.2",
|
|
||||||
"class-transformer": "^0.5.1",
|
"class-transformer": "^0.5.1",
|
||||||
"core-js": "^3.26.1",
|
"core-js": "^3.26.1",
|
||||||
"dexie": "^3.2.2",
|
"dexie": "^3.2.2",
|
||||||
"did-jwt": "^6.9.0",
|
|
||||||
"ethereum-cryptography": "^1.1.2",
|
"ethereum-cryptography": "^1.1.2",
|
||||||
"ethereumjs-util": "^7.1.5",
|
"ethereumjs-util": "^7.1.5",
|
||||||
"ethr-did-resolver": "^8.0.0",
|
"ethr-did-resolver": "^8.0.0",
|
||||||
@@ -34,7 +32,6 @@
|
|||||||
"localstorage-slim": "^2.3.0",
|
"localstorage-slim": "^2.3.0",
|
||||||
"luxon": "^3.1.1",
|
"luxon": "^3.1.1",
|
||||||
"merkletreejs": "^0.3.9",
|
"merkletreejs": "^0.3.9",
|
||||||
"moment": "^2.29.4",
|
|
||||||
"papaparse": "^5.3.2",
|
"papaparse": "^5.3.2",
|
||||||
"pina": "^0.20.2204228",
|
"pina": "^0.20.2204228",
|
||||||
"pinia-plugin-persistedstate": "^3.0.1",
|
"pinia-plugin-persistedstate": "^3.0.1",
|
||||||
@@ -43,7 +40,6 @@
|
|||||||
"reflect-metadata": "^0.1.13",
|
"reflect-metadata": "^0.1.13",
|
||||||
"register-service-worker": "^1.7.2",
|
"register-service-worker": "^1.7.2",
|
||||||
"vue": "^3.2.45",
|
"vue": "^3.2.45",
|
||||||
"vue-axios": "^3.5.2",
|
|
||||||
"vue-class-component": "^8.0.0-0",
|
"vue-class-component": "^8.0.0-0",
|
||||||
"vue-property-decorator": "^9.1.2",
|
"vue-property-decorator": "^9.1.2",
|
||||||
"vue-router": "^4.1.6",
|
"vue-router": "^4.1.6",
|
||||||
|
|||||||
33
project.yaml
33
project.yaml
@@ -1,33 +0,0 @@
|
|||||||
- top screens from img/screens.pdf milestone:2 :
|
|
||||||
- edit page :
|
|
||||||
- saves successfully but does not transition
|
|
||||||
- view all :
|
|
||||||
- on "home" and "folder", the tab on bottom does not highlight (though it does highlight on the "magnifying glass")
|
|
||||||
|
|
||||||
- document the pagination assignee:trent
|
|
||||||
- add infinite scroll assignee:matthew
|
|
||||||
- view one
|
|
||||||
blocks: ref:https://raw.githubusercontent.com/trentlarson/lives-of-gifts/master/project.yaml#kickstarter%20for%20time
|
|
||||||
|
|
||||||
- replace user-affecting console.logs with error messages (eg. catches)
|
|
||||||
|
|
||||||
- contacts v1:
|
|
||||||
- .5 make advanced "show/hide amounts" button into a nice UI toggle
|
|
||||||
- .2 show error to user when adding a duplicate contact
|
|
||||||
- parse input more robustly (with CSV lib and not commas)
|
|
||||||
|
|
||||||
- commit screen
|
|
||||||
|
|
||||||
- discover screen
|
|
||||||
|
|
||||||
- backup all data
|
|
||||||
|
|
||||||
- Next Viable Product afterward
|
|
||||||
|
|
||||||
- Connect with phone contacts
|
|
||||||
|
|
||||||
- Multiple identities
|
|
||||||
|
|
||||||
- Peer DID
|
|
||||||
|
|
||||||
- DIDComm
|
|
||||||
@@ -4,6 +4,4 @@
|
|||||||
export enum AppString {
|
export enum AppString {
|
||||||
APP_NAME = "Kickstart for time",
|
APP_NAME = "Kickstart for time",
|
||||||
VERSION = "0.1",
|
VERSION = "0.1",
|
||||||
DEFAULT_ENDORSER_API_SERVER = "https://test.endorser.ch:8000",
|
|
||||||
//DEFAULT_ENDORSER_API_SERVER = "http://localhost:3000",
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,20 +1,6 @@
|
|||||||
import BaseDexie, { Table } from "dexie";
|
import BaseDexie from "dexie";
|
||||||
import { encrypted, Encryption } from "@pvermeer/dexie-encrypted-addon";
|
import { encrypted, Encryption } from "@pvermeer/dexie-encrypted-addon";
|
||||||
import {
|
import { accountsSchema, AccountsTable } from "./tables/accounts";
|
||||||
Account,
|
|
||||||
AccountsSchema,
|
|
||||||
Contact,
|
|
||||||
ContactsSchema,
|
|
||||||
MASTER_SETTINGS,
|
|
||||||
Settings,
|
|
||||||
SettingsSchema,
|
|
||||||
} from "./tables";
|
|
||||||
|
|
||||||
type AllTables = {
|
|
||||||
accounts: Table<Account>;
|
|
||||||
contacts: Table<Contact>;
|
|
||||||
settings: Table<Settings>;
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* In order to make the next line be acceptable, the program needs to have its linter suppress a rule:
|
* In order to make the next line be acceptable, the program needs to have its linter suppress a rule:
|
||||||
@@ -24,15 +10,10 @@ type AllTables = {
|
|||||||
*
|
*
|
||||||
* https://9to5answer.com/how-to-bypass-warning-unexpected-any-specify-a-different-type-typescript-eslint-no-explicit-any
|
* https://9to5answer.com/how-to-bypass-warning-unexpected-any-specify-a-different-type-typescript-eslint-no-explicit-any
|
||||||
*/
|
*/
|
||||||
type DexieTables = AllTables;
|
type DexieTables = AccountsTable;
|
||||||
export type Dexie<T extends unknown = DexieTables> = BaseDexie & T;
|
export type Dexie<T extends unknown = DexieTables> = BaseDexie & T;
|
||||||
export const db = new BaseDexie("KickStart") as Dexie;
|
export const db = new BaseDexie("kickStarter") as Dexie;
|
||||||
const AllSchemas = Object.assign(
|
const schema = Object.assign({}, accountsSchema);
|
||||||
{},
|
|
||||||
AccountsSchema,
|
|
||||||
ContactsSchema,
|
|
||||||
SettingsSchema
|
|
||||||
);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Needed to enable a special webpack setting to allow *await* below:
|
* Needed to enable a special webpack setting to allow *await* below:
|
||||||
@@ -46,13 +27,6 @@ const secret =
|
|||||||
if (localStorage.getItem("secret") == null) {
|
if (localStorage.getItem("secret") == null) {
|
||||||
localStorage.setItem("secret", secret);
|
localStorage.setItem("secret", secret);
|
||||||
}
|
}
|
||||||
|
console.log(secret);
|
||||||
//console.log("IndexedDB Encryption Secret:", secret);
|
|
||||||
encrypted(db, { secretKey: secret });
|
encrypted(db, { secretKey: secret });
|
||||||
db.version(1).stores(AllSchemas);
|
db.version(1).stores(schema);
|
||||||
|
|
||||||
// initialize, a la https://dexie.org/docs/Tutorial/Design#the-populate-event
|
|
||||||
db.on("populate", function () {
|
|
||||||
// ensure there's an initial entry for settings
|
|
||||||
db.settings.add({ id: MASTER_SETTINGS });
|
|
||||||
});
|
|
||||||
|
|||||||
18
src/db/tables/accounts.ts
Normal file
18
src/db/tables/accounts.ts
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
import { Table } from "dexie";
|
||||||
|
|
||||||
|
export type Account = {
|
||||||
|
id?: number;
|
||||||
|
publicKey: string;
|
||||||
|
mnemonic: string;
|
||||||
|
identity: string;
|
||||||
|
dateCreated: number;
|
||||||
|
};
|
||||||
|
|
||||||
|
export type AccountsTable = {
|
||||||
|
accounts: Table<Account>;
|
||||||
|
};
|
||||||
|
|
||||||
|
// mark encrypted field by starting with a $ character
|
||||||
|
export const accountsSchema = {
|
||||||
|
accounts: "++id, publicKey, $mnemonic, $identity, dateCreated",
|
||||||
|
};
|
||||||
@@ -1,41 +0,0 @@
|
|||||||
export type Account = {
|
|
||||||
id?: number; // auto-generated by Dexie
|
|
||||||
dateCreated: string;
|
|
||||||
derivationPath: string;
|
|
||||||
identity: string;
|
|
||||||
publicKeyHex: string;
|
|
||||||
mnemonic: string;
|
|
||||||
};
|
|
||||||
|
|
||||||
// mark encrypted field by starting with a $ character
|
|
||||||
// see https://github.com/PVermeer/dexie-addon-suite-monorepo/tree/master/packages/dexie-encrypted-addon
|
|
||||||
export const AccountsSchema = {
|
|
||||||
accounts:
|
|
||||||
"++id, dateCreated, derivationPath, $identity, $mnemonic, publicKeyHex",
|
|
||||||
};
|
|
||||||
|
|
||||||
export interface Contact {
|
|
||||||
did: string;
|
|
||||||
name?: string;
|
|
||||||
publicKeyBase64?: string;
|
|
||||||
seesMe?: boolean;
|
|
||||||
registered?: boolean;
|
|
||||||
}
|
|
||||||
|
|
||||||
export const ContactsSchema = {
|
|
||||||
contacts: "++did, name, publicKeyBase64, registered, seesMe",
|
|
||||||
};
|
|
||||||
|
|
||||||
// a singleton
|
|
||||||
export type Settings = {
|
|
||||||
id: number;
|
|
||||||
firstName?: string;
|
|
||||||
lastName?: string;
|
|
||||||
showContactGivesInline?: boolean;
|
|
||||||
};
|
|
||||||
|
|
||||||
export const SettingsSchema = {
|
|
||||||
settings: "id",
|
|
||||||
};
|
|
||||||
|
|
||||||
export const MASTER_SETTINGS = 1;
|
|
||||||
@@ -4,8 +4,6 @@ import { getRandomBytesSync } from "ethereum-cryptography/random";
|
|||||||
import { entropyToMnemonic } from "ethereum-cryptography/bip39";
|
import { entropyToMnemonic } from "ethereum-cryptography/bip39";
|
||||||
import { wordlist } from "ethereum-cryptography/bip39/wordlists/english";
|
import { wordlist } from "ethereum-cryptography/bip39/wordlists/english";
|
||||||
import { HDNode } from "@ethersproject/hdnode";
|
import { HDNode } from "@ethersproject/hdnode";
|
||||||
import * as didJwt from "did-jwt";
|
|
||||||
import * as u8a from "uint8arrays";
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
@@ -39,12 +37,6 @@ export const newIdentifier = (
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @param {string} mnemonic
|
|
||||||
* @return {*} {[string, string, string, string]}
|
|
||||||
*/
|
|
||||||
export const deriveAddress = (
|
export const deriveAddress = (
|
||||||
mnemonic: string
|
mnemonic: string
|
||||||
): [string, string, string, string] => {
|
): [string, string, string, string] => {
|
||||||
@@ -65,86 +57,9 @@ export const deriveAddress = (
|
|||||||
*
|
*
|
||||||
* @return {*} {string}
|
* @return {*} {string}
|
||||||
*/
|
*/
|
||||||
export const generateSeed = (): string => {
|
export const createIdentifier = (): string => {
|
||||||
const entropy: Uint8Array = getRandomBytesSync(32);
|
const entropy: Uint8Array = getRandomBytesSync(32);
|
||||||
const mnemonic = entropyToMnemonic(entropy, wordlist);
|
const mnemonic = entropyToMnemonic(entropy, wordlist);
|
||||||
|
|
||||||
return mnemonic;
|
return mnemonic;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
|
||||||
* Retreive an access token
|
|
||||||
*
|
|
||||||
* @param {IIdentifier} identifier
|
|
||||||
* @return {*}
|
|
||||||
*/
|
|
||||||
export const accessToken = async (identifier: IIdentifier) => {
|
|
||||||
const did: string = identifier.did;
|
|
||||||
const privateKeyHex: string = identifier.keys[0].privateKeyHex as string;
|
|
||||||
|
|
||||||
const signer = SimpleSigner(privateKeyHex);
|
|
||||||
|
|
||||||
const nowEpoch = Math.floor(Date.now() / 1000);
|
|
||||||
const endEpoch = nowEpoch + 60; // add one minute
|
|
||||||
|
|
||||||
const tokenPayload = { exp: endEpoch, iat: nowEpoch, iss: did };
|
|
||||||
const alg = undefined; // defaults to 'ES256K', more standardized but harder to verify vs ES256K-R
|
|
||||||
const jwt: string = await didJwt.createJWT(tokenPayload, {
|
|
||||||
alg,
|
|
||||||
issuer: did,
|
|
||||||
signer,
|
|
||||||
});
|
|
||||||
return jwt;
|
|
||||||
};
|
|
||||||
|
|
||||||
export const sign = async (privateKeyHex: string) => {
|
|
||||||
const signer = SimpleSigner(privateKeyHex);
|
|
||||||
|
|
||||||
return signer;
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Copied out of did-jwt since it's deprecated in that library.
|
|
||||||
*
|
|
||||||
* The SimpleSigner returns a configured function for signing data.
|
|
||||||
*
|
|
||||||
* @example
|
|
||||||
* const signer = SimpleSigner(process.env.PRIVATE_KEY)
|
|
||||||
* signer(data, (err, signature) => {
|
|
||||||
* ...
|
|
||||||
* })
|
|
||||||
*
|
|
||||||
* @param {String} hexPrivateKey a hex encoded private key
|
|
||||||
* @return {Function} a configured signer function
|
|
||||||
*/
|
|
||||||
export function SimpleSigner(hexPrivateKey: string): didJwt.Signer {
|
|
||||||
const signer = didJwt.ES256KSigner(didJwt.hexToBytes(hexPrivateKey), true);
|
|
||||||
return async (data) => {
|
|
||||||
const signature = (await signer(data)) as string;
|
|
||||||
return fromJose(signature);
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
// from did-jwt/util; see SimpleSigner above
|
|
||||||
export function fromJose(signature: string): {
|
|
||||||
r: string;
|
|
||||||
s: string;
|
|
||||||
recoveryParam?: number;
|
|
||||||
} {
|
|
||||||
const signatureBytes: Uint8Array = didJwt.base64ToBytes(signature);
|
|
||||||
if (signatureBytes.length < 64 || signatureBytes.length > 65) {
|
|
||||||
throw new TypeError(
|
|
||||||
`Wrong size for signature. Expected 64 or 65 bytes, but got ${signatureBytes.length}`
|
|
||||||
);
|
|
||||||
}
|
|
||||||
const r = bytesToHex(signatureBytes.slice(0, 32));
|
|
||||||
const s = bytesToHex(signatureBytes.slice(32, 64));
|
|
||||||
const recoveryParam =
|
|
||||||
signatureBytes.length === 65 ? signatureBytes[64] : undefined;
|
|
||||||
return { r, s, recoveryParam };
|
|
||||||
}
|
|
||||||
|
|
||||||
// from did-jwt/util; see SimpleSigner above
|
|
||||||
export function bytesToHex(b: Uint8Array): string {
|
|
||||||
return u8a.toString(b, "base16");
|
|
||||||
}
|
|
||||||
|
|||||||
14
src/main.ts
14
src/main.ts
@@ -1,11 +1,9 @@
|
|||||||
|
import { VueDexiePlugin } from "@/plugins/dexieVuePlugin";
|
||||||
import { createPinia } from "pinia";
|
import { createPinia } from "pinia";
|
||||||
import { createApp } from "vue";
|
import { createApp } from "vue";
|
||||||
import App from "./App.vue";
|
import App from "./App.vue";
|
||||||
import "./registerServiceWorker";
|
import "./registerServiceWorker";
|
||||||
import router from "./router";
|
import router from "./router";
|
||||||
import axios from "axios";
|
|
||||||
import VueAxios from "vue-axios";
|
|
||||||
|
|
||||||
import "./assets/styles/tailwind.css";
|
import "./assets/styles/tailwind.css";
|
||||||
|
|
||||||
import { library } from "@fortawesome/fontawesome-svg-core";
|
import { library } from "@fortawesome/fontawesome-svg-core";
|
||||||
@@ -20,15 +18,12 @@ import {
|
|||||||
faShareNodes,
|
faShareNodes,
|
||||||
faQrcode,
|
faQrcode,
|
||||||
faUser,
|
faUser,
|
||||||
faUsers,
|
|
||||||
faPen,
|
faPen,
|
||||||
faPlus,
|
|
||||||
faTrashCan,
|
faTrashCan,
|
||||||
faCalendar,
|
faCalendar,
|
||||||
faEllipsisVertical,
|
faEllipsisVertical,
|
||||||
faSpinner,
|
faSpinner,
|
||||||
faCircleCheck,
|
faCircleCheck,
|
||||||
faXmark,
|
|
||||||
} from "@fortawesome/free-solid-svg-icons";
|
} from "@fortawesome/free-solid-svg-icons";
|
||||||
|
|
||||||
library.add(
|
library.add(
|
||||||
@@ -42,22 +37,19 @@ library.add(
|
|||||||
faShareNodes,
|
faShareNodes,
|
||||||
faQrcode,
|
faQrcode,
|
||||||
faUser,
|
faUser,
|
||||||
faUsers,
|
|
||||||
faPen,
|
faPen,
|
||||||
faPlus,
|
|
||||||
faTrashCan,
|
faTrashCan,
|
||||||
faCalendar,
|
faCalendar,
|
||||||
faEllipsisVertical,
|
faEllipsisVertical,
|
||||||
faSpinner,
|
faSpinner,
|
||||||
faCircleCheck,
|
faCircleCheck
|
||||||
faXmark
|
|
||||||
);
|
);
|
||||||
|
|
||||||
import { FontAwesomeIcon } from "@fortawesome/vue-fontawesome";
|
import { FontAwesomeIcon } from "@fortawesome/vue-fontawesome";
|
||||||
|
|
||||||
createApp(App)
|
createApp(App)
|
||||||
.component("fa", FontAwesomeIcon)
|
.component("fa", FontAwesomeIcon)
|
||||||
|
.use(VueDexiePlugin())
|
||||||
.use(createPinia())
|
.use(createPinia())
|
||||||
.use(VueAxios, axios)
|
|
||||||
.use(router)
|
.use(router)
|
||||||
.mount("#app");
|
.mount("#app");
|
||||||
|
|||||||
18
src/plugins/dexieVuePlugin/index.ts
Normal file
18
src/plugins/dexieVuePlugin/index.ts
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
import Vue from 'vue'
|
||||||
|
import { PluginObject } from 'vue'
|
||||||
|
|
||||||
|
// define the plugin class
|
||||||
|
class VueDexiePlugin implements PluginObject<{}> {
|
||||||
|
// the install method is called when the plugin is installed
|
||||||
|
public static install(app: typeof Vue): void {
|
||||||
|
// define a custom property
|
||||||
|
app.$myProperty = 'Hello, World!'
|
||||||
|
|
||||||
|
// define a custom method
|
||||||
|
app.prototype.$myMethod = (): string => {
|
||||||
|
return this.$myProperty
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default new VueDexiePlugin()
|
||||||
@@ -1,25 +1,19 @@
|
|||||||
import { createRouter, createWebHistory, RouteRecordRaw } from "vue-router";
|
import { createRouter, createWebHistory, RouteRecordRaw } from "vue-router";
|
||||||
import { db } from "@/db";
|
import { useAppStore } from "../store/app";
|
||||||
|
import HomeView from "../views/HomeView.vue";
|
||||||
|
|
||||||
const routes: Array<RouteRecordRaw> = [
|
const routes: Array<RouteRecordRaw> = [
|
||||||
{
|
{
|
||||||
path: "/",
|
path: "/",
|
||||||
name: "home",
|
name: "home",
|
||||||
component: () =>
|
component: HomeView,
|
||||||
import(/* webpackChunkName: "start" */ "../views/DiscoverView.vue"),
|
|
||||||
beforeEnter: async (to, from, next) => {
|
|
||||||
await db.open();
|
|
||||||
const num_accounts = await db.accounts.count();
|
|
||||||
if (num_accounts > 0) {
|
|
||||||
next();
|
|
||||||
} else {
|
|
||||||
next({ name: "start" });
|
|
||||||
}
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
path: "/about",
|
path: "/about",
|
||||||
name: "about",
|
name: "about",
|
||||||
|
// route level code-splitting
|
||||||
|
// this generates a separate chunk (about.[hash].js) for this route
|
||||||
|
// which is lazy-loaded when the route is visited.
|
||||||
component: () =>
|
component: () =>
|
||||||
import(/* webpackChunkName: "about" */ "../views/AboutView.vue"),
|
import(/* webpackChunkName: "about" */ "../views/AboutView.vue"),
|
||||||
},
|
},
|
||||||
@@ -43,12 +37,6 @@ const routes: Array<RouteRecordRaw> = [
|
|||||||
/* webpackChunkName: "confirm-contact" */ "../views/ConfirmContactView.vue"
|
/* webpackChunkName: "confirm-contact" */ "../views/ConfirmContactView.vue"
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
{
|
|
||||||
path: "/contacts",
|
|
||||||
name: "contacts",
|
|
||||||
component: () =>
|
|
||||||
import(/* webpackChunkName: "contacts" */ "../views/ContactsView.vue"),
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
path: "/scan-contact",
|
path: "/scan-contact",
|
||||||
name: "scan-contact",
|
name: "scan-contact",
|
||||||
@@ -87,12 +75,6 @@ const routes: Array<RouteRecordRaw> = [
|
|||||||
/* webpackChunkName: "new-edit-commitment" */ "../views/NewEditCommitmentView.vue"
|
/* webpackChunkName: "new-edit-commitment" */ "../views/NewEditCommitmentView.vue"
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
{
|
|
||||||
path: "/project",
|
|
||||||
name: "project",
|
|
||||||
component: () =>
|
|
||||||
import(/* webpackChunkName: "project" */ "../views/ProjectViewView.vue"),
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
path: "/new-edit-project",
|
path: "/new-edit-project",
|
||||||
name: "new-edit-project",
|
name: "new-edit-project",
|
||||||
@@ -101,6 +83,12 @@ const routes: Array<RouteRecordRaw> = [
|
|||||||
/* webpackChunkName: "new-edit-project" */ "../views/NewEditProjectView.vue"
|
/* webpackChunkName: "new-edit-project" */ "../views/NewEditProjectView.vue"
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
path: "/project",
|
||||||
|
name: "project",
|
||||||
|
component: () =>
|
||||||
|
import(/* webpackChunkName: "project" */ "../views/ProjectViewView.vue"),
|
||||||
|
},
|
||||||
{
|
{
|
||||||
path: "/projects",
|
path: "/projects",
|
||||||
name: "projects",
|
name: "projects",
|
||||||
@@ -117,10 +105,37 @@ const routes: Array<RouteRecordRaw> = [
|
|||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
/** @type {*} */
|
|
||||||
const router = createRouter({
|
const router = createRouter({
|
||||||
history: createWebHistory(process.env.BASE_URL),
|
history: createWebHistory(process.env.BASE_URL),
|
||||||
routes,
|
routes,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
router.beforeEach(async (to) => {
|
||||||
|
const publicPages = ["/start", "/account", "/import-account"];
|
||||||
|
const isPublic = publicPages.includes(to.path);
|
||||||
|
const appStore = useAppStore();
|
||||||
|
let return_path = "/start";
|
||||||
|
|
||||||
|
if (isPublic) {
|
||||||
|
switch (appStore.condition) {
|
||||||
|
case "uninitialized":
|
||||||
|
return_path = "";
|
||||||
|
break;
|
||||||
|
case "registering":
|
||||||
|
return_path = to.path;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
switch (appStore.condition) {
|
||||||
|
case "registered":
|
||||||
|
return_path = to.path;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (return_path == "") {
|
||||||
|
return;
|
||||||
|
} else {
|
||||||
|
return return_path;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
export default router;
|
export default router;
|
||||||
|
|||||||
22
src/store/account.ts
Normal file
22
src/store/account.ts
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
// @ts-check
|
||||||
|
import { defineStore } from "pinia";
|
||||||
|
|
||||||
|
export const useAccountStore = defineStore({
|
||||||
|
id: "account",
|
||||||
|
state: () => ({
|
||||||
|
account: JSON.parse(
|
||||||
|
typeof localStorage["account"] == "undefined"
|
||||||
|
? null
|
||||||
|
: localStorage["account"]
|
||||||
|
),
|
||||||
|
}),
|
||||||
|
getters: {
|
||||||
|
firstName: (state) => state.account.firstName,
|
||||||
|
lastName: (state) => state.account.lastName,
|
||||||
|
},
|
||||||
|
actions: {
|
||||||
|
reset() {
|
||||||
|
localStorage.removeItem("account");
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
@@ -4,17 +4,21 @@ import { defineStore } from "pinia";
|
|||||||
export const useAppStore = defineStore({
|
export const useAppStore = defineStore({
|
||||||
id: "app",
|
id: "app",
|
||||||
state: () => ({
|
state: () => ({
|
||||||
_projectId:
|
_condition:
|
||||||
typeof localStorage.getItem("projectId") === "undefined"
|
typeof localStorage["condition"] == "undefined"
|
||||||
? ""
|
? "uninitialized"
|
||||||
: localStorage.getItem("projectId"),
|
: localStorage["condition"],
|
||||||
|
_lastView:
|
||||||
|
typeof localStorage["lastView"] == "undefined"
|
||||||
|
? "/start"
|
||||||
|
: localStorage["lastView"],
|
||||||
}),
|
}),
|
||||||
getters: {
|
getters: {
|
||||||
projectId: (state): string => state._projectId as string,
|
condition: (state) => state._condition,
|
||||||
},
|
},
|
||||||
actions: {
|
actions: {
|
||||||
async setProjectId(newProjectId: string) {
|
reset() {
|
||||||
localStorage.setItem("projectId", newProjectId);
|
localStorage.removeItem("condition");
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,60 +0,0 @@
|
|||||||
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);
|
|
||||||
}
|
|
||||||
@@ -29,10 +29,10 @@
|
|||||||
<!-- Commitments -->
|
<!-- Commitments -->
|
||||||
<li class="basis-1/5 rounded-md text-slate-500">
|
<li class="basis-1/5 rounded-md text-slate-500">
|
||||||
<router-link
|
<router-link
|
||||||
:to="{ name: 'contacts' }"
|
:to="{ name: 'commitments' }"
|
||||||
class="block text-center py-3 px-1"
|
class="block text-center py-3 px-1"
|
||||||
>
|
>
|
||||||
<fa icon="users" class="fa-fw"></fa>
|
<fa icon="hand" class="fa-fw"></fa>
|
||||||
</router-link>
|
</router-link>
|
||||||
</li>
|
</li>
|
||||||
<!-- Profile -->
|
<!-- Profile -->
|
||||||
@@ -72,7 +72,7 @@
|
|||||||
|
|
||||||
<!-- Identity Details -->
|
<!-- Identity Details -->
|
||||||
<div class="bg-slate-100 rounded-md overflow-hidden px-4 py-3 mb-4">
|
<div class="bg-slate-100 rounded-md overflow-hidden px-4 py-3 mb-4">
|
||||||
<h2 class="text-xl font-semibold mb-2">{{ firstName }} {{ lastName }}</h2>
|
<h2 class="text-xl font-semibold mb-2">Firstname Lastname</h2>
|
||||||
|
|
||||||
<div class="text-slate-500 text-sm font-bold">ID</div>
|
<div class="text-slate-500 text-sm font-bold">ID</div>
|
||||||
<div
|
<div
|
||||||
@@ -80,9 +80,7 @@
|
|||||||
>
|
>
|
||||||
<span
|
<span
|
||||||
><code>{{ address }}</code>
|
><code>{{ address }}</code>
|
||||||
<button @click="copy(address)">
|
<fa icon="copy" class="text-slate-400 fa-fw ml-1"></fa>
|
||||||
<fa icon="copy" class="text-slate-400 fa-fw ml-1"></fa>
|
|
||||||
</button>
|
|
||||||
</span>
|
</span>
|
||||||
<span>
|
<span>
|
||||||
<button
|
<button
|
||||||
@@ -102,19 +100,15 @@
|
|||||||
<div class="text-sm text-slate-500 mb-1">
|
<div class="text-sm text-slate-500 mb-1">
|
||||||
<span
|
<span
|
||||||
><code>{{ publicHex }}</code>
|
><code>{{ publicHex }}</code>
|
||||||
<button @click="copy(publicHex)">
|
<fa icon="copy" class="text-slate-400 fa-fw ml-1"></fa>
|
||||||
<fa icon="copy" class="text-slate-400 fa-fw ml-1"></fa>
|
|
||||||
</button>
|
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="text-slate-500 text-sm font-bold">Derivation Path</div>
|
<div class="text-slate-500 text-sm font-bold">Derivation Path</div>
|
||||||
<div class="text-sm text-slate-500 mb-1">
|
<div class="text-sm text-slate-500 mb-1">
|
||||||
<span
|
<span
|
||||||
><code>{{ derivationPath }}</code>
|
><code>{{ UPORT_ROOT_DERIVATION_PATH }}</code>
|
||||||
<button @click="copy(derivationPath)">
|
<fa icon="copy" class="text-slate-400 fa-fw ml-1"></fa>
|
||||||
<fa icon="copy" class="text-slate-400 fa-fw ml-1"></fa>
|
|
||||||
</button>
|
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -168,158 +162,91 @@
|
|||||||
</button>
|
</button>
|
||||||
</form>
|
</form>
|
||||||
</dialog>
|
</dialog>
|
||||||
|
|
||||||
<h3 class="text-sm uppercase font-semibold mb-3">Advanced</h3>
|
|
||||||
|
|
||||||
<div class="flex">
|
|
||||||
<button
|
|
||||||
href=""
|
|
||||||
class="text-center text-md text-white px-1.5 py-2 rounded-md mb-6"
|
|
||||||
v-bind:class="showContactGivesClassNames()"
|
|
||||||
@click="toggleShowContactAmounts"
|
|
||||||
>
|
|
||||||
{{ showContactGives ? "Showing" : "Hiding" }}
|
|
||||||
amounts given with contacts (Click to
|
|
||||||
{{ showContactGives ? "hide" : "show" }})
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div v-bind:class="computedAlertClassNames()">
|
|
||||||
<button
|
|
||||||
class="close-button bg-slate-200 w-8 leading-loose rounded-full absolute top-2 right-2"
|
|
||||||
@click="onClickClose()"
|
|
||||||
>
|
|
||||||
<fa icon="xmark"></fa>
|
|
||||||
</button>
|
|
||||||
<h4 class="font-bold pr-5">{{ alertTitle }}</h4>
|
|
||||||
<p>{{ alertMessage }}</p>
|
|
||||||
</div>
|
|
||||||
</section>
|
</section>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { Options, Vue } from "vue-class-component";
|
import { Options, Vue } from "vue-class-component";
|
||||||
import { useClipboard } from "@vueuse/core";
|
import { createIdentifier, deriveAddress, newIdentifier } from "../libs/crypto";
|
||||||
import { db } from "@/db";
|
import { IIdentifier } from "@veramo/core";
|
||||||
import { MASTER_SETTINGS } from "@/db/tables";
|
import * as R from "ramda";
|
||||||
import { deriveAddress, generateSeed, newIdentifier } from "@/libs/crypto";
|
import { db } from "../db";
|
||||||
//import { testServerRegisterUser } from "../test";
|
|
||||||
|
|
||||||
@Options({
|
@Options({
|
||||||
components: {},
|
components: {},
|
||||||
})
|
})
|
||||||
export default class AccountViewView extends Vue {
|
export default class AccountViewView extends Vue {
|
||||||
// This registers current user in vue plugin with: $vm.ctx.testRegisterUser()
|
|
||||||
//testRegisterUser = testServerRegisterUser;
|
|
||||||
|
|
||||||
address = "";
|
|
||||||
firstName = "";
|
|
||||||
lastName = "";
|
|
||||||
mnemonic = "";
|
mnemonic = "";
|
||||||
|
address = "";
|
||||||
|
privateHex = "";
|
||||||
publicHex = "";
|
publicHex = "";
|
||||||
derivationPath = "";
|
UPORT_ROOT_DERIVATION_PATH = "";
|
||||||
showContactGives = false;
|
|
||||||
|
|
||||||
copy = useClipboard().copy;
|
|
||||||
|
|
||||||
// 'created' hook runs when the Vue instance is first created
|
|
||||||
async created() {
|
async created() {
|
||||||
await db.open();
|
const previousIdentifiers: Array<IIdentifier> = [];
|
||||||
try {
|
const toLowercase = true;
|
||||||
const settings = await db.settings.get(MASTER_SETTINGS);
|
this.mnemonic = createIdentifier();
|
||||||
if (settings) {
|
[
|
||||||
this.firstName = settings.firstName || "";
|
this.address,
|
||||||
this.lastName = settings.lastName || "";
|
this.privateHex,
|
||||||
this.showContactGives = !!settings.showContactGivesInline;
|
this.publicHex,
|
||||||
|
this.UPORT_ROOT_DERIVATION_PATH,
|
||||||
|
] = deriveAddress(this.mnemonic);
|
||||||
|
//appStore.dispatch(appSlice.actions.addLog({log: false, msg: "... derived keys and address..."}))
|
||||||
|
const prevIds = previousIdentifiers || [];
|
||||||
|
if (toLowercase) {
|
||||||
|
const foundEqual = R.find(
|
||||||
|
(id: IIdentifier) => id.did.split(":")[2] === this.address,
|
||||||
|
prevIds
|
||||||
|
);
|
||||||
|
if (foundEqual) {
|
||||||
|
// appStore.dispatch(appSlice.actions.addLog({log: true, msg: "Will create a normal-case version of the DID since a regular version exists."}))
|
||||||
|
} else {
|
||||||
|
this.address = this.address.toLowerCase();
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
const numAccounts = await db.accounts.count();
|
// They're not trying to convert to lowercase.
|
||||||
if (numAccounts === 0) {
|
const foundLower = R.find(
|
||||||
let privateHex = "";
|
(id: IIdentifier) =>
|
||||||
this.mnemonic = generateSeed();
|
id.did.split(":")[2] === this.address.toLowerCase(),
|
||||||
[this.address, privateHex, this.publicHex, this.derivationPath] =
|
prevIds
|
||||||
deriveAddress(this.mnemonic);
|
);
|
||||||
|
if (foundLower) {
|
||||||
const newId = newIdentifier(
|
// appStore.dispatch(appSlice.actions.addLog({log: true, msg: "Will create a lowercase version of the DID since a lowercase version exists."}))
|
||||||
this.address,
|
this.address = this.address.toLowerCase();
|
||||||
this.publicHex,
|
|
||||||
privateHex,
|
|
||||||
this.derivationPath
|
|
||||||
);
|
|
||||||
await db.accounts.add({
|
|
||||||
dateCreated: new Date().toISOString(),
|
|
||||||
derivationPath: this.derivationPath,
|
|
||||||
identity: JSON.stringify(newId),
|
|
||||||
mnemonic: this.mnemonic,
|
|
||||||
publicKeyHex: newId.keys[0].publicKeyHex,
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
} catch (err) {
|
|
||||||
this.alertMessage =
|
|
||||||
"Clear your cache and start over (after data backup). See console log for more info.";
|
|
||||||
console.log("Telling user to clear cache because:", err);
|
|
||||||
this.alertTitle = "Error Creating Account";
|
|
||||||
this.isAlertVisible = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const accounts = await db.accounts.toArray();
|
const newId = newIdentifier(
|
||||||
const identity = JSON.parse(accounts[0].identity);
|
this.address,
|
||||||
this.address = identity.did;
|
this.publicHex,
|
||||||
this.publicHex = identity.keys[0].publicKeyHex;
|
this.privateHex,
|
||||||
this.derivationPath = identity.keys[0].meta.derivationPath;
|
this.UPORT_ROOT_DERIVATION_PATH
|
||||||
}
|
);
|
||||||
|
|
||||||
public async toggleShowContactAmounts() {
|
|
||||||
this.showContactGives = !this.showContactGives;
|
|
||||||
try {
|
try {
|
||||||
await db.open();
|
await db.open();
|
||||||
const settings = await db.settings.get(MASTER_SETTINGS);
|
const num_accounts = await db.accounts.count();
|
||||||
if (settings) {
|
if (num_accounts === 0) {
|
||||||
db.settings.update(MASTER_SETTINGS, {
|
console.log("...");
|
||||||
showContactGivesInline: this.showContactGives,
|
await db.accounts.add({
|
||||||
|
publicKey: newId.keys[0].publicKeyHex,
|
||||||
|
mnemonic: this.mnemonic,
|
||||||
|
identity: JSON.stringify(newId),
|
||||||
|
dateCreated: new Date().getTime(),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
const accounts = await db.accounts.toArray();
|
||||||
|
console.log(accounts[0]);
|
||||||
|
const identity = JSON.parse(accounts[0].identity);
|
||||||
|
|
||||||
|
this.address = identity.did;
|
||||||
|
this.publicHex = identity.keys[0].publicKeyHex;
|
||||||
|
|
||||||
|
//appStore.dispatch(appSlice.actions.addLog({log: false, msg: "... created new ID..."}))
|
||||||
|
//appStore.dispatch(appSlice.actions.addLog({log: false, msg: "... stored new ID..."}))
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
this.alertMessage =
|
console.log("Error!");
|
||||||
"Clear your cache and start over (after data backup). See console log for more info.";
|
console.log(err);
|
||||||
console.log("Telling user to clear cache because:", err);
|
|
||||||
this.alertTitle = "Error Creating Account";
|
|
||||||
this.isAlertVisible = true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public showContactGivesClassNames() {
|
|
||||||
return {
|
|
||||||
"bg-slate-900": !this.showContactGives,
|
|
||||||
"bg-green-600": this.showContactGives,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
alertMessage = "";
|
|
||||||
alertTitle = "";
|
|
||||||
isAlertVisible = false;
|
|
||||||
|
|
||||||
public onClickClose() {
|
|
||||||
this.isAlertVisible = false;
|
|
||||||
this.alertTitle = "";
|
|
||||||
this.alertMessage = "";
|
|
||||||
}
|
|
||||||
|
|
||||||
public computedAlertClassNames() {
|
|
||||||
return {
|
|
||||||
hidden: !this.isAlertVisible,
|
|
||||||
"dismissable-alert": true,
|
|
||||||
"bg-slate-100": true,
|
|
||||||
"p-5": true,
|
|
||||||
rounded: true,
|
|
||||||
"drop-shadow-lg": true,
|
|
||||||
absolute: true,
|
|
||||||
"top-3": true,
|
|
||||||
"inset-x-3": true,
|
|
||||||
"transition-transform": true,
|
|
||||||
"ease-in": true,
|
|
||||||
"duration-300": true,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
@@ -1,442 +0,0 @@
|
|||||||
<template>
|
|
||||||
<!-- QUICK NAV -->
|
|
||||||
<nav id="QuickNav" class="fixed bottom-0 left-0 right-0 bg-slate-200">
|
|
||||||
<ul class="flex text-2xl p-2 gap-2">
|
|
||||||
<!-- Home Feed -->
|
|
||||||
<li class="basis-1/5 rounded-md text-slate-500">
|
|
||||||
<router-link :to="{ name: 'home' }" class="block text-center py-3 px-1"
|
|
||||||
><fa icon="house-chimney" class="fa-fw"></fa
|
|
||||||
></router-link>
|
|
||||||
</li>
|
|
||||||
<!-- Search -->
|
|
||||||
<li class="basis-1/5 rounded-md bg-slate-400 text-white">
|
|
||||||
<router-link
|
|
||||||
:to="{ name: 'discover' }"
|
|
||||||
class="block text-center py-3 px-1"
|
|
||||||
><fa icon="magnifying-glass" class="fa-fw"></fa
|
|
||||||
></router-link>
|
|
||||||
</li>
|
|
||||||
<!-- Contacts -->
|
|
||||||
<li class="basis-1/5 rounded-md text-slate-500">
|
|
||||||
<router-link
|
|
||||||
:to="{ name: 'projects' }"
|
|
||||||
class="block text-center py-3 px-1"
|
|
||||||
><fa icon="folder-open" class="fa-fw"></fa
|
|
||||||
></router-link>
|
|
||||||
</li>
|
|
||||||
<!-- Commitments -->
|
|
||||||
<li class="basis-1/5 rounded-md text-slate-500">
|
|
||||||
<router-link
|
|
||||||
:to="{ name: 'contacts' }"
|
|
||||||
class="block text-center py-3 px-1"
|
|
||||||
><fa icon="users" class="fa-fw"></fa
|
|
||||||
></router-link>
|
|
||||||
</li>
|
|
||||||
<!-- Profile -->
|
|
||||||
<li class="basis-1/5 rounded-md text-slate-500">
|
|
||||||
<router-link
|
|
||||||
:to="{ name: 'account' }"
|
|
||||||
class="block text-center py-3 px-1"
|
|
||||||
><fa icon="circle-user" class="fa-fw"></fa
|
|
||||||
></router-link>
|
|
||||||
</li>
|
|
||||||
</ul>
|
|
||||||
</nav>
|
|
||||||
|
|
||||||
<section id="Content" class="p-6 pb-24">
|
|
||||||
<!-- Heading -->
|
|
||||||
<h1 id="ViewHeading" class="text-4xl text-center font-light pt-4 mb-8">
|
|
||||||
My Contacts
|
|
||||||
</h1>
|
|
||||||
|
|
||||||
<!-- New Contact -->
|
|
||||||
<div class="mb-4 flex">
|
|
||||||
<input
|
|
||||||
type="text"
|
|
||||||
placeholder="DID, Name, Public Key"
|
|
||||||
class="block w-full rounded-l border border-r-0 border-slate-400 px-3 py-2"
|
|
||||||
v-model="contactInput"
|
|
||||||
/>
|
|
||||||
<button
|
|
||||||
class="px-4 rounded-r bg-slate-200 border border-l-0 border-slate-400"
|
|
||||||
@click="onClickNewContact()"
|
|
||||||
>
|
|
||||||
<fa icon="plus" class="fa-fw"></fa>
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="flex justify-between" v-if="showGiveTotals">
|
|
||||||
<div class="w-full text-right">
|
|
||||||
Hours to Add:
|
|
||||||
<input
|
|
||||||
class="border border rounded border-slate-400 w-24 text-right"
|
|
||||||
type="text"
|
|
||||||
placeholder="1"
|
|
||||||
v-model="hourInput"
|
|
||||||
/>
|
|
||||||
<br />
|
|
||||||
<input
|
|
||||||
class="border border rounded border-slate-400 w-48"
|
|
||||||
type="text"
|
|
||||||
placeholder="Description"
|
|
||||||
v-model="hourDescriptionInput"
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<!-- Results List -->
|
|
||||||
<ul class="">
|
|
||||||
<li
|
|
||||||
class="border-b border-slate-300"
|
|
||||||
v-for="contact in contacts"
|
|
||||||
:key="contact.did"
|
|
||||||
>
|
|
||||||
<div class="grow overflow-hidden">
|
|
||||||
<h2 class="text-base font-semibold">
|
|
||||||
{{ contact.name || "(no name)" }}
|
|
||||||
</h2>
|
|
||||||
<div class="text-sm truncate">{{ contact.did }}</div>
|
|
||||||
<div class="text-sm truncate">{{ contact.publicKeyBase64 }}</div>
|
|
||||||
<div v-if="showGiveTotals" class="float-right">
|
|
||||||
<div class="float-right">
|
|
||||||
to: {{ givenByMeTotals[contact.did] || 0 }}
|
|
||||||
<button
|
|
||||||
class="text-md uppercase bg-slate-500 text-white px-1.5 py-2 rounded-md mb-6"
|
|
||||||
@click="onClickAddGive(identity.did, contact.did)"
|
|
||||||
>
|
|
||||||
+
|
|
||||||
</button>
|
|
||||||
by: {{ givenToMeTotals[contact.did] || 0 }}
|
|
||||||
<button
|
|
||||||
class="text-md uppercase bg-slate-500 text-white px-1.5 py-2 rounded-md mb-6"
|
|
||||||
@click="onClickAddGive(contact.did, identity.did)"
|
|
||||||
>
|
|
||||||
+
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</li>
|
|
||||||
</ul>
|
|
||||||
</section>
|
|
||||||
<div v-bind:class="computedAlertClassNames()">
|
|
||||||
<button
|
|
||||||
class="close-button bg-slate-200 w-8 leading-loose rounded-full absolute top-2 right-2"
|
|
||||||
@click="onClickClose()"
|
|
||||||
>
|
|
||||||
<fa icon="xmark"></fa>
|
|
||||||
</button>
|
|
||||||
<h4 class="font-bold pr-5">{{ alertTitle }}</h4>
|
|
||||||
<p>{{ alertMessage }}</p>
|
|
||||||
</div>
|
|
||||||
</template>
|
|
||||||
|
|
||||||
<script lang="ts">
|
|
||||||
import { AxiosError } from "axios";
|
|
||||||
import * as didJwt from "did-jwt";
|
|
||||||
import * as R from "ramda";
|
|
||||||
import { Options, Vue } from "vue-class-component";
|
|
||||||
|
|
||||||
import { AppString } from "@/constants/app";
|
|
||||||
import { accessToken, SimpleSigner } from "@/libs/crypto";
|
|
||||||
import { IIdentifier } from "@veramo/core";
|
|
||||||
import { db } from "../db";
|
|
||||||
import { Contact } from "../db/tables";
|
|
||||||
|
|
||||||
export interface GiveVerifiableCredential {
|
|
||||||
"@context": string;
|
|
||||||
"@type": string;
|
|
||||||
agent: { identifier: string };
|
|
||||||
description?: string;
|
|
||||||
object: { amountOfThisGood: number; unitCode: string };
|
|
||||||
recipient: { identifier: string };
|
|
||||||
}
|
|
||||||
|
|
||||||
@Options({
|
|
||||||
components: {},
|
|
||||||
})
|
|
||||||
export default class ContactsView extends Vue {
|
|
||||||
contacts: Array<Contact> = [];
|
|
||||||
contactInput = "";
|
|
||||||
// { "did:...": amount } entry for each contact
|
|
||||||
givenByMeTotals: Record<string, number> = {};
|
|
||||||
// { "did:...": amount } entry for each contact
|
|
||||||
givenToMeTotals: Record<string, number> = {};
|
|
||||||
hourDescriptionInput = "";
|
|
||||||
hourInput = "0";
|
|
||||||
identity: IIdentifier | null = null;
|
|
||||||
showGiveTotals = false;
|
|
||||||
|
|
||||||
// 'created' hook runs when the Vue instance is first created
|
|
||||||
async created() {
|
|
||||||
await db.open();
|
|
||||||
const accounts = await db.accounts.toArray();
|
|
||||||
this.identity = JSON.parse(accounts[0].identity);
|
|
||||||
this.contacts = await db.contacts.toArray();
|
|
||||||
|
|
||||||
const params = new URLSearchParams(window.location.search);
|
|
||||||
this.showGiveTotals = params.get("showGiveTotals") == "true";
|
|
||||||
if (this.showGiveTotals) {
|
|
||||||
this.loadGives();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async onClickNewContact(): Promise<void> {
|
|
||||||
let did = this.contactInput;
|
|
||||||
let name, publicKeyBase64;
|
|
||||||
const commaPos1 = this.contactInput.indexOf(",");
|
|
||||||
if (commaPos1 > -1) {
|
|
||||||
did = this.contactInput.substring(0, commaPos1).trim();
|
|
||||||
name = this.contactInput.substring(commaPos1 + 1).trim();
|
|
||||||
const commaPos2 = this.contactInput.indexOf(",", commaPos1 + 1);
|
|
||||||
if (commaPos2 > -1) {
|
|
||||||
name = this.contactInput.substring(commaPos1 + 1, commaPos2).trim();
|
|
||||||
publicKeyBase64 = this.contactInput.substring(commaPos2 + 1).trim();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
const newContact = { did, name, publicKeyBase64 };
|
|
||||||
await db.contacts.add(newContact);
|
|
||||||
this.contacts = this.contacts.concat([newContact]);
|
|
||||||
}
|
|
||||||
|
|
||||||
async loadGives() {
|
|
||||||
if (!this.identity) {
|
|
||||||
console.error(
|
|
||||||
"Attempted to load Give records with no identity available."
|
|
||||||
);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const endorserApiServer = AppString.DEFAULT_ENDORSER_API_SERVER;
|
|
||||||
|
|
||||||
// load all the time I have given
|
|
||||||
try {
|
|
||||||
const url =
|
|
||||||
endorserApiServer +
|
|
||||||
"/api/v2/report/gives?agentId=" +
|
|
||||||
encodeURIComponent(this.identity?.did);
|
|
||||||
const token = await accessToken(this.identity);
|
|
||||||
const headers = {
|
|
||||||
"Content-Type": "application/json",
|
|
||||||
Authorization: "Bearer " + token,
|
|
||||||
};
|
|
||||||
const resp = await this.axios.get(url, { headers });
|
|
||||||
//console.log("Server response", resp.status, resp.data);
|
|
||||||
if (resp.status === 200) {
|
|
||||||
const contactTotals: Record<string, number> = {};
|
|
||||||
for (const give of resp.data.data) {
|
|
||||||
if (give.unit == "HUR") {
|
|
||||||
const recipDid: string = give.recipientDid;
|
|
||||||
const prevAmount = contactTotals[recipDid] || 0;
|
|
||||||
contactTotals[recipDid] = prevAmount + give.amount;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
//console.log("Done retrieving gives", contactTotals);
|
|
||||||
this.givenByMeTotals = contactTotals;
|
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
this.alertTitle = "Error from Server";
|
|
||||||
this.alertMessage = error as string;
|
|
||||||
this.isAlertVisible = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// load all the time I have received
|
|
||||||
try {
|
|
||||||
const url =
|
|
||||||
endorserApiServer +
|
|
||||||
"/api/v2/report/gives?recipientId=" +
|
|
||||||
encodeURIComponent(this.identity.did);
|
|
||||||
const token = await accessToken(this.identity);
|
|
||||||
const headers = {
|
|
||||||
"Content-Type": "application/json",
|
|
||||||
Authorization: "Bearer " + token,
|
|
||||||
};
|
|
||||||
const resp = await this.axios.get(url, { headers });
|
|
||||||
//console.log("Server response", resp.status, resp.data);
|
|
||||||
if (resp.status === 200) {
|
|
||||||
const contactTotals: Record<string, number> = {};
|
|
||||||
for (const give of resp.data.data) {
|
|
||||||
if (give.unit == "HUR") {
|
|
||||||
const prevAmount = contactTotals[give.agentDid] || 0;
|
|
||||||
contactTotals[give.agentDid] = prevAmount + give.amount;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
//console.log("Done retrieving receipts", contactTotals);
|
|
||||||
this.givenToMeTotals = contactTotals;
|
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
this.alertTitle = "Error from Server";
|
|
||||||
this.alertMessage = error as string;
|
|
||||||
this.isAlertVisible = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// from https://stackoverflow.com/a/175787/845494
|
|
||||||
//
|
|
||||||
private isNumeric(str: string): boolean {
|
|
||||||
return !isNaN(+str);
|
|
||||||
}
|
|
||||||
|
|
||||||
private nameForDid(contacts: Array<Contact>, did: string): string {
|
|
||||||
const contact = R.find((con) => con.did == did, contacts);
|
|
||||||
return contact?.name || "this unnamed user";
|
|
||||||
}
|
|
||||||
|
|
||||||
async onClickAddGive(fromDid: string, toDid: string): Promise<void> {
|
|
||||||
if (!this.isNumeric(this.hourInput)) {
|
|
||||||
this.alertTitle = "Input Error";
|
|
||||||
this.alertMessage =
|
|
||||||
"This is not a valid number of hours: " + this.hourInput;
|
|
||||||
this.isAlertVisible = true;
|
|
||||||
} else if (!parseFloat(this.hourInput)) {
|
|
||||||
this.alertTitle = "Input Error";
|
|
||||||
this.alertMessage = "Giving 0 hours does nothing.";
|
|
||||||
this.isAlertVisible = true;
|
|
||||||
} else if (!this.identity) {
|
|
||||||
this.alertTitle = "Status Error";
|
|
||||||
this.alertMessage = "No identity is available.";
|
|
||||||
this.isAlertVisible = true;
|
|
||||||
} else {
|
|
||||||
let toFrom;
|
|
||||||
if (fromDid == this.identity?.did) {
|
|
||||||
toFrom = "from you to " + this.nameForDid(this.contacts, toDid);
|
|
||||||
} else {
|
|
||||||
toFrom = "from " + this.nameForDid(this.contacts, fromDid) + " to you";
|
|
||||||
}
|
|
||||||
if (
|
|
||||||
confirm(
|
|
||||||
"Are you sure you want to record " +
|
|
||||||
this.hourInput +
|
|
||||||
" hours " +
|
|
||||||
toFrom +
|
|
||||||
"?"
|
|
||||||
)
|
|
||||||
) {
|
|
||||||
this.createAndSubmitGive(
|
|
||||||
this.identity,
|
|
||||||
fromDid,
|
|
||||||
toDid,
|
|
||||||
parseFloat(this.hourInput),
|
|
||||||
this.hourDescriptionInput
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private async createAndSubmitGive(
|
|
||||||
identity: IIdentifier,
|
|
||||||
fromDid: string,
|
|
||||||
toDid: string,
|
|
||||||
amount: number,
|
|
||||||
description: string
|
|
||||||
): Promise<void> {
|
|
||||||
// Make a claim
|
|
||||||
const vcClaim: GiveVerifiableCredential = {
|
|
||||||
"@context": "https://schema.org",
|
|
||||||
"@type": "GiveAction",
|
|
||||||
agent: { identifier: fromDid },
|
|
||||||
object: { amountOfThisGood: amount, unitCode: "HUR" },
|
|
||||||
recipient: { identifier: toDid },
|
|
||||||
};
|
|
||||||
if (description) {
|
|
||||||
vcClaim.description = description;
|
|
||||||
}
|
|
||||||
// Make a payload for the claim
|
|
||||||
const vcPayload = {
|
|
||||||
vc: {
|
|
||||||
"@context": ["https://www.w3.org/2018/credentials/v1"],
|
|
||||||
type: ["VerifiableCredential"],
|
|
||||||
credentialSubject: vcClaim,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
// Create a signature using private key of identity
|
|
||||||
if (identity.keys[0].privateKeyHex !== null) {
|
|
||||||
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
||||||
const privateKeyHex: string = identity.keys[0].privateKeyHex!;
|
|
||||||
const signer = await SimpleSigner(privateKeyHex);
|
|
||||||
const alg = undefined;
|
|
||||||
// Create a JWT for the request
|
|
||||||
const vcJwt: string = await didJwt.createJWT(vcPayload, {
|
|
||||||
alg: alg,
|
|
||||||
issuer: identity.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/v2/claim";
|
|
||||||
const token = await accessToken(identity);
|
|
||||||
const headers = {
|
|
||||||
"Content-Type": "application/json",
|
|
||||||
Authorization: "Bearer " + token,
|
|
||||||
};
|
|
||||||
|
|
||||||
try {
|
|
||||||
const resp = await this.axios.post(url, payload, { headers });
|
|
||||||
//console.log("Got resp data:", resp.data);
|
|
||||||
if (resp.data?.success?.handleId) {
|
|
||||||
this.alertTitle = "";
|
|
||||||
this.alertMessage = "";
|
|
||||||
if (fromDid === identity.did) {
|
|
||||||
this.givenByMeTotals[toDid] = this.givenByMeTotals[toDid] + amount;
|
|
||||||
// do this to update the UI (is there a better way?)
|
|
||||||
// eslint-disable-next-line no-self-assign
|
|
||||||
this.givenByMeTotals = this.givenByMeTotals;
|
|
||||||
} else {
|
|
||||||
this.givenToMeTotals[fromDid] =
|
|
||||||
this.givenToMeTotals[fromDid] + amount;
|
|
||||||
// do this to update the UI (is there a better way?)
|
|
||||||
// eslint-disable-next-line no-self-assign
|
|
||||||
this.givenToMeTotals = this.givenToMeTotals;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
let userMessage = "There was an error. See logs for more info.";
|
|
||||||
const serverError = error as AxiosError;
|
|
||||||
if (serverError) {
|
|
||||||
if (serverError.message) {
|
|
||||||
userMessage = serverError.message; // Info for the user
|
|
||||||
} else {
|
|
||||||
userMessage = JSON.stringify(serverError.toJSON());
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
userMessage = error as string;
|
|
||||||
}
|
|
||||||
// Now set that error for the user to see.
|
|
||||||
this.alertTitle = "Error with Server";
|
|
||||||
this.alertMessage = userMessage;
|
|
||||||
this.isAlertVisible = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
alertTitle = "";
|
|
||||||
alertMessage = "";
|
|
||||||
isAlertVisible = false;
|
|
||||||
|
|
||||||
public onClickClose() {
|
|
||||||
this.isAlertVisible = false;
|
|
||||||
this.alertTitle = "";
|
|
||||||
this.alertMessage = "";
|
|
||||||
}
|
|
||||||
|
|
||||||
public computedAlertClassNames() {
|
|
||||||
return {
|
|
||||||
hidden: !this.isAlertVisible,
|
|
||||||
"dismissable-alert": true,
|
|
||||||
"bg-slate-100": true,
|
|
||||||
"p-5": true,
|
|
||||||
rounded: true,
|
|
||||||
"drop-shadow-lg": true,
|
|
||||||
absolute: true,
|
|
||||||
"top-3": true,
|
|
||||||
"inset-x-3": true,
|
|
||||||
"transition-transform": true,
|
|
||||||
"ease-in": true,
|
|
||||||
"duration-300": true,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
@@ -19,17 +19,15 @@
|
|||||||
<!-- Projects -->
|
<!-- Projects -->
|
||||||
<li class="basis-1/5 rounded-md text-slate-500">
|
<li class="basis-1/5 rounded-md text-slate-500">
|
||||||
<router-link
|
<router-link
|
||||||
:to="{ name: 'projects' }"
|
:to="{ name: 'project' }"
|
||||||
class="block text-center py-3 px-1"
|
class="block text-center py-3 px-1"
|
||||||
><fa icon="folder-open" class="fa-fw"></fa
|
><fa icon="folder-open" class="fa-fw"></fa
|
||||||
></router-link>
|
></router-link>
|
||||||
</li>
|
</li>
|
||||||
<!-- Commitments -->
|
<!-- Commitments -->
|
||||||
<li class="basis-1/5 rounded-md text-slate-500">
|
<li class="basis-1/5 rounded-md text-slate-500">
|
||||||
<router-link
|
<router-link :to="{ name: '' }" class="block text-center py-3 px-1"
|
||||||
:to="{ name: 'contacts' }"
|
><fa icon="hand" class="fa-fw"></fa
|
||||||
class="block text-center py-3 px-1"
|
|
||||||
><fa icon="users" class="fa-fw"></fa
|
|
||||||
></router-link>
|
></router-link>
|
||||||
</li>
|
</li>
|
||||||
<!-- Profile -->
|
<!-- Profile -->
|
||||||
|
|||||||
@@ -14,84 +14,42 @@
|
|||||||
</h1>
|
</h1>
|
||||||
</div>
|
</div>
|
||||||
<!-- Import Account Form -->
|
<!-- Import Account Form -->
|
||||||
<p class="text-center text-xl mb-4 font-light">
|
<form>
|
||||||
Enter your seed phrase below to import your identity on this device.
|
<p class="text-center text-xl mb-4 font-light">
|
||||||
</p>
|
Enter your seed phrase below to import your identity on this device.
|
||||||
<input
|
</p>
|
||||||
type="text"
|
<input
|
||||||
placeholder="Seed Phrase"
|
type="text"
|
||||||
class="block w-full rounded border border-slate-400 mb-4 px-3 py-2"
|
placeholder="Seed Phrase"
|
||||||
v-model="mnemonic"
|
class="block w-full rounded border border-slate-400 mb-4 px-3 py-2"
|
||||||
/>
|
/>
|
||||||
{{ mnemonic }}
|
<div class="mt-8">
|
||||||
<div class="mt-8">
|
<input
|
||||||
<button
|
type="submit"
|
||||||
@click="from_mnemonic()"
|
class="block w-full text-center text-lg font-bold uppercase bg-blue-600 text-white px-2 py-3 rounded-md mb-2"
|
||||||
class="block w-full text-center text-lg font-bold uppercase bg-blue-600 text-white px-2 py-3 rounded-md mb-2"
|
value="Import Identity"
|
||||||
>
|
/>
|
||||||
Import
|
<button
|
||||||
</button>
|
@click="onCancelClick()"
|
||||||
<button
|
type="button"
|
||||||
@click="onCancelClick()"
|
class="block w-full text-center text-md uppercase bg-slate-500 text-white px-1.5 py-2 rounded-md"
|
||||||
type="button"
|
>
|
||||||
class="block w-full text-center text-md uppercase bg-slate-500 text-white px-1.5 py-2 rounded-md"
|
Cancel
|
||||||
>
|
</button>
|
||||||
Cancel
|
</div>
|
||||||
</button>
|
</form>
|
||||||
</div>
|
|
||||||
</section>
|
</section>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { Options, Vue } from "vue-class-component";
|
import { Options, Vue } from "vue-class-component";
|
||||||
import { deriveAddress, newIdentifier } from "../libs/crypto";
|
|
||||||
import { db } from "@/db";
|
|
||||||
|
|
||||||
@Options({
|
@Options({
|
||||||
components: {},
|
components: {},
|
||||||
})
|
})
|
||||||
export default class ImportAccountView extends Vue {
|
export default class ImportAccountView extends Vue {
|
||||||
mnemonic = "";
|
|
||||||
address = "";
|
|
||||||
privateHex = "";
|
|
||||||
publicHex = "";
|
|
||||||
derivationPath = "";
|
|
||||||
|
|
||||||
public onCancelClick() {
|
public onCancelClick() {
|
||||||
this.$router.back();
|
this.$router.back();
|
||||||
}
|
}
|
||||||
|
|
||||||
public async from_mnemonic() {
|
|
||||||
const mne: string = this.mnemonic.trim().toLowerCase();
|
|
||||||
if (this.mnemonic.trim().length > 0) {
|
|
||||||
[this.address, this.privateHex, this.publicHex, this.derivationPath] =
|
|
||||||
deriveAddress(mne);
|
|
||||||
|
|
||||||
const newId = newIdentifier(
|
|
||||||
this.address,
|
|
||||||
this.publicHex,
|
|
||||||
this.privateHex,
|
|
||||||
this.derivationPath
|
|
||||||
);
|
|
||||||
|
|
||||||
try {
|
|
||||||
await db.open();
|
|
||||||
const num_accounts = await db.accounts.count();
|
|
||||||
if (num_accounts === 0) {
|
|
||||||
await db.accounts.add({
|
|
||||||
dateCreated: new Date().toISOString(),
|
|
||||||
derivationPath: this.derivationPath,
|
|
||||||
identity: JSON.stringify(newId),
|
|
||||||
mnemonic: mne,
|
|
||||||
publicKeyHex: newId.keys[0].publicKeyHex,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
this.$router.push({ name: "account" });
|
|
||||||
} catch (err) {
|
|
||||||
console.log("Error!");
|
|
||||||
console.log(err);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
@@ -18,20 +18,17 @@
|
|||||||
type="text"
|
type="text"
|
||||||
placeholder="First Name"
|
placeholder="First Name"
|
||||||
class="block w-full rounded border border-slate-400 mb-4 px-3 py-2"
|
class="block w-full rounded border border-slate-400 mb-4 px-3 py-2"
|
||||||
v-model="firstName"
|
|
||||||
/>
|
/>
|
||||||
<input
|
<input
|
||||||
type="text"
|
type="text"
|
||||||
placeholder="Last Name"
|
placeholder="Last Name"
|
||||||
class="block w-full rounded border border-slate-400 mb-4 px-3 py-2"
|
class="block w-full rounded border border-slate-400 mb-4 px-3 py-2"
|
||||||
v-model="lastName"
|
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<div class="mt-8">
|
<div class="mt-8">
|
||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
class="block w-full text-center text-lg font-bold uppercase bg-blue-600 text-white px-2 py-3 rounded-md mb-2"
|
class="block w-full text-center text-lg font-bold uppercase bg-blue-600 text-white px-2 py-3 rounded-md mb-2"
|
||||||
@click="onClickSaveChanges()"
|
|
||||||
>
|
>
|
||||||
Save Changes
|
Save Changes
|
||||||
</button>
|
</button>
|
||||||
@@ -39,7 +36,6 @@
|
|||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
class="block w-full text-center text-md uppercase bg-slate-500 text-white px-1.5 py-2 rounded-md"
|
class="block w-full text-center text-md uppercase bg-slate-500 text-white px-1.5 py-2 rounded-md"
|
||||||
@click="onClickCancel()"
|
|
||||||
>
|
>
|
||||||
Cancel
|
Cancel
|
||||||
</button>
|
</button>
|
||||||
@@ -50,44 +46,9 @@
|
|||||||
|
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { Options, Vue } from "vue-class-component";
|
import { Options, Vue } from "vue-class-component";
|
||||||
import { db } from "@/db";
|
|
||||||
import { MASTER_SETTINGS } from "@/db/tables";
|
|
||||||
|
|
||||||
@Options({
|
@Options({
|
||||||
components: {},
|
components: {},
|
||||||
})
|
})
|
||||||
export default class NewEditAccountView extends Vue {
|
export default class NewEditAccountView extends Vue {}
|
||||||
firstName =
|
|
||||||
localStorage.getItem("firstName") === null
|
|
||||||
? "--"
|
|
||||||
: localStorage.getItem("firstName");
|
|
||||||
lastName =
|
|
||||||
localStorage.getItem("lastName") === null
|
|
||||||
? "--"
|
|
||||||
: localStorage.getItem("lastName");
|
|
||||||
|
|
||||||
// 'created' hook runs when the Vue instance is first created
|
|
||||||
async created() {
|
|
||||||
await db.open();
|
|
||||||
const settings = await db.settings.get(MASTER_SETTINGS);
|
|
||||||
if (settings) {
|
|
||||||
this.firstName = settings.firstName || "";
|
|
||||||
this.lastName = settings.lastName || "";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
onClickSaveChanges() {
|
|
||||||
db.settings.update(MASTER_SETTINGS, {
|
|
||||||
firstName: this.firstName,
|
|
||||||
lastName: this.lastName,
|
|
||||||
});
|
|
||||||
localStorage.setItem("firstName", this.firstName as string);
|
|
||||||
localStorage.setItem("lastName", this.lastName as string);
|
|
||||||
this.$router.push({ name: "account" });
|
|
||||||
}
|
|
||||||
|
|
||||||
onClickCancel() {
|
|
||||||
this.$router.back();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
@@ -10,281 +10,69 @@
|
|||||||
class="text-lg text-center px-2 py-1 absolute -left-2 -top-1"
|
class="text-lg text-center px-2 py-1 absolute -left-2 -top-1"
|
||||||
><fa icon="chevron-left" class="fa-fw"></fa
|
><fa icon="chevron-left" class="fa-fw"></fa
|
||||||
></router-link>
|
></router-link>
|
||||||
[New/Edit] Plan
|
|
||||||
|
[New/Edit] Project
|
||||||
</h1>
|
</h1>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- Project Details -->
|
<!-- Project Details -->
|
||||||
<!-- Image - (see design model) Empty -->
|
<form>
|
||||||
|
<!-- Image - (see design model) Empty -->
|
||||||
|
|
||||||
<div>
|
<!-- Image - Populated -->
|
||||||
{{ errorMessage }}
|
<div class="relative mb-4 rounded-md overflow-hidden">
|
||||||
</div>
|
<div class="absolute top-3 right-3 flex gap-2">
|
||||||
|
<button
|
||||||
|
class="text-md font-bold uppercase bg-blue-600 text-white px-3 py-2 rounded"
|
||||||
|
>
|
||||||
|
<fa icon="pen" class="fa-fw"></fa>
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
class="text-md font-bold uppercase bg-red-600 text-white px-3 py-2 rounded"
|
||||||
|
>
|
||||||
|
<fa icon="trash-can" class="fa-fw"></fa>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
<img src="https://picsum.photos/800/400" class="w-full" />
|
||||||
|
</div>
|
||||||
|
|
||||||
<input
|
<input
|
||||||
type="text"
|
type="text"
|
||||||
placeholder="Project Name"
|
placeholder="Project Name"
|
||||||
class="block w-full rounded border border-slate-400 mb-4 px-3 py-2"
|
class="block w-full rounded border border-slate-400 mb-4 px-3 py-2"
|
||||||
v-model="projectName"
|
/>
|
||||||
/>
|
|
||||||
|
|
||||||
<textarea
|
<textarea
|
||||||
placeholder="Description"
|
placeholder="Description"
|
||||||
class="block w-full rounded border border-slate-400 mb-4 px-3 py-2"
|
class="block w-full rounded border border-slate-400 mb-4 px-3 py-2"
|
||||||
rows="5"
|
rows="5"
|
||||||
v-model="description"
|
></textarea>
|
||||||
maxlength="500"
|
<div class="text-xs text-slate-500 italic -mt-3 mb-4">
|
||||||
></textarea>
|
88/500 max. characters
|
||||||
<div class="text-xs text-slate-500 italic -mt-3 mb-4">
|
</div>
|
||||||
{{ description.length }}/500 max. characters
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="mt-8">
|
<div class="mt-8">
|
||||||
<button
|
<input
|
||||||
:disabled="isHiddenSave"
|
type="submit"
|
||||||
class="block w-full text-center text-lg font-bold uppercase bg-blue-600 text-white px-2 py-3 rounded-md mb-2"
|
class="block w-full text-center text-lg font-bold uppercase bg-blue-600 text-white px-2 py-3 rounded-md mb-2"
|
||||||
@click="onSaveProjectClick()"
|
value="Save Project"
|
||||||
>
|
/>
|
||||||
<!-- SHOW if in idle state -->
|
<button
|
||||||
<span :class="{ hidden: isHiddenSave }">Save Project</span>
|
type="button"
|
||||||
|
class="block w-full text-center text-md uppercase bg-slate-500 text-white px-1.5 py-2 rounded-md"
|
||||||
<!-- SHOW if in saving state; DISABLE button while in saving state -->
|
|
||||||
<span :class="{ hidden: isHiddenSpinner }"
|
|
||||||
><i class="fa-solid fa-spinner fa-spin-pulse"></i>
|
|
||||||
Saving…</span
|
|
||||||
>
|
>
|
||||||
</button>
|
Cancel
|
||||||
<button
|
</button>
|
||||||
type="button"
|
</div>
|
||||||
class="block w-full text-center text-md uppercase bg-slate-500 text-white px-1.5 py-2 rounded-md"
|
</form>
|
||||||
@click="onCancelClick()"
|
|
||||||
>
|
|
||||||
Cancel
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
</section>
|
</section>
|
||||||
<div v-bind:class="computedAlertClassNames()">
|
|
||||||
<button
|
|
||||||
class="close-button bg-slate-200 w-8 leading-loose rounded-full absolute top-2 right-2"
|
|
||||||
@click="onClickClose()"
|
|
||||||
>
|
|
||||||
<fa icon="xmark"></fa>
|
|
||||||
</button>
|
|
||||||
<h4 class="font-bold pr-5">{{ alertTitle }}</h4>
|
|
||||||
<p>{{ alertMessage }}</p>
|
|
||||||
</div>
|
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { Options, Vue } from "vue-class-component";
|
import { Options, Vue } from "vue-class-component";
|
||||||
import { AppString } from "@/constants/app";
|
|
||||||
import { db } from "../db";
|
|
||||||
import { accessToken, SimpleSigner } from "@/libs/crypto";
|
|
||||||
import * as didJwt from "did-jwt";
|
|
||||||
import { IIdentifier } from "@veramo/core";
|
|
||||||
import { useAppStore } from "@/store/app";
|
|
||||||
import { AxiosError } from "axios";
|
|
||||||
|
|
||||||
interface VerifiableCredential {
|
|
||||||
"@context": string;
|
|
||||||
"@type": string;
|
|
||||||
name: string;
|
|
||||||
description: string;
|
|
||||||
identifier?: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Options({
|
@Options({
|
||||||
components: {},
|
components: {},
|
||||||
})
|
})
|
||||||
export default class NewEditProjectView extends Vue {
|
export default class NewEditProjectView extends Vue {}
|
||||||
projectName = "";
|
|
||||||
description = "";
|
|
||||||
errorMessage = "";
|
|
||||||
alertTitle = "";
|
|
||||||
alertMessage = "";
|
|
||||||
|
|
||||||
projectId = localStorage.getItem("projectId") || "";
|
|
||||||
isHiddenSave = false;
|
|
||||||
isHiddenSpinner = true;
|
|
||||||
|
|
||||||
// 'created' hook runs when the Vue instance is first created
|
|
||||||
async created() {
|
|
||||||
if (this.projectId === "") {
|
|
||||||
console.log("This is a new project");
|
|
||||||
} else {
|
|
||||||
await db.open();
|
|
||||||
const num_accounts = await db.accounts.count();
|
|
||||||
if (num_accounts === 0) {
|
|
||||||
console.log("Problem! Should have a profile!");
|
|
||||||
} else {
|
|
||||||
const accounts = await db.accounts.toArray();
|
|
||||||
const identity = JSON.parse(accounts[0].identity);
|
|
||||||
this.LoadProject(identity);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async LoadProject(identity: IIdentifier) {
|
|
||||||
const endorserApiServer = AppString.DEFAULT_ENDORSER_API_SERVER;
|
|
||||||
// eslint-disable-next-line prettier/prettier
|
|
||||||
const url = endorserApiServer + "/api/claim/byHandle/" + encodeURIComponent(this.projectId);
|
|
||||||
const token = await accessToken(identity);
|
|
||||||
const headers = {
|
|
||||||
"Content-Type": "application/json",
|
|
||||||
Authorization: "Bearer " + token,
|
|
||||||
};
|
|
||||||
|
|
||||||
try {
|
|
||||||
const resp = await this.axios.get(url, { headers });
|
|
||||||
console.log(resp.status, resp.data);
|
|
||||||
if (resp.status === 200) {
|
|
||||||
const claim = resp.data.claim;
|
|
||||||
this.projectName = claim.name;
|
|
||||||
this.description = claim.description;
|
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
console.log(error);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private async SaveProject(identity: IIdentifier) {
|
|
||||||
// Make a claim
|
|
||||||
const vcClaim: VerifiableCredential = {
|
|
||||||
"@context": "https://schema.org",
|
|
||||||
"@type": "PlanAction",
|
|
||||||
name: this.projectName,
|
|
||||||
description: this.description,
|
|
||||||
identifier: this.projectId || undefined,
|
|
||||||
};
|
|
||||||
if (this.projectId) {
|
|
||||||
vcClaim.identifier = this.projectId;
|
|
||||||
}
|
|
||||||
// Make a payload for the claim
|
|
||||||
const vcPayload = {
|
|
||||||
sub: "PlanAction",
|
|
||||||
vc: {
|
|
||||||
"@context": ["https://www.w3.org/2018/credentials/v1"],
|
|
||||||
type: ["VerifiableCredential"],
|
|
||||||
credentialSubject: vcClaim,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
// create a signature using private key of identity
|
|
||||||
if (
|
|
||||||
identity.keys[0].privateKeyHex !== "undefined" &&
|
|
||||||
identity.keys[0].privateKeyHex !== null
|
|
||||||
) {
|
|
||||||
// eslint-disable-next-line
|
|
||||||
const privateKeyHex: string = identity.keys[0].privateKeyHex!;
|
|
||||||
const signer = await SimpleSigner(privateKeyHex);
|
|
||||||
const alg = undefined;
|
|
||||||
// create a JWT for the request
|
|
||||||
const vcJwt: string = await didJwt.createJWT(vcPayload, {
|
|
||||||
alg: alg,
|
|
||||||
issuer: identity.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/v2/claim";
|
|
||||||
const token = await accessToken(identity);
|
|
||||||
const headers = {
|
|
||||||
"Content-Type": "application/json",
|
|
||||||
Authorization: "Bearer " + token,
|
|
||||||
};
|
|
||||||
|
|
||||||
try {
|
|
||||||
const resp = await this.axios.post(url, payload, { headers });
|
|
||||||
console.log("Got resp data:", resp.data);
|
|
||||||
// handleId is new in server v release-1.6.0; remove fullIri when that
|
|
||||||
// version shows up here: https://endorser.ch:3000/api-docs/
|
|
||||||
if (resp.data?.success?.handleId || resp.data?.success?.fullIri) {
|
|
||||||
this.errorMessage = "";
|
|
||||||
this.alertTitle = "";
|
|
||||||
this.alertMessage = "";
|
|
||||||
// handleId is new in server v release-1.6.0; remove fullIri when that
|
|
||||||
// version shows up here: https://endorser.ch:3000/api-docs/
|
|
||||||
useAppStore().setProjectId(
|
|
||||||
resp.data.success.handleId || resp.data.success.fullIri
|
|
||||||
);
|
|
||||||
setTimeout(
|
|
||||||
function (that: Vue) {
|
|
||||||
const route = {
|
|
||||||
name: "project",
|
|
||||||
};
|
|
||||||
console.log(route);
|
|
||||||
that.$router.push(route);
|
|
||||||
},
|
|
||||||
2000,
|
|
||||||
this
|
|
||||||
);
|
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
let userMessage = "There was an error. See logs for more info.";
|
|
||||||
const serverError = error as AxiosError;
|
|
||||||
if (serverError) {
|
|
||||||
this.isAlertVisible = true;
|
|
||||||
if (serverError.message) {
|
|
||||||
this.alertTitle = "User Message";
|
|
||||||
userMessage = serverError.message; // This is info for the user.
|
|
||||||
this.alertMessage = userMessage;
|
|
||||||
} else {
|
|
||||||
this.alertTitle = "Server Message";
|
|
||||||
this.alertMessage = JSON.stringify(serverError.toJSON());
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
console.log("Here's the full error trying to save the claim:", error);
|
|
||||||
this.alertTitle = "Claim Error";
|
|
||||||
this.alertMessage = error as string;
|
|
||||||
}
|
|
||||||
// Now set that error for the user to see.
|
|
||||||
this.errorMessage = userMessage;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public onClickClose() {
|
|
||||||
this.isAlertVisible = false;
|
|
||||||
this.alertTitle = "";
|
|
||||||
this.alertMessage = "";
|
|
||||||
}
|
|
||||||
|
|
||||||
public async onSaveProjectClick() {
|
|
||||||
this.isHiddenSave = true;
|
|
||||||
this.isHiddenSpinner = false;
|
|
||||||
await db.open();
|
|
||||||
const num_accounts = await db.accounts.count();
|
|
||||||
if (num_accounts === 0) {
|
|
||||||
console.log("Problem! Should have a profile!");
|
|
||||||
} else {
|
|
||||||
const accounts = await db.accounts.toArray();
|
|
||||||
const identity = JSON.parse(accounts[0].identity);
|
|
||||||
this.SaveProject(identity);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public onCancelClick() {
|
|
||||||
this.$router.back();
|
|
||||||
}
|
|
||||||
|
|
||||||
isAlertVisible = false;
|
|
||||||
public computedAlertClassNames() {
|
|
||||||
return {
|
|
||||||
hidden: !this.isAlertVisible,
|
|
||||||
"dismissable-alert": true,
|
|
||||||
"bg-slate-100": true,
|
|
||||||
"p-5": true,
|
|
||||||
rounded: true,
|
|
||||||
"drop-shadow-lg": true,
|
|
||||||
absolute: true,
|
|
||||||
"top-3": true,
|
|
||||||
"inset-x-3": true,
|
|
||||||
"transition-transform": true,
|
|
||||||
"ease-in": true,
|
|
||||||
"duration-300": true,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
@@ -4,31 +4,27 @@
|
|||||||
<ul class="flex text-2xl p-2 gap-2">
|
<ul class="flex text-2xl p-2 gap-2">
|
||||||
<!-- Home Feed -->
|
<!-- Home Feed -->
|
||||||
<li class="basis-1/5 rounded-md text-slate-500">
|
<li class="basis-1/5 rounded-md text-slate-500">
|
||||||
<router-link :to="{ name: 'home' }" class="block text-center py-3 px-1"
|
<a href="" class="block text-center py-3 px-1"
|
||||||
><fa icon="house-chimney" class="fa-fw"></fa
|
><fa icon="house-chimney" class="fa-fw"></fa
|
||||||
></router-link>
|
></a>
|
||||||
</li>
|
</li>
|
||||||
<!-- Search -->
|
<!-- Search -->
|
||||||
<li class="basis-1/5 rounded-md bg-slate-400 text-white">
|
<li class="basis-1/5 rounded-md text-slate-500">
|
||||||
<router-link
|
<a href="search.html" class="block text-center py-3 px-1"
|
||||||
:to="{ name: 'discover' }"
|
|
||||||
class="block text-center py-3 px-1"
|
|
||||||
><fa icon="magnifying-glass" class="fa-fw"></fa
|
><fa icon="magnifying-glass" class="fa-fw"></fa
|
||||||
></router-link>
|
></a>
|
||||||
</li>
|
</li>
|
||||||
<!-- Projects -->
|
<!-- Projects -->
|
||||||
<li class="basis-1/5 rounded-md text-slate-500">
|
<li class="basis-1/5 rounded-md bg-slate-400 text-white">
|
||||||
<router-link
|
<a href="" class="block text-center py-3 px-1"
|
||||||
:to="{ name: 'projects' }"
|
|
||||||
class="block text-center py-3 px-1"
|
|
||||||
><fa icon="folder-open" class="fa-fw"></fa
|
><fa icon="folder-open" class="fa-fw"></fa
|
||||||
></router-link>
|
></a>
|
||||||
</li>
|
</li>
|
||||||
<!-- Commitments -->
|
<!-- Commitments -->
|
||||||
<li class="basis-1/5 rounded-md text-slate-500">
|
<li class="basis-1/5 rounded-md text-slate-500">
|
||||||
<router-link :to="{ name: '' }" class="block text-center py-3 px-1"
|
<a href="" class="block text-center py-3 px-1"
|
||||||
><fa icon="hand" class="fa-fw"></fa
|
><fa icon="hand" class="fa-fw"></fa
|
||||||
></router-link>
|
></a>
|
||||||
</li>
|
</li>
|
||||||
<!-- Profile -->
|
<!-- Profile -->
|
||||||
<li class="basis-1/5 rounded-md text-slate-500">
|
<li class="basis-1/5 rounded-md text-slate-500">
|
||||||
@@ -60,50 +56,35 @@
|
|||||||
><fa icon="ellipsis-vertical" class="fa-fw"></fa
|
><fa icon="ellipsis-vertical" class="fa-fw"></fa
|
||||||
></a>
|
></a>
|
||||||
|
|
||||||
View Plan
|
View Project
|
||||||
</h1>
|
</h1>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div>
|
|
||||||
{{ errorMessage }}
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<!-- Project Details -->
|
<!-- Project Details -->
|
||||||
<div class="bg-slate-100 rounded-md overflow-hidden px-4 py-3 mb-4">
|
<div class="bg-slate-100 rounded-md overflow-hidden px-4 py-3 mb-4">
|
||||||
|
<!-- Image -->
|
||||||
|
<div class="-mx-4 -mt-3 mb-3">
|
||||||
|
<img src="https://picsum.photos/800/400" class="w-full" />
|
||||||
|
</div>
|
||||||
|
|
||||||
<div>
|
<div>
|
||||||
<h2 class="text-xl font-semibold">{{ name }}</h2>
|
<h2 class="text-xl font-semibold">Canyon cleanup</h2>
|
||||||
<div class="flex justify-between gap-4 text-sm mb-3">
|
<div class="flex justify-between gap-4 text-sm mb-3">
|
||||||
<span><fa icon="user" class="fa-fw text-slate-400"></fa> Rotary</span>
|
<span><fa icon="user" class="fa-fw text-slate-400"></fa> Rotary</span>
|
||||||
<span
|
<span
|
||||||
><fa icon="calendar" class="fa-fw text-slate-400"></fa
|
><fa icon="calendar" class="fa-fw text-slate-400"></fa> 8 days
|
||||||
>{{ timeSince }}
|
ago</span
|
||||||
</span>
|
>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="text-sm text-slate-500">
|
<div class="text-sm text-slate-500">
|
||||||
<div v-if="!expanded">
|
Sed ut perspiciatis unde omnis iste natus error sit voluptatem
|
||||||
{{ truncatedDesc }}
|
accusantium doloremque laudantium…
|
||||||
<a v-if="description.length >= truncateLength" @click="expandText"
|
<a href="" class="uppercase text-xs font-semibold text-slate-700"
|
||||||
>Read More</a
|
>Read More</a
|
||||||
>
|
>
|
||||||
</div>
|
|
||||||
<div v-else>
|
|
||||||
{{ description }}
|
|
||||||
<a
|
|
||||||
@click="collapseText"
|
|
||||||
class="uppercase text-xs font-semibold text-slate-700"
|
|
||||||
>Read Less</a
|
|
||||||
>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<button
|
|
||||||
type="button"
|
|
||||||
class="block w-full text-center text-md uppercase bg-slate-500 text-white px-1.5 py-2 rounded-md"
|
|
||||||
@click="onEditClick()"
|
|
||||||
>
|
|
||||||
Edit
|
|
||||||
</button>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- Commit -->
|
<!-- Commit -->
|
||||||
@@ -145,94 +126,9 @@
|
|||||||
|
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { Options, Vue } from "vue-class-component";
|
import { Options, Vue } from "vue-class-component";
|
||||||
import { accessToken } from "@/libs/crypto";
|
|
||||||
import { db } from "../db";
|
|
||||||
import { IIdentifier } from "@veramo/core";
|
|
||||||
import { AppString } from "@/constants/app";
|
|
||||||
import * as moment from "moment";
|
|
||||||
import { AxiosError } from "axios";
|
|
||||||
|
|
||||||
@Options({
|
@Options({
|
||||||
components: {},
|
components: {},
|
||||||
})
|
})
|
||||||
export default class ProjectViewView extends Vue {
|
export default class ProjectViewView extends Vue {}
|
||||||
expanded = false;
|
|
||||||
name = "";
|
|
||||||
description = "";
|
|
||||||
truncatedDesc = "";
|
|
||||||
truncateLength = 40;
|
|
||||||
timeSince = "";
|
|
||||||
projectId = localStorage.getItem("projectId") || "";
|
|
||||||
errorMessage = "";
|
|
||||||
|
|
||||||
onEditClick() {
|
|
||||||
localStorage.setItem("projectId", this.projectId as string);
|
|
||||||
const route = {
|
|
||||||
name: "new-edit-project",
|
|
||||||
};
|
|
||||||
console.log(route);
|
|
||||||
this.$router.push(route);
|
|
||||||
}
|
|
||||||
|
|
||||||
expandText() {
|
|
||||||
this.expanded = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
collapseText() {
|
|
||||||
this.expanded = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
async LoadProject(identity: IIdentifier) {
|
|
||||||
const endorserApiServer = AppString.DEFAULT_ENDORSER_API_SERVER;
|
|
||||||
// eslint-disable-next-line prettier/prettier
|
|
||||||
const url = endorserApiServer + "/api/claim/byHandle/" + encodeURIComponent(this.projectId);
|
|
||||||
const token = await accessToken(identity);
|
|
||||||
const headers = {
|
|
||||||
"Content-Type": "application/json",
|
|
||||||
Authorization: "Bearer " + token,
|
|
||||||
};
|
|
||||||
|
|
||||||
try {
|
|
||||||
const resp = await this.axios.get(url, { headers });
|
|
||||||
console.log("resp.status, resp.data", resp.status, resp.data);
|
|
||||||
if (resp.status === 200) {
|
|
||||||
const startTime = resp.data.startTime;
|
|
||||||
if (startTime != null) {
|
|
||||||
const eventDate = new Date(startTime);
|
|
||||||
const now = moment.now();
|
|
||||||
this.timeSince = moment.utc(now).to(eventDate);
|
|
||||||
}
|
|
||||||
this.name = resp.data.claim?.name || "(no name)";
|
|
||||||
this.description = resp.data.claim?.description || "(no description)";
|
|
||||||
this.truncatedDesc = this.description.slice(0, this.truncateLength);
|
|
||||||
} else if (resp.status === 404) {
|
|
||||||
// actually, axios throws an error so we never get here
|
|
||||||
this.errorMessage = "That project does not exist.";
|
|
||||||
}
|
|
||||||
} catch (error: unknown) {
|
|
||||||
const serverError = error as AxiosError;
|
|
||||||
if (serverError.response?.status === 404) {
|
|
||||||
this.errorMessage = "That project does not exist.";
|
|
||||||
} else {
|
|
||||||
this.errorMessage =
|
|
||||||
"Something went wrong retrieving that project." +
|
|
||||||
" See logs for more info.";
|
|
||||||
console.log("Error retrieving project:", error);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 'created' hook runs when the Vue instance is first created
|
|
||||||
async created() {
|
|
||||||
await db.open();
|
|
||||||
const num_accounts = await db.accounts.count();
|
|
||||||
if (num_accounts === 0) {
|
|
||||||
console.log("Problem! Should have a profile!");
|
|
||||||
} else {
|
|
||||||
const accounts = await db.accounts.toArray();
|
|
||||||
const identity = JSON.parse(accounts[0].identity);
|
|
||||||
this.LoadProject(identity);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
@@ -1,178 +1,3 @@
|
|||||||
<template>
|
<template>
|
||||||
<!-- QUICK NAV -->
|
<section id="Content" class="p-6 pb-24"></section>
|
||||||
<nav id="QuickNav" class="fixed bottom-0 left-0 right-0 bg-slate-200">
|
|
||||||
<ul class="flex text-2xl p-2 gap-2">
|
|
||||||
<!-- Home Feed -->
|
|
||||||
<li class="basis-1/5 rounded-md text-slate-500">
|
|
||||||
<router-link :to="{ name: 'home' }" class="block text-center py-3 px-1"
|
|
||||||
><fa icon="house-chimney" class="fa-fw"></fa
|
|
||||||
></router-link>
|
|
||||||
</li>
|
|
||||||
<!-- Search -->
|
|
||||||
<li class="basis-1/5 rounded-md bg-slate-400 text-white">
|
|
||||||
<router-link
|
|
||||||
:to="{ name: 'discover' }"
|
|
||||||
class="block text-center py-3 px-1"
|
|
||||||
><fa icon="magnifying-glass" class="fa-fw"></fa
|
|
||||||
></router-link>
|
|
||||||
</li>
|
|
||||||
<!-- Projects -->
|
|
||||||
<li class="basis-1/5 rounded-md text-slate-500">
|
|
||||||
<router-link
|
|
||||||
:to="{ name: 'projects' }"
|
|
||||||
class="block text-center py-3 px-1"
|
|
||||||
><fa icon="folder-open" class="fa-fw"></fa
|
|
||||||
></router-link>
|
|
||||||
</li>
|
|
||||||
<!-- Commitments -->
|
|
||||||
<li class="basis-1/5 rounded-md text-slate-500">
|
|
||||||
<router-link
|
|
||||||
:to="{ name: 'contacts' }"
|
|
||||||
class="block text-center py-3 px-1"
|
|
||||||
><fa icon="users" class="fa-fw"></fa
|
|
||||||
></router-link>
|
|
||||||
</li>
|
|
||||||
<!-- Profile -->
|
|
||||||
<li class="basis-1/5 rounded-md text-slate-500">
|
|
||||||
<router-link
|
|
||||||
:to="{ name: 'account' }"
|
|
||||||
class="block text-center py-3 px-1"
|
|
||||||
><fa icon="circle-user" class="fa-fw"></fa
|
|
||||||
></router-link>
|
|
||||||
</li>
|
|
||||||
</ul>
|
|
||||||
</nav>
|
|
||||||
<section id="Content" class="p-6 pb-24">
|
|
||||||
<!-- Heading -->
|
|
||||||
<h1 id="ViewHeading" class="text-4xl text-center font-light pt-4 mb-8">
|
|
||||||
My Plans
|
|
||||||
</h1>
|
|
||||||
|
|
||||||
<!-- Quick Search -->
|
|
||||||
<form id="QuickSearch" class="mb-4 flex">
|
|
||||||
<input
|
|
||||||
type="text"
|
|
||||||
placeholder="Search…"
|
|
||||||
class="block w-full rounded-l border border-r-0 border-slate-400 px-3 py-2"
|
|
||||||
/>
|
|
||||||
<button
|
|
||||||
class="px-4 rounded-r bg-slate-200 border border-l-0 border-slate-400"
|
|
||||||
>
|
|
||||||
<fa icon="magnifying-glass" class="fa-fw"></fa>
|
|
||||||
</button>
|
|
||||||
</form>
|
|
||||||
|
|
||||||
<!-- New Project -->
|
|
||||||
<button
|
|
||||||
class="fixed right-6 bottom-24 text-center text-4xl leading-none bg-blue-600 text-white w-14 py-2.5 rounded-full"
|
|
||||||
@click="onClickNewProject()"
|
|
||||||
>
|
|
||||||
<fa icon="plus" class="fa-fw"></fa>
|
|
||||||
</button>
|
|
||||||
|
|
||||||
<!-- Results List -->
|
|
||||||
<ul class="">
|
|
||||||
<li
|
|
||||||
class="border-b border-slate-300"
|
|
||||||
v-for="project in projects"
|
|
||||||
:key="project.handleId"
|
|
||||||
>
|
|
||||||
<a
|
|
||||||
@click="onClickLoadProject(project.handleId)"
|
|
||||||
class="block py-4 flex gap-4"
|
|
||||||
>
|
|
||||||
<div class="flex-none w-12">
|
|
||||||
<img
|
|
||||||
src="https://picsum.photos/200/200?random=1"
|
|
||||||
class="w-full rounded"
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="grow overflow-hidden">
|
|
||||||
<h2 class="text-base font-semibold">{{ project.name }}</h2>
|
|
||||||
<div class="text-sm truncate">
|
|
||||||
{{ project.description }}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</a>
|
|
||||||
</li>
|
|
||||||
</ul>
|
|
||||||
</section>
|
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script lang="ts">
|
|
||||||
import { Options, Vue } from "vue-class-component";
|
|
||||||
import { accessToken } from "@/libs/crypto";
|
|
||||||
import { db } from "../db";
|
|
||||||
import { IIdentifier } from "@veramo/core";
|
|
||||||
import { AppString } from "@/constants/app";
|
|
||||||
|
|
||||||
@Options({
|
|
||||||
components: {},
|
|
||||||
})
|
|
||||||
export default class ProjectsView extends Vue {
|
|
||||||
projects: { handleId: string; name: string; description: string }[] = [];
|
|
||||||
|
|
||||||
onClickLoadProject(id: string) {
|
|
||||||
console.log("projectId", id);
|
|
||||||
localStorage.setItem("projectId", id);
|
|
||||||
const route = {
|
|
||||||
name: "project",
|
|
||||||
};
|
|
||||||
console.log(route);
|
|
||||||
this.$router.push(route);
|
|
||||||
}
|
|
||||||
|
|
||||||
async LoadProjects(identity: IIdentifier) {
|
|
||||||
const endorserApiServer = AppString.DEFAULT_ENDORSER_API_SERVER;
|
|
||||||
const url = endorserApiServer + "/api/v2/report/plansByIssuer";
|
|
||||||
const token = await accessToken(identity);
|
|
||||||
const headers = {
|
|
||||||
"Content-Type": "application/json",
|
|
||||||
Authorization: "Bearer " + token,
|
|
||||||
};
|
|
||||||
|
|
||||||
try {
|
|
||||||
const resp = await this.axios.get(url, { headers });
|
|
||||||
if (resp.status === 200) {
|
|
||||||
const plans = resp.data.data;
|
|
||||||
for (let i = 0; i < plans.length; i++) {
|
|
||||||
const plan = plans[i];
|
|
||||||
const data = {
|
|
||||||
name: plan.name,
|
|
||||||
description: plan.description,
|
|
||||||
// handleId is new in server v release-1.6.0; remove fullIri when that
|
|
||||||
// version shows up here: https://endorser.ch:3000/api-docs/
|
|
||||||
handleId: plan.handleId || plan.fullIri,
|
|
||||||
};
|
|
||||||
this.projects.push(data);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
console.log(error);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 'created' hook runs when the Vue instance is first created
|
|
||||||
async created() {
|
|
||||||
await db.open();
|
|
||||||
const num_accounts = await db.accounts.count();
|
|
||||||
if (num_accounts === 0) {
|
|
||||||
console.log("Problem! Should have a profile!");
|
|
||||||
} else {
|
|
||||||
const accounts = await db.accounts.toArray();
|
|
||||||
const identity = JSON.parse(accounts[0].identity);
|
|
||||||
this.LoadProjects(identity);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
onClickNewProject(): void {
|
|
||||||
localStorage.removeItem("projectId");
|
|
||||||
const route = {
|
|
||||||
name: "new-edit-project",
|
|
||||||
};
|
|
||||||
console.log(route);
|
|
||||||
this.$router.push(route);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
|
|||||||
Reference in New Issue
Block a user