@usebutr/sui 2.0.2 → 3.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +40 -0
- package/README.md +25 -4
- package/dist/index.d.ts +12 -69
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +44 -135
- package/dist/index.js.map +1 -1
- package/package.json +4 -4
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,45 @@
|
|
|
1
1
|
# @usebutr/sui
|
|
2
2
|
|
|
3
|
+
## 3.0.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated dependencies [[`488fe13`](https://github.com/pedroapfilho/usebutr/commit/488fe13fe9cddb99ff6c5d60f798140e6ac4076f)]:
|
|
8
|
+
- @usebutr/core@3.0.1
|
|
9
|
+
- @usebutr/wallet-standard-shared@2.0.1
|
|
10
|
+
|
|
11
|
+
## 3.0.0
|
|
12
|
+
|
|
13
|
+
### Major Changes
|
|
14
|
+
|
|
15
|
+
- [#203](https://github.com/pedroapfilho/usebutr/pull/203) [`1263f86`](https://github.com/pedroapfilho/usebutr/commit/1263f8666afd43b4f7dbf8df1763709c3edf09d9) Thanks [@pedroapfilho](https://github.com/pedroapfilho)! - Adapters now say what they can do by having the method: `capabilities` is gone, and an optional method (`sendTx`, `signMessage`, `getBalance`, `switchChain`, …) exists only when it works for that wallet. No adapter returns a placeholder balance or a receipt that stays pending anymore.
|
|
16
|
+
|
|
17
|
+
- `sendTx(tx, { account, chain })` replaces `sendTx` and `sendTxToChain`, and `signMessage`, `signTransaction` and `getBalance` take options objects. `chain` is a `ChainBase`. An adapter either routes the call to that chain, switches the wallet to it, or rejects; none ignores it.
|
|
18
|
+
- An `account` the wallet does not expose now rejects instead of signing with the first account. `chain.name` is the chain's name, never the wallet's.
|
|
19
|
+
- `getAccounts()` resolves the active account first. `getAccount` and `switchAccount` are removed.
|
|
20
|
+
- `getSigner()` resolves a tagged `WalletSigner` (`eip1193`, `wallet-standard`, `walletconnect`, `ledger-*`, …), so it can be narrowed with `switch (signer.kind)` instead of cast.
|
|
21
|
+
- `createWalletManager(config, { initialState })` owns discovery, hydration and persistence, and works without React. `config.sources` replaces the `discovery`, `connectors` and `createConnector` props. `fromAdapters` registers WalletConnect, Ledger and hand-built adapters, which now also appear in `useDiscoveredWallets()`.
|
|
22
|
+
- `WalletManagerProvider` takes `config` and `initialState`. `useSigner(wallet)` and `useBalance(wallet, { token, account })` take the wallet entry itself, and id-taking hooks read the active wallet only when the id is omitted (`null` reads none). The hooks are `useWalletManager`, `useWalletState`, `useConnect`, `useWallet`, `useSelectedWallet` (now typed per platform), `useAccounts`, `useConnectionStatus`, `useIsHydrated`, `useIsReconnecting`, `useDiscoveredWallets`, `useConnectedWallets`, the `…ByPlatform` groupings, `useBalance` and `useSigner`.
|
|
23
|
+
- `manager.connect()` and `useConnect().connectAsync()` resolve the `ConnectedWallet` and reject with a `ConnectionError`, now an `Error` subclass with a `kind` and a new `WalletNotFound` kind. `useConnect().connect()` never rejects: the failure lands in its `error`.
|
|
24
|
+
- `WalletPersistence` is `load()` / `save(state)`, and `createWalletStorage` replaces `new WalletStorage`. Storage keys are unchanged.
|
|
25
|
+
- Chain registries (`EVM_CHAINS`, `SVM_CHAINS`, …, `CHAINS_BY_PLATFORM`) move to `@usebutr/core`, and `BITCOIN_CHAINS` gains `testnet4`. `@usebutr/wallets` loads every platform's signer kinds, so an app that imports only it can narrow `signer.kind`.
|
|
26
|
+
- `@usebutr/react` requires React 19, which its `use()` call already needed.
|
|
27
|
+
- WalletConnect requests on Solana, Sui and Bitcoin now carry their chain, so they no longer fall through to the first namespace in a multi-namespace session. Solana takes `SVM_CHAINS` chains and maps them to the genesis-hash ids WalletConnect sessions use.
|
|
28
|
+
- Ledger's Solana `signTransaction` returns the full signed transaction, Sui signs the intent message, and Bitcoin `signMessage` returns a BIP-137 signature.
|
|
29
|
+
- `@usebutr/testing`'s fake adapter resolves a `signer` you pass instead of registering a test-only signer kind.
|
|
30
|
+
- `setAccount` selects an exposed account without changing any account's chain. Unknown accounts are ignored; chain changes come from the adapter.
|
|
31
|
+
- WalletConnect EVM events use the namespace in `session_event`, including empty account lists that end the connection. Local chain switches still update the manager.
|
|
32
|
+
- Failed persistence saves wait for every key write to finish before reporting failure, so delayed writes cannot overwrite a later disconnect.
|
|
33
|
+
- `@usebutr/svm/transaction` provides the shared legacy/v0 signing codec used by Ledger and WalletConnect, with consistent layout and signature validation.
|
|
34
|
+
|
|
35
|
+
See the migration guide at https://docs.usebutr.com/migration.
|
|
36
|
+
|
|
37
|
+
### Patch Changes
|
|
38
|
+
|
|
39
|
+
- Updated dependencies [[`1263f86`](https://github.com/pedroapfilho/usebutr/commit/1263f8666afd43b4f7dbf8df1763709c3edf09d9), [`5d1f234`](https://github.com/pedroapfilho/usebutr/commit/5d1f23403263f7a1f8a48be061727972fe749b5f)]:
|
|
40
|
+
- @usebutr/core@3.0.0
|
|
41
|
+
- @usebutr/wallet-standard-shared@2.0.0
|
|
42
|
+
|
|
3
43
|
## 2.0.2
|
|
4
44
|
|
|
5
45
|
### Patch Changes
|
package/README.md
CHANGED
|
@@ -11,22 +11,43 @@ connection-state library. Your application owns the picker UI and chain client.
|
|
|
11
11
|
npm install @usebutr/react @usebutr/core @usebutr/sui zustand @wallet-standard/app
|
|
12
12
|
```
|
|
13
13
|
|
|
14
|
-
React
|
|
14
|
+
React 19 is a peer dependency of the provider. Discovery does not render a connect modal; add your picker as the provider child. `@wallet-standard/app` is required for Wallet Standard discovery.
|
|
15
15
|
|
|
16
16
|
## Usage
|
|
17
17
|
|
|
18
18
|
```tsx
|
|
19
19
|
import type { ReactNode } from "react";
|
|
20
|
-
import {
|
|
20
|
+
import type { WalletManagerConfig } from "@usebutr/core";
|
|
21
21
|
import { discoverSuiAdapters } from "@usebutr/sui";
|
|
22
22
|
import { WalletManagerProvider } from "@usebutr/react";
|
|
23
23
|
|
|
24
|
-
|
|
24
|
+
// Every `discover*Adapters` export is a wallet source as-is.
|
|
25
|
+
const config: WalletManagerConfig = { sources: [discoverSuiAdapters] };
|
|
26
|
+
|
|
25
27
|
export const WalletProvider = ({ children }: { children: ReactNode }) => (
|
|
26
|
-
<WalletManagerProvider
|
|
28
|
+
<WalletManagerProvider config={config}>{children}</WalletManagerProvider>
|
|
27
29
|
);
|
|
28
30
|
```
|
|
29
31
|
|
|
32
|
+
Each adapter defines `sendTx` (`sui:signAndExecuteTransaction`, resolves the digest), `signMessage` (`sui:signPersonalMessage`) and `signTransaction` (resolves `{ bytes, signature }` for `executeTransactionBlock`) only when the wallet advertises the matching feature, and `switchChain` only when it advertises more than one Sui network. Transactions are a `@mysten/sui` `Transaction`, its JSON string, or BCS bytes. Wallet Standard carries the chain per call, so `options.chain` routes one transaction without moving the wallet. Balances and receipts need your own `SuiClient`. Check a method's presence before calling it:
|
|
33
|
+
|
|
34
|
+
```ts
|
|
35
|
+
import type { ConnectedWallet, SuiTransactionInput } from "@usebutr/core";
|
|
36
|
+
import { SUI_CHAINS } from "@usebutr/core";
|
|
37
|
+
|
|
38
|
+
export const send = async (wallet: ConnectedWallet<"sui">, transaction: SuiTransactionInput) => {
|
|
39
|
+
if (!wallet.connector.sendTx) {
|
|
40
|
+
throw new Error(`${wallet.connector.name} cannot send Sui transactions`);
|
|
41
|
+
}
|
|
42
|
+
return wallet.connector.sendTx(transaction, {
|
|
43
|
+
account: wallet.account,
|
|
44
|
+
chain: SUI_CHAINS.testnet,
|
|
45
|
+
});
|
|
46
|
+
};
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
An `account` the wallet does not expose, or a chain it does not advertise, rejects. `getSigner()` resolves `{ kind: "wallet-standard", wallet }`: reach any other feature with `getFeature` from `@usebutr/wallet-standard-shared` and the feature types this package exports. Chain registries (`SUI_CHAINS`, `SUI_CHAINS_LIST`) come from `@usebutr/core`.
|
|
50
|
+
|
|
30
51
|
## Documentation
|
|
31
52
|
|
|
32
53
|
- [Package reference](https://docs.usebutr.com/api/sui)
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { WalletStandardWallet, WalletStandardWalletAccount } from "@usebutr/wallet-standard-shared";
|
|
1
|
+
import { PlatformDiscoverer, SuiAdapter, WalletAdapter } from "@usebutr/core";
|
|
2
|
+
import { WalletStandardModuleLoader, WalletStandardWallet, WalletStandardWalletAccount } from "@usebutr/wallet-standard-shared";
|
|
3
3
|
//#region src/wallet-standard-types.d.ts
|
|
4
4
|
type SuiSignPersonalMessageInput = {
|
|
5
5
|
account: WalletStandardWalletAccount;
|
|
@@ -48,66 +48,20 @@ type SuiSignAndExecuteTransactionFeature = {
|
|
|
48
48
|
//#endregion
|
|
49
49
|
//#region src/wallet-standard-adapter.d.ts
|
|
50
50
|
/**
|
|
51
|
-
*
|
|
52
|
-
*
|
|
53
|
-
* receipt reads need
|
|
51
|
+
* Wallet Standard carries the chain per call, so `sendTx` and
|
|
52
|
+
* `signTransaction` route `options.chain` without moving the wallet. Balance
|
|
53
|
+
* and receipt reads need a `SuiClient`, which butr does not ship.
|
|
54
54
|
*/
|
|
55
55
|
declare const buildSuiAdapter: (wallet: WalletStandardWallet,
|
|
56
|
-
/**
|
|
57
|
-
*
|
|
58
|
-
|
|
59
|
-
registerDisconnector?: (emit: () => void) => void) => WalletAdapter | null;
|
|
56
|
+
/** Discovery passes this so a Wallet Standard `unregister` tears down the
|
|
57
|
+
* connected pool entry. */
|
|
58
|
+
registerDisconnector?: (emit: () => void) => void) => SuiAdapter | null;
|
|
60
59
|
/**
|
|
61
|
-
* Requires the optional `@wallet-standard/app` peer dep
|
|
60
|
+
* Requires the optional `@wallet-standard/app` peer dep; without it Sui
|
|
61
|
+
* discovery silently does nothing.
|
|
62
62
|
* Spec: https://docs.sui.io/standards/wallet-standard
|
|
63
63
|
*/
|
|
64
|
-
declare const discoverSuiAdapters: (onAdapter: (adapter: WalletAdapter) => void) => (() => void);
|
|
65
|
-
//#endregion
|
|
66
|
-
//#region src/chains.d.ts
|
|
67
|
-
declare const SUI_CHAINS: {
|
|
68
|
-
readonly devnet: {
|
|
69
|
-
readonly id: "sui:devnet";
|
|
70
|
-
readonly name: "Sui Devnet";
|
|
71
|
-
readonly namespace: "sui";
|
|
72
|
-
readonly reference: "devnet";
|
|
73
|
-
};
|
|
74
|
-
readonly localnet: {
|
|
75
|
-
readonly id: "sui:localnet";
|
|
76
|
-
readonly name: "Sui Localnet";
|
|
77
|
-
readonly namespace: "sui";
|
|
78
|
-
readonly reference: "localnet";
|
|
79
|
-
};
|
|
80
|
-
readonly mainnet: {
|
|
81
|
-
readonly id: "sui:mainnet";
|
|
82
|
-
readonly name: "Sui Mainnet";
|
|
83
|
-
readonly namespace: "sui";
|
|
84
|
-
readonly reference: "mainnet";
|
|
85
|
-
};
|
|
86
|
-
readonly testnet: {
|
|
87
|
-
readonly id: "sui:testnet";
|
|
88
|
-
readonly name: "Sui Testnet";
|
|
89
|
-
readonly namespace: "sui";
|
|
90
|
-
readonly reference: "testnet";
|
|
91
|
-
};
|
|
92
|
-
};
|
|
93
|
-
declare const SUI_CHAINS_LIST: ReadonlyArray<ChainBase>;
|
|
94
|
-
//#endregion
|
|
95
|
-
//#region src/capabilities.d.ts
|
|
96
|
-
type WalletStandardCapabilityInput = {
|
|
97
|
-
chainCount: number;
|
|
98
|
-
features: {
|
|
99
|
-
events: boolean;
|
|
100
|
-
signAndExecuteTransaction: boolean;
|
|
101
|
-
signMessage: boolean;
|
|
102
|
-
signTransaction: boolean;
|
|
103
|
-
};
|
|
104
|
-
};
|
|
105
|
-
/**
|
|
106
|
-
* `signIn` is false: Sui Wallet Standard has no Sign-In-With-Sui feature.
|
|
107
|
-
* `signAndExecuteTransaction` means the wallet broadcasts, while
|
|
108
|
-
* `signTransaction` is sign-only and leaves the broadcast to the consumer.
|
|
109
|
-
*/
|
|
110
|
-
declare const resolveSuiCapabilities: (input: WalletStandardCapabilityInput) => WalletCapabilities;
|
|
64
|
+
declare const discoverSuiAdapters: (onAdapter: (adapter: WalletAdapter) => void, loadModule?: WalletStandardModuleLoader) => (() => void);
|
|
111
65
|
//#endregion
|
|
112
66
|
//#region src/discoverer.d.ts
|
|
113
67
|
/**
|
|
@@ -116,16 +70,5 @@ declare const resolveSuiCapabilities: (input: WalletStandardCapabilityInput) =>
|
|
|
116
70
|
*/
|
|
117
71
|
declare const suiDiscoverer: PlatformDiscoverer;
|
|
118
72
|
//#endregion
|
|
119
|
-
|
|
120
|
-
/**
|
|
121
|
-
* Sui's `getSigner()` hands back the Wallet Standard wallet, which consumers
|
|
122
|
-
* narrow through its `features` map.
|
|
123
|
-
*/
|
|
124
|
-
declare module "@usebutr/core" {
|
|
125
|
-
interface SignerForPlatform {
|
|
126
|
-
sui: WalletStandardWallet;
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
//#endregion
|
|
130
|
-
export { SUI_CHAINS, SUI_CHAINS_LIST, type SuiSignAndExecuteTransactionFeature, type SuiSignAndExecuteTransactionInput, type SuiSignAndExecuteTransactionOutput, type SuiSignPersonalMessageFeature, type SuiSignPersonalMessageInput, type SuiSignPersonalMessageOutput, type SuiSignTransactionFeature, type SuiSignTransactionInput, type SuiSignTransactionOutput, type WalletStandardCapabilityInput, buildSuiAdapter, discoverSuiAdapters, resolveSuiCapabilities, suiDiscoverer };
|
|
73
|
+
export { type SuiSignAndExecuteTransactionFeature, type SuiSignAndExecuteTransactionInput, type SuiSignAndExecuteTransactionOutput, type SuiSignPersonalMessageFeature, type SuiSignPersonalMessageInput, type SuiSignPersonalMessageOutput, type SuiSignTransactionFeature, type SuiSignTransactionInput, type SuiSignTransactionOutput, buildSuiAdapter, discoverSuiAdapters, suiDiscoverer };
|
|
131
74
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/wallet-standard-types.ts","../src/wallet-standard-adapter.ts","../src/
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/wallet-standard-types.ts","../src/wallet-standard-adapter.ts","../src/discoverer.ts"],"mappings":";;;KAOK;EACH,SAAS;EACT,SAAS;;KAGN;EACH;EACA;;KAGG;EACH,sBACE,OAAO,gCACJ,QAAQ;EACb;;KAGG;EACH,SAAS;EACT;EACA;IAAe,cAAc;;;KAG1B;EACH;EACA;;KAGG;EACH,kBAAkB,OAAO,4BAA4B,QAAQ;EAC7D;;KAGG;EACH,SAAS;EACT;EACA;IAAe,cAAc;;;KAG1B;EACH;EACA;EACA;EACA;;KAGG;EACH,4BACE,OAAO,sCACJ,QAAQ;EACb;;;;;;;;;cCdI,kBAAe,QACX,sBAGe;;;AAAA,wBAAC,8BACvB;;;;;;cA0EG,sBAAmB,YACX,SAAS,wBAAsB,aAC9B;;;;;;;cCpHT,eAAe"}
|
package/dist/index.js
CHANGED
|
@@ -1,170 +1,79 @@
|
|
|
1
|
-
import { base64ToBytes, bytesToBase64 } from "@usebutr/core";
|
|
2
|
-
import {
|
|
1
|
+
import { SUI_CHAINS_LIST, base64ToBytes, bytesToBase64 } from "@usebutr/core";
|
|
2
|
+
import { createWalletStandardCore, discoverWalletStandard, getFeature, slugify } from "@usebutr/wallet-standard-shared";
|
|
3
3
|
|
|
4
|
-
//#region src/
|
|
4
|
+
//#region src/wallet-standard-adapter.ts
|
|
5
5
|
/**
|
|
6
|
-
* `
|
|
7
|
-
* `
|
|
8
|
-
* `
|
|
6
|
+
* Sui wallets accept only the `toJSON()` form, so a JSON or base64 string and
|
|
7
|
+
* BCS bytes are wrapped. A `Transaction` passes through untouched: its
|
|
8
|
+
* `toJSON` reads `this`, which a copied method would lose.
|
|
9
9
|
*/
|
|
10
|
-
const resolveSuiCapabilities = (input) => buildWalletCapabilities({
|
|
11
|
-
chainCount: input.chainCount,
|
|
12
|
-
events: input.features.events,
|
|
13
|
-
sendTransaction: input.features.signAndExecuteTransaction,
|
|
14
|
-
signIn: false,
|
|
15
|
-
signMessage: input.features.signMessage,
|
|
16
|
-
signTransaction: input.features.signTransaction
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
//#endregion
|
|
20
|
-
//#region src/wallet-standard-adapter.ts
|
|
21
|
-
const SUI_PREFIX = "sui:";
|
|
22
|
-
const SUI_DECIMALS = 9;
|
|
23
|
-
const SUI_MAINNET = "sui:mainnet";
|
|
24
|
-
const isSuiSignPersonalMessageFeature = (feature) => "signPersonalMessage" in feature && typeof feature.signPersonalMessage === "function";
|
|
25
|
-
const isSuiSignAndExecuteTransactionFeature = (feature) => "signAndExecuteTransaction" in feature && typeof feature.signAndExecuteTransaction === "function";
|
|
26
|
-
const isSuiSignTransactionFeature = (feature) => "signTransaction" in feature && typeof feature.signTransaction === "function";
|
|
27
|
-
/** Coerce butr's `unknown` tx into the shape the Sui Wallet Standard features
|
|
28
|
-
* expect: an object with `toJSON()` returning a Promise<string>. A raw string
|
|
29
|
-
* or BCS byte array is wrapped, because wallets accept only the `toJSON()`
|
|
30
|
-
* form and a bare string reaches them as a shape they cannot consume. */
|
|
31
10
|
const coerceSuiTransaction = (tx) => {
|
|
32
11
|
if (typeof tx === "string") return { toJSON: () => Promise.resolve(tx) };
|
|
33
12
|
if (tx instanceof Uint8Array) {
|
|
34
13
|
const encoded = bytesToBase64(tx);
|
|
35
14
|
return { toJSON: () => Promise.resolve(encoded) };
|
|
36
15
|
}
|
|
37
|
-
|
|
38
|
-
throw new TypeError("Sui sendTx/signTransaction expects a @mysten/sui Transaction (with toJSON()), a base64-encoded string, or BCS bytes");
|
|
16
|
+
return tx;
|
|
39
17
|
};
|
|
40
18
|
/**
|
|
41
|
-
*
|
|
42
|
-
*
|
|
43
|
-
* receipt reads need
|
|
19
|
+
* Wallet Standard carries the chain per call, so `sendTx` and
|
|
20
|
+
* `signTransaction` route `options.chain` without moving the wallet. Balance
|
|
21
|
+
* and receipt reads need a `SuiClient`, which butr does not ship.
|
|
44
22
|
*/
|
|
45
23
|
const buildSuiAdapter = (wallet, registerDisconnector) => {
|
|
46
24
|
const core = createWalletStandardCore({
|
|
47
|
-
|
|
25
|
+
chains: SUI_CHAINS_LIST,
|
|
48
26
|
id: slugify("sui", wallet.name),
|
|
49
27
|
label: "Sui",
|
|
50
28
|
namespace: "sui",
|
|
51
|
-
|
|
52
|
-
preferredChainIds: [SUI_MAINNET],
|
|
29
|
+
preferredChainIds: ["sui:mainnet"],
|
|
53
30
|
registerDisconnector,
|
|
54
31
|
trackChainChanges: true,
|
|
55
32
|
wallet
|
|
56
33
|
});
|
|
57
34
|
if (core === null) return null;
|
|
58
|
-
const
|
|
59
|
-
const
|
|
60
|
-
const
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
const resolveTargetChain = (targetChainId) => {
|
|
64
|
-
const candidate = targetChainId.startsWith(SUI_PREFIX) ? targetChainId : `${SUI_PREFIX}${targetChainId}`;
|
|
65
|
-
if (!wallet.chains.includes(candidate)) throw new Error(`Wallet ${wallet.name} does not advertise chain "${candidate}". Available: ${wallet.chains.join(", ")}`);
|
|
66
|
-
return candidate;
|
|
67
|
-
};
|
|
68
|
-
const executeTx = async (tx, account, chain) => {
|
|
69
|
-
if (signAndExecute === void 0) throw new Error(`Wallet ${wallet.name} does not advertise sui:signAndExecuteTransaction`);
|
|
70
|
-
const wsAccount = core.resolveAccount(account);
|
|
71
|
-
const transaction = coerceSuiTransaction(tx);
|
|
72
|
-
return (await signAndExecute.signAndExecuteTransaction({
|
|
73
|
-
account: wsAccount,
|
|
74
|
-
chain: chain ?? core.currentChainId(),
|
|
75
|
-
transaction
|
|
76
|
-
})).digest;
|
|
77
|
-
};
|
|
78
|
-
const adapter = {
|
|
79
|
-
...core,
|
|
80
|
-
capabilities: resolveSuiCapabilities({
|
|
81
|
-
chainCount: core.chainCount,
|
|
82
|
-
features: {
|
|
83
|
-
events: core.hasEvents,
|
|
84
|
-
signAndExecuteTransaction: Boolean(signAndExecute),
|
|
85
|
-
signMessage: Boolean(signMessage),
|
|
86
|
-
signTransaction: Boolean(signTx)
|
|
87
|
-
}
|
|
88
|
-
}),
|
|
35
|
+
const signAndExecute = getFeature(wallet, "sui:signAndExecuteTransaction", "signAndExecuteTransaction");
|
|
36
|
+
const signPersonalMessage = getFeature(wallet, "sui:signPersonalMessage", "signPersonalMessage");
|
|
37
|
+
const signTransaction = getFeature(wallet, "sui:signTransaction", "signTransaction");
|
|
38
|
+
return {
|
|
39
|
+
...core.base,
|
|
89
40
|
chainPlatform: "sui",
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
async
|
|
98
|
-
await
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
async sendTxToChain(tx, targetChainId, account, cb) {
|
|
102
|
-
const target = resolveTargetChain(targetChainId);
|
|
103
|
-
if (target !== core.currentChainId()) cb?.();
|
|
104
|
-
return await executeTx(tx, account, target);
|
|
105
|
-
},
|
|
106
|
-
async signMessage(msg, account) {
|
|
107
|
-
if (signMessage === void 0) throw new Error(`Wallet ${wallet.name} does not advertise sui:signPersonalMessage`);
|
|
108
|
-
const output = await signMessage.signPersonalMessage({
|
|
109
|
-
account: core.resolveAccount(account),
|
|
110
|
-
message: msg
|
|
41
|
+
...signAndExecute !== void 0 && { async sendTx(tx, options) {
|
|
42
|
+
return (await signAndExecute.signAndExecuteTransaction({
|
|
43
|
+
account: core.resolveAccount(options?.account),
|
|
44
|
+
chain: core.resolveChainId(options?.chain),
|
|
45
|
+
transaction: coerceSuiTransaction(tx)
|
|
46
|
+
})).digest;
|
|
47
|
+
} },
|
|
48
|
+
...signPersonalMessage !== void 0 && { async signMessage(message, options) {
|
|
49
|
+
const output = await signPersonalMessage.signPersonalMessage({
|
|
50
|
+
account: core.resolveAccount(options?.account),
|
|
51
|
+
message
|
|
111
52
|
});
|
|
112
53
|
return {
|
|
113
54
|
signature: base64ToBytes(output.signature),
|
|
114
55
|
signedMessage: base64ToBytes(output.bytes)
|
|
115
56
|
};
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
signature: base64ToBytes(output.signature)
|
|
129
|
-
};
|
|
57
|
+
} },
|
|
58
|
+
...signTransaction !== void 0 && { async signTransaction(tx, options) {
|
|
59
|
+
const output = await signTransaction.signTransaction({
|
|
60
|
+
account: core.resolveAccount(options?.account),
|
|
61
|
+
chain: core.resolveChainId(options?.chain),
|
|
62
|
+
transaction: coerceSuiTransaction(tx)
|
|
63
|
+
});
|
|
64
|
+
return {
|
|
65
|
+
bytes: base64ToBytes(output.bytes),
|
|
66
|
+
signature: base64ToBytes(output.signature)
|
|
67
|
+
};
|
|
68
|
+
} }
|
|
130
69
|
};
|
|
131
|
-
return adapter;
|
|
132
70
|
};
|
|
133
71
|
/**
|
|
134
|
-
* Requires the optional `@wallet-standard/app` peer dep
|
|
72
|
+
* Requires the optional `@wallet-standard/app` peer dep; without it Sui
|
|
73
|
+
* discovery silently does nothing.
|
|
135
74
|
* Spec: https://docs.sui.io/standards/wallet-standard
|
|
136
75
|
*/
|
|
137
|
-
const discoverSuiAdapters = (onAdapter) => discoverWalletStandard(onAdapter,
|
|
138
|
-
|
|
139
|
-
//#endregion
|
|
140
|
-
//#region src/chains.ts
|
|
141
|
-
const SUI_CHAINS = {
|
|
142
|
-
devnet: {
|
|
143
|
-
id: "sui:devnet",
|
|
144
|
-
name: "Sui Devnet",
|
|
145
|
-
namespace: "sui",
|
|
146
|
-
reference: "devnet"
|
|
147
|
-
},
|
|
148
|
-
localnet: {
|
|
149
|
-
id: "sui:localnet",
|
|
150
|
-
name: "Sui Localnet",
|
|
151
|
-
namespace: "sui",
|
|
152
|
-
reference: "localnet"
|
|
153
|
-
},
|
|
154
|
-
mainnet: {
|
|
155
|
-
id: "sui:mainnet",
|
|
156
|
-
name: "Sui Mainnet",
|
|
157
|
-
namespace: "sui",
|
|
158
|
-
reference: "mainnet"
|
|
159
|
-
},
|
|
160
|
-
testnet: {
|
|
161
|
-
id: "sui:testnet",
|
|
162
|
-
name: "Sui Testnet",
|
|
163
|
-
namespace: "sui",
|
|
164
|
-
reference: "testnet"
|
|
165
|
-
}
|
|
166
|
-
};
|
|
167
|
-
const SUI_CHAINS_LIST = Object.values(SUI_CHAINS);
|
|
76
|
+
const discoverSuiAdapters = (onAdapter, loadModule) => discoverWalletStandard(onAdapter, buildSuiAdapter, loadModule);
|
|
168
77
|
|
|
169
78
|
//#endregion
|
|
170
79
|
//#region src/discoverer.ts
|
|
@@ -175,5 +84,5 @@ const SUI_CHAINS_LIST = Object.values(SUI_CHAINS);
|
|
|
175
84
|
const suiDiscoverer = { subscribe: discoverSuiAdapters };
|
|
176
85
|
|
|
177
86
|
//#endregion
|
|
178
|
-
export {
|
|
87
|
+
export { buildSuiAdapter, discoverSuiAdapters, suiDiscoverer };
|
|
179
88
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[],"sources":["../src/capabilities.ts","../src/wallet-standard-adapter.ts","../src/chains.ts","../src/discoverer.ts"],"sourcesContent":["import type { WalletCapabilities } from \"@usebutr/core\";\nimport { buildWalletCapabilities } from \"@usebutr/wallet-standard-shared\";\n\ntype WalletStandardCapabilityInput = {\n chainCount: number;\n features: {\n events: boolean;\n signAndExecuteTransaction: boolean;\n signMessage: boolean;\n signTransaction: boolean;\n };\n};\n\n/**\n * `signIn` is false: Sui Wallet Standard has no Sign-In-With-Sui feature.\n * `signAndExecuteTransaction` means the wallet broadcasts, while\n * `signTransaction` is sign-only and leaves the broadcast to the consumer.\n */\nconst resolveSuiCapabilities = (input: WalletStandardCapabilityInput): WalletCapabilities =>\n buildWalletCapabilities({\n chainCount: input.chainCount,\n events: input.features.events,\n sendTransaction: input.features.signAndExecuteTransaction,\n signIn: false,\n signMessage: input.features.signMessage,\n signTransaction: input.features.signTransaction,\n });\n\nexport type { WalletStandardCapabilityInput };\nexport { resolveSuiCapabilities };\n","import type { TransactionInput, WalletAdapter } from \"@usebutr/core\";\nimport { base64ToBytes, bytesToBase64 } from \"@usebutr/core\";\nimport {\n createWalletStandardCore,\n discoverWalletStandard,\n getFeature,\n slugify,\n} from \"@usebutr/wallet-standard-shared\";\nimport type { WalletStandardFeature, WalletStandardWallet } from \"@usebutr/wallet-standard-shared\";\n\nimport { resolveSuiCapabilities } from \"./capabilities\";\nimport type {\n SuiSignAndExecuteTransactionFeature,\n SuiSignPersonalMessageFeature,\n SuiSignTransactionFeature,\n} from \"./wallet-standard-types\";\n\nconst SUI_PREFIX = \"sui:\";\nconst SUI_DECIMALS = 9;\nconst SUI_MAINNET = \"sui:mainnet\";\n\nconst isSuiSignPersonalMessageFeature = (\n feature: WalletStandardFeature,\n): feature is WalletStandardFeature & SuiSignPersonalMessageFeature =>\n \"signPersonalMessage\" in feature && typeof feature.signPersonalMessage === \"function\";\n\nconst isSuiSignAndExecuteTransactionFeature = (\n feature: WalletStandardFeature,\n): feature is WalletStandardFeature & SuiSignAndExecuteTransactionFeature =>\n \"signAndExecuteTransaction\" in feature && typeof feature.signAndExecuteTransaction === \"function\";\n\nconst isSuiSignTransactionFeature = (\n feature: WalletStandardFeature,\n): feature is WalletStandardFeature & SuiSignTransactionFeature =>\n \"signTransaction\" in feature && typeof feature.signTransaction === \"function\";\n\n/** Coerce butr's `unknown` tx into the shape the Sui Wallet Standard features\n * expect: an object with `toJSON()` returning a Promise<string>. A raw string\n * or BCS byte array is wrapped, because wallets accept only the `toJSON()`\n * form and a bare string reaches them as a shape they cannot consume. */\nconst coerceSuiTransaction = (tx: TransactionInput) => {\n if (typeof tx === \"string\") {\n return { toJSON: () => Promise.resolve(tx) };\n }\n if (tx instanceof Uint8Array) {\n const encoded = bytesToBase64(tx);\n return { toJSON: () => Promise.resolve(encoded) };\n }\n if (typeof tx === \"object\" && tx !== null && \"toJSON\" in tx && typeof tx.toJSON === \"function\") {\n return { toJSON: tx.toJSON };\n }\n throw new TypeError(\n \"Sui sendTx/signTransaction expects a @mysten/sui Transaction (with toJSON()), a base64-encoded string, or BCS bytes\",\n );\n};\n\n/**\n * Sui Wallet Standard has no \"switch network\" RPC, so `switchChain` moves\n * butr's view only and the wallet's own UI owns its cluster. Balance and\n * receipt reads need `@mysten/sui`'s `SuiClient`, which butr doesn't ship.\n */\nconst buildSuiAdapter = (\n wallet: WalletStandardWallet,\n /** Optional. Called with a function that pushes a synthetic\n * `disconnected` event to all current subscribers. The discovery\n * layer invokes it on Wallet Standard `unregister`. */\n registerDisconnector?: (emit: () => void) => void,\n): WalletAdapter | null => {\n const core = createWalletStandardCore({\n chainPrefix: SUI_PREFIX,\n id: slugify(\"sui\", wallet.name),\n label: \"Sui\",\n namespace: \"sui\",\n platform: \"Sui\",\n preferredChainIds: [SUI_MAINNET],\n registerDisconnector,\n trackChainChanges: true,\n wallet,\n });\n if (core === null) {\n return null;\n }\n\n const signMessage = getFeature(\n wallet,\n \"sui:signPersonalMessage\",\n isSuiSignPersonalMessageFeature,\n );\n const signAndExecute = getFeature(\n wallet,\n \"sui:signAndExecuteTransaction\",\n isSuiSignAndExecuteTransactionFeature,\n );\n const signTx = getFeature(wallet, \"sui:signTransaction\", isSuiSignTransactionFeature);\n\n /** Resolve a caller-supplied target into a chain the wallet advertises,\n * accepting either a full CAIP-2 id (`sui:testnet`) or a bare reference. */\n const resolveTargetChain = (targetChainId: string): string => {\n const candidate = targetChainId.startsWith(SUI_PREFIX)\n ? targetChainId\n : `${SUI_PREFIX}${targetChainId}`;\n if (!wallet.chains.includes(candidate)) {\n throw new Error(\n `Wallet ${wallet.name} does not advertise chain \"${candidate}\". Available: ${wallet.chains.join(\", \")}`,\n );\n }\n return candidate;\n };\n\n const executeTx = async (\n tx: TransactionInput,\n account?: { walletAddress: string },\n chain?: string,\n ): Promise<string> => {\n if (signAndExecute === undefined) {\n throw new Error(`Wallet ${wallet.name} does not advertise sui:signAndExecuteTransaction`);\n }\n const wsAccount = core.resolveAccount(account);\n const transaction = coerceSuiTransaction(tx);\n const output = await signAndExecute.signAndExecuteTransaction({\n account: wsAccount,\n chain: chain ?? core.currentChainId(),\n transaction,\n });\n return output.digest;\n };\n\n const adapter: WalletAdapter = {\n ...core,\n capabilities: resolveSuiCapabilities({\n chainCount: core.chainCount,\n features: {\n events: core.hasEvents,\n signAndExecuteTransaction: Boolean(signAndExecute),\n signMessage: Boolean(signMessage),\n signTransaction: Boolean(signTx),\n },\n }),\n chainPlatform: \"sui\",\n\n getBalance: () =>\n Promise.resolve({\n decimals: SUI_DECIMALS,\n formatted: \"0\",\n symbol: \"SUI\",\n value: 0n,\n }),\n\n getTransactionReceipt: () => Promise.resolve({ status: \"Pending\" as const }),\n\n async requestAccounts() {\n await core.connect();\n },\n\n sendTx: (tx, account) => executeTx(tx, account),\n\n async sendTxToChain(tx, targetChainId, account, cb) {\n const target = resolveTargetChain(targetChainId);\n if (target !== core.currentChainId()) {\n cb?.();\n }\n const digest = await executeTx(tx, account, target);\n return digest;\n },\n\n async signMessage(msg, account) {\n if (signMessage === undefined) {\n throw new Error(`Wallet ${wallet.name} does not advertise sui:signPersonalMessage`);\n }\n const output = await signMessage.signPersonalMessage({\n account: core.resolveAccount(account),\n message: msg,\n });\n return {\n signature: base64ToBytes(output.signature),\n signedMessage: base64ToBytes(output.bytes),\n };\n },\n };\n\n if (signTx !== undefined) {\n adapter.signTransaction = async (tx, account) => {\n const wsAccount = core.resolveAccount(account);\n const transaction = coerceSuiTransaction(tx);\n const output = await signTx.signTransaction({\n account: wsAccount,\n chain: core.currentChainId(),\n transaction,\n });\n return {\n bytes: base64ToBytes(output.bytes),\n signature: base64ToBytes(output.signature),\n };\n };\n }\n\n return adapter;\n};\n\n/**\n * Requires the optional `@wallet-standard/app` peer dep.\n * Spec: https://docs.sui.io/standards/wallet-standard\n */\nconst discoverSuiAdapters = (onAdapter: (adapter: WalletAdapter) => void): (() => void) =>\n discoverWalletStandard(onAdapter, (wallet, registerDisconnector) =>\n buildSuiAdapter(wallet, registerDisconnector),\n );\n\nexport { buildSuiAdapter, discoverSuiAdapters };\n","import type { ChainBase } from \"@usebutr/core\";\n\nconst SUI_CHAINS = {\n devnet: { id: \"sui:devnet\", name: \"Sui Devnet\", namespace: \"sui\", reference: \"devnet\" },\n localnet: {\n id: \"sui:localnet\",\n name: \"Sui Localnet\",\n namespace: \"sui\",\n reference: \"localnet\",\n },\n mainnet: {\n id: \"sui:mainnet\",\n name: \"Sui Mainnet\",\n namespace: \"sui\",\n reference: \"mainnet\",\n },\n testnet: { id: \"sui:testnet\", name: \"Sui Testnet\", namespace: \"sui\", reference: \"testnet\" },\n} as const satisfies Record<string, ChainBase>;\n\nconst SUI_CHAINS_LIST: ReadonlyArray<ChainBase> = Object.values(SUI_CHAINS);\n\nexport { SUI_CHAINS, SUI_CHAINS_LIST };\n","import type { PlatformDiscoverer } from \"@usebutr/core\";\n\nimport { discoverSuiAdapters } from \"./wallet-standard-adapter\";\n\n/**\n * Sui's `PlatformDiscoverer`: Sui Wallet Standard announcements. No\n * legacy fallback; Sui standardised on Wallet Standard from launch.\n */\nconst suiDiscoverer: PlatformDiscoverer = {\n subscribe: discoverSuiAdapters,\n};\n\nexport { suiDiscoverer };\n"],"mappings":"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"}
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../src/wallet-standard-adapter.ts","../src/discoverer.ts"],"sourcesContent":["import type { SuiAdapter, SuiTransactionInput, WalletAdapter } from \"@usebutr/core\";\nimport { base64ToBytes, bytesToBase64, SUI_CHAINS_LIST } from \"@usebutr/core\";\nimport {\n createWalletStandardCore,\n discoverWalletStandard,\n getFeature,\n slugify,\n} from \"@usebutr/wallet-standard-shared\";\nimport type {\n WalletStandardModuleLoader,\n WalletStandardWallet,\n} from \"@usebutr/wallet-standard-shared\";\n\nimport type {\n SuiSignAndExecuteTransactionFeature,\n SuiSignPersonalMessageFeature,\n SuiSignTransactionFeature,\n SuiSignTransactionInput,\n} from \"./wallet-standard-types\";\n\ntype WalletTransaction = SuiSignTransactionInput[\"transaction\"];\n\n/**\n * Sui wallets accept only the `toJSON()` form, so a JSON or base64 string and\n * BCS bytes are wrapped. A `Transaction` passes through untouched: its\n * `toJSON` reads `this`, which a copied method would lose.\n */\nconst coerceSuiTransaction = (tx: SuiTransactionInput): WalletTransaction => {\n if (typeof tx === \"string\") {\n return { toJSON: () => Promise.resolve(tx) };\n }\n if (tx instanceof Uint8Array) {\n const encoded = bytesToBase64(tx);\n return { toJSON: () => Promise.resolve(encoded) };\n }\n return tx;\n};\n\n/**\n * Wallet Standard carries the chain per call, so `sendTx` and\n * `signTransaction` route `options.chain` without moving the wallet. Balance\n * and receipt reads need a `SuiClient`, which butr does not ship.\n */\nconst buildSuiAdapter = (\n wallet: WalletStandardWallet,\n /** Discovery passes this so a Wallet Standard `unregister` tears down the\n * connected pool entry. */\n registerDisconnector?: (emit: () => void) => void,\n): SuiAdapter | null => {\n const core = createWalletStandardCore({\n chains: SUI_CHAINS_LIST,\n id: slugify(\"sui\", wallet.name),\n label: \"Sui\",\n namespace: \"sui\",\n preferredChainIds: [\"sui:mainnet\"],\n registerDisconnector,\n trackChainChanges: true,\n wallet,\n });\n if (core === null) {\n return null;\n }\n\n const signAndExecute = getFeature<SuiSignAndExecuteTransactionFeature>(\n wallet,\n \"sui:signAndExecuteTransaction\",\n \"signAndExecuteTransaction\",\n );\n const signPersonalMessage = getFeature<SuiSignPersonalMessageFeature>(\n wallet,\n \"sui:signPersonalMessage\",\n \"signPersonalMessage\",\n );\n const signTransaction = getFeature<SuiSignTransactionFeature>(\n wallet,\n \"sui:signTransaction\",\n \"signTransaction\",\n );\n\n return {\n ...core.base,\n chainPlatform: \"sui\",\n ...(signAndExecute !== undefined && {\n async sendTx(tx, options) {\n const output = await signAndExecute.signAndExecuteTransaction({\n account: core.resolveAccount(options?.account),\n chain: core.resolveChainId(options?.chain),\n transaction: coerceSuiTransaction(tx),\n });\n return output.digest;\n },\n }),\n ...(signPersonalMessage !== undefined && {\n async signMessage(message, options) {\n const output = await signPersonalMessage.signPersonalMessage({\n account: core.resolveAccount(options?.account),\n message,\n });\n return {\n signature: base64ToBytes(output.signature),\n signedMessage: base64ToBytes(output.bytes),\n };\n },\n }),\n ...(signTransaction !== undefined && {\n async signTransaction(tx, options) {\n const output = await signTransaction.signTransaction({\n account: core.resolveAccount(options?.account),\n chain: core.resolveChainId(options?.chain),\n transaction: coerceSuiTransaction(tx),\n });\n return { bytes: base64ToBytes(output.bytes), signature: base64ToBytes(output.signature) };\n },\n }),\n };\n};\n\n/**\n * Requires the optional `@wallet-standard/app` peer dep; without it Sui\n * discovery silently does nothing.\n * Spec: https://docs.sui.io/standards/wallet-standard\n */\nconst discoverSuiAdapters = (\n onAdapter: (adapter: WalletAdapter) => void,\n loadModule?: WalletStandardModuleLoader,\n): (() => void) => discoverWalletStandard(onAdapter, buildSuiAdapter, loadModule);\n\nexport { buildSuiAdapter, discoverSuiAdapters };\n","import type { PlatformDiscoverer } from \"@usebutr/core\";\n\nimport { discoverSuiAdapters } from \"./wallet-standard-adapter\";\n\n/**\n * Sui's `PlatformDiscoverer`: Sui Wallet Standard announcements. No\n * legacy fallback; Sui standardised on Wallet Standard from launch.\n */\nconst suiDiscoverer: PlatformDiscoverer = {\n subscribe: discoverSuiAdapters,\n};\n\nexport { suiDiscoverer };\n"],"mappings":";;;;;;;;;AA2BA,MAAM,wBAAwB,OAA+C;CAC3E,IAAI,OAAO,OAAO,UAChB,OAAO,EAAE,cAAc,QAAQ,QAAQ,EAAE,EAAE;CAE7C,IAAI,cAAc,YAAY;EAC5B,MAAM,UAAU,cAAc,EAAE;EAChC,OAAO,EAAE,cAAc,QAAQ,QAAQ,OAAO,EAAE;CAClD;CACA,OAAO;AACT;;;;;;AAOA,MAAM,mBACJ,QAGA,yBACsB;CACtB,MAAM,OAAO,yBAAyB;EACpC,QAAQ;EACR,IAAI,QAAQ,OAAO,OAAO,IAAI;EAC9B,OAAO;EACP,WAAW;EACX,mBAAmB,CAAC,aAAa;EACjC;EACA,mBAAmB;EACnB;CACF,CAAC;CACD,IAAI,SAAS,MACX,OAAO;CAGT,MAAM,iBAAiB,WACrB,QACA,iCACA,2BACF;CACA,MAAM,sBAAsB,WAC1B,QACA,2BACA,qBACF;CACA,MAAM,kBAAkB,WACtB,QACA,uBACA,iBACF;CAEA,OAAO;EACL,GAAG,KAAK;EACR,eAAe;EACf,GAAI,mBAAmB,UAAa,EAClC,MAAM,OAAO,IAAI,SAAS;GAMxB,QAAO,MALc,eAAe,0BAA0B;IAC5D,SAAS,KAAK,eAAe,SAAS,OAAO;IAC7C,OAAO,KAAK,eAAe,SAAS,KAAK;IACzC,aAAa,qBAAqB,EAAE;GACtC,CAAC,EACY,CAAC;EAChB,EACF;EACA,GAAI,wBAAwB,UAAa,EACvC,MAAM,YAAY,SAAS,SAAS;GAClC,MAAM,SAAS,MAAM,oBAAoB,oBAAoB;IAC3D,SAAS,KAAK,eAAe,SAAS,OAAO;IAC7C;GACF,CAAC;GACD,OAAO;IACL,WAAW,cAAc,OAAO,SAAS;IACzC,eAAe,cAAc,OAAO,KAAK;GAC3C;EACF,EACF;EACA,GAAI,oBAAoB,UAAa,EACnC,MAAM,gBAAgB,IAAI,SAAS;GACjC,MAAM,SAAS,MAAM,gBAAgB,gBAAgB;IACnD,SAAS,KAAK,eAAe,SAAS,OAAO;IAC7C,OAAO,KAAK,eAAe,SAAS,KAAK;IACzC,aAAa,qBAAqB,EAAE;GACtC,CAAC;GACD,OAAO;IAAE,OAAO,cAAc,OAAO,KAAK;IAAG,WAAW,cAAc,OAAO,SAAS;GAAE;EAC1F,EACF;CACF;AACF;;;;;;AAOA,MAAM,uBACJ,WACA,eACiB,uBAAuB,WAAW,iBAAiB,UAAU;;;;;;;;ACrHhF,MAAM,gBAAoC,EACxC,WAAW,oBACb"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@usebutr/sui",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.1",
|
|
4
4
|
"description": "Wallet Standard adapter for butr (Sui).",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"butr",
|
|
@@ -40,13 +40,13 @@
|
|
|
40
40
|
"access": "public"
|
|
41
41
|
},
|
|
42
42
|
"dependencies": {
|
|
43
|
-
"@usebutr/core": "
|
|
44
|
-
"@usebutr/wallet-standard-shared": "
|
|
43
|
+
"@usebutr/core": "3.0.1",
|
|
44
|
+
"@usebutr/wallet-standard-shared": "2.0.1"
|
|
45
45
|
},
|
|
46
46
|
"devDependencies": {
|
|
47
47
|
"@wallet-standard/app": "^1.1.1",
|
|
48
48
|
"typescript": "^7.0.2",
|
|
49
|
-
"vitest": "^
|
|
49
|
+
"vitest": "^5.0.1",
|
|
50
50
|
"@repo/config-vitest": "0.0.0",
|
|
51
51
|
"@repo/typescript-config": "0.0.0"
|
|
52
52
|
},
|