Skip to content

Commit

Permalink
Merge pull request #200 from Concordium/web3Proofs
Browse files Browse the repository at this point in the history
Web3Id proofs
  • Loading branch information
shjortConcordium authored Aug 24, 2023
2 parents 395a633 + f810805 commit 5eb8f77
Show file tree
Hide file tree
Showing 26 changed files with 1,738 additions and 254 deletions.
2 changes: 1 addition & 1 deletion deps/concordium-base
Submodule concordium-base updated 58 files
+0 −2 README.md
+1 −1 concordium-contracts-common
+0 −7 haskell-bins/genesis/README.md
+2 −4 haskell-src/Concordium/Genesis/Data/P6.hs
+3 −3 identity-provider-service/Cargo.lock
+3 −3 idiss/Cargo.lock
+3 −3 mobile_wallet/Cargo.lock
+16 −10 mobile_wallet/src/lib.rs
+4 −0 rust-bins/CHANGELOG.md
+4 −4 rust-bins/Cargo.lock
+1 −1 rust-bins/Cargo.toml
+0 −115 rust-bins/data-generation-notes.md
+3 −3 rust-bins/src/bin/client.rs
+5 −5 rust-bins/src/bin/generate_testdata.rs
+0 −438 rust-bins/src/bin/genesis_tool.rs
+3 −7 rust-bins/src/bin/user_cli.rs
+303 −266 rust-src/Cargo.lock
+11 −0 rust-src/concordium_base/CHANGELOG.md
+13 −3 rust-src/concordium_base/benches/bulletproofs.rs
+2 −2 rust-src/concordium_base/benches/compute_message.rs
+16 −2 rust-src/concordium_base/benches/set_proof_bench.rs
+2 −2 rust-src/concordium_base/benches/verify_cdi.rs
+2 −38 rust-src/concordium_base/src/base.rs
+126 −10 rust-src/concordium_base/src/bulletproofs/range_proof.rs
+250 −35 rust-src/concordium_base/src/bulletproofs/set_membership_proof.rs
+246 −36 rust-src/concordium_base/src/bulletproofs/set_non_membership_proof.rs
+14 −17 rust-src/concordium_base/src/cis4_types.rs
+16 −1 rust-src/concordium_base/src/common/impls.rs
+47 −0 rust-src/concordium_base/src/common/serialize.rs
+18 −5 rust-src/concordium_base/src/common/types.rs
+2 −7 rust-src/concordium_base/src/constants.rs
+2 −74 rust-src/concordium_base/src/curve_arithmetic/bls12_381_instance.rs
+2 −11 rust-src/concordium_base/src/curve_arithmetic/mod.rs
+7 −0 rust-src/concordium_base/src/encrypted_transfers/proofs/generate_proofs.rs
+5 −3 rust-src/concordium_base/src/id/account_holder.rs
+6 −6 rust-src/concordium_base/src/id/chain.rs
+2 −2 rust-src/concordium_base/src/id/ffi.rs
+6 −0 rust-src/concordium_base/src/id/id_proof_types.rs
+77 −13 rust-src/concordium_base/src/id/id_prover.rs
+230 −20 rust-src/concordium_base/src/id/id_verifier.rs
+15 −4 rust-src/concordium_base/src/id/identity_provider.rs
+189 −0 rust-src/concordium_base/src/id/sigma_protocols/com_ineq.rs
+2 −0 rust-src/concordium_base/src/id/sigma_protocols/com_lin.rs
+1 −0 rust-src/concordium_base/src/id/sigma_protocols/mod.rs
+3 −3 rust-src/concordium_base/src/id/test.rs
+125 −89 rust-src/concordium_base/src/id/types.rs
+3 −2 rust-src/concordium_base/src/id/utils.rs
+77 −8 rust-src/concordium_base/src/transactions.rs
+35 −1 rust-src/concordium_base/src/web3id/did.rs
+671 −329 rust-src/concordium_base/src/web3id/mod.rs
+1 −1 rust-src/concordium_base_derive/Cargo.toml
+9 −5 rust-src/concordium_base_derive/src/lib.rs
+54 −48 rust-src/key_derivation/src/lib.rs
+119 −105 smart-contracts/wasm-chain-integration/Cargo.lock
+2 −2 smart-contracts/wasm-chain-integration/Cargo.toml
+3 −2 smart-contracts/wasm-chain-integration/src/constants.rs
+40 −28 smart-contracts/wasm-test/Cargo.lock
+1 −1 smart-contracts/wasm-transform/Cargo.toml
7 changes: 6 additions & 1 deletion packages/common/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Changelog

## Unreleased
## 9.1.0

### Added

Expand All @@ -14,6 +14,11 @@ Added a functions that handle conversions between CCD and micro CCD. The CCD amo

All function parameters now also accepts strings, these strings can use comma as a decimal seperator.


- `Web3StatementBuilder` function.
- `getVerifiablePresentation` function.
- Various helper methods for web3Id statements and verifiable presentations.

## 9.0.0

