Skip to content

Commit

Permalink
Merge pull request #2454 from WalletConnect/feat/random-session-ident…
Browse files Browse the repository at this point in the history
…ifier

feat: random session identifier
  • Loading branch information
ganchoradkov authored Jun 19, 2024
2 parents 9702919 + 5c12c91 commit 5899f27
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 1 deletion.
3 changes: 2 additions & 1 deletion packages/core/src/controllers/crypto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import { KeyChain } from "./keychain";
export class Crypto implements ICrypto {
public name = CRYPTO_CONTEXT;
public keychain: ICrypto["keychain"];
public readonly randomSessionIdentifier = generateRandomBytes32();

private initialized = false;

Expand Down Expand Up @@ -69,7 +70,7 @@ export class Crypto implements ICrypto {
this.isInitialized();
const seed = await this.getClientSeed();
const keyPair = relayAuth.generateKeyPair(seed);
const sub = generateRandomBytes32();
const sub = this.randomSessionIdentifier;
const ttl = CRYPTO_JWT_TTL;
const jwt = await relayAuth.signJWT(sub, aud, ttl, keyPair);
return jwt;
Expand Down
3 changes: 3 additions & 0 deletions packages/core/test/relayer.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -269,10 +269,13 @@ describe("Relayer", () => {
});

it("should restart transport after connection drop", async () => {
const randomSessionIdentifier = relayer.core.crypto.randomSessionIdentifier;
await relayer.provider.connection.close();
expect(relayer.connected).to.be.false;
await relayer.restartTransport();
expect(relayer.connected).to.be.true;
// the identifier should be the same
expect(relayer.core.crypto.randomSessionIdentifier).to.eq(randomSessionIdentifier);
});

it("should close transport 10 seconds after init if NOT active", async () => {
Expand Down
2 changes: 2 additions & 0 deletions packages/types/src/core/crypto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ export abstract class ICrypto {

public abstract keychain: IKeyChain;

public abstract readonly randomSessionIdentifier: string;

constructor(
public core: ICore,
public logger: Logger,
Expand Down

0 comments on commit 5899f27

Please sign in to comment.