Skip to content

Commit

Permalink
Add test for SingleSignOnEIP4361AuthProvider.
Browse files Browse the repository at this point in the history
  • Loading branch information
derekpierre committed Aug 19, 2024
1 parent fade5ec commit 1d05688
Showing 1 changed file with 37 additions and 4 deletions.
41 changes: 37 additions & 4 deletions packages/taco-auth/test/auth-provider.test.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
import {
bobSecretKeyBytes,
fakeProvider,
fakeSigner,
TEST_SIWE_PARAMS,
} from '@nucypher/test-utils';
import { SiweMessage } from 'siwe';
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';

import { EIP4361AuthProvider } from '../src/providers';
import {
EIP4361AuthProvider,
SingleSignOnEIP4361AuthProvider,
} from '../src/providers';
import { EIP4361TypedDataSchema } from '../src/providers/eip4361/common';

describe('auth provider', () => {
const provider = fakeProvider(bobSecretKeyBytes);
const signer = fakeSigner(bobSecretKeyBytes);
const signer = provider.getSigner();
const eip4361Provider = new EIP4361AuthProvider(
provider,
signer,
Expand Down Expand Up @@ -65,7 +67,7 @@ describe('auth provider caching', () => {
});

const provider = fakeProvider(bobSecretKeyBytes);
const signer = fakeSigner(bobSecretKeyBytes);
const signer = provider.getSigner();
const eip4361Provider = new EIP4361AuthProvider(
provider,
signer,
Expand Down Expand Up @@ -99,3 +101,34 @@ describe('auth provider caching', () => {
expect(typedSignatureThirdCall).not.toEqual(typedSignature);
});
});

describe('single sign-on auth provider', async () => {
const provider = fakeProvider(bobSecretKeyBytes);
const signer = provider.getSigner();

const eip4361Provider = new EIP4361AuthProvider(
provider,
signer,
TEST_SIWE_PARAMS,
);
const originalTypedSignature =
await eip4361Provider.getOrCreateAuthSignature();

it('use existing SIWE message', async () => {
const originalSiweMessage = originalTypedSignature.typedData;
const originalSiweSignature = originalTypedSignature.signature;

const singleSignOnProvider =
await SingleSignOnEIP4361AuthProvider.fromExistingSiweInfo(
originalSiweMessage,
originalSiweSignature,
);

const typedSignature =
await singleSignOnProvider.getOrCreateAuthSignature();
expect(typedSignature.typedData).toEqual(originalSiweMessage);
expect(typedSignature.signature).toEqual(originalSiweSignature);
expect(typedSignature.address).toEqual(await signer.getAddress());
expect(typedSignature.scheme).toEqual('EIP4361');
});
});

0 comments on commit 1d05688

Please sign in to comment.