Skip to content

Commit

Permalink
bump sui sdk version (#193)
Browse files Browse the repository at this point in the history
* bump sui sdk version

* remove commented out code

* fix

* fix docs

* bump major
  • Loading branch information
LukassF authored Jul 26, 2024
1 parent 96390e3 commit 175b2d3
Show file tree
Hide file tree
Showing 16 changed files with 493 additions and 185 deletions.
12 changes: 3 additions & 9 deletions sdk/apps/docs/docs/for_wallets/sign_message.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,27 +32,21 @@ client.on('signMessages', async (e) => {
<TabItem value="SUI" label="SUI">

```js
import {
fromB64,
IntentScope,
messageWithIntent,
toB64,
toSerializedSignature
} from '@mysten/sui.js'
import { fromB64, messageWithIntent, toB64, toSerializedSignature } from '@mysten/sui'
import { blake2b } from '@noble/hashes/blake2b'

client.on('signMessages', async (e) => {
const msg = e.messages[0].message
const msgTo64 = toB64(new TextEncoder().encode(msg))
const intentMessage = messageWithIntent(IntentScope.PersonalMessage, fromB64(msgTo64))
const intentMessage = messageWithIntent('PersonalMessage', fromB64(msgTo64))
const digest = blake2b(intentMessage, { dkLen: 32 })
const signature = alice_keypair.signData(digest)
const signedMessage = {
messageBytes: msg,
signature: toSerializedSignature({
signature,
signatureScheme: 'ED25519',
pubKey: alice_keypair.getPublicKey()
publicKey: alice_keypair.getPublicKey()
})
}
// resolve
Expand Down
8 changes: 4 additions & 4 deletions sdk/apps/docs/docs/for_wallets/sign_transaction.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ import {
messageWithIntent,
toB64,
toSerializedSignature,
TransactionBlock,
} from '@mysten/sui.js'
Transaction,
} from '@mysten/sui'
import { blake2b } from '@noble/hashes/blake2b'

interface SignSuiTransactionEvent {
Expand All @@ -62,8 +62,8 @@ const alice_keypair: Ed25519Keypair = Ed25519Keypair.fromSecretKey(hexToBytes(A

client.on('signTransactions', async (e) => {
const tx = e.transactions[0].transaction
const transactionBlockBytes = await TransactionBlock.from(tx).build({
provider: suiConnection,
const transactionBlockBytes = await Transaction.from(tx).build({
client: suiConnection,
onlyTransactionKind: true
})

Expand Down
10 changes: 5 additions & 5 deletions sdk/apps/docs/docs/sui/sign_transaction.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ Sending a signTransaction requires established connection with user wallet.
Transaction are sent to the client via wallet interface. Client can accept or reject the request. Once client signs transaction, `signTransactionBlock()` method returns resolved promise with Signed Transaction.

```js
import { TransactionBlock } from '@mysten/sui.js'
import { Transaction } from '@mysten/sui'

const tx = new TransactionBlock()
const coin = tx.splitCoins(tx.gas, [tx.pure(100)])
tx.transferObjects([coin], tx.pure(RECEIVER_SUI_ADDRESS))
const tx = new Transaction()
const coin = tx.splitCoins(tx.gas, [tx.pure.u64(100)])
tx.transferObjects([coin], tx.pure.address(RECEIVER_SUI_ADDRESS))
tx.setSenderIfNotSet(RECEIVER_SUI_ADDRESS)

const signedTx: SignedTransaction = await app.signTransactionBlock({
transactionBlock: tx, // TransactionBlock
transactionBlock: tx, // Transaction
account: aliceWalletAccount, // WalletAccount
chain: 'sui:testnet' // IdentifierString
})
Expand Down
7 changes: 3 additions & 4 deletions sdk/apps/modal-example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,15 @@
"dependencies": {
"@aptos-labs/ts-sdk": "^1.9.1",
"@aptos-labs/wallet-standard": "^0.0.11",
"@mysten/sui.js": "^0.42.0",
"@mysten/wallet-adapter-wallet-standard": "^0.8.0",
"@mysten/sui": "^1.2.1",
"@nightlylabs/nightly-connect-polkadot": "0.0.16",
"@nightlylabs/nightly-connect-solana": "0.0.29",
"@nightlylabs/nightly-connect-sui": "0.0.29",
"@nightlylabs/nightly-connect-sui": "0.1.0",
"@nightlylabs/wallet-selector-aptos": "0.1.6",
"@nightlylabs/wallet-selector-base": "^0.4.1",
"@nightlylabs/wallet-selector-polkadot": "0.2.7",
"@nightlylabs/wallet-selector-solana": "0.3.2",
"@nightlylabs/wallet-selector-sui": "0.3.2",
"@nightlylabs/wallet-selector-sui": "0.4.0",
"@polkadot/api": "^10.10.1",
"@polkadot/extension-inject": "^0.46.5",
"@solana/web3.js": "^1.77.2",
Expand Down
133 changes: 64 additions & 69 deletions sdk/apps/modal-example/src/routes/sui.tsx
Original file line number Diff line number Diff line change
@@ -1,62 +1,62 @@
import { createEffect, createSignal, onMount, Show } from "solid-js";
import { Title } from "@solidjs/meta";
import { NightlyConnectSuiAdapter } from "@nightlylabs/wallet-selector-sui";
import { TransactionBlock } from "@mysten/sui.js/transactions";
import toast from "solid-toast";
import { createEffect, createSignal, onMount, Show } from 'solid-js'
import { Title } from '@solidjs/meta'
import { NightlyConnectSuiAdapter } from '@nightlylabs/wallet-selector-sui'
import { Transaction } from '@mysten/sui/transactions'
import toast from 'solid-toast'

export default function Sui() {
const [adapter, setAdapter] = createSignal<NightlyConnectSuiAdapter>();
const [eager, setEager] = createSignal(false);
const [publicKey, setPublicKey] = createSignal<string>();
const [adapter, setAdapter] = createSignal<NightlyConnectSuiAdapter>()
const [eager, setEager] = createSignal(false)
const [publicKey, setPublicKey] = createSignal<string>()
onMount(async () => {
NightlyConnectSuiAdapter.build(
{
appMetadata: {
name: "NCTestSui",
description: "Nightly Connect Test",
icon: "https://docs.nightly.app/img/logo.png",
additionalInfo: "Courtesy of Nightly Connect team",
},
name: 'NCTestSui',
description: 'Nightly Connect Test',
icon: 'https://docs.nightly.app/img/logo.png',
additionalInfo: 'Courtesy of Nightly Connect team'
}
},
{},
document.getElementById("modalAnchor")
document.getElementById('modalAnchor')
).then(async (adapter) => {
adapter.canEagerConnect().then((canEagerConnect) => {
setEager(canEagerConnect);
});
setEager(canEagerConnect)
})

adapter.on("connect", (accounts) => {
setPublicKey(accounts[0].address);
});
adapter.on('connect', (accounts) => {
setPublicKey(accounts[0].address)
})

adapter.on("disconnect", () => {
setPublicKey(undefined);
console.log("adapter disconnected");
});
adapter.on('disconnect', () => {
setPublicKey(undefined)
console.log('adapter disconnected')
})

adapter.on("change", (a) => {
adapter.on('change', (a) => {
if (!!a.accounts?.length && a.accounts[0].address) {
setPublicKey(a.accounts[0].address);
setPublicKey(a.accounts[0].address)
}
});
})

setAdapter(adapter);
});
});
setAdapter(adapter)
})
})
createEffect(() => {
if (eager()) {
adapter()
?.connect()
.then(
() => {
console.log("connect resolved successfully");
console.log('connect resolved successfully')
},
() => {
console.log("connect rejected");
console.log('connect rejected')
}
);
)
}
});
})

