Skip to content

Commit

Permalink
change(vos-pass): add updates on challenger and account used for `SES…
Browse files Browse the repository at this point in the history
…SION_KEY`
  • Loading branch information
pandres95 committed Nov 29, 2024
1 parent 05cca24 commit 0c9c765
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 11 deletions.
10 changes: 4 additions & 6 deletions vos-pass/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,10 @@ export class Pass {
static async generateChallenge(
api: ApiPromise
): Promise<[Uint8Array, Compact<BlockNumber>]> {
const block = await api.rpc.chain.getBlock();
const blockNumber = block.block.header.number;
const blockNumberBytes = blockNumber.toBn().toBuffer("le");

const hashed = await hash.blake2b(blockNumberBytes, 256);
return [hexToU8a(`0x${hashed}`), blockNumber];
const {
block: { header },
} = await api.rpc.chain.getBlock();
return [header.hash, header.number];
}

constructor(private api: ApiPromise) {}
Expand Down
9 changes: 4 additions & 5 deletions vos-pass/tests/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// deno-lint-ignore-file no-explicit-any
import { ApiPromise, Keyring } from "@polkadot/api";
import { Blockchain, setStorage } from "npm:@acala-network/chopsticks";
import type {
Expand Down Expand Up @@ -123,7 +122,6 @@ describe("Pass", opts, () => {
// Define origin and user information
const user = {
id: hashedUserId,
name: "testuser",
displayName: "Test User",
};

Expand All @@ -135,7 +133,6 @@ describe("Pass", opts, () => {
},
user: {
id: user.id,
name: user.name,
displayName: user.displayName,
},
challenge,
Expand Down Expand Up @@ -172,6 +169,7 @@ describe("Pass", opts, () => {
const ALICE = KEYRING.addFromUri("//Alice");
const result = await signSendAndWait(tx, ALICE);

// Verification
expect(result.events).toContainEqual({
event: {
method: "Registered",
Expand Down Expand Up @@ -225,9 +223,10 @@ describe("Pass", opts, () => {
new Uint8Array(assertionResponse.response.signature)
);

const SESSION_KEY = KEYRING.addFromUri("//Alice");
const SESSION_KEY = KEYRING.addFromUri("//Bob");
const result = await signSendAndWait(tx, SESSION_KEY);

// Verification
expect(result.events).toContainEqual({
event: {
section: "pass",
Expand Down Expand Up @@ -258,7 +257,7 @@ describe("Pass", opts, () => {
});

// We'll use the previously used session key.
const SESSION_KEY = KEYRING.addFromUri("//Alice");
const SESSION_KEY = KEYRING.addFromUri("//Bob");
const SESSION_KEY_FREE_AMOUNT = await kreivoApi.query.system.account(
SESSION_KEY.address
);
Expand Down

0 comments on commit 0c9c765

Please sign in to comment.