@@ -2,10 +2,18 @@ import { encryptData, decrypt as shutterDecrypt } from "@shutter-network/shutter
2
2
import { Hex , stringToHex , hexToString } from "viem" ;
3
3
import crypto from "crypto" ;
4
4
import "isomorphic-fetch" ;
5
+ import env from "./utils/env" ;
5
6
6
7
// Time in seconds to wait before the message can be decrypted
7
8
export const DECRYPTION_DELAY = 5 ;
8
9
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
+
9
17
interface ShutterApiMessageData {
10
18
eon : number ;
11
19
identity : string ;
@@ -38,7 +46,7 @@ async function fetchShutterData(decryptionTimestamp: number): Promise<ShutterApi
38
46
const identityPrefix = generateRandomBytes32 ( ) ;
39
47
console . log ( `Generated identity prefix: ${ identityPrefix } ` ) ;
40
48
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` , {
42
50
method : "POST" ,
43
51
headers : {
44
52
accept : "application/json" ,
@@ -88,7 +96,7 @@ async function fetchShutterData(decryptionTimestamp: number): Promise<ShutterApi
88
96
async function fetchDecryptionKey ( identity : string ) : Promise < ShutterDecryptionKeyData > {
89
97
console . log ( `Fetching decryption key for identity: ${ identity } ` ) ;
90
98
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 } ` , {
92
100
method : "GET" ,
93
101
headers : {
94
102
accept : "application/json" ,
@@ -232,6 +240,7 @@ Examples:
232
240
console . error ( "Usage: yarn ts-node shutter.ts encrypt <message>" ) ;
233
241
process . exit ( 1 ) ;
234
242
}
243
+ console . log ( `Using Shutter API ${ SHUTTER_API_URL [ SHUTTER_API ] } ...` ) ;
235
244
const { encryptedCommitment, identity } = await encrypt ( message ) ;
236
245
console . log ( "\nEncrypted Commitment:" , encryptedCommitment ) ;
237
246
console . log ( "Identity:" , identity ) ;
@@ -245,6 +254,7 @@ Examples:
245
254
console . error ( "Note: The identity is the one returned during encryption" ) ;
246
255
process . exit ( 1 ) ;
247
256
}
257
+ console . log ( `Using Shutter API ${ SHUTTER_API_URL [ SHUTTER_API ] } ...` ) ;
248
258
const decryptedMessage = await decrypt ( encryptedMessage , identity ) ;
249
259
console . log ( "\nDecrypted Message:" , decryptedMessage ) ;
250
260
break ;
0 commit comments