Skip to content

Commit

Permalink
bump mysten packages
Browse files Browse the repository at this point in the history
  • Loading branch information
awojciak committed Sep 22, 2023
1 parent 0d7b9a4 commit fc9da28
Show file tree
Hide file tree
Showing 17 changed files with 202 additions and 197 deletions.
4 changes: 2 additions & 2 deletions sdk/apps/modal-example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
"vite": "^4.1.4"
},
"dependencies": {
"@mysten/sui.js": "^0.37.1",
"@mysten/wallet-adapter-wallet-standard": "^0.7.9",
"@mysten/sui.js": "^0.42.0",
"@mysten/wallet-adapter-wallet-standard": "^0.8.0",
"@nightlylabs/wallet-selector-solana": "0.2.2",
"@nightlylabs/nightly-connect-solana": "0.0.26",
"@nightlylabs/nightly-connect-sui": "0.0.25",
Expand Down
4 changes: 2 additions & 2 deletions sdk/apps/modal-example/src/routes/sui.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { createEffect, createSignal, onMount, Show } from 'solid-js'
import { Title } from 'solid-start'
import { NightlyConnectSuiAdapter } from '@nightlylabs/wallet-selector-sui'
import { TransactionBlock } from '@mysten/sui.js'
import { TransactionBlock } from '@mysten/sui.js/transactions'
import toast from 'solid-toast'

export default function Sui() {
Expand Down Expand Up @@ -104,7 +104,7 @@ export default function Sui() {
onClick={async () => {
try {
const accounts = await adapter()!.getAccounts()
await adapter()!.signMessage!({
await adapter()!.signPersonalMessage!({
message: new TextEncoder().encode('I love Nightly'),
account: accounts[0]
})
Expand Down
4 changes: 2 additions & 2 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 'solid-start'
import { NightlyConnectSuiAdapter } from '@nightlylabs/wallet-selector-sui'
import { TransactionBlock } from '@mysten/sui.js'
import { TransactionBlock } from '@mysten/sui.js/transactions'
import toast from 'solid-toast'

export default function Sui() {
Expand Down Expand Up @@ -82,7 +82,7 @@ export default function Sui() {
onClick={async () => {
try {
const accounts = await adapter()!.getAccounts()
await adapter()!.signMessage!({
await adapter()!.signPersonalMessage!({
message: new TextEncoder().encode('I love Nightly'),
account: accounts[0]
})
Expand Down
8 changes: 4 additions & 4 deletions sdk/apps/nextjs-example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@
"dependencies": {
"@nightlylabs/wallet-selector-solana": "0.2.2",
"@nightlylabs/wallet-selector-sui": "0.2.2",
"@mysten/wallet-adapter-wallet-standard": "0.7.12",
"@mysten/wallet-adapter-base": "0.7.12",
"@mysten/sui.js": "0.37.1",
"@mysten/wallet-kit": "0.4.12",
"@mysten/wallet-adapter-wallet-standard": "0.8.0",
"@mysten/wallet-adapter-base": "0.9.0",
"@mysten/sui.js": "0.42.0",
"@mysten/wallet-kit": "0.7.3",
"@solana/web3.js": "^1.77.2",
"@types/node": "20.4.2",
"@types/react": "18.2.15",
Expand Down
4 changes: 2 additions & 2 deletions sdk/apps/sui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@
"typescript": "^5.1.3"
},
"dependencies": {
"@mysten/sui.js": "^0.37.1",
"@mysten/wallet-standard": "^0.5.12",
"@mysten/sui.js": "^0.42.0",
"@mysten/wallet-standard": "^0.8.0",
"@nightlylabs/nightly-connect-base": "0.0.25",
"@noble/hashes": "^1.3.0",
"eventemitter3": "^5.0.1",
Expand Down
18 changes: 18 additions & 0 deletions sdk/apps/sui/rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,15 @@ export default [
plugins: [typescript(), nodeResolve(), commonjs(), terser()],
external: [
'@mysten/sui.js',
'@mysten/sui.js/dist/cjs/signers/types',
'@mysten/sui.js/client',
'@mysten/sui.js/transactions',
'@mysten/sui.js/keypairs/ed25519',
'@mysten/sui.js/dist/cjs/providers/json-rpc-provider',
'@mysten/sui.js/dist/cjs/rpc/connection',
'@mysten/sui.js/verify',
'@mysten/sui.js/utils',
'@mysten/sui.js/cryptography',
'@mysten/wallet-standard',
'@noble/hashes',
'@nightlylabs/nightly-connect-base',
Expand Down Expand Up @@ -55,6 +64,15 @@ export default [
],
external: [
'@mysten/sui.js',
'@mysten/sui.js/dist/cjs/signers/types',
'@mysten/sui.js/client',
'@mysten/sui.js/transactions',
'@mysten/sui.js/keypairs/ed25519',
'@mysten/sui.js/dist/cjs/providers/json-rpc-provider',
'@mysten/sui.js/dist/cjs/rpc/connection',
'@mysten/sui.js/verify',
'@mysten/sui.js/utils',
'@mysten/sui.js/cryptography',
'@mysten/wallet-standard',
'@noble/hashes',
'@nightlylabs/nightly-connect-base',
Expand Down
6 changes: 3 additions & 3 deletions sdk/apps/sui/src/app.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { UserConnectedEvent } from '../../../bindings/UserConnectedEvent'
import { SignedMessage, SignedTransaction } from '@mysten/sui.js'
import { SignedMessage, SignedTransaction } from '@mysten/sui.js/dist/cjs/signers/types'
import {
SuiSignAndExecuteTransactionBlockInput,
SuiSignAndExecuteTransactionBlockOutput,
SuiSignMessageInput,
SuiSignPersonalMessageInput,
SuiSignTransactionBlockInput
} from '@mysten/wallet-standard'
import {
Expand Down Expand Up @@ -98,7 +98,7 @@ export class AppSui extends EventEmitter<SuiAppEvents> {
return JSON.parse(signedTx[0].transaction)
}

signMessage = async (input: SuiSignMessageInput, encoding?: string) => {
signMessage = async (input: SuiSignPersonalMessageInput, encoding?: string) => {
const request: MessageToSign = {
message: new TextDecoder().decode(input.message),
metadata: JSON.stringify({ encoding: encoding || 'hex', account: input.account })
Expand Down
3 changes: 2 additions & 1 deletion sdk/apps/sui/src/client.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { AppDisconnectedEvent } from '../../../bindings/AppDisconnectedEvent'
import { SignedMessage, SignedTransaction, SuiTransactionBlockResponse } from '@mysten/sui.js'
import { SuiTransactionBlockResponse } from '@mysten/sui.js/client'
import { SignedMessage, SignedTransaction } from '@mysten/sui.js/dist/cjs/signers/types'
import {
BaseClient,
ClientBaseInitialize,
Expand Down
29 changes: 9 additions & 20 deletions sdk/apps/sui/src/e2e.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,11 @@ import { assert, beforeAll, beforeEach, describe, expect, test, vi } from 'vites
import { AppSui } from './app'
import { ClientSui } from './client'
import { signTransactionBlock, SUI_NETWORK, TEST_APP_INITIALIZE } from './utils'

import {
Ed25519Keypair,
fromB64,
IntentScope,
messageWithIntent,
toB64,
toSerializedSignature,
TransactionBlock,
verifyMessage
} from '@mysten/sui.js'
import { fromB64, toB64 } from '@mysten/sui.js/utils'
import { TransactionBlock } from '@mysten/sui.js/transactions'
import { Ed25519Keypair } from '@mysten/sui.js/keypairs/ed25519'
import { verifyPersonalMessage } from '@mysten/sui.js/verify'
import { IntentScope, messageWithIntent, toSerializedSignature } from '@mysten/sui.js/cryptography'
import { blake2b } from '@noble/hashes/blake2b'
import { fetch } from 'cross-fetch'
import { WalletAccount } from '@mysten/wallet-standard'
Expand Down Expand Up @@ -95,10 +89,9 @@ describe('SUI client tests', () => {
chain: 'sui:testnet'
})

const isValid = await verifyMessage(
signedTx.transactionBlockBytes,
signedTx.signature,
IntentScope.TransactionData
const isValid = await verifyPersonalMessage(
new TextEncoder().encode(signedTx.transactionBlockBytes),
signedTx.signature
)
expect(isValid).toBeTruthy()
})
Expand Down Expand Up @@ -130,11 +123,7 @@ describe('SUI client tests', () => {
account: aliceWalletAccount
})
const signData = new TextEncoder().encode(msgToSign)
const isValid = await verifyMessage(
signData,
signedMessage.signature,
IntentScope.PersonalMessage
)
const isValid = await verifyPersonalMessage(signData, signedMessage.signature)
expect(isValid).toBe(true)
})
test('#on("signAndExecuteSignTransaction")', async () => {
Expand Down
13 changes: 7 additions & 6 deletions sdk/apps/sui/src/http-client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@ import {
smartDelay
} from '@nightlylabs/nightly-connect-base'
import { HttpClientSui } from './http-client'

import { Ed25519Keypair, IntentScope, toB64, TransactionBlock, verifyMessage } from '@mysten/sui.js'
import { toB64 } from '@mysten/sui.js/utils'
import { TransactionBlock } from '@mysten/sui.js/transactions'
import { Ed25519Keypair } from '@mysten/sui.js/keypairs/ed25519'
import { verifyPersonalMessage } from '@mysten/sui.js/verify'
import { hexToBytes } from '@noble/hashes/utils'
import { WalletAccount } from '@mysten/wallet-standard'

Expand Down Expand Up @@ -93,10 +95,9 @@ describe('SUI http-client tests', () => {
await smartDelay()
const signedTx = await promiseSignTransaction

const isValid = await verifyMessage(
signedTx.transactionBlockBytes,
signedTx.signature,
IntentScope.TransactionData
const isValid = await verifyPersonalMessage(
new TextEncoder().encode(signedTx.transactionBlockBytes),
signedTx.signature
)
expect(isValid).toBeTruthy()
})
Expand Down
2 changes: 1 addition & 1 deletion sdk/apps/sui/src/http-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { SUI_NETWORK, parseRequest } from './utils'
import { HttpConnectSessionRequest } from '../../../bindings/HttpConnectSessionRequest'
import { HttpGetPendingRequestsRequest } from '../../../bindings/HttpGetPendingRequestsRequest'
import { HttpGetPendingRequestRequest } from '../../../bindings/HttpGetPendingRequestRequest'
import { SignedTransaction } from '@mysten/sui.js'
import { SignedTransaction } from '@mysten/sui.js//dist/cjs/signers/types'
import { HttpGetSessionInfoResponse } from '../../../bindings/HttpGetSessionInfoResponse'

export class HttpClientSui {
Expand Down
30 changes: 18 additions & 12 deletions sdk/apps/sui/src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
import {
JsonRpcProvider,
Connection,
TransactionBlock,
messageWithIntent,
IntentScope,
toSerializedSignature,
Ed25519Keypair
} from '@mysten/sui.js'
import { TransactionBlock } from '@mysten/sui.js/transactions'
import { Ed25519Keypair } from '@mysten/sui.js/keypairs/ed25519'
import { IntentScope, messageWithIntent, toSerializedSignature } from '@mysten/sui.js/cryptography'
import { blake2b } from '@noble/hashes/blake2b'
import { AppBaseInitialize, ContentType, RELAY_ENDPOINT, RequestContent } from '@nightlylabs/nightly-connect-base'
import { CustomSuiRequest, SignMessagesSuiRequest, SignTransactionsSuiRequest, SuiRequest } from './requestTypes'
import {
AppBaseInitialize,
ContentType,
RELAY_ENDPOINT,
RequestContent
} from '@nightlylabs/nightly-connect-base'
import {
CustomSuiRequest,
SignMessagesSuiRequest,
SignTransactionsSuiRequest,
SuiRequest
} from './requestTypes'
import { JsonRpcProvider } from '@mysten/sui.js/dist/cjs/providers/json-rpc-provider'
import { Connection } from '@mysten/sui.js/dist/cjs/rpc/connection'

export type AppSuiInitialize = Omit<AppBaseInitialize, 'network'>

Expand Down Expand Up @@ -81,4 +87,4 @@ export const parseRequest = (request: RequestContent, sessionId: string): SuiReq
return customRequest
}
}
}
}
8 changes: 4 additions & 4 deletions sdk/packages/selector-sui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@
"author": "",
"license": "ISC",
"dependencies": {
"@mysten/sui.js": "^0.37.1",
"@mysten/wallet-adapter-wallet-standard": "^0.7.12",
"@mysten/wallet-standard": "^0.5.12",
"@mysten/wallet-adapter-base": "^0.7.12",
"@mysten/sui.js": "^0.42.0",
"@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.25",
"@nightlylabs/wallet-selector-base": "0.2.2",
"@wallet-standard/core": "^1.0.3",
Expand Down
4 changes: 4 additions & 0 deletions sdk/packages/selector-sui/rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,11 @@ export default [
],
external: [
'@mysten/sui.js',
'@mysten/sui.js/verify',
'@mysten/sui.js/dist/cjs/signers/types',
'@mysten/sui.js/client',
'@mysten/wallet-adapter-wallet-standard',
'@mysten/wallet-adapter-wallet-standard/dist/StandardWalletAdapter',
'@mysten/wallet-standard',
'@nightlylabs/nightly-connect-sui',
'@nightlylabs/wallet-selector-base',
Expand Down
40 changes: 24 additions & 16 deletions sdk/packages/selector-sui/src/adapter.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
/* eslint-disable @typescript-eslint/no-empty-function */
import {
SignedMessage,
SignedTransaction,
SuiTransactionBlockResponse,
publicKeyFromSerialized
} from '@mysten/sui.js'
import { WalletAdapter } from '@mysten/wallet-adapter-base'
import { publicKeyFromRawBytes } from '@mysten/sui.js/verify'
import { SignedTransaction } from '@mysten/sui.js/dist/cjs/signers/types'
import { SuiTransactionBlockResponse } from '@mysten/sui.js/client'
// import { WalletAdapter } from '@mysten/wallet-adapter-base'
import { StandardWalletAdapter } from '@mysten/wallet-adapter-wallet-standard'
import type {
StandardWalletAdapterWallet,
SignedPersonalMessage,
SuiSignAndExecuteTransactionBlockInput,
SuiSignMessageInput,
SuiSignPersonalMessageInput,
SuiSignTransactionBlockInput
} from '@mysten/wallet-standard'
import { SUI_CHAINS } from '@mysten/wallet-standard'
Expand Down Expand Up @@ -38,11 +35,14 @@ import {
import type { StandardEventsOnMethod, WalletAccount } from '@wallet-standard/core'
import bs58 from 'bs58'
import { suiWalletsFilter } from './detection'
import { StandardWalletAdapterConfig } from '@mysten/wallet-adapter-wallet-standard/dist/StandardWalletAdapter'

export const convertBase58toBase64 = (base58: string) => {
const buffer = bs58.decode(base58)
return buffer.toString('base64')
}
export class NightlyConnectSuiAdapter implements WalletAdapter {
export class NightlyConnectSuiAdapter {
// TODO: add later "implements WalletAdapter"
name = 'Nightly Connect' as const
icon = logoBase64
connected = false
Expand Down Expand Up @@ -428,19 +428,25 @@ export class NightlyConnectSuiAdapter implements WalletAdapter {
this.connecting = false
}

signMessage = async (messageInput: SuiSignMessageInput): Promise<SignedMessage> => {
signPersonalMessage = async (
messageInput: SuiSignPersonalMessageInput
): Promise<SignedPersonalMessage> => {
if (!this._app || !this._connectionType) {
throw new Error('Wallet not ready')
}
switch (this._connectionType) {
case ConnectionType.Nightly: {
return await this._app.signMessage(messageInput)
const message = await this._app.signMessage(messageInput)
return {
bytes: message.messageBytes,
signature: message.signature
}
}
case ConnectionType.WalletStandard: {
if (!this._innerStandardAdapter) {
throw new Error('Wallet not ready')
}
return await this._innerStandardAdapter.signMessage(messageInput)
return await this._innerStandardAdapter.signPersonalMessage(messageInput)
}
}
}
Expand All @@ -459,6 +465,7 @@ export class NightlyConnectSuiAdapter implements WalletAdapter {
if (!this._innerStandardAdapter) {
throw new Error('Wallet not ready')
}
// @ts-expect-error(remove after standard will use 0.42)
return await this._innerStandardAdapter.signTransactionBlock(transactionInput)
}
}
Expand All @@ -478,6 +485,7 @@ export class NightlyConnectSuiAdapter implements WalletAdapter {
if (!this._innerStandardAdapter) {
throw new Error('Wallet not ready')
}
// @ts-expect-error(remove after standard will use 0.42)
return await this._innerStandardAdapter.signAndExecuteTransactionBlock(transactionInput)
}
}
Expand Down Expand Up @@ -606,8 +614,8 @@ export class NightlyConnectSuiAdapter implements WalletAdapter {
}

const adapter = new StandardWalletAdapter({
wallet: wallet.standardWallet as StandardWalletAdapterWallet
})
wallet: wallet.standardWallet
} as StandardWalletAdapterConfig)

try {
await adapter.connect()
Expand Down Expand Up @@ -635,7 +643,7 @@ export class NightlyConnectSuiAdapter implements WalletAdapter {
}
}
export const createSuiWalletAccountFromString = (publicKey: string): WalletAccount => {
const suiPk = publicKeyFromSerialized('ED25519', convertBase58toBase64(publicKey))
const suiPk = publicKeyFromRawBytes('ED25519', bs58.decode(publicKey))
return {
address: suiPk.toSuiAddress(),
publicKey: suiPk.toBytes(),
Expand Down
Loading

0 comments on commit fc9da28

Please sign in to comment.