Skip to content

Commit

Permalink
TS SDK 1.0 (#16735)
Browse files Browse the repository at this point in the history
## Description 

Describe the changes or additions included in this PR.

## Test Plan 

How did you test the new or updated feature?

---
If your changes are not user-facing and do not break anything, you can
skip the following section. Otherwise, please briefly describe what has
changed under the Release Notes section.

### Type of Change (Check all that apply)

- [ ] protocol change
- [ ] user-visible impact
- [ ] breaking change for a client SDKs
- [ ] breaking change for FNs (FN binary must upgrade)
- [ ] breaking change for validators or node operators (must upgrade
binaries)
- [ ] breaking change for on-chain data layout
- [ ] necessitate either a data wipe or data migration

### Release notes
  • Loading branch information
hayes-mysten authored May 29, 2024
1 parent a1ce332 commit a92b03d
Show file tree
Hide file tree
Showing 559 changed files with 15,531 additions and 17,470 deletions.
2 changes: 1 addition & 1 deletion .changeset/bright-wombats-try.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
'@mysten/sui.js': patch
'@mysten/sui': patch
---

Add support for more JSON RPC error codes
18 changes: 18 additions & 0 deletions .changeset/witty-llamas-smile.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
---
'@mysten/sui': major
'@mysten/bcs': major
'@mysten/ledgerjs-hw-app-sui': minor
'@mysten/graphql-transport': minor
'@mysten/wallet-standard': minor
'@mysten/suins-toolkit': minor
'@mysten/create-dapp': minor
'@mysten/dapp-kit': minor
'@mysten/deepbook': minor
'@mysten/zklogin': minor
'@mysten/zksend': minor
'@mysten/enoki': minor
'@mysten/kiosk': minor
---

The Typescript SDK has been renamed to `@mysten/sui` and includes many new features and breaking changes.
See the [full migration guide](https://sdk.mystenlabs.com/typescript/migrations/sui-1.0) for details on how to upgrade.
2 changes: 1 addition & 1 deletion .github/actions/ts-e2e/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,5 +64,5 @@ runs:
shell: bash

- name: Run TS SDK e2e tests
run: pnpm dlx concurrently --kill-others --success command-1 "$E2E_RUN_LOCAL_NET_CMD" 'pnpm --filter @mysten/sui.js --filter @mysten/graphql-transport test:e2e'
run: pnpm dlx concurrently --kill-others --success command-1 "$E2E_RUN_LOCAL_NET_CMD" 'pnpm --filter @mysten/sui --filter @mysten/graphql-transport test:e2e'
shell: bash
4 changes: 2 additions & 2 deletions .github/workflows/e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:
runs-on: ubuntu-latest
outputs:
isWallet: ${{ (steps.turbo.outputs.packages && contains(fromJson(steps.turbo.outputs.packages), 'sui-wallet')) }}
isTypescriptSDK: ${{ (steps.turbo.outputs.packages && contains(fromJson(steps.turbo.outputs.packages), '@mysten/sui.js')) }}
isTypescriptSDK: ${{ (steps.turbo.outputs.packages && contains(fromJson(steps.turbo.outputs.packages), '@mysten/sui')) }}
isGraphQlTransport: ${{ (steps.turbo.outputs.packages && contains(fromJson(steps.turbo.outputs.packages), '@mysten/graphql-transport')) }}
isRust: ${{ steps.diff.outputs.isRust }}
steps:
Expand Down Expand Up @@ -66,7 +66,7 @@ jobs:
- name: Run TS SDK e2e tests
if: ${{ needs.diff.outputs.isTypescriptSDK == 'true' || needs.diff.outputs.isRust == 'true'}}
run: pnpm dlx concurrently --kill-others --success command-1 "$E2E_RUN_LOCAL_NET_CMD" 'pnpm --filter @mysten/sui.js test:e2e'
run: pnpm dlx concurrently --kill-others --success command-1 "$E2E_RUN_LOCAL_NET_CMD" 'pnpm --filter @mysten/sui test:e2e'

- name: Run RPC/GrpahQL comaptability e2e tests
if: ${{ needs.diff.outputs.isGraphQlTransport == 'true' || needs.diff.outputs.isRust == 'true'}}
Expand Down
4 changes: 2 additions & 2 deletions apps/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"@hookform/resolvers": "^3.1.1",
"@mysten/dapp-kit": "workspace:*",
"@mysten/kiosk": "workspace:*",
"@mysten/sui.js": "workspace:*",
"@mysten/sui": "workspace:*",
"@sentry/react": "^7.59.2",
"@tanstack/react-query": "^5.0.0",
"bignumber.js": "^9.1.1",
Expand All @@ -48,6 +48,6 @@
"tailwindcss": "^3.3.3",
"typescript": "^5.3.3",
"vite": "^4.4.4",
"vitest": "^0.33.0"
"vitest": "^1.6.0"
}
}
2 changes: 1 addition & 1 deletion apps/core/src/api/SentryHttpTransport.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0

