Skip to content

Commit

Permalink
Merge branch 'main' into transaction-payloads-json
Browse files Browse the repository at this point in the history
  • Loading branch information
lassemoldrup committed Jan 30, 2024
2 parents 3e315e1 + 3bb69dd commit 59b47ee
Show file tree
Hide file tree
Showing 37 changed files with 1,777 additions and 1,088 deletions.
2 changes: 1 addition & 1 deletion deps/concordium-base
Submodule concordium-base updated 217 files
35 changes: 35 additions & 0 deletions examples/wallet/src/ConfirmIdentity.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import React, { useEffect, useState } from 'react';
import { useLocation, useNavigate } from 'react-router-dom';
import { extractIdentityObjectUrl, fetchIdentity } from './util';
import { identityObjectKey } from './constants';

export function ConfirmIdentity() {
const location = useLocation();
const [error, setError] = useState<string>();
const navigate = useNavigate();

useEffect(() => {
const identityObjectUrl = extractIdentityObjectUrl(location.hash);
fetchIdentity(identityObjectUrl)
.then((raw) => {
localStorage.setItem(identityObjectKey, JSON.stringify(raw));
navigate('/identity');
})
.catch(setError);
}, [location.hash]);

if (error) {
return (
<div>
<h3>Identity creation failed</h3>
<div>{error}</div>
</div>
);
}

return (
<>
<h3>Identity is not ready yet. Please wait.</h3>
</>
);
}
33 changes: 24 additions & 9 deletions examples/wallet/src/CreateAccount.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import React, { useMemo, useState } from 'react';
import { useNavigate } from 'react-router-dom';
import { mnemonicToSeedSync } from '@scure/bip39';
import { Buffer } from 'buffer/';
import { AccountWorkerInput } from './types';
import {
credNumber,
Expand All @@ -16,10 +14,11 @@ import {
getCryptographicParameters,
getIdentityProviders,
getDefaultTransactionExpiry,
createCredentialDeploymentKeysAndRandomness,
} from './util';
import {
CredentialDeploymentTransaction,
CredentialInput,
CredentialInputNoSeed,
IdentityObjectV1,
getAccountAddress,
signCredentialTransaction,
Expand Down Expand Up @@ -79,19 +78,35 @@ export function CreateAccount({ identity }: { identity: IdentityObjectV1 }) {
});

const global = await getCryptographicParameters();
const credentialInput: CredentialInput = {
net: network,

const {
idCredSec,
prfKey,
attributeRandomness,
blindingRandomness,
credentialPublicKeys,
} = createCredentialDeploymentKeysAndRandomness(
seedPhrase,
network,
selectedIdentityProvider.ipInfo.ipIdentity,
identityIndex,
credNumber
);

const credentialInput: CredentialInputNoSeed = {
revealedAttributes: [],
seedAsHex: Buffer.from(mnemonicToSeedSync(seedPhrase)).toString(
'hex'
),
idObject: identity,
identityIndex,
globalContext: global,
credNumber,
ipInfo: selectedIdentityProvider.ipInfo,
arsInfos: selectedIdentityProvider.arsInfos,
attributeRandomness,
credentialPublicKeys,
idCredSec,
prfKey,
sigRetrievelRandomness: blindingRandomness,
};

const expiry = getDefaultTransactionExpiry();
const workerInput: AccountWorkerInput = {
credentialInput,
Expand Down
31 changes: 24 additions & 7 deletions examples/wallet/src/CreateIdentity.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import React, { useEffect, useMemo, useState } from 'react';
import { useNavigate } from 'react-router-dom';
import {
ConcordiumHdWallet,
CryptographicParameters,
IdObjectRequestV1,
IdentityRequestInput,
IdentityRequestWithKeysInput,
Versioned,
} from '@concordium/web-sdk';
import { IdentityProviderWithMetadata } from './types';
Expand All @@ -14,8 +15,6 @@ import {
getRedirectUri,
sendIdentityRequest,
} from './util';
import { mnemonicToSeedSync } from '@scure/bip39';
import { Buffer } from 'buffer/';
import {
identityIndex,
network,
Expand Down Expand Up @@ -87,22 +86,40 @@ export function CreateIdentity() {
worker.removeEventListener('message', listener);
});

const identityRequestInput: IdentityRequestInput = {
net: network,
seed: Buffer.from(mnemonicToSeedSync(seedPhrase)).toString('hex'),
identityIndex,
// Derive the required secret key material.
const wallet = ConcordiumHdWallet.fromSeedPhrase(seedPhrase, network);
const identityProviderIndex =
selectedIdentityProvider.ipInfo.ipIdentity;
const idCredSec = wallet
.getIdCredSec(identityProviderIndex, identityIndex)
.toString('hex');
const prfKey = wallet
.getPrfKey(identityProviderIndex, identityIndex)
.toString('hex');
const blindingRandomness = wallet
.getSignatureBlindingRandomness(
identityProviderIndex,
identityIndex
)
.toString('hex');

const identityRequestInput: IdentityRequestWithKeysInput = {
arsInfos: selectedIdentityProvider.arsInfos,
arThreshold: determineAnonymityRevokerThreshold(
Object.keys(selectedIdentityProvider.arsInfos).length
),
ipInfo: selectedIdentityProvider.ipInfo,
globalContext: cryptographicParameters,
idCredSec,
prfKey,
blindingRandomness,
};
worker.postMessage(identityRequestInput);
}

return (
<div>
<h3>Identity Issuance</h3>
<label>
Select an identity provider
<select
Expand Down
36 changes: 12 additions & 24 deletions examples/wallet/src/Identity.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { AttributeList, IdentityObjectV1 } from '@concordium/web-sdk';
import React, { useEffect, useState } from 'react';
import { useLocation } from 'react-router-dom';
import { extractIdentityObjectUrl, fetchIdentity } from './util';
import React, { useMemo, useState } from 'react';
import { CreateAccount } from './CreateAccount';
import { identityObjectKey } from './constants';

function DisplayIdentity({ attributes }: { attributes: AttributeList }) {
return (
Expand All @@ -17,31 +16,20 @@ function DisplayIdentity({ attributes }: { attributes: AttributeList }) {
}

export function Identity() {
const location = useLocation();
const [identity, setIdentity] = useState<IdentityObjectV1>();
const [error, setError] = useState<string>();

useEffect(() => {
const identityObjectUrl = extractIdentityObjectUrl(location.hash);

// To be able to create an account the identity is required. In a production
// wallet the identity should be persisted, and not only kept in memory as in this
// example.
fetchIdentity(identityObjectUrl).then(setIdentity).catch(setError);
}, [location.hash]);

if (error) {
return (
<div>
<h3>Identity creation failed</h3>
<div>{error}</div>
</div>
);
}
const [missingIdentity, setMissingIdentity] = useState<boolean>(false);
const identity = useMemo<IdentityObjectV1>(() => {
const identityObjectJson = localStorage.getItem(identityObjectKey);
if (identityObjectJson) {
return JSON.parse(identityObjectJson);
} else {
setMissingIdentity(true);
}
}, []);

return (
<>
<h3>Your Concordium identity</h3>
{missingIdentity && <h3>Missing identity in storage</h3>}
{identity && (
<>
<DisplayIdentity attributes={identity.attributeList} />
Expand Down
15 changes: 15 additions & 0 deletions examples/wallet/src/Index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ import { Identity } from './Identity';
import { Account } from './Account';
import { CreateIdentity } from './CreateIdentity';
import { SetupSeedPhrase } from './Setup';
import { RecoverIdentity } from './RecoverIdentity';
import { ConfirmIdentity } from './ConfirmIdentity';
import { NewIdentity } from './NewIdentity';

const container = document.getElementById('root');

Expand All @@ -18,14 +21,26 @@ const router = createBrowserRouter([
path: '/',
element: <SetupSeedPhrase />,
},
{
path: '/new',
element: <NewIdentity />,
},
{
path: '/create',
element: <CreateIdentity />,
},
{
path: '/confirm-identity',
element: <ConfirmIdentity />,
},
{
path: '/identity',
element: <Identity />,
},
{
path: '/recover',
element: <RecoverIdentity />,
},
{
path: '/account/:accountAddress',
element: <Account />,
Expand Down
17 changes: 17 additions & 0 deletions examples/wallet/src/NewIdentity.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import React from 'react';
import { useNavigate } from 'react-router-dom';

export function NewIdentity() {
const navigate = useNavigate();
return (
<div>
<h3>Your Concordium Identity</h3>
<button onClick={() => navigate('/create')}>
Create new identity
</button>
<button onClick={() => navigate('/recover')}>
Recover existing identity
</button>
</div>
);
}
Loading

0 comments on commit 59b47ee

Please sign in to comment.