### Breaking changes
Expand Down
4 changes: 2 additions & 2 deletions packages/common/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@concordium/common-sdk",
"version": "9.0.0",
"version": "9.1.0-alpha.1",
"license": "Apache-2.0",
"engines": {
"node": ">=14.16.0"
Expand Down Expand Up @@ -52,7 +52,7 @@
"build-dev": "tsc"
},
"dependencies": {
"@concordium/rust-bindings": "1.1.0",
"@concordium/rust-bindings": "1.2.0-alpha.1",
"@grpc/grpc-js": "^1.3.4",
"@noble/ed25519": "^1.7.1",
"@protobuf-ts/runtime-rpc": "^2.8.2",
Expand Down
26 changes: 12 additions & 14 deletions packages/common/src/HdWallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@ import * as wasm from '@concordium/rust-bindings';
import { mnemonicToSeedSync, validateMnemonic } from '@scure/bip39';
import { wordlist } from '@scure/bip39/wordlists/english';
import { Buffer } from 'buffer/';
import { AttributesKeys, Network, CryptographicParameters } from './types';
import {
AttributesKeys,
Network,
CryptographicParameters,
ContractAddress,
} from './types';
import { isHex } from './util';

/**
Expand Down Expand Up @@ -153,38 +158,31 @@ export class ConcordiumHdWallet {
}

getVerifiableCredentialSigningKey(
issuer: ContractAddress,
verifiableCredentialIndex: number
): Buffer {
return Buffer.from(
wasm.getVerifiableCredentialSigningKey(
this.seedAsHex,
this.network,
issuer.index,
issuer.subindex,
verifiableCredentialIndex
),
'hex'
);
}

getVerifiableCredentialPublicKey(
issuer: ContractAddress,
verifiableCredentialIndex: number
): Buffer {
return Buffer.from(
wasm.getVerifiableCredentialPublicKey(
this.seedAsHex,
this.network,
verifiableCredentialIndex
),
'hex'
);
}

getVerifiableCredentialEncryptionKey(
verifiableCredentialIndex: number
): Buffer {
return Buffer.from(
wasm.getVerifiableCredentialEncryptionKey(
this.seedAsHex,
this.network,
issuer.index,
issuer.subindex,
verifiableCredentialIndex
),
'hex'
Expand Down
100 changes: 100 additions & 0 deletions packages/common/src/commonProofTypes.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
export interface StatementBuilder<ValueType, AttributeType> {
addRange(
attribute: AttributeType,
lower: ValueType,
upper: ValueType
): this;

addMembership(attribute: AttributeType, set: ValueType[]): this;

addNonMembership(attribute: AttributeType, set: ValueType[]): this;
revealAttribute(attribute: AttributeType): this;
getStatement(): GenericAtomicStatement<AttributeType, ValueType>[];
}

export const MIN_DATE = '18000101';
export const MAX_DATE = '99990101';
export const EU_MEMBERS = [
'AT',
'BE',
'BG',
'CY',
'CZ',
'DK',
'EE',
'FI',
'FR',
'DE',
'GR',
'HU',
'IE',
'IT',
'LV',
'LT',
'LU',
'MT',
'NL',
'PL',
'PT',
'RO',
'SK',
'SI',
'ES',
'SE',
'HR',
];

export enum StatementTypes {
RevealAttribute = 'RevealAttribute',
AttributeInSet = 'AttributeInSet',
AttributeNotInSet = 'AttributeNotInSet',
AttributeInRange = 'AttributeInRange',
}

type LaxStringEnum<E extends string> = `${E}`;

export type GenericRevealStatement<TagType> = {
type: LaxStringEnum<StatementTypes.RevealAttribute>;
attributeTag: TagType;
};

export type GenericMembershipStatement<TagType, ValueType> = {
type: LaxStringEnum<StatementTypes.AttributeInSet>;
attributeTag: TagType;
set: ValueType[];
};

export type GenericNonMembershipStatement<TagType, ValueType> = {
type: LaxStringEnum<StatementTypes.AttributeNotInSet>;
attributeTag: TagType;
set: ValueType[];
};

export type GenericRangeStatement<TagType, ValueType> = {
type: LaxStringEnum<StatementTypes.AttributeInRange>;
attributeTag: TagType;
lower: ValueType;
upper: ValueType;
};

export type GenericAtomicStatement<TagType, ValueType> =
| GenericRevealStatement<TagType>
| GenericMembershipStatement<TagType, ValueType>
| GenericNonMembershipStatement<TagType, ValueType>
| GenericRangeStatement<TagType, ValueType>;

export type RevealProof<ValueType> = {
type: StatementTypes.RevealAttribute;
proof: string;
attribute: ValueType;
};

// Type for proofs that do not have additional fields
export type GenericAtomicProof = {
type: Exclude<StatementTypes, StatementTypes.RevealAttribute>;
proof: string;
};

export type AtomicProof<ValueType> =
| RevealProof<ValueType>
| GenericAtomicProof;
69 changes: 20 additions & 49 deletions packages/common/src/idProofTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,43 +5,27 @@ import {
Network,
Versioned,
} from '.';
import {
AtomicProof,
GenericAtomicStatement,
GenericMembershipStatement,
GenericNonMembershipStatement,
GenericRangeStatement,
GenericRevealStatement,
} from './commonProofTypes';

export enum StatementTypes {
RevealAttribute = 'RevealAttribute',
AttributeInSet = 'AttributeInSet',
AttributeNotInSet = 'AttributeNotInSet',
AttributeInRange = 'AttributeInRange',
}

export type RevealStatement = {
type: StatementTypes.RevealAttribute;
attributeTag: AttributeKey;
};

export type MembershipStatement = {
type: StatementTypes.AttributeInSet;
attributeTag: AttributeKey;
set: string[];
};

export type NonMembershipStatement = {
type: StatementTypes.AttributeNotInSet;
attributeTag: AttributeKey;
set: string[];
};

export type RangeStatement = {
type: StatementTypes.AttributeInRange;
attributeTag: AttributeKey;
lower: string;
upper: string;
};
export type RangeStatement = GenericRangeStatement<AttributeKey, string>;
export type NonMembershipStatement = GenericNonMembershipStatement<
AttributeKey,
string
>;
export type MembershipStatement = GenericMembershipStatement<
AttributeKey,
string
>;
export type RevealStatement = GenericRevealStatement<AttributeKey>;

export type AtomicStatement =
| RevealStatement
| MembershipStatement
| NonMembershipStatement
| RangeStatement;
export type AtomicStatement = GenericAtomicStatement<AttributeKey, string>;
export type IdStatement = AtomicStatement[];

export type IdProofInput = {
Expand All @@ -56,21 +40,8 @@ export type IdProofInput = {
challenge: string; // Hex
};

export type RevealProof = {
type: StatementTypes.RevealAttribute;
proof: string;
attribute: string;
};

// Type for proofs that do not have additional fields
export type GenericAtomicProof = {
type: Exclude<StatementTypes, StatementTypes.RevealAttribute>;
proof: string;
};

export type AtomicProof = RevealProof | GenericAtomicProof;
export type IdProof = {
proofs: AtomicProof[];
proofs: AtomicProof<string>[];
};

export type IdProofOutput = {
Expand Down
39 changes: 6 additions & 33 deletions packages/common/src/idProofs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,42 +13,15 @@ import {
MembershipStatement,
NonMembershipStatement,
RangeStatement,
StatementTypes,
} from './idProofTypes';
import {
EU_MEMBERS,
MAX_DATE,
MIN_DATE,
StatementTypes,
} from './commonProofTypes';
import { whereAlpha2 } from 'iso-3166-1';

export const MIN_DATE = '18000101';
export const MAX_DATE = '99990101';
export const EU_MEMBERS = [
'AT',
'BE',
'BG',
'CY',
'CZ',
'DK',
'EE',
'FI',
'FR',
'DE',
'GR',
'HU',
'IE',
'IT',
'LV',
'LT',
'LU',
'MT',
'NL',
'PL',
'PT',
'RO',
'SK',
'SI',
'ES',
'SE',
'HR',
];

/**
* Given a number x, return the date string for x years ago.
* @param yearsAgo how many years to go back from today
Expand Down
14 changes: 13 additions & 1 deletion packages/common/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,27 @@ export {
deserializeInitError,
deserializeTypeValue,
} from './deserialization';
export * from './idProofs';

export {
StatementTypes,
StatementBuilder,
MIN_DATE,
MAX_DATE,
EU_MEMBERS,
} from './commonProofTypes';
export * from './idProofTypes';
export * from './idProofs';
export * from './web3ProofTypes';
export * from './web3Proofs';

export * from './signHelpers';
export * from './versionedTypeHelpers';
export * from './accountHelpers';
export * from './blockSummaryHelpers';
export * from './rewardStatusHelpers';
export * from './HdWallet';
export * from './schemaHelpers';
export * from './web3IdHelpers';

export { getContractName } from './contractHelpers';
export { isHex, streamToList, wasmToSchema, unwrap } from './util';
Expand Down
23 changes: 23 additions & 0 deletions packages/common/src/web3IdHelpers.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import * as wasm from '@concordium/rust-bindings';
import { stringify } from 'json-bigint';
import { ContractAddress, CryptographicParameters } from './types';

export type VerifyWeb3IdCredentialSignatureInput = {
globalContext: CryptographicParameters;
signature: string;
values: Record<string, string | bigint>;
randomness: Record<string, string>;
holder: string;
issuerPublicKey: string;
issuerContract: ContractAddress;
};

/**
* Verifies that the given signature is correct for the given values/randomness/holder/issuerPublicKey/issuerContract
*/
export function verifyWeb3IdCredentialSignature(
input: VerifyWeb3IdCredentialSignatureInput
): boolean {
// Use json-bigint stringify to ensure we can handle bigints
return wasm.verifyWeb3IdCredentialSignature(stringify(input));
}
Loading

0 comments on commit 5eb8f77

Please sign in to comment.