import { SuiHTTPTransport } from '@mysten/sui.js/client';
import { SuiHTTPTransport } from '@mysten/sui/client';
import * as Sentry from '@sentry/react';

const IGNORED_METHODS = ['suix_resolveNameServiceNames', 'suix_resolveNameServiceAddresses'];
Expand Down
4 changes: 2 additions & 2 deletions apps/core/src/hooks/useFormatCoin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
// SPDX-License-Identifier: Apache-2.0

import { useSuiClient } from '@mysten/dapp-kit';
import { CoinMetadata } from '@mysten/sui.js/client';
import { SUI_TYPE_ARG } from '@mysten/sui.js/utils';
import { CoinMetadata } from '@mysten/sui/client';
import { SUI_TYPE_ARG } from '@mysten/sui/utils';
import { useQuery, type UseQueryResult } from '@tanstack/react-query';
import BigNumber from 'bignumber.js';
import { useMemo } from 'react';
Expand Down
2 changes: 1 addition & 1 deletion apps/core/src/hooks/useGetCoins.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// SPDX-License-Identifier: Apache-2.0

import { useSuiClient } from '@mysten/dapp-kit';
import { PaginatedCoins } from '@mysten/sui.js/client';
import { PaginatedCoins } from '@mysten/sui/client';
import { useInfiniteQuery } from '@tanstack/react-query';

const MAX_COINS_PER_REQUEST = 10;
Expand Down
2 changes: 1 addition & 1 deletion apps/core/src/hooks/useGetDelegatedStake.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// SPDX-License-Identifier: Apache-2.0

import { useSuiClient } from '@mysten/dapp-kit';
import type { DelegatedStake } from '@mysten/sui.js/client';
import type { DelegatedStake } from '@mysten/sui/client';
import { useQuery, type UseQueryOptions } from '@tanstack/react-query';

