Skip to content

Commit

Permalink
Rename OffChainAttestationVersion
Browse files Browse the repository at this point in the history
  • Loading branch information
lbeder committed Jan 8, 2024
1 parent 7f7072e commit c374d68
Show file tree
Hide file tree
Showing 11 changed files with 47 additions and 47 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ await transaction.wait();
To verify an offchain attestation, you can use the `verifyOffchainAttestationSignature` function provided by the EAS SDK. Here's an example:

```javascript
import { OffChainAttestationVersion, Offchain, PartialTypedDataConfig } from "@ethereum-attestation-service/eas-sdk";
import { OffchainAttestationVersion, Offchain, PartialTypedDataConfig } from "@ethereum-attestation-service/eas-sdk";

const attestation = {
// your offchain attestation
Expand All @@ -297,7 +297,7 @@ const attestation = {
},
uid: "0x5134f511e0533f997e569dac711952dde21daf14b316f3cce23835defc82c065",
message: {
version: OffChainAttestationVersion.Version1,
version: OffchainAttestationVersion.Version1,
schema: "0x27d06e3659317e9a4f8154d1e849eb53d43d91fb4f219884d1684f86d797804a",
refUID: "0x0000000000000000000000000000000000000000000000000000000000000000",
time: 1671219600,
Expand All @@ -316,7 +316,7 @@ const EAS_CONFIG: PartialTypedDataConfig = {
version: attestation.sig.domain.version,
chainId: attestation.sig.domain.chainId,
};
const offchain = new Offchain(EAS_CONFIG, OffChainAttestationVersion.Version1);
const offchain = new Offchain(EAS_CONFIG, OffchainAttestationVersion.Version1);
const isValidAttestation = offchain.verifyOffchainAttestationSignature(
attestation.signer,
attestation.sig
Expand Down
2 changes: 1 addition & 1 deletion dist/eas.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions dist/offchain/offchain.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ export { EIP712Request, PartialTypedDataConfig, EIP712MessageTypes } from './typ
export interface OffchainAttestationType extends EIP712Types<EIP712MessageTypes> {
domain: string;
}
export declare enum OffChainAttestationVersion {
export declare enum OffchainAttestationVersion {
Legacy = 0,
Version1 = 1
}
export declare const OFFCHAIN_ATTESTATION_TYPES: Record<OffChainAttestationVersion, OffchainAttestationType[]>;
export declare const OFFCHAIN_ATTESTATION_TYPES: Record<OffchainAttestationVersion, OffchainAttestationType[]>;
export type OffchainAttestationParams = {
version: number;
schema: string;
Expand All @@ -27,7 +27,7 @@ export interface SignedOffchainAttestation extends EIP712Response<EIP712MessageT
uid: string;
}
export declare class Offchain extends TypedDataHandler {
readonly version: OffChainAttestationVersion;
readonly version: OffchainAttestationVersion;
protected signingType: OffchainAttestationType;
protected readonly verificationTypes: OffchainAttestationType[];
private readonly eas;
Expand Down
20 changes: 10 additions & 10 deletions dist/offchain/offchain.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@ethereum-attestation-service/eas-sdk",
"version": "1.3.7",
"version": "1.3.8",
"description": "Ethereum Attestation Service - TypeScript/JavaScript SDK",
"repository": "[email protected]:ethereum-attestation-service/eas-sdk.git",
"author": "Leonid Beder <[email protected]>",
Expand Down
4 changes: 2 additions & 2 deletions src/eas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { EAS__factory, EAS as EASContract } from '@ethereum-attestation-service/
import { Overrides, TransactionReceipt } from 'ethers';
import { EIP712Proxy } from './eip712-proxy';
import { legacyVersion } from './legacy/version';
import { Delegated, Offchain, OffChainAttestationVersion } from './offchain';
import { Delegated, Offchain, OffchainAttestationVersion } from './offchain';
import {
AttestationRequest,
DelegatedAttestationRequest,
Expand Down Expand Up @@ -450,7 +450,7 @@ export class EAS extends Base<EASContract> {
version: await this.getVersion(),
chainId: await this.getChainId()
},
OffChainAttestationVersion.Version1,
OffchainAttestationVersion.Version1,
this
);

Expand Down
14 changes: 7 additions & 7 deletions src/offchain/offchain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ export interface OffchainAttestationType extends EIP712Types<EIP712MessageTypes>
domain: string;
}

export enum OffChainAttestationVersion {
export enum OffchainAttestationVersion {
Legacy = 0,
Version1 = 1
}

export const OFFCHAIN_ATTESTATION_TYPES: Record<OffChainAttestationVersion, OffchainAttestationType[]> = {
[OffChainAttestationVersion.Legacy]: [
export const OFFCHAIN_ATTESTATION_TYPES: Record<OffchainAttestationVersion, OffchainAttestationType[]> = {
[OffchainAttestationVersion.Legacy]: [
{
domain: 'EAS Attestation',
primaryType: 'Attestation',
Expand Down Expand Up @@ -73,7 +73,7 @@ export const OFFCHAIN_ATTESTATION_TYPES: Record<OffChainAttestationVersion, Offc
}
}
],
[OffChainAttestationVersion.Version1]: [
[OffchainAttestationVersion.Version1]: [
{
domain: 'EAS Attestation',
primaryType: 'Attest',
Expand Down Expand Up @@ -117,13 +117,13 @@ export interface SignedOffchainAttestation extends EIP712Response<EIP712MessageT
}

export class Offchain extends TypedDataHandler {
public readonly version: OffChainAttestationVersion;
public readonly version: OffchainAttestationVersion;
protected signingType: OffchainAttestationType;
protected readonly verificationTypes: OffchainAttestationType[];
private readonly eas: EAS;

constructor(config: PartialTypedDataConfig, version: number, eas: EAS) {
if (version > OffChainAttestationVersion.Version1) {
if (version > OffchainAttestationVersion.Version1) {
throw new Error('Unsupported version');
}

Expand Down Expand Up @@ -227,7 +227,7 @@ export class Offchain extends TypedDataHandler {

public static getOffchainUID(params: OffchainAttestationParams): string {
return getOffchainUID(
params.version ?? OffChainAttestationVersion.Legacy,
params.version ?? OffchainAttestationVersion.Legacy,
params.schema,
params.recipient,
params.time,
Expand Down
26 changes: 13 additions & 13 deletions test/test/eas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
DelegatedProxy,
Offchain,
OFFCHAIN_ATTESTATION_TYPES,
OffChainAttestationVersion
OffchainAttestationVersion
} from '../../src/offchain';
import { InvalidAddress, InvalidDomain, InvalidPrimaryType, InvalidTypes } from '../../src/offchain/typed-data-handler';
import { SchemaRegistry } from '../../src/schema-registry';
Expand Down Expand Up @@ -595,10 +595,10 @@ describe('EAS API', () => {
});

describe('versioning', () => {
it(`should support version ${OffChainAttestationVersion.Legacy}`, async () => {
it(`should support version ${OffchainAttestationVersion.Legacy}`, async () => {
const response = await offchain.signOffchainAttestation(
{
version: OffChainAttestationVersion.Legacy,
version: OffchainAttestationVersion.Legacy,
schema: schemaId,
recipient: await recipient.getAddress(),
time: await latest(),
Expand All @@ -612,10 +612,10 @@ describe('EAS API', () => {
expect(await offchain.verifyOffchainAttestationSignature(await sender.getAddress(), response)).to.be.true;
});

it(`should support version ${OffChainAttestationVersion.Version1}`, async () => {
it(`should support version ${OffchainAttestationVersion.Version1}`, async () => {
const response = await offchain.signOffchainAttestation(
{
version: OffChainAttestationVersion.Version1,
version: OffchainAttestationVersion.Version1,
schema: schemaId,
recipient: await recipient.getAddress(),
time: await latest(),
Expand All @@ -638,7 +638,7 @@ describe('EAS API', () => {
it('should verify the attestation onchain', async () => {
const response = await offchain.signOffchainAttestation(
{
version: OffChainAttestationVersion.Version1,
version: OffchainAttestationVersion.Version1,
schema: schemaId,
recipient: await recipient.getAddress(),
time: await latest(),
Expand All @@ -655,7 +655,7 @@ describe('EAS API', () => {

it('should throw on onchain verification of invalid attestations', async () => {
const params = {
version: OffChainAttestationVersion.Version1,
version: OffchainAttestationVersion.Version1,
schema: schemaId,
recipient: await recipient.getAddress(),
time: await latest(),
Expand Down Expand Up @@ -686,7 +686,7 @@ describe('EAS API', () => {

it('should throw on offchain verification of invalid attestations', async () => {
const params = {
version: OffChainAttestationVersion.Version1,
version: OffchainAttestationVersion.Version1,
schema: schemaId,
recipient: await recipient.getAddress(),
time: await latest(),
Expand Down Expand Up @@ -765,7 +765,7 @@ describe('EAS API', () => {
it('should verify offchain attestations with legacy/obsoleted domains', async () => {
const { config } = offchain;
const params = {
version: OffChainAttestationVersion.Legacy,
version: OffchainAttestationVersion.Legacy,
schema: schemaId,
recipient: await recipient.getAddress(),
time: await latest(),
Expand All @@ -777,11 +777,11 @@ describe('EAS API', () => {
const senderAddress = await sender.getAddress();

// Legacy version
const legacyOffchain = new Offchain(config, OffChainAttestationVersion.Legacy, new EAS(ZERO_ADDRESS));
const legacyOffchain = new Offchain(config, OffchainAttestationVersion.Legacy, new EAS(ZERO_ADDRESS));

let customOffchain = new CustomOffchain(
config,
OffChainAttestationVersion.Legacy,
OffchainAttestationVersion.Legacy,
{ contractVersion: '0.0.1' },
new EAS(ZERO_ADDRESS)
);
Expand All @@ -790,10 +790,10 @@ describe('EAS API', () => {
await expect(legacyOffchain.verifyOffchainAttestationSignature(senderAddress, response)).to.be.true;

// Legacy types
for (const type of OFFCHAIN_ATTESTATION_TYPES[OffChainAttestationVersion.Legacy].slice(1)) {
for (const type of OFFCHAIN_ATTESTATION_TYPES[OffchainAttestationVersion.Legacy].slice(1)) {
customOffchain = new CustomOffchain(
config,
OffChainAttestationVersion.Legacy,
OffchainAttestationVersion.Legacy,
{
contractVersion: '0.26',
type
Expand Down
4 changes: 2 additions & 2 deletions test/test/helpers/custom-offchain.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { EAS } from '../../../src/eas';
import { Offchain, OffchainAttestationType, OffChainAttestationVersion, TypedDataConfig } from '../../../src/offchain';
import { Offchain, OffchainAttestationType, OffchainAttestationVersion, TypedDataConfig } from '../../../src/offchain';

interface CustomOffchainParams {
contractVersion: string;
type?: OffchainAttestationType;
}

export class CustomOffchain extends Offchain {
constructor(config: TypedDataConfig, version: OffChainAttestationVersion, params: CustomOffchainParams, eas: EAS) {
constructor(config: TypedDataConfig, version: OffchainAttestationVersion, params: CustomOffchainParams, eas: EAS) {
super(config, version, eas);

const { contractVersion, type } = params;
Expand Down
6 changes: 3 additions & 3 deletions test/test/helpers/eas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import {
EIP712Response,
EIP712RevocationParams,
EIP712RevocationProxyParams,
OffChainAttestationVersion
OffchainAttestationVersion
} from '../../../src/offchain';
import { Transaction } from '../../../src/transaction';
import { getOffchainUID } from '../../../src/utils';
Expand Down Expand Up @@ -171,7 +171,7 @@ export const expectAttestation = async (

const now = await latest();
const uid = getOffchainUID(
OffChainAttestationVersion.Version1,
OffchainAttestationVersion.Version1,
schema,
recipient,
now,
Expand All @@ -182,7 +182,7 @@ export const expectAttestation = async (
);
const response = await offchain.signOffchainAttestation(
{
version: OffChainAttestationVersion.Version1,
version: OffchainAttestationVersion.Version1,
schema,
recipient,
time: now,
Expand Down
4 changes: 2 additions & 2 deletions test/test/offchain-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
decodeBase64ZippedBase64,
EAS,
Offchain,
OffChainAttestationVersion,
OffchainAttestationVersion,
zipAndEncodeToBase64
} from '../../src';
import { ZERO_ADDRESS } from '../utils/Constants';
Expand Down Expand Up @@ -92,7 +92,7 @@ describe('offchain utils', () => {
address: testAttestation.sig.domain.verifyingContract,
version: testAttestation.sig.domain.version
},
OffChainAttestationVersion.Version1,
OffchainAttestationVersion.Version1,
new EAS(ZERO_ADDRESS)
);

Expand Down

0 comments on commit c374d68

Please sign in to comment.