From 4ddb5b645d6736a422eb9eb19f5bacba4f697f15 Mon Sep 17 00:00:00 2001 From: Dawid Sowa Date: Thu, 10 Oct 2024 17:12:28 +0200 Subject: [PATCH] feat: extend sandbox with PoO request PoO - proof of ownership --- .../src/data-request/PersonaDataCard.tsx | 1 - .../one-time-data-request/AccountsProof.tsx | 92 +++++++++++++++++++ .../OneTimeDataRequestsPage.tsx | 65 ++++++++++++- .../one-time-data-request/PersonaProof.tsx | 49 ++++++++++ package-lock.json | 34 +++++-- packages/common/package.json | 2 +- 6 files changed, 231 insertions(+), 12 deletions(-) create mode 100644 apps/sandbox/src/one-time-data-request/AccountsProof.tsx create mode 100644 apps/sandbox/src/one-time-data-request/PersonaProof.tsx diff --git a/apps/sandbox/src/data-request/PersonaDataCard.tsx b/apps/sandbox/src/data-request/PersonaDataCard.tsx index 61c12b8bc..91b5fe84d 100644 --- a/apps/sandbox/src/data-request/PersonaDataCard.tsx +++ b/apps/sandbox/src/data-request/PersonaDataCard.tsx @@ -76,7 +76,6 @@ export const PersonaDataCard = () => { ) } )} - ; void +}) => { + const enabled = !!state.enabled + return ( + { + updateState({ ...state, enabled: ev.target.checked }) + }} + /> + } + > + + + {state.data.addresses.map((address, index) => ( + + { + const addresses = [...state.data.addresses] + addresses[index] = ev.target.value + updateState({ + ...state, + data: { + addresses + } + }) + }} + /> + + + ))} + + + ) +} diff --git a/apps/sandbox/src/one-time-data-request/OneTimeDataRequestsPage.tsx b/apps/sandbox/src/one-time-data-request/OneTimeDataRequestsPage.tsx index cf12d4939..2eb137fb6 100644 --- a/apps/sandbox/src/one-time-data-request/OneTimeDataRequestsPage.tsx +++ b/apps/sandbox/src/one-time-data-request/OneTimeDataRequestsPage.tsx @@ -12,6 +12,8 @@ import { OneTimeDataRequestBuilderItem } from '@common/rdt' import { useState } from 'react' +import { PersonaProofCard } from './PersonaProof' +import { AccountsProofCard } from './AccountsProof' export const OneTimeDataRequestsPage = () => { const [state, setState] = useState<{ accounts: { @@ -32,6 +34,18 @@ export const OneTimeDataRequestsPage = () => { phoneNumbers: boolean } } + personaProof: { + enabled: boolean + data: { + address: string + } + } + accountsProof: { + enabled: boolean + data: { + addresses: string[] + } + } }>({ accounts: { enabled: true, @@ -47,6 +61,18 @@ export const OneTimeDataRequestsPage = () => { emailAddresses: false, phoneNumbers: false } + }, + personaProof: { + enabled: false, + data: { + address: '' + } + }, + accountsProof: { + enabled: false, + data: { + addresses: [] + } } }) @@ -54,7 +80,8 @@ export const OneTimeDataRequestsPage = () => { @@ -77,6 +104,25 @@ export const OneTimeDataRequestsPage = () => { }} /> + + { + setState((prev) => ({ ...prev, personaProof })) + }} + /> + { + setState((prev) => ({ ...prev, accountsProof })) + }} + /> + { dataRequest.push(personaDataRequest) } + if ( + state.personaProof.enabled || + state.accountsProof.enabled + ) { + let poo = OneTimeDataRequestBuilder.proofOfOwnership() + dataRequest.push( + state.accountsProof.enabled + ? (state.personaProof.enabled + ? poo.identity(state.personaProof.data.address) + : poo + ).accounts( + state.accountsProof.data.addresses.filter(Boolean) + ) + : poo + ) + } + rdt.walletApi.sendOneTimeRequest(...dataRequest) }} sx={{ alignSelf: 'center', width: '150px' }} diff --git a/apps/sandbox/src/one-time-data-request/PersonaProof.tsx b/apps/sandbox/src/one-time-data-request/PersonaProof.tsx new file mode 100644 index 000000000..cb603c5bb --- /dev/null +++ b/apps/sandbox/src/one-time-data-request/PersonaProof.tsx @@ -0,0 +1,49 @@ +import Box from '@mui/joy/Box' +import Checkbox from '@mui/joy/Checkbox' +import { Card } from '../components/Card' +import { Input } from '@mui/joy' + +export const PersonaProofCard = ({ + state, + updateState +}: { + state: { + enabled: boolean + data: { + address: string + } + } + updateState: (state: { + enabled: boolean + data: { + address: string + } + }) => void +}) => { + const enabled = !!state.enabled + return ( + { + updateState({ ...state, enabled: ev.target.checked }) + }} + /> + } + > + + { + updateState({ + ...state, + data: { address: event.target.value.toString() } + }) + }} + /> + + + ) +} diff --git a/package-lock.json b/package-lock.json index ea66c9837..a3e23cdba 100644 --- a/package-lock.json +++ b/package-lock.json @@ -8913,9 +8913,9 @@ } }, "node_modules/@radixdlt/radix-dapp-toolkit": { - "version": "2.1.1", - "resolved": "https://registry.npmjs.org/@radixdlt/radix-dapp-toolkit/-/radix-dapp-toolkit-2.1.1.tgz", - "integrity": "sha512-HgKio/tDY31/E/t+eF/4B1xPiOdQRhxgR+sZ4nKmFPQPEgTfkckrvaIgkYnI4NfZfuQC/Nb+ODSimKIWSzkNHw==", + "version": "2.2.0-dev.5", + "resolved": "https://registry.npmjs.org/@radixdlt/radix-dapp-toolkit/-/radix-dapp-toolkit-2.2.0-dev.5.tgz", + "integrity": "sha512-3X63N1Ld7yd6mx8/VcWXQAUdYLbV6/ERd0hWJqYXq+nNtUhJDS+d1pn6OVbR3+5/VK8nGA6tSys+L+6qs5FvEA==", "dependencies": { "@noble/curves": "^1.4.0", "base64url": "^3.0.1", @@ -8925,11 +8925,11 @@ "immer": "^10.0.4", "lit": "^3.1.2", "lit-html": "^3.1.2", - "neverthrow": "^6.1.0", + "neverthrow": "^8.0.0", "rxjs": "^7.8.1", "tslog": ">=4.8.0", "uuid": "^10.0.0", - "valibot": "0.30.0" + "valibot": "0.42.1" }, "engines": { "node": ">=18" @@ -8994,6 +8994,14 @@ "@types/trusted-types": "^2.0.2" } }, + "node_modules/@radixdlt/radix-dapp-toolkit/node_modules/neverthrow": { + "version": "8.0.0", + "resolved": "https://registry.npmjs.org/neverthrow/-/neverthrow-8.0.0.tgz", + "integrity": "sha512-SX2Z50+U27I+CF3NwHE9J8MB6+bYRRub3U+1nAKxnL6c+2vW2l/WsYEC0e3Wqg8DwiJvrquqE0YhxlVTzGJGsg==", + "engines": { + "node": ">=18" + } + }, "node_modules/@radixdlt/radix-dapp-toolkit/node_modules/uuid": { "version": "10.0.0", "resolved": "https://registry.npmjs.org/uuid/-/uuid-10.0.0.tgz", @@ -31326,9 +31334,17 @@ } }, "node_modules/valibot": { - "version": "0.30.0", - "resolved": "https://registry.npmjs.org/valibot/-/valibot-0.30.0.tgz", - "integrity": "sha512-5POBdbSkM+3nvJ6ZlyQHsggisfRtyT4tVTo1EIIShs6qCdXJnyWU5TJ68vr8iTg5zpOLjXLRiBqNx+9zwZz/rA==" + "version": "0.42.1", + "resolved": "https://registry.npmjs.org/valibot/-/valibot-0.42.1.tgz", + "integrity": "sha512-3keXV29Ar5b//Hqi4MbSdV7lfVp6zuYLZuA9V1PvQUsXqogr+u5lvLPLk3A4f74VUXDnf/JfWMN6sB+koJ/FFw==", + "peerDependencies": { + "typescript": ">=5" + }, + "peerDependenciesMeta": { + "typescript": { + "optional": true + } + } }, "node_modules/validate-npm-package-license": { "version": "3.0.4", @@ -32236,7 +32252,7 @@ "@floating-ui/dom": "^1.5.3", "@radixdlt/babylon-core-api-sdk": "^1.2.3", "@radixdlt/babylon-gateway-api-sdk": "^1.7.3", - "@radixdlt/radix-dapp-toolkit": "^2.1.1", + "@radixdlt/radix-dapp-toolkit": "2.2.0-dev.5", "@radixdlt/radix-engine-toolkit": "^1.0.5", "@radixdlt/rola": "^2.0.0", "dayjs": "^1.11.10", diff --git a/packages/common/package.json b/packages/common/package.json index 099539746..6caadace2 100644 --- a/packages/common/package.json +++ b/packages/common/package.json @@ -7,7 +7,7 @@ "@floating-ui/dom": "^1.5.3", "@radixdlt/babylon-core-api-sdk": "^1.2.3", "@radixdlt/babylon-gateway-api-sdk": "^1.7.3", - "@radixdlt/radix-dapp-toolkit": "^2.1.1", + "@radixdlt/radix-dapp-toolkit": "2.2.0-dev.5", "@radixdlt/radix-engine-toolkit": "^1.0.5", "@radixdlt/rola": "^2.0.0", "dayjs": "^1.11.10",