type UseGetDelegatedStakesOptions = {
Expand Down
4 changes: 2 additions & 2 deletions apps/core/src/hooks/useGetDynamicFields.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
// SPDX-License-Identifier: Apache-2.0

import { useSuiClient } from '@mysten/dapp-kit';
import { DynamicFieldPage } from '@mysten/sui.js/client';
import { normalizeSuiAddress } from '@mysten/sui.js/utils';
import { DynamicFieldPage } from '@mysten/sui/client';
import { normalizeSuiAddress } from '@mysten/sui/utils';
import { useInfiniteQuery } from '@tanstack/react-query';

const MAX_PAGE_SIZE = 10;
Expand Down
2 changes: 1 addition & 1 deletion apps/core/src/hooks/useGetKioskContents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import { useSuiClientContext } from '@mysten/dapp-kit';
import { KIOSK_ITEM, KioskClient, KioskItem, KioskOwnerCap } from '@mysten/kiosk';
import { SuiClient } from '@mysten/sui.js/client';
import { SuiClient } from '@mysten/sui/client';
import { useQuery } from '@tanstack/react-query';

import { getKioskIdFromOwnerCap, ORIGINBYTE_KIOSK_OWNER_TOKEN } from '../utils/kiosk';
Expand Down
2 changes: 1 addition & 1 deletion apps/core/src/hooks/useGetObject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// SPDX-License-Identifier: Apache-2.0

import { useSuiClient } from '@mysten/dapp-kit';
import { normalizeSuiAddress } from '@mysten/sui.js/utils';
import { normalizeSuiAddress } from '@mysten/sui/utils';
import { useQuery } from '@tanstack/react-query';

const defaultOptions = {
Expand Down
2 changes: 1 addition & 1 deletion apps/core/src/hooks/useGetOwnedObjects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// SPDX-License-Identifier: Apache-2.0

import { useSuiClient } from '@mysten/dapp-kit';
import { PaginatedObjectsResponse, type SuiObjectDataFilter } from '@mysten/sui.js/client';
import { PaginatedObjectsResponse, type SuiObjectDataFilter } from '@mysten/sui/client';
import { useInfiniteQuery } from '@tanstack/react-query';

const MAX_OBJECTS_PER_REQ = 6;
Expand Down
4 changes: 2 additions & 2 deletions apps/core/src/hooks/useGetTransferAmount.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0
import { SuiTransactionBlockResponse } from '@mysten/sui.js/client';
import { SUI_TYPE_ARG } from '@mysten/sui.js/utils';
import { SuiTransactionBlockResponse } from '@mysten/sui/client';
import { SUI_TYPE_ARG } from '@mysten/sui/utils';
import { useMemo } from 'react';

import { getTotalGasUsed } from '../utils/transaction';
Expand Down
2 changes: 1 addition & 1 deletion apps/core/src/hooks/useGetValidatorsEvents.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0
import { useSuiClient } from '@mysten/dapp-kit';
import { SuiEvent, type EventId } from '@mysten/sui.js/client';
import { SuiEvent, type EventId } from '@mysten/sui/client';
import { useQuery } from '@tanstack/react-query';

type GetValidatorsEvent = {
Expand Down
2 changes: 1 addition & 1 deletion apps/core/src/hooks/useMultiGetObjects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// SPDX-License-Identifier: Apache-2.0

import { useSuiClient } from '@mysten/dapp-kit';
import { SuiObjectDataOptions, SuiObjectResponse } from '@mysten/sui.js/client';
import { SuiObjectDataOptions, SuiObjectResponse } from '@mysten/sui/client';
import { useQuery, UseQueryOptions } from '@tanstack/react-query';

import { chunkArray } from '../utils/chunkArray';
Expand Down
2 changes: 1 addition & 1 deletion apps/core/src/hooks/useTransactionSummary.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import {
DryRunTransactionBlockResponse,
type SuiTransactionBlockResponse,
} from '@mysten/sui.js/client';
} from '@mysten/sui/client';
import { useMemo } from 'react';

import { getBalanceChangeSummary } from '../utils/transaction/getBalanceChangeSummary';
Expand Down
2 changes: 1 addition & 1 deletion apps/core/src/utils/getRefGasPrice.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0

import { SuiValidatorSummary } from '@mysten/sui.js/client';
import { SuiValidatorSummary } from '@mysten/sui/client';

import { calculateStakeShare } from './calculateStakeShare';

Expand Down
2 changes: 1 addition & 1 deletion apps/core/src/utils/hasDisplayData.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Copyright (c) Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0

import { SuiObjectResponse } from '@mysten/sui.js/client';
import { SuiObjectResponse } from '@mysten/sui/client';

export const hasDisplayData = (obj: SuiObjectResponse) => !!obj.data?.display?.data;
2 changes: 1 addition & 1 deletion apps/core/src/utils/kiosk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// SPDX-License-Identifier: Apache-2.0

import { KIOSK_OWNER_CAP, Network, PERSONAL_KIOSK_RULE_ADDRESS } from '@mysten/kiosk';
import { SuiObjectData, SuiObjectResponse } from '@mysten/sui.js/client';
import { SuiObjectData, SuiObjectResponse } from '@mysten/sui/client';

export const ORIGINBYTE_KIOSK_MODULE =
'0x95a441d389b07437d00dd07e0b6f05f513d7659b13fd7c5d3923c7d9d847199b::ob_kiosk';
Expand Down
4 changes: 2 additions & 2 deletions apps/core/src/utils/transaction/getBalanceChangeSummary.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import {
type DryRunTransactionBlockResponse,
type ObjectOwner,
type SuiTransactionBlockResponse,
} from '@mysten/sui.js/client';
import { normalizeSuiObjectId, parseStructTag } from '@mysten/sui.js/utils';
} from '@mysten/sui/client';
import { normalizeSuiObjectId, parseStructTag } from '@mysten/sui/utils';

export type BalanceChange = {
coinType: string;
Expand Down
2 changes: 1 addition & 1 deletion apps/core/src/utils/transaction/getGasSummary.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
SuiGasData,
SuiTransactionBlockResponse,
TransactionEffects,
} from '@mysten/sui.js/client';
} from '@mysten/sui/client';

