Skip to content

Commit

Permalink
feat: Export Auth type (#466)
Browse files Browse the repository at this point in the history
  • Loading branch information
rrr523 authored Jan 3, 2024
1 parent 4206ece commit 159cb9c
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 24 deletions.
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

0 comments on commit 159cb9c

Please sign in to comment.