From 5e9ad577ff32cbf4b2ac61cab69993e7d54dddfd Mon Sep 17 00:00:00 2001 From: jawndiego Date: Sun, 16 Jun 2024 19:04:02 -0400 Subject: [PATCH 01/23] init --- apps/site/app/api/post/route.ts | 61 +++++----- apps/site/app/api/postBatch/route.ts | 64 ++++++----- apps/site/app/api/registerFor/route.ts | 65 ++++++----- apps/site/config/publicClient.ts | 6 +- apps/site/config/syndicateClient.ts | 100 ++++++++++++++++ apps/site/lib/api.ts | 151 +++++++++++++++++++------ apps/site/package.json | 1 + packages/scrypt/constants/addresses.ts | 8 +- pnpm-lock.yaml | 87 ++++++-------- 9 files changed, 361 insertions(+), 182 deletions(-) create mode 100644 apps/site/config/syndicateClient.ts diff --git a/apps/site/app/api/post/route.ts b/apps/site/app/api/post/route.ts index 49bd4da5..340de104 100644 --- a/apps/site/app/api/post/route.ts +++ b/apps/site/app/api/post/route.ts @@ -1,43 +1,52 @@ -import { novaPubClient } from '@/config/publicClient' -import { Defender } from '@openzeppelin/defender-sdk' +import { + syndicateClient, + generatePostTxnInput, + projectId, +} from '@/config/syndicateClient' import { ethers } from 'ethers' import type { NextRequest } from 'next/server' import { addresses, postGatewayABI } from 'scrypt' import type { Hex } from 'viem' +import { waitUntilTx, authToken } from '@/lib' + export const maxDuration = 30 // This function can run for a maximum of 30 seconds export async function POST(req: NextRequest) { const post = await req.json() - const credentials = { - relayerApiKey: process.env.NONCE_API_UNO, - relayerApiSecret: process.env.NONCE_SECRET_UNO, + if (!syndicateClient) { + return new Response( + JSON.stringify({ + success: false, + hash: null, + error: 'Syndicate client not initialized', + }), + { + status: 500, + headers: { 'Content-Type': 'application/json' }, + }, + ) } - try { - const defenderClient = new Defender(credentials) - const provider = defenderClient.relaySigner.getProvider() - const signer = defenderClient.relaySigner.getSigner(provider, { - speed: 'fast', - }) + const postTx = + await syndicateClient.officialActions.transact.sendTransaction( + generatePostTxnInput(post), + ) - const postGateway = new ethers.Contract( - addresses.postGateway.nova, - postGatewayABI, - signer as unknown as ethers.Signer, - ) - - const tx = await postGateway.post(post) - - await novaPubClient.waitForTransactionReceipt({ - hash: tx.hash as Hex, + const successfulTxHash = await waitUntilTx({ + projectID: projectId as string, + txID: postTx.transactionId, + authToken: authToken as string, }) - return new Response(JSON.stringify({ success: true, hash: tx.hash }), { - status: 200, - headers: { 'Content-Type': 'application/json' }, - }) + return new Response( + JSON.stringify({ success: true, hash: successfulTxHash }), + { + status: 200, + headers: { 'Content-Type': 'application/json' }, + }, + ) } catch (error) { let errorMessage = 'Unknown error' let statusCode = 500 @@ -57,4 +66,4 @@ export async function POST(req: NextRequest) { }, ) } -} +} \ No newline at end of file diff --git a/apps/site/app/api/postBatch/route.ts b/apps/site/app/api/postBatch/route.ts index 047c7412..f2c89c02 100644 --- a/apps/site/app/api/postBatch/route.ts +++ b/apps/site/app/api/postBatch/route.ts @@ -1,43 +1,47 @@ -import { novaPubClient } from '@/config/publicClient' -import { Defender } from '@openzeppelin/defender-sdk' -import { ethers } from 'ethers' import type { NextRequest } from 'next/server' -import { addresses, postGatewayABI } from 'scrypt' -import type { Hex } from 'viem' - -export const maxDuration = 30 // This function can run for a maximum of 30 seconds +import { + syndicateClient, + generatePostBatchTxnInput, + projectId, +} from '@/config/syndicateClient' +import { waitUntilTx, authToken } from '@/lib' export async function POST(req: NextRequest) { const postsArray = await req.json() - console.log({ postsArray }) - const credentials = { - relayerApiKey: process.env.NONCE_API_UNO, - relayerApiSecret: process.env.NONCE_SECRET_UNO, + if (!syndicateClient) { + return new Response( + JSON.stringify({ + success: false, + hash: null, + error: 'Syndicate client not initialized', + }), + { + status: 500, + headers: { 'Content-Type': 'application/json' }, + }, + ) } try { - const defenderClient = new Defender(credentials) - const provider = defenderClient.relaySigner.getProvider() - const signer = defenderClient.relaySigner.getSigner(provider, { - speed: 'fast', - }) + const postTx = + await syndicateClient.officialActions.transact.sendTransaction( + generatePostBatchTxnInput(postsArray), + ) - const postGateway = new ethers.Contract( - addresses.postGateway.nova, - postGatewayABI, - signer as unknown as ethers.Signer, - ) - - const tx = await postGateway.postBatch(postsArray) - await novaPubClient.waitForTransactionReceipt({ - hash: tx.hash as Hex, + const successfulTxHash = await waitUntilTx({ + projectID: projectId as string, + txID: postTx.transactionId, + authToken: authToken as string, }) - return new Response(JSON.stringify({ success: true, hash: tx.hash }), { - status: 200, - headers: { 'Content-Type': 'application/json' }, - }) + return new Response( + JSON.stringify({ success: true, hash: successfulTxHash }), + { + status: 200, + headers: { 'Content-Type': 'application/json' }, + }, + ) } catch (error) { let errorMessage = 'Unknown error' let statusCode = 500 @@ -57,4 +61,4 @@ export async function POST(req: NextRequest) { }, ) } -} +} \ No newline at end of file diff --git a/apps/site/app/api/registerFor/route.ts b/apps/site/app/api/registerFor/route.ts index ebf2d7db..90e39fb7 100644 --- a/apps/site/app/api/registerFor/route.ts +++ b/apps/site/app/api/registerFor/route.ts @@ -1,9 +1,13 @@ import { optimismPubClient } from '@/config/publicClient' -import { Defender } from '@openzeppelin/defender-sdk' -import { ethers } from 'ethers' import type { NextRequest } from 'next/server' -import { addresses, idRegistryABI } from 'scrypt' import { type Hex, decodeAbiParameters } from 'viem' +import { + syndicateClient, + generateIdRegistryInput, + projectId +} from '@/config/syndicateClient' +import { waitUntilTx, authToken } from '@/lib' + export const maxDuration = 30 // This function can run for a maximum of 30 seconds @@ -15,50 +19,49 @@ export async function POST(req: NextRequest) { const { to, recovery, deadline, sig } = userWithoutUsername console.log({ userWithoutUsername }) - const credentials = { - relayerApiKey: process.env.IDREGISTRY_API_UNO, - relayerApiSecret: process.env.IDREGISTRY_SECRET_UNO, + + if (!syndicateClient) { + return new Response( + JSON.stringify({ + success: false, + hash: null, + error: 'Syndicate client not initialized', + }), + { + status: 500, + headers: { 'Content-Type': 'application/json' }, + }, + ) } try { - const defenderClient = new Defender(credentials) - const provider = defenderClient.relaySigner.getProvider() - const signer = defenderClient.relaySigner.getSigner(provider, { - speed: 'fast', - }) + const registerTx = + await syndicateClient.officialActions.transact.sendTransaction( + generateIdRegistryInput({ to, recovery, deadline, sig }), + ) - const idRegistry = new ethers.Contract( - addresses.idRegistry.optimism, - idRegistryABI, - signer as unknown as ethers.Signer, - ) - - const registerTxn = await idRegistry.registerFor( - to, - recovery, - deadline, - sig, - ) + const successfulTxHash = await waitUntilTx({ + projectID: projectId as string, + txID: registerTx.transactionId, + authToken: authToken as string, + }) - const txnReceipt = await optimismPubClient.waitForTransactionReceipt({ - hash: registerTxn.hash as Hex, - }) - const [rid, recoveryAddress] = decodeAbiParameters( + const [rid] = decodeAbiParameters( [ { name: 'rid', type: 'uint256' }, { name: 'recoveryAddress', type: 'address' }, ], - txnReceipt.logs[0].data, + successfulTxHash.logs[0].data, ) console.log('rid: ', rid) - console.log('transaction receipt: ', registerTxn) + console.log('transaction receipt: ', successfulTxHash) return new Response( JSON.stringify({ success: true, - hash: registerTxn.hash, + hash: successfulTxHash, rid: rid.toString(), }), { @@ -86,4 +89,4 @@ export async function POST(req: NextRequest) { }, ) } -} +} \ No newline at end of file diff --git a/apps/site/config/publicClient.ts b/apps/site/config/publicClient.ts index cd6035ba..9d672a69 100644 --- a/apps/site/config/publicClient.ts +++ b/apps/site/config/publicClient.ts @@ -1,13 +1,13 @@ import { http, createPublicClient } from 'viem' -import { optimism } from 'viem/chains' +import { optimism, optimismSepolia } from 'viem/chains' import { arbitrumNova } from './customChainConfig' export const optimismPubClient = createPublicClient({ - chain: optimism, + chain: optimismSepolia, transport: http(process.env.NEXT_PUBLIC_OPTIMISM_RPC_URL), }) export const novaPubClient = createPublicClient({ chain: arbitrumNova, transport: http(process.env.NEXT_PUBLIC_NOVA_RPC_URL), -}) +}) \ No newline at end of file diff --git a/apps/site/config/syndicateClient.ts b/apps/site/config/syndicateClient.ts new file mode 100644 index 00000000..77f1dcea --- /dev/null +++ b/apps/site/config/syndicateClient.ts @@ -0,0 +1,100 @@ +import { SyndicateClient } from '@syndicateio/syndicate-node' +import { addresses } from 'scrypt' + +type PostMessage = { + rid: bigint + timestamp: bigint + msgType: number + msgBody: string +} + +type Post = { + signer: string + message: PostMessage + hashType: number + hash: string + sigType: number + sig: string +} + +type Register = { + to: string + recovery: string + deadline: number + sig: string +} + +type PostBatchFunction = { + posts: Post[] +} + +export const projectId = process.env.SYNDICATE_PROJECT_ID_POSTGATEWAY + +if (!projectId) { + throw new Error( + 'SYNDICATE_PROJECT_ID_POSTGATEWAY is not defined in environment variables.', + ) +} + +export const generatePostBatchTxnInput = (postsArray: PostBatchFunction) => ({ + projectId: projectId, + contractAddress: addresses.postGateway.nova, + chainId: 42170, + functionSignature: + 'postBatch((address signer, (uint256 rid, uint256 timestamp, uint8 msgType, bytes msgBody) message, uint16 hashType, bytes32 hash, uint16 sigType, bytes sig)[] posts)', + args: { + posts: postsArray, + }, +}) + +export const generatePostTxnInput = (post: Post) => ({ + projectId: projectId, + contractAddress: addresses.postGateway.nova, + chainId: 42170, + functionSignature: + 'post((address signer, (uint256 rid, uint256 timestamp, uint8 msgType, bytes msgBody) message, uint16 hashType, bytes32 hash, uint16 sigType, bytes sig) post)', + args: { + post: post, + }, +}) + +export const generateIdRegistryInput = (register: Register) => ({ + projectId: projectId, + contractAddress: addresses.idRegistry.optimism, + chainId: 11155420, + functionSignature: + 'registerFor(address to, address recovery, uint256 deadline, bytes sig)', + args: { + to: register.to, + recovery: register.recovery, + deadline: register.deadline, + sig: register.sig, + }, +}) + +const apiKey = process.env.SYNDICATE_API_KEY + +export const syndicateClient = + !projectId || !apiKey + ? null + : { + officialActions: new SyndicateClient({ + token: () => apiKey, + }), + projectId: projectId, + generatePostTxnInput, + generatePostBatchTxnInput, + generateIdRegistryInput, + } + +if (!projectId || !apiKey) { + throw new Error( + 'Missing SYNDICATE_PROJECT_ID_POSTGATEWAY or SYNDICATE_API_KEY in environment variables.', + ) +} + +if (!projectId || !apiKey) { + throw new Error( + 'Missing SYNDICATE_PROJECT_ID_POSTGATEWAY or SYNDICATE_API_KEY in environment variables.', + ) +} \ No newline at end of file diff --git a/apps/site/lib/api.ts b/apps/site/lib/api.ts index cffc7886..269b5f44 100644 --- a/apps/site/lib/api.ts +++ b/apps/site/lib/api.ts @@ -1,7 +1,3 @@ -'use client' - -import { getAccessToken } from '@privy-io/react-auth' - type Message = { rid: bigint timestamp: bigint @@ -25,6 +21,102 @@ type User = { sig: string } +export interface TransactionAttempt { + block: number + blockCreatedAt: string + chainId: number + createdAt: string + hash: string + nonce: number + reverted: boolean + signedTxn: string + status: string + transactionId: string + updatedAt: string + walletAddress: string +} + +export interface SyndicateApiResponse { + chainId: number + contractAddress: string + createdAt: string + data: string + decodedData: object + functionSignature: string + invalid: boolean + projectId: string + transactionAttempts: TransactionAttempt[] + transactionId: string + updatedAt: string + value: string +} + +export interface WaitUntilTxOptions { + projectID: string + txID: string + authToken: string + maxAttempts?: number + every?: number +} + +export const authToken = process.env.SYNDICATE_API_KEY + +export const getTransactionRequest = async ({ + projectID, + txID, + authToken, +}: Pick & { authToken: string }) => { + const response = await fetch( + `https://api.syndicate.io/wallet/project/${projectID}/request/${txID}`, + { + method: 'GET', + headers: { Authorization: `Bearer ${authToken}` }, + }, + ) + if (!response.ok) { + throw new Error(`Failed to get transaction request: ${response.statusText}`) + } + return response.json() +} + +export async function waitUntilTx({ + projectID, + txID, + authToken, + maxAttempts = 20, + every = 1000, +}: WaitUntilTxOptions) { + let currAttempts = 0 + let transactionHash = null + + while (!transactionHash && currAttempts < maxAttempts) { + const txAttempts = ( + await getTransactionRequest({ projectID, txID, authToken }) + )?.transactionAttempts + + console.log({ txAttempts }) + + if (txAttempts && txAttempts.length > 0) { + const lastAttempt = txAttempts[txAttempts.length - 1] + if (lastAttempt.status === 'PENDING' && !lastAttempt.reverted) { + transactionHash = lastAttempt.hash + break + } + } + + currAttempts++ + if (!transactionHash && currAttempts < maxAttempts) { + await new Promise((resolve) => setTimeout(resolve, every)) + } + } + + if (!transactionHash) { + throw new Error('Transaction not found within maximum attempts') + } + + return transactionHash +} + /* API ROUTES */ // This is in to help with serialization of bigints during json stringify @@ -84,8 +176,7 @@ export async function relayRegisterFor( /* MEDIA SERVICE */ -export async function w3sUpload(body: FormData) { - const authToken = await getAccessToken() +export async function w3sUpload(body: FormData, authToken: string | null) { try { const res = await fetch('https://river-media-service.up.railway.app/w3s', { method: 'POST', @@ -96,9 +187,7 @@ export async function w3sUpload(body: FormData) { if (res.status === 413) { console.error('File too large') throw new Error('File too large. Please try a smaller file.') - } - - if (!res.ok) { + } else if (!res.ok) { const errorText = await res.text() console.error('Could not upload file', errorText) throw new Error( @@ -113,31 +202,23 @@ export async function w3sUpload(body: FormData) { } } -export async function uploadToMux(body: string) { - const authToken = await getAccessToken() - try { - const res = await fetch( - 'https://river-media-service.up.railway.app/mux/upload', - { - method: 'POST', - headers: authToken - ? { Authorization: `Bearer ${authToken}` } - : undefined, - body, - }, - ) - if (!res.ok) { - console.error('Could not upload to Mux', await res.text()) - throw new Error('Could not upload to Mux') - } - const muxResponseData = await res.json() +export async function uploadToMux(body: string, authToken: string | null) { + const res = await fetch( + 'https://river-media-service.up.railway.app/mux/upload', + { + method: 'POST', + headers: authToken ? { Authorization: `Bearer ${authToken}` } : undefined, + body, + }, + ) + if (!res.ok) { + console.error('Could not upload to Mux', await res.text()) + throw new Error('Could not upload to Mux') + } + const muxResponseData = await res.json() - return { - id: muxResponseData.id, - playbackId: muxResponseData.playbackId, - } - } catch (error) { - console.error('Upload to Mux failed', error) - throw error + return { + id: muxResponseData.id, + playbackId: muxResponseData.playbackId, } -} +} \ No newline at end of file diff --git a/apps/site/package.json b/apps/site/package.json index 9a205ea1..79d2cd8f 100644 --- a/apps/site/package.json +++ b/apps/site/package.json @@ -29,6 +29,7 @@ "@radix-ui/react-popover": "^1.0.7", "@radix-ui/react-separator": "^1.0.3", "@radix-ui/react-slot": "^1.0.2", + "@syndicateio/syndicate-node": "^1.0.1", "@vercel/analytics": "^1.0.2", "@vercel/kv": "^1.0.0", "base64url": "^3.0.1", diff --git a/packages/scrypt/constants/addresses.ts b/packages/scrypt/constants/addresses.ts index e3a189e4..e27e73bf 100644 --- a/packages/scrypt/constants/addresses.ts +++ b/packages/scrypt/constants/addresses.ts @@ -9,8 +9,12 @@ type AddressBook = { } export const addresses: AddressBook = { + // idRegistry: { + // optimism: '0x44192479891D358Ec917765dbF6472B916DC9A0C', + // }, + // optimism sepolia idRegistry: { - optimism: '0x44192479891D358Ec917765dbF6472B916DC9A0C', + optimism: '0xaa5914c16c40c029635493a8713051a3ee45ee1f', }, postGateway: { nova: '0x423a602F5e551A25b28eb33eB56B961590aD5290', @@ -18,4 +22,4 @@ export const addresses: AddressBook = { riverRecovery: { optimism: '0xFB0F92f8abdFA25415ADbb6EC0cd9EC33953F29a', }, -} +} \ No newline at end of file diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 10fe00a0..d0fd0af1 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -130,6 +130,9 @@ importers: '@radix-ui/react-slot': specifier: ^1.0.2 version: 1.0.2(@types/react@18.2.21)(react@18.2.0) + '@syndicateio/syndicate-node': + specifier: ^1.0.1 + version: 1.0.1 '@vercel/analytics': specifier: ^1.0.2 version: 1.0.2 @@ -4901,6 +4904,18 @@ packages: tslib: 2.6.2 dev: false + /@syndicateio/syndicate-node@1.0.1: + resolution: {integrity: sha512-WaXyHPabxLL73qnkrzdOzeaqC+6hccnnnkRCQsreIYPteHSOk7AjGrHTgRBcPHGPtdv35rQEG/4vv5WkxHtCoA==} + dependencies: + form-data: 4.0.0 + js-base64: 3.7.2 + node-fetch: 2.7.0(encoding@0.1.13) + qs: 6.11.2 + url-join: 4.0.1 + transitivePeerDependencies: + - encoding + dev: false + /@szmarczak/http-timer@4.0.6: resolution: {integrity: sha512-4BAffykYOgO+5nzBWYwE3W90sBgLJoUPRWWcL8wlyiM8IB8ipJz3UMJ9KXQd1RKQXpKp8Tutn80HZtWsu2u76w==} engines: {node: '>=10'} @@ -6522,14 +6537,6 @@ packages: responselike: 2.0.1 dev: false - /call-bind@1.0.5: - resolution: {integrity: sha512-C3nQxfFZxFRVoJoGKKI8y3MOEo129NQ+FgQ08iye+Mk4zNZZGdjfs06bVTr+DBSlA66Q2VEcMki/cUCP4SercQ==} - dependencies: - function-bind: 1.1.2 - get-intrinsic: 1.2.2 - set-function-length: 1.1.1 - dev: true - /call-bind@1.0.7: resolution: {integrity: sha512-GHTSNSYICQ7scH7sZ+M2rFopRoLh8t2bLSW6BbgrtLsahOIB5iyAVJf9GjWK3cYTDaMj4XdBpM1cA6pIS0Kv2w==} engines: {node: '>= 0.4'} @@ -6539,7 +6546,6 @@ packages: function-bind: 1.1.2 get-intrinsic: 1.2.4 set-function-length: 1.2.1 - dev: false /callsites@3.1.0: resolution: {integrity: sha512-P8BjAsXvZS+VIDUI11hHCQEv74YT67YUi5JJFNWIqL235sBmjX4+qx9Muvls5ivyNENctx46xQLQ3aTuE7ssaQ==} @@ -7312,15 +7318,6 @@ packages: engines: {node: '>=10'} dev: false - /define-data-property@1.1.1: - resolution: {integrity: sha512-E7uGkTzkk1d0ByLeSc6ZsFS79Axg+m1P/VsgYsxHgiuc3tFSj+MjMIwe90FC4lOAZzNBdY7kkO2P2wKdsQ1vgQ==} - engines: {node: '>= 0.4'} - dependencies: - get-intrinsic: 1.2.4 - gopd: 1.0.1 - has-property-descriptors: 1.0.1 - dev: true - /define-data-property@1.1.4: resolution: {integrity: sha512-rBMvIzlpA8v6E+SJZoo++HAYqsLrkg7MSfIinMPFhmkorw7X+dOXVJQs+QT69zGkzMyfDnIMN2Wid1+NbL3T+A==} engines: {node: '>= 0.4'} @@ -7328,7 +7325,6 @@ packages: es-define-property: 1.0.0 es-errors: 1.3.0 gopd: 1.0.1 - dev: false /defu@6.1.3: resolution: {integrity: sha512-Vy2wmG3NTkmHNg/kzpuvHhkqeIx3ODWqasgCRbKtbXEN0G+HpEEv9BtJLp7ZG1CZloFaC41Ah3ZFbq7aqCqMeQ==} @@ -7607,7 +7603,6 @@ packages: engines: {node: '>= 0.4'} dependencies: get-intrinsic: 1.2.4 - dev: false /es-errors@1.3.0: resolution: {integrity: sha512-Zf5H2Kxt2xjTvbJvP2ZWLEICxA6j+hAmMzIlypy4xcBg1vKVnx89Wy0GbS+kf5cwCVFFzdCFh2XSCFNULS6csw==} @@ -8587,15 +8582,6 @@ packages: resolution: {integrity: sha512-DyFP3BM/3YHTQOCUL/w0OZHR0lpKeGrxotcHWcqNEdnltqFwXVfhEBQ94eIo34AfQpo0rGki4cyIiftY06h2Fg==} engines: {node: 6.* || 8.* || >= 10.*} - /get-intrinsic@1.2.2: - resolution: {integrity: sha512-0gSo4ml/0j98Y3lngkFEot/zhiCeWsbYIlZ+uZOVgzLyLaUw7wxUL+nCTP0XJvJg1AXulJRI3UJi8GsbDuxdGA==} - dependencies: - function-bind: 1.1.2 - has-proto: 1.0.1 - has-symbols: 1.0.3 - hasown: 2.0.1 - dev: true - /get-intrinsic@1.2.4: resolution: {integrity: sha512-5uYhsJH8VJBTv7oslg4BznJYhDoRI6waYCxMmCdnTrcCrHA/fCFKoTFz2JKKE0HdDFUF7/oQuhzumXJK7paBRQ==} engines: {node: '>= 0.4'} @@ -8898,17 +8884,10 @@ packages: engines: {node: '>=8'} dev: true - /has-property-descriptors@1.0.1: - resolution: {integrity: sha512-VsX8eaIewvas0xnvinAe9bw4WfIeODpGYikiWYLH+dma0Jw6KHYqWiWfhQlgOVK8D6PvjubK5Uc4P0iIhIcNVg==} - dependencies: - get-intrinsic: 1.2.4 - dev: true - /has-property-descriptors@1.0.2: resolution: {integrity: sha512-55JNKuIW+vq4Ke1BjOTjM2YctQIvCT7GFzHwmfZPGo5wnrgkid0YQtnAleFSqumZm4az3n2BS+erby5ipJdgrg==} dependencies: es-define-property: 1.0.0 - dev: false /has-proto@1.0.1: resolution: {integrity: sha512-7qE+iP+O+bgF9clE5+UoBFzE65mlBiVj3tKCrlNQ0Ogwm0BjpT/gK4SlLYDMybDh5I3TCTKnPPa0oMG7JDYrhg==} @@ -8946,12 +8925,6 @@ packages: minimalistic-assert: 1.0.1 dev: false - /hasown@2.0.0: - resolution: {integrity: sha512-vUptKVTpIJhcczKBbgnS+RtcuYMB8+oNzPK2/Hp3hanz8JmpATdmmgLgSaadVREkDm+e2giHwY3ZRkyjSIDDFA==} - engines: {node: '>= 0.4'} - dependencies: - function-bind: 1.1.2 - /hasown@2.0.1: resolution: {integrity: sha512-1/th4MHjnwncwXsIW6QMzlvYL9kG5e/CpVvLRZe4XPa8TOUNbCELqmvhDmnkNsAjwaG4+I8gJJL0JBvTTLO9qA==} engines: {node: '>= 0.4'} @@ -9453,7 +9426,7 @@ packages: /is-core-module@2.13.1: resolution: {integrity: sha512-hHrIjvZsftOsvKSn2TRYl63zvxsgE0K+0mYMoH6gD4omR5IWB2KynivBQczo3+wF1cCkjzvptnI9Q0sPU66ilw==} dependencies: - hasown: 2.0.0 + hasown: 2.0.1 /is-decimal@2.0.1: resolution: {integrity: sha512-AAB9hiomQs5DXWcRB1rqsxGUstbRroFOPPVAomNk/3XHR5JyEZChOyTWe2oayKnsSsr/kcGqF+z6yuH6HHpN0A==} @@ -9691,6 +9664,10 @@ packages: engines: {node: '>=10'} dev: false + /js-base64@3.7.2: + resolution: {integrity: sha512-NnRs6dsyqUXejqk/yv2aiXlAvOs56sLkX6nUdeaNezI5LFFLlsZjOThmwnrcwh5ZZRwZlCMnVAY3CvhIhoVEKQ==} + dev: false + /js-cookie@2.2.1: resolution: {integrity: sha512-HvdH2LzI/EAZcUwA8+0nKNtWHqS+ZmijLA30RwZA0bo7ToCckjK5MkGhjED9KoRcXO6BaGI3I9UIzSA1FKFPOQ==} dev: false @@ -9773,7 +9750,7 @@ packages: resolution: {integrity: sha512-zfA+5SuwYN2VWqN1/5HZaDzQKLJHaBVMZIIM+wuYjdptkaQsqzDdqjqf+lZZJUuJq1aanHiY8LhH8LmH+qBYJA==} engines: {node: '>= 0.4'} dependencies: - call-bind: 1.0.5 + call-bind: 1.0.7 isarray: 2.0.5 jsonify: 0.0.1 object-keys: 1.1.1 @@ -12230,6 +12207,13 @@ packages: side-channel: 1.0.4 dev: false + /qs@6.11.2: + resolution: {integrity: sha512-tDNIz22aBzCDxLtVH++VnTfzxlfeK5CbqohpSqpJgj1Wg/cQbStNAz3NuqCs5vV+pjBsK4x4pN9HlVh7rcYRiA==} + engines: {node: '>=0.6'} + dependencies: + side-channel: 1.0.4 + dev: false + /qs@6.5.3: resolution: {integrity: sha512-qxXIEh4pCGfHICj1mAJQ2/2XVZkjCDTcEgfoSQxc/fYivUZxTkk7L3bDBJSoNrEzXI17oUO5Dp07ktqE5KzczA==} engines: {node: '>=0.6'} @@ -13015,16 +12999,6 @@ packages: /set-blocking@2.0.0: resolution: {integrity: sha512-KiKBS8AnWGEyLzofFfmvKwpdPzqiy16LvQfK3yv/fVH7Bj13/wl3JSR1J+rfgRE9q7xUJK4qvgS8raSOeLUehw==} - /set-function-length@1.1.1: - resolution: {integrity: sha512-VoaqjbBJKiWtg4yRcKBQ7g7wnGnLV3M8oLvVWwOk2PdYY6PEFegR1vezXR0tw6fZGF9csVakIRjrJiy2veSBFQ==} - engines: {node: '>= 0.4'} - dependencies: - define-data-property: 1.1.1 - get-intrinsic: 1.2.4 - gopd: 1.0.1 - has-property-descriptors: 1.0.1 - dev: true - /set-function-length@1.2.1: resolution: {integrity: sha512-j4t6ccc+VsKwYHso+kElc5neZpjtq9EnRICFZtWyBsLojhmeF/ZBd/elqm22WJh/BziDe/SBiOeAt0m2mfLD0g==} engines: {node: '>= 0.4'} @@ -13035,7 +13009,6 @@ packages: get-intrinsic: 1.2.4 gopd: 1.0.1 has-property-descriptors: 1.0.2 - dev: false /set-harmonic-interval@1.0.1: resolution: {integrity: sha512-AhICkFV84tBP1aWqPwLZqFvAwqEoVA9kxNMniGEUvzOlm4vLmOFLiTT3UZ6bziJTy4bOVpzWGTfSCbmaayGx8g==} @@ -14282,6 +14255,10 @@ packages: punycode: 2.3.1 dev: false + /url-join@4.0.1: + resolution: {integrity: sha512-jk1+QP6ZJqyOiuEI9AEWQfju/nB2Pw466kbA0LEZljHwKeMgd9WrAEgEGxjPDD2+TNbbb37rTyhEfrCXfuKXnA==} + dev: false + /url-set-query@1.0.0: resolution: {integrity: sha512-3AChu4NiXquPfeckE5R5cGdiHCMWJx1dwCWOmWIL4KHAziJNOFIYJlpGFeKDvwLPHovZRCxK3cYlwzqI9Vp+Gg==} dev: false From c52826a61e5e2fe1e2d24c8c3467a992d7e6486a Mon Sep 17 00:00:00 2001 From: jawndiego Date: Sun, 16 Jun 2024 19:10:05 -0400 Subject: [PATCH 02/23] matches main --- apps/site/lib/api.ts | 51 +++++++++++++++++++++++++++----------------- 1 file changed, 32 insertions(+), 19 deletions(-) diff --git a/apps/site/lib/api.ts b/apps/site/lib/api.ts index 269b5f44..f4dbc322 100644 --- a/apps/site/lib/api.ts +++ b/apps/site/lib/api.ts @@ -1,3 +1,5 @@ +import { getAccessToken } from '@privy-io/react-auth' + type Message = { rid: bigint timestamp: bigint @@ -176,7 +178,8 @@ export async function relayRegisterFor( /* MEDIA SERVICE */ -export async function w3sUpload(body: FormData, authToken: string | null) { +export async function w3sUpload(body: FormData) { + const authToken = await getAccessToken() try { const res = await fetch('https://river-media-service.up.railway.app/w3s', { method: 'POST', @@ -187,7 +190,9 @@ export async function w3sUpload(body: FormData, authToken: string | null) { if (res.status === 413) { console.error('File too large') throw new Error('File too large. Please try a smaller file.') - } else if (!res.ok) { + } + + if (!res.ok) { const errorText = await res.text() console.error('Could not upload file', errorText) throw new Error( @@ -202,23 +207,31 @@ export async function w3sUpload(body: FormData, authToken: string | null) { } } -export async function uploadToMux(body: string, authToken: string | null) { - const res = await fetch( - 'https://river-media-service.up.railway.app/mux/upload', - { - method: 'POST', - headers: authToken ? { Authorization: `Bearer ${authToken}` } : undefined, - body, - }, - ) - if (!res.ok) { - console.error('Could not upload to Mux', await res.text()) - throw new Error('Could not upload to Mux') - } - const muxResponseData = await res.json() +export async function uploadToMux(body: string) { + const authToken = await getAccessToken() + try { + const res = await fetch( + 'https://river-media-service.up.railway.app/mux/upload', + { + method: 'POST', + headers: authToken + ? { Authorization: `Bearer ${authToken}` } + : undefined, + body, + }, + ) + if (!res.ok) { + console.error('Could not upload to Mux', await res.text()) + throw new Error('Could not upload to Mux') + } + const muxResponseData = await res.json() - return { - id: muxResponseData.id, - playbackId: muxResponseData.playbackId, + return { + id: muxResponseData.id, + playbackId: muxResponseData.playbackId, + } + } catch (error) { + console.error('Upload to Mux failed', error) + throw error } } \ No newline at end of file From 97ef2e5952c8823790df94d08177cad32cd36bd4 Mon Sep 17 00:00:00 2001 From: jawndiego Date: Sun, 16 Jun 2024 19:10:42 -0400 Subject: [PATCH 03/23] formatting --- apps/site/app/api/post/route.ts | 3 +-- apps/site/app/api/postBatch/route.ts | 2 +- apps/site/app/api/registerFor/route.ts | 16 +++++++--------- apps/site/config/publicClient.ts | 2 +- apps/site/config/syndicateClient.ts | 2 +- apps/site/lib/api.ts | 2 +- 6 files changed, 12 insertions(+), 15 deletions(-) diff --git a/apps/site/app/api/post/route.ts b/apps/site/app/api/post/route.ts index 340de104..33c56023 100644 --- a/apps/site/app/api/post/route.ts +++ b/apps/site/app/api/post/route.ts @@ -9,7 +9,6 @@ import { addresses, postGatewayABI } from 'scrypt' import type { Hex } from 'viem' import { waitUntilTx, authToken } from '@/lib' - export const maxDuration = 30 // This function can run for a maximum of 30 seconds export async function POST(req: NextRequest) { @@ -66,4 +65,4 @@ export async function POST(req: NextRequest) { }, ) } -} \ No newline at end of file +} diff --git a/apps/site/app/api/postBatch/route.ts b/apps/site/app/api/postBatch/route.ts index f2c89c02..47c5e179 100644 --- a/apps/site/app/api/postBatch/route.ts +++ b/apps/site/app/api/postBatch/route.ts @@ -61,4 +61,4 @@ export async function POST(req: NextRequest) { }, ) } -} \ No newline at end of file +} diff --git a/apps/site/app/api/registerFor/route.ts b/apps/site/app/api/registerFor/route.ts index 90e39fb7..2e51e817 100644 --- a/apps/site/app/api/registerFor/route.ts +++ b/apps/site/app/api/registerFor/route.ts @@ -4,11 +4,10 @@ import { type Hex, decodeAbiParameters } from 'viem' import { syndicateClient, generateIdRegistryInput, - projectId + projectId, } from '@/config/syndicateClient' import { waitUntilTx, authToken } from '@/lib' - export const maxDuration = 30 // This function can run for a maximum of 30 seconds export async function POST(req: NextRequest) { @@ -40,12 +39,11 @@ export async function POST(req: NextRequest) { generateIdRegistryInput({ to, recovery, deadline, sig }), ) - const successfulTxHash = await waitUntilTx({ - projectID: projectId as string, - txID: registerTx.transactionId, - authToken: authToken as string, - }) - + const successfulTxHash = await waitUntilTx({ + projectID: projectId as string, + txID: registerTx.transactionId, + authToken: authToken as string, + }) const [rid] = decodeAbiParameters( [ @@ -89,4 +87,4 @@ export async function POST(req: NextRequest) { }, ) } -} \ No newline at end of file +} diff --git a/apps/site/config/publicClient.ts b/apps/site/config/publicClient.ts index 9d672a69..07129db1 100644 --- a/apps/site/config/publicClient.ts +++ b/apps/site/config/publicClient.ts @@ -10,4 +10,4 @@ export const optimismPubClient = createPublicClient({ export const novaPubClient = createPublicClient({ chain: arbitrumNova, transport: http(process.env.NEXT_PUBLIC_NOVA_RPC_URL), -}) \ No newline at end of file +}) diff --git a/apps/site/config/syndicateClient.ts b/apps/site/config/syndicateClient.ts index 77f1dcea..be04f21e 100644 --- a/apps/site/config/syndicateClient.ts +++ b/apps/site/config/syndicateClient.ts @@ -97,4 +97,4 @@ if (!projectId || !apiKey) { throw new Error( 'Missing SYNDICATE_PROJECT_ID_POSTGATEWAY or SYNDICATE_API_KEY in environment variables.', ) -} \ No newline at end of file +} diff --git a/apps/site/lib/api.ts b/apps/site/lib/api.ts index f4dbc322..a0091c4e 100644 --- a/apps/site/lib/api.ts +++ b/apps/site/lib/api.ts @@ -234,4 +234,4 @@ export async function uploadToMux(body: string) { console.error('Upload to Mux failed', error) throw error } -} \ No newline at end of file +} From a71449b6549c92ebde7d618a8290b6b7da48a664 Mon Sep 17 00:00:00 2001 From: jawndiego Date: Sun, 16 Jun 2024 19:23:32 -0400 Subject: [PATCH 04/23] distinguisihing project ids --- apps/site/app/api/post/route.ts | 4 ++-- apps/site/app/api/postBatch/route.ts | 4 ++-- apps/site/app/api/registerFor/route.ts | 4 ++-- apps/site/config/syndicateClient.ts | 22 +++++++++------------- 4 files changed, 15 insertions(+), 19 deletions(-) diff --git a/apps/site/app/api/post/route.ts b/apps/site/app/api/post/route.ts index 33c56023..d25fa486 100644 --- a/apps/site/app/api/post/route.ts +++ b/apps/site/app/api/post/route.ts @@ -1,7 +1,7 @@ import { syndicateClient, generatePostTxnInput, - projectId, + projectIdPost, } from '@/config/syndicateClient' import { ethers } from 'ethers' import type { NextRequest } from 'next/server' @@ -34,7 +34,7 @@ export async function POST(req: NextRequest) { ) const successfulTxHash = await waitUntilTx({ - projectID: projectId as string, + projectID: projectIdPost as string, txID: postTx.transactionId, authToken: authToken as string, }) diff --git a/apps/site/app/api/postBatch/route.ts b/apps/site/app/api/postBatch/route.ts index 47c5e179..4080688d 100644 --- a/apps/site/app/api/postBatch/route.ts +++ b/apps/site/app/api/postBatch/route.ts @@ -2,7 +2,7 @@ import type { NextRequest } from 'next/server' import { syndicateClient, generatePostBatchTxnInput, - projectId, + projectIdPost, } from '@/config/syndicateClient' import { waitUntilTx, authToken } from '@/lib' @@ -30,7 +30,7 @@ export async function POST(req: NextRequest) { ) const successfulTxHash = await waitUntilTx({ - projectID: projectId as string, + projectID: projectIdPost as string, txID: postTx.transactionId, authToken: authToken as string, }) diff --git a/apps/site/app/api/registerFor/route.ts b/apps/site/app/api/registerFor/route.ts index 2e51e817..9193a201 100644 --- a/apps/site/app/api/registerFor/route.ts +++ b/apps/site/app/api/registerFor/route.ts @@ -4,7 +4,7 @@ import { type Hex, decodeAbiParameters } from 'viem' import { syndicateClient, generateIdRegistryInput, - projectId, + projectIdRegistry, } from '@/config/syndicateClient' import { waitUntilTx, authToken } from '@/lib' @@ -40,7 +40,7 @@ export async function POST(req: NextRequest) { ) const successfulTxHash = await waitUntilTx({ - projectID: projectId as string, + projectID: projectIdRegistry as string, txID: registerTx.transactionId, authToken: authToken as string, }) diff --git a/apps/site/config/syndicateClient.ts b/apps/site/config/syndicateClient.ts index be04f21e..96f92f79 100644 --- a/apps/site/config/syndicateClient.ts +++ b/apps/site/config/syndicateClient.ts @@ -28,16 +28,13 @@ type PostBatchFunction = { posts: Post[] } -export const projectId = process.env.SYNDICATE_PROJECT_ID_POSTGATEWAY +export const projectIdPost = process.env.SYNDICATE_PROJECT_ID_POSTGATEWAY! +export const projectIdRegistry = process.env.SYNDICATE_PROJECT_ID_REGISTRY! + -if (!projectId) { - throw new Error( - 'SYNDICATE_PROJECT_ID_POSTGATEWAY is not defined in environment variables.', - ) -} export const generatePostBatchTxnInput = (postsArray: PostBatchFunction) => ({ - projectId: projectId, + projectId: projectIdPost, contractAddress: addresses.postGateway.nova, chainId: 42170, functionSignature: @@ -48,7 +45,7 @@ export const generatePostBatchTxnInput = (postsArray: PostBatchFunction) => ({ }) export const generatePostTxnInput = (post: Post) => ({ - projectId: projectId, + projectId: projectIdPost, contractAddress: addresses.postGateway.nova, chainId: 42170, functionSignature: @@ -59,7 +56,7 @@ export const generatePostTxnInput = (post: Post) => ({ }) export const generateIdRegistryInput = (register: Register) => ({ - projectId: projectId, + projectId: projectIdRegistry, contractAddress: addresses.idRegistry.optimism, chainId: 11155420, functionSignature: @@ -75,25 +72,24 @@ export const generateIdRegistryInput = (register: Register) => ({ const apiKey = process.env.SYNDICATE_API_KEY export const syndicateClient = - !projectId || !apiKey + !projectIdRegistry|| projectIdPost|| !apiKey ? null : { officialActions: new SyndicateClient({ token: () => apiKey, }), - projectId: projectId, generatePostTxnInput, generatePostBatchTxnInput, generateIdRegistryInput, } -if (!projectId || !apiKey) { +if (!projectIdRegistry|| projectIdPost || !apiKey) { throw new Error( 'Missing SYNDICATE_PROJECT_ID_POSTGATEWAY or SYNDICATE_API_KEY in environment variables.', ) } -if (!projectId || !apiKey) { +if (!projectIdRegistry|| projectIdPost || !apiKey) { throw new Error( 'Missing SYNDICATE_PROJECT_ID_POSTGATEWAY or SYNDICATE_API_KEY in environment variables.', ) From fd740217be4308e5b1aad62d039943942a32ba8d Mon Sep 17 00:00:00 2001 From: jawndiego Date: Sun, 16 Jun 2024 19:28:59 -0400 Subject: [PATCH 05/23] env --- apps/site/config/syndicateClient.ts | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/apps/site/config/syndicateClient.ts b/apps/site/config/syndicateClient.ts index 96f92f79..16009c72 100644 --- a/apps/site/config/syndicateClient.ts +++ b/apps/site/config/syndicateClient.ts @@ -83,14 +83,3 @@ export const syndicateClient = generateIdRegistryInput, } -if (!projectIdRegistry|| projectIdPost || !apiKey) { - throw new Error( - 'Missing SYNDICATE_PROJECT_ID_POSTGATEWAY or SYNDICATE_API_KEY in environment variables.', - ) -} - -if (!projectIdRegistry|| projectIdPost || !apiKey) { - throw new Error( - 'Missing SYNDICATE_PROJECT_ID_POSTGATEWAY or SYNDICATE_API_KEY in environment variables.', - ) -} From 5af932d224f0cc1798bb7e909c4e90cac16f7595 Mon Sep 17 00:00:00 2001 From: jawndiego Date: Sun, 16 Jun 2024 19:30:56 -0400 Subject: [PATCH 06/23] registry --- apps/site/config/syndicateClient.ts | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/apps/site/config/syndicateClient.ts b/apps/site/config/syndicateClient.ts index 16009c72..49e548a3 100644 --- a/apps/site/config/syndicateClient.ts +++ b/apps/site/config/syndicateClient.ts @@ -29,9 +29,7 @@ type PostBatchFunction = { } export const projectIdPost = process.env.SYNDICATE_PROJECT_ID_POSTGATEWAY! -export const projectIdRegistry = process.env.SYNDICATE_PROJECT_ID_REGISTRY! - - +export const projectIdRegistry = process.env.SYNDICATE_PROJECT_ID_IDREGISTRY! export const generatePostBatchTxnInput = (postsArray: PostBatchFunction) => ({ projectId: projectIdPost, @@ -72,7 +70,7 @@ export const generateIdRegistryInput = (register: Register) => ({ const apiKey = process.env.SYNDICATE_API_KEY export const syndicateClient = - !projectIdRegistry|| projectIdPost|| !apiKey + !projectIdRegistry || projectIdPost || !apiKey ? null : { officialActions: new SyndicateClient({ @@ -82,4 +80,3 @@ export const syndicateClient = generatePostBatchTxnInput, generateIdRegistryInput, } - From e66f133d7984954916524bb7d6159029aa394135 Mon Sep 17 00:00:00 2001 From: jawndiego Date: Sun, 16 Jun 2024 19:56:50 -0400 Subject: [PATCH 07/23] non null --- apps/site/config/syndicateClient.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/apps/site/config/syndicateClient.ts b/apps/site/config/syndicateClient.ts index 49e548a3..8a3dc987 100644 --- a/apps/site/config/syndicateClient.ts +++ b/apps/site/config/syndicateClient.ts @@ -28,8 +28,10 @@ type PostBatchFunction = { posts: Post[] } -export const projectIdPost = process.env.SYNDICATE_PROJECT_ID_POSTGATEWAY! -export const projectIdRegistry = process.env.SYNDICATE_PROJECT_ID_IDREGISTRY! +export const projectIdPost = + process.env.SYNDICATE_PROJECT_ID_POSTGATEWAY ?? 'Error' +export const projectIdRegistry = + process.env.SYNDICATE_PROJECT_ID_IDREGISTRY ?? 'Error' export const generatePostBatchTxnInput = (postsArray: PostBatchFunction) => ({ projectId: projectIdPost, From c12cb45c90e7c9665fdaa5d99f914ea05fa85f7e Mon Sep 17 00:00:00 2001 From: jawndiego Date: Sun, 16 Jun 2024 20:04:29 -0400 Subject: [PATCH 08/23] syndicate client --- apps/site/config/syndicateClient.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/apps/site/config/syndicateClient.ts b/apps/site/config/syndicateClient.ts index 8a3dc987..b84af3f3 100644 --- a/apps/site/config/syndicateClient.ts +++ b/apps/site/config/syndicateClient.ts @@ -72,12 +72,13 @@ export const generateIdRegistryInput = (register: Register) => ({ const apiKey = process.env.SYNDICATE_API_KEY export const syndicateClient = - !projectIdRegistry || projectIdPost || !apiKey + !projectIdRegistry || !projectIdPost || !apiKey ? null : { officialActions: new SyndicateClient({ - token: () => apiKey, + token: () => apiKey }), + projectId: projectIdPost! || projectIdRegistry!, generatePostTxnInput, generatePostBatchTxnInput, generateIdRegistryInput, From 9853014da8120afc54deb2ff8bd4061514a9e37e Mon Sep 17 00:00:00 2001 From: jawndiego Date: Sun, 16 Jun 2024 20:05:55 -0400 Subject: [PATCH 09/23] non null --- apps/site/config/syndicateClient.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/apps/site/config/syndicateClient.ts b/apps/site/config/syndicateClient.ts index b84af3f3..99221220 100644 --- a/apps/site/config/syndicateClient.ts +++ b/apps/site/config/syndicateClient.ts @@ -76,9 +76,9 @@ export const syndicateClient = ? null : { officialActions: new SyndicateClient({ - token: () => apiKey + token: () => apiKey, }), - projectId: projectIdPost! || projectIdRegistry!, + projectId: projectIdPost || projectIdRegistry, generatePostTxnInput, generatePostBatchTxnInput, generateIdRegistryInput, From f88bd8e79ceaf3081cf0895b482d2402ae9dcb8d Mon Sep 17 00:00:00 2001 From: jawndiego Date: Sun, 16 Jun 2024 20:12:05 -0400 Subject: [PATCH 10/23] use client --- apps/site/lib/api.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/apps/site/lib/api.ts b/apps/site/lib/api.ts index a0091c4e..1d6eb48f 100644 --- a/apps/site/lib/api.ts +++ b/apps/site/lib/api.ts @@ -1,3 +1,4 @@ +'use client' import { getAccessToken } from '@privy-io/react-auth' type Message = { From 349512a604075c8797325971722e7d19c37c326d Mon Sep 17 00:00:00 2001 From: jawndiego Date: Sun, 16 Jun 2024 21:28:42 -0400 Subject: [PATCH 11/23] client diff --- apps/site/app/api/post/route.ts | 6 +++--- apps/site/app/api/postBatch/route.ts | 6 +++--- apps/site/app/api/registerFor/route.ts | 6 +++--- apps/site/config/syndicateClient.ts | 26 +++++++++++++++++++------- 4 files changed, 28 insertions(+), 16 deletions(-) diff --git a/apps/site/app/api/post/route.ts b/apps/site/app/api/post/route.ts index d25fa486..e06d74db 100644 --- a/apps/site/app/api/post/route.ts +++ b/apps/site/app/api/post/route.ts @@ -1,5 +1,5 @@ import { - syndicateClient, + syndicateClientPost, generatePostTxnInput, projectIdPost, } from '@/config/syndicateClient' @@ -14,7 +14,7 @@ export const maxDuration = 30 // This function can run for a maximum of 30 secon export async function POST(req: NextRequest) { const post = await req.json() - if (!syndicateClient) { + if (!syndicateClientPost) { return new Response( JSON.stringify({ success: false, @@ -29,7 +29,7 @@ export async function POST(req: NextRequest) { } try { const postTx = - await syndicateClient.officialActions.transact.sendTransaction( + await syndicateClientPost.officialActions.transact.sendTransaction( generatePostTxnInput(post), ) diff --git a/apps/site/app/api/postBatch/route.ts b/apps/site/app/api/postBatch/route.ts index 4080688d..040c458c 100644 --- a/apps/site/app/api/postBatch/route.ts +++ b/apps/site/app/api/postBatch/route.ts @@ -1,6 +1,6 @@ import type { NextRequest } from 'next/server' import { - syndicateClient, + syndicateClientPost, generatePostBatchTxnInput, projectIdPost, } from '@/config/syndicateClient' @@ -9,7 +9,7 @@ import { waitUntilTx, authToken } from '@/lib' export async function POST(req: NextRequest) { const postsArray = await req.json() - if (!syndicateClient) { + if (!syndicateClientPost) { return new Response( JSON.stringify({ success: false, @@ -25,7 +25,7 @@ export async function POST(req: NextRequest) { try { const postTx = - await syndicateClient.officialActions.transact.sendTransaction( + await syndicateClientPost.officialActions.transact.sendTransaction( generatePostBatchTxnInput(postsArray), ) diff --git a/apps/site/app/api/registerFor/route.ts b/apps/site/app/api/registerFor/route.ts index 9193a201..1ea00f8f 100644 --- a/apps/site/app/api/registerFor/route.ts +++ b/apps/site/app/api/registerFor/route.ts @@ -2,7 +2,7 @@ import { optimismPubClient } from '@/config/publicClient' import type { NextRequest } from 'next/server' import { type Hex, decodeAbiParameters } from 'viem' import { - syndicateClient, + syndicateClientIdRegistry, generateIdRegistryInput, projectIdRegistry, } from '@/config/syndicateClient' @@ -19,7 +19,7 @@ export async function POST(req: NextRequest) { console.log({ userWithoutUsername }) - if (!syndicateClient) { + if (!syndicateClientIdRegistry) { return new Response( JSON.stringify({ success: false, @@ -35,7 +35,7 @@ export async function POST(req: NextRequest) { try { const registerTx = - await syndicateClient.officialActions.transact.sendTransaction( + await syndicateClientIdRegistry.officialActions.transact.sendTransaction( generateIdRegistryInput({ to, recovery, deadline, sig }), ) diff --git a/apps/site/config/syndicateClient.ts b/apps/site/config/syndicateClient.ts index 99221220..15c0190d 100644 --- a/apps/site/config/syndicateClient.ts +++ b/apps/site/config/syndicateClient.ts @@ -69,17 +69,29 @@ export const generateIdRegistryInput = (register: Register) => ({ }, }) -const apiKey = process.env.SYNDICATE_API_KEY +const apiPostKey = process.env.SYNDICATE_POST_API_KEY +const apiIdKey = process.env.SYNDICATE_ID_API_KEY -export const syndicateClient = - !projectIdRegistry || !projectIdPost || !apiKey - ? null - : { + +export const syndicateClientPost = + projectIdPost !== 'Error' && apiPostKey + ? { officialActions: new SyndicateClient({ - token: () => apiKey, + token: () => apiPostKey!, }), - projectId: projectIdPost || projectIdRegistry, + projectId: projectIdPost, generatePostTxnInput, generatePostBatchTxnInput, + } + : null; + +export const syndicateClientIdRegistry = + projectIdRegistry !== 'Error' && apiIdKey + ? { + officialActions: new SyndicateClient({ + token: () => apiIdKey!, + }), + projectId: projectIdRegistry, generateIdRegistryInput, } + : null; \ No newline at end of file From 9a5cfe1a84189cf27cacf8d18bafb756a95f51d8 Mon Sep 17 00:00:00 2001 From: jawndiego Date: Sun, 16 Jun 2024 21:30:33 -0400 Subject: [PATCH 12/23] client --- apps/site/config/syndicateClient.ts | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/apps/site/config/syndicateClient.ts b/apps/site/config/syndicateClient.ts index 15c0190d..b0fb2005 100644 --- a/apps/site/config/syndicateClient.ts +++ b/apps/site/config/syndicateClient.ts @@ -72,26 +72,25 @@ export const generateIdRegistryInput = (register: Register) => ({ const apiPostKey = process.env.SYNDICATE_POST_API_KEY const apiIdKey = process.env.SYNDICATE_ID_API_KEY - export const syndicateClientPost = projectIdPost !== 'Error' && apiPostKey ? { officialActions: new SyndicateClient({ - token: () => apiPostKey!, + token: () => apiPostKey, }), projectId: projectIdPost, generatePostTxnInput, generatePostBatchTxnInput, } - : null; + : null export const syndicateClientIdRegistry = projectIdRegistry !== 'Error' && apiIdKey ? { officialActions: new SyndicateClient({ - token: () => apiIdKey!, + token: () => apiIdKey, }), projectId: projectIdRegistry, generateIdRegistryInput, } - : null; \ No newline at end of file + : null From 4044cd5c9cde4f7d0c44fbd89c3690f28895691b Mon Sep 17 00:00:00 2001 From: jawndiego Date: Mon, 17 Jun 2024 10:50:51 -0400 Subject: [PATCH 13/23] change address --- packages/scrypt/constants/addresses.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/scrypt/constants/addresses.ts b/packages/scrypt/constants/addresses.ts index e27e73bf..681a910c 100644 --- a/packages/scrypt/constants/addresses.ts +++ b/packages/scrypt/constants/addresses.ts @@ -14,7 +14,7 @@ export const addresses: AddressBook = { // }, // optimism sepolia idRegistry: { - optimism: '0xaa5914c16c40c029635493a8713051a3ee45ee1f', + optimism: '0xCd1f2a68D79592Ce047091d35DD804Fa6B07d125', }, postGateway: { nova: '0x423a602F5e551A25b28eb33eB56B961590aD5290', From 5b1d62bd2981720e909175c0bdf2be2aa8218b21 Mon Sep 17 00:00:00 2001 From: jawndiego Date: Mon, 17 Jun 2024 11:23:03 -0400 Subject: [PATCH 14/23] new address --- packages/scrypt/constants/addresses.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/scrypt/constants/addresses.ts b/packages/scrypt/constants/addresses.ts index 681a910c..c2eb551e 100644 --- a/packages/scrypt/constants/addresses.ts +++ b/packages/scrypt/constants/addresses.ts @@ -14,7 +14,7 @@ export const addresses: AddressBook = { // }, // optimism sepolia idRegistry: { - optimism: '0xCd1f2a68D79592Ce047091d35DD804Fa6B07d125', + optimism: '0xc5799be72019c0b79a176bb386644b8be3b58590', }, postGateway: { nova: '0x423a602F5e551A25b28eb33eB56B961590aD5290', From f8114d4a05efa0961252bacbd10f4b45196d89ad Mon Sep 17 00:00:00 2001 From: jawndiego Date: Mon, 17 Jun 2024 11:57:09 -0400 Subject: [PATCH 15/23] EIP 712 diff --- packages/scrypt/lib/username/eip712.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/scrypt/lib/username/eip712.ts b/packages/scrypt/lib/username/eip712.ts index 624b48f6..d1e652e7 100644 --- a/packages/scrypt/lib/username/eip712.ts +++ b/packages/scrypt/lib/username/eip712.ts @@ -1,10 +1,10 @@ import { addresses } from '../../constants' -import { optimism } from 'viem/chains' +import { optimism, optimismSepolia } from 'viem/chains' export const ID_REGISTRY_EIP_712_DOMAIN = { name: 'River IdRegistry', version: '1', - chainId: optimism.id, + chainId: optimismSepolia.id, verifyingContract: addresses.idRegistry.optimism, } as const From a171d9e2bf51f82cc00efbf12039f475a2023457 Mon Sep 17 00:00:00 2001 From: jawndiego Date: Mon, 17 Jun 2024 12:03:18 -0400 Subject: [PATCH 16/23] chain --- apps/site/components/client/EditUsernameDialog.tsx | 2 +- apps/site/components/client/UsernameDialog.tsx | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/apps/site/components/client/EditUsernameDialog.tsx b/apps/site/components/client/EditUsernameDialog.tsx index 97f6e0a3..be7129eb 100644 --- a/apps/site/components/client/EditUsernameDialog.tsx +++ b/apps/site/components/client/EditUsernameDialog.tsx @@ -107,7 +107,7 @@ export function EditUsernameDialog({ open, setOpen }: UsernameDialogProps) { const ID_REGISTRY_EIP_712_DOMAIN = { name: 'River IdRegistry', version: '1', - chainId: 10, + chainId: 11155420, verifyingContract: addresses.idRegistry.optimism, } as const const REGISTER_TYPE = [ diff --git a/apps/site/components/client/UsernameDialog.tsx b/apps/site/components/client/UsernameDialog.tsx index 24d749ed..f35b7406 100644 --- a/apps/site/components/client/UsernameDialog.tsx +++ b/apps/site/components/client/UsernameDialog.tsx @@ -102,7 +102,7 @@ export function UsernameDialog({ open, setOpen }: UsernameDialogProps) { const ID_REGISTRY_EIP_712_DOMAIN = { name: 'River IdRegistry', version: '1', - chainId: 10, + chainId: 11155420, verifyingContract: addresses.idRegistry.optimism, } as const const REGISTER_TYPE = [ From 593a4c53075aa48d49ece03606148ea077489d69 Mon Sep 17 00:00:00 2001 From: jawndiego Date: Mon, 24 Jun 2024 12:48:38 -0400 Subject: [PATCH 17/23] syn helpers --- apps/site/app/api/post/route.ts | 12 ++++-------- apps/site/app/api/postBatch/route.ts | 11 ++++++----- apps/site/app/api/registerFor/route.ts | 23 +++++++++++++++-------- 3 files changed, 25 insertions(+), 21 deletions(-) diff --git a/apps/site/app/api/post/route.ts b/apps/site/app/api/post/route.ts index e06d74db..af50bed9 100644 --- a/apps/site/app/api/post/route.ts +++ b/apps/site/app/api/post/route.ts @@ -3,11 +3,8 @@ import { generatePostTxnInput, projectIdPost, } from '@/config/syndicateClient' -import { ethers } from 'ethers' import type { NextRequest } from 'next/server' -import { addresses, postGatewayABI } from 'scrypt' -import type { Hex } from 'viem' -import { waitUntilTx, authToken } from '@/lib' +import { waitForHash } from '@syndicateio/syndicate-node/utils' export const maxDuration = 30 // This function can run for a maximum of 30 seconds @@ -33,10 +30,9 @@ export async function POST(req: NextRequest) { generatePostTxnInput(post), ) - const successfulTxHash = await waitUntilTx({ - projectID: projectIdPost as string, - txID: postTx.transactionId, - authToken: authToken as string, + const successfulTxHash = await waitForHash(syndicateClientPost, { + projectId: projectIdPost, + transactionId: postTx.transactionId, }) return new Response( diff --git a/apps/site/app/api/postBatch/route.ts b/apps/site/app/api/postBatch/route.ts index 040c458c..e606698e 100644 --- a/apps/site/app/api/postBatch/route.ts +++ b/apps/site/app/api/postBatch/route.ts @@ -4,7 +4,7 @@ import { generatePostBatchTxnInput, projectIdPost, } from '@/config/syndicateClient' -import { waitUntilTx, authToken } from '@/lib' +import { waitForHash } from '@syndicateio/syndicate-node/utils' export async function POST(req: NextRequest) { const postsArray = await req.json() @@ -29,12 +29,13 @@ export async function POST(req: NextRequest) { generatePostBatchTxnInput(postsArray), ) - const successfulTxHash = await waitUntilTx({ - projectID: projectIdPost as string, - txID: postTx.transactionId, - authToken: authToken as string, + const successfulTxHash = await waitForHash(syndicateClientPost, { + projectId: projectIdPost, + transactionId: postTx.transactionId, }) + console.log({ successfulTxHash }) + return new Response( JSON.stringify({ success: true, hash: successfulTxHash }), { diff --git a/apps/site/app/api/registerFor/route.ts b/apps/site/app/api/registerFor/route.ts index 1ea00f8f..6c130577 100644 --- a/apps/site/app/api/registerFor/route.ts +++ b/apps/site/app/api/registerFor/route.ts @@ -1,12 +1,13 @@ -import { optimismPubClient } from '@/config/publicClient' import type { NextRequest } from 'next/server' -import { type Hex, decodeAbiParameters } from 'viem' +import { decodeAbiParameters } from 'viem' import { syndicateClientIdRegistry, generateIdRegistryInput, projectIdRegistry, } from '@/config/syndicateClient' -import { waitUntilTx, authToken } from '@/lib' +import { waitForHash } from '@syndicateio/syndicate-node/utils' +import { optimismPubClient } from '@/config/publicClient' +import type { Hex } from 'viem' export const maxDuration = 30 // This function can run for a maximum of 30 seconds @@ -39,10 +40,15 @@ export async function POST(req: NextRequest) { generateIdRegistryInput({ to, recovery, deadline, sig }), ) - const successfulTxHash = await waitUntilTx({ - projectID: projectIdRegistry as string, - txID: registerTx.transactionId, - authToken: authToken as string, + const successfulTxHash = await waitForHash(syndicateClientIdRegistry, { + projectId: projectIdRegistry, + transactionId: registerTx.transactionId, + }) + + console.log({ successfulTxHash }) + + const txnReceipt = await optimismPubClient.waitForTransactionReceipt({ + hash: successfulTxHash as Hex, }) const [rid] = decodeAbiParameters( @@ -50,7 +56,8 @@ export async function POST(req: NextRequest) { { name: 'rid', type: 'uint256' }, { name: 'recoveryAddress', type: 'address' }, ], - successfulTxHash.logs[0].data, + + txnReceipt.logs[0].data, ) console.log('rid: ', rid) From 7921a858a5966e854b7cb5e15cc94fddbfa4256a Mon Sep 17 00:00:00 2001 From: jawndiego Date: Mon, 24 Jun 2024 13:01:40 -0400 Subject: [PATCH 18/23] cleaner --- apps/site/app/api/post/route.ts | 16 ++-------------- apps/site/app/api/postBatch/route.ts | 17 ++--------------- apps/site/app/api/registerFor/route.ts | 26 ++------------------------ apps/site/biome.json | 4 +++- 4 files changed, 9 insertions(+), 54 deletions(-) diff --git a/apps/site/app/api/post/route.ts b/apps/site/app/api/post/route.ts index af50bed9..404a2fe6 100644 --- a/apps/site/app/api/post/route.ts +++ b/apps/site/app/api/post/route.ts @@ -11,22 +11,10 @@ export const maxDuration = 30 // This function can run for a maximum of 30 secon export async function POST(req: NextRequest) { const post = await req.json() - if (!syndicateClientPost) { - return new Response( - JSON.stringify({ - success: false, - hash: null, - error: 'Syndicate client not initialized', - }), - { - status: 500, - headers: { 'Content-Type': 'application/json' }, - }, - ) - } try { const postTx = - await syndicateClientPost.officialActions.transact.sendTransaction( + // biome-ignore lint: + await syndicateClientPost!.officialActions.transact.sendTransaction( generatePostTxnInput(post), ) diff --git a/apps/site/app/api/postBatch/route.ts b/apps/site/app/api/postBatch/route.ts index e606698e..2ad30a0d 100644 --- a/apps/site/app/api/postBatch/route.ts +++ b/apps/site/app/api/postBatch/route.ts @@ -9,23 +9,10 @@ import { waitForHash } from '@syndicateio/syndicate-node/utils' export async function POST(req: NextRequest) { const postsArray = await req.json() - if (!syndicateClientPost) { - return new Response( - JSON.stringify({ - success: false, - hash: null, - error: 'Syndicate client not initialized', - }), - { - status: 500, - headers: { 'Content-Type': 'application/json' }, - }, - ) - } - try { const postTx = - await syndicateClientPost.officialActions.transact.sendTransaction( + // biome-ignore lint: + await syndicateClientPost!.officialActions.transact.sendTransaction( generatePostBatchTxnInput(postsArray), ) diff --git a/apps/site/app/api/registerFor/route.ts b/apps/site/app/api/registerFor/route.ts index 6c130577..ac4508ea 100644 --- a/apps/site/app/api/registerFor/route.ts +++ b/apps/site/app/api/registerFor/route.ts @@ -13,30 +13,13 @@ export const maxDuration = 30 // This function can run for a maximum of 30 secon export async function POST(req: NextRequest) { const user = await req.json() - console.log({ user }) - const { username, ...userWithoutUsername } = user const { to, recovery, deadline, sig } = userWithoutUsername - console.log({ userWithoutUsername }) - - if (!syndicateClientIdRegistry) { - return new Response( - JSON.stringify({ - success: false, - hash: null, - error: 'Syndicate client not initialized', - }), - { - status: 500, - headers: { 'Content-Type': 'application/json' }, - }, - ) - } - try { const registerTx = - await syndicateClientIdRegistry.officialActions.transact.sendTransaction( + // biome-ignore lint: + await syndicateClientIdRegistry!.officialActions.transact.sendTransaction( generateIdRegistryInput({ to, recovery, deadline, sig }), ) @@ -45,8 +28,6 @@ export async function POST(req: NextRequest) { transactionId: registerTx.transactionId, }) - console.log({ successfulTxHash }) - const txnReceipt = await optimismPubClient.waitForTransactionReceipt({ hash: successfulTxHash as Hex, }) @@ -60,9 +41,6 @@ export async function POST(req: NextRequest) { txnReceipt.logs[0].data, ) - console.log('rid: ', rid) - console.log('transaction receipt: ', successfulTxHash) - return new Response( JSON.stringify({ success: true, diff --git a/apps/site/biome.json b/apps/site/biome.json index 9a95a48f..bc66ade3 100644 --- a/apps/site/biome.json +++ b/apps/site/biome.json @@ -15,7 +15,9 @@ "rules": { "recommended": true, "style": { - "noUselessElse": "off" + "noUselessElse": "off", + "noNonNullAssertion":"off" + }, "suspicious": { "noRedeclare": "off", From 6353da67ef37d25d0e858818effd316fe447e0bc Mon Sep 17 00:00:00 2001 From: jawndiego Date: Mon, 24 Jun 2024 15:54:46 -0400 Subject: [PATCH 19/23] remove try catch --- apps/site/app/api/post/route.ts | 54 +++++----------- apps/site/app/api/postBatch/route.ts | 54 +++++----------- apps/site/app/api/registerFor/route.ts | 87 ++++++++++---------------- apps/site/biome.json | 3 +- 4 files changed, 67 insertions(+), 131 deletions(-) diff --git a/apps/site/app/api/post/route.ts b/apps/site/app/api/post/route.ts index 404a2fe6..ea2cba19 100644 --- a/apps/site/app/api/post/route.ts +++ b/apps/site/app/api/post/route.ts @@ -6,47 +6,27 @@ import { import type { NextRequest } from 'next/server' import { waitForHash } from '@syndicateio/syndicate-node/utils' -export const maxDuration = 30 // This function can run for a maximum of 30 seconds - export async function POST(req: NextRequest) { const post = await req.json() - try { - const postTx = - // biome-ignore lint: - await syndicateClientPost!.officialActions.transact.sendTransaction( - generatePostTxnInput(post), - ) - - const successfulTxHash = await waitForHash(syndicateClientPost, { - projectId: projectIdPost, - transactionId: postTx.transactionId, - }) - - return new Response( - JSON.stringify({ success: true, hash: successfulTxHash }), - { - status: 200, - headers: { 'Content-Type': 'application/json' }, - }, + const postTx = + // biome-ignore lint: + await syndicateClientPost!.officialActions.transact.sendTransaction( + generatePostTxnInput(post), ) - } catch (error) { - let errorMessage = 'Unknown error' - let statusCode = 500 - if (error instanceof Error) { - errorMessage = error.message - statusCode = - // biome-ignore lint: `status` is not part of the standard Error interface - typeof (error as any).status === 'number' ? (error as any).status : 500 - } + const successfulTxHash = await waitForHash(syndicateClientPost, { + projectId: projectIdPost, + transactionId: postTx.transactionId, + }) - return new Response( - JSON.stringify({ success: false, hash: null, error: errorMessage }), - { - status: statusCode, - headers: { 'Content-Type': 'application/json' }, - }, - ) - } + console.log({ successfulTxHash }) + + return new Response( + JSON.stringify({ success: true, hash: successfulTxHash }), + { + status: 200, + headers: { 'Content-Type': 'application/json' }, + }, + ) } diff --git a/apps/site/app/api/postBatch/route.ts b/apps/site/app/api/postBatch/route.ts index 2ad30a0d..34715bcb 100644 --- a/apps/site/app/api/postBatch/route.ts +++ b/apps/site/app/api/postBatch/route.ts @@ -9,44 +9,24 @@ import { waitForHash } from '@syndicateio/syndicate-node/utils' export async function POST(req: NextRequest) { const postsArray = await req.json() - try { - const postTx = - // biome-ignore lint: - await syndicateClientPost!.officialActions.transact.sendTransaction( - generatePostBatchTxnInput(postsArray), - ) - - const successfulTxHash = await waitForHash(syndicateClientPost, { - projectId: projectIdPost, - transactionId: postTx.transactionId, - }) - - console.log({ successfulTxHash }) - - return new Response( - JSON.stringify({ success: true, hash: successfulTxHash }), - { - status: 200, - headers: { 'Content-Type': 'application/json' }, - }, + const postTx = + // biome-ignore lint: + await syndicateClientPost!.officialActions.transact.sendTransaction( + generatePostBatchTxnInput(postsArray), ) - } catch (error) { - let errorMessage = 'Unknown error' - let statusCode = 500 - if (error instanceof Error) { - errorMessage = error.message - statusCode = - // biome-ignore lint: `status` is not part of the standard Error interface - typeof (error as any).status === 'number' ? (error as any).status : 500 - } + const successfulTxHash = await waitForHash(syndicateClientPost, { + projectId: projectIdPost, + transactionId: postTx.transactionId, + }) - return new Response( - JSON.stringify({ success: false, hash: null, error: errorMessage }), - { - status: statusCode, - headers: { 'Content-Type': 'application/json' }, - }, - ) - } + console.log({ successfulTxHash }) + + return new Response( + JSON.stringify({ success: true, hash: successfulTxHash }), + { + status: 200, + headers: { 'Content-Type': 'application/json' }, + }, + ) } diff --git a/apps/site/app/api/registerFor/route.ts b/apps/site/app/api/registerFor/route.ts index ac4508ea..63971565 100644 --- a/apps/site/app/api/registerFor/route.ts +++ b/apps/site/app/api/registerFor/route.ts @@ -9,67 +9,44 @@ import { waitForHash } from '@syndicateio/syndicate-node/utils' import { optimismPubClient } from '@/config/publicClient' import type { Hex } from 'viem' -export const maxDuration = 30 // This function can run for a maximum of 30 seconds - export async function POST(req: NextRequest) { const user = await req.json() const { username, ...userWithoutUsername } = user const { to, recovery, deadline, sig } = userWithoutUsername - try { - const registerTx = + const registerTx = // biome-ignore lint: - await syndicateClientIdRegistry!.officialActions.transact.sendTransaction( - generateIdRegistryInput({ to, recovery, deadline, sig }), - ) - - const successfulTxHash = await waitForHash(syndicateClientIdRegistry, { - projectId: projectIdRegistry, - transactionId: registerTx.transactionId, - }) - - const txnReceipt = await optimismPubClient.waitForTransactionReceipt({ - hash: successfulTxHash as Hex, - }) - - const [rid] = decodeAbiParameters( - [ - { name: 'rid', type: 'uint256' }, - { name: 'recoveryAddress', type: 'address' }, - ], - - txnReceipt.logs[0].data, + await syndicateClientIdRegistry!.officialActions.transact.sendTransaction( + generateIdRegistryInput({ to, recovery, deadline, sig }), ) - return new Response( - JSON.stringify({ - success: true, - hash: successfulTxHash, - rid: rid.toString(), - }), - { - status: 200, - headers: { 'Content-Type': 'application/json' }, - }, - ) - } catch (error) { - console.error(error) - let errorMessage = 'Unknown error' - let statusCode = 500 - - if (error instanceof Error) { - errorMessage = error.message - statusCode = - // biome-ignore lint: `status` is not part of the standard Error interface - typeof (error as any).status === 'number' ? (error as any).status : 500 - } - - return new Response( - JSON.stringify({ success: false, error: errorMessage }), - { - status: statusCode, - headers: { 'Content-Type': 'application/json' }, - }, - ) - } + const successfulTxHash = await waitForHash(syndicateClientIdRegistry, { + projectId: projectIdRegistry, + transactionId: registerTx.transactionId, + }) + + const txnReceipt = await optimismPubClient.waitForTransactionReceipt({ + hash: successfulTxHash as Hex, + }) + + const [rid] = decodeAbiParameters( + [ + { name: 'rid', type: 'uint256' }, + { name: 'recoveryAddress', type: 'address' }, + ], + + txnReceipt.logs[0].data, + ) + + return new Response( + JSON.stringify({ + success: true, + hash: successfulTxHash, + rid: rid.toString(), + }), + { + status: 200, + headers: { 'Content-Type': 'application/json' }, + }, + ) } diff --git a/apps/site/biome.json b/apps/site/biome.json index bc66ade3..ff55bcbf 100644 --- a/apps/site/biome.json +++ b/apps/site/biome.json @@ -16,8 +16,7 @@ "recommended": true, "style": { "noUselessElse": "off", - "noNonNullAssertion":"off" - + "noNonNullAssertion": "off" }, "suspicious": { "noRedeclare": "off", From 5d32cf86b98704df2a8ff0b44001c3894b7bfb95 Mon Sep 17 00:00:00 2001 From: jawndiego Date: Mon, 24 Jun 2024 16:57:44 -0400 Subject: [PATCH 20/23] push change to syndicate config --- apps/site/app/api/post/route.ts | 2 +- apps/site/app/api/postBatch/route.ts | 2 +- apps/site/config/syndicateClient.ts | 25 ++++++++++++++----------- 3 files changed, 16 insertions(+), 13 deletions(-) diff --git a/apps/site/app/api/post/route.ts b/apps/site/app/api/post/route.ts index ea2cba19..b49099fe 100644 --- a/apps/site/app/api/post/route.ts +++ b/apps/site/app/api/post/route.ts @@ -11,7 +11,7 @@ export async function POST(req: NextRequest) { const postTx = // biome-ignore lint: - await syndicateClientPost!.officialActions.transact.sendTransaction( + await syndicateClientPost!.transact.sendTransaction( generatePostTxnInput(post), ) diff --git a/apps/site/app/api/postBatch/route.ts b/apps/site/app/api/postBatch/route.ts index 34715bcb..c621492e 100644 --- a/apps/site/app/api/postBatch/route.ts +++ b/apps/site/app/api/postBatch/route.ts @@ -11,7 +11,7 @@ export async function POST(req: NextRequest) { const postTx = // biome-ignore lint: - await syndicateClientPost!.officialActions.transact.sendTransaction( + await syndicateClientPost!.transact.sendTransaction( generatePostBatchTxnInput(postsArray), ) diff --git a/apps/site/config/syndicateClient.ts b/apps/site/config/syndicateClient.ts index b0fb2005..88ca5f6b 100644 --- a/apps/site/config/syndicateClient.ts +++ b/apps/site/config/syndicateClient.ts @@ -72,17 +72,20 @@ export const generateIdRegistryInput = (register: Register) => ({ const apiPostKey = process.env.SYNDICATE_POST_API_KEY const apiIdKey = process.env.SYNDICATE_ID_API_KEY -export const syndicateClientPost = - projectIdPost !== 'Error' && apiPostKey - ? { - officialActions: new SyndicateClient({ - token: () => apiPostKey, - }), - projectId: projectIdPost, - generatePostTxnInput, - generatePostBatchTxnInput, - } - : null +// export const syndicateClientPost = +// projectIdPost !== 'Error' && apiPostKey +// ? { +// officialActions: new SyndicateClient({ +// token: () => apiPostKey, +// }), +// projectId: projectIdPost, +// generatePostTxnInput, +// generatePostBatchTxnInput, + +// } +// : null + +export const syndicateClientPost = new SyndicateClient({ token: apiPostKey as string }) export const syndicateClientIdRegistry = projectIdRegistry !== 'Error' && apiIdKey From 98f7b599e1f1375c8c75f19cd8fa9e8318bd688b Mon Sep 17 00:00:00 2001 From: jawndiego Date: Mon, 24 Jun 2024 17:03:03 -0400 Subject: [PATCH 21/23] clients --- apps/site/app/api/registerFor/route.ts | 2 +- apps/site/config/syndicateClient.ts | 30 ++------------------------ 2 files changed, 3 insertions(+), 29 deletions(-) diff --git a/apps/site/app/api/registerFor/route.ts b/apps/site/app/api/registerFor/route.ts index 63971565..ae162873 100644 --- a/apps/site/app/api/registerFor/route.ts +++ b/apps/site/app/api/registerFor/route.ts @@ -16,7 +16,7 @@ export async function POST(req: NextRequest) { const registerTx = // biome-ignore lint: - await syndicateClientIdRegistry!.officialActions.transact.sendTransaction( + await syndicateClientIdRegistry!.transact.sendTransaction( generateIdRegistryInput({ to, recovery, deadline, sig }), ) diff --git a/apps/site/config/syndicateClient.ts b/apps/site/config/syndicateClient.ts index 88ca5f6b..cd8d5346 100644 --- a/apps/site/config/syndicateClient.ts +++ b/apps/site/config/syndicateClient.ts @@ -69,31 +69,5 @@ export const generateIdRegistryInput = (register: Register) => ({ }, }) -const apiPostKey = process.env.SYNDICATE_POST_API_KEY -const apiIdKey = process.env.SYNDICATE_ID_API_KEY - -// export const syndicateClientPost = -// projectIdPost !== 'Error' && apiPostKey -// ? { -// officialActions: new SyndicateClient({ -// token: () => apiPostKey, -// }), -// projectId: projectIdPost, -// generatePostTxnInput, -// generatePostBatchTxnInput, - -// } -// : null - -export const syndicateClientPost = new SyndicateClient({ token: apiPostKey as string }) - -export const syndicateClientIdRegistry = - projectIdRegistry !== 'Error' && apiIdKey - ? { - officialActions: new SyndicateClient({ - token: () => apiIdKey, - }), - projectId: projectIdRegistry, - generateIdRegistryInput, - } - : null +export const syndicateClientPost = new SyndicateClient({ token: process.env.SYNDICATE_POST_API_KEY as string }) +export const syndicateClientIdRegistry = new SyndicateClient({ token: process.env.SYNDICATE_ID_API_KEY as string }) \ No newline at end of file From a9924f32477abfe7336a98f38e51ee5f96ae54cd Mon Sep 17 00:00:00 2001 From: jawndiego Date: Mon, 24 Jun 2024 17:04:49 -0400 Subject: [PATCH 22/23] chain id back to optimism main --- apps/site/components/client/EditUsernameDialog.tsx | 2 +- apps/site/components/client/UsernameDialog.tsx | 2 +- apps/site/config/syndicateClient.ts | 2 +- packages/scrypt/constants/addresses.ts | 6 +----- 4 files changed, 4 insertions(+), 8 deletions(-) diff --git a/apps/site/components/client/EditUsernameDialog.tsx b/apps/site/components/client/EditUsernameDialog.tsx index be7129eb..97f6e0a3 100644 --- a/apps/site/components/client/EditUsernameDialog.tsx +++ b/apps/site/components/client/EditUsernameDialog.tsx @@ -107,7 +107,7 @@ export function EditUsernameDialog({ open, setOpen }: UsernameDialogProps) { const ID_REGISTRY_EIP_712_DOMAIN = { name: 'River IdRegistry', version: '1', - chainId: 11155420, + chainId: 10, verifyingContract: addresses.idRegistry.optimism, } as const const REGISTER_TYPE = [ diff --git a/apps/site/components/client/UsernameDialog.tsx b/apps/site/components/client/UsernameDialog.tsx index f35b7406..24d749ed 100644 --- a/apps/site/components/client/UsernameDialog.tsx +++ b/apps/site/components/client/UsernameDialog.tsx @@ -102,7 +102,7 @@ export function UsernameDialog({ open, setOpen }: UsernameDialogProps) { const ID_REGISTRY_EIP_712_DOMAIN = { name: 'River IdRegistry', version: '1', - chainId: 11155420, + chainId: 10, verifyingContract: addresses.idRegistry.optimism, } as const const REGISTER_TYPE = [ diff --git a/apps/site/config/syndicateClient.ts b/apps/site/config/syndicateClient.ts index cd8d5346..7b722f26 100644 --- a/apps/site/config/syndicateClient.ts +++ b/apps/site/config/syndicateClient.ts @@ -58,7 +58,7 @@ export const generatePostTxnInput = (post: Post) => ({ export const generateIdRegistryInput = (register: Register) => ({ projectId: projectIdRegistry, contractAddress: addresses.idRegistry.optimism, - chainId: 11155420, + chainId: 10, functionSignature: 'registerFor(address to, address recovery, uint256 deadline, bytes sig)', args: { diff --git a/packages/scrypt/constants/addresses.ts b/packages/scrypt/constants/addresses.ts index c2eb551e..32b8828b 100644 --- a/packages/scrypt/constants/addresses.ts +++ b/packages/scrypt/constants/addresses.ts @@ -9,12 +9,8 @@ type AddressBook = { } export const addresses: AddressBook = { - // idRegistry: { - // optimism: '0x44192479891D358Ec917765dbF6472B916DC9A0C', - // }, - // optimism sepolia idRegistry: { - optimism: '0xc5799be72019c0b79a176bb386644b8be3b58590', + optimism: '0x44192479891D358Ec917765dbF6472B916DC9A0C', }, postGateway: { nova: '0x423a602F5e551A25b28eb33eB56B961590aD5290', From cc90894d248c65c359a36dc40856ed9e95897779 Mon Sep 17 00:00:00 2001 From: jawndiego Date: Mon, 24 Jun 2024 17:07:20 -0400 Subject: [PATCH 23/23] optimism --- apps/site/config/publicClient.ts | 4 ++-- packages/scrypt/lib/username/eip712.ts | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/apps/site/config/publicClient.ts b/apps/site/config/publicClient.ts index 07129db1..cd6035ba 100644 --- a/apps/site/config/publicClient.ts +++ b/apps/site/config/publicClient.ts @@ -1,9 +1,9 @@ import { http, createPublicClient } from 'viem' -import { optimism, optimismSepolia } from 'viem/chains' +import { optimism } from 'viem/chains' import { arbitrumNova } from './customChainConfig' export const optimismPubClient = createPublicClient({ - chain: optimismSepolia, + chain: optimism, transport: http(process.env.NEXT_PUBLIC_OPTIMISM_RPC_URL), }) diff --git a/packages/scrypt/lib/username/eip712.ts b/packages/scrypt/lib/username/eip712.ts index d1e652e7..624b48f6 100644 --- a/packages/scrypt/lib/username/eip712.ts +++ b/packages/scrypt/lib/username/eip712.ts @@ -1,10 +1,10 @@ import { addresses } from '../../constants' -import { optimism, optimismSepolia } from 'viem/chains' +import { optimism } from 'viem/chains' export const ID_REGISTRY_EIP_712_DOMAIN = { name: 'River IdRegistry', version: '1', - chainId: optimismSepolia.id, + chainId: optimism.id, verifyingContract: addresses.idRegistry.optimism, } as const