type Optional<T> = {
[K in keyof T]?: T[K];
Expand Down
2 changes: 1 addition & 1 deletion apps/core/src/utils/transaction/getLabel.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Copyright (c) Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0
import { SuiTransactionBlockResponse } from '@mysten/sui.js/client';
import { SuiTransactionBlockResponse } from '@mysten/sui/client';

// todo: add more logic for deriving transaction label
export const getLabel = (transaction: SuiTransactionBlockResponse, currentAddress?: string) => {
Expand Down
2 changes: 1 addition & 1 deletion apps/core/src/utils/transaction/getObjectChangeSummary.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
SuiObjectChangePublished,
SuiObjectChangeTransferred,
SuiObjectChangeWrapped,
} from '@mysten/sui.js/client';
} from '@mysten/sui/client';

import { groupByOwner } from './groupByOwner';
import { SuiObjectChangeTypes } from './types';
Expand Down
2 changes: 1 addition & 1 deletion apps/core/src/utils/transaction/getObjectDisplayLookup.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Copyright (c) Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0
import { DisplayFieldsResponse, SuiObjectResponse } from '@mysten/sui.js/client';
import { DisplayFieldsResponse, SuiObjectResponse } from '@mysten/sui/client';

import { hasDisplayData } from '../hasDisplayData';

Expand Down
2 changes: 1 addition & 1 deletion apps/core/src/utils/transaction/getOwnerType.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0

import type { SuiObjectChange } from '@mysten/sui.js/client';
import type { SuiObjectChange } from '@mysten/sui/client';

