Skip to content

Commit

Permalink
Run linter.
Browse files Browse the repository at this point in the history
  • Loading branch information
derekpierre committed May 30, 2024
1 parent a0cb56e commit 507e8b2
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 28 deletions.
2 changes: 1 addition & 1 deletion packages/taco-auth/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export * from './eip712';
export * from './eip4361';
export * from './eip712';
export * from './types';
10 changes: 5 additions & 5 deletions packages/taco-auth/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import type { SiweMessage } from 'siwe';
import { FormattedEip712 } from './eip712';

export interface TypedSignature {
signature: string;
address: string;
scheme: 'EIP712' | 'EIP4361';
typedData: FormattedEip712 | SiweMessage;
}
signature: string;
address: string;
scheme: 'EIP712' | 'EIP4361';
typedData: FormattedEip712 | SiweMessage;
}
6 changes: 2 additions & 4 deletions packages/taco-auth/test/taco-auth.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,9 @@ describe('taco authorization', () => {
expect(typedData).toBeDefined();
expect(typedData.domain).toEqual('TACo');
expect(typedData.version).toEqual('1');
expect(typedData.nonce).toBeDefined(); // random
expect(typedData.nonce).toBeDefined(); // random
expect(typedData.uri).toEqual('taco://');
expect(typedData.chainId).toEqual(
(await provider.getNetwork()).chainId,
);
expect(typedData.chainId).toEqual((await provider.getNetwork()).chainId);
expect(typedData.statement).toEqual(
`${typedData.domain} wants you to sign in with your Ethereum account: ${await signer.getAddress()}`,
);
Expand Down
6 changes: 3 additions & 3 deletions packages/taco/src/conditions/condition.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { objectEquals } from '@nucypher/shared';
import { z } from 'zod';

import { USER_ADDRESS_PARAMS, USER_ADDRESS_PARAM_DEFAULT } from './const';
import { USER_ADDRESS_PARAMS } from './const';

type ConditionSchema = z.ZodSchema;
export type ConditionProps = z.infer<ConditionSchema>;
Expand Down Expand Up @@ -43,11 +43,11 @@ export class Condition {
return param;
}
}
return null
return null;
}

public requiresSigner(): boolean {
return Boolean(this.findParamWithSigner())
return Boolean(this.findParamWithSigner());
}

public toObj() {
Expand Down
10 changes: 7 additions & 3 deletions packages/taco/src/conditions/context/context.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import { Context, Conditions as WASMConditions } from '@nucypher/nucypher-core';
import { fromJSON, toJSON } from '@nucypher/shared';
import { EIP712SignatureProvider, EIP4361SignatureProvider, TypedSignature } from '@nucypher/taco-auth';
import {
EIP4361SignatureProvider,
EIP712SignatureProvider,
TypedSignature,
} from '@nucypher/taco-auth';
import { ethers } from 'ethers';

import { CompoundConditionType } from '../compound-condition';
Expand All @@ -10,7 +14,6 @@ import {
CONTEXT_PARAM_PREFIX,
CONTEXT_PARAM_REGEXP,
RESERVED_CONTEXT_PARAMS,
USER_ADDRESS_PARAMS,
USER_ADDRESS_PARAM_DEFAULT,
USER_ADDRESS_PARAM_EIP4361,
USER_ADDRESS_PARAM_EIP712,
Expand All @@ -23,7 +26,8 @@ const ERR_RESERVED_PARAM = (key: string) =>
`Cannot use reserved parameter name ${key} as custom parameter`;
const ERR_INVALID_CUSTOM_PARAM = (key: string) =>
`Custom parameter ${key} must start with ${CONTEXT_PARAM_PREFIX}`;
const ERR_SIGNER_REQUIRED = (key: string) => `Signer required to satisfy ${key} context variable in condition`;
const ERR_SIGNER_REQUIRED = (key: string) =>
`Signer required to satisfy ${key} context variable in condition`;
const ERR_MISSING_CONTEXT_PARAMS = (params: string[]) =>
`Missing custom context parameter(s): ${params.join(', ')}`;
const ERR_UNKNOWN_CONTEXT_PARAMS = (params: string[]) =>
Expand Down
46 changes: 34 additions & 12 deletions packages/taco/test/conditions/context.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import { initialize } from '@nucypher/nucypher-core';
import {
EIP4361SignatureProvider,
EIP712SignatureProvider,
} from '@nucypher/taco-auth';
import { fakeProvider, fakeSigner } from '@nucypher/test-utils';
import { ethers } from 'ethers';
import { beforeAll, describe, expect, it, vi } from 'vitest';

import { EIP4361SignatureProvider, EIP712SignatureProvider } from '@nucypher/taco-auth';
import { toBytes, toHexString } from '../../src';
import {
ContractCondition,
Expand All @@ -19,8 +22,8 @@ import {
} from '../../src/conditions/const';
import { CustomContextParam } from '../../src/conditions/context';
import {
ReturnValueTestProps,
paramOrContextParamSchema,
ReturnValueTestProps,
} from '../../src/conditions/shared';
import {
testContractConditionObj,
Expand Down Expand Up @@ -299,7 +302,7 @@ describe('authentication provider', () => {
expect(() => conditionExpr.buildContext(provider, {}, undefined)).toThrow(
`Signer required to satisfy ${userAddressParam} context variable in condition`,
);
})
});
});

