Skip to content

Commit

Permalink
Add full support for did.request using regular links
Browse files Browse the repository at this point in the history
  • Loading branch information
sondreb committed Oct 8, 2023
1 parent f1f73d5 commit 13425d2
Show file tree
Hide file tree
Showing 13 changed files with 44 additions and 22 deletions.
19 changes: 17 additions & 2 deletions angular/src/app/services/frontend.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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
Expand Down Expand Up @@ -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';
}
Expand Down
4 changes: 3 additions & 1 deletion angular/src/app/services/secure-state.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, string> = new Map<string, string>();

// Made public to support a minor hack for frontend service.
public keys: Map<string, string> = new Map<string, string>();

unlockedWalletsSubject: BehaviorSubject<string[]> = new BehaviorSubject<string[]>([]);

Expand Down
2 changes: 1 addition & 1 deletion angular/src/manifest/blockcore/manifest.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
2 changes: 1 addition & 1 deletion angular/src/manifest/blockcore/manifest.webmanifest
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion angular/src/manifest/coinvault/manifest.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
2 changes: 1 addition & 1 deletion angular/src/manifest/coinvault/manifest.webmanifest
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion angular/src/manifest/freecity/manifest.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
2 changes: 1 addition & 1 deletion angular/src/manifest/freecity/manifest.webmanifest
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
4 changes: 2 additions & 2 deletions angular/src/shared/background-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
5 changes: 2 additions & 3 deletions angular/src/shared/handlers/did-request-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ export class DidRequestHandler implements ActionHandler {
};
}

async execute(state: ActionState, permission: Permission): Promise<ActionResponse> {
async execute(state: ActionState, permission: Permission, secure: any = null): Promise<ActionResponse> {
// 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;
Expand All @@ -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 = {
Expand Down
16 changes: 11 additions & 5 deletions angular/src/shared/shared-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, string>(Object.entries(keys));
} else {
this.keys = new Map<string, string>();
let keys = await this.storage.get('keys', false);

if (keys != null && Object.keys(keys).length > 0) {
this.keys = new Map<string, string>(Object.entries(keys));
} else {
this.keys = new Map<string, string>();
}
}
}

Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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\"",
Expand Down

0 comments on commit 13425d2

Please sign in to comment.