export const getOwnerType = (change: SuiObjectChange) => {
if (!('owner' in change)) return '';
Expand Down
4 changes: 2 additions & 2 deletions apps/wallet/configs/ts/tsconfig.common.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@
"_values/*": ["./src/ui/styles/values/*"],
"_utils": ["./src/ui/styles/utils"],
"_utils/*": ["./src/ui/styles/utils/*"],
"@mysten/sui.js/*": ["../../sdk/typescript/src/*"],
"@mysten/sui.js": ["../../sdk/typescript/src/"],
"@mysten/sui/*": ["../../sdk/typescript/src/*"],
"@mysten/sui": ["../../sdk/typescript/src/"],
"@mysten/kiosk": ["../../sdk/kiosk/src/index.ts"],
"@mysten/bcs": ["../../sdk/bcs/src/"],
"@mysten/dapp-kit": ["../../sdk/dapp-kit/src/"],
Expand Down
2 changes: 1 addition & 1 deletion apps/wallet/configs/webpack/webpack.config.common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ const commonConfig: () => Promise<Configuration> = async () => {
},
resolve: {
extensions: ['.ts', '.tsx', '.js'],
// Fix .js imports from @mysten/sui.js since we are importing it from source
// Fix .js imports from @mysten/sui since we are importing it from source
extensionAlias: {
'.js': ['.js', '.ts', '.tsx', '.jsx'],
'.mjs': ['.mjs', '.mts'],
Expand Down
6 changes: 3 additions & 3 deletions apps/wallet/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
"dotenv-webpack": "^8.0.0",
"eslint-webpack-plugin": "^4.0.1",
"git-rev-sync": "^3.0.2",
"happy-dom": "^10.5.1",
"happy-dom": "^14.11.0",
"html-webpack-plugin": "^5.5.3",
"mini-css-extract-plugin": "^2.7.6",
"onchange": "^7.1.0",
Expand All @@ -95,7 +95,7 @@
"typescript": "^5.3.3",
"vite": "^4.4.4",
"vite-tsconfig-paths": "^4.2.0",
"vitest": "^0.33.0",
"vitest": "^1.6.0",
"web-ext": "^7.6.2",
"webpack": "^5.79.0",
"webpack-cli": "^5.0.1",
Expand All @@ -120,7 +120,7 @@
"@mysten/icons": "workspace:*",
"@mysten/kiosk": "workspace:*",
"@mysten/ledgerjs-hw-app-sui": "workspace:*",
"@mysten/sui.js": "workspace:*",
"@mysten/sui": "workspace:*",
"@mysten/wallet-standard": "workspace:*",
"@mysten/zklogin": "workspace:*",
"@noble/hashes": "^1.3.1",
Expand Down
2 changes: 1 addition & 1 deletion apps/wallet/src/background/Transactions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { type SignMessageRequest } from '_payloads/transactions/SignMessage';
import type { TransactionRequestResponse } from '_payloads/transactions/ui/TransactionRequestResponse';
import type { ContentScriptConnection } from '_src/background/connections/ContentScriptConnection';
import { type SignedTransaction } from '_src/ui/app/WalletSigner';
import { type SuiTransactionBlockResponse } from '@mysten/sui.js/client';
import { type SuiTransactionBlockResponse } from '@mysten/sui/client';
import { type SuiSignMessageOutput } from '@mysten/wallet-standard';
import { filter, lastValueFrom, map, race, Subject, take } from 'rxjs';
import { v4 as uuidV4 } from 'uuid';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import {
validateEntropy,
} from '_shared/utils/bip39';
import { decrypt, encrypt } from '_src/shared/cryptography/keystore';
import { mnemonicToSeedHex } from '@mysten/sui.js/cryptography';
import { Ed25519Keypair } from '@mysten/sui.js/keypairs/ed25519';
import { mnemonicToSeedHex } from '@mysten/sui/cryptography';
import { Ed25519Keypair } from '@mysten/sui/keypairs/ed25519';
import { sha256 } from '@noble/hashes/sha256';
import { bytesToHex } from '@noble/hashes/utils';
import Dexie from 'dexie';
Expand Down
12 changes: 4 additions & 8 deletions apps/wallet/src/background/accounts/Account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,7 @@
// SPDX-License-Identifier: Apache-2.0

import { type Serializable } from '_src/shared/cryptography/keystore';
import {
toSerializedSignature,
type Keypair,
type SerializedSignature,
} from '@mysten/sui.js/cryptography';
import { toSerializedSignature, type Keypair } from '@mysten/sui/cryptography';
import { blake2b } from '@noble/hashes/blake2b';

import { setupAutoLockAlarm } from '../auto-lock-accounts';
Expand Down Expand Up @@ -71,10 +67,10 @@ export abstract class Account<
return data as T;
}

protected generateSignature(data: Uint8Array, keyPair: Keypair) {
protected async generateSignature(data: Uint8Array, keyPair: Keypair) {
const digest = blake2b(data, { dkLen: 32 });
const pubkey = keyPair.getPublicKey();
const signature = keyPair.signData(digest);
const signature = await keyPair.sign(digest);
const signatureScheme = keyPair.getKeyScheme();
return toSerializedSignature({
signature,
Expand Down Expand Up @@ -176,7 +172,7 @@ export function isPasswordUnLockable(account: unknown): account is PasswordUnloc

export interface SigningAccount {
readonly canSign: true;
signData(data: Uint8Array): Promise<SerializedSignature>;
signData(data: Uint8Array): Promise<string>;
}

export function isSigningAccount(account: any): account is SigningAccount {
Expand Down
2 changes: 1 addition & 1 deletion apps/wallet/src/background/accounts/MnemonicAccount.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// SPDX-License-Identifier: Apache-2.0

import { fromExportedKeypair } from '_src/shared/utils/from-exported-keypair';
import { type Keypair } from '@mysten/sui.js/cryptography';
import { type Keypair } from '@mysten/sui/cryptography';

import { MnemonicAccountSource } from '../account-sources/MnemonicAccountSource';
import {
Expand Down
2 changes: 1 addition & 1 deletion apps/wallet/src/background/accounts/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
type MethodPayload,
} from '_src/shared/messaging/messages/payloads/MethodPayload';
import { type WalletStatusChange } from '_src/shared/messaging/messages/payloads/wallet-status-change';
import { fromB64 } from '@mysten/sui.js/utils';
import { fromB64 } from '@mysten/sui/utils';
import Dexie from 'dexie';

import { getAccountSourceByID } from '../account-sources';
Expand Down
Loading

0 comments on commit a92b03d

Please sign in to comment.