return (
<main>
Expand All @@ -71,75 +71,70 @@ export default function Sui() {
?.connect()
.then(
() => {
console.log("connect resolved successfully");
console.log('connect resolved successfully')
},
() => {
console.log("connect rejected");
console.log('connect rejected')
}
);
}}
>
)
}}>
Connect
</button>
}
>
}>
<h1>Current address: {publicKey()}</h1>
<button
onClick={async () => {
try {
const transactionBlock = new TransactionBlock();
const transactionBlock = new Transaction()
const coin = transactionBlock.splitCoins(transactionBlock.gas, [
transactionBlock.pure(50000000),
]);
transactionBlock.pure.u64(50000000)
])
transactionBlock.transferObjects(
[coin],
transactionBlock.pure(
"0xd85c7ad90905e0bd49b72420deb5f4077cab62840fb3917ca2945e41d8854013"
transactionBlock.pure.address(
'0xd85c7ad90905e0bd49b72420deb5f4077cab62840fb3917ca2945e41d8854013'
)
);
const accounts = await adapter()!.getAccounts();
)
const accounts = await adapter()!.getAccounts()
await adapter()!.signAndExecuteTransactionBlock({
transactionBlock,
chain: "sui:testnet",
account: accounts[0],
});
chain: 'sui:testnet',
account: accounts[0]
})

