Skip to content

Commit

Permalink
feat!(auth): remove eip712
Browse files Browse the repository at this point in the history
  • Loading branch information
piotr-roslaniec committed Jul 9, 2024
1 parent f452c6a commit e6c4e1b
Show file tree
Hide file tree
Showing 13 changed files with 33 additions and 383 deletions.
12 changes: 1 addition & 11 deletions packages/taco-auth/src/auth-provider.ts
Original file line number Diff line number Diff line change
@@ -1,30 +1,20 @@
import { AuthSignature } from './auth-sig';
import { EIP4361AuthProvider, EIP712AuthProvider } from './providers';
import { EIP4361AuthProvider } from './providers';

/**
* @deprecated Use EIP4361_AUTH_METHOD instead.
*/
export const EIP712_AUTH_METHOD = 'EIP712';
export const EIP4361_AUTH_METHOD = 'EIP4361';


export interface AuthProvider {
getOrCreateAuthSignature(): Promise<AuthSignature>;
}

export type AuthProviders = {
[EIP712_AUTH_METHOD]?: EIP712AuthProvider;
[EIP4361_AUTH_METHOD]?: EIP4361AuthProvider;
// Fallback to satisfy type checking
[key: string]: AuthProvider | undefined;
};

export const USER_ADDRESS_PARAM_DEFAULT = ':userAddress';
export const USER_ADDRESS_PARAM_EIP712 = `:userAddress${EIP712_AUTH_METHOD}`;
export const USER_ADDRESS_PARAM_EIP4361 = `:userAddress${EIP4361_AUTH_METHOD}`;

export const AUTH_METHOD_FOR_PARAM: Record<string, string> = {
[USER_ADDRESS_PARAM_DEFAULT]: EIP4361_AUTH_METHOD,
[USER_ADDRESS_PARAM_EIP712]: EIP712_AUTH_METHOD,
[USER_ADDRESS_PARAM_EIP4361]: EIP4361_AUTH_METHOD,
};
12 changes: 4 additions & 8 deletions packages/taco-auth/src/auth-sig.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,15 @@
import { EthAddressSchema } from '@nucypher/shared';
import { z } from 'zod';

import { EIP4361_AUTH_METHOD, EIP712_AUTH_METHOD } from './auth-provider';
import { EIP4361TypedDataSchema, EIP712TypedDataSchema } from './providers';
import { EIP4361_AUTH_METHOD } from './auth-provider';
import { EIP4361TypedDataSchema } from './providers';


export const authSignatureSchema = z.object({
signature: z.string(),
address: EthAddressSchema,
scheme: z.enum([EIP712_AUTH_METHOD, EIP4361_AUTH_METHOD]),
typedData: z.union([
EIP4361TypedDataSchema,
// TODO(#536): Remove post EIP712 deprecation
EIP712TypedDataSchema,
]),
scheme: z.enum([EIP4361_AUTH_METHOD]),
typedData: EIP4361TypedDataSchema,
});

export type AuthSignature = z.infer<typeof authSignatureSchema>;
19 changes: 0 additions & 19 deletions packages/taco-auth/src/helper.ts

This file was deleted.

1 change: 0 additions & 1 deletion packages/taco-auth/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
export * from './providers';
export * from './helper';
export * from './auth-sig';
export * from './auth-provider';
155 changes: 0 additions & 155 deletions packages/taco-auth/src/providers/eip712.ts

This file was deleted.

