Skip to content
This repository was archived by the owner on Apr 24, 2025. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,11 @@ export const API = {
DECODE_INVOICE_ENDPOINT: '/v0/decode-invoice',
FETCH_ZBD_PROD_IPS_ENDPOINT: '/v0/prod-ips',
BTCUSD_PRICE_TICKER_ENDPOINT: '/v0/btcusd',

//OAuth2
OAUTH2_AUTHORIZATION_ENDPOINT: '/v1/oauth2/authorize',
OAUTH2_GET_TOKEN_ENDPOINT: '/v1/oauth2/token',
OAUTH2_GET_USER_PROFILE_ENDPOINT: '/v1/oauth2/user',
OAUTH2_GET_USER_WALLET_ENDPOINT: '/v1/oauth2/wallet'

}
62 changes: 61 additions & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -360,4 +360,64 @@ export interface FetchChargeFromGamertagOptionsType {
internalId: string;
}


export interface OAuth2AuthorizationRequestType {
clientId: string;
responseType: string;
redirectUri: string;
codeChallengeMethod: string;
codeChallenge: string;
scope: string;
}

export interface OAuth2AuthorizationResponseType {
data: {
accessToken: string;
},
success: boolean;
}

export interface OAuth2GetAccessTokenRequestType {
clientId: string;
clientSecret: string;
grantType: string;
redirectUri: string;
code: string;
codeVerifier: string;
}

export interface OAuth2GetRefreshTokenRequestType {
clientId: string;
clientSecret: string;
grantType: string;
redirectUri: string;
refreshToken: string;
}

export interface GetUserDataResponseType {
data: {
email: string;
gamertag: string;
id: string;
image: string;
isVerified: string;
ligthningAddress: string;
publicBio: string;
publicStaticCharge: string;
social: Record<string, string>;
},
success: boolean;
}

export interface GetUserWalletDataResponseType {
data: {
balance: string;
remainingAmountLimits: {
daily: string;
maxCredit: string;
monthly: string;
weekly: string;
},
},
message: string;
success: boolean;
}
93 changes: 93 additions & 0 deletions src/zbd.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ import {
ValidateLightningAddressDataResponseType,
SendLightningAddressPaymentDataResponseType,
CreateChargeFromLightningAddressOptionsType,
OAuth2AuthorizationRequestType,
OAuth2GetAccessTokenRequestType,
OAuth2GetRefreshTokenRequestType,
} from './types';

class zbd {
Expand Down Expand Up @@ -397,6 +400,96 @@ class zbd {

return response;
}

async authorizeOAuth2(options: OAuth2AuthorizationRequestType) {

const queryParams = new URLSearchParams();
queryParams.append('client_id', options.clientId);
queryParams.append('response_type', options.responseType);
queryParams.append('redirect_uri', options.redirectUri);
queryParams.append('code_challenge', options.codeChallenge);
queryParams.append('code_challenge_method', options.codeChallengeMethod);

const response = await getData({
url: `${API_URL}${API.OAUTH2_AUTHORIZATION_ENDPOINT}?${queryParams}`,
headers: { ...this.apiCoreHeaders },
});

return response;
}

async getOAuth2AccessToken(options: OAuth2GetAccessTokenRequestType) {

const queryParams = new URLSearchParams({
'Content-Type': 'application/json'
});

const requestBody = {
client_id: options.clientId,
client_secret: options.clientSecret,
grant_type: options.grantType,
redirect_uri: options.redirectUri,
code: options.code,
code_verifier: options.codeVerifier,
}

const response = await postData({
url: `${API_URL}${API.OAUTH2_GET_TOKEN_ENDPOINT}?${queryParams}`,
headers: {
...this.apiCoreHeaders,
},
body: requestBody,
});

return response;
}

async refreshOAuth2Token(options: OAuth2GetRefreshTokenRequestType) {

const requestBody = {
client_id: options.clientId,
client_secret: options.clientSecret,
grant_type: options.grantType,
redirect_uri: options.redirectUri,
refresh_token: options.refreshToken,
}

const response = await postData({
url: `${API_URL}${API.OAUTH2_GET_TOKEN_ENDPOINT}`,
headers: {
...this.apiCoreHeaders,
},
body: requestBody,
});

return response;
}

async getUser(oauth2AccessToken: string) {

const response = await getData({
url: `${API_URL}${API.OAUTH2_GET_USER_PROFILE_ENDPOINT}`,
headers: {
...this.apiCoreHeaders,
usertoken: oauth2AccessToken,
},
});

return response;
}

async getUserWallet(oauth2AccessToken: string) {

const response = await getData({
url: `${API_URL}${API.OAUTH2_GET_USER_WALLET_ENDPOINT}`,
headers: {
...this.apiCoreHeaders,
usertoken: oauth2AccessToken,
},
});

return response;
}
}

export { zbd };