@@ -2,10 +2,18 @@ import { encryptData, decrypt as shutterDecrypt } from "@shutter-network/shutter
22import { Hex , stringToHex , hexToString } from "viem" ;
33import crypto from "crypto" ;
44import "isomorphic-fetch" ;
5+ import env from "./utils/env" ;
56
67// Time in seconds to wait before the message can be decrypted
78export const DECRYPTION_DELAY = 5 ;
89
10+ const SHUTTER_API_URL = {
11+ mainnet : "https://shutter-api.shutter.network" ,
12+ testnet : "https://shutter-api.chiado.staging.shutter.network" ,
13+ } ;
14+
15+ const SHUTTER_API = env . optional ( "SHUTTER_API" , "mainnet" ) as keyof typeof SHUTTER_API_URL ;
16+
917interface ShutterApiMessageData {
1018 eon : number ;
1119 identity : string ;
@@ -38,7 +46,7 @@ async function fetchShutterData(decryptionTimestamp: number): Promise<ShutterApi
3846 const identityPrefix = generateRandomBytes32 ( ) ;
3947 console . log ( `Generated identity prefix: ${ identityPrefix } ` ) ;
4048
41- const response = await fetch ( "https://shutter- api.shutter.network/api/ register_identity" , {
49+ const response = await fetch ( ` ${ SHUTTER_API_URL [ SHUTTER_API ] } / api/ register_identity` , {
4250 method : "POST" ,
4351 headers : {
4452 accept : "application/json" ,
@@ -88,7 +96,7 @@ async function fetchShutterData(decryptionTimestamp: number): Promise<ShutterApi
8896async function fetchDecryptionKey ( identity : string ) : Promise < ShutterDecryptionKeyData > {
8997 console . log ( `Fetching decryption key for identity: ${ identity } ` ) ;
9098
91- const response = await fetch ( `https://shutter-api.shutter.network /api/get_decryption_key?identity=${ identity } ` , {
99+ const response = await fetch ( `${ SHUTTER_API_URL [ SHUTTER_API ] } /api/get_decryption_key?identity=${ identity } ` , {
92100 method : "GET" ,
93101 headers : {
94102 accept : "application/json" ,
@@ -232,6 +240,7 @@ Examples:
232240 console . error ( "Usage: yarn ts-node shutter.ts encrypt <message>" ) ;
233241 process . exit ( 1 ) ;
234242 }
243+ console . log ( `Using Shutter API ${ SHUTTER_API_URL [ SHUTTER_API ] } ...` ) ;
235244 const { encryptedCommitment, identity } = await encrypt ( message ) ;
236245 console . log ( "\nEncrypted Commitment:" , encryptedCommitment ) ;
237246 console . log ( "Identity:" , identity ) ;
@@ -245,6 +254,7 @@ Examples:
245254 console . error ( "Note: The identity is the one returned during encryption" ) ;
246255 process . exit ( 1 ) ;
247256 }
257+ console . log ( `Using Shutter API ${ SHUTTER_API_URL [ SHUTTER_API ] } ...` ) ;
248258 const decryptedMessage = await decrypt ( encryptedMessage , identity ) ;
249259 console . log ( "\nDecrypted Message:" , decryptedMessage ) ;
250260 break ;
0 commit comments