1 change: 0 additions & 1 deletion packages/taco-auth/src/providers/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
export * from './eip712';
export * from './eip4361';
32 changes: 1 addition & 31 deletions packages/taco-auth/test/auth-provider.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,39 +7,9 @@ import {
import { SiweMessage } from 'siwe';
import { describe, expect, it } from 'vitest';

import {
EIP4361AuthProvider,
EIP712AuthProvider,
EIP712TypedData,
} from '../src';
import { EIP4361AuthProvider } from '../src';

describe('auth provider', () => {
it('creates a new EIP-712 message', async () => {
const provider = fakeProvider(bobSecretKeyBytes);
const signer = fakeSigner(bobSecretKeyBytes);

const eip712Provider = new EIP712AuthProvider(provider, signer);
const eip712Message = await eip712Provider.getOrCreateAuthSignature();
expect(eip712Message.signature).toBeDefined();
expect(eip712Message.address).toEqual(await signer.getAddress());
expect(eip712Message.scheme).toEqual('EIP712');

const typedData = eip712Message.typedData as EIP712TypedData;
expect(typedData).toBeDefined();
expect(typedData.types.Wallet).toBeDefined();
expect(typedData.domain.name).toEqual('TACo');
expect(typedData.domain.version).toEqual('1');
expect(typedData.domain.chainId).toEqual(
(await provider.getNetwork()).chainId,
);
expect(typedData.domain.salt).toBeDefined();
expect(typedData.message.address).toEqual(await signer.getAddress());
expect(typedData.message.blockNumber).toEqual(
await provider.getBlockNumber(),
);
expect(typedData.message['blockHash']).toBeDefined();
});

it('creates a new SIWE message', async () => {
const provider = fakeProvider(bobSecretKeyBytes);
const signer = fakeSigner(bobSecretKeyBytes);
Expand Down
74 changes: 2 additions & 72 deletions packages/taco-auth/test/auth-sig.test.ts
Original file line number Diff line number Diff line change
@@ -1,67 +1,8 @@
import { describe, expect, it } from 'vitest';

import {
authSignatureSchema,
} from '../src';
import { authSignatureSchema } from '../src';


const eip712AuthSignature = {
'signature': 'fake-typed-signature',
'address': '0x0000000000000000000000000000000000000000',
'scheme': 'EIP712',
'typedData': {
'types': {
'Wallet': [
{
'name': 'address',
'type': 'address',
},
{
'name': 'signatureText',
'type': 'string',
},
{
'name': 'blockNumber',
'type': 'uint256',
},
{
'name': 'blockHash',
'type': 'bytes32',
},
],
'EIP712Domain': [
{
'name': 'name',
'type': 'string',
},
{
'name': 'version',
'type': 'string',
},
{
'name': 'chainId',
'type': 'uint256',
},
{
'name': 'salt',
'type': 'bytes32',
},
],
},
'domain': {
'name': 'TACo',
'version': '1',
'chainId': 1234,
'salt': '0x55d90a3b041db6dda74671bc83a25d1508979b19a105be17f57f86fe08627dbd',
},
'message': {
'address': '0x0000000000000000000000000000000000000000',
'signatureText': 'I\'m the owner of address 0x0000000000000000000000000000000000000000 as of block number 1000',
'blockNumber': 1000,
'blockHash': '0x0000000000000000000000000000000000000000',
},
'primaryType': 'Wallet',
},
};
const eip4361AuthSignature = {
'signature': 'fake-signature',
'address': '0x0000000000000000000000000000000000000000',
Expand All @@ -70,17 +11,6 @@ const eip4361AuthSignature = {
};

describe('auth signature', () => {
it('accepts a well-formed EIP172 auth signature', async () => {
authSignatureSchema.parse(eip712AuthSignature);
});

it('rejects an EIP712 auth signature with missing fields', async () => {
expect(() => authSignatureSchema.parse({
...eip712AuthSignature,
'signature': undefined,
})).toThrow();
});

it('accepts a well-formed EIP4361 auth signature', async () => {
authSignatureSchema.parse(eip4361AuthSignature);
});
Expand Down
12 changes: 2 additions & 10 deletions packages/taco/src/conditions/const.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
import {ChainId} from '@nucypher/shared';
import {
USER_ADDRESS_PARAM_DEFAULT,
USER_ADDRESS_PARAM_EIP4361,
USER_ADDRESS_PARAM_EIP712
} from "@nucypher/taco-auth";
import { ChainId } from '@nucypher/shared';
import { USER_ADDRESS_PARAM_DEFAULT } from "@nucypher/taco-auth";

export const USER_ADDRESS_PARAM_EXTERNAL_EIP4361 =
':userAddressExternalEIP4361';
Expand All @@ -21,16 +17,12 @@ export const SUPPORTED_CHAIN_IDS = [
];

export const USER_ADDRESS_PARAMS = [
USER_ADDRESS_PARAM_EIP712,
USER_ADDRESS_PARAM_EIP4361,
USER_ADDRESS_PARAM_EXTERNAL_EIP4361,
// Ordering matters, this should always be last
USER_ADDRESS_PARAM_DEFAULT,
];

export const RESERVED_CONTEXT_PARAMS = [
USER_ADDRESS_PARAM_DEFAULT,
USER_ADDRESS_PARAM_EIP712,
USER_ADDRESS_PARAM_EIP4361,
// USER_ADDRESS_PARAM_EXTERNAL_EIP4361 is not reserved and can be used as a custom context parameter
];
Loading

0 comments on commit e6c4e1b

Please sign in to comment.