Skip to content

Commit

Permalink
feat: use @radixdlt/rola + update to RCNet V3
Browse files Browse the repository at this point in the history
  • Loading branch information
dawidsowardx committed Sep 5, 2023
1 parent dcc1d0f commit c4eddba
Show file tree
Hide file tree
Showing 15 changed files with 82 additions and 372 deletions.
45 changes: 23 additions & 22 deletions examples/typescript-full-stack/apps/client/src/main.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import "./style.css";
import typescriptLogo from "./typescript.svg";
import radixLogo from "/radix-icon_128x128.png";
import './style.css'
import typescriptLogo from './typescript.svg'
import radixLogo from '/radix-icon_128x128.png'
import {
DataRequestBuilder,
RadixDappToolkit,
} from "@radixdlt/radix-dapp-toolkit";
RadixNetwork,
} from '@radixdlt/radix-dapp-toolkit'

document.querySelector<HTMLDivElement>("#app")!.innerHTML = `
document.querySelector<HTMLDivElement>('#app')!.innerHTML = `
<div>
<a href="https://github.com/radixdlt/radix-dapp-toolkit" target="_blank">
<img src="${radixLogo}" class="logo" alt="Radix logo" />
Expand All @@ -21,43 +22,43 @@ document.querySelector<HTMLDivElement>("#app")!.innerHTML = `
Click on the Radix and TypeScript logos to learn more
</p>
</div>
`;
`

const radixDappToolkit = RadixDappToolkit({
dAppDefinitionAddress:
"account_tdx_d_12xxwkx4fmz680e9wz8atdnyslr9vt7x9qvcfxhtqfnpfhxyjzwtyna",
networkId: 13,
});
'account_tdx_e_1285lfp3kwjnyu5esdsy7u9j0482tsw8fj3tnj95gjsgj6qa23yarx8',
networkId: RadixNetwork.RCnetV3,
})

// Clear the dApp state for example purposes
setTimeout(() => {
radixDappToolkit.disconnect();
});
radixDappToolkit.disconnect()
})

radixDappToolkit.walletApi.setRequestData(
DataRequestBuilder.persona().withProof(),
DataRequestBuilder.accounts().atLeast(1).withProof()
);
)

const getChallenge: () => Promise<string> = () =>
fetch("http://localhost:3000/create-challenge")
fetch('http://localhost:3000/create-challenge')
.then((res) => res.json())
.then((res) => res.challenge);
.then((res) => res.challenge)

radixDappToolkit.walletApi.provideChallengeGenerator(getChallenge);
radixDappToolkit.walletApi.provideChallengeGenerator(getChallenge)

const rolaResultElement = document.getElementById("rola-result")!;
const rolaResultElement = document.getElementById('rola-result')!

radixDappToolkit.walletApi.dataRequestControl(async ({ proofs }) => {
const { valid } = await fetch("http://localhost:3000/verify", {
method: "POST",
const { valid } = await fetch('http://localhost:3000/verify', {
method: 'POST',
body: JSON.stringify(proofs),
headers: { "content-type": "application/json" },
}).then((res): Promise<{ valid: boolean }> => res.json());
headers: { 'content-type': 'application/json' },
}).then((res): Promise<{ valid: boolean }> => res.json())

rolaResultElement.innerHTML = JSON.stringify(
proofs.map((item) => ({ ...item, rolaVerified: valid })),
null,
2
);
});
)
})
1 change: 0 additions & 1 deletion examples/typescript-full-stack/apps/client/src/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,5 @@ button:focus-visible {

pre {
text-align: left;
background: black;
padding: 1rem;
}
1 change: 1 addition & 0 deletions examples/typescript-full-stack/apps/server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"license": "MIT",
"dependencies": {
"@radixdlt/radix-dapp-toolkit": "0.6.1",
"@radixdlt/rola": "0.2.1",
"@radixdlt/radix-engine-toolkit": "0.3.0",
"@types/cors": "^2.8.13",
"@types/elliptic": "^6.4.14",
Expand Down
17 changes: 8 additions & 9 deletions examples/typescript-full-stack/apps/server/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import express from 'express'
import { secureRandom } from './rola/crypto/secure-random'
import { SignedChallenge } from '@radixdlt/radix-dapp-toolkit'
import { RolaFactory } from './rola/rola'
import { secureRandom } from './secure-random'
import cors from 'cors'
import { GatewayService } from './rola/gateway'
import { Rola } from '@radixdlt/rola'
import { SignedChallenge, RadixNetwork } from '@radixdlt/radix-dapp-toolkit'
import { ResultAsync } from 'neverthrow'

const app = express()
Expand Down Expand Up @@ -40,11 +39,11 @@ const ChallengeStore = () => {

const challengeStore = ChallengeStore()

const rola = RolaFactory({
gatewayService: GatewayService('https://ansharnet-gateway.radixdlt.com'), // gateway service to query the ledger
const { verifySignedChallenge } = Rola({
applicationName: 'Rola Full Stack Typescript Example',
dAppDefinitionAddress:
'account_tdx_d_12xxwkx4fmz680e9wz8atdnyslr9vt7x9qvcfxhtqfnpfhxyjzwtyna', // address of the dApp definition
networkId: 13, // network id of the Radix network
'account_tdx_e_1285lfp3kwjnyu5esdsy7u9j0482tsw8fj3tnj95gjsgj6qa23yarx8', // address of the dApp definition
networkId: RadixNetwork.RCnetV3, // network id of the Radix network
expectedOrigin: 'http://localhost:4000', // origin of the client making the wallet request
})

Expand All @@ -67,7 +66,7 @@ app.post<{}, { valid: boolean }, SignedChallenge[]>(
if (!isChallengeValid) return res.send({ valid: false })

const result = await ResultAsync.combine(
req.body.map((signedChallenge) => rola(signedChallenge))
req.body.map((signedChallenge) => verifySignedChallenge(signedChallenge))
)

if (result.isErr()) return res.send({ valid: false })
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

24 changes: 0 additions & 24 deletions examples/typescript-full-stack/apps/server/src/rola/gateway.ts

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Loading

0 comments on commit c4eddba

Please sign in to comment.