Skip to content

Commit

Permalink
revert absolute import path and update CI flow
Browse files Browse the repository at this point in the history
  • Loading branch information
phn210 committed Mar 8, 2024
1 parent 7d7a42b commit 1292501
Show file tree
Hide file tree
Showing 19 changed files with 1,980 additions and 1,239 deletions.
38 changes: 22 additions & 16 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,26 @@
name: CI
on: [push, pull_request]
jobs:
test:
runs-on: ubuntu-latest
timeout-minutes: 10
test:
runs-on: [ubuntu-latest, windows-latest, macOS-latest]
timeout-minutes: 10
strategy:
matrix:
node-version: [14.x, 16.x, 18.x, 20.x]
steps:
- name: Set up NodeJS
uses: actions/setup-node@v2
with:
node-version: '16'
- name: Git checkout
uses: actions/checkout@v2
- name: NPM ci, build, & test
run: |
npm install
npm run build --if-present
npm test
env:
CI: true
- uses: actions/checkout@v3
- name: Clean global cache
run: npm cache clean --force
- name: Set up Node
uses: ./
with:
node-version: ${{ matrix.node-version }}
cache: 'npm'
- name: Install dependencies
run: npm install
- name: CI build & test
run: |
npm run build --if-present
npm test
env:
CI: true
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ node_modules
build
coverage
.husky
.yml

# Editor
.vscode
Expand Down
2,975 changes: 1,859 additions & 1,116 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@auxo-dev/auxo-libs",
"version": "0.4.0",
"version": "0.4.2",
"description": "",
"author": "",
"license": "Apache-2.0",
Expand Down
2 changes: 1 addition & 1 deletion src/Bit255.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Provable, Reducer, Scalar, SmartContract, method } from 'o1js';
import { Bit255 } from 'src/Bit255.js';
import { Bit255 } from './Bit255.js';

