From dc877833ed400166fd1384b315c9ac068d6a80f5 Mon Sep 17 00:00:00 2001 From: rrr523 <59029880+rrr523@users.noreply.github.com> Date: Mon, 24 Jul 2023 18:01:46 +0800 Subject: [PATCH] feat: Add Two Apis (#179) * feat: Add Two Apis * Create mean-wombats-remain.md --- .changeset/mean-wombats-remain.md | 5 ++++ packages/chain-sdk/src/api/objectt.ts | 42 ++++++++++++++++++++++++++- 2 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 .changeset/mean-wombats-remain.md diff --git a/.changeset/mean-wombats-remain.md b/.changeset/mean-wombats-remain.md new file mode 100644 index 00000000..8cbc9e87 --- /dev/null +++ b/.changeset/mean-wombats-remain.md @@ -0,0 +1,5 @@ +--- +"@bnb-chain/greenfield-chain-sdk": patch +--- + +feat: Add `getObjectPolicy` and `isObjectPermissionAllowed` diff --git a/packages/chain-sdk/src/api/objectt.ts b/packages/chain-sdk/src/api/objectt.ts index 505d9b19..77448f87 100644 --- a/packages/chain-sdk/src/api/objectt.ts +++ b/packages/chain-sdk/src/api/objectt.ts @@ -5,6 +5,7 @@ import { MsgUpdateObjectInfoSDKTypeEIP712 } from '@/messages/greenfield/storage/ import { getAuthorizationAuthTypeV2 } from '@/utils/auth'; import { fetchWithTimeout, METHOD_GET, METHOD_PUT, NORMAL_ERROR_CODE } from '@/utils/http'; import { + ActionType, Principal, PrincipalType, } from '@bnb-chain/greenfield-cosmos-types/greenfield/permission/common'; @@ -16,6 +17,8 @@ import { QueryHeadObjectResponse, QueryNFTRequest, QueryObjectNFTResponse, + QueryPolicyForAccountResponse, + QueryVerifyPermissionResponse, } from '@bnb-chain/greenfield-cosmos-types/greenfield/storage/query'; import { MsgCancelCreateObject, @@ -103,7 +106,18 @@ export interface IObject { principalAddr: string, ): Promise; - // TODO: IsObjectPermissionAllowed + isObjectPermissionAllowed( + bucketName: string, + objectName: string, + actionType: ActionType, + operator: string, + ): Promise; + + getObjectPolicy( + bucketName: string, + objectName: string, + principalAddr: string, + ): Promise; // TODO: GetObjectUploadProgress // TODO: getObjectStatusFromSP } @@ -609,6 +623,32 @@ export class Objectt implements IObject { return await this.storage.putPolicy(msg); } + public async isObjectPermissionAllowed( + bucketName: string, + objectName: string, + actionType: ActionType, + operator: string, + ) { + const rpc = await this.queryClient.getStorageQueryClient(); + return await rpc.VerifyPermission({ + bucketName, + objectName, + actionType, + operator, + }); + } + + public async getObjectPolicy(bucketName: string, objectName: string, principalAddr: string) { + const rpc = await this.queryClient.getStorageQueryClient(); + + const resource = GRNToString(newObjectGRN(bucketName, objectName)); + + return await rpc.QueryPolicyForAccount({ + resource, + principalAddress: principalAddr, + }); + } + public async deleteObjectPolicy( operator: string, bucketName: string,