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

Fix proofs with number attributes #342

Merged
merged 1 commit into from
Aug 18, 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 packages/browser-wallet-api/src/wallet-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ class WalletApi extends EventEmitter implements IWalletApi {
const res = await this.messageHandler.sendMessage<MessageStatusWrapper<string>>(
MessageType.AddWeb3IdCredential,
{
credential,
credential: stringify(credential),
metadataUrl,
}
);
Expand Down
4 changes: 2 additions & 2 deletions packages/browser-wallet/src/background/web3Id.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ export async function web3IdAddCredentialFinishHandler(input: {
* Run condition which ensures that the web3IdCredential request is valid.
*/
export const runIfValidWeb3IdCredentialRequest: RunCondition<MessageStatusWrapper<undefined>> = async (msg) => {
const { credential }: { credential: APIVerifiableCredential } = msg.payload;
const credential: APIVerifiableCredential = parse(msg.payload.credential);
const network = await storedCurrentNetwork.get();

if (!network) {
Expand Down Expand Up @@ -151,7 +151,7 @@ async function createWeb3Proof(input: Web3IdProofInput): Promise<ProofBackground
}

export const createWeb3IdProofHandler: ExtensionMessageHandler = (msg, _sender, respond) => {
createWeb3Proof(msg.payload)
createWeb3Proof(parse(msg.payload))
.then(respond)
.catch((e: Error) => respond({ status: BackgroundResponseStatus.Error, error: e.message }));
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import {
import { APIVerifiableCredential } from '@concordium/browser-wallet-api-helpers';
import { networkConfigurationAtom } from '@popup/store/settings';
import { MetadataUrl } from '@concordium/browser-wallet-api-helpers/lib/wallet-api-types';
import { parse } from '@shared/utils/payload-helpers';
import { VerifiableCredentialCard } from '../VerifiableCredential/VerifiableCredentialCard';

type Props = {
Expand All @@ -36,7 +37,7 @@ interface Location {
state: {
payload: {
url: string;
credential: APIVerifiableCredential;
credential: string;
metadataUrl: MetadataUrl;
};
};
Expand All @@ -58,7 +59,8 @@ export default function AddWeb3IdCredential({ onAllow, onReject }: Props) {

const [error, setError] = useState<string>();

const { credential, url, metadataUrl } = state.payload;
const { credential: rawCredential, url, metadataUrl } = state.payload;
const credential: APIVerifiableCredential = parse(rawCredential);

useEffect(() => onClose(onReject), [onClose, onReject]);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import { createWeb3IdDIDFromCredential, DisplayCredentialStatementProps, SecretS
function getPropertyTitle(attributeTag: string, schema: VerifiableCredentialSchema) {
// TODO use localization here
const property = schema.properties.credentialSubject.properties.attributes.properties[attributeTag];
return property.title;
return property ? property.title : attributeTag;
}

function useStatementValue(statement: SecretStatementV2, schema: VerifiableCredentialSchema): string {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import { parse } from '@shared/utils/payload-helpers';
import { VerifiableCredential, VerifiableCredentialStatus } from '@shared/storage/types';
import { getVerifiableCredentialStatus } from '@shared/utils/verifiable-credential-helpers';
import { useAsyncMemo } from 'wallet-common-helpers';
import { stringify } from '@concordium/browser-wallet-api/src/util';
import {
getAccountCredentialCommitmentInput,
getViableAccountCredentialsForStatement,
Expand Down Expand Up @@ -189,7 +190,7 @@ export default function Web3ProofRequest({ onReject, onSubmit }: Props) {

const result: ProofBackgroundResponse<string> = await popupMessageHandler.sendInternalMessage(
InternalMessageType.CreateWeb3IdProof,
input
stringify(input)
);

if (result.status !== BackgroundResponseStatus.Success) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,17 @@ export function getViableAccountCredentialsForStatement(

// TODO Replace with canProveAtomicStatement when SDK is updated
function doesCredentialSatisfyStatement(statement: AtomicStatementV2, cred: VerifiableCredential): boolean {
const value = cred.credentialSubject.attributes[statement.attributeTag];
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;
Expand Down
Loading