describe('Bit255', () => {
it('Should be provable', async () => {
Expand Down
2 changes: 1 addition & 1 deletion src/Bit255.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Bool, Field, Poseidon, Provable, Scalar, Struct } from 'o1js';
import { CustomScalar } from 'src/CustomScalar.js';
import { CustomScalar } from './CustomScalar.js';

// WARNING - Convert between Scalar and Bit255 does not preserve bigint value
export class Bit255 extends Struct({
Expand Down
2 changes: 1 addition & 1 deletion src/CustomScalar.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Scalar } from 'o1js';
import { CustomScalar } from 'src/CustomScalar.js';
import { CustomScalar } from './CustomScalar.js';

describe('CustomScalar', () => {
it('Should convert correctly', async () => {
Expand Down
114 changes: 57 additions & 57 deletions src/CustomScalar.ts
Original file line number Diff line number Diff line change
@@ -1,62 +1,62 @@
import { Bool, Field, Poseidon, Scalar, Struct } from 'o1js';

export class CustomScalar extends Struct({
head: Field,
tail: Field,
head: Field,
tail: Field,
}) {
static fromScalar(scalar: Scalar): CustomScalar {
let bits = scalar.toFields().map((e) => Bool.fromFields([e]));
return new CustomScalar({
head: Field.fromBits(bits.slice(0, 127)),
tail: Field.fromBits(bits.slice(127)),
});
}

static fromFields(fields: Field[]): CustomScalar {
return new CustomScalar({
head: fields[0],
tail: fields[1],
});
}

static toScalar(scalar: CustomScalar): Scalar {
return Scalar.fromBits(
scalar.head
.toBits()
.slice(0, 127)
.concat(scalar.tail.toBits().slice(0, 128))
);
}

static toFields(value: { head: Field; tail: Field }): Field[] {
return [value.head].concat([value.tail]);
}

static sizeInFields(): number {
return 2;
}

hash(): Field {
return Poseidon.hash(this.toScalar().toFields());
}

equals(s: CustomScalar): Bool {
return this.head.equals(s.head).and(this.tail.equals(s.tail));
}

assertEquals(s: CustomScalar): void {
this.equals(s).assertTrue();
}

toScalar(): Scalar {
return CustomScalar.toScalar(this);
}

toFields(): Field[] {
return CustomScalar.toFields(this);
}

fromFields(fields: Field[]): CustomScalar {
return CustomScalar.fromFields(fields);
}
static fromScalar(scalar: Scalar): CustomScalar {
let bits = scalar.toFields().map((e) => Bool.fromFields([e]));
return new CustomScalar({
head: Field.fromBits(bits.slice(0, 127)),
tail: Field.fromBits(bits.slice(127)),
});
}

static fromFields(fields: Field[]): CustomScalar {
return new CustomScalar({
head: fields[0],
tail: fields[1],
});
}

static toScalar(scalar: CustomScalar): Scalar {
return Scalar.fromBits(
scalar.head
.toBits()
.slice(0, 127)
.concat(scalar.tail.toBits().slice(0, 128))
);
}

static toFields(value: { head: Field; tail: Field }): Field[] {
return [value.head].concat([value.tail]);
}

static sizeInFields(): number {
return 2;
}

hash(): Field {
return Poseidon.hash(this.toScalar().toFields());
}

equals(s: CustomScalar): Bool {
return this.head.equals(s.head).and(this.tail.equals(s.tail));
}

assertEquals(s: CustomScalar): void {
this.equals(s).assertTrue();
}

toScalar(): Scalar {
return CustomScalar.toScalar(this);
}

toFields(): Field[] {
return CustomScalar.toFields(this);
}

fromFields(fields: Field[]): CustomScalar {
return CustomScalar.fromFields(fields);
}
}
6 changes: 3 additions & 3 deletions src/DynamicArray.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ import {
GroupDynamicArray,
PublicKeyDynamicArray,
ScalarDynamicArray,
} from 'src/DynamicArray.js';
import { CustomScalar } from 'src/CustomScalar.js';
import { Bit255 } from 'src/Bit255.js';
} from './DynamicArray.js';
import { CustomScalar } from './CustomScalar.js';
import { Bit255 } from './Bit255.js';

describe('DynamicArray', () => {
const MAX_HEIGHT = 5;
Expand Down
6 changes: 3 additions & 3 deletions src/DynamicArray.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ import {
Struct,
} from 'o1js';

import { Bit255 } from 'src/Bit255.js';
import { CustomScalar } from 'src/CustomScalar.js';
import { hashable } from 'src/Hashable.js';
import { Bit255 } from './Bit255.js';
import { CustomScalar } from './CustomScalar.js';
import { hashable } from './Hashable.js';

export {
Bit255DynamicArray,
Expand Down
22 changes: 11 additions & 11 deletions src/Hashable.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import { Bool, Field, Poseidon, Provable } from 'o1js';

export type HashableProvable<T> = Provable<T> & {
hash(x: T): Field;
equals(x: T, other: T): Bool;
hash(x: T): Field;
equals(x: T, other: T): Bool;
};

export function hashable<T>(type: Provable<T>): HashableProvable<T> {
return {
...type,
hash(x: T): Field {
return Poseidon.hash(type.toFields(x));
},
equals(x: T, other: T): Bool {
return this.hash(x).equals(this.hash(other));
},
};
return {
...type,
hash(x: T): Field {
return Poseidon.hash(type.toFields(x));
},
equals(x: T, other: T): Bool {
return this.hash(x).equals(this.hash(other));
},
};
}
2 changes: 1 addition & 1 deletion src/IPFSHash.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Provable } from 'o1js';
import { IpfsHash } from 'src/IpfsHash.js';
import { IpfsHash } from './IpfsHash.js';

describe('IpfsHash', () => {
it('Should be provable code', async () => {
Expand Down
2 changes: 1 addition & 1 deletion src/IPFSHash.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Encoding } from 'o1js';
import { FieldDynamicArray } from 'src/DynamicArray.js';
import { FieldDynamicArray } from './DynamicArray.js';

export class IpfsHash extends FieldDynamicArray(3) {
static fromString(s: string): IpfsHash {
Expand Down
10 changes: 5 additions & 5 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export { Bit255 } from 'src/Bit255.js';
export { Bit255 } from './Bit255.js';

export { CustomScalar } from 'src/CustomScalar.js';
export { CustomScalar } from './CustomScalar.js';

export {
Bit255DynamicArray,
Expand All @@ -10,8 +10,8 @@ export {
ScalarDynamicArray,
PublicKeyDynamicArray,
DynamicArray,
} from 'src/DynamicArray.js';
} from './DynamicArray.js';

export { IpfsHash } from 'src/IpfsHash.js';
export { IpfsHash } from './IpfsHash.js';

export * as Utils from 'src/utils/index.js';
export * as Utils from './utils/index.js';
4 changes: 2 additions & 2 deletions src/utils/benchmark.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import fs from 'fs';
import { Profiler } from 'src/utils/constants.js';
import { Profiler } from './constants.js';

export { getProfiler, getMemoryUsage };

const round = (x: number) => Math.round(x * 100) / 100;

function getProfiler(name: string): Profiler {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
let times: Record<string, any> = {};
let label: string;

Expand Down
2 changes: 1 addition & 1 deletion src/utils/config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import fs from 'fs/promises';
import { PrivateKey, PublicKey } from 'o1js';
import { Base58Key, Config, Key, ZkApp } from 'src/utils/constants.js';
import { Base58Key, Config, Key, ZkApp } from './constants.js';

export { readConfig, readZkAppConfig, readUserConfig };

Expand Down
14 changes: 5 additions & 9 deletions src/utils/index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
export { getProfiler, getMemoryUsage } from 'src/utils/benchmark.js';
export { getProfiler, getMemoryUsage } from './benchmark.js';

export {
readConfig,
readZkAppConfig,
readUserConfig,
} from 'src/utils/config.js';
export { readConfig, readZkAppConfig, readUserConfig } from './config.js';

export {
Profiler,
Expand All @@ -18,7 +14,7 @@ export {
TxResult,
FetchedActions,
FetchedEvents,
} from 'src/utils/constants.js';
} from './constants.js';

export {
randomAccounts,
Expand All @@ -30,7 +26,7 @@ export {
fetchActions,
fetchEvents,
fetchZkAppState,
} from 'src/utils/network.js';
} from './network.js';

export {
updateActionState,
Expand All @@ -39,4 +35,4 @@ export {
buildAssertMessage,
requireSignature,
requireCaller,
} from 'src/utils/zkApp.js';
} from './zkApp.js';
4 changes: 2 additions & 2 deletions src/utils/network.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
UInt32,
fetchAccount,
} from 'o1js';
import { getMemoryUsage } from 'src/utils/benchmark.js';
import { getMemoryUsage } from './benchmark.js';
import {
FeePayer,
FetchedActions,
Expand All @@ -21,7 +21,7 @@ import {
Program,
TxResult,
ZkApp,
} from 'src/utils/constants.js';
} from './constants.js';

export {
randomAccounts,
Expand Down
Loading

0 comments on commit 1292501

Please sign in to comment.