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/zk #471

Closed
wants to merge 17 commits into from
Closed
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/new-scissors-eat.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@bnb-chain/greenfield-js-sdk': patch
---

feat: compatibility window WASM method and lazy load function
5 changes: 5 additions & 0 deletions .changeset/sharp-needles-exist.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@bnb-chain/greenfield-zk-crypto': minor
---

feat: Build WASM
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
41 changes: 39 additions & 2 deletions examples/nextjs/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,49 @@
# @demo/wallet

## 0.0.25

### Patch Changes

- Updated dependencies
[[`159cb9c`](https://github.com/bnb-chain/greenfield-js-sdk/commit/159cb9c896d3d44b92715b2c12a6db1aeed20081)]:
- @bnb-chain/[email protected]

## 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)]:
- @bnb-chain/[email protected]

## 0.0.24-alpha.2

### Patch Changes

- Updated dependencies
[[`24ec472`](https://github.com/bnb-chain/greenfield-js-sdk/commit/24ec472b4507d0f3cba3c8fc55b4e9f924d5b1c7)]:
- @bnb-chain/[email protected]

## 0.0.24-alpha.1

### Patch Changes

- Updated dependencies
[[`b41fdf0`](https://github.com/bnb-chain/greenfield-js-sdk/commit/b41fdf057b7b4b0f416a74fb04ed0793c52c51f7)]:
- @bnb-chain/[email protected]

## 0.0.24-alpha.0

### Patch Changes

- Updated dependencies
[[`4cf4abc`](https://github.com/bnb-chain/greenfield-js-sdk/commit/4cf4abc348c080f73abd8578f0092ca6ab318fe3)]:
- @bnb-chain/[email protected]
[[`865be47`](https://github.com/bnb-chain/greenfield-js-sdk/commit/865be476dfd78f86b9d0a7dba3074fbf7ae32bb7),
[`865be47`](https://github.com/bnb-chain/greenfield-js-sdk/commit/865be476dfd78f86b9d0a7dba3074fbf7ae32bb7)]:
- @bnb-chain/[email protected]


## 0.0.23

Expand Down
4 changes: 2 additions & 2 deletions examples/nextjs/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@demo/wallet",
"version": "0.0.24",
"version": "0.0.25",
"private": true,
"scripts": {
"dev": "cross-env NODE_ENV=development next dev",
Expand All @@ -11,7 +11,7 @@
"lint": "next lint"
},
"dependencies": {
"@bnb-chain/greenfield-cosmos-types": "0.4.0-alpha.25",
"@bnb-chain/greenfield-cosmos-types": "0.4.0-alpha.30",
"@bnb-chain/greenfield-js-sdk": "workspace:*",
"@bnb-chain/reed-solomon": "workspace:*",
"@cosmjs/encoding": "^0.32.0",
Expand Down
25 changes: 23 additions & 2 deletions examples/nextjs/src/components/bucket/create/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { client, selectSp } from '@/client';
import { getOffchainAuthKeys } from '@/utils/offchainAuth';
import { GRNToString, newBucketGRN, newGroupGRN } from '@bnb-chain/greenfield-js-sdk';
import { add } from 'lodash';
import { useState } from 'react';
import { useAccount } from 'wagmi';

Expand Down Expand Up @@ -58,13 +60,32 @@ export const CreateBucket = () => {
},
);

const simulateInfo = await createBucketTx.simulate({
const setTagTx = await client.storage.setTag({
operator: address,
resource: GRNToString(newBucketGRN(createBucketInfo.bucketName)),
tags: {
tags: [
{
key: 'x',
value: 'xx',
},
{
key: 'y',
value: 'yy',
},
],
},
});

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

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

console.log('simulateInfo', simulateInfo);

const res = await createBucketTx.broadcast({
const res = await tx.broadcast({
denom: 'BNB',
gasLimit: Number(simulateInfo?.gasLimit),
gasPrice: simulateInfo?.gasPrice || '5000000000',
Expand Down
11 changes: 5 additions & 6 deletions examples/nextjs/src/components/feegrant/createObj.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { Wallet } from '@ethersproject/wallet';
import { ChangeEvent, useState } from 'react';
import { parseEther } from 'viem';
import { useAccount } from 'wagmi';
import { ReedSolomon } from '@bnb-chain/reed-solomon';

/**
* fee grant for creat object
Expand Down Expand Up @@ -124,11 +125,9 @@ export const CreateObj = () => {

console.log('temp account', granteeAddr, privateKey);

const rs = new ReedSolomon();
const fileBytes = await file.arrayBuffer();
const hashResult = await (window as any).FileHandle.getCheckSums(
new Uint8Array(fileBytes),
);
const { contentLength, expectCheckSums } = hashResult;
const expectCheckSums = rs.encode(new Uint8Array(fileBytes));

const createObjectTx = await client.object.createObject(
{
Expand All @@ -137,13 +136,13 @@ export const CreateObj = () => {
objectName: objectName,
visibility: 'VISIBILITY_TYPE_PUBLIC_READ',
redundancyType: 'REDUNDANCY_EC_TYPE',
contentLength,
contentLength: fileBytes.byteLength,
expectCheckSums,
fileType: file.type,
},
{
type: 'ECDSA',
privateKey: ACCOUNT_PRIVATEKEY,
privateKey: privateKey,
},
);

Expand Down
45 changes: 43 additions & 2 deletions examples/nextjs/src/components/group/update/index.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { client } from '@/client';
import { GRNToString, newBucketGRN, newGroupGRN, toTimestamp } from '@bnb-chain/greenfield-js-sdk';
import { GRNToString, newGroupGRN, toTimestamp } from '@bnb-chain/greenfield-js-sdk';
import { useState } from 'react';
import { zeroAddress } from 'viem';
import { useAccount } from 'wagmi';

export const GroupUpdate = () => {
Expand Down Expand Up @@ -120,6 +119,48 @@ export const GroupUpdate = () => {
>
updateGroupExtra
</button>
<br />
<button
onClick={async () => {
if (!address) return;

const resource = GRNToString(newGroupGRN(address, groupName));

const updateGroupTx = await client.storage.setTag({
operator: address,
resource,
// tags: {
// tags: [],
// },
tags: {
tags: [
{
key: 'x',
value: 'xx',
},
],
},
});

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

console.log(simulateInfo);

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

console.log('res', res);
}}
>
update group tags
</button>
</div>
);
};
6 changes: 0 additions & 6 deletions examples/nextjs/src/pages/_document.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,6 @@ export default function Document() {
<Main />
<NextScript />
</body>
<script src="https://unpkg.com/@bnb-chain/[email protected]/dist/browser/umd/index.js"></script>
<script
dangerouslySetInnerHTML={{
__html: `window.__PUBLIC_FILE_HANDLE_WASM_PATH__ = 'https://unpkg.com/@bnb-chain/[email protected]/dist/node/file-handle.wasm'`,
}}
></script>
</Html>
);
}
21 changes: 21 additions & 0 deletions examples/nodejs-file-management/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# @demo/nodejs

## 0.0.26

### 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)]:
- @bnb-chain/[email protected]

## 0.0.2-alpha.0

### Patch Changes

- Updated dependencies
[[`865be47`](https://github.com/bnb-chain/greenfield-js-sdk/commit/865be476dfd78f86b9d0a7dba3074fbf7ae32bb7),
[`865be47`](https://github.com/bnb-chain/greenfield-js-sdk/commit/865be476dfd78f86b9d0a7dba3074fbf7ae32bb7)]:
- @bnb-chain/[email protected]
4 changes: 2 additions & 2 deletions examples/nodejs-file-management/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@demo/nodejs",
"version": "0.0.1",
"version": "0.0.26",
"type": "commonjs",
"private": true,
"scripts": {
Expand All @@ -10,7 +10,7 @@
"author": "",
"license": "ISC",
"dependencies": {
"@bnb-chain/greenfield-js-sdk": "^1.1.2",
"@bnb-chain/greenfield-js-sdk": "^1.2.0",
"@bnb-chain/reed-solomon": "^1.1.1",
"dotenv": "^16.3.1",
"mime-types": "^2.1.35"
Expand Down
3 changes: 3 additions & 0 deletions examples/nodejs/cases/storage.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ console.log('objectName', objectName);
primarySpAddress: spInfo.primarySpAddress,
},
paymentAddress: ACCOUNT_ADDRESS,
tags: {
tags: [],
},
},
{
type: 'ECDSA',
Expand Down
58 changes: 58 additions & 0 deletions packages/js-sdk/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,63 @@
# @bnb-chain/greenfield-js-sdk

## 1.2.0

### Minor Changes

- [#461](https://github.com/bnb-chain/greenfield-js-sdk/pull/461)
[`865be47`](https://github.com/bnb-chain/greenfield-js-sdk/commit/865be476dfd78f86b9d0a7dba3074fbf7ae32bb7)
Thanks [@rrr523](https://github.com/rrr523)! - feat: Add SetTag API

### Patch Changes

- [#464](https://github.com/bnb-chain/greenfield-js-sdk/pull/464)
[`24ec472`](https://github.com/bnb-chain/greenfield-js-sdk/commit/24ec472b4507d0f3cba3c8fc55b4e9f924d5b1c7)
Thanks [@rrr523](https://github.com/rrr523)! - feat: Sp Api Types

- [`b41fdf0`](https://github.com/bnb-chain/greenfield-js-sdk/commit/b41fdf057b7b4b0f416a74fb04ed0793c52c51f7)
Thanks [@rrr523](https://github.com/rrr523)! - chore: pnpm --no-frozen-lockfile

- [#461](https://github.com/bnb-chain/greenfield-js-sdk/pull/461)
[`865be47`](https://github.com/bnb-chain/greenfield-js-sdk/commit/865be476dfd78f86b9d0a7dba3074fbf7ae32bb7)
Thanks [@rrr523](https://github.com/rrr523)! - feat: Upgrade cosmos types to 0.4.0-alpha.30

## 1.2.0-alpha.2

### Patch Changes

- [#464](https://github.com/bnb-chain/greenfield-js-sdk/pull/464)
[`24ec472`](https://github.com/bnb-chain/greenfield-js-sdk/commit/24ec472b4507d0f3cba3c8fc55b4e9f924d5b1c7)
Thanks [@rrr523](https://github.com/rrr523)! - feat: Sp Api Types

## 1.2.0-alpha.1

### Patch Changes

- [`b41fdf0`](https://github.com/bnb-chain/greenfield-js-sdk/commit/b41fdf057b7b4b0f416a74fb04ed0793c52c51f7)
Thanks [@rrr523](https://github.com/rrr523)! - chore: pnpm --no-frozen-lockfile

## 1.2.0-alpha.0

### Minor Changes

- [#461](https://github.com/bnb-chain/greenfield-js-sdk/pull/461)
[`865be47`](https://github.com/bnb-chain/greenfield-js-sdk/commit/865be476dfd78f86b9d0a7dba3074fbf7ae32bb7)
Thanks [@rrr523](https://github.com/rrr523)! - feat: Add SetTag API

### Patch Changes

- [#461](https://github.com/bnb-chain/greenfield-js-sdk/pull/461)
[`865be47`](https://github.com/bnb-chain/greenfield-js-sdk/commit/865be476dfd78f86b9d0a7dba3074fbf7ae32bb7)
Thanks [@rrr523](https://github.com/rrr523)! - feat: Upgrade cosmos types to 0.4.0-alpha.30

## 1.1.3

### Patch Changes

- [#466](https://github.com/bnb-chain/greenfield-js-sdk/pull/466)
[`159cb9c`](https://github.com/bnb-chain/greenfield-js-sdk/commit/159cb9c896d3d44b92715b2c12a6db1aeed20081)
Thanks [@rrr523](https://github.com/rrr523)! - feat: Export Auth type

## 1.1.2

### Patch Changes
Expand Down
4 changes: 2 additions & 2 deletions 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.1.2",
"version": "1.2.0",
"description": "greenfield js chain and sp sdk",
"main": "./dist/cjs/index.js",
"module": "./dist/esm/index.js",
Expand Down Expand Up @@ -59,7 +59,7 @@
]
},
"dependencies": {
"@bnb-chain/greenfield-cosmos-types": "0.4.0-alpha.23",
"@bnb-chain/greenfield-cosmos-types": "0.4.0-alpha.30",
"@bnb-chain/greenfield-zk-crypto": "workspace:*",
"@cosmjs/proto-signing": "^0.32.0",
"@cosmjs/stargate": "^0.32.0",
Expand Down
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
Loading
Loading