@@ -93,7 +93,8 @@ type EngineFeature =
9393 | "CONTRACT_SUBSCRIPTIONS"
9494 | "IP_ALLOWLIST"
9595 | "HETEROGENEOUS_WALLET_TYPES"
96- | "SMART_BACKEND_WALLETS" ;
96+ | "SMART_BACKEND_WALLETS"
97+ | "WALLET_CREDENTIALS" ;
9798
9899interface EngineSystemHealth {
99100 status : string ;
@@ -860,6 +861,10 @@ export type SetWalletConfigInput =
860861 gcpKmsKeyRingId : string ;
861862 gcpApplicationCredentialEmail : string ;
862863 gcpApplicationCredentialPrivateKey : string ;
864+ }
865+ | {
866+ type : "circle" ;
867+ circleApiKey : string ;
863868 } ;
864869
865870export function useEngineSetWalletConfig ( params : {
@@ -869,8 +874,8 @@ export function useEngineSetWalletConfig(params: {
869874 const { instanceUrl, authToken } = params ;
870875 const queryClient = useQueryClient ( ) ;
871876
872- return useMutation < WalletConfigResponse , void , SetWalletConfigInput > ( {
873- mutationFn : async ( input ) => {
877+ return useMutation ( {
878+ mutationFn : async ( input : SetWalletConfigInput ) => {
874879 invariant ( instanceUrl , "instance is required" ) ;
875880
876881 const res = await fetch ( `${ instanceUrl } configuration/wallets` , {
@@ -884,7 +889,7 @@ export function useEngineSetWalletConfig(params: {
884889 throw new Error ( json . error . message ) ;
885890 }
886891
887- return json . result ;
892+ return json . result as WalletConfigResponse ;
888893 } ,
889894 onSuccess : ( ) => {
890895 return queryClient . invalidateQueries ( {
@@ -894,10 +899,17 @@ export function useEngineSetWalletConfig(params: {
894899 } ) ;
895900}
896901
897- export type CreateBackendWalletInput = {
898- type : EngineBackendWalletType ;
899- label ?: string ;
900- } ;
902+ export type CreateBackendWalletInput =
903+ | {
904+ type : Exclude < EngineBackendWalletType , "circle" | "smart:circle" > ;
905+ label ?: string ;
906+ }
907+ | {
908+ type : "circle" | "smart:circle" ;
909+ label ?: string ;
910+ credentialId : string ;
911+ isTestnet : boolean ;
912+ } ;
901913
902914export function useEngineCreateBackendWallet ( params : {
903915 instanceUrl : string ;
@@ -1851,3 +1863,118 @@ export function useEngineDeleteNotificationChannel(engineId: string) {
18511863 } ,
18521864 } ) ;
18531865}
1866+
1867+ export interface WalletCredential {
1868+ id : string ;
1869+ type : string ;
1870+ label : string ;
1871+ isDefault : boolean | null ;
1872+ createdAt : string ;
1873+ updatedAt : string ;
1874+ }
1875+
1876+ interface CreateWalletCredentialInput {
1877+ type : "circle" ;
1878+ label : string ;
1879+ entitySecret ?: string ;
1880+ isDefault ?: boolean ;
1881+ }
1882+
1883+ export function useEngineWalletCredentials ( params : {
1884+ instanceUrl : string ;
1885+ authToken : string ;
1886+ page ?: number ;
1887+ limit ?: number ;
1888+ } ) {
1889+ const { instanceUrl, authToken, page = 1 , limit = 100 } = params ;
1890+
1891+ return useQuery ( {
1892+ queryKey : [ ...engineKeys . walletCredentials ( instanceUrl ) , page , limit ] ,
1893+ queryFn : async ( ) => {
1894+ const res = await fetch (
1895+ `${ instanceUrl } wallet-credentials?page=${ page } &limit=${ limit } ` ,
1896+ {
1897+ method : "GET" ,
1898+ headers : getEngineRequestHeaders ( authToken ) ,
1899+ } ,
1900+ ) ;
1901+
1902+ const json = await res . json ( ) ;
1903+ return ( json . result as WalletCredential [ ] ) || [ ] ;
1904+ } ,
1905+ enabled : ! ! instanceUrl ,
1906+ } ) ;
1907+ }
1908+
1909+ export function useEngineCreateWalletCredential ( params : {
1910+ instanceUrl : string ;
1911+ authToken : string ;
1912+ } ) {
1913+ const { instanceUrl, authToken } = params ;
1914+ const queryClient = useQueryClient ( ) ;
1915+
1916+ return useMutation ( {
1917+ mutationFn : async ( input : CreateWalletCredentialInput ) => {
1918+ invariant ( instanceUrl , "instance is required" ) ;
1919+
1920+ const res = await fetch ( `${ instanceUrl } wallet-credentials` , {
1921+ method : "POST" ,
1922+ headers : getEngineRequestHeaders ( authToken ) ,
1923+ body : JSON . stringify ( input ) ,
1924+ } ) ;
1925+ const json = await res . json ( ) ;
1926+
1927+ if ( json . error ) {
1928+ throw new Error ( json . error . message ) ;
1929+ }
1930+
1931+ return json . result as WalletCredential ;
1932+ } ,
1933+ onSuccess : ( ) => {
1934+ return queryClient . invalidateQueries ( {
1935+ queryKey : engineKeys . walletCredentials ( instanceUrl ) ,
1936+ } ) ;
1937+ } ,
1938+ } ) ;
1939+ }
1940+
1941+ interface UpdateWalletCredentialInput {
1942+ label ?: string ;
1943+ isDefault ?: boolean ;
1944+ entitySecret ?: string ;
1945+ }
1946+
1947+ export function useEngineUpdateWalletCredential ( params : {
1948+ instanceUrl : string ;
1949+ authToken : string ;
1950+ } ) {
1951+ const { instanceUrl, authToken } = params ;
1952+ const queryClient = useQueryClient ( ) ;
1953+
1954+ return useMutation ( {
1955+ mutationFn : async ( {
1956+ id,
1957+ ...input
1958+ } : UpdateWalletCredentialInput & { id : string } ) => {
1959+ invariant ( instanceUrl , "instance is required" ) ;
1960+
1961+ const res = await fetch ( `${ instanceUrl } wallet-credentials/${ id } ` , {
1962+ method : "PUT" ,
1963+ headers : getEngineRequestHeaders ( authToken ) ,
1964+ body : JSON . stringify ( input ) ,
1965+ } ) ;
1966+ const json = await res . json ( ) ;
1967+
1968+ if ( json . error ) {
1969+ throw new Error ( json . error . message ) ;
1970+ }
1971+
1972+ return json . result as WalletCredential ;
1973+ } ,
1974+ onSuccess : ( ) => {
1975+ return queryClient . invalidateQueries ( {
1976+ queryKey : engineKeys . walletCredentials ( instanceUrl ) ,
1977+ } ) ;
1978+ } ,
1979+ } ) ;
1980+ }
0 commit comments