Skip to content

Commit

Permalink
feat: switch to ox (#287)
Browse files Browse the repository at this point in the history
* upgrade to turbopack v2

* switch to [ox](https://oxlib.sh)

* fix ci

* wip

* should probably migrate to bun anyways smh

* lint

* pnpm strikes again
  • Loading branch information
m1guelpf authored Nov 12, 2024
1 parent a160c13 commit 293aac8
Show file tree
Hide file tree
Showing 16 changed files with 171 additions and 171 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:

- uses: pnpm/action-setup@v4
with:
version: 8
version: 9.12.2

- name: Setup Node.js environment
uses: actions/setup-node@v3
Expand Down Expand Up @@ -43,7 +43,7 @@ jobs:

- uses: pnpm/action-setup@v4
with:
version: 8
version: 9.12.2

- name: Setup Node.js environment
uses: actions/setup-node@v3
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:

- uses: pnpm/action-setup@v4
with:
version: 8
version: 9.12.2

- name: Set up Node
uses: actions/setup-node@v3
Expand All @@ -48,7 +48,7 @@ jobs:
run: pnpm publish -r --report-summary
env:
NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}

publish-github:
needs: release
name: Publish
Expand Down Expand Up @@ -77,4 +77,4 @@ jobs:
- name: Publish
run: pnpm publish -r --report-summary
env:
NODE_AUTH_TOKEN: ${{secrets.GIT_HUB_TOKEN}}
NODE_AUTH_TOKEN: ${{secrets.GIT_HUB_TOKEN}}
26 changes: 13 additions & 13 deletions .github/workflows/relyance-sci.yml
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
name: Relyance SCI Scan

on:
schedule:
- cron: "0 20 * * *"
workflow_dispatch:
schedule:
- cron: '0 20 * * *'
workflow_dispatch:

jobs:
execute-relyance-sci:
name: Relyance SCI Job
runs-on: ubuntu-latest
execute-relyance-sci:
name: Relyance SCI Job
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v4
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Pull and run SCI binary
run: |-
docker pull gcr.io/relyance-ext/compliance_inspector:release && \
docker run --rm -v `pwd`:/repo --env API_KEY='${{ secrets.DPP_SCI_KEY }}' gcr.io/relyance-ext/compliance_inspector:release
- name: Pull and run SCI binary
run: |-
docker pull gcr.io/relyance-ext/compliance_inspector:release && \
docker run --rm -v `pwd`:/repo --env API_KEY='${{ secrets.DPP_SCI_KEY }}' gcr.io/relyance-ext/compliance_inspector:release
18 changes: 3 additions & 15 deletions cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,8 @@
"enabled": true,
"language": "en-US",
"allowCompoundWords": true,
"dictionaries": [
"typescript",
"node",
"npm",
"html"
],
"enabledLanguageIds": [
"typescript",
"typescriptreact",
"javascript",
"markdown",
"yaml",
"json"
],
"dictionaries": ["typescript", "node", "npm", "html"],
"enabledLanguageIds": ["typescript", "typescriptreact", "javascript", "markdown", "yaml", "json"],
"words": [
"arrayify",
"consts",
Expand All @@ -30,10 +18,10 @@
"keccak",
"merkle",
"NextJS",
"ox",
"QRCode",
"tsup",
"TTFB",
"viem",
"webp",
"worldid",
"zustand"
Expand Down
2 changes: 1 addition & 1 deletion examples/with-html/index.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<!DOCTYPE html>
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
Expand Down
18 changes: 17 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,25 @@
"prepublishOnly": "npm run build"
},
"devDependencies": {
"turbo": "^1.13.0"
"prettier": "^3.3.3",
"prettier-plugin-sort-imports-desc": "^1.0.0",
"turbo": "^2.2.3"
},
"engines": {
"node": ">=18"
},
"packageManager": "[email protected]",
"prettier": {
"semi": false,
"tabWidth": 4,
"useTabs": true,
"printWidth": 120,
"singleQuote": true,
"trailingComma": "es5",
"arrowParens": "avoid",
"bracketSpacing": true,
"plugins": [
"prettier-plugin-sort-imports-desc"
]
}
}
4 changes: 1 addition & 3 deletions packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,12 @@
"dependencies": {
"browser-or-node": "3.0.0-pre.0",
"buffer": "^6.0.3",
"viem": "^2.17.0",
"ox": "^0.1.0",
"zustand": "^4.5"
},
"devDependencies": {
"@typescript-eslint/eslint-plugin": "^6.13.1",
"@typescript-eslint/parser": "^6.13.1",
"prettier": "^2.7.1",
"prettier-plugin-sort-imports-desc": "^1.0.0",
"tsup": "^8.1.0",
"typescript": "^5.3.2"
}
Expand Down
12 changes: 6 additions & 6 deletions packages/core/src/lib/hashing.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Buffer } from 'buffer/index.js'
import type { IDKitConfig } from '@/types/config'
import { AbiParameters, Bytes, Hex, Hash } from 'ox'
import type { AbiEncodedValue } from '@/types/config'
import { encodePacked, isBytes, isHex, keccak256 } from 'viem'

