Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Export Auth type #466

Merged
merged 1 commit into from
Jan 3, 2024
Merged
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
5 changes: 5 additions & 0 deletions .changeset/eleven-mirrors-fry.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@bnb-chain/greenfield-js-sdk': patch
---

feat: Export Auth type
3 changes: 2 additions & 1 deletion packages/js-sdk/src/api/bucket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import { bytesToUtf8, hexToBytes } from 'ethereum-cryptography/utils';
import Long from 'long';
import { container, delay, inject, injectable } from 'tsyringe';
import {
AuthType,
GRNToString,
MsgCreateBucketTypeUrl,
MsgDeleteBucketTypeUrl,
Expand Down Expand Up @@ -65,7 +66,7 @@ import {
getQueryBucketReadQuotaMetaInfo,
parseReadQuotaResponse,
} from '../clients/spclient/spApis/queryBucketReadQuota';
import { AuthType, SpClient } from '../clients/spclient/spClient';
import { SpClient } from '../clients/spclient/spClient';
import { TxClient } from '../clients/txClient';
import { METHOD_GET, NORMAL_ERROR_CODE } from '../constants/http';
import { MsgCreateBucketSDKTypeEIP712 } from '../messages/greenfield/storage/MsgCreateBucket';
Expand Down
3 changes: 2 additions & 1 deletion packages/js-sdk/src/api/objects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,9 @@ import {
newObjectGRN,
} from '..';
import { RpcQueryClient } from '../clients/queryclient';
import { AuthType, SpClient } from '../clients/spclient/spClient';
import { SpClient } from '../clients/spclient/spClient';
import {
AuthType,
CreateObjectApprovalRequest,
CreateObjectApprovalResponse,
GetListObjectPoliciesRequest,
Expand Down
3 changes: 2 additions & 1 deletion packages/js-sdk/src/api/payment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import {
} from '@bnb-chain/greenfield-cosmos-types/greenfield/payment/tx';
import { container, delay, inject, injectable } from 'tsyringe';
import {
AuthType,
MsgDepositTypeUrl,
MsgDisableRefundTypeUrl,
MsgWithdrawTypeUrl,
Expand All @@ -41,7 +42,7 @@ import {
getListUserPaymentAccountMetaInfo,
parseListUserPaymentAccountResponse,
} from '../clients/spclient/spApis/listUserPaymentAccounts';
import { AuthType, SpClient } from '../clients/spclient/spClient';
import { SpClient } from '../clients/spclient/spClient';
import { TxClient } from '../clients/txClient';
import { MsgDepositSDKTypeEIP712 } from '../messages/greenfield/payment/MsgDeposit';
import { MsgDisableRefundSDKTypeEIP712 } from '../messages/greenfield/payment/MsgDisableRefund';
Expand Down
3 changes: 1 addition & 2 deletions packages/js-sdk/src/clients/spclient/auth.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import { signSignatureByEddsa } from '@/offchainauth';
import { ReqMeta } from '@/types/auth';
import { AuthType, ReqMeta } from '@/types/auth';
import { hexlify, joinSignature } from '@ethersproject/bytes';
import { SigningKey } from '@ethersproject/signing-key';
import { Headers } from 'cross-fetch';
import { keccak256 } from 'ethereum-cryptography/keccak.js';
import { utf8ToBytes } from 'ethereum-cryptography/utils.js';
import { AuthType } from './spClient';

export const getCanonicalHeaders = (reqMeta: Partial<ReqMeta>, reqHeaders: Headers) => {
const sortedHeaders = getSortedHeaders(reqHeaders, SUPPORTED_HEADERS);
Expand Down
20 changes: 1 addition & 19 deletions packages/js-sdk/src/clients/spclient/spClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,29 +7,11 @@ import {
} from '@/clients/spclient/auth';
import { parseError } from '@/clients/spclient/spApis/parseError';
import { SP_NOT_AVAILABLE_ERROR_CODE, SP_NOT_AVAILABLE_ERROR_MSG } from '@/constants/http';
import { ReqMeta } from '@/types/auth';
import { AuthType, ReqMeta } from '@/types/auth';
import { injectable } from 'tsyringe';
import { getGetObjectMetaInfo } from './spApis/getObject';
import { getPutObjectMetaInfo } from './spApis/putObject';

/**
* ECDSA Signature
*/
export type ECDSA = {
type: 'ECDSA';
privateKey: string;
};
/**
* EDDSA Signature
*/
export type EDDSA = {
type: 'EDDSA';
seed: string;
domain: string;
address: string;
};
export type AuthType = ECDSA | EDDSA;

export interface ISpClient {
callApi(
url: string,
Expand Down
18 changes: 18 additions & 0 deletions packages/js-sdk/src/types/auth.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,23 @@
import { METHOD_GET, METHOD_POST, METHOD_PUT } from '@/constants/http';

/**
* ECDSA Signature
*/
export type ECDSA = {
type: 'ECDSA';
privateKey: string;
};
/**
* EDDSA Signature
*/
export type EDDSA = {
type: 'EDDSA';
seed: string;
domain: string;
address: string;
};
export type AuthType = ECDSA | EDDSA;

export interface ReqMeta {
method: typeof METHOD_GET | typeof METHOD_POST | typeof METHOD_PUT;
contentType: string;
Expand Down
Loading