Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Relayer: Introduce Relayer.GenerateAAT #98

Merged
merged 1 commit into from
Mar 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import {
MAINNET_RPC_URL,
DISPATCHERS,
RELAY_DATA,
POCKET_AAT,
} from "./config.js";

// Instantiate a provider for querying information on the chain!
Expand Down Expand Up @@ -53,7 +52,7 @@ export const transactionBuilder = new TransactionBuilder({

// Create a new `Send` Message which is used to send funds over the network.
const sendMsg = transactionBuilder.send(
signer.getAddress(),
signer.getAddress(),
"07a6fca4dea9f01e4c19f301df0d0afac128561b",
// Amount in uPOKT (1 POKT = 1*10^6 uPOKT)
"1000000"
Expand All @@ -76,10 +75,14 @@ const session = await relayer.getNewSession({
applicationPubKey: process.env.APP_PUBLIC_KEY,
});

const appSigner = await KeyManager.fromPrivateKey(process.env.APP_PRIVATE_KEY);
const clientSigner = await KeyManager.createRandom();
const aat = await Relayer.GenerateAAT(appSigner, clientSigner.publicKey);

const relay = await relayer.relay({
data: process.env.RELAY_DATA,
blockchain: process.env.APP_CHAIN,
pocketAAT: POCKET_AAT,
pocketAAT: aat,
session: session,
});
```
Expand Down
15 changes: 15 additions & 0 deletions packages/relayer/src/relayer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -358,4 +358,19 @@ export class Relayer implements AbstractRelayer {
max = Math.floor(max)
return Math.floor(randomNumber * (max - min + 1)) + min
}

static async GenerateAAT(
applicationPrivKey: KeyManager,
clientPubKey: string,
): Promise<PocketAAT> {
const aat = {
version: "0.0.1",
applicationPublicKey: applicationPrivKey.getPublicKey(),
clientPublicKey: clientPubKey,
applicationSignature: "",
};
const hash = this.hashAAT(aat);
aat.applicationSignature = await applicationPrivKey.sign(hash);
return aat;
}
}
Loading