export interface HashFunctionOutput {
hash: bigint
Expand All @@ -15,8 +15,8 @@ export interface HashFunctionOutput {
* @param input Any string, hex-like string, bytes represented as a hex string.
* @returns
*/
export function hashToField(input: Uint8Array | string): HashFunctionOutput {
if (isBytes(input) || isHex(input)) return hashEncodedBytes(input)
export function hashToField(input: Bytes.Bytes | string): HashFunctionOutput {
if (Bytes.validate(input) || Hex.validate(input)) return hashEncodedBytes(input)

return hashString(input)
}
Expand All @@ -32,7 +32,7 @@ export function packAndEncode(input: [string, unknown][]): HashFunctionOutput {
[[], []]
)

return hashEncodedBytes(encodePacked(types, values))
return hashEncodedBytes(AbiParameters.encodePacked(types, values))
}

/**
Expand All @@ -52,8 +52,8 @@ function hashString(input: string): HashFunctionOutput {
* @param input - Bytes represented as a hex string.
* @returns
*/
function hashEncodedBytes(input: `0x${string}` | Uint8Array): HashFunctionOutput {
const hash = BigInt(keccak256(input)) >> 8n
function hashEncodedBytes(input: Hex.Hex | Bytes.Bytes): HashFunctionOutput {
const hash = BigInt(Hash.keccak256(input, { as: 'Hex' })) >> 8n
const rawDigest = hash.toString(16)

return { hash, digest: `0x${rawDigest.padStart(64, '0')}` }
Expand Down
2 changes: 1 addition & 1 deletion packages/core/tsup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export default defineConfig({
clean: true,
outDir: 'build',
format: ['esm', 'cjs'],
external: ['zustand', 'viem'],
external: ['zustand', 'ox'],
entry: ['src/index.ts', 'src/lib/hashing.ts', 'src/lib/backend.ts'],
define: { 'process.env.NODE_ENV': '"production"' },
})
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import clsx from 'clsx'
import { __ } from '@/lang'
import type { FC } from 'react'
import copy from 'copy-to-clipboard'
Expand All @@ -8,7 +9,6 @@ import { useCallback, useState } from 'react'
import { AnimatePresence, motion } from 'framer-motion'
import WorldcoinIcon from '@/components/Icons/WorldcoinIcon'
import QRPlaceholderIcon from '@/components/Icons/QRPlaceholderIcon'
import clsx from 'clsx'

type Props = {
qrData: string | null
Expand All @@ -29,7 +29,7 @@ const QRState: FC<Props> = ({ qrData, showQR, setShowQR }) => {

return (
<>
<div className={clsx("md:hidden", {"mb-10 space-y-4": !showQR})}>
<div className={clsx('md:hidden', { 'mb-10 space-y-4': !showQR })}>
<motion.a
href={qrData ?? ''}
whileTap={{ scale: 0.95 }}
Expand All @@ -38,7 +38,8 @@ const QRState: FC<Props> = ({ qrData, showQR, setShowQR }) => {
layoutId={media == 'desktop' ? undefined : 'worldid-button'}
className={clsx(
'flex w-full items-center space-x-2 rounded-2xl border border-transparent p-4 font-medium shadow-sm',
'bg-0d151d text-white dark:bg-white dark:text-0d151d', {hidden: showQR}
'bg-0d151d text-white dark:bg-white dark:text-0d151d',
{ hidden: showQR }
)}
>
<WorldcoinIcon className="size-5" />
Expand All @@ -50,8 +51,8 @@ const QRState: FC<Props> = ({ qrData, showQR, setShowQR }) => {
{__('Open Worldcoin App')}
</motion.span>
</motion.a>
<div className={clsx("mb-3", {"space-y-4": !showQR})}>
<div className={clsx("flex items-center space-x-4 ", {hidden: showQR})}>
<div className={clsx('mb-3', { 'space-y-4': !showQR })}>
<div className={clsx('flex items-center space-x-4 ', { hidden: showQR })}>
<hr className="flex-1" />
<span className="text-xs font-medium text-9ba3ae">or</span>
<hr className="flex-1" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import clsx from 'clsx'
import { __ } from '@/lang'
import { IDKITStage } from '@/types'
import QRState from './WorldID/QRState'
Expand All @@ -9,7 +10,6 @@ import { useWorldBridge } from '@/services/wld-bridge'
import LoadingIcon from '@/components/Icons/LoadingIcon'
import WorldcoinIcon from '@/components/Icons/WorldcoinIcon'
import { AppErrorCodes, VerificationState, VerificationLevel } from '@worldcoin/idkit-core'
import clsx from 'clsx'

const getOptions = (store: IDKitStore) => ({
signal: store.signal,
Expand Down Expand Up @@ -68,7 +68,7 @@ const WorldIDState = () => {
}, [result, handleVerify, verificationState, setStage, errorCode, setErrorState, verification_level])

return (
<div className={clsx("-mt-6 space-y-5", {"space-y-10": !showQR})}>
<div className={clsx('-mt-6 space-y-5', { 'space-y-10': !showQR })}>
<div>
<div className="mb-4 flex items-center justify-center">
<WorldcoinIcon className="h-10 text-0d151d dark:text-white" />
Expand Down
13 changes: 8 additions & 5 deletions packages/react/src/components/QRCode.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,15 @@ const generateMatrix = (data: string): Array<number[]> => {
const arr = QRCodeUtil.create(data, { errorCorrectionLevel: 'M' }).modules.data as Uint8Array
const sqrt = Math.sqrt(arr.length)

return arr.reduce((rows, key, index) => {
if (index % sqrt === 0) rows.push([key])
else rows[rows.length - 1].push(key)
return arr.reduce(
(rows, key, index) => {
if (index % sqrt === 0) rows.push([key])
else rows[rows.length - 1].push(key)

return rows
}, [] as Array<number[]>)
return rows
},
[] as Array<number[]>
)
}

type Props = {
Expand Down
4 changes: 2 additions & 2 deletions packages/react/src/lang/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ const getLang = (): Record<string, string> | undefined => {
type CleanWord<T> = T extends `${string}${' ' | ',' | '!' | '?' | '.' | '`'}${string}`
? never
: T extends ''
? never
: T
? never
: T

type ExtractPlaceholders<S extends string> = S extends `${string}:${infer Placeholder}`
? Placeholder extends `${infer Word}${' ' | ',' | '!' | '?' | '.' | '`'}${infer Rest}`
Expand Down
2 changes: 1 addition & 1 deletion packages/react/tsup.config.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { defineConfig } from 'tsup'
import packageJson from './package.json' assert { type: 'json' }
import packageJson from './package.json' assert {}

export default defineConfig({
dts: true,
Expand Down
Loading

0 comments on commit 293aac8

Please sign in to comment.