Skip to content

Commit

Permalink
refactor (#236)
Browse files Browse the repository at this point in the history
* refactor: Tx

* fix: Type

* feat: Add Group API

* feat: Update Sp API

* feat: Bucket add authType

* feat:  and  add  params

* fix: Types

* feat: Change type
  • Loading branch information
rrr523 authored Aug 21, 2023
1 parent 53fa253 commit 41581f4
Show file tree
Hide file tree
Showing 26 changed files with 620 additions and 432 deletions.
5 changes: 5 additions & 0 deletions .changeset/brave-avocados-impress.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@bnb-chain/greenfield-js-sdk': patch
---

refactor: Tx
5 changes: 5 additions & 0 deletions .changeset/eighty-parrots-tap.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@bnb-chain/greenfield-js-sdk': patch
---

feat: Changet auth type: `OffChainAuth` -> `EDDSA`, `V1` -> `ECDSA`
5 changes: 5 additions & 0 deletions .changeset/itchy-candles-fold.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@bnb-chain/greenfield-js-sdk': patch
---

feat: Upgrade types and update SP API: `getQueryGlobalSpStorePriceByTime` `getQuerySpStoragePrice`
5 changes: 5 additions & 0 deletions .changeset/many-fans-decide.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@bnb-chain/greenfield-js-sdk': patch
---

feat: `getCreateBucketApproval` and `createBucket` add `authType` params
5 changes: 5 additions & 0 deletions .changeset/spicy-lizards-think.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@bnb-chain/greenfield-js-sdk': patch
---

feat: `getCreateObjectApproval` and `createObject` add `authType` params
5 changes: 5 additions & 0 deletions .changeset/strong-wombats-help.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@bnb-chain/greenfield-js-sdk': patch
---

feat: Group Exist API: `queryGroupMembersExist` `queryGroupExist` `queryGroupsExistById`
6 changes: 4 additions & 2 deletions examples/nextjs/src/client/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@ import { GREEN_CHAIN_ID, GRPC_URL } from '@/config';
import { Client } from '@bnb-chain/greenfield-js-sdk';

export const client = Client.create(GRPC_URL, String(GREEN_CHAIN_ID), {
zkCryptoUrl: 'https://dcellar.io/static/dcellar-web-ui/wasm/zk.wasm',
// zkCryptoUrl: 'https://dcellar.io/static/dcellar-web-ui/wasm/zk.wasm',
zkCryptoUrl:
'https://unpkg.com/@bnb-chain/greenfield-zk-crypto@0.0.2-alpha.4/dist/node/zk-crypto.wasm',
});

export const getSps = async () => {
const sps = await client.sp.getStorageProviders();
const finalSps = (sps ?? []).filter((v: any) => v.endpoint.includes('https'));
const finalSps = (sps ?? []).filter((v: any) => v.endpoint.includes('nodereal'));

return finalSps;
};
Expand Down
29 changes: 18 additions & 11 deletions examples/nextjs/src/components/bucket/create/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { client, selectSp } from '@/client';
import { ACCOUNT_PRIVATEKEY } from '@/config/env';
import { getOffchainAuthKeys } from '@/utils/offchainAuth';
import { useState } from 'react';
import { useAccount } from 'wagmi';
Expand Down Expand Up @@ -37,18 +38,24 @@ export const CreateBucket = () => {
return;
}

const createBucketTx = await client.bucket.createBucket({
bucketName: createBucketInfo.bucketName,
creator: address,
visibility: 'VISIBILITY_TYPE_PUBLIC_READ',
chargedReadQuota: '0',
spInfo: {
primarySpAddress: spInfo.primarySpAddress,
const createBucketTx = await client.bucket.createBucket(
{
bucketName: createBucketInfo.bucketName,
creator: address,
visibility: 'VISIBILITY_TYPE_PUBLIC_READ',
chargedReadQuota: '0',
spInfo: {
primarySpAddress: spInfo.primarySpAddress,
},
},
signType: 'offChainAuth',
domain: window.location.origin,
seedString: offChainData.seedString,
});
{
// type: 'ECDSA',
// privateKey: ACCOUNT_PRIVATEKEY,
type: 'EDDSA',
domain: window.location.origin,
seed: offChainData.seedString,
},
);

const simulateInfo = await createBucketTx.simulate({
denom: 'BNB',
Expand Down
37 changes: 22 additions & 15 deletions examples/nextjs/src/components/object/create/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { client } from '@/client';
import { ACCOUNT_PRIVATEKEY } from '@/config/env';
import { getOffchainAuthKeys } from '@/utils/offchainAuth';
import { ChangeEvent, useState } from 'react';
import { useAccount } from 'wagmi';
Expand Down Expand Up @@ -67,19 +68,25 @@ export const CreateObject = () => {
console.log('offChainData', offChainData);
console.log('hashResult', hashResult);

const createObjectTx = await client.object.createObject({
bucketName: createObjectInfo.bucketName,
objectName: createObjectInfo.objectName,
creator: address,
visibility: 'VISIBILITY_TYPE_PUBLIC_READ',
fileType: file.type,
redundancyType: 'REDUNDANCY_EC_TYPE',
contentLength,
expectCheckSums: JSON.parse(expectCheckSums),
signType: 'offChainAuth',
domain: window.location.origin,
seedString: offChainData.seedString,
});
const createObjectTx = await client.object.createObject(
{
bucketName: createObjectInfo.bucketName,
objectName: createObjectInfo.objectName,
creator: address,
visibility: 'VISIBILITY_TYPE_PUBLIC_READ',
fileType: file.type,
redundancyType: 'REDUNDANCY_EC_TYPE',
contentLength,
expectCheckSums: JSON.parse(expectCheckSums),
},
{
type: 'EDDSA',
domain: window.location.origin,
seed: offChainData.seedString,
// type: 'ECDSA',
// privateKey: ACCOUNT_PRIVATEKEY,
},
);

const simulateInfo = await createObjectTx.simulate({
denom: 'BNB',
Expand Down Expand Up @@ -157,9 +164,9 @@ export const CreateObject = () => {
creator: address,
},
{
signType: 'offChainAuth',
type: 'EDDSA',
domain: window.location.origin,
seedString: offChainData.seedString,
seed: offChainData.seedString,
},
);

Expand Down
4 changes: 2 additions & 2 deletions examples/nextjs/src/pages/_document.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ export default function Document() {
<Main />
<NextScript />
</body>
<script src="http://localhost:9001/dist/browser/umd/index.js"></script>
<script src="https://unpkg.com/@bnb-chain/greenfiled-file-handle@0.2.1-alpha.0/dist/browser/umd/index.js"></script>
<script
dangerouslySetInnerHTML={{
__html: `window.__PUBLIC_FILE_HANDLE_WASM_PATH__ = 'https://unpkg.com/@bnb-chain/greenfiled-file-handle@0.2.1/dist/node/file-handle.wasm'`,
__html: `window.__PUBLIC_FILE_HANDLE_WASM_PATH__ = 'https://unpkg.com/@bnb-chain/greenfiled-file-handle@0.2.1-alpha.0/dist/node/file-handle.wasm'`,
}}
></script>
</Html>
Expand Down
55 changes: 35 additions & 20 deletions examples/nodejs/index.js
Original file line number Diff line number Diff line change
@@ -1,28 +1,43 @@
const { Client } = require('@bnb-chain/greenfield-js-sdk');
const { getCheckSums } = require('@bnb-chain/greenfiled-file-handle/files');
const fs = require('fs');
// const { getCheckSums } = require('@bnb-chain/greenfiled-file-handle/files');
// const fs = require('fs');

// const client = Client.create('https://gnfd-dev.qa.bnbchain.world', '8981');

const client = Client.create('https://gnfd.qa.bnbchain.world', '9000');

// (async () => {
// const filePath = './package.json';
// const fileBuf = fs.readFileSync(filePath);
// const DEFAULT_SEGMENT_SIZE = 16 * 1024 * 1024;
// const DEFAULT_DATA_BLOCKS = 4;
// const DEFAULT_PARITY_BLOCKS = 2;
// const bytes = new Uint8Array(fileBuf);
(async () => {
const createBucketTx = await client.bucket.createBucket({
bucketName: 'foo',
creator: '0x1C893441AB6c1A75E01887087ea508bE8e07AAae',
visibility: 'VISIBILITY_TYPE_PUBLIC_READ',
chargedReadQuota: '0',
spInfo: {
primarySpAddress: '0x66d06FFe266B46C6F0730cC9Ec2fc5B811cdA085',
},
signType: 'authTypeV1',
privateKey: '0x6547492644d0136f76ef65e3bd04a77d079ed38028f747700c6c6063564d7032',
// signType: 'offChainAuth',
// domain: window.location.origin,
// seedString: offChainData.seedString,
});

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

// const hashResult = await getCheckSums(
// Buffer.from(bytes).toString('hex'),
// DEFAULT_SEGMENT_SIZE,
// DEFAULT_DATA_BLOCKS,
// DEFAULT_PARITY_BLOCKS,
// );
// console.log('hashResult', hashResult);
// })();
console.log('simulateInfo', simulateInfo);

(async () => {
const account = await client.account.getAccount('0x1C893441AB6c1A75E01887087ea508bE8e07AAae');
const res = await createBucketTx.broadcast({
denom: 'BNB',
gasLimit: Number(simulateInfo?.gasLimit),
gasPrice: simulateInfo?.gasPrice || '5000000000',
payer: '0x1C893441AB6c1A75E01887087ea508bE8e07AAae',
granter: '',
privateKey: '0x6547492644d0136f76ef65e3bd04a77d079ed38028f747700c6c6063564d7032',
});

console.log(account);
if (res.code === 0) {
console.log('success');
}
})();
3 changes: 2 additions & 1 deletion packages/chain-sdk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@
]
},
"dependencies": {
"@bnb-chain/greenfield-cosmos-types": "0.4.0-alpha.22",
"@bnb-chain/greenfield-zk-crypto": "workspace:*",
"@bnb-chain/greenfield-cosmos-types": "0.4.0-alpha.21",
"@cosmjs/proto-signing": "^0.30.1",
"@cosmjs/stargate": "^0.30.1",
"@cosmjs/tendermint-rpc": "^0.30.1",
Expand All @@ -67,6 +67,7 @@
"dayjs": "^1.11.7",
"dotenv": "^16.0.3",
"ethereum-cryptography": "^2.0.0",
"fast-xml-parser": "^4.2.7",
"lodash.clonedeep": "^4.5.0",
"lodash.mapvalues": "^4.6.0",
"lodash.sortby": "^4.7.0",
Expand Down
Loading

0 comments on commit 41581f4

Please sign in to comment.