it('it supports just one provider at a time', () => {
Expand All @@ -313,7 +316,9 @@ describe('authentication provider', () => {
const condition = new ContractCondition(conditionObj);
const conditionExpr = new ConditionExpression(condition);
expect(conditionExpr.contextRequiresSigner()).toBe(true);
expect(() => conditionExpr.buildContext(provider, {}, signer)).not.toThrow();
expect(() =>
conditionExpr.buildContext(provider, {}, signer),
).not.toThrow();
});

it('supports multiple providers when needed', () => {
Expand All @@ -328,13 +333,18 @@ describe('authentication provider', () => {
const condition = new ContractCondition(conditionObj);
const conditionExpr = new ConditionExpression(condition);
expect(conditionExpr.contextRequiresSigner()).toBe(true);
expect(() => conditionExpr.buildContext(provider, {}, signer)).not.toThrow();
expect(() =>
conditionExpr.buildContext(provider, {}, signer),
).not.toThrow();
});

// TODO: Consider rewriting those tests to be a bit more comprehensive and deduplicate them

it('supports default auth method (eip712)', () => {
const eip712Spy = vi.spyOn(EIP712SignatureProvider.prototype, "getOrCreateWalletSignature");
const eip712Spy = vi.spyOn(
EIP712SignatureProvider.prototype,
'getOrCreateWalletSignature',
);
const conditionObj = {
...testContractConditionObj,
returnValueTest: {
Expand All @@ -345,12 +355,17 @@ describe('authentication provider', () => {
const condition = new ContractCondition(conditionObj);
const conditionExpr = new ConditionExpression(condition);
expect(conditionExpr.contextRequiresSigner()).toBe(true);
expect(() => conditionExpr.buildContext(provider, {}, signer).toObj()).not.toThrow();
expect(() =>
conditionExpr.buildContext(provider, {}, signer).toObj(),
).not.toThrow();
expect(eip712Spy).toHaveBeenCalledOnce();
});

it('supports eip712', () => {
const eip712Spy = vi.spyOn(EIP712SignatureProvider.prototype, "getOrCreateWalletSignature");
const eip712Spy = vi.spyOn(
EIP712SignatureProvider.prototype,
'getOrCreateWalletSignature',
);
const conditionObj = {
...testContractConditionObj,
returnValueTest: {
Expand All @@ -361,12 +376,17 @@ describe('authentication provider', () => {
const condition = new ContractCondition(conditionObj);
const conditionExpr = new ConditionExpression(condition);
expect(conditionExpr.contextRequiresSigner()).toBe(true);
expect(() => conditionExpr.buildContext(provider, {}, signer).toObj()).not.toThrow();
expect(() =>
conditionExpr.buildContext(provider, {}, signer).toObj(),
).not.toThrow();
expect(eip712Spy).toHaveBeenCalledOnce();
});

it('supports eip4361', () => {
const eip4361Spy = vi.spyOn(EIP4361SignatureProvider.prototype, "getOrCreateSiweMessage");
const eip4361Spy = vi.spyOn(
EIP4361SignatureProvider.prototype,
'getOrCreateSiweMessage',
);
const conditionObj = {
...testContractConditionObj,
returnValueTest: {
Expand All @@ -377,10 +397,12 @@ describe('authentication provider', () => {
const condition = new ContractCondition(conditionObj);
const conditionExpr = new ConditionExpression(condition);
expect(conditionExpr.contextRequiresSigner()).toBe(true);
expect(() => conditionExpr.buildContext(provider, {}, signer).toObj()).not.toThrow();
expect(() =>
conditionExpr.buildContext(provider, {}, signer).toObj(),
).not.toThrow();
expect(eip4361Spy).toHaveBeenCalledOnce();
});
})
});

describe('param or context param schema', () => {
it('accepts a plain string', () => {
Expand Down

0 comments on commit 507e8b2

Please sign in to comment.