11import crypto from 'crypto'
22import { v4 as uuid } from 'uuid'
33import { AxiosInstance } from 'axios'
4- import { request } from '../services/request'
4+ import { mixinRequest , request } from '../services/request'
55import { UserClient } from './user'
66import { AddressClient } from './address'
77
88
99import {
1010 AddressClientRequest , AddressCreateParams , Address ,
1111 AppClientRequest , UpdateAppRequest , App , FavoriteApp ,
12+ AssetClientRequest , Asset , ExchangeRate , NetworkTicker ,
1213 Attachment , AttachmentClientRequest ,
1314 ConversationClientRequest , ConversationCreateParmas , Conversation , ConversationUpdateParams , Participant , ConversationAction ,
1415 MessageClientRequest , AcknowledgementRequest , MessageRequest ,
1516 MultisigClientRequest , MultisigRequest , MultisigUTXO ,
1617 PINClientRequest , Turn ,
17- SnapshotClientRequest , Snapshot ,
18+ SnapshotClientRequest , Snapshot , SnapshotQuery ,
1819 TransferClientRequest , TransferInput , Payment , GhostInput , GhostKeys , WithdrawInput , RawTransaction ,
19- UserClientRequest , User , UserRelationship , Keystore , AssetClientRequest , Asset , ExchangeRate
20+ UserClientRequest , User , UserRelationship , Keystore
2021} from '../types'
2122import { AppClient } from './app'
2223import { AssetClient } from './asset'
@@ -65,6 +66,7 @@ export class Client implements
6566 readAsset ! : ( asset_id : string ) => Promise < Asset >
6667 readAssets ! : ( ) => Promise < Asset [ ] >
6768 readAssetFee ! : ( asset_id : string ) => Promise < number >
69+ readAssetNetworkTicker ! : ( asset_id : string , offset ?: string ) => Promise < NetworkTicker >
6870
6971 readExchangeRates ! : ( ) => Promise < ExchangeRate [ ] >
7072
@@ -107,14 +109,12 @@ export class Client implements
107109 readTurnServers ! : ( ) => Promise < Turn [ ] >
108110
109111 // Snapshot...
110-
111- readSnapshots ! : ( asset_id ?: string , offset ?: string , order ?: string , limit ?: number ) => Promise < Snapshot [ ] >
112- readNetworkSnapshots ! : ( asset_id ?: string , offset ?: string , order ?: string , limit ?: number ) => Promise < Snapshot [ ] >
112+ readSnapshots ! : ( params : SnapshotQuery ) => Promise < Snapshot [ ] >
113+ readNetworkSnapshots ! : ( params : SnapshotQuery ) => Promise < Snapshot [ ] >
113114 readSnapshot ! : ( snapshot_id : string ) => Promise < Snapshot >
114115 readNetworkSnapshot ! : ( snapshot_id : string ) => Promise < Snapshot >
115116
116117 // Transfer...
117-
118118 verifyPayment ! : ( params : TransferInput ) => Promise < Payment >
119119 transfer ! : ( params : TransferInput , pin ?: string ) => Promise < Snapshot >
120120 readTransfer ! : ( trace_id : string ) => Promise < Snapshot >
@@ -134,6 +134,17 @@ export class Client implements
134134 modifyRelationships ! : ( relationship : UserRelationship ) => Promise < User >
135135 readBlockUsers ! : ( ) => Promise < User [ ] >
136136
137+
138+ // Oauth...
139+ authorizeToken ( code : string , client_secret ?: string , code_verifier ?: string ) : Promise < { access_token : string , scope : string } > {
140+ if ( ! client_secret ) client_secret = this . keystore . client_secret
141+ if ( ! client_secret ) return Promise . reject ( new Error ( 'client_secret required' ) )
142+ return this . request . post ( '/oauth/token' , {
143+ client_secret, code, code_verifier,
144+ client_id : this . keystore . client_id ,
145+ } )
146+ }
147+
137148 newUUID ( ) : string {
138149 return uuid ( )
139150 }
@@ -174,4 +185,7 @@ function _extends(origin: any, target: any) {
174185 for ( const key in target . prototype ) {
175186 origin . prototype [ key ] = target . prototype [ key ]
176187 } ;
177- }
188+ }
189+
190+ export const authorizeToken = ( client_id : string , code : string , client_secret : string , code_verifier ?: string ) : Promise < { access_token : string , scope : string } > =>
191+ mixinRequest . get ( '/oauth/token' , { params : { client_id, code, code_verifier, client_secret } } )
0 commit comments