toast.success("Transaction was signed and sent!");
toast.success('Transaction was signed and sent!')
} catch (e) {
toast.error("Error: couldn't sign and send transaction!");
console.log(e);
toast.error("Error: couldn't sign and send transaction!")
console.log(e)
}
}}
>
}}>
Send 0.05 SUI
</button>
<button
onClick={async () => {
try {
const accounts = await adapter()!.getAccounts();
const accounts = await adapter()!.getAccounts()
await adapter()!.signPersonalMessage!({
message: new TextEncoder().encode("I love Nightly"),
account: accounts[0],
});
message: new TextEncoder().encode('I love Nightly'),
account: accounts[0]
})

toast.success("Message was signed!");
toast.success('Message was signed!')
} catch (e) {
toast.error("Error: couldn't sign message!");
console.log(e);
toast.error("Error: couldn't sign message!")
console.log(e)
}
}}
>
}}>
Sign message
</button>
<button
onClick={() => {
adapter()?.disconnect();
setPublicKey(undefined);
}}
>
adapter()?.disconnect()
setPublicKey(undefined)
}}>
Disconnect
</button>
</Show>
</main>
);
)
}
8 changes: 4 additions & 4 deletions sdk/apps/modal-example/src/routes/suiInitOnConnect.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { createSignal, onMount, Show } from 'solid-js'
import { Title } from '@solidjs/meta'
import { NightlyConnectSuiAdapter } from '@nightlylabs/wallet-selector-sui'
import { TransactionBlock } from '@mysten/sui.js/transactions'
import { Transaction } from '@mysten/sui/transactions'
import toast from 'solid-toast'

export default function Sui() {
Expand Down Expand Up @@ -66,13 +66,13 @@ export default function Sui() {
<button
onClick={async () => {
try {
const transactionBlock = new TransactionBlock()
const transactionBlock = new Transaction()
const coin = transactionBlock.splitCoins(transactionBlock.gas, [
transactionBlock.pure(50000000)
transactionBlock.pure.u64(50000000)
])
transactionBlock.transferObjects(
[coin],
transactionBlock.pure(
transactionBlock.pure.address(
'0xd85c7ad90905e0bd49b72420deb5f4077cab62840fb3917ca2945e41d8854013'
)
)
Expand Down
9 changes: 4 additions & 5 deletions sdk/packages/selector-sui/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@nightlylabs/wallet-selector-sui",
"version": "0.3.2",
"version": "0.4.0",
"description": "",
"type": "module",
"exports": {
Expand All @@ -24,11 +24,10 @@
"author": "",
"license": "ISC",
"dependencies": {
"@mysten/sui.js": "^0.42.0",
"@mysten/sui": "^1.2.1",
"@mysten/wallet-adapter-wallet-standard": "^0.8.0",
"@mysten/wallet-standard": "^0.8.0",
"@mysten/wallet-adapter-base": "^0.9.0",
"@nightlylabs/nightly-connect-sui": "0.0.29",
"@mysten/wallet-standard": "^0.12.12",
"@nightlylabs/nightly-connect-sui": "0.1.0",
"@nightlylabs/wallet-selector-base": "0.4.1",
"@wallet-standard/core": "^1.0.3",
"bs58": "^4.0.1",
Expand Down
4 changes: 2 additions & 2 deletions sdk/packages/selector-sui/src/adapter.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* eslint-disable @typescript-eslint/no-empty-function */
import { publicKeyFromRawBytes } from '@mysten/sui.js/verify'
import { publicKeyFromRawBytes } from '@mysten/sui/verify'
import { StandardWalletAdapter } from '@mysten/wallet-adapter-wallet-standard'
import type {
SuiSignAndExecuteTransactionBlockMethod,
Expand Down Expand Up @@ -846,7 +846,7 @@ export const createSuiWalletAccountFromString = (publicKey: string): WalletAccou
const suiPk = publicKeyFromRawBytes('ED25519', bs58.decode(publicKey))
return {
address: suiPk.toSuiAddress(),
publicKey: suiPk.toBytes(),
publicKey: suiPk.toRawBytes(),
chains: SUI_CHAINS,
features: [
'standard:connect',
Expand Down
6 changes: 3 additions & 3 deletions sdk/packages/sui/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@nightlylabs/nightly-connect-sui",
"version": "0.0.29",
"version": "0.1.0",
"type": "module",
"exports": {
".": {
Expand Down Expand Up @@ -46,8 +46,8 @@
"typescript": "^5.1.3"
},
"dependencies": {
"@mysten/sui.js": "^0.42.0",
"@mysten/wallet-standard": "^0.8.0",
"@mysten/sui": "^1.2.1",
"@mysten/wallet-standard": "^0.12.12",
"@nightlylabs/nightly-connect-base": "^0.0.28",
"@noble/hashes": "^1.3.0",
"eventemitter3": "^5.0.1",
Expand Down
Loading

0 comments on commit 175b2d3

Please sign in to comment.