Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update web sdk and fix related TODOS #362

Merged
merged 9 commits into from
Aug 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/add-example-Web3Id/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@
"start": "live-server ./index.html --mount=/sdk.js:../../node_modules/@concordium/web-sdk/lib/concordium.min.js --mount=/helpers.js:../../packages/browser-wallet-api-helpers/lib/concordiumHelpers.min.js"
},
"dependencies": {
"@concordium/web-sdk": "^6.1.0-alpha.1"
"@concordium/web-sdk": "^6.1.1"
}
}
2 changes: 1 addition & 1 deletion examples/eSealing/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"license": "Apache-2.0",
"dependencies": {
"@concordium/react-components": "^0.2.0",
"@concordium/web-sdk": "^6.1.0-alpha.1",
"@concordium/web-sdk": "^6.1.1",
"@thi.ng/leb128": "^2.1.18",
"@types/sha256": "^0.2.0",
"@walletconnect/types": "^2.1.4",
Expand Down
2 changes: 1 addition & 1 deletion examples/nft-minting/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"packageManager": "[email protected]",
"dependencies": {
"@concordium/browser-wallet-api-helpers": "workspace:^",
"@concordium/web-sdk": "^6.1.0-alpha.1",
"@concordium/web-sdk": "^6.1.1",
"cors": "^2.8.5",
"express": "^4.18.1",
"express-fileupload": "^1.4.0",
Expand Down
2 changes: 1 addition & 1 deletion examples/piggybank/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"packageManager": "[email protected]",
"dependencies": {
"@concordium/browser-wallet-api-helpers": "workspace:^",
"@concordium/web-sdk": "^6.1.0-alpha.1",
"@concordium/web-sdk": "^6.1.1",
"react": "^18.1.0",
"react-dom": "^18.1.0"
},
Expand Down
2 changes: 1 addition & 1 deletion examples/two-step-transfer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@
"start": "live-server ../two-step-transfer/index.html --mount=/sdk.js:../../node_modules/@concordium/web-sdk/lib/concordium.min.js --mount=/helpers.js:../../packages/browser-wallet-api-helpers/lib/concordiumHelpers.min.js"
},
"dependencies": {
"@concordium/web-sdk": "^6.1.0-alpha.1"
"@concordium/web-sdk": "^6.1.1"
}
}
2 changes: 1 addition & 1 deletion examples/voting/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"packageManager": "[email protected]",
"dependencies": {
"@concordium/browser-wallet-api-helpers": "^2.0.0",
"@concordium/web-sdk": "^6.1.0-alpha.1",
"@concordium/web-sdk": "^6.1.1",
"bootstrap": "^5.2.1",
"cross-env": "^7.0.3",
"moment": "^2.29.4",
Expand Down
2 changes: 1 addition & 1 deletion examples/wCCD/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"license": "Apache-2.0",
"dependencies": {
"@concordium/react-components": "^0.2.0",
"@concordium/web-sdk": "^6.1.0-alpha.1",
"@concordium/web-sdk": "^6.1.1",
"@thi.ng/leb128": "^2.1.18",
"@walletconnect/types": "^2.1.4",
"mathjs": "^11.4.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/browser-wallet-api-helpers/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"url": "https://concordium.com"
},
"dependencies": {
"@concordium/web-sdk": "^6.1.0-alpha.1"
"@concordium/web-sdk": "^6.1.1"
},
"devDependencies": {
"@babel/core": "^7.17.10",
Expand Down
2 changes: 1 addition & 1 deletion packages/browser-wallet-api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"license": "Apache-2.0",
"dependencies": {
"@concordium/browser-wallet-api-helpers": "workspace:^",
"@concordium/common-sdk": "^9.1.0-alpha.1",
"@concordium/common-sdk": "^9.1.1",
"@protobuf-ts/grpcweb-transport": "^2.8.2",
"@protobuf-ts/runtime-rpc": "^2.8.2",
"buffer": "^6.0.3",
Expand Down
3 changes: 2 additions & 1 deletion packages/browser-wallet-api/src/wallet-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ import {
import EventEmitter from 'events';
import type { JsonRpcRequest } from '@concordium/common-sdk/lib/providers/provider';
import { IdProofOutput, IdStatement } from '@concordium/common-sdk/lib/idProofTypes';
import { CredentialStatements, VerifiablePresentation } from '@concordium/common-sdk/lib/web3ProofTypes';
import { CredentialStatements } from '@concordium/common-sdk/lib/web3ProofTypes';
import { VerifiablePresentation } from '@concordium/common-sdk/lib/types/VerifiablePresentation';
import { ConcordiumGRPCClient } from '@concordium/common-sdk/lib/GRPCClient';
import JSONBig from 'json-bigint';
import { stringify } from './util';
Expand Down
3 changes: 2 additions & 1 deletion packages/browser-wallet/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Changelog

## Unreleased
## 1.1.3

### Changed

Expand All @@ -11,6 +11,7 @@
- An issue where the import window would fail to open.
- Updated the JSON schema for the verifiable credential schema validation, so that invalid schemas are rejected.
- An issue where a verifiable with the `NotActivated` status would show as `Pending`.
- Enable validation of veriable presentation requests before opening the popup window.
- An issue that allowed empty credential statements to be accepted by the wallet-api.
- An issue where the wallet allowed for requests adding credentials with more attributes than listed in the schema.

Expand Down
4 changes: 2 additions & 2 deletions packages/browser-wallet/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@concordium/browser-wallet",
"version": "1.1.2",
"version": "1.1.3",
"description": "Browser extension wallet for the Concordium blockchain",
"author": "Concordium Software",
"license": "Apache-2.0",
Expand All @@ -19,7 +19,7 @@
"dependencies": {
"@concordium/browser-wallet-api": "workspace:^",
"@concordium/browser-wallet-api-helpers": "workspace:^",
"@concordium/web-sdk": "^6.1.0-alpha.1",
"@concordium/web-sdk": "^6.1.1",
"@noble/ed25519": "^1.7.0",
"@protobuf-ts/runtime-rpc": "^2.8.2",
"@scure/bip39": "^1.1.0",
Expand Down
12 changes: 9 additions & 3 deletions packages/browser-wallet/src/background/web3Id.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ import {
createConcordiumClient,
verifyWeb3IdCredentialSignature,
isHex,
verifyAtomicStatements,
isAccountCredentialStatement,
IDENTITY_SUBJECT_SCHEMA,
} from '@concordium/web-sdk';
import {
sessionVerifiableCredentials,
Expand Down Expand Up @@ -172,9 +175,12 @@ export const runIfValidWeb3IdProof: RunCondition<MessageStatusWrapper<undefined>
}
try {
const statements: CredentialStatements = parse(msg.payload.statements);
// TODO Enable when SDK is updated
// // If a statement does not verify, an error is thrown.
// statements.every((credStatement) => verifyAtomicStatements(credStatement.statement));
// If a statement does not verify, an error is thrown.
statements.every((credStatement) =>
isAccountCredentialStatement(credStatement)
? verifyAtomicStatements(credStatement.statement, IDENTITY_SUBJECT_SCHEMA)
: verifyAtomicStatements(credStatement.statement)
);

const noEmptyQualifier = statements.every((credStatement) => credStatement.idQualifier.issuers.length > 0);
if (!noEmptyQualifier) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ export default function AddWeb3IdCredential({ onAllow, onReject }: Props) {
return credentialSubjectId;
}

if (web3IdCredentials.loading || storedWeb3IdCredentials.loading || !validationComplete) {
if (web3IdCredentials.loading || storedWeb3IdCredentials.loading || (!validationComplete && !error)) {
return null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { ClassName } from 'wallet-common-helpers';
import clsx from 'clsx';
import { VerifiableCredentialMetadata } from '@shared/utils/verifiable-credential-helpers';
import Img from '@popup/shared/Img';
import { CredentialSubject } from '@concordium/web-sdk';
import { AttributeType, CredentialSubject } from '@concordium/web-sdk';
import { VerifiableCredentialStatus, MetadataUrl, VerifiableCredentialSchema } from '@shared/storage/types';
import StatusIcon from './VerifiableCredentialStatus';

Expand All @@ -28,7 +28,7 @@ export function DisplayAttribute({
attributeTitle,
}: {
attributeKey: string;
attributeValue: string | bigint;
attributeValue: AttributeType;
attributeTitle: string;
}) {
return (
Expand Down Expand Up @@ -82,8 +82,8 @@ function ClickableVerifiableCredential({ children, onClick, metadata, className
function applySchemaAndLocalization(
schema: VerifiableCredentialSchema,
localization?: Record<string, string>
): (value: [string, string | bigint]) => { title: string; key: string; value: string | bigint } {
return (value: [string, string | bigint]) => {
): (value: [string, AttributeType]) => { title: string; key: string; value: AttributeType } {
return (value: [string, AttributeType]) => {
const attributeSchema = schema.properties.credentialSubject.properties.attributes.properties[value[0]];
if (!attributeSchema) {
throw new Error(`Missing attribute schema for key: ${value[0]}`);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,11 @@ import {
RevealStatementV2,
StatementTypes,
VerifiableCredentialStatement,
CredentialSubject,
AttributeType,
} from '@concordium/web-sdk';
import { storedVerifiableCredentialSchemasAtom } from '@popup/store/verifiable-credential';
import {
VerifiableCredential,
CredentialSubject,
VerifiableCredentialSchema,
VerifiableCredentialStatus,
} from '@shared/storage/types';
import { VerifiableCredential, VerifiableCredentialSchema, VerifiableCredentialStatus } from '@shared/storage/types';
import { getVerifiableCredentialPublicKeyfromSubjectDID } from '@shared/utils/verifiable-credential-helpers';
import { useAtomValue } from 'jotai';
import React, { useCallback, useEffect, useMemo, useState } from 'react';
Expand Down Expand Up @@ -48,7 +45,7 @@ function useStatementValue(statement: SecretStatementV2, schema: VerifiableCrede
export function useStatementDescription(statement: SecretStatementV2, schema: VerifiableCredentialSchema) {
const { t } = useTranslation('web3IdProofRequest', { keyPrefix: 'displayStatement.descriptions' });
const name = getPropertyTitle(statement.attributeTag, schema);
const listToString = (list: (string | bigint)[]) => list.map((member) => member.toString()).join(', ');
const listToString = (list: AttributeType[]) => list.map((member) => member.toString()).join(', ');

switch (statement.type) {
case StatementTypes.AttributeInRange:
Expand All @@ -70,7 +67,7 @@ type DisplayWeb3StatementProps<Statement> = ClassName & {

type AttributeInfo = {
name: string;
value: string | bigint;
value: AttributeType;
};

function extractAttributesFromCredentialSubjectForSingleStatement(
Expand Down
37 changes: 6 additions & 31 deletions packages/browser-wallet/src/popup/pages/Web3ProofRequest/utils.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import {
RequestStatement,
canProveCredentialStatement,
ConcordiumHdWallet,
createWeb3CommitmentInputWithHdWallet,
createAccountCommitmentInputWithHdWallet,
Expand All @@ -10,7 +9,7 @@ import {
AtomicStatementV2,
RevealStatementV2,
createWeb3IdDID,
StatementTypes,
canProveCredentialStatement,
} from '@concordium/web-sdk';
import { isIdentityOfCredential } from '@shared/utils/identity-helpers';
import {
Expand Down Expand Up @@ -92,40 +91,16 @@ export function getViableAccountCredentialsForStatement(
if (allowedIssuers.includes(c.providerIndex)) {
const identity = (identities || []).find((id) => isIdentityOfCredential(id)(c));
if (identity) {
return canProveCredentialStatement(credentialStatement, identity.idObject.value.attributeList);
return canProveCredentialStatement(
credentialStatement,
identity.idObject.value.attributeList.chosenAttributes
);
}
}
return false;
});
}

// TODO Replace with canProveAtomicStatement when SDK is updated
function doesCredentialSatisfyStatement(statement: AtomicStatementV2, cred: VerifiableCredential): boolean {
let value = cred.credentialSubject.attributes[statement.attributeTag];

// temporary handling of numbers saved as numbers;
if (typeof value === 'number') {
value = BigInt(value);
}

if (value === undefined) {
return false;
}

switch (statement.type) {
case StatementTypes.AttributeInRange:
return statement.lower <= value && statement.upper > value;
case StatementTypes.AttributeInSet:
return statement.set.includes(value);
case StatementTypes.AttributeNotInSet:
return !statement.set.includes(value);
case StatementTypes.RevealAttribute:
return value !== undefined;
default:
throw new Error('Unknown statementType encountered');
}
}

/**
* Given a credential statement for a verifiable credential, and a list of verifiable credentials, return the filtered list of verifiable credentials that satisfy the statement.
*/
Expand All @@ -143,7 +118,7 @@ export function getViableWeb3IdCredentialsForStatement(
);

return allowedCredentials.filter((cred) =>
credentialStatement.statement.every((stm) => doesCredentialSatisfyStatement(stm, cred))
canProveCredentialStatement(credentialStatement, cred.credentialSubject.attributes)
);
}

Expand Down
16 changes: 2 additions & 14 deletions packages/browser-wallet/src/popup/shared/utils/account-helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,7 @@ export function useSelectedCredential() {
return useCredential(selectedAccount);
}

// TODO fix type
export function useHdWallet():
| (ConcordiumHdWallet & { getVerifiableCredentialBackupEncryptionKey: () => Buffer })
| undefined {
export function useHdWallet(): ConcordiumHdWallet | undefined {
const network = useAtomValue(networkConfigurationAtom);
const seedPhrase = useDecryptedSeedPhrase();

Expand All @@ -79,16 +76,7 @@ export function useHdWallet():
return undefined;
}

// return ConcordiumHdWallet.fromHex(seedPhrase, getNet(network));
// TODO remove this hack when SDK is updated
// START OF HACK
const w = ConcordiumHdWallet.fromHex(seedPhrase, getNet(network));
// eslint-disable-next-line @typescript-eslint/no-explicit-any
(w as any).getVerifiableCredentialBackupEncryptionKey = () =>
w.getVerifiableCredentialSigningKey({ index: 0n, subindex: 0n }, 0);
// eslint-disable-next-line @typescript-eslint/no-explicit-any
return w as any;
// END OF HACK
return ConcordiumHdWallet.fromHex(seedPhrase, getNet(network));
}, [seedPhrase]);

return wallet;
Expand Down
33 changes: 26 additions & 7 deletions packages/browser-wallet/src/shared/storage/types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
import { APIVerifiableCredential } from '@concordium/browser-wallet-api-helpers';
import type { CryptographicParameters, HexString, IdentityObjectV1, Network, Versioned } from '@concordium/web-sdk';
import type {
CredentialSubject,
CryptographicParameters,
HexString,
IdentityObjectV1,
Network,
Versioned,
} from '@concordium/web-sdk';

export enum ChromeStorageKey {
ConnectedSites = 'connectedSites',
Expand Down Expand Up @@ -273,11 +280,6 @@ export enum VerifiableCredentialStatus {
Pending,
}

export type CredentialSubject = {
id: string;
attributes: Record<string, string | bigint>;
};

export interface VerifiableCredential extends APIVerifiableCredential {
// With ID
credentialSubject: CredentialSubject;
Expand All @@ -296,8 +298,25 @@ interface CredentialSchemaProperty {
format?: string;
}

export type TimestampProperty = {
title: string;
type: 'object';
properties: {
type: {
type: 'string';
const: 'date-time';
};
timestamp: {
type: 'string';
format?: 'date-time';
};
};
required: ['type', 'timestamp'];
description?: string;
};

type CredentialSchemaAttributes = {
properties: Record<string, CredentialSchemaProperty>;
properties: Record<string, CredentialSchemaProperty | TimestampProperty>;
required: string[];
} & CredentialSchemaProperty;

Expand Down
Loading
Loading