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

fix: Delete Policy #332

Merged
merged 1 commit into from
Sep 14, 2023
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/tender-bats-help.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@bnb-chain/greenfield-js-sdk': patch
---

fix: Delete Policy
1 change: 0 additions & 1 deletion examples/nextjs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
"lint": "next lint"
},
"dependencies": {
"@bnb-chain/greenfield-cosmos-types": "0.4.0-alpha.23",
"@bnb-chain/greenfield-js-sdk": "workspace:*",
"@bnb-chain/greenfiled-file-handle": "workspace:*",
"@cosmjs/encoding": "^0.29.5",
Expand Down
1 change: 0 additions & 1 deletion examples/nextjs/src/components/customtx/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { client } from '@/client';
import { MsgSend } from '@bnb-chain/greenfield-cosmos-types/cosmos/bank/v1beta1/tx';
import { useAccount } from 'wagmi';

export const CustomTx = () => {
Expand Down
49 changes: 49 additions & 0 deletions examples/nextjs/src/components/policy/bucketPolicy/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,55 @@ export const BucketPolicy = () => {
>
put bucket policy
</button>
<button
onClick={async () => {
if (!address) return;

const tx = await client.bucket.deleteBucketPolicy(
address,
policyBucketInfo.bucketName,
address,
'PRINCIPAL_TYPE_GNFD_ACCOUNT',
);

const simulateInfo = await tx.simulate({
denom: 'BNB',
});

console.log('simulateInfo', simulateInfo);

const res = await tx.broadcast({
denom: 'BNB',
gasLimit: Number(simulateInfo?.gasLimit),
gasPrice: simulateInfo?.gasPrice || '5000000000',
payer: address,
granter: '',
});

console.log('res', res);

if (res.code === 0) {
alert('success');
}
}}
>
delete bucket policy
</button>
{/* <button onClick={async () => {
if (!address) return;

const principal: PermissionTypes.Principal = {

}

await client.storage.deletePolicy({
operator: address,
principal,
resource:
})
}}>
xx
</button> */}
</>
);
};
35 changes: 35 additions & 0 deletions examples/nextjs/src/components/policy/objectPolicy/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,41 @@ export const ObjectPolicy = () => {
>
put object policy
</button>
<button
onClick={async () => {
if (!address) return;

const tx = await client.object.deleteObjectPolicy(
address,
policyObjectInfo.bucketName,
policyObjectInfo.objectName,
address,
'PRINCIPAL_TYPE_GNFD_GROUP',
);

const simulateInfo = await tx.simulate({
denom: 'BNB',
});

console.log('simulateInfo', simulateInfo);

const res = await tx.broadcast({
denom: 'BNB',
gasLimit: Number(simulateInfo?.gasLimit),
gasPrice: simulateInfo?.gasPrice || '5000000000',
payer: address,
granter: '',
});

console.log('res', res);

if (res.code === 0) {
alert('success');
}
}}
>
delete object policy
</button>
</>
);
};
11 changes: 9 additions & 2 deletions packages/chain-sdk/src/api/bucket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import {
ActionType,
Principal,
PrincipalType,
principalTypeFromJSON,
} from '@bnb-chain/greenfield-cosmos-types/greenfield/permission/common';
import { visibilityTypeFromJSON } from '@bnb-chain/greenfield-cosmos-types/greenfield/storage/common';
import {
Expand Down Expand Up @@ -107,6 +108,7 @@ export interface IBucket {
operator: string,
bucketName: string,
principalAddr: string,
principalType: keyof typeof PrincipalType,
): Promise<TxResponse>;

getBucketMeta(params: GetBucketMetaRequest): Promise<SpResponse<GetBucketMetaResponse>>;
Expand Down Expand Up @@ -496,10 +498,15 @@ export class Bucket implements IBucket {
return this.storage.putPolicy(msg);
}

public async deleteBucketPolicy(operator: string, bucketName: string, principalAddr: string) {
public async deleteBucketPolicy(
operator: string,
bucketName: string,
principalAddr: string,
principalType: keyof typeof PrincipalType,
) {
const resource = GRNToString(newBucketGRN(bucketName));
const principal: Principal = {
type: PrincipalType.PRINCIPAL_TYPE_GNFD_ACCOUNT,
type: principalTypeFromJSON(principalType),
value: principalAddr,
};

Expand Down
5 changes: 4 additions & 1 deletion packages/chain-sdk/src/api/objectt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import {
ActionType,
Principal,
PrincipalType,
principalTypeFromJSON,
} from '@bnb-chain/greenfield-cosmos-types/greenfield/permission/common';
import {
redundancyTypeFromJSON,
Expand Down Expand Up @@ -148,6 +149,7 @@ export interface IObject {
bucketName: string,
objectName: string,
principalAddr: string,
principalType: keyof typeof PrincipalType,
): Promise<TxResponse>;

isObjectPermissionAllowed(
Expand Down Expand Up @@ -669,10 +671,11 @@ export class Objectt implements IObject {
bucketName: string,
objectName: string,
principalAddr: string,
principalType: keyof typeof PrincipalType,
) {
const resource = GRNToString(newObjectGRN(bucketName, objectName));
const principal: Principal = {
type: PrincipalType.PRINCIPAL_TYPE_GNFD_ACCOUNT,
type: principalTypeFromJSON(principalType),
value: principalAddr,
};

Expand Down
2 changes: 1 addition & 1 deletion packages/chain-sdk/src/clients/txClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ export class TxClient implements ITxClient {
);

const eip712 = createEIP712(wrapperTypes, this.chainId, messages);
// console.log('eip712', eip712);

const { pubKey, signature } = privateKey
? this.getSignByPriKey(eip712, privateKey)
: await this.getSignByWallet(eip712, accountInfo.address, signTypedDataCallback);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,19 @@ export const MsgDeletePolicySDKTypeEIP712 = {
name: 'resource',
type: 'string',
},
{
name: 'principal',
type: 'TypeMsg1Principal',
},
],
TypeMsg1Principal: [
{
name: 'type',
type: 'string',
},
{
name: 'value',
type: 'string',
},
],
};
Loading