Skip to content

Commit

Permalink
re-remove doesCredentialSatisfyStatement + bump versions
Browse files Browse the repository at this point in the history
  • Loading branch information
Hjort committed Aug 28, 2023
1 parent 2d4898f commit f122fb8
Show file tree
Hide file tree
Showing 13 changed files with 35 additions and 77 deletions.
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"
"@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",
"@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",
"@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",
"@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"
"@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",
"@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",
"@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"
"@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",
"@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
2 changes: 1 addition & 1 deletion packages/browser-wallet/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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' });

Expand Down
52 changes: 5 additions & 47 deletions packages/browser-wallet/src/popup/pages/Web3ProofRequest/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@ import {
AtomicStatementV2,
RevealStatementV2,
createWeb3IdDID,
StatementTypes,
isStringAttributeInRange,
AttributeType,
canProveCredentialStatement,
} from '@concordium/web-sdk';
import { isIdentityOfCredential } from '@shared/utils/identity-helpers';
import {
Expand Down Expand Up @@ -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<string, AttributeType>
): 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.
Expand All @@ -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
);
}
}
Expand All @@ -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)
);
}

Expand Down
38 changes: 19 additions & 19 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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

Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit f122fb8

Please sign in to comment.