From a15fcc0b47b8c148ef7b07b93c316d550652c4e6 Mon Sep 17 00:00:00 2001 From: Hjort Date: Mon, 28 Aug 2023 11:48:17 +0200 Subject: [PATCH 1/8] Update SDK and fix TODOS that waited for the update --- examples/add-example-Web3Id/package.json | 2 +- examples/eSealing/package.json | 2 +- examples/nft-minting/package.json | 2 +- examples/piggybank/package.json | 2 +- examples/two-step-transfer/package.json | 2 +- examples/voting/package.json | 2 +- examples/wCCD/package.json | 2 +- .../browser-wallet-api-helpers/package.json | 2 +- packages/browser-wallet-api/package.json | 2 +- packages/browser-wallet/package.json | 2 +- .../browser-wallet/src/background/web3Id.ts | 12 +++- .../DisplayStatement/DisplayStatement.tsx | 2 +- .../src/popup/pages/Web3ProofRequest/utils.ts | 36 ++---------- .../src/popup/shared/utils/account-helpers.ts | 16 +---- yarn.lock | 58 +++++++++++-------- 15 files changed, 61 insertions(+), 83 deletions(-) diff --git a/examples/add-example-Web3Id/package.json b/examples/add-example-Web3Id/package.json index cdeeaaec..e1f5b3a4 100644 --- a/examples/add-example-Web3Id/package.json +++ b/examples/add-example-Web3Id/package.json @@ -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.0" } } diff --git a/examples/eSealing/package.json b/examples/eSealing/package.json index dfa8d916..67f8ba15 100644 --- a/examples/eSealing/package.json +++ b/examples/eSealing/package.json @@ -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.0", "@thi.ng/leb128": "^2.1.18", "@types/sha256": "^0.2.0", "@walletconnect/types": "^2.1.4", diff --git a/examples/nft-minting/package.json b/examples/nft-minting/package.json index b8c6afb8..52af0675 100644 --- a/examples/nft-minting/package.json +++ b/examples/nft-minting/package.json @@ -3,7 +3,7 @@ "packageManager": "yarn@3.2.0", "dependencies": { "@concordium/browser-wallet-api-helpers": "workspace:^", - "@concordium/web-sdk": "^6.1.0-alpha.1", + "@concordium/web-sdk": "^6.1.0", "cors": "^2.8.5", "express": "^4.18.1", "express-fileupload": "^1.4.0", diff --git a/examples/piggybank/package.json b/examples/piggybank/package.json index 8b6a10f7..14315a7c 100644 --- a/examples/piggybank/package.json +++ b/examples/piggybank/package.json @@ -3,7 +3,7 @@ "packageManager": "yarn@3.2.0", "dependencies": { "@concordium/browser-wallet-api-helpers": "workspace:^", - "@concordium/web-sdk": "^6.1.0-alpha.1", + "@concordium/web-sdk": "^6.1.0", "react": "^18.1.0", "react-dom": "^18.1.0" }, diff --git a/examples/two-step-transfer/package.json b/examples/two-step-transfer/package.json index ed4b56dd..0ed1ef66 100644 --- a/examples/two-step-transfer/package.json +++ b/examples/two-step-transfer/package.json @@ -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.0" } } diff --git a/examples/voting/package.json b/examples/voting/package.json index 7d33b767..35af23c1 100644 --- a/examples/voting/package.json +++ b/examples/voting/package.json @@ -4,7 +4,7 @@ "packageManager": "yarn@3.2.0", "dependencies": { "@concordium/browser-wallet-api-helpers": "^2.0.0", - "@concordium/web-sdk": "^6.1.0-alpha.1", + "@concordium/web-sdk": "^6.1.0", "bootstrap": "^5.2.1", "cross-env": "^7.0.3", "moment": "^2.29.4", diff --git a/examples/wCCD/package.json b/examples/wCCD/package.json index e81b826d..3174a5f2 100644 --- a/examples/wCCD/package.json +++ b/examples/wCCD/package.json @@ -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.0", "@thi.ng/leb128": "^2.1.18", "@walletconnect/types": "^2.1.4", "mathjs": "^11.4.0", diff --git a/packages/browser-wallet-api-helpers/package.json b/packages/browser-wallet-api-helpers/package.json index 5a1db886..0e24990d 100644 --- a/packages/browser-wallet-api-helpers/package.json +++ b/packages/browser-wallet-api-helpers/package.json @@ -19,7 +19,7 @@ "url": "https://concordium.com" }, "dependencies": { - "@concordium/web-sdk": "^6.1.0-alpha.1" + "@concordium/web-sdk": "^6.1.0" }, "devDependencies": { "@babel/core": "^7.17.10", diff --git a/packages/browser-wallet-api/package.json b/packages/browser-wallet-api/package.json index e8a163eb..e6d7fe57 100644 --- a/packages/browser-wallet-api/package.json +++ b/packages/browser-wallet-api/package.json @@ -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.0", "@protobuf-ts/grpcweb-transport": "^2.8.2", "@protobuf-ts/runtime-rpc": "^2.8.2", "buffer": "^6.0.3", diff --git a/packages/browser-wallet/package.json b/packages/browser-wallet/package.json index ec1c0787..b18fc61d 100644 --- a/packages/browser-wallet/package.json +++ b/packages/browser-wallet/package.json @@ -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.0", "@noble/ed25519": "^1.7.0", "@protobuf-ts/runtime-rpc": "^2.8.2", "@scure/bip39": "^1.1.0", diff --git a/packages/browser-wallet/src/background/web3Id.ts b/packages/browser-wallet/src/background/web3Id.ts index aeef7b44..a3dcbd3a 100644 --- a/packages/browser-wallet/src/background/web3Id.ts +++ b/packages/browser-wallet/src/background/web3Id.ts @@ -5,6 +5,9 @@ import { createConcordiumClient, verifyWeb3IdCredentialSignature, isHex, + verifyAtomicStatements, + isAccountCredentialStatement, + IDENTITY_SUBJECT_SCHEMA, } from '@concordium/web-sdk'; import { sessionVerifiableCredentials, @@ -172,9 +175,12 @@ export const runIfValidWeb3IdProof: RunCondition } 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) { diff --git a/packages/browser-wallet/src/popup/pages/IdProofRequest/DisplayStatement/DisplayStatement.tsx b/packages/browser-wallet/src/popup/pages/IdProofRequest/DisplayStatement/DisplayStatement.tsx index 53c164a8..41fe9f3b 100644 --- a/packages/browser-wallet/src/popup/pages/IdProofRequest/DisplayStatement/DisplayStatement.tsx +++ b/packages/browser-wallet/src/popup/pages/IdProofRequest/DisplayStatement/DisplayStatement.tsx @@ -56,7 +56,7 @@ type StatementTooltipProps = { reveal?: boolean; }; -function StatementTooltip({ reveal }: StatementTooltipProps) { +export function StatementTooltip({ reveal }: StatementTooltipProps) { const [open, setOpen] = useState(false); const { t } = useTranslation('idProofRequest', { keyPrefix: 'displayStatement' }); diff --git a/packages/browser-wallet/src/popup/pages/Web3ProofRequest/utils.ts b/packages/browser-wallet/src/popup/pages/Web3ProofRequest/utils.ts index 511717d2..64ab799d 100644 --- a/packages/browser-wallet/src/popup/pages/Web3ProofRequest/utils.ts +++ b/packages/browser-wallet/src/popup/pages/Web3ProofRequest/utils.ts @@ -10,7 +10,7 @@ import { AtomicStatementV2, RevealStatementV2, createWeb3IdDID, - StatementTypes, + canProveAtomicStatement, } from '@concordium/web-sdk'; import { isIdentityOfCredential } from '@shared/utils/identity-helpers'; import { @@ -92,40 +92,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. */ @@ -143,7 +119,7 @@ export function getViableWeb3IdCredentialsForStatement( ); return allowedCredentials.filter((cred) => - credentialStatement.statement.every((stm) => doesCredentialSatisfyStatement(stm, cred)) + credentialStatement.statement.every((stm) => canProveAtomicStatement(stm, cred.credentialSubject.attributes)) ); } diff --git a/packages/browser-wallet/src/popup/shared/utils/account-helpers.ts b/packages/browser-wallet/src/popup/shared/utils/account-helpers.ts index 6058810d..cb7e4938 100644 --- a/packages/browser-wallet/src/popup/shared/utils/account-helpers.ts +++ b/packages/browser-wallet/src/popup/shared/utils/account-helpers.ts @@ -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(); @@ -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; diff --git a/yarn.lock b/yarn.lock index 273a9331..75527a13 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1918,7 +1918,7 @@ __metadata: "@babel/plugin-transform-modules-commonjs": ^7.12.1 "@babel/plugin-transform-runtime": ^7.12.1 "@babel/preset-env": ^7.12.1 - "@concordium/web-sdk": ^6.1.0-alpha.1 + "@concordium/web-sdk": ^6.1.0 typescript: ^4.3.5 webpack: ^5.72.0 webpack-cli: ^4.9.2 @@ -1930,7 +1930,7 @@ __metadata: resolution: "@concordium/browser-wallet-api@workspace:packages/browser-wallet-api" dependencies: "@concordium/browser-wallet-api-helpers": "workspace:^" - "@concordium/common-sdk": ^9.1.0-alpha.1 + "@concordium/common-sdk": ^9.1.0 "@protobuf-ts/grpcweb-transport": ^2.8.2 "@protobuf-ts/runtime-rpc": ^2.8.2 "@types/json-bigint": ^1.0.1 @@ -1958,7 +1958,7 @@ __metadata: "@babel/core": ^7.18.2 "@concordium/browser-wallet-api": "workspace:^" "@concordium/browser-wallet-api-helpers": "workspace:^" - "@concordium/web-sdk": ^6.1.0-alpha.1 + "@concordium/web-sdk": ^6.1.0 "@craftamap/esbuild-plugin-html": ^0.4.0 "@mdx-js/react": ^1.6.22 "@noble/ed25519": ^1.7.0 @@ -2027,15 +2027,16 @@ __metadata: languageName: unknown linkType: soft -"@concordium/common-sdk@npm:9.1.0-alpha.1, @concordium/common-sdk@npm:^9.1.0-alpha.1": - version: 9.1.0-alpha.1 - resolution: "@concordium/common-sdk@npm:9.1.0-alpha.1" +"@concordium/common-sdk@npm:9.1.0, @concordium/common-sdk@npm:^9.1.0": + version: 9.1.0 + resolution: "@concordium/common-sdk@npm:9.1.0" dependencies: - "@concordium/rust-bindings": 1.2.0-alpha.1 + "@concordium/rust-bindings": 1.2.0 "@grpc/grpc-js": ^1.3.4 "@noble/ed25519": ^1.7.1 "@protobuf-ts/runtime-rpc": ^2.8.2 "@scure/bip39": ^1.1.0 + big.js: ^6.2.0 bs58check: ^2.1.2 buffer: ^6.0.3 cross-fetch: 3.1.5 @@ -2043,7 +2044,7 @@ __metadata: iso-3166-1: ^2.1.1 json-bigint: ^1.0.0 uuid: ^8.3.2 - checksum: dd87f2e6fae7f9590ed167ad5f739d82b25bebb29cca14f871db2a8c9c5957f9e7d19cdf9d062a7191417968a7544d0a8678674f3cb06949055088ee4d44e443 + checksum: 1adc45dee4abcd1b06d9066515745346593f7bd6abbcdd7d85e62862e58102b80f973cc8d6cf481f573301ba13188c5bd3cddeb7105cab41d2344041cd001291 languageName: node linkType: hard @@ -2085,10 +2086,10 @@ __metadata: languageName: node linkType: hard -"@concordium/rust-bindings@npm:1.2.0-alpha.1": - version: 1.2.0-alpha.1 - resolution: "@concordium/rust-bindings@npm:1.2.0-alpha.1" - checksum: c5f17b05a19eef4edcdcd0ef8372615662f5a05f8de062dff87c3c95b35583c556a5633d0394c91ac8680cd9bb7b06134b745cb7e850e9dcc94715d8cf72ef5f +"@concordium/rust-bindings@npm:1.2.0": + version: 1.2.0 + resolution: "@concordium/rust-bindings@npm:1.2.0" + checksum: a0deb7d2a8bea7b32487a85fd9981e40a1e0ad5ca72c625887e7d735933abae9adac34ab3047a0ac2f3e690ac8c5ac5d7a763a5fef9efe2c6d209860aa5cf6ec languageName: node linkType: hard @@ -2103,17 +2104,17 @@ __metadata: languageName: node linkType: hard -"@concordium/web-sdk@npm:^6.1.0-alpha.1": - version: 6.1.0-alpha.1 - resolution: "@concordium/web-sdk@npm:6.1.0-alpha.1" +"@concordium/web-sdk@npm:^6.1.0": + version: 6.1.0 + resolution: "@concordium/web-sdk@npm:6.1.0" dependencies: - "@concordium/common-sdk": 9.1.0-alpha.1 - "@concordium/rust-bindings": 1.2.0-alpha.1 + "@concordium/common-sdk": 9.1.0 + "@concordium/rust-bindings": 1.2.0 "@grpc/grpc-js": ^1.3.4 "@protobuf-ts/grpcweb-transport": ^2.8.2 buffer: ^6.0.3 process: ^0.11.10 - checksum: 97590bae0e27fcb1157407aac12f4f3fd05c89580ea2e75007b3803e1fa32c142279558610597b263de84e8e28a3f3ca478c69a173c35578b3d215a3cc16cc1e + checksum: 17f99eb2c17ada999ed699dde03668e3b9b7a95c59da6391cb09a0bb61f5dd7aa2bf4c6e935b728f46126f16ba521ef1695e37e2b040db7ba72da2cf5de8ba63 languageName: node linkType: hard @@ -6735,7 +6736,7 @@ __metadata: resolution: "NFT-Minting@workspace:examples/nft-minting" dependencies: "@concordium/browser-wallet-api-helpers": "workspace:^" - "@concordium/web-sdk": ^6.1.0-alpha.1 + "@concordium/web-sdk": ^6.1.0 "@craftamap/esbuild-plugin-html": ^0.4.0 "@types/react": ^18.0.9 "@types/react-dom": ^18.0.5 @@ -6878,7 +6879,7 @@ __metadata: version: 0.0.0-use.local resolution: "add-example-web3-id@workspace:examples/add-example-Web3Id" dependencies: - "@concordium/web-sdk": ^6.1.0-alpha.1 + "@concordium/web-sdk": ^6.1.0 live-server: ^1.2.2 languageName: unknown linkType: soft @@ -7855,6 +7856,13 @@ __metadata: languageName: node linkType: hard +"big.js@npm:^6.2.0": + version: 6.2.1 + resolution: "big.js@npm:6.2.1" + checksum: 0b234a2fd56c52bed2798ed2020bcab6fef5e9523b99a05406ad071d1aed6ee97ada9fb8de9576092da74c68825c276e19015743b8d1baea269b60a5c666b0cd + languageName: node + linkType: hard + "bignumber.js@npm:^9.0.0": version: 9.0.2 resolution: "bignumber.js@npm:9.0.2" @@ -10187,7 +10195,7 @@ __metadata: resolution: "e_sealing@workspace:examples/eSealing" dependencies: "@concordium/react-components": ^0.2.0 - "@concordium/web-sdk": ^6.1.0-alpha.1 + "@concordium/web-sdk": ^6.1.0 "@craftamap/esbuild-plugin-html": ^0.4.0 "@thi.ng/leb128": ^2.1.18 "@types/node": ^18.7.23 @@ -17567,7 +17575,7 @@ __metadata: resolution: "piggybank@workspace:examples/piggybank" dependencies: "@concordium/browser-wallet-api-helpers": "workspace:^" - "@concordium/web-sdk": ^6.1.0-alpha.1 + "@concordium/web-sdk": ^6.1.0 "@craftamap/esbuild-plugin-html": ^0.4.0 "@types/react": ^18.0.9 "@types/react-dom": ^18.0.5 @@ -21484,7 +21492,7 @@ __metadata: version: 0.0.0-use.local resolution: "two-step-transfer@workspace:examples/two-step-transfer" dependencies: - "@concordium/web-sdk": ^6.1.0-alpha.1 + "@concordium/web-sdk": ^6.1.0 live-server: ^1.2.2 languageName: unknown linkType: soft @@ -22182,7 +22190,7 @@ __metadata: resolution: "voting@workspace:examples/voting" dependencies: "@concordium/browser-wallet-api-helpers": ^2.0.0 - "@concordium/web-sdk": ^6.1.0-alpha.1 + "@concordium/web-sdk": ^6.1.0 "@types/node": ^18.7.23 "@types/react": ^18.0.9 "@types/react-dom": ^18.0.5 @@ -22307,7 +22315,7 @@ __metadata: resolution: "wccd@workspace:examples/wCCD" dependencies: "@concordium/react-components": ^0.2.0 - "@concordium/web-sdk": ^6.1.0-alpha.1 + "@concordium/web-sdk": ^6.1.0 "@craftamap/esbuild-plugin-html": ^0.4.0 "@thi.ng/leb128": ^2.1.18 "@types/node": ^18.7.23 From d78eefa4ce67b7fda52ef52bbb6f0f1b8cda611d Mon Sep 17 00:00:00 2001 From: Hjort Date: Mon, 28 Aug 2023 12:51:40 +0200 Subject: [PATCH 2/8] re-add doesCredentialSatisfyStatement and improve range check for string/dates --- packages/browser-wallet/CHANGELOG.md | 1 + .../src/popup/pages/Web3ProofRequest/utils.ts | 53 ++++++++++++++++--- 2 files changed, 48 insertions(+), 6 deletions(-) diff --git a/packages/browser-wallet/CHANGELOG.md b/packages/browser-wallet/CHANGELOG.md index 3e55c07d..1081a51c 100644 --- a/packages/browser-wallet/CHANGELOG.md +++ b/packages/browser-wallet/CHANGELOG.md @@ -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. ## 1.1.2 diff --git a/packages/browser-wallet/src/popup/pages/Web3ProofRequest/utils.ts b/packages/browser-wallet/src/popup/pages/Web3ProofRequest/utils.ts index 64ab799d..37278e91 100644 --- a/packages/browser-wallet/src/popup/pages/Web3ProofRequest/utils.ts +++ b/packages/browser-wallet/src/popup/pages/Web3ProofRequest/utils.ts @@ -1,6 +1,5 @@ import { RequestStatement, - canProveCredentialStatement, ConcordiumHdWallet, createWeb3CommitmentInputWithHdWallet, createAccountCommitmentInputWithHdWallet, @@ -10,7 +9,9 @@ import { AtomicStatementV2, RevealStatementV2, createWeb3IdDID, - canProveAtomicStatement, + StatementTypes, + isStringAttributeInRange, + AttributeType, } from '@concordium/web-sdk'; import { isIdentityOfCredential } from '@shared/utils/identity-helpers'; import { @@ -78,6 +79,45 @@ export function getWeb3CommitmentInput(verifiableCredential: VerifiableCredentia ); } +function isInRange(value: AttributeType, lower: AttributeType, upper: AttributeType) { + if (typeof value === 'string' && typeof lower === 'string' && typeof upper === 'string') { + return isStringAttributeInRange(value, lower, upper); + } + if (typeof value === 'bigint' && typeof lower === 'bigint' && typeof upper === 'bigint') { + return lower <= value && upper > value; + } + if (value instanceof Date && lower instanceof Date && upper instanceof Date) { + return lower.getTime() <= value.getTime() && upper.getTime() > value.getTime(); + } + // Mismatch in types. + return false; +} + +// TODO Replace with canProveAtomicStatement when SDK is updated (AttributeNotInSet vs undefined) +function doesCredentialSatisfyStatement( + statement: AtomicStatementV2, + attributes: Record +): boolean { + const value = attributes[statement.attributeTag]; + + if (value === undefined) { + return false; + } + + switch (statement.type) { + case StatementTypes.AttributeInRange: + return isInRange(value, statement.lower, statement.upper); + 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 an account credential, and a list of account credentials, return the filtered list of credentials that satisfy the statement. * Note this also requires the identities for the account credentials as an additional argument, to actually check the attributes of the credential. @@ -92,9 +132,8 @@ 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.chosenAttributes + credentialStatement.statement.every((stm) => + doesCredentialSatisfyStatement(stm, identity.idObject.value.attributeList.chosenAttributes) ); } } @@ -119,7 +158,9 @@ export function getViableWeb3IdCredentialsForStatement( ); return allowedCredentials.filter((cred) => - credentialStatement.statement.every((stm) => canProveAtomicStatement(stm, cred.credentialSubject.attributes)) + credentialStatement.statement.every((stm) => + doesCredentialSatisfyStatement(stm, cred.credentialSubject.attributes) + ) ); } From 2d4898f6b82e2127a5bd2d855effedd258a52277 Mon Sep 17 00:00:00 2001 From: Hjort Date: Mon, 28 Aug 2023 13:10:16 +0200 Subject: [PATCH 3/8] Fix errors + use AttributeType --- packages/browser-wallet-api/src/wallet-api.ts | 3 ++- .../VerifiableCredentialCard.tsx | 8 ++++---- .../VerifiableCredentialStatement.tsx | 13 +++++-------- .../browser-wallet/src/shared/storage/types.ts | 14 ++++++++------ 4 files changed, 19 insertions(+), 19 deletions(-) diff --git a/packages/browser-wallet-api/src/wallet-api.ts b/packages/browser-wallet-api/src/wallet-api.ts index aceef2cf..c7d22bcf 100644 --- a/packages/browser-wallet-api/src/wallet-api.ts +++ b/packages/browser-wallet-api/src/wallet-api.ts @@ -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'; diff --git a/packages/browser-wallet/src/popup/pages/VerifiableCredential/VerifiableCredentialCard.tsx b/packages/browser-wallet/src/popup/pages/VerifiableCredential/VerifiableCredentialCard.tsx index ddc59202..e18a5b62 100644 --- a/packages/browser-wallet/src/popup/pages/VerifiableCredential/VerifiableCredentialCard.tsx +++ b/packages/browser-wallet/src/popup/pages/VerifiableCredential/VerifiableCredentialCard.tsx @@ -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'; @@ -28,7 +28,7 @@ export function DisplayAttribute({ attributeTitle, }: { attributeKey: string; - attributeValue: string | bigint; + attributeValue: AttributeType; attributeTitle: string; }) { return ( @@ -82,8 +82,8 @@ function ClickableVerifiableCredential({ children, onClick, metadata, className function applySchemaAndLocalization( schema: VerifiableCredentialSchema, localization?: Record -): (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]}`); diff --git a/packages/browser-wallet/src/popup/pages/Web3ProofRequest/VerifiableCredentialStatement.tsx b/packages/browser-wallet/src/popup/pages/Web3ProofRequest/VerifiableCredentialStatement.tsx index 0d432539..54adbf67 100644 --- a/packages/browser-wallet/src/popup/pages/Web3ProofRequest/VerifiableCredentialStatement.tsx +++ b/packages/browser-wallet/src/popup/pages/Web3ProofRequest/VerifiableCredentialStatement.tsx @@ -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'; @@ -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: @@ -70,7 +67,7 @@ type DisplayWeb3StatementProps = ClassName & { type AttributeInfo = { name: string; - value: string | bigint; + value: AttributeType; }; function extractAttributesFromCredentialSubjectForSingleStatement( diff --git a/packages/browser-wallet/src/shared/storage/types.ts b/packages/browser-wallet/src/shared/storage/types.ts index 25c95147..000ca5f0 100644 --- a/packages/browser-wallet/src/shared/storage/types.ts +++ b/packages/browser-wallet/src/shared/storage/types.ts @@ -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', @@ -273,11 +280,6 @@ export enum VerifiableCredentialStatus { Pending, } -export type CredentialSubject = { - id: string; - attributes: Record; -}; - export interface VerifiableCredential extends APIVerifiableCredential { // With ID credentialSubject: CredentialSubject; From f122fb89b95a76f7f7b2c3fd78ff4ecabc4c40f1 Mon Sep 17 00:00:00 2001 From: Hjort Date: Mon, 28 Aug 2023 15:14:47 +0200 Subject: [PATCH 4/8] re-remove doesCredentialSatisfyStatement + bump versions --- examples/add-example-Web3Id/package.json | 2 +- examples/eSealing/package.json | 2 +- examples/nft-minting/package.json | 2 +- examples/piggybank/package.json | 2 +- examples/two-step-transfer/package.json | 2 +- examples/voting/package.json | 2 +- examples/wCCD/package.json | 2 +- .../browser-wallet-api-helpers/package.json | 2 +- packages/browser-wallet-api/package.json | 2 +- packages/browser-wallet/package.json | 2 +- .../DisplayStatement/DisplayStatement.tsx | 2 +- .../src/popup/pages/Web3ProofRequest/utils.ts | 52 ++----------------- yarn.lock | 38 +++++++------- 13 files changed, 35 insertions(+), 77 deletions(-) diff --git a/examples/add-example-Web3Id/package.json b/examples/add-example-Web3Id/package.json index e1f5b3a4..8730dfc5 100644 --- a/examples/add-example-Web3Id/package.json +++ b/examples/add-example-Web3Id/package.json @@ -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" + "@concordium/web-sdk": "^6.1.1" } } diff --git a/examples/eSealing/package.json b/examples/eSealing/package.json index 67f8ba15..165690f0 100644 --- a/examples/eSealing/package.json +++ b/examples/eSealing/package.json @@ -5,7 +5,7 @@ "license": "Apache-2.0", "dependencies": { "@concordium/react-components": "^0.2.0", - "@concordium/web-sdk": "^6.1.0", + "@concordium/web-sdk": "^6.1.1", "@thi.ng/leb128": "^2.1.18", "@types/sha256": "^0.2.0", "@walletconnect/types": "^2.1.4", diff --git a/examples/nft-minting/package.json b/examples/nft-minting/package.json index 52af0675..c6113b42 100644 --- a/examples/nft-minting/package.json +++ b/examples/nft-minting/package.json @@ -3,7 +3,7 @@ "packageManager": "yarn@3.2.0", "dependencies": { "@concordium/browser-wallet-api-helpers": "workspace:^", - "@concordium/web-sdk": "^6.1.0", + "@concordium/web-sdk": "^6.1.1", "cors": "^2.8.5", "express": "^4.18.1", "express-fileupload": "^1.4.0", diff --git a/examples/piggybank/package.json b/examples/piggybank/package.json index 14315a7c..275e75c3 100644 --- a/examples/piggybank/package.json +++ b/examples/piggybank/package.json @@ -3,7 +3,7 @@ "packageManager": "yarn@3.2.0", "dependencies": { "@concordium/browser-wallet-api-helpers": "workspace:^", - "@concordium/web-sdk": "^6.1.0", + "@concordium/web-sdk": "^6.1.1", "react": "^18.1.0", "react-dom": "^18.1.0" }, diff --git a/examples/two-step-transfer/package.json b/examples/two-step-transfer/package.json index 0ed1ef66..42dca1cc 100644 --- a/examples/two-step-transfer/package.json +++ b/examples/two-step-transfer/package.json @@ -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" + "@concordium/web-sdk": "^6.1.1" } } diff --git a/examples/voting/package.json b/examples/voting/package.json index 35af23c1..cc316ced 100644 --- a/examples/voting/package.json +++ b/examples/voting/package.json @@ -4,7 +4,7 @@ "packageManager": "yarn@3.2.0", "dependencies": { "@concordium/browser-wallet-api-helpers": "^2.0.0", - "@concordium/web-sdk": "^6.1.0", + "@concordium/web-sdk": "^6.1.1", "bootstrap": "^5.2.1", "cross-env": "^7.0.3", "moment": "^2.29.4", diff --git a/examples/wCCD/package.json b/examples/wCCD/package.json index 3174a5f2..21d95191 100644 --- a/examples/wCCD/package.json +++ b/examples/wCCD/package.json @@ -5,7 +5,7 @@ "license": "Apache-2.0", "dependencies": { "@concordium/react-components": "^0.2.0", - "@concordium/web-sdk": "^6.1.0", + "@concordium/web-sdk": "^6.1.1", "@thi.ng/leb128": "^2.1.18", "@walletconnect/types": "^2.1.4", "mathjs": "^11.4.0", diff --git a/packages/browser-wallet-api-helpers/package.json b/packages/browser-wallet-api-helpers/package.json index 0e24990d..ffdb86fb 100644 --- a/packages/browser-wallet-api-helpers/package.json +++ b/packages/browser-wallet-api-helpers/package.json @@ -19,7 +19,7 @@ "url": "https://concordium.com" }, "dependencies": { - "@concordium/web-sdk": "^6.1.0" + "@concordium/web-sdk": "^6.1.1" }, "devDependencies": { "@babel/core": "^7.17.10", diff --git a/packages/browser-wallet-api/package.json b/packages/browser-wallet-api/package.json index e6d7fe57..47a19976 100644 --- a/packages/browser-wallet-api/package.json +++ b/packages/browser-wallet-api/package.json @@ -7,7 +7,7 @@ "license": "Apache-2.0", "dependencies": { "@concordium/browser-wallet-api-helpers": "workspace:^", - "@concordium/common-sdk": "^9.1.0", + "@concordium/common-sdk": "^9.1.1", "@protobuf-ts/grpcweb-transport": "^2.8.2", "@protobuf-ts/runtime-rpc": "^2.8.2", "buffer": "^6.0.3", diff --git a/packages/browser-wallet/package.json b/packages/browser-wallet/package.json index b18fc61d..49057213 100644 --- a/packages/browser-wallet/package.json +++ b/packages/browser-wallet/package.json @@ -19,7 +19,7 @@ "dependencies": { "@concordium/browser-wallet-api": "workspace:^", "@concordium/browser-wallet-api-helpers": "workspace:^", - "@concordium/web-sdk": "^6.1.0", + "@concordium/web-sdk": "^6.1.1", "@noble/ed25519": "^1.7.0", "@protobuf-ts/runtime-rpc": "^2.8.2", "@scure/bip39": "^1.1.0", diff --git a/packages/browser-wallet/src/popup/pages/IdProofRequest/DisplayStatement/DisplayStatement.tsx b/packages/browser-wallet/src/popup/pages/IdProofRequest/DisplayStatement/DisplayStatement.tsx index 41fe9f3b..53c164a8 100644 --- a/packages/browser-wallet/src/popup/pages/IdProofRequest/DisplayStatement/DisplayStatement.tsx +++ b/packages/browser-wallet/src/popup/pages/IdProofRequest/DisplayStatement/DisplayStatement.tsx @@ -56,7 +56,7 @@ type StatementTooltipProps = { reveal?: boolean; }; -export function StatementTooltip({ reveal }: StatementTooltipProps) { +function StatementTooltip({ reveal }: StatementTooltipProps) { const [open, setOpen] = useState(false); const { t } = useTranslation('idProofRequest', { keyPrefix: 'displayStatement' }); diff --git a/packages/browser-wallet/src/popup/pages/Web3ProofRequest/utils.ts b/packages/browser-wallet/src/popup/pages/Web3ProofRequest/utils.ts index 37278e91..6123bc5c 100644 --- a/packages/browser-wallet/src/popup/pages/Web3ProofRequest/utils.ts +++ b/packages/browser-wallet/src/popup/pages/Web3ProofRequest/utils.ts @@ -9,9 +9,7 @@ import { AtomicStatementV2, RevealStatementV2, createWeb3IdDID, - StatementTypes, - isStringAttributeInRange, - AttributeType, + canProveCredentialStatement, } from '@concordium/web-sdk'; import { isIdentityOfCredential } from '@shared/utils/identity-helpers'; import { @@ -79,45 +77,6 @@ export function getWeb3CommitmentInput(verifiableCredential: VerifiableCredentia ); } -function isInRange(value: AttributeType, lower: AttributeType, upper: AttributeType) { - if (typeof value === 'string' && typeof lower === 'string' && typeof upper === 'string') { - return isStringAttributeInRange(value, lower, upper); - } - if (typeof value === 'bigint' && typeof lower === 'bigint' && typeof upper === 'bigint') { - return lower <= value && upper > value; - } - if (value instanceof Date && lower instanceof Date && upper instanceof Date) { - return lower.getTime() <= value.getTime() && upper.getTime() > value.getTime(); - } - // Mismatch in types. - return false; -} - -// TODO Replace with canProveAtomicStatement when SDK is updated (AttributeNotInSet vs undefined) -function doesCredentialSatisfyStatement( - statement: AtomicStatementV2, - attributes: Record -): boolean { - const value = attributes[statement.attributeTag]; - - if (value === undefined) { - return false; - } - - switch (statement.type) { - case StatementTypes.AttributeInRange: - return isInRange(value, statement.lower, statement.upper); - 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 an account credential, and a list of account credentials, return the filtered list of credentials that satisfy the statement. * Note this also requires the identities for the account credentials as an additional argument, to actually check the attributes of the credential. @@ -132,8 +91,9 @@ export function getViableAccountCredentialsForStatement( if (allowedIssuers.includes(c.providerIndex)) { const identity = (identities || []).find((id) => isIdentityOfCredential(id)(c)); if (identity) { - credentialStatement.statement.every((stm) => - doesCredentialSatisfyStatement(stm, identity.idObject.value.attributeList.chosenAttributes) + return canProveCredentialStatement( + credentialStatement, + identity.idObject.value.attributeList.chosenAttributes ); } } @@ -158,9 +118,7 @@ export function getViableWeb3IdCredentialsForStatement( ); return allowedCredentials.filter((cred) => - credentialStatement.statement.every((stm) => - doesCredentialSatisfyStatement(stm, cred.credentialSubject.attributes) - ) + canProveCredentialStatement(credentialStatement, cred.credentialSubject.attributes) ); } diff --git a/yarn.lock b/yarn.lock index 75527a13..cceee53b 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1918,7 +1918,7 @@ __metadata: "@babel/plugin-transform-modules-commonjs": ^7.12.1 "@babel/plugin-transform-runtime": ^7.12.1 "@babel/preset-env": ^7.12.1 - "@concordium/web-sdk": ^6.1.0 + "@concordium/web-sdk": ^6.1.1 typescript: ^4.3.5 webpack: ^5.72.0 webpack-cli: ^4.9.2 @@ -1930,7 +1930,7 @@ __metadata: resolution: "@concordium/browser-wallet-api@workspace:packages/browser-wallet-api" dependencies: "@concordium/browser-wallet-api-helpers": "workspace:^" - "@concordium/common-sdk": ^9.1.0 + "@concordium/common-sdk": ^9.1.1 "@protobuf-ts/grpcweb-transport": ^2.8.2 "@protobuf-ts/runtime-rpc": ^2.8.2 "@types/json-bigint": ^1.0.1 @@ -1958,7 +1958,7 @@ __metadata: "@babel/core": ^7.18.2 "@concordium/browser-wallet-api": "workspace:^" "@concordium/browser-wallet-api-helpers": "workspace:^" - "@concordium/web-sdk": ^6.1.0 + "@concordium/web-sdk": ^6.1.1 "@craftamap/esbuild-plugin-html": ^0.4.0 "@mdx-js/react": ^1.6.22 "@noble/ed25519": ^1.7.0 @@ -2027,9 +2027,9 @@ __metadata: languageName: unknown linkType: soft -"@concordium/common-sdk@npm:9.1.0, @concordium/common-sdk@npm:^9.1.0": - version: 9.1.0 - resolution: "@concordium/common-sdk@npm:9.1.0" +"@concordium/common-sdk@npm:9.1.1, @concordium/common-sdk@npm:^9.1.1": + version: 9.1.1 + resolution: "@concordium/common-sdk@npm:9.1.1" dependencies: "@concordium/rust-bindings": 1.2.0 "@grpc/grpc-js": ^1.3.4 @@ -2044,7 +2044,7 @@ __metadata: iso-3166-1: ^2.1.1 json-bigint: ^1.0.0 uuid: ^8.3.2 - checksum: 1adc45dee4abcd1b06d9066515745346593f7bd6abbcdd7d85e62862e58102b80f973cc8d6cf481f573301ba13188c5bd3cddeb7105cab41d2344041cd001291 + checksum: e7f43e085b968e9772f2559b2530bca59a9aab426332c3e088f266a76bc1e913bedff097aa61bc5a9c5ddb78db4decf2fd6a027d7231e95fcb368fe41f2820c8 languageName: node linkType: hard @@ -2104,17 +2104,17 @@ __metadata: languageName: node linkType: hard -"@concordium/web-sdk@npm:^6.1.0": - version: 6.1.0 - resolution: "@concordium/web-sdk@npm:6.1.0" +"@concordium/web-sdk@npm:^6.1.1": + version: 6.1.1 + resolution: "@concordium/web-sdk@npm:6.1.1" dependencies: - "@concordium/common-sdk": 9.1.0 + "@concordium/common-sdk": 9.1.1 "@concordium/rust-bindings": 1.2.0 "@grpc/grpc-js": ^1.3.4 "@protobuf-ts/grpcweb-transport": ^2.8.2 buffer: ^6.0.3 process: ^0.11.10 - checksum: 17f99eb2c17ada999ed699dde03668e3b9b7a95c59da6391cb09a0bb61f5dd7aa2bf4c6e935b728f46126f16ba521ef1695e37e2b040db7ba72da2cf5de8ba63 + checksum: 85fa565d4ea9e6dfbc7b924b96e511fdb8094d7d3fdbc733204e65495f1969f9a9dd13a3e869c6b5e2501d1b65e1eb7296f282e78b456d3f03d0fac2c101ccad languageName: node linkType: hard @@ -6736,7 +6736,7 @@ __metadata: resolution: "NFT-Minting@workspace:examples/nft-minting" dependencies: "@concordium/browser-wallet-api-helpers": "workspace:^" - "@concordium/web-sdk": ^6.1.0 + "@concordium/web-sdk": ^6.1.1 "@craftamap/esbuild-plugin-html": ^0.4.0 "@types/react": ^18.0.9 "@types/react-dom": ^18.0.5 @@ -6879,7 +6879,7 @@ __metadata: version: 0.0.0-use.local resolution: "add-example-web3-id@workspace:examples/add-example-Web3Id" dependencies: - "@concordium/web-sdk": ^6.1.0 + "@concordium/web-sdk": ^6.1.1 live-server: ^1.2.2 languageName: unknown linkType: soft @@ -10195,7 +10195,7 @@ __metadata: resolution: "e_sealing@workspace:examples/eSealing" dependencies: "@concordium/react-components": ^0.2.0 - "@concordium/web-sdk": ^6.1.0 + "@concordium/web-sdk": ^6.1.1 "@craftamap/esbuild-plugin-html": ^0.4.0 "@thi.ng/leb128": ^2.1.18 "@types/node": ^18.7.23 @@ -17575,7 +17575,7 @@ __metadata: resolution: "piggybank@workspace:examples/piggybank" dependencies: "@concordium/browser-wallet-api-helpers": "workspace:^" - "@concordium/web-sdk": ^6.1.0 + "@concordium/web-sdk": ^6.1.1 "@craftamap/esbuild-plugin-html": ^0.4.0 "@types/react": ^18.0.9 "@types/react-dom": ^18.0.5 @@ -21492,7 +21492,7 @@ __metadata: version: 0.0.0-use.local resolution: "two-step-transfer@workspace:examples/two-step-transfer" dependencies: - "@concordium/web-sdk": ^6.1.0 + "@concordium/web-sdk": ^6.1.1 live-server: ^1.2.2 languageName: unknown linkType: soft @@ -22190,7 +22190,7 @@ __metadata: resolution: "voting@workspace:examples/voting" dependencies: "@concordium/browser-wallet-api-helpers": ^2.0.0 - "@concordium/web-sdk": ^6.1.0 + "@concordium/web-sdk": ^6.1.1 "@types/node": ^18.7.23 "@types/react": ^18.0.9 "@types/react-dom": ^18.0.5 @@ -22315,7 +22315,7 @@ __metadata: resolution: "wccd@workspace:examples/wCCD" dependencies: "@concordium/react-components": ^0.2.0 - "@concordium/web-sdk": ^6.1.0 + "@concordium/web-sdk": ^6.1.1 "@craftamap/esbuild-plugin-html": ^0.4.0 "@thi.ng/leb128": ^2.1.18 "@types/node": ^18.7.23 From 88c9c37e65498c2e470148cb2cffcda590dbd09f Mon Sep 17 00:00:00 2001 From: Hjort Date: Tue, 29 Aug 2023 10:24:48 +0200 Subject: [PATCH 5/8] Bump version --- packages/browser-wallet/CHANGELOG.md | 2 +- packages/browser-wallet/package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/browser-wallet/CHANGELOG.md b/packages/browser-wallet/CHANGELOG.md index ec6e3fb1..26d19c00 100644 --- a/packages/browser-wallet/CHANGELOG.md +++ b/packages/browser-wallet/CHANGELOG.md @@ -1,6 +1,6 @@ # Changelog -## Unreleased +## 1.1.3 ### Changed diff --git a/packages/browser-wallet/package.json b/packages/browser-wallet/package.json index 49057213..02e9c5bc 100644 --- a/packages/browser-wallet/package.json +++ b/packages/browser-wallet/package.json @@ -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", From 38fb4c570a4924459294a10c5bd547c3b3520a4c Mon Sep 17 00:00:00 2001 From: Hjort Date: Tue, 29 Aug 2023 10:43:44 +0200 Subject: [PATCH 6/8] Add timestamp property to credentialSchema --- .../src/shared/storage/types.ts | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/packages/browser-wallet/src/shared/storage/types.ts b/packages/browser-wallet/src/shared/storage/types.ts index 000ca5f0..1ef3c8c5 100644 --- a/packages/browser-wallet/src/shared/storage/types.ts +++ b/packages/browser-wallet/src/shared/storage/types.ts @@ -298,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; + properties: Record; required: string[]; } & CredentialSchemaProperty; From c379da2e4f653b3ced756879636b6c0245e497a9 Mon Sep 17 00:00:00 2001 From: orhoj Date: Tue, 29 Aug 2023 10:49:47 +0200 Subject: [PATCH 7/8] Update schema check to support timestamp --- .../utils/verifiable-credential-helpers.ts | 106 +++++++++++++++--- 1 file changed, 91 insertions(+), 15 deletions(-) diff --git a/packages/browser-wallet/src/shared/utils/verifiable-credential-helpers.ts b/packages/browser-wallet/src/shared/utils/verifiable-credential-helpers.ts index c5f66489..61a0146b 100644 --- a/packages/browser-wallet/src/shared/utils/verifiable-credential-helpers.ts +++ b/packages/browser-wallet/src/shared/utils/verifiable-credential-helpers.ts @@ -382,23 +382,30 @@ const verifiableCredentialSchemaSchema = { }, properties: { additionalProperties: { - additionalProperties: false, - properties: { - description: { - type: 'string', + anyOf: [ + { + additionalProperties: false, + properties: { + description: { + type: 'string', + }, + format: { + type: 'string', + }, + title: { + type: 'string', + }, + type: { + type: 'string', + }, + }, + required: ['title', 'type', 'description'], + type: 'object', }, - format: { - type: 'string', + { + $ref: '#/definitions/TimestampProperty', }, - title: { - type: 'string', - }, - type: { - type: 'string', - }, - }, - required: ['title', 'type', 'description'], - type: 'object', + ], }, type: 'object', }, @@ -458,6 +465,75 @@ const verifiableCredentialSchemaSchema = { required: ['credentialSubject'], type: 'object', }, + TimestampProperty: { + additionalProperties: false, + properties: { + description: { + type: 'string', + }, + properties: { + additionalProperties: false, + properties: { + timestamp: { + additionalProperties: false, + properties: { + format: { + const: 'date-time', + type: 'string', + }, + type: { + const: 'string', + type: 'string', + }, + }, + required: ['type'], + type: 'object', + }, + type: { + additionalProperties: false, + properties: { + const: { + const: 'date-time', + type: 'string', + }, + type: { + const: 'string', + type: 'string', + }, + }, + required: ['type', 'const'], + type: 'object', + }, + }, + required: ['type', 'timestamp'], + type: 'object', + }, + required: { + items: [ + { + const: 'type', + type: 'string', + }, + { + const: 'timestamp', + type: 'string', + }, + ], + maxItems: 2, + minItems: 2, + type: 'array', + }, + title: { + type: 'string', + }, + type: { + const: 'object', + type: 'string', + }, + }, + required: ['title', 'type', 'properties', 'required'], + type: 'object', + }, VerifiableCredentialSchema: { additionalProperties: false, properties: { From 4727811a45618538e07b33b79589ad23ec12badd Mon Sep 17 00:00:00 2001 From: Hjort Date: Tue, 29 Aug 2023 11:04:05 +0200 Subject: [PATCH 8/8] Fix blank screen when fetching schema causes an error --- .../src/popup/pages/AddWeb3IdCredential/AddWeb3IdCredential.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/browser-wallet/src/popup/pages/AddWeb3IdCredential/AddWeb3IdCredential.tsx b/packages/browser-wallet/src/popup/pages/AddWeb3IdCredential/AddWeb3IdCredential.tsx index dcddfd64..818c85ae 100644 --- a/packages/browser-wallet/src/popup/pages/AddWeb3IdCredential/AddWeb3IdCredential.tsx +++ b/packages/browser-wallet/src/popup/pages/AddWeb3IdCredential/AddWeb3IdCredential.tsx @@ -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; }