From 13425d2eb248bef382e8741ef5d6f7b27408698a Mon Sep 17 00:00:00 2001 From: SondreB Date: Sun, 8 Oct 2023 22:10:01 +0200 Subject: [PATCH] Add full support for did.request using regular links --- angular/src/app/services/frontend.service.ts | 19 +++++++++++++++++-- .../src/app/services/secure-state.service.ts | 4 +++- angular/src/manifest/blockcore/manifest.json | 2 +- .../manifest/blockcore/manifest.webmanifest | 2 +- angular/src/manifest/coinvault/manifest.json | 2 +- .../manifest/coinvault/manifest.webmanifest | 2 +- angular/src/manifest/freecity/manifest.json | 2 +- .../manifest/freecity/manifest.webmanifest | 2 +- angular/src/shared/background-manager.ts | 4 ++-- .../shared/handlers/did-request-handler.ts | 5 ++--- angular/src/shared/shared-manager.ts | 16 +++++++++++----- package-lock.json | 4 ++-- package.json | 2 +- 13 files changed, 44 insertions(+), 22 deletions(-) diff --git a/angular/src/app/services/frontend.service.ts b/angular/src/app/services/frontend.service.ts index 86f78844..1f1a835d 100644 --- a/angular/src/app/services/frontend.service.ts +++ b/angular/src/app/services/frontend.service.ts @@ -10,6 +10,8 @@ import { SettingsService } from './settings.service'; import { StateService } from './state.service'; import { WalletManager } from './wallet-manager'; import { DOCUMENT } from '@angular/common'; +import { DidRequestHandler } from 'src/shared/handlers/did-request-handler'; +import { SecureStateService } from './secure-state.service'; @Injectable({ providedIn: 'root', @@ -29,6 +31,7 @@ export class FrontendService implements OnInit { private router: Router, private state: StateService, private settings: SettingsService, + private secure: SecureStateService, private message: MessageService, private sharedManager: SharedManager, private dwn: DecentralizedWebNode @@ -81,10 +84,22 @@ export class FrontendService implements OnInit { return 'ok'; } case 'did.request': { - debugger; const msg = message as any; + const handler = new DidRequestHandler(this.networkManager); + + const state: any = { + content: msg.request.params[0].challenge, + message: { + app: msg.app + } + } + + const result = await handler.execute(state, msg, this.secure); + let payload = JSON.stringify(result.response); + let url = msg.request.params[0].callback; - url = url.replace('%s', msg.key); // This is the DID. + url = url.replace('%s', payload); + this.document.location.href = url; return 'ok'; } diff --git a/angular/src/app/services/secure-state.service.ts b/angular/src/app/services/secure-state.service.ts index c060037e..6d705de3 100644 --- a/angular/src/app/services/secure-state.service.ts +++ b/angular/src/app/services/secure-state.service.ts @@ -12,7 +12,9 @@ export class SecureStateService { // The background.ts is responsible for clearing the secure state when timeout is reached. /** Contains the master seed for unlocked wallets. This object should never be persisted and only exists in memory. */ - private keys: Map = new Map(); + + // Made public to support a minor hack for frontend service. + public keys: Map = new Map(); unlockedWalletsSubject: BehaviorSubject = new BehaviorSubject([]); diff --git a/angular/src/manifest/blockcore/manifest.json b/angular/src/manifest/blockcore/manifest.json index be666265..cfeb157b 100644 --- a/angular/src/manifest/blockcore/manifest.json +++ b/angular/src/manifest/blockcore/manifest.json @@ -1,6 +1,6 @@ { "name": "Blockcore Wallet", - "version": "1.0.33", + "version": "1.0.34", "manifest_version": 3, "description": "Non-Custodial wallet for Coins, Tokens, Identities, NFTs and more.", "author": "Blockcore", diff --git a/angular/src/manifest/blockcore/manifest.webmanifest b/angular/src/manifest/blockcore/manifest.webmanifest index 55140363..9ac8cfa7 100644 --- a/angular/src/manifest/blockcore/manifest.webmanifest +++ b/angular/src/manifest/blockcore/manifest.webmanifest @@ -4,7 +4,7 @@ "start_url": "./", "name": "Blockcore Wallet", "short_name": "Blockcore", - "version": "1.0.33", + "version": "1.0.34", "author": "Blockcore", "display": "standalone", "theme_color": "#22a893", diff --git a/angular/src/manifest/coinvault/manifest.json b/angular/src/manifest/coinvault/manifest.json index aa225cff..d17bce65 100644 --- a/angular/src/manifest/coinvault/manifest.json +++ b/angular/src/manifest/coinvault/manifest.json @@ -1,6 +1,6 @@ { "name": "CoinVault", - "version": "1.0.33", + "version": "1.0.34", "manifest_version": 3, "description": "Non-Custodial wallet for Stratis, Cirrus, NFTs and more.", "author": "Softchains Ltd", diff --git a/angular/src/manifest/coinvault/manifest.webmanifest b/angular/src/manifest/coinvault/manifest.webmanifest index 81a3a873..d9872123 100644 --- a/angular/src/manifest/coinvault/manifest.webmanifest +++ b/angular/src/manifest/coinvault/manifest.webmanifest @@ -4,7 +4,7 @@ "start_url": "./", "name": "CoinVault", "short_name": "CoinVault", - "version": "1.0.33", + "version": "1.0.34", "author": "Softchains Ltd", "display": "standalone", "theme_color": "#206997", diff --git a/angular/src/manifest/freecity/manifest.json b/angular/src/manifest/freecity/manifest.json index ab8a321b..c30e82e6 100644 --- a/angular/src/manifest/freecity/manifest.json +++ b/angular/src/manifest/freecity/manifest.json @@ -1,6 +1,6 @@ { "name": "Free City Wallet", - "version": "1.0.33", + "version": "1.0.34", "manifest_version": 3, "description": "Manage your citizenship, identity, properties, social network and more.", "author": "City Chain Foundation", diff --git a/angular/src/manifest/freecity/manifest.webmanifest b/angular/src/manifest/freecity/manifest.webmanifest index cc0becce..02beab92 100644 --- a/angular/src/manifest/freecity/manifest.webmanifest +++ b/angular/src/manifest/freecity/manifest.webmanifest @@ -4,7 +4,7 @@ "start_url": "./", "name": "Free City Wallet", "short_name": "FreeCityWallet", - "version": "1.0.33", + "version": "1.0.34", "author": "City Chain Foundation", "display": "standalone", "theme_color": "#DFAB3C", diff --git a/angular/src/shared/background-manager.ts b/angular/src/shared/background-manager.ts index f80c8dae..2c34705f 100644 --- a/angular/src/shared/background-manager.ts +++ b/angular/src/shared/background-manager.ts @@ -150,8 +150,8 @@ export class BackgroundManager { return true; } - async getKey(walletId: string, accountId: string, keyId: string) { - await this.sharedManager.loadPrivateKeys(); + async getKey(walletId: string, accountId: string, keyId: string, secure: any = null) { + await this.sharedManager.loadPrivateKeys(secure); // Get the secret seed. const masterSeedBase64 = this.sharedManager.getPrivateKey(walletId); diff --git a/angular/src/shared/handlers/did-request-handler.ts b/angular/src/shared/handlers/did-request-handler.ts index 4f88ad08..45f76c82 100644 --- a/angular/src/shared/handlers/did-request-handler.ts +++ b/angular/src/shared/handlers/did-request-handler.ts @@ -25,9 +25,9 @@ export class DidRequestHandler implements ActionHandler { }; } - async execute(state: ActionState, permission: Permission): Promise { + async execute(state: ActionState, permission: Permission, secure: any = null): Promise { // Get the private key - const { network, node } = await this.backgroundManager.getKey(permission.walletId, permission.accountId, permission.keyId); + const { network, node } = await this.backgroundManager.getKey(permission.walletId, permission.accountId, permission.keyId, secure); if (state.content) { let contentText = state.content; @@ -47,7 +47,6 @@ export class DidRequestHandler implements ActionHandler { // "jws" or "jwt"? // const didDocument = identity.document(); - const jws = await createJWS(proofContent, tools.getSigner(privateKey), { kid: `${identity.did}${verificationMethod.id}` }); let returnData: ActionResponse = { diff --git a/angular/src/shared/shared-manager.ts b/angular/src/shared/shared-manager.ts index 5798744e..cb1e458f 100644 --- a/angular/src/shared/shared-manager.ts +++ b/angular/src/shared/shared-manager.ts @@ -37,13 +37,19 @@ export class SharedManager { return this.allNetworks.find((w) => w.id == networkType); } - async loadPrivateKeys() { - let keys = await this.storage.get('keys', false); + // Secure can be supplied to load the keys from secure storage instead of storage service. + async loadPrivateKeys(secure: any = null) { + if (secure) { + this.keys = secure.keys; - if (keys != null && Object.keys(keys).length > 0) { - this.keys = new Map(Object.entries(keys)); } else { - this.keys = new Map(); + let keys = await this.storage.get('keys', false); + + if (keys != null && Object.keys(keys).length > 0) { + this.keys = new Map(Object.entries(keys)); + } else { + this.keys = new Map(); + } } } diff --git a/package-lock.json b/package-lock.json index 8fb1d342..44556477 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "blockcore-wallet", - "version": "1.0.33", + "version": "1.0.34", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "blockcore-wallet", - "version": "1.0.33", + "version": "1.0.34", "dependencies": { "@angular/animations": "14.2.1", "@angular/cdk": "14.2.1", diff --git a/package.json b/package.json index 7a005a7f..126cbaa1 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "blockcore-wallet", - "version": "1.0.33", + "version": "1.0.34", "description": "An Non-Custodial HD wallet in your browser for Coins, Tokens, Identities, NFTs and more", "scripts": { "version": "node -p \"require('./package.json').version\"",