Skip to content

Commit

Permalink
Merge branch 'main' into alpha
Browse files Browse the repository at this point in the history
  • Loading branch information
rrr523 committed Mar 6, 2024
2 parents 97f5279 + a63777d commit 9322418
Show file tree
Hide file tree
Showing 22 changed files with 207 additions and 149 deletions.
2 changes: 1 addition & 1 deletion doc-site/docs/client/greenfield.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const client = Client.create(GRPC_URL, GREEN_CHAIN_ID);
// Browser
const client = Client.create(GRPC_URL, String(GREEN_CHAIN_ID), {
zkCryptoUrl:
'https://unpkg.com/@bnb-chain/greenfield-zk-crypto/dist/node/zk-crypto.wasm',
'https://unpkg.com/@bnb-chain/greenfield-zk-crypto@0.0.3/dist/node/zk-crypto.wasm',
});
```

Expand Down
2 changes: 1 addition & 1 deletion doc-site/docusaurus.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const config = {
staticDirectories: ['static'],

// Set the production url of your site here
url: 'https://greenfield-js-sdk.netlify.app',
url: 'https://docs.bnbchain.org',
// Set the /<baseUrl>/ pathname under which your site is served
// For GitHub pages deployment, it is often '/<projectName>/'
baseUrl: '/greenfield-js-sdk/',
Expand Down
29 changes: 23 additions & 6 deletions examples/nextjs/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,23 @@
# @demo/wallet

## 0.0.27

### Patch Changes

- Updated dependencies
[[`389119e`](https://github.com/bnb-chain/greenfield-js-sdk/commit/389119ea489441d90b0e1d1f8a3946bc97ca6228),
[`389119e`](https://github.com/bnb-chain/greenfield-js-sdk/commit/389119ea489441d90b0e1d1f8a3946bc97ca6228)]:
- @bnb-chain/greenfield-js-sdk@1.2.2

## 0.0.26

### Patch Changes

- Updated dependencies
[[`a467c26`](https://github.com/bnb-chain/greenfield-js-sdk/commit/a467c26f6991a2f482c969235252f548c90c9827),
[`ec70921`](https://github.com/bnb-chain/greenfield-js-sdk/commit/ec70921011c5b08ea97fb7bd8712de6aa00431a0)]:
- @bnb-chain/greenfield-js-sdk@1.2.1

## 0.0.25

### Patch Changes
Expand All @@ -11,12 +29,12 @@
## 0.0.24

### Patch Changes

- Updated dependencies
[[`24ec472`](https://github.com/bnb-chain/greenfield-js-sdk/commit/24ec472b4507d0f3cba3c8fc55b4e9f924d5b1c7),
[`b41fdf0`](https://github.com/bnb-chain/greenfield-js-sdk/commit/b41fdf057b7b4b0f416a74fb04ed0793c52c51f7),
[`865be47`](https://github.com/bnb-chain/greenfield-js-sdk/commit/865be476dfd78f86b9d0a7dba3074fbf7ae32bb7),
[`865be47`](https://github.com/bnb-chain/greenfield-js-sdk/commit/865be476dfd78f86b9d0a7dba3074fbf7ae32bb7)]:
[[`24ec472`](https://github.com/bnb-chain/greenfield-js-sdk/commit/24ec472b4507d0f3cba3c8fc55b4e9f924d5b1c7),
[`b41fdf0`](https://github.com/bnb-chain/greenfield-js-sdk/commit/b41fdf057b7b4b0f416a74fb04ed0793c52c51f7),
[`865be47`](https://github.com/bnb-chain/greenfield-js-sdk/commit/865be476dfd78f86b9d0a7dba3074fbf7ae32bb7),
[`865be47`](https://github.com/bnb-chain/greenfield-js-sdk/commit/865be476dfd78f86b9d0a7dba3074fbf7ae32bb7)]:
- @bnb-chain/greenfield-js-sdk@1.2.0

## 0.0.24-alpha.2
Expand Down Expand Up @@ -44,7 +62,6 @@
[`865be47`](https://github.com/bnb-chain/greenfield-js-sdk/commit/865be476dfd78f86b9d0a7dba3074fbf7ae32bb7)]:
- @bnb-chain/greenfield-js-sdk@1.2.0-alpha.0


## 0.0.23

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion examples/nextjs/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@demo/wallet",
"version": "0.0.25",
"version": "0.0.27",
"private": true,
"scripts": {
"dev": "cross-env NODE_ENV=development next dev",
Expand Down
20 changes: 18 additions & 2 deletions examples/nextjs/src/components/feegrant/createObj.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
GRNToString,
MsgCreateObjectTypeUrl,
newBucketGRN,
newObjectGRN,
PermissionTypes,
toTimestamp,
} from '@bnb-chain/greenfield-js-sdk';
Expand Down Expand Up @@ -146,13 +147,28 @@ export const CreateObj = () => {
},
);

const simulateInfo = await createObjectTx.simulate({
const setTagTx = await client.storage.setTag({
operator: granteeAddr,
resource: GRNToString(newObjectGRN(bucketName, objectName)),
tags: {
tags: [
{
key: 'x',
value: 'xx',
},
],
},
});

const multiTx = await client.txClient.multiTx([createObjectTx, setTagTx]);

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

console.log('simulateInfo', simulateInfo);

const res = await createObjectTx.broadcast({
const res = await multiTx.broadcast({
denom: 'BNB',
gasLimit: Number(simulateInfo?.gasLimit),
gasPrice: simulateInfo?.gasPrice || '5000000000',
Expand Down
25 changes: 25 additions & 0 deletions packages/js-sdk/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,30 @@
# @bnb-chain/greenfield-js-sdk

## 1.2.2

### Patch Changes

- [#487](https://github.com/bnb-chain/greenfield-js-sdk/pull/487)
[`389119e`](https://github.com/bnb-chain/greenfield-js-sdk/commit/389119ea489441d90b0e1d1f8a3946bc97ca6228)
Thanks [@rrr523](https://github.com/rrr523)! - feat: Support source map

- [#487](https://github.com/bnb-chain/greenfield-js-sdk/pull/487)
[`389119e`](https://github.com/bnb-chain/greenfield-js-sdk/commit/389119ea489441d90b0e1d1f8a3946bc97ca6228)
Thanks [@rrr523](https://github.com/rrr523)! - feat: Verify Address

## 1.2.1

### Patch Changes

- [#484](https://github.com/bnb-chain/greenfield-js-sdk/pull/484)
[`a467c26`](https://github.com/bnb-chain/greenfield-js-sdk/commit/a467c26f6991a2f482c969235252f548c90c9827)
Thanks [@rrr523](https://github.com/rrr523)! - fix: Using Cross Fetch replace native fetch (occurs
on Nodejs 18-)

- [#485](https://github.com/bnb-chain/greenfield-js-sdk/pull/485)
[`ec70921`](https://github.com/bnb-chain/greenfield-js-sdk/commit/ec70921011c5b08ea97fb7bd8712de6aa00431a0)
Thanks [@rrr523](https://github.com/rrr523)! - feat: Verify and Assert params

## 1.2.0

### Minor Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/js-sdk/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@bnb-chain/greenfield-js-sdk",
"version": "1.2.0",
"version": "1.2.2",
"description": "greenfield js chain and sp sdk",
"main": "./dist/cjs/index.js",
"module": "./dist/esm/index.js",
Expand Down
2 changes: 2 additions & 0 deletions packages/js-sdk/rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export default async () => {
output: {
dir: './dist/esm',
format: 'esm',
sourcemap: true,
},
external: resolveExternal(),
context: 'window',
Expand Down Expand Up @@ -55,6 +56,7 @@ export default async () => {
output: {
dir: './dist/cjs',
format: 'cjs',
sourcemap: true,
},
external: resolveExternal(),
plugins: [
Expand Down
47 changes: 21 additions & 26 deletions packages/js-sdk/src/api/bucket.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { assertAuthType, assertStringRequire } from '@/utils/asserts/params';
import { UInt64Value } from '@bnb-chain/greenfield-cosmos-types/greenfield/common/wrapper';
import {
ActionType,
Expand Down Expand Up @@ -92,8 +93,8 @@ import type {
ReadQuotaRequest,
SpResponse,
} from '../types/sp';
import { verifyAddress, verifyBucketName, verifyUrl } from '../utils/asserts/s3';
import { decodeObjectFromHexString } from '../utils/encoding';
import { isValidAddress, isValidBucketName, isValidUrl } from '../utils/s3';
import { Sp } from './sp';
import { Storage } from './storage';

Expand Down Expand Up @@ -216,15 +217,10 @@ export class Bucket implements IBucket {
} = params;

try {
if (!spInfo.primarySpAddress) {
throw new Error('Primary sp address is missing');
}
if (!isValidBucketName(bucketName)) {
throw new Error('Error bucket name');
}
if (!creator) {
throw new Error('Empty creator address');
}
assertAuthType(authType);
assertStringRequire(spInfo.primarySpAddress, 'Primary sp address is missing');
assertStringRequire(creator, 'Empty creator address');
verifyBucketName(bucketName);

const endpoint = await this.sp.getSPUrlByPrimaryAddr(spInfo.primarySpAddress);

Expand Down Expand Up @@ -288,6 +284,7 @@ export class Bucket implements IBucket {
}

public async createBucket(params: CreateBucketApprovalRequest, authType: AuthType) {
assertAuthType(authType);
const { body } = await this.getCreateBucketApproval(params, authType);

if (!body) {
Expand Down Expand Up @@ -362,12 +359,9 @@ export class Bucket implements IBucket {
public async listBuckets(configParam: GetUserBucketsRequest) {
try {
const { address, duration = 30000, endpoint } = configParam;
if (!isValidAddress(address)) {
throw new Error('Error address');
}
if (!isValidUrl(endpoint)) {
throw new Error('Invalid endpoint');
}
verifyAddress(address);
verifyUrl(endpoint);

const { url } = getUserBucketMetaInfo(endpoint);

const headers = new Headers({
Expand Down Expand Up @@ -417,9 +411,10 @@ export class Bucket implements IBucket {
): Promise<SpResponse<IQuotaProps>> {
try {
const { bucketName, duration = 30000 } = params;
if (!isValidBucketName(bucketName)) {
throw new Error('Error bucket name');
}

verifyBucketName(bucketName);
assertAuthType(authType);

let endpoint = params.endpoint;
if (!endpoint) {
endpoint = await this.sp.getSPUrlByBucket(bucketName);
Expand Down Expand Up @@ -528,6 +523,7 @@ export class Bucket implements IBucket {
}

public async getMigrateBucketApproval(params: MigrateBucketApprovalRequest, authType: AuthType) {
assertAuthType(authType);
const { bucketName, operator, dstPrimarySpId } = params;

try {
Expand Down Expand Up @@ -579,8 +575,9 @@ export class Bucket implements IBucket {
}

public async migrateBucket(params: MigrateBucketApprovalRequest, authType: AuthType) {
const { signedMsg } = await this.getMigrateBucketApproval(params, authType);
assertAuthType(authType);

const { signedMsg } = await this.getMigrateBucketApproval(params, authType);
if (!signedMsg) {
throw new Error('Get migrate bucket approval error');
}
Expand Down Expand Up @@ -621,9 +618,7 @@ export class Bucket implements IBucket {

public async getBucketMeta(params: GetBucketMetaRequest) {
const { bucketName } = params;
if (!isValidBucketName(bucketName)) {
throw new Error('Error bucket name');
}
verifyBucketName(bucketName);

let endpoint = params.endpoint;
if (!endpoint) {
Expand All @@ -649,14 +644,14 @@ export class Bucket implements IBucket {

public async listBucketReadRecords(params: ListBucketReadRecordRequest, authType: AuthType) {
try {
assertAuthType(authType);

const { bucketName } = params;
let endpoint = params.endpoint;
if (!endpoint) {
endpoint = await this.sp.getSPUrlByBucket(bucketName);
}
if (!isValidUrl(endpoint)) {
throw new Error('Invalid endpoint');
}
verifyUrl(endpoint);

const { url, optionsWithOutHeaders, reqMeta } = getListBucketReadRecordMetaInfo(
endpoint,
Expand Down
Loading

0 comments on commit 9322